Cleanup code

This commit is contained in:
tzugen 2021-06-19 20:42:03 +02:00
parent 30bbeb7594
commit d8b032e2e3
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
7 changed files with 521 additions and 531 deletions

View File

@ -35,6 +35,9 @@ exceptions:
empty-blocks:
active: true
EmptyFunctionBlock:
active: true
ignoreOverridden: true
complexity:
active: true

View File

@ -16,66 +16,28 @@
Copyright 2010 (C) Sindre Mehus
*/
package org.moire.ultrasonic.util;
package org.moire.ultrasonic.util
import android.app.Activity;
import android.app.Activity
/**
* @author Sindre Mehus
*/
public abstract class SilentBackgroundTask<T> extends BackgroundTask<T>
{
abstract class SilentBackgroundTask<T>(activity: Activity?) : BackgroundTask<T>(activity) {
override fun execute() {
val thread: Thread = object : Thread() {
override fun run() {
try {
val result = doInBackground()
handler.post { done(result) }
} catch (all: Throwable) {
handler.post { error(all) }
}
}
}
thread.start()
}
public SilentBackgroundTask(Activity activity)
{
super(activity);
}
@Override
public void execute()
{
Thread thread = new Thread()
{
@Override
public void run()
{
try
{
final T result = doInBackground();
getHandler().post(new Runnable()
{
@Override
public void run()
{
done(result);
}
});
}
catch (final Throwable t)
{
getHandler().post(new Runnable()
{
@Override
public void run()
{
error(t);
}
});
}
}
};
thread.start();
}
@Override
public void updateProgress(int messageId)
{
}
@Override
public void updateProgress(String message)
{
}
override fun updateProgress(messageId: Int) {}
override fun updateProgress(message: String) {}
}

View File

@ -198,7 +198,7 @@ class CachedMusicService(private val musicService: MusicService) : MusicService,
}
@Throws(Exception::class)
override fun createPlaylist(id: String, name: String, entries: List<MusicDirectory.Entry>) {
override fun createPlaylist(id: String?, name: String?, entries: List<MusicDirectory.Entry>) {
cachedPlaylists.clear()
musicService.createPlaylist(id, name, entries)
}

View File

@ -73,7 +73,7 @@ interface MusicService {
fun getPlaylists(refresh: Boolean): List<Playlist>
@Throws(Exception::class)
fun createPlaylist(id: String, name: String, entries: List<MusicDirectory.Entry>)
fun createPlaylist(id: String?, name: String?, entries: List<MusicDirectory.Entry>)
@Throws(Exception::class)
fun deletePlaylist(id: String)

View File

@ -221,7 +221,7 @@ class OfflineMusicService : MusicService, KoinComponent {
@Suppress("TooGenericExceptionCaught")
@Throws(Exception::class)
override fun createPlaylist(id: String, name: String, entries: List<MusicDirectory.Entry>) {
override fun createPlaylist(id: String?, name: String?, entries: List<MusicDirectory.Entry>) {
val playlistFile =
FileUtil.getPlaylistFile(activeServerProvider.getActiveServer().name, name)
val fw = FileWriter(playlistFile)

View File

@ -295,12 +295,20 @@ open class RESTMusicService(
return response.body()!!.playlists.toDomainEntitiesList()
}
/**
* Either ID or String is required.
* ID is required when updating
* String is required when creating
*/
@Throws(Exception::class)
override fun createPlaylist(
id: String,
name: String,
id: String?,
name: String?,
entries: List<MusicDirectory.Entry>
) {
if (id == null && name == null)
throw IllegalArgumentException("Either id or name is required.")
val pSongIds: MutableList<String> = ArrayList(entries.size)
for ((id1) in entries) {