Code style improvements
This commit is contained in:
parent
22f791e05f
commit
cb70aeb3cf
|
@ -619,12 +619,11 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
|
||||
public void onEventMainThread(ServiceEvent event) {
|
||||
Log.d(TAG, "onEvent(" + event + ")");
|
||||
switch(event.action) {
|
||||
case SERVICE_STARTED:
|
||||
if (controller != null) {
|
||||
controller.init();
|
||||
}
|
||||
break;
|
||||
if (event.action == ServiceEvent.Action.SERVICE_STARTED) {
|
||||
if (controller != null) {
|
||||
controller.init();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,15 +80,13 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
|
|||
Toast.makeText(context, R.string.download_canceled_msg, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else { // media is downloaded
|
||||
if (item.hasMedia() && item.getMedia().isCurrentlyPlaying()) {
|
||||
if (media.isCurrentlyPlaying()) {
|
||||
PlaybackService.startIfNotRunning(context, media, true, false);
|
||||
context.sendBroadcast(new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
|
||||
}
|
||||
else if (item.hasMedia() && item.getMedia().isCurrentlyPaused()) {
|
||||
} else if (media.isCurrentlyPaused()) {
|
||||
PlaybackService.startIfNotRunning(context, media, true, false);
|
||||
context.sendBroadcast(new Intent(PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
DBTasks.playMedia(context, media, false, true, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,35 +168,35 @@ public class ExternalPlayerFragment extends Fragment {
|
|||
|
||||
private boolean loadMediaInfo() {
|
||||
Log.d(TAG, "Loading media info");
|
||||
if (controller != null) {
|
||||
Playable media = controller.getMedia();
|
||||
if (media != null) {
|
||||
txtvTitle.setText(media.getEpisodeTitle());
|
||||
mFeedName.setText(media.getFeedTitle());
|
||||
onPositionObserverUpdate();
|
||||
if (controller == null) {
|
||||
Log.w(TAG, "loadMediaInfo was called while PlaybackController was null!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Glide.with(getActivity())
|
||||
.load(media.getImageLocation())
|
||||
.placeholder(R.color.light_gray)
|
||||
.error(R.color.light_gray)
|
||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||
.fitCenter()
|
||||
.dontAnimate()
|
||||
.into(imgvCover);
|
||||
Playable media = controller.getMedia();
|
||||
if (media != null) {
|
||||
txtvTitle.setText(media.getEpisodeTitle());
|
||||
mFeedName.setText(media.getFeedTitle());
|
||||
onPositionObserverUpdate();
|
||||
|
||||
fragmentLayout.setVisibility(View.VISIBLE);
|
||||
if (controller.isPlayingVideoLocally()) {
|
||||
butPlay.setVisibility(View.GONE);
|
||||
} else {
|
||||
butPlay.setVisibility(View.VISIBLE);
|
||||
}
|
||||
return true;
|
||||
Glide.with(getActivity())
|
||||
.load(media.getImageLocation())
|
||||
.placeholder(R.color.light_gray)
|
||||
.error(R.color.light_gray)
|
||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||
.fitCenter()
|
||||
.dontAnimate()
|
||||
.into(imgvCover);
|
||||
|
||||
fragmentLayout.setVisibility(View.VISIBLE);
|
||||
if (controller.isPlayingVideoLocally()) {
|
||||
butPlay.setVisibility(View.GONE);
|
||||
} else {
|
||||
Log.w(TAG, "loadMediaInfo was called while the media object of playbackService was null!");
|
||||
return false;
|
||||
butPlay.setVisibility(View.VISIBLE);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
Log.w(TAG, "loadMediaInfo was called while playbackService was null!");
|
||||
Log.w(TAG, "loadMediaInfo was called while the media object of playbackService was null!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,6 @@ public class PlayerWidgetJobService extends JobIntentService {
|
|||
private PlaybackService playbackService;
|
||||
private final Object waitForService = new Object();
|
||||
|
||||
public PlayerWidgetJobService() {
|
||||
}
|
||||
|
||||
public static void updateWidget(Context context) {
|
||||
enqueueWork(context, PlayerWidgetJobService.class, 0, new Intent(context, PlayerWidgetJobService.class));
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
|
||||
|
@ -150,42 +151,43 @@ public final class DBTasks {
|
|||
*
|
||||
* @param context Might be used for accessing the database
|
||||
* @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) {
|
||||
if (isRefreshing.compareAndSet(false, true)) {
|
||||
new Thread(() -> {
|
||||
if (feeds != null) {
|
||||
refreshFeeds(context, feeds);
|
||||
} else {
|
||||
refreshFeeds(context, DBReader.getFeedList());
|
||||
}
|
||||
isRefreshing.set(false);
|
||||
|
||||
SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, MODE_PRIVATE);
|
||||
prefs.edit().putLong(PREF_LAST_REFRESH, System.currentTimeMillis()).apply();
|
||||
|
||||
if (FlattrUtils.hasToken()) {
|
||||
Log.d(TAG, "Flattring all pending things.");
|
||||
new FlattrClickWorker(context).executeAsync(); // flattr pending things
|
||||
|
||||
Log.d(TAG, "Fetching flattr status.");
|
||||
new FlattrStatusFetcher(context).start();
|
||||
|
||||
}
|
||||
if (ClientConfig.gpodnetCallbacks.gpodnetEnabled()) {
|
||||
GpodnetSyncService.sendSyncIntent(context);
|
||||
}
|
||||
Log.d(TAG, "refreshAllFeeds autodownload");
|
||||
autodownloadUndownloadedItems(context);
|
||||
|
||||
if (callback != null) {
|
||||
callback.run();
|
||||
}
|
||||
}).start();
|
||||
} else {
|
||||
public static void refreshAllFeeds(final Context context, final List<Feed> feeds, @Nullable Runnable callback) {
|
||||
if (!isRefreshing.compareAndSet(false, true)) {
|
||||
Log.d(TAG, "Ignoring request to refresh all feeds: Refresh lock is locked");
|
||||
return;
|
||||
}
|
||||
|
||||
new Thread(() -> {
|
||||
if (feeds != null) {
|
||||
refreshFeeds(context, feeds);
|
||||
} else {
|
||||
refreshFeeds(context, DBReader.getFeedList());
|
||||
}
|
||||
isRefreshing.set(false);
|
||||
|
||||
SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, MODE_PRIVATE);
|
||||
prefs.edit().putLong(PREF_LAST_REFRESH, System.currentTimeMillis()).apply();
|
||||
|
||||
if (FlattrUtils.hasToken()) {
|
||||
Log.d(TAG, "Flattring all pending things.");
|
||||
new FlattrClickWorker(context).executeAsync(); // flattr pending things
|
||||
|
||||
Log.d(TAG, "Fetching flattr status.");
|
||||
new FlattrStatusFetcher(context).start();
|
||||
|
||||
}
|
||||
if (ClientConfig.gpodnetCallbacks.gpodnetEnabled()) {
|
||||
GpodnetSyncService.sendSyncIntent(context);
|
||||
}
|
||||
Log.d(TAG, "refreshAllFeeds autodownload");
|
||||
autodownloadUndownloadedItems(context);
|
||||
|
||||
if (callback != null) {
|
||||
callback.run();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.os.Parcelable;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -183,6 +184,7 @@ public interface Playable extends Parcelable,
|
|||
*
|
||||
* @return The restored Playable object
|
||||
*/
|
||||
@Nullable
|
||||
public static Playable createInstanceFromPreferences(Context context) {
|
||||
long currentlyPlayingMedia = PlaybackPreferences.getCurrentlyPlayingMedia();
|
||||
if (currentlyPlayingMedia != PlaybackPreferences.NO_MEDIA_PLAYING) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.os.Build;
|
|||
import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
@ -212,25 +213,26 @@ public abstract class PlaybackController {
|
|||
* Returns an intent that starts the PlaybackService and plays the last
|
||||
* 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");
|
||||
Playable media = PlayableUtils.createInstanceFromPreferences(activity);
|
||||
if (media != null) {
|
||||
Intent serviceIntent = new Intent(activity, PlaybackService.class);
|
||||
serviceIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, media);
|
||||
serviceIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED, false);
|
||||
serviceIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY, true);
|
||||
boolean fileExists = media.localFileAvailable();
|
||||
boolean lastIsStream = PlaybackPreferences.getCurrentEpisodeIsStream();
|
||||
if (!fileExists && !lastIsStream && media instanceof FeedMedia) {
|
||||
DBTasks.notifyMissingFeedMediaFile(activity, (FeedMedia) media);
|
||||
}
|
||||
serviceIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM,
|
||||
lastIsStream || !fileExists);
|
||||
return serviceIntent;
|
||||
if (media == null) {
|
||||
Log.d(TAG, "No last played media found");
|
||||
return null;
|
||||
}
|
||||
Log.d(TAG, "No last played media found");
|
||||
return null;
|
||||
|
||||
Intent serviceIntent = new Intent(activity, PlaybackService.class);
|
||||
serviceIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, media);
|
||||
serviceIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED, false);
|
||||
serviceIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY, true);
|
||||
boolean fileExists = media.localFileAvailable();
|
||||
boolean lastIsStream = PlaybackPreferences.getCurrentEpisodeIsStream();
|
||||
if (!fileExists && !lastIsStream && media instanceof FeedMedia) {
|
||||
DBTasks.notifyMissingFeedMediaFile(activity, (FeedMedia) media);
|
||||
}
|
||||
serviceIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM,
|
||||
lastIsStream || !fileExists);
|
||||
return serviceIntent;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue