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",
semver : "1.0.0",
twitterSerial : "0.1.6",
koin : "2.1.6",
koin : "2.2.2",
picasso : "2.71828",
junit4 : "4.12",

View File

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

View File

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

View File

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

View File

@ -40,6 +40,8 @@ public class UltrasonicAppWidgetProvider extends AppWidgetProvider
final Resources res = context.getResources();
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));
linkButtons(context, views, false);
@ -183,8 +185,10 @@ public class UltrasonicAppWidgetProvider extends AppWidgetProvider
*/
private static void linkButtons(Context context, RemoteViews views, boolean playerActive)
{
// TODO: If playerActive = true, display the PlayerFragment automatically
Intent intent = new Intent(context, playerActive ? NavigationActivity.class : NavigationActivity.class);
Intent intent = new Intent(context, NavigationActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);;
if (playerActive)
intent.putExtra(Constants.INTENT_EXTRA_NAME_SHOW_PLAYER, true);
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
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.UltrasonicAppWidgetProvider4X3;
import org.moire.ultrasonic.provider.UltrasonicAppWidgetProvider4X4;
import org.moire.ultrasonic.util.Constants;
import org.moire.ultrasonic.util.FileUtil;
import org.moire.ultrasonic.util.NowPlayingEventDistributor;
import org.moire.ultrasonic.util.ShufflePlayBuffer;
@ -637,9 +638,10 @@ public class MediaPlayerService extends Service
notificationBuilder.setContent(contentView);
// TODO: Navigate automatically to PlayerFragment
Intent notificationIntent = new Intent(this, NavigationActivity.class);
notificationBuilder.setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0));
Intent notificationIntent = new Intent(this, NavigationActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
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) {
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_SHUFFLE = "subsonic.shuffle";
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_RANDOM = "subsonic.random";
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_VIDEOS = "subsonic.videos";
public static final String INTENT_EXTRA_NAME_SHOW_PLAYER = "subsonic.showplayer";
// Names for Intent Actions
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>
{
private final Activity tabActivity;
private final boolean cancellable;
private boolean cancelled;
private SwipeRefreshLayout swipe;
private final SwipeRefreshLayout swipe;
private final CancellationToken cancel;
public LoadingTask(Activity activity, final boolean cancellable, SwipeRefreshLayout swipe)
public LoadingTask(Activity activity, SwipeRefreshLayout swipe, CancellationToken cancel)
{
super(activity);
tabActivity = activity;
this.cancellable = cancellable;
this.swipe = swipe;
this.cancel = cancel;
}
@Override
@ -37,7 +34,7 @@ public abstract class LoadingTask<T> extends BackgroundTask<T>
try
{
final T result = doInBackground();
if (isCancelled())
if (cancel.isCancellationRequested())
{
return;
}
@ -54,7 +51,7 @@ public abstract class LoadingTask<T> extends BackgroundTask<T>
}
catch (final Throwable t)
{
if (isCancelled())
if (cancel.isCancellationRequested())
{
return;
}
@ -73,24 +70,8 @@ public abstract class LoadingTask<T> extends BackgroundTask<T>
}.start();
}
@SuppressLint("NewApi")
private boolean isCancelled()
{
// TODO: Implement cancelled
//return Build.VERSION.SDK_INT >= 17 ? tabActivity.isDestroyed() || cancelled : cancelled;
return cancelled;
}
@Override
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
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)
{
// TODO: Navigate automatically to PlayerFragment if playerActive = true
Intent intent = new Intent(context, playerActive ? NavigationActivity.class : NavigationActivity.class);
Intent intent = new Intent(context, NavigationActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
if (playerActive)
intent.putExtra(Constants.INTENT_EXTRA_NAME_SHOW_PLAYER, true);
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
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
override fun onNewIntent(intent: 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) {
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.musicServiceModule
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 timber.log.Timber
import timber.log.Timber.DebugTree
@ -30,8 +30,7 @@ class UApp : MultiDexApplication() {
}
startKoin {
// TODO Current version of Koin has a bug, which forces the usage of Level.ERROR
timberLogger(Level.ERROR)
logger(TimberKoinLogger(Level.INFO))
// declare Android context
androidContext(this@UApp)
// declare modules to use

View File

@ -1,21 +1,10 @@
package org.moire.ultrasonic.log
import org.koin.core.KoinApplication
import org.koin.core.logger.Level
import org.koin.core.logger.Logger
import org.koin.core.logger.MESSAGE
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
*/

View File

@ -19,10 +19,10 @@
package org.moire.ultrasonic.service
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.unloadKoinModules
import org.koin.core.get
import org.koin.core.qualifier.named
import org.moire.ultrasonic.cache.Directories
import org.moire.ultrasonic.data.ActiveServerProvider

View File

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