[Android] Audioplayer: code cleaning

Geoffrey Métais git at videolan.org
Wed Jul 4 14:05:45 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jul  4 11:10:48 2018 +0200| [d1923072f5a17b9e4da5b56123236bf17e4f4bff] | committer: Geoffrey Métais

Audioplayer: code cleaning

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

 .../src/org/videolan/vlc/gui/audio/AudioPlayer.kt  | 25 +++++++++++-----------
 1 file changed, 12 insertions(+), 13 deletions(-)

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 7b055b799..3d570ca92 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -54,6 +54,7 @@ import kotlinx.coroutines.experimental.async
 import kotlinx.coroutines.experimental.channels.Channel
 import kotlinx.coroutines.experimental.channels.actor
 import kotlinx.coroutines.experimental.launch
+import kotlinx.coroutines.experimental.withContext
 import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.medialibrary.Tools
 import org.videolan.medialibrary.media.MediaWrapper
@@ -72,6 +73,7 @@ import org.videolan.vlc.gui.video.VideoPlayerActivity
 import org.videolan.vlc.gui.view.AudioMediaSwitcher.AudioMediaSwitcherListener
 import org.videolan.vlc.util.AndroidDevices
 import org.videolan.vlc.util.Constants
+import org.videolan.vlc.util.VLCIO
 import org.videolan.vlc.viewmodels.PlaybackProgress
 import org.videolan.vlc.viewmodels.PlaylistModel
 
@@ -277,7 +279,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
                 if (TextUtils.isEmpty(mw.artworkMrl)) {
                     setDefaultBackground()
                 } else {
-                    val blurredCover = async { UiTools.blurBitmap(AudioUtil.readCoverBitmap(Uri.decode(mw.artworkMrl), binding.contentLayout.width)) }.await()
+                    val blurredCover = withContext(VLCIO) { UiTools.blurBitmap(AudioUtil.readCoverBitmap(Uri.decode(mw.artworkMrl), binding.contentLayout.width)) }
                     if (blurredCover !== null) {
                         val activity = activity as? AudioPlayerContainerActivity
                         if (activity === null) return at launch
@@ -326,19 +328,17 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
     }
 
     fun onNextClick(view: View) {
-        if (service === null) return
-        if (service?.hasNext() == true)
-            service?.next()
-        else
-            Snackbar.make(binding.root, R.string.lastsong, Snackbar.LENGTH_SHORT).show()
+        service?.run {
+            if (hasNext()) next()
+            else Snackbar.make(binding.root, R.string.lastsong, Snackbar.LENGTH_SHORT).show()
+        }
     }
 
     fun onPreviousClick(view: View) {
-        if (service === null) return
-        if (service?.hasPrevious() == true || service?.isSeekable == true)
-            service?.previous(false)
-        else
-            Snackbar.make(binding.root, R.string.firstsong, Snackbar.LENGTH_SHORT).show()
+        service?.run {
+            if (hasPrevious() || isSeekable) previous(false)
+            else Snackbar.make(binding.root, R.string.firstsong, Snackbar.LENGTH_SHORT).show()
+        }
     }
 
     fun onRepeatClick(view: View) {
@@ -420,8 +420,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
     fun onSearchClick(v: View) {
         binding.playlistSearch.visibility = View.GONE
         binding.playlistSearchText.visibility = View.VISIBLE
-        if (binding.playlistSearchText.editText != null)
-            binding.playlistSearchText.editText!!.requestFocus()
+        binding.playlistSearchText.editText?.requestFocus()
         val imm = VLCApplication.getAppContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
         imm.showSoftInput(binding.playlistSearchText.editText, InputMethodManager.SHOW_IMPLICIT)
         handler.postDelayed(hideSearchRunnable, SEARCH_TIMEOUT_MILLIS.toLong())



More information about the Android mailing list