Fixed TODOs:

- Updated Koin
- Fixed Player start from widgets and notification
- Added cancellation to LoadingTask
- Minor fixes and cleanup
This commit is contained in:
Nite 2021-02-11 21:51:27 +01:00
parent 3dc6df9116
commit d70d2cc2fb
No known key found for this signature in database
GPG Key ID: 1D1AD59B1C6386C1
15 changed files with 40 additions and 69 deletions

View File

@ -27,7 +27,7 @@ ext.versions = [
okhttp : "3.10.0", okhttp : "3.10.0",
semver : "1.0.0", semver : "1.0.0",
twitterSerial : "0.1.6", twitterSerial : "0.1.6",
koin : "2.1.6", koin : "2.2.2",
picasso : "2.71828", picasso : "2.71828",
junit4 : "4.12", junit4 : "4.12",

View File

@ -252,7 +252,7 @@ public class PlaylistsFragment extends Fragment {
@Override @Override
public void onClick(DialogInterface dialog, int which) public void onClick(DialogInterface dialog, int which)
{ {
new LoadingTask<Void>(getActivity(), false, refreshPlaylistsListView) new LoadingTask<Void>(getActivity(), refreshPlaylistsListView, cancellationToken)
{ {
@Override @Override
protected Void doInBackground() throws Throwable protected Void doInBackground() throws Throwable
@ -337,7 +337,7 @@ public class PlaylistsFragment extends Fragment {
@Override @Override
public void onClick(DialogInterface dialog, int which) public void onClick(DialogInterface dialog, int which)
{ {
new LoadingTask<Void>(getActivity(), false, refreshPlaylistsListView) new LoadingTask<Void>(getActivity(), refreshPlaylistsListView, cancellationToken)
{ {
@Override @Override
protected Void doInBackground() throws Throwable protected Void doInBackground() throws Throwable

View File

@ -76,7 +76,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
private EditTextPreference sharingDefaultDescription; private EditTextPreference sharingDefaultDescription;
private EditTextPreference sharingDefaultGreeting; private EditTextPreference sharingDefaultGreeting;
private TimeSpanPreference sharingDefaultExpiration; private TimeSpanPreference sharingDefaultExpiration;
private PreferenceCategory serversCategory;
private Preference resumeOnBluetoothDevice; private Preference resumeOnBluetoothDevice;
private Preference pauseOnBluetoothDevice; private Preference pauseOnBluetoothDevice;
private CheckBoxPreference debugLogToFile; private CheckBoxPreference debugLogToFile;
@ -133,7 +132,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
sharingDefaultDescription = findPreference(Constants.PREFERENCES_KEY_DEFAULT_SHARE_DESCRIPTION); sharingDefaultDescription = findPreference(Constants.PREFERENCES_KEY_DEFAULT_SHARE_DESCRIPTION);
sharingDefaultGreeting = findPreference(Constants.PREFERENCES_KEY_DEFAULT_SHARE_GREETING); sharingDefaultGreeting = findPreference(Constants.PREFERENCES_KEY_DEFAULT_SHARE_GREETING);
sharingDefaultExpiration = findPreference(Constants.PREFERENCES_KEY_DEFAULT_SHARE_EXPIRATION); sharingDefaultExpiration = findPreference(Constants.PREFERENCES_KEY_DEFAULT_SHARE_EXPIRATION);
serversCategory = findPreference(Constants.PREFERENCES_KEY_SERVERS_KEY);
resumeOnBluetoothDevice = findPreference(Constants.PREFERENCES_KEY_RESUME_ON_BLUETOOTH_DEVICE); resumeOnBluetoothDevice = findPreference(Constants.PREFERENCES_KEY_RESUME_ON_BLUETOOTH_DEVICE);
pauseOnBluetoothDevice = findPreference(Constants.PREFERENCES_KEY_PAUSE_ON_BLUETOOTH_DEVICE); pauseOnBluetoothDevice = findPreference(Constants.PREFERENCES_KEY_PAUSE_ON_BLUETOOTH_DEVICE);
debugLogToFile = findPreference(Constants.PREFERENCES_KEY_DEBUG_LOG_TO_FILE); debugLogToFile = findPreference(Constants.PREFERENCES_KEY_DEBUG_LOG_TO_FILE);
@ -236,7 +234,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
@Override @Override
public void onPermissionRequestFinished(boolean hasPermission) { public void onPermissionRequestFinished(boolean hasPermission) {
if (hasPermission) { if (hasPermission) {
FilePickerDialog filePickerDialog = FilePickerDialog.Companion.createFilePickerDialog(getActivity()); FilePickerDialog filePickerDialog = FilePickerDialog.Companion.createFilePickerDialog(getContext());
filePickerDialog.setDefaultDirectory(FileUtil.getDefaultMusicDirectory(getActivity()).getPath()); filePickerDialog.setDefaultDirectory(FileUtil.getDefaultMusicDirectory(getActivity()).getPath());
filePickerDialog.setInitialDirectory(cacheLocation.getSummary().toString()); filePickerDialog.setInitialDirectory(cacheLocation.getSummary().toString());
filePickerDialog.setOnFileSelectedListener(new OnFileSelectedListener() { filePickerDialog.setOnFileSelectedListener(new OnFileSelectedListener() {

View File

@ -231,7 +231,7 @@ public class SharesFragment extends Fragment {
@Override @Override
public void onClick(DialogInterface dialog, int which) public void onClick(DialogInterface dialog, int which)
{ {
new LoadingTask<Void>(getActivity(), false, refreshSharesListView) new LoadingTask<Void>(getActivity(), refreshSharesListView, cancellationToken)
{ {
@Override @Override
protected Void doInBackground() throws Throwable protected Void doInBackground() throws Throwable
@ -327,7 +327,7 @@ public class SharesFragment extends Fragment {
@Override @Override
public void onClick(DialogInterface dialog, int which) public void onClick(DialogInterface dialog, int which)
{ {
new LoadingTask<Void>(getActivity(), false, refreshSharesListView) new LoadingTask<Void>(getActivity(), refreshSharesListView, cancellationToken)
{ {
@Override @Override
protected Void doInBackground() throws Throwable protected Void doInBackground() throws Throwable

View File

@ -40,6 +40,8 @@ public class UltrasonicAppWidgetProvider extends AppWidgetProvider
final Resources res = context.getResources(); final Resources res = context.getResources();
final RemoteViews views = new RemoteViews(context.getPackageName(), this.layoutId); final RemoteViews views = new RemoteViews(context.getPackageName(), this.layoutId);
views.setTextViewText(R.id.title, null);
views.setTextViewText(R.id.album, null);
views.setTextViewText(R.id.artist, res.getText(R.string.widget_initial_text)); views.setTextViewText(R.id.artist, res.getText(R.string.widget_initial_text));
linkButtons(context, views, false); linkButtons(context, views, false);
@ -183,8 +185,10 @@ public class UltrasonicAppWidgetProvider extends AppWidgetProvider
*/ */
private static void linkButtons(Context context, RemoteViews views, boolean playerActive) private static void linkButtons(Context context, RemoteViews views, boolean playerActive)
{ {
// TODO: If playerActive = true, display the PlayerFragment automatically Intent intent = new Intent(context, NavigationActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);;
Intent intent = new Intent(context, playerActive ? NavigationActivity.class : NavigationActivity.class); if (playerActive)
intent.putExtra(Constants.INTENT_EXTRA_NAME_SHOW_PLAYER, true);
intent.setAction("android.intent.action.MAIN"); intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER"); intent.addCategory("android.intent.category.LAUNCHER");
PendingIntent pendingIntent = PendingIntent.getActivity(context, 10, intent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pendingIntent = PendingIntent.getActivity(context, 10, intent, PendingIntent.FLAG_UPDATE_CURRENT);

View File

@ -30,6 +30,7 @@ import org.moire.ultrasonic.provider.UltrasonicAppWidgetProvider4X1;
import org.moire.ultrasonic.provider.UltrasonicAppWidgetProvider4X2; import org.moire.ultrasonic.provider.UltrasonicAppWidgetProvider4X2;
import org.moire.ultrasonic.provider.UltrasonicAppWidgetProvider4X3; import org.moire.ultrasonic.provider.UltrasonicAppWidgetProvider4X3;
import org.moire.ultrasonic.provider.UltrasonicAppWidgetProvider4X4; import org.moire.ultrasonic.provider.UltrasonicAppWidgetProvider4X4;
import org.moire.ultrasonic.util.Constants;
import org.moire.ultrasonic.util.FileUtil; import org.moire.ultrasonic.util.FileUtil;
import org.moire.ultrasonic.util.NowPlayingEventDistributor; import org.moire.ultrasonic.util.NowPlayingEventDistributor;
import org.moire.ultrasonic.util.ShufflePlayBuffer; import org.moire.ultrasonic.util.ShufflePlayBuffer;
@ -637,9 +638,10 @@ public class MediaPlayerService extends Service
notificationBuilder.setContent(contentView); notificationBuilder.setContent(contentView);
// TODO: Navigate automatically to PlayerFragment Intent notificationIntent = new Intent(this, NavigationActivity.class)
Intent notificationIntent = new Intent(this, NavigationActivity.class); .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationBuilder.setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0)); notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_SHOW_PLAYER, true);
notificationBuilder.setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT));
if (playerState == PlayerState.PAUSED || playerState == PlayerState.IDLE) { if (playerState == PlayerState.PAUSED || playerState == PlayerState.IDLE) {
contentView.setImageViewResource(R.id.control_play, R.drawable.media_start_normal_dark); contentView.setImageViewResource(R.id.control_play, R.drawable.media_start_normal_dark);

View File

@ -52,13 +52,12 @@ public final class Constants
public static final String INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET = "subsonic.albumlistoffset"; public static final String INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET = "subsonic.albumlistoffset";
public static final String INTENT_EXTRA_NAME_SHUFFLE = "subsonic.shuffle"; public static final String INTENT_EXTRA_NAME_SHUFFLE = "subsonic.shuffle";
public static final String INTENT_EXTRA_NAME_REFRESH = "subsonic.refresh"; public static final String INTENT_EXTRA_NAME_REFRESH = "subsonic.refresh";
public static final String INTENT_EXTRA_REQUEST_SEARCH = "subsonic.requestsearch";
public static final String INTENT_EXTRA_NAME_EXIT = "subsonic.exit";
public static final String INTENT_EXTRA_NAME_STARRED = "subsonic.starred"; public static final String INTENT_EXTRA_NAME_STARRED = "subsonic.starred";
public static final String INTENT_EXTRA_NAME_RANDOM = "subsonic.random"; public static final String INTENT_EXTRA_NAME_RANDOM = "subsonic.random";
public static final String INTENT_EXTRA_NAME_GENRE_NAME = "subsonic.genre"; public static final String INTENT_EXTRA_NAME_GENRE_NAME = "subsonic.genre";
public static final String INTENT_EXTRA_NAME_IS_ALBUM = "subsonic.isalbum"; public static final String INTENT_EXTRA_NAME_IS_ALBUM = "subsonic.isalbum";
public static final String INTENT_EXTRA_NAME_VIDEOS = "subsonic.videos"; public static final String INTENT_EXTRA_NAME_VIDEOS = "subsonic.videos";
public static final String INTENT_EXTRA_NAME_SHOW_PLAYER = "subsonic.showplayer";
// Names for Intent Actions // Names for Intent Actions
public static final String CMD_PROCESS_KEYCODE = "org.moire.ultrasonic.CMD_PROCESS_KEYCODE"; public static final String CMD_PROCESS_KEYCODE = "org.moire.ultrasonic.CMD_PROCESS_KEYCODE";

View File

@ -11,17 +11,14 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
*/ */
public abstract class LoadingTask<T> extends BackgroundTask<T> public abstract class LoadingTask<T> extends BackgroundTask<T>
{ {
private final Activity tabActivity; private final SwipeRefreshLayout swipe;
private final boolean cancellable; private final CancellationToken cancel;
private boolean cancelled;
private SwipeRefreshLayout swipe;
public LoadingTask(Activity activity, final boolean cancellable, SwipeRefreshLayout swipe) public LoadingTask(Activity activity, SwipeRefreshLayout swipe, CancellationToken cancel)
{ {
super(activity); super(activity);
tabActivity = activity;
this.cancellable = cancellable;
this.swipe = swipe; this.swipe = swipe;
this.cancel = cancel;
} }
@Override @Override
@ -37,7 +34,7 @@ public abstract class LoadingTask<T> extends BackgroundTask<T>
try try
{ {
final T result = doInBackground(); final T result = doInBackground();
if (isCancelled()) if (cancel.isCancellationRequested())
{ {
return; return;
} }
@ -54,7 +51,7 @@ public abstract class LoadingTask<T> extends BackgroundTask<T>
} }
catch (final Throwable t) catch (final Throwable t)
{ {
if (isCancelled()) if (cancel.isCancellationRequested())
{ {
return; return;
} }
@ -73,24 +70,8 @@ public abstract class LoadingTask<T> extends BackgroundTask<T>
}.start(); }.start();
} }
@SuppressLint("NewApi")
private boolean isCancelled()
{
// TODO: Implement cancelled
//return Build.VERSION.SDK_INT >= 17 ? tabActivity.isDestroyed() || cancelled : cancelled;
return cancelled;
}
@Override @Override
public void updateProgress(final String message) public void updateProgress(final String message)
{ {
getHandler().post(new Runnable()
{
@Override
public void run()
{
// TODO: This seems to be NOOP, can it be removed?
}
});
} }
} }

View File

@ -85,14 +85,5 @@ public abstract class TabActivityBackgroundTask<T> extends BackgroundTask<T>
@Override @Override
public void updateProgress(final String message) public void updateProgress(final String message)
{ {
// TODO: Remove
getHandler().post(new Runnable()
{
@Override
public void run()
{
//activity.updateProgress(message);
}
});
} }
} }

View File

@ -1019,8 +1019,10 @@ public class Util
public static void linkButtons(Context context, RemoteViews views, boolean playerActive) public static void linkButtons(Context context, RemoteViews views, boolean playerActive)
{ {
// TODO: Navigate automatically to PlayerFragment if playerActive = true Intent intent = new Intent(context, NavigationActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
Intent intent = new Intent(context, playerActive ? NavigationActivity.class : NavigationActivity.class); if (playerActive)
intent.putExtra(Constants.INTENT_EXTRA_NAME_SHOW_PLAYER, true);
intent.setAction("android.intent.action.MAIN"); intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER"); intent.addCategory("android.intent.category.LAUNCHER");
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

View File

@ -238,8 +238,15 @@ class NavigationActivity : AppCompatActivity() {
// android.intent.action.SEARCH and android.media.action.MEDIA_PLAY_FROM_SEARCH calls here // android.intent.action.SEARCH and android.media.action.MEDIA_PLAY_FROM_SEARCH calls here
override fun onNewIntent(intent: Intent?) { override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent) super.onNewIntent(intent)
if (intent == null) return;
val query = intent?.getStringExtra(SearchManager.QUERY) if (intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHOW_PLAYER, false))
{
findNavController(R.id.nav_host_fragment).navigate(R.id.playerFragment)
return
}
val query = intent.getStringExtra(SearchManager.QUERY)
if (query != null) { if (query != null) {
val autoPlay = intent.action == MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH val autoPlay = intent.action == MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH

View File

@ -13,7 +13,7 @@ import org.moire.ultrasonic.di.featureFlagsModule
import org.moire.ultrasonic.di.mediaPlayerModule import org.moire.ultrasonic.di.mediaPlayerModule
import org.moire.ultrasonic.di.musicServiceModule import org.moire.ultrasonic.di.musicServiceModule
import org.moire.ultrasonic.log.FileLoggerTree import org.moire.ultrasonic.log.FileLoggerTree
import org.moire.ultrasonic.log.timberLogger import org.moire.ultrasonic.log.TimberKoinLogger
import org.moire.ultrasonic.util.Util import org.moire.ultrasonic.util.Util
import timber.log.Timber import timber.log.Timber
import timber.log.Timber.DebugTree import timber.log.Timber.DebugTree
@ -30,8 +30,7 @@ class UApp : MultiDexApplication() {
} }
startKoin { startKoin {
// TODO Current version of Koin has a bug, which forces the usage of Level.ERROR logger(TimberKoinLogger(Level.INFO))
timberLogger(Level.ERROR)
// declare Android context // declare Android context
androidContext(this@UApp) androidContext(this@UApp)
// declare modules to use // declare modules to use

View File

@ -1,21 +1,10 @@
package org.moire.ultrasonic.log package org.moire.ultrasonic.log
import org.koin.core.KoinApplication
import org.koin.core.logger.Level import org.koin.core.logger.Level
import org.koin.core.logger.Logger import org.koin.core.logger.Logger
import org.koin.core.logger.MESSAGE import org.koin.core.logger.MESSAGE
import timber.log.Timber import timber.log.Timber
/**
* KoinApplication Extension to use Timber with Koin
*/
fun KoinApplication.timberLogger(
level: Level = Level.INFO
): KoinApplication {
koin._logger = TimberKoinLogger(level)
return this
}
/** /**
* Timber Logger implementation for Koin * Timber Logger implementation for Koin
*/ */

View File

@ -19,10 +19,10 @@
package org.moire.ultrasonic.service package org.moire.ultrasonic.service
import android.content.Context import android.content.Context
import org.koin.core.KoinComponent import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import org.koin.core.context.loadKoinModules import org.koin.core.context.loadKoinModules
import org.koin.core.context.unloadKoinModules import org.koin.core.context.unloadKoinModules
import org.koin.core.get
import org.koin.core.qualifier.named import org.koin.core.qualifier.named
import org.moire.ultrasonic.cache.Directories import org.moire.ultrasonic.cache.Directories
import org.moire.ultrasonic.data.ActiveServerProvider import org.moire.ultrasonic.data.ActiveServerProvider

View File

@ -107,7 +107,6 @@ class DownloadHandler(
@Throws(Throwable::class) @Throws(Throwable::class)
override fun doInBackground(): List<MusicDirectory.Entry> { override fun doInBackground(): List<MusicDirectory.Entry> {
// TODO: Handle swipe spinner here instead of the ProgressListener
val musicService = getMusicService(activity) val musicService = getMusicService(activity)
val songs: MutableList<MusicDirectory.Entry> = LinkedList() val songs: MutableList<MusicDirectory.Entry> = LinkedList()
val root: MusicDirectory val root: MusicDirectory