mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-07-21 19:01:57 +03:00
Compare commits
4 Commits
21a27c691d
...
d9dfef4016
Author | SHA1 | Date | |
---|---|---|---|
|
d9dfef4016 | ||
|
3bd3607220 | ||
|
e35a33edde | ||
|
c1013f6b80 |
@ -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, activity);
|
return CommunicationError.getErrorMessage(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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, context))
|
.setMessage(getErrorMessage(exception))
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,7 @@ 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
|
||||||
@ -662,7 +663,6 @@ 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(context, R.string.download_playlist_done)
|
Util.toast(UApp.applicationContext(), 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, context)
|
CommunicationError.getErrorMessage(it)
|
||||||
)
|
)
|
||||||
Util.toast(context, msg)
|
Util.toast(UApp.applicationContext(), msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,13 +351,11 @@ open class TrackCollectionFragment(
|
|||||||
|
|
||||||
val isArtist = navArgs.isArtist
|
val isArtist = navArgs.isArtist
|
||||||
|
|
||||||
// Need a valid id to download stuff
|
// Need a valid id to recurse sub directories stuff
|
||||||
val id = navArgs.id ?: return
|
if (hasSubFolders && navArgs.id != null) {
|
||||||
|
|
||||||
if (hasSubFolders) {
|
|
||||||
downloadHandler.fetchTracksAndAddToController(
|
downloadHandler.fetchTracksAndAddToController(
|
||||||
fragment = this,
|
fragment = this,
|
||||||
id = id,
|
id = navArgs.id!!,
|
||||||
append = append,
|
append = append,
|
||||||
autoPlay = !append,
|
autoPlay = !append,
|
||||||
shuffle = shuffle,
|
shuffle = shuffle,
|
||||||
|
@ -46,7 +46,7 @@ class DownloadHandler(
|
|||||||
var successString: String? = null
|
var successString: String? = null
|
||||||
|
|
||||||
// Launch the Job
|
// Launch the Job
|
||||||
executeTaskWithToast(fragment, {
|
executeTaskWithToast({
|
||||||
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(fragment, {
|
executeTaskWithToast({
|
||||||
val songs: MutableList<Track> =
|
val songs: MutableList<Track> =
|
||||||
getTracksFromServer(isArtist, id, isDirectory, name, isShare)
|
getTracksFromServer(isArtist, id, isDirectory, name, isShare)
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ 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
|
||||||
|
|
||||||
@ -46,14 +47,14 @@ object CommunicationError {
|
|||||||
|
|
||||||
ErrorDialog(
|
ErrorDialog(
|
||||||
context = context,
|
context = context,
|
||||||
message = getErrorMessage(error, context)
|
message = getErrorMessage(error)
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@Suppress("ReturnCount")
|
@Suppress("ReturnCount")
|
||||||
fun getErrorMessage(error: Throwable, context: Context?): String {
|
fun getErrorMessage(error: Throwable): String {
|
||||||
if (context == null) return "Couldn't get Error message, Context is null"
|
val context = UApp.applicationContext()
|
||||||
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) {
|
||||||
|
@ -17,6 +17,7 @@ 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 {
|
||||||
@ -30,7 +31,6 @@ 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, fragment.context)
|
CommunicationError.getErrorMessage(it)
|
||||||
} 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(fragment.context, toastString)
|
Util.toast(UApp.applicationContext(), toastString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ fun CoroutineScope.executeTaskWithModalDialog(
|
|||||||
successString: () -> String
|
successString: () -> String
|
||||||
) {
|
) {
|
||||||
// Create the job
|
// Create the job
|
||||||
val job = executeTaskWithToast(fragment, task, successString)
|
val job = executeTaskWithToast(task, successString)
|
||||||
|
|
||||||
// Create the dialog
|
// Create the dialog
|
||||||
val builder = InfoDialog.Builder(fragment.requireContext())
|
val builder = InfoDialog.Builder(fragment.requireContext())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user