mirror of
https://github.com/lizongying/my-tv.git
synced 2026-10-27 22:56:32 +08:00
创建 SP 工具类,管理所有(除 ChannelUtils 以外)用户偏好设置
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.lizongying.mytv
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
@@ -34,8 +33,6 @@ class MainFragment : BrowseSupportFragment() {
|
||||
|
||||
var tvListViewModel = TVListViewModel()
|
||||
|
||||
private lateinit var sharedPref: SharedPreferences
|
||||
|
||||
private var lastVideoUrl = ""
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
@@ -58,7 +55,6 @@ class MainFragment : BrowseSupportFragment() {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
activity?.let { request.initYSP(it) }
|
||||
sharedPref = (activity as? MainActivity)?.sharedPref!!
|
||||
|
||||
loadRows()
|
||||
|
||||
@@ -156,7 +152,7 @@ class MainFragment : BrowseSupportFragment() {
|
||||
|
||||
adapter = rowsAdapter
|
||||
|
||||
itemPosition = sharedPref.getInt(POSITION, 0)
|
||||
itemPosition = SP.itemPosition
|
||||
if (itemPosition >= tvListViewModel.size()) {
|
||||
itemPosition = 0
|
||||
}
|
||||
@@ -322,11 +318,8 @@ class MainFragment : BrowseSupportFragment() {
|
||||
override fun onStop() {
|
||||
Log.i(TAG, "onStop")
|
||||
super.onStop()
|
||||
with(sharedPref.edit()) {
|
||||
putInt(POSITION, itemPosition)
|
||||
apply()
|
||||
}
|
||||
Log.i(TAG, "$POSITION saved")
|
||||
SP.itemPosition = itemPosition
|
||||
Log.i(TAG, "position saved")
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
@@ -337,6 +330,5 @@ class MainFragment : BrowseSupportFragment() {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "MainFragment"
|
||||
private const val POSITION = "position"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user