[Android] Stop inflating audio player on activity destroyed

Geoffrey Métais git at videolan.org
Tue Feb 5 11:25:58 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb  5 10:16:27 2019 +0100| [c0405b5b4a81286aafe6fc984b70faa5ee740c1d] | committer: Geoffrey Métais

Stop inflating audio player on activity destroyed

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

 .../vlc/gui/AudioPlayerContainerActivity.java      | 30 ++++++++++------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
index f014e0838..333ce5536 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
@@ -65,7 +65,6 @@ import androidx.annotation.Nullable;
 import androidx.appcompat.widget.Toolbar;
 import androidx.appcompat.widget.ViewStubCompat;
 import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import androidx.core.view.ViewCompat;
 import androidx.fragment.app.Fragment;
 import androidx.fragment.app.FragmentManager;
 import androidx.lifecycle.Observer;
@@ -118,19 +117,8 @@ public class AudioPlayerContainerActivity extends BaseActivity {
         mTabLayout.setVisibility( show ? View.VISIBLE : View.GONE);
     }
 
-    private float elevation = 0f;
-    public void toggleAppBarElevation(final boolean elevate) {
-        if (!AndroidUtil.isLolliPopOrLater) return;
-        if (elevation == 0f) elevation = getResources().getDimensionPixelSize(R.dimen.default_appbar_elevation);
-        mAppBarLayout.post(new Runnable() {
-            @Override
-            public void run() {
-                ViewCompat.setElevation(mAppBarLayout, elevate ? elevation : 0f);
-            }
-        });
-    }
-
     private void initAudioPlayer() {
+        if (isFinishing()) return;
         findViewById(R.id.audio_player_stub).setVisibility(View.VISIBLE);
         mAudioPlayer = (AudioPlayer) getSupportFragmentManager().findFragmentById(R.id.audio_player);
         mBottomSheetBehavior = (BottomSheetBehavior) BottomSheetBehavior.from(mAudioPlayerContainer);
@@ -161,6 +149,12 @@ public class AudioPlayerContainerActivity extends BaseActivity {
         ExternalMonitor.INSTANCE.unsubscribeStorageCb(this);
     }
 
+    @Override
+    protected void onDestroy() {
+        mActivityHandler.removeMessages(ACTION_SHOW_PLAYER);
+        super.onDestroy();
+    }
+
     @Override
     public void onBackPressed() {
         if (slideDownAudioPlayer()) return;
@@ -251,11 +245,13 @@ public class AudioPlayerContainerActivity extends BaseActivity {
         if (mAudioPlayerContainer.getVisibility() != View.VISIBLE) {
             mAudioPlayerContainer.setVisibility(View.VISIBLE);
         }
-        if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
-            mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
+        if (mBottomSheetBehavior != null) {
+            if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
+                mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
+            }
+            mBottomSheetBehavior.setHideable(false);
+            mBottomSheetBehavior.lock(false);
         }
-        mBottomSheetBehavior.setHideable(false);
-        mBottomSheetBehavior.lock(false);
     }
 
     /**



More information about the Android mailing list