Compare commits

..

No commits in common. "d9dfef4016062efcea37df1b929960264d0555b8" and "21a27c691d05aee76c53d03e7008c2bf1fbdb133" have entirely different histories.

7 changed files with 20 additions and 19 deletions

View File

@ -58,7 +58,7 @@ public abstract class BackgroundTask<T> implements ProgressListener
protected String getErrorMessage(Throwable error)
{
return CommunicationError.getErrorMessage(error);
return CommunicationError.getErrorMessage(error, activity);
}
@Override

View File

@ -401,7 +401,7 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
Timber.w(exception)
ErrorDialog.Builder(requireContext())
.setTitle(R.string.error_label)
.setMessage(getErrorMessage(exception))
.setMessage(getErrorMessage(exception, context))
.show()
}
}

View File

@ -78,7 +78,6 @@ import org.moire.ultrasonic.R
import org.moire.ultrasonic.adapters.BaseAdapter
import org.moire.ultrasonic.adapters.TrackViewBinder
import org.moire.ultrasonic.api.subsonic.models.AlbumListType
import org.moire.ultrasonic.app.UApp
import org.moire.ultrasonic.audiofx.EqualizerController
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.shouldUseId3Tags
@ -663,6 +662,7 @@ class PlayerFragment :
parentId = track.parent,
isAlbum = true
)
findNavController().navigate(action)
return true
}
@ -822,16 +822,16 @@ class PlayerFragment :
musicService.createPlaylist(null, playlistName, entries)
}.invokeOnCompletion {
if (it == null || it is CancellationException) {
Util.toast(UApp.applicationContext(), R.string.download_playlist_done)
Util.toast(context, R.string.download_playlist_done)
} else {
Timber.e(it, "Exception has occurred in savePlaylistInBackground")
val msg = String.format(
Locale.ROOT,
"%s %s",
resources.getString(R.string.download_playlist_error),
CommunicationError.getErrorMessage(it)
CommunicationError.getErrorMessage(it, context)
)
Util.toast(UApp.applicationContext(), msg)
Util.toast(context, msg)
}
}
}

View File

@ -351,11 +351,13 @@ open class TrackCollectionFragment(
val isArtist = navArgs.isArtist
// Need a valid id to recurse sub directories stuff
if (hasSubFolders && navArgs.id != null) {
// Need a valid id to download stuff
val id = navArgs.id ?: return
if (hasSubFolders) {
downloadHandler.fetchTracksAndAddToController(
fragment = this,
id = navArgs.id!!,
id = id,
append = append,
autoPlay = !append,
shuffle = shuffle,

View File

@ -46,7 +46,7 @@ class DownloadHandler(
var successString: String? = null
// Launch the Job
executeTaskWithToast({
executeTaskWithToast(fragment, {
val tracksToDownload: List<Track> = tracks
?: getTracksFromServer(isArtist, id!!, isDirectory, name, isShare)
@ -104,7 +104,7 @@ class DownloadHandler(
) {
var successString: String? = null
// Launch the Job
executeTaskWithToast({
executeTaskWithToast(fragment, {
val songs: MutableList<Track> =
getTracksFromServer(isArtist, id, isDirectory, name, isShare)

View File

@ -20,7 +20,6 @@ import kotlinx.coroutines.CoroutineExceptionHandler
import org.moire.ultrasonic.R
import org.moire.ultrasonic.api.subsonic.ApiNotSupportedException
import org.moire.ultrasonic.api.subsonic.SubsonicRESTException
import org.moire.ultrasonic.app.UApp
import org.moire.ultrasonic.subsonic.getLocalizedErrorMessage
import timber.log.Timber
@ -47,14 +46,14 @@ object CommunicationError {
ErrorDialog(
context = context,
message = getErrorMessage(error)
message = getErrorMessage(error, context)
).show()
}
@JvmStatic
@Suppress("ReturnCount")
fun getErrorMessage(error: Throwable): String {
val context = UApp.applicationContext()
fun getErrorMessage(error: Throwable, context: Context?): String {
if (context == null) return "Couldn't get Error message, Context is null"
if (error is IOException && !Util.hasUsableNetwork()) {
return context.resources.getString(R.string.background_task_no_network)
} else if (error is FileNotFoundException) {

View File

@ -17,7 +17,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.moire.ultrasonic.R
import org.moire.ultrasonic.app.UApp
import timber.log.Timber
object CoroutinePatterns {
@ -31,6 +30,7 @@ object CoroutinePatterns {
}
fun CoroutineScope.executeTaskWithToast(
fragment: Fragment,
task: suspend CoroutineScope.() -> Unit,
successString: () -> String?
): Job {
@ -40,7 +40,7 @@ fun CoroutineScope.executeTaskWithToast(
// Setup a handler when the job is done
job.invokeOnCompletion {
val toastString = if (it != null && it !is CancellationException) {
CommunicationError.getErrorMessage(it)
CommunicationError.getErrorMessage(it, fragment.context)
} else {
successString()
}
@ -49,7 +49,7 @@ fun CoroutineScope.executeTaskWithToast(
if (toastString == null) return@invokeOnCompletion
launch(Dispatchers.Main) {
Util.toast(UApp.applicationContext(), toastString)
Util.toast(fragment.context, toastString)
}
}
@ -62,7 +62,7 @@ fun CoroutineScope.executeTaskWithModalDialog(
successString: () -> String
) {
// Create the job
val job = executeTaskWithToast(task, successString)
val job = executeTaskWithToast(fragment, task, successString)
// Create the dialog
val builder = InfoDialog.Builder(fragment.requireContext())