[Android] TV: Implement CoroutineScope & set clock nullable

Geoffrey Métais git at videolan.org
Tue Apr 30 14:41:35 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Apr 30 14:39:36 2019 +0200| [cae99991c18fa06def0d262cfbf9be1c33c510d5] | committer: Geoffrey Métais

TV: Implement CoroutineScope & set clock nullable

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

 .../videolan/vlc/gui/tv/browser/BaseTvActivity.kt  | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.kt
index 5c996f599..3cd9d88bf 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.kt
@@ -28,14 +28,12 @@ import android.content.Intent
 import android.content.SharedPreferences
 import android.os.Build
 import android.os.Bundle
-import android.os.Handler
 import android.view.KeyEvent
 import android.view.View
 import android.widget.TextView
 import androidx.fragment.app.FragmentActivity
 import androidx.lifecycle.Observer
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.ObsoleteCoroutinesApi
+import kotlinx.coroutines.*
 import org.videolan.medialibrary.Medialibrary
 import org.videolan.vlc.*
 import org.videolan.vlc.gui.helpers.UiTools
@@ -43,10 +41,12 @@ import org.videolan.vlc.gui.tv.SearchActivity
 import org.videolan.vlc.gui.tv.registerTimeView
 import org.videolan.vlc.util.Settings
 
+private const val TAG = "VLC/BaseTvActivity"
+
 @ObsoleteCoroutinesApi
 @ExperimentalCoroutinesApi
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
-abstract class BaseTvActivity : FragmentActivity() {
+abstract class BaseTvActivity : FragmentActivity(), CoroutineScope by MainScope() {
 
     private lateinit var mediaLibrary: Medialibrary
     private lateinit var settings: SharedPreferences
@@ -55,12 +55,12 @@ abstract class BaseTvActivity : FragmentActivity() {
 
     override fun onCreate(savedInstanceState: Bundle?) {
         //Init Medialibrary if KO
-        if (savedInstanceState != null) this.startMedialibrary(firstRun = false, upgrade = false, parse = true)
+        if (savedInstanceState != null) startMedialibrary(firstRun = false, upgrade = false, parse = true)
         super.onCreate(savedInstanceState)
         mediaLibrary = VLCApplication.mlInstance
         settings = Settings.getInstance(this)
         registerLiveData()
-        Handler().post { this at BaseTvActivity.registerTimeView(findViewById<View>(R.id.tv_time) as TextView) }
+        launch { findViewById<View>(R.id.tv_time)?.let { registerTimeView(it as TextView) } }
     }
 
     override fun onStart() {
@@ -77,6 +77,11 @@ abstract class BaseTvActivity : FragmentActivity() {
         super.onStop()
     }
 
+    override fun onDestroy() {
+        super.onDestroy()
+        cancel()
+    }
+
     override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
         if (keyCode == KeyEvent.KEYCODE_SEARCH) {
             startActivity(Intent(this, SearchActivity::class.java))
@@ -107,9 +112,4 @@ abstract class BaseTvActivity : FragmentActivity() {
             MediaParsingService.newStorages.value = null
         })
     }
-
-    companion object {
-
-        private const val TAG = "VLC/BaseTvActivity"
-    }
 }



More information about the Android mailing list