mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-15 08:50:35 +03:00
Merge branch 'playAll' into 'develop'
Fix playing all tracks when the selection has no id See merge request ultrasonic/ultrasonic!1033
This commit is contained in:
commit
d9dfef4016
@ -58,7 +58,7 @@ public abstract class BackgroundTask<T> implements ProgressListener
|
||||
|
||||
protected String getErrorMessage(Throwable error)
|
||||
{
|
||||
return CommunicationError.getErrorMessage(error, activity);
|
||||
return CommunicationError.getErrorMessage(error);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -401,7 +401,7 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
|
||||
Timber.w(exception)
|
||||
ErrorDialog.Builder(requireContext())
|
||||
.setTitle(R.string.error_label)
|
||||
.setMessage(getErrorMessage(exception, context))
|
||||
.setMessage(getErrorMessage(exception))
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ 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
|
||||
@ -662,7 +663,6 @@ 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(context, R.string.download_playlist_done)
|
||||
Util.toast(UApp.applicationContext(), 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, context)
|
||||
CommunicationError.getErrorMessage(it)
|
||||
)
|
||||
Util.toast(context, msg)
|
||||
Util.toast(UApp.applicationContext(), msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -351,13 +351,11 @@ open class TrackCollectionFragment(
|
||||
|
||||
val isArtist = navArgs.isArtist
|
||||
|
||||
// Need a valid id to download stuff
|
||||
val id = navArgs.id ?: return
|
||||
|
||||
if (hasSubFolders) {
|
||||
// Need a valid id to recurse sub directories stuff
|
||||
if (hasSubFolders && navArgs.id != null) {
|
||||
downloadHandler.fetchTracksAndAddToController(
|
||||
fragment = this,
|
||||
id = id,
|
||||
id = navArgs.id!!,
|
||||
append = append,
|
||||
autoPlay = !append,
|
||||
shuffle = shuffle,
|
||||
|
@ -46,7 +46,7 @@ class DownloadHandler(
|
||||
var successString: String? = null
|
||||
|
||||
// Launch the Job
|
||||
executeTaskWithToast(fragment, {
|
||||
executeTaskWithToast({
|
||||
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(fragment, {
|
||||
executeTaskWithToast({
|
||||
val songs: MutableList<Track> =
|
||||
getTracksFromServer(isArtist, id, isDirectory, name, isShare)
|
||||
|
||||
|
@ -20,6 +20,7 @@ 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
|
||||
|
||||
@ -46,14 +47,14 @@ object CommunicationError {
|
||||
|
||||
ErrorDialog(
|
||||
context = context,
|
||||
message = getErrorMessage(error, context)
|
||||
message = getErrorMessage(error)
|
||||
).show()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@Suppress("ReturnCount")
|
||||
fun getErrorMessage(error: Throwable, context: Context?): String {
|
||||
if (context == null) return "Couldn't get Error message, Context is null"
|
||||
fun getErrorMessage(error: Throwable): String {
|
||||
val context = UApp.applicationContext()
|
||||
if (error is IOException && !Util.hasUsableNetwork()) {
|
||||
return context.resources.getString(R.string.background_task_no_network)
|
||||
} else if (error is FileNotFoundException) {
|
||||
|
@ -17,6 +17,7 @@ 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 {
|
||||
@ -30,7 +31,6 @@ 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, fragment.context)
|
||||
CommunicationError.getErrorMessage(it)
|
||||
} else {
|
||||
successString()
|
||||
}
|
||||
@ -49,7 +49,7 @@ fun CoroutineScope.executeTaskWithToast(
|
||||
if (toastString == null) return@invokeOnCompletion
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
Util.toast(fragment.context, toastString)
|
||||
Util.toast(UApp.applicationContext(), toastString)
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ fun CoroutineScope.executeTaskWithModalDialog(
|
||||
successString: () -> String
|
||||
) {
|
||||
// Create the job
|
||||
val job = executeTaskWithToast(fragment, task, successString)
|
||||
val job = executeTaskWithToast(task, successString)
|
||||
|
||||
// Create the dialog
|
||||
val builder = InfoDialog.Builder(fragment.requireContext())
|
||||
|
Loading…
x
Reference in New Issue
Block a user