Skip to content

Commit

Permalink
save channel
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Mar 22, 2024
1 parent e5cac3e commit 7ab4a91
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
13 changes: 9 additions & 4 deletions app/src/main/java/com/lizongying/mytv0/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand Down Expand Up @@ -136,15 +134,15 @@ 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
}
TVList.setPosition(position)
}

fun next() {
position = TVList.position.value?.inc() ?: 0
var position = TVList.position.value?.inc() ?: 0
if (position == TVList.size()) {
position = 0
}
Expand Down Expand Up @@ -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"
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/lizongying/mytv0/SP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TVGroupModel : ViewModel() {
}

init {
_position.value = SP.positionCategory
_position.value = SP.positionGroup
}

fun size(): Int {
Expand Down

0 comments on commit 7ab4a91

Please sign in to comment.