[Android] Fix AB repeat for audio player

Geoffrey Métais git at videolan.org
Thu Dec 20 15:35:42 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec 20 15:32:47 2018 +0100| [dd007f46a256a3597ea459a46643e71e7fedd97e] | committer: Geoffrey Métais

Fix AB repeat for audio player

And show "Save playslit" in video player
Fix #702

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

 vlc-android/res/layout-land/audio_player.xml              | 15 ---------------
 vlc-android/res/layout/audio_player.xml                   | 15 ---------------
 vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt | 12 +-----------
 .../org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt |  7 ++++---
 4 files changed, 5 insertions(+), 44 deletions(-)

diff --git a/vlc-android/res/layout-land/audio_player.xml b/vlc-android/res/layout-land/audio_player.xml
index c2d1f50f4..18b18ff49 100644
--- a/vlc-android/res/layout-land/audio_player.xml
+++ b/vlc-android/res/layout-land/audio_player.xml
@@ -98,21 +98,6 @@
                     android:imeOptions="actionSearch"/>
             </com.google.android.material.textfield.TextInputLayout>
 
-            <ImageView
-                android:id="@+id/playlist_ab_repeat"
-                android:layout_width="32dp"
-                android:layout_height="32dp"
-                android:layout_gravity="center"
-                app:layout_constraintEnd_toStartOf="@+id/playlist_search"
-                app:layout_constraintTop_toTopOf="parent"
-                app:layout_constraintBottom_toBottomOf="parent"
-                android:layout_marginEnd="8dp"
-                android:focusable="true"
-                android:scaleType="fitXY"
-                android:onClick="@{fragment::onABRepeat}"
-                android:contentDescription="@string/ab_repeat"
-                android:src="?attr/ic_repeat" />
-
             <ImageView
                 android:id="@+id/playlist_search"
                 android:layout_width="32dp"
diff --git a/vlc-android/res/layout/audio_player.xml b/vlc-android/res/layout/audio_player.xml
index b04d8fa56..c89ac6f34 100644
--- a/vlc-android/res/layout/audio_player.xml
+++ b/vlc-android/res/layout/audio_player.xml
@@ -97,21 +97,6 @@
                     android:imeOptions="actionSearch"/>
             </com.google.android.material.textfield.TextInputLayout>
 
-            <ImageView
-                android:id="@+id/playlist_ab_repeat"
-                android:layout_width="32dp"
-                android:layout_height="32dp"
-                android:layout_gravity="center"
-                app:layout_constraintEnd_toStartOf="@+id/playlist_search"
-                app:layout_constraintTop_toTopOf="parent"
-                app:layout_constraintBottom_toBottomOf="parent"
-                android:layout_marginEnd="8dp"
-                android:focusable="true"
-                android:scaleType="fitXY"
-                android:onClick="@{fragment::onABRepeat}"
-                android:contentDescription="@string/ab_repeat"
-                android:src="?attr/ic_repeat" />
-
             <ImageView
                 android:id="@+id/playlist_search"
                 android:layout_width="32dp"
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index b791b9634..522f6331b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -70,7 +70,6 @@ import org.videolan.vlc.gui.helpers.SwipeDragItemTouchHelperCallback
 import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.gui.video.VideoPlayerActivity
 import org.videolan.vlc.gui.view.AudioMediaSwitcher.AudioMediaSwitcherListener
-import org.videolan.vlc.media.ABRepeat
 import org.videolan.vlc.media.PlaylistManager.Companion.hasMedia
 import org.videolan.vlc.util.*
 import org.videolan.vlc.viewmodels.PlaybackProgress
@@ -117,7 +116,6 @@ class AudioPlayer : androidx.fragment.app.Fragment(), PlaylistAdapter.IPlayer, T
         playlistModel = PlaylistModel.get(this)
         playlistModel.progress.observe(this at AudioPlayer,  Observer { it?.let { updateProgress(it) } })
         playlistModel.dataset.observe(this at AudioPlayer, playlistObserver)
-        playlistModel.abRepeat?.observe(this, abRepeatObserver)
         helper = PlaybackServiceActivity.Helper(activity, playlistModel)
         playlistAdapter.setModel(playlistModel)
     }
@@ -455,14 +453,6 @@ class AudioPlayer : androidx.fragment.app.Fragment(), PlaylistAdapter.IPlayer, T
 
     override fun afterTextChanged(editable: Editable) {}
 
-    private val abRepeatObserver = Observer<ABRepeat> { abr ->
-        if (abr != null) binding.playlistAbRepeat.setImageResource(when {
-            abr.start == -1L -> R.drawable.ic_repeat
-            abr.stop == -1L -> R.drawable.ic_repeat_one
-            else -> R.drawable.ic_repeat_all
-        })
-    }
-
     private val playlistObserver = Observer<MutableList<MediaWrapper>> {
         playlistAdapter.update(it!!)
         updateActor.offer(Unit)
@@ -470,7 +460,7 @@ class AudioPlayer : androidx.fragment.app.Fragment(), PlaylistAdapter.IPlayer, T
 
     override fun onDestroy() {
         super.onDestroy()
-        playlistModel.abRepeat.removeObserver(abRepeatObserver)
+        optionsDelegate.release()
         playlistModel.dataset.removeObserver(playlistObserver)
         playlistModel.onCleared()
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
index 2271ea055..11910f54c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
@@ -85,6 +85,7 @@ class PlayerOptionsDelegate(val activity: AppCompatActivity, val service: Playba
 
     fun setup() {
         if (!this::recyclerview.isInitialized) return
+        service.playlistManager.abRepeat.observe(activity, abrObs)
         val options = mutableListOf<PlayerOption>()
         options.add(PlayerOption(ID_SLEEP, R.attr.ic_sleep_normal_style, res.getString(R.string.sleep_title)))
         options.add(PlayerOption(ID_PLAYBACK_SPEED, R.attr.ic_speed_normal_style, res.getString(R.string.playback_speed)))
@@ -99,11 +100,11 @@ class PlayerOptionsDelegate(val activity: AppCompatActivity, val service: Playba
                 options.add(PlayerOption(ID_POPUP_VIDEO, R.attr.ic_popup_dim, res.getString(R.string.ctx_pip_title)))
             options.add(PlayerOption(ID_REPEAT, R.attr.ic_repeat, res.getString(R.string.repeat_title)))
             if (service.canShuffle()) options.add(PlayerOption(ID_SHUFFLE, R.attr.ic_shuffle, res.getString(R.string.shuffle_title)))
-            options.add(PlayerOption(ID_ABREPEAT, R.attr.ic_abrepeat, res.getString(R.string.ab_repeat)))
-            service.playlistManager.abRepeat.observe(activity, abrObs)
             val chaptersCount = service.getChapters(-1)?.size ?: 0
             if (chaptersCount > 1) options.add(PlayerOption(ID_CHAPTER_TITLE, R.attr.ic_chapter_normal_style, res.getString(R.string.go_to_chapter)))
-        } else options.add(PlayerOption(ID_SAVE_PLAYLIST, R.attr.ic_save, res.getString(R.string.playlist_save)))
+        }
+        options.add(PlayerOption(ID_ABREPEAT, R.attr.ic_abrepeat, res.getString(R.string.ab_repeat)))
+        options.add(PlayerOption(ID_SAVE_PLAYLIST, R.attr.ic_save, res.getString(R.string.playlist_save)))
         if (service.playlistManager.player.canDoPassthrough() && settings.getString("aout", "0") == "0")
         options.add(PlayerOption(ID_PASSTHROUGH, R.attr.ic_passthrough, res.getString(R.string.audio_digital_title)))
         (recyclerview.adapter as OptionsAdapter).update(options)



More information about the Android mailing list