[Android] Improve code

Habib Kazemi git at videolan.org
Mon Aug 6 16:18:24 CEST 2018


vlc-android | branch: master | Habib Kazemi <kazemihabib1996 at gmail.com> | Mon Jul 30 19:26:06 2018 +0430| [18e98f0d5d31a2e31f4f8e4fca041705429035c8] | committer: Geoffrey Métais

Improve code

Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>

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

 .../videolan/vlc/gui/network/MRLPanelFragment.kt    |  6 +-----
 .../org/videolan/vlc/viewmodels/MRLPanelModel.kt    | 21 ++++++---------------
 2 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt b/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt
index b84eebe98..c96f1c6f1 100644
--- a/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt
@@ -106,9 +106,7 @@ class MRLPanelFragment : DialogFragment(), View.OnKeyListener, TextView.OnEditor
         dismiss()
     }
 
-    override fun onEditorAction(v: TextView, actionId: Int, event: KeyEvent): Boolean {
-        return false
-    }
+    override fun onEditorAction(v: TextView, actionId: Int, event: KeyEvent) = false
 
     override fun onClick(v: View) {
         processUri()
@@ -116,9 +114,7 @@ class MRLPanelFragment : DialogFragment(), View.OnKeyListener, TextView.OnEditor
 
     override fun onDestroy() {
         super.onDestroy()
-        val activity = activity
         // TV
         (activity as? DialogActivity)?.finish()
     }
-
 }
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/MRLPanelModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/MRLPanelModel.kt
index 75b9f2840..124d8629b 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/MRLPanelModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/MRLPanelModel.kt
@@ -22,17 +22,13 @@ package org.videolan.vlc.viewmodels
 
 import android.arch.lifecycle.MutableLiveData
 import android.arch.lifecycle.ViewModel
-import android.databinding.BaseObservable
-import android.databinding.ObservableArrayList
 import android.databinding.ObservableField
 import android.text.Editable
-import android.text.TextWatcher
-import android.util.Log
-import kotlinx.coroutines.experimental.android.UI
-import kotlinx.coroutines.experimental.launch
+import kotlinx.coroutines.experimental.withContext
 import org.videolan.medialibrary.media.MediaWrapper
 import org.videolan.vlc.VLCApplication
 import org.videolan.vlc.util.VLCIO
+import org.videolan.vlc.util.uiJob
 
 
 class MRLPanelModel: ViewModel() {
@@ -44,13 +40,8 @@ class MRLPanelModel: ViewModel() {
 
      val observableHistory = MutableLiveData<Array<MediaWrapper>>()
 
-     fun updateHistory() {
-          launch(VLCIO) {
-               val history = VLCApplication.getMLInstance().lastStreamsPlayed()
-               launch(UI) {
-                   observableHistory.value = history
-               }
-          }
-     }
-
+    fun updateHistory() = uiJob {
+        val history = withContext(VLCIO) { VLCApplication.getMLInstance().lastStreamsPlayed() }
+        observableHistory.value = history
+    }
 }
\ No newline at end of file



More information about the Android mailing list