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) protected String getErrorMessage(Throwable error)
{ {
return CommunicationError.getErrorMessage(error); return CommunicationError.getErrorMessage(error, activity);
} }
@Override @Override

View File

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

View File

@ -78,7 +78,6 @@ import org.moire.ultrasonic.R
import org.moire.ultrasonic.adapters.BaseAdapter import org.moire.ultrasonic.adapters.BaseAdapter
import org.moire.ultrasonic.adapters.TrackViewBinder import org.moire.ultrasonic.adapters.TrackViewBinder
import org.moire.ultrasonic.api.subsonic.models.AlbumListType import org.moire.ultrasonic.api.subsonic.models.AlbumListType
import org.moire.ultrasonic.app.UApp
import org.moire.ultrasonic.audiofx.EqualizerController import org.moire.ultrasonic.audiofx.EqualizerController
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.shouldUseId3Tags import org.moire.ultrasonic.data.ActiveServerProvider.Companion.shouldUseId3Tags
@ -663,6 +662,7 @@ class PlayerFragment :
parentId = track.parent, parentId = track.parent,
isAlbum = true isAlbum = true
) )
findNavController().navigate(action) findNavController().navigate(action)
return true return true
} }
@ -822,16 +822,16 @@ class PlayerFragment :
musicService.createPlaylist(null, playlistName, entries) musicService.createPlaylist(null, playlistName, entries)
}.invokeOnCompletion { }.invokeOnCompletion {
if (it == null || it is CancellationException) { if (it == null || it is CancellationException) {
Util.toast(UApp.applicationContext(), R.string.download_playlist_done) Util.toast(context, R.string.download_playlist_done)
} else { } else {
Timber.e(it, "Exception has occurred in savePlaylistInBackground") Timber.e(it, "Exception has occurred in savePlaylistInBackground")
val msg = String.format( val msg = String.format(
Locale.ROOT, Locale.ROOT,
"%s %s", "%s %s",
resources.getString(R.string.download_playlist_error), 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 val isArtist = navArgs.isArtist
// Need a valid id to recurse sub directories stuff // Need a valid id to download stuff
if (hasSubFolders && navArgs.id != null) { val id = navArgs.id ?: return
if (hasSubFolders) {
downloadHandler.fetchTracksAndAddToController( downloadHandler.fetchTracksAndAddToController(
fragment = this, fragment = this,
id = navArgs.id!!, id = id,
append = append, append = append,
autoPlay = !append, autoPlay = !append,
shuffle = shuffle, shuffle = shuffle,

View File

@ -46,7 +46,7 @@ class DownloadHandler(
var successString: String? = null var successString: String? = null
// Launch the Job // Launch the Job
executeTaskWithToast({ executeTaskWithToast(fragment, {
val tracksToDownload: List<Track> = tracks val tracksToDownload: List<Track> = tracks
?: getTracksFromServer(isArtist, id!!, isDirectory, name, isShare) ?: getTracksFromServer(isArtist, id!!, isDirectory, name, isShare)
@ -104,7 +104,7 @@ class DownloadHandler(
) { ) {
var successString: String? = null var successString: String? = null
// Launch the Job // Launch the Job
executeTaskWithToast({ executeTaskWithToast(fragment, {
val songs: MutableList<Track> = val songs: MutableList<Track> =
getTracksFromServer(isArtist, id, isDirectory, name, isShare) 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.R
import org.moire.ultrasonic.api.subsonic.ApiNotSupportedException import org.moire.ultrasonic.api.subsonic.ApiNotSupportedException
import org.moire.ultrasonic.api.subsonic.SubsonicRESTException import org.moire.ultrasonic.api.subsonic.SubsonicRESTException
import org.moire.ultrasonic.app.UApp
import org.moire.ultrasonic.subsonic.getLocalizedErrorMessage import org.moire.ultrasonic.subsonic.getLocalizedErrorMessage
import timber.log.Timber import timber.log.Timber
@ -47,14 +46,14 @@ object CommunicationError {
ErrorDialog( ErrorDialog(
context = context, context = context,
message = getErrorMessage(error) message = getErrorMessage(error, context)
).show() ).show()
} }
@JvmStatic @JvmStatic
@Suppress("ReturnCount") @Suppress("ReturnCount")
fun getErrorMessage(error: Throwable): String { fun getErrorMessage(error: Throwable, context: Context?): String {
val context = UApp.applicationContext() if (context == null) return "Couldn't get Error message, Context is null"
if (error is IOException && !Util.hasUsableNetwork()) { if (error is IOException && !Util.hasUsableNetwork()) {
return context.resources.getString(R.string.background_task_no_network) return context.resources.getString(R.string.background_task_no_network)
} else if (error is FileNotFoundException) { } else if (error is FileNotFoundException) {

View File

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