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) {
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,35 +168,35 @@ 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) {
|
||||||
Playable media = controller.getMedia();
|
Log.w(TAG, "loadMediaInfo was called while PlaybackController was null!");
|
||||||
if (media != null) {
|
return false;
|
||||||
txtvTitle.setText(media.getEpisodeTitle());
|
}
|
||||||
mFeedName.setText(media.getFeedTitle());
|
|
||||||
onPositionObserverUpdate();
|
|
||||||
|
|
||||||
Glide.with(getActivity())
|
Playable media = controller.getMedia();
|
||||||
.load(media.getImageLocation())
|
if (media != null) {
|
||||||
.placeholder(R.color.light_gray)
|
txtvTitle.setText(media.getEpisodeTitle());
|
||||||
.error(R.color.light_gray)
|
mFeedName.setText(media.getFeedTitle());
|
||||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
onPositionObserverUpdate();
|
||||||
.fitCenter()
|
|
||||||
.dontAnimate()
|
|
||||||
.into(imgvCover);
|
|
||||||
|
|
||||||
fragmentLayout.setVisibility(View.VISIBLE);
|
Glide.with(getActivity())
|
||||||
if (controller.isPlayingVideoLocally()) {
|
.load(media.getImageLocation())
|
||||||
butPlay.setVisibility(View.GONE);
|
.placeholder(R.color.light_gray)
|
||||||
} else {
|
.error(R.color.light_gray)
|
||||||
butPlay.setVisibility(View.VISIBLE);
|
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||||
}
|
.fitCenter()
|
||||||
return true;
|
.dontAnimate()
|
||||||
|
.into(imgvCover);
|
||||||
|
|
||||||
|
fragmentLayout.setVisibility(View.VISIBLE);
|
||||||
|
if (controller.isPlayingVideoLocally()) {
|
||||||
|
butPlay.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "loadMediaInfo was called while the media object of playbackService was null!");
|
butPlay.setVisibility(View.VISIBLE);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
} else {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
|
@ -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,42 +151,43 @@ 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)) {
|
||||||
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 {
|
|
||||||
Log.d(TAG, "Ignoring request to refresh all feeds: Refresh lock is locked");
|
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.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) {
|
||||||
|
@ -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,25 +213,26 @@ 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) {
|
||||||
Intent serviceIntent = new Intent(activity, PlaybackService.class);
|
Log.d(TAG, "No last played media found");
|
||||||
serviceIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, media);
|
return null;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
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…
x
Reference in New Issue
Block a user