mirror of
https://github.com/lizongying/my-tv.git
synced 2026-11-26 13:26:29 +08:00
创建 SP 工具类,管理所有(除 ChannelUtils 以外)用户偏好设置
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package com.lizongying.mytv
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.Signature
|
||||
@@ -43,11 +41,6 @@ class MainActivity : FragmentActivity() {
|
||||
private val delayHideMain: Long = 5000
|
||||
private val delayHideSetting: Long = 10000
|
||||
|
||||
lateinit var sharedPref: SharedPreferences
|
||||
private var channelReversal = false
|
||||
private var channelNum = true
|
||||
private var bootStartup = true
|
||||
|
||||
private var versionName = ""
|
||||
|
||||
init {
|
||||
@@ -79,19 +72,13 @@ class MainActivity : FragmentActivity() {
|
||||
.commit()
|
||||
}
|
||||
gestureDetector = GestureDetector(this, GestureListener())
|
||||
|
||||
sharedPref = getPreferences(Context.MODE_PRIVATE)
|
||||
channelReversal = sharedPref.getBoolean(CHANNEL_REVERSAL, channelReversal)
|
||||
channelNum = sharedPref.getBoolean(CHANNEL_NUM, channelNum)
|
||||
bootStartup = sharedPref.getBoolean(BOOT_STARTUP, bootStartup)
|
||||
|
||||
versionName = getPackageInfo().versionName
|
||||
settingFragment = SettingFragment(versionName, channelReversal, channelNum, bootStartup)
|
||||
settingFragment = SettingFragment(versionName, SP.channelReversal, SP.channelNum, SP.bootStartup)
|
||||
}
|
||||
|
||||
fun showInfoFragment(tvViewModel: TVViewModel) {
|
||||
infoFragment.show(tvViewModel)
|
||||
if (channelNum) {
|
||||
if (SP.channelNum) {
|
||||
channelFragment.show(tvViewModel)
|
||||
}
|
||||
}
|
||||
@@ -105,7 +92,7 @@ class MainActivity : FragmentActivity() {
|
||||
return
|
||||
}
|
||||
|
||||
if (channelNum) {
|
||||
if (SP.channelNum) {
|
||||
channelFragment.show(channel)
|
||||
}
|
||||
}
|
||||
@@ -223,30 +210,6 @@ class MainActivity : FragmentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
fun saveChannelReversal(channelReversal: Boolean) {
|
||||
with(sharedPref.edit()) {
|
||||
putBoolean(CHANNEL_REVERSAL, channelReversal)
|
||||
apply()
|
||||
}
|
||||
this.channelReversal = channelReversal
|
||||
}
|
||||
|
||||
fun saveChannelNum(channelNum: Boolean) {
|
||||
with(sharedPref.edit()) {
|
||||
putBoolean(CHANNEL_NUM, channelNum)
|
||||
apply()
|
||||
}
|
||||
this.channelNum = channelNum
|
||||
}
|
||||
|
||||
fun saveBootStartup(bootStartup: Boolean) {
|
||||
with(sharedPref.edit()) {
|
||||
putBoolean(BOOT_STARTUP, bootStartup)
|
||||
apply()
|
||||
}
|
||||
this.bootStartup = bootStartup
|
||||
}
|
||||
|
||||
private fun showSetting() {
|
||||
if (!mainFragment.isHidden) {
|
||||
return
|
||||
@@ -271,7 +234,7 @@ class MainActivity : FragmentActivity() {
|
||||
|
||||
private fun channelUp() {
|
||||
if (mainFragment.isHidden) {
|
||||
if (channelReversal) {
|
||||
if (SP.channelReversal) {
|
||||
next()
|
||||
return
|
||||
}
|
||||
@@ -288,7 +251,7 @@ class MainActivity : FragmentActivity() {
|
||||
|
||||
private fun channelDown() {
|
||||
if (mainFragment.isHidden) {
|
||||
if (channelReversal) {
|
||||
if (SP.channelReversal) {
|
||||
prev()
|
||||
return
|
||||
}
|
||||
@@ -520,7 +483,7 @@ class MainActivity : FragmentActivity() {
|
||||
override fun onResume() {
|
||||
Log.i(TAG, "onResume")
|
||||
super.onResume()
|
||||
if (!mainFragment.isHidden){
|
||||
if (!mainFragment.isHidden) {
|
||||
handler.postDelayed(hideMain, delayHideMain)
|
||||
}
|
||||
}
|
||||
@@ -531,10 +494,7 @@ class MainActivity : FragmentActivity() {
|
||||
handler.removeCallbacks(hideMain)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "MainActivity"
|
||||
private const val CHANNEL_REVERSAL = "channel_reversal"
|
||||
private const val CHANNEL_NUM = "channel_num"
|
||||
const val BOOT_STARTUP = "boot_startup"
|
||||
private companion object {
|
||||
const val TAG = "MainActivity"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user