From 7ab4a912648be0bffb1bb86ac10cf6ba921f0831 Mon Sep 17 00:00:00 2001 From: Li ZongYing Date: Fri, 22 Mar 2024 18:27:54 +0800 Subject: [PATCH] save channel --- .../main/java/com/lizongying/mytv0/MainActivity.kt | 13 +++++++++---- app/src/main/java/com/lizongying/mytv0/SP.kt | 8 ++++---- .../com/lizongying/mytv0/models/TVGroupModel.kt | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/lizongying/mytv0/MainActivity.kt b/app/src/main/java/com/lizongying/mytv0/MainActivity.kt index 175eecc..1dd9f5e 100644 --- a/app/src/main/java/com/lizongying/mytv0/MainActivity.kt +++ b/app/src/main/java/com/lizongying/mytv0/MainActivity.kt @@ -31,8 +31,6 @@ class MainActivity : FragmentActivity() { private var doubleBackToExitPressedOnce = false - private var position = 0 - private lateinit var gestureDetector: GestureDetector override fun onCreate(savedInstanceState: Bundle?) { @@ -136,7 +134,7 @@ class MainActivity : FragmentActivity() { } fun prev() { - position = TVList.position.value?.dec() ?: 0 + var position = TVList.position.value?.dec() ?: 0 if (position == -1) { position = TVList.size() - 1 } @@ -144,7 +142,7 @@ class MainActivity : FragmentActivity() { } fun next() { - position = TVList.position.value?.inc() ?: 0 + var position = TVList.position.value?.inc() ?: 0 if (position == TVList.size()) { position = 0 } @@ -431,6 +429,13 @@ class MainActivity : FragmentActivity() { return super.onKeyDown(keyCode, event) } + override fun onStop() { + super.onStop() + SP.positionGroup = TVList.groupModel.position.value!! + SP.position = TVList.position.value!! + Log.i(TAG, "position ${TVList.position.value!!} saved") + } + companion object { private const val TAG = "MainActivity" } diff --git a/app/src/main/java/com/lizongying/mytv0/SP.kt b/app/src/main/java/com/lizongying/mytv0/SP.kt index 372b80a..694cd5d 100644 --- a/app/src/main/java/com/lizongying/mytv0/SP.kt +++ b/app/src/main/java/com/lizongying/mytv0/SP.kt @@ -17,7 +17,7 @@ object SP { // Position in list of the selected channel item private const val KEY_POSITION = "position" - private const val KEY_POSITION_CATEGORY = "position_group" + private const val KEY_POSITION_GROUP = "position_group" private const val KEY_POSITION_SUB = "position_sub" @@ -49,9 +49,9 @@ object SP { get() = sp.getInt(KEY_POSITION, 0) set(value) = sp.edit().putInt(KEY_POSITION, value).apply() - var positionCategory: Int - get() = sp.getInt(KEY_POSITION_CATEGORY, 0) - set(value) = sp.edit().putInt(KEY_POSITION_CATEGORY, value).apply() + var positionGroup: Int + get() = sp.getInt(KEY_POSITION_GROUP, 0) + set(value) = sp.edit().putInt(KEY_POSITION_GROUP, value).apply() var positionSub: Int get() = sp.getInt(KEY_POSITION_SUB, 0) diff --git a/app/src/main/java/com/lizongying/mytv0/models/TVGroupModel.kt b/app/src/main/java/com/lizongying/mytv0/models/TVGroupModel.kt index 1010c16..9f86d2e 100644 --- a/app/src/main/java/com/lizongying/mytv0/models/TVGroupModel.kt +++ b/app/src/main/java/com/lizongying/mytv0/models/TVGroupModel.kt @@ -35,7 +35,7 @@ class TVGroupModel : ViewModel() { } init { - _position.value = SP.positionCategory + _position.value = SP.positionGroup } fun size(): Int {