[Android] Use internal variable to manage pause/resume
Geoffrey Métais
git at videolan.org
Fri May 19 15:54:04 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri May 19 14:34:21 2017 +0200| [36542b1fdb8ac6317be4e4fe675b6b5354e4bcc5] | committer: Geoffrey Métais
Use internal variable to manage pause/resume
> https://code.videolan.org/videolan/vlc-android/commit/36542b1fdb8ac6317be4e4fe675b6b5354e4bcc5
---
.../src/org/videolan/vlc/MediaParsingService.java | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.java b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
index 1539bd1..b2033b1 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.java
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
@@ -66,26 +66,26 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
private final ThreadPoolExecutor mThreadPool = new ThreadPoolExecutor(1, 1, 30, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(), VLCApplication.THREAD_FACTORY);
+ boolean mScanPaused = false;
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
- boolean paused = false;
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case ACTION_PAUSE_SCAN:
if (mWakeLock.isHeld())
mWakeLock.release();
- paused = true;
+ mScanPaused = true;
mMedialibrary.pauseBackgroundOperations();
break;
case ACTION_RESUME_SCAN:
if (!mWakeLock.isHeld())
mWakeLock.acquire();
mMedialibrary.resumeBackgroundOperations();
- paused = false;
+ mScanPaused = false;
break;
case Medialibrary.ACTION_IDLE:
if (intent.getBooleanExtra(Medialibrary.STATE_IDLE, true)) {
- if (!paused) {
+ if (!mScanPaused) {
stopSelf();
return;
}
@@ -271,13 +271,12 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
String progressText = sb.toString();
builder.setContentText(progressText);
- boolean isWorking = mMedialibrary.isWorking();
- if (wasWorking != isWorking) {
- wasWorking = isWorking;
- notificationIntent.setAction(isWorking ? ACTION_PAUSE_SCAN : ACTION_RESUME_SCAN);
+ if (wasWorking != mMedialibrary.isWorking()) {
+ wasWorking = !wasWorking;
+ notificationIntent.setAction(mScanPaused ? ACTION_RESUME_SCAN : ACTION_PAUSE_SCAN);
PendingIntent pi = PendingIntent.getBroadcast(VLCApplication.getAppContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
- NotificationCompat.Action playpause = isWorking ? new NotificationCompat.Action(R.drawable.ic_pause, getString(R.string.pause), pi)
- : new NotificationCompat.Action(R.drawable.ic_play, getString(R.string.resume), pi);
+ NotificationCompat.Action playpause = mScanPaused ? new NotificationCompat.Action(R.drawable.ic_play, getString(R.string.resume), pi)
+ : new NotificationCompat.Action(R.drawable.ic_pause, getString(R.string.pause), pi);
builder.mActions.clear();
builder.addAction(playpause);
}
More information about the Android
mailing list