[Android] Clean code for popup manager

Geoffrey Métais git at videolan.org
Tue Jul 11 11:13:24 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jul 11 09:42:20 2017 +0200| [1b4897b0ce654d3c35da3e3033058e0075cfd080] | committer: Geoffrey Métais

Clean code for popup manager

> https://code.videolan.org/videolan/vlc-android/commit/1b4897b0ce654d3c35da3e3033058e0075cfd080
---

 .../org/videolan/vlc/gui/video/PopupManager.java   | 32 ++++++++--------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.java b/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.java
index 733f53828..f5965a593 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.java
@@ -24,12 +24,9 @@
 
 package org.videolan.vlc.gui.video;
 
-import android.app.Notification;
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
-import android.content.SharedPreferences;
-import android.net.Uri;
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Message;
@@ -258,8 +255,7 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
         switch (v.getId()) {
             case R.id.video_play_pause:
                 if (mService.hasMedia()) {
-                    boolean isPLaying = mService.isPlaying();
-                    if (isPLaying)
+                    if (mService.isPlaying())
                         mService.pause();
                     else
                         mService.play();
@@ -277,19 +273,16 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
 
     private void stopPlayback() {
         long time = mService.getTime();
-        long length = mService.getLength();
-        Uri uri = mService.getCurrentMediaWrapper().getUri();
-        //remove saved position if in the last 5 seconds
-        if (length - time < 5000)
-            time = 0;
-        else
-            time -= 2000; // go back 2 seconds, to compensate loading time
+        if (time != -1) {
+            // remove saved position if in the last 5 seconds
+            // else, go back 2 seconds, to compensate loading time
+            time = mService.getLength() - time < 5000 ? 0 :  2000;
+            // Save position
+            if (mService.isSeekable())
+                PreferenceManager.getDefaultSharedPreferences(mService).edit()
+                        .putLong(PreferencesActivity.VIDEO_RESUME_TIME, time).apply();
+        }
         mService.stop();
-
-        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(mService).edit();
-        // Save position
-        if (mService.isSeekable() && time != -1)
-            editor.putLong(PreferencesActivity.VIDEO_RESUME_TIME, time).apply();
     }
 
     private void showNotification() {
@@ -316,10 +309,9 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
             builder.addAction(R.drawable.ic_popup_play, mService.getString(R.string.play), piPlay);
         builder.addAction(R.drawable.ic_popup_expand_w, mService.getString(R.string.popup_expand), piExpand);
 
-        Notification notification = builder.build();
         try {
-            NotificationManagerCompat.from(mService).notify(42, notification);
-        } catch (IllegalArgumentException e) {}
+            NotificationManagerCompat.from(mService).notify(42, builder.build());
+        } catch (IllegalArgumentException ignored) {}
     }
 
     private void hideNotification() {



More information about the Android mailing list