Code style improvements

This commit is contained in:
ByteHamster 2018-05-06 19:15:40 +02:00
parent 22f791e05f
commit cb70aeb3cf
7 changed files with 87 additions and 87 deletions

View File

@ -619,12 +619,11 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
public void onEventMainThread(ServiceEvent event) { public void onEventMainThread(ServiceEvent event) {
Log.d(TAG, "onEvent(" + event + ")"); Log.d(TAG, "onEvent(" + event + ")");
switch(event.action) { if (event.action == ServiceEvent.Action.SERVICE_STARTED) {
case SERVICE_STARTED:
if (controller != null) { if (controller != null) {
controller.init(); controller.init();
} }
break;
} }
} }

View File

@ -80,15 +80,13 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
Toast.makeText(context, R.string.download_canceled_msg, Toast.LENGTH_LONG).show(); Toast.makeText(context, R.string.download_canceled_msg, Toast.LENGTH_LONG).show();
} }
} else { // media is downloaded } else { // media is downloaded
if (item.hasMedia() && item.getMedia().isCurrentlyPlaying()) { if (media.isCurrentlyPlaying()) {
PlaybackService.startIfNotRunning(context, media, true, false); PlaybackService.startIfNotRunning(context, media, true, false);
context.sendBroadcast(new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE)); context.sendBroadcast(new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
} } else if (media.isCurrentlyPaused()) {
else if (item.hasMedia() && item.getMedia().isCurrentlyPaused()) {
PlaybackService.startIfNotRunning(context, media, true, false); PlaybackService.startIfNotRunning(context, media, true, false);
context.sendBroadcast(new Intent(PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE)); context.sendBroadcast(new Intent(PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE));
} } else {
else {
DBTasks.playMedia(context, media, false, true, false); DBTasks.playMedia(context, media, false, true, false);
} }
} }

View File

@ -168,7 +168,11 @@ public class ExternalPlayerFragment extends Fragment {
private boolean loadMediaInfo() { private boolean loadMediaInfo() {
Log.d(TAG, "Loading media info"); Log.d(TAG, "Loading media info");
if (controller != null) { if (controller == null) {
Log.w(TAG, "loadMediaInfo was called while PlaybackController was null!");
return false;
}
Playable media = controller.getMedia(); Playable media = controller.getMedia();
if (media != null) { if (media != null) {
txtvTitle.setText(media.getEpisodeTitle()); txtvTitle.setText(media.getEpisodeTitle());
@ -195,10 +199,6 @@ public class ExternalPlayerFragment extends Fragment {
Log.w(TAG, "loadMediaInfo was called while the media object of playbackService was null!"); Log.w(TAG, "loadMediaInfo was called while the media object of playbackService was null!");
return false; return false;
} }
} else {
Log.w(TAG, "loadMediaInfo was called while playbackService was null!");
return false;
}
} }
private String getPositionString(int position, int duration) { private String getPositionString(int position, int duration) {

View File

@ -31,9 +31,6 @@ public class PlayerWidgetJobService extends JobIntentService {
private PlaybackService playbackService; private PlaybackService playbackService;
private final Object waitForService = new Object(); private final Object waitForService = new Object();
public PlayerWidgetJobService() {
}
public static void updateWidget(Context context) { public static void updateWidget(Context context) {
enqueueWork(context, PlayerWidgetJobService.class, 0, new Intent(context, PlayerWidgetJobService.class)); enqueueWork(context, PlayerWidgetJobService.class, 0, new Intent(context, PlayerWidgetJobService.class));
} }

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.util.Log; import android.util.Log;
@ -150,10 +151,14 @@ public final class DBTasks {
* *
* @param context Might be used for accessing the database * @param context Might be used for accessing the database
* @param feeds List of Feeds that should be refreshed. * @param feeds List of Feeds that should be refreshed.
* @param callback Called after everything was added enqueued for download * @param callback Called after everything was added enqueued for download. Might be null.
*/ */
public static void refreshAllFeeds(final Context context, final List<Feed> feeds, Runnable callback) { public static void refreshAllFeeds(final Context context, final List<Feed> feeds, @Nullable Runnable callback) {
if (isRefreshing.compareAndSet(false, true)) { if (!isRefreshing.compareAndSet(false, true)) {
Log.d(TAG, "Ignoring request to refresh all feeds: Refresh lock is locked");
return;
}
new Thread(() -> { new Thread(() -> {
if (feeds != null) { if (feeds != null) {
refreshFeeds(context, feeds); refreshFeeds(context, feeds);
@ -183,9 +188,6 @@ public final class DBTasks {
callback.run(); callback.run();
} }
}).start(); }).start();
} else {
Log.d(TAG, "Ignoring request to refresh all feeds: Refresh lock is locked");
}
} }
/** /**

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Parcelable; import android.os.Parcelable;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
import java.util.List; import java.util.List;
@ -183,6 +184,7 @@ public interface Playable extends Parcelable,
* *
* @return The restored Playable object * @return The restored Playable object
*/ */
@Nullable
public static Playable createInstanceFromPreferences(Context context) { public static Playable createInstanceFromPreferences(Context context) {
long currentlyPlayingMedia = PlaybackPreferences.getCurrentlyPlayingMedia(); long currentlyPlayingMedia = PlaybackPreferences.getCurrentlyPlayingMedia();
if (currentlyPlayingMedia != PlaybackPreferences.NO_MEDIA_PLAYING) { if (currentlyPlayingMedia != PlaybackPreferences.NO_MEDIA_PLAYING) {

View File

@ -14,6 +14,7 @@ import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@ -212,10 +213,14 @@ public abstract class PlaybackController {
* Returns an intent that starts the PlaybackService and plays the last * Returns an intent that starts the PlaybackService and plays the last
* played media or null if no last played media could be found. * played media or null if no last played media could be found.
*/ */
private Intent getPlayLastPlayedMediaIntent() { @Nullable private Intent getPlayLastPlayedMediaIntent() {
Log.d(TAG, "Trying to restore last played media"); Log.d(TAG, "Trying to restore last played media");
Playable media = PlayableUtils.createInstanceFromPreferences(activity); Playable media = PlayableUtils.createInstanceFromPreferences(activity);
if (media != null) { if (media == null) {
Log.d(TAG, "No last played media found");
return null;
}
Intent serviceIntent = new Intent(activity, PlaybackService.class); Intent serviceIntent = new Intent(activity, PlaybackService.class);
serviceIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, media); serviceIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, media);
serviceIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED, false); serviceIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED, false);
@ -229,9 +234,6 @@ public abstract class PlaybackController {
lastIsStream || !fileExists); lastIsStream || !fileExists);
return serviceIntent; return serviceIntent;
} }
Log.d(TAG, "No last played media found");
return null;
}