[Android] Fix crash when changing video display in SecondaryActivity

Nicolas Pomepuy git at videolan.org
Wed Sep 25 16:28:51 CEST 2019


vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Wed Sep 25 07:07:59 2019 +0200| [66f5f8e38801b473900fb3aa30edeb2c0ed1b382] | committer: Geoffrey Métais

Fix crash when changing video display in SecondaryActivity

(cherry picked from commit 11fd6f1022411febdeb80a7e701251e6dfc80dc1)

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

 vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt      |  4 ++++
 vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt    | 12 ++++++++++++
 .../src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt |  6 +++---
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.kt      |  7 +++++++
 4 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt b/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt
index 3b1eeb033..e5005ccb6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/ContentActivity.kt
@@ -160,6 +160,10 @@ open class ContentActivity : AudioPlayerContainerActivity(), SearchView.OnQueryT
 
     override fun onQueryTextSubmit(query: String) = false
 
+    open fun forceLoadVideoFragment() {
+        throw NotImplementedError("forceLoadVideoFragment not implemented")
+    }
+
     private fun openSearchActivity() {
         startActivity(Intent(Intent.ACTION_SEARCH, null, this, SearchActivity::class.java)
                 .putExtra(SearchManager.QUERY, searchView.query.toString()))
diff --git a/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt b/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt
index 79d627364..250e601de 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt
@@ -83,6 +83,18 @@ class SecondaryActivity : ContentActivity() {
         }
     }
 
+    override fun forceLoadVideoFragment() {
+        val fragmentId = intent.getStringExtra(KEY_FRAGMENT)
+        fetchSecondaryFragment(fragmentId)
+        if (fragment == null) {
+            finish()
+            return
+        }
+        supportFragmentManager.beginTransaction()
+                .replace(R.id.fragment_placeholder, fragment!!)
+                .commit()
+    }
+
     override fun onResume() {
         overridePendingTransition(0, 0)
         super.onResume()
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
index 300fb5564..684e8b015 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
@@ -287,17 +287,17 @@ abstract class MediaBrowserFragment<T : SortableModel> : Fragment(), ActionMode.
             }
             R.id.video_min_group_length_disable -> {
                 Settings.getInstance(requireActivity()).edit().putString("video_min_group_length", "-1").apply()
-                (activity as MainActivity).forceLoadVideoFragment()
+                (activity as ContentActivity).forceLoadVideoFragment()
                 return true
             }
             R.id.video_min_group_length_folder -> {
                 Settings.getInstance(requireActivity()).edit().putString("video_min_group_length", "0").apply()
-                (activity as MainActivity).forceLoadVideoFragment()
+                (activity as ContentActivity).forceLoadVideoFragment()
                 return true
             }
             R.id.video_min_group_length_name -> {
                 Settings.getInstance(requireActivity()).edit().putString("video_min_group_length", "6").apply()
-                (activity as MainActivity).forceLoadVideoFragment()
+                (activity as ContentActivity).forceLoadVideoFragment()
                 return true
             }
             else -> return super.onOptionsItemSelected(item)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
index 43214a2ee..36ba5352e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -46,6 +46,7 @@ import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.tools.MultiSelectHelper
 import org.videolan.vlc.R
 import org.videolan.vlc.databinding.VideoGridBinding
+import org.videolan.vlc.gui.ContentActivity
 import org.videolan.vlc.gui.MainActivity
 import org.videolan.vlc.gui.SecondaryActivity
 import org.videolan.vlc.gui.browser.MediaBrowserFragment
@@ -133,6 +134,12 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
                 MediaUtils.loadlastPlaylist(activity, PLAYLIST_TYPE_VIDEO)
                 true
             }
+            R.id.ml_menu_display_list, R.id.ml_menu_display_grid -> {
+                val displayInCards = Settings.getInstance(requireActivity()).getBoolean("video_display_in_cards", true)
+                Settings.getInstance(requireActivity()).edit().putBoolean("video_display_in_cards", !displayInCards).apply()
+                (activity as ContentActivity).forceLoadVideoFragment()
+                true
+            }
             else -> super.onOptionsItemSelected(item)
         }
     }



More information about the Android mailing list