Skip to content

Commit

Permalink
fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Aug 15, 2024
1 parent 8657d20 commit ad9bfa8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
12 changes: 8 additions & 4 deletions app/src/main/java/com/lizongying/mytv0/BootReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ class BootReceiver : BroadcastReceiver() {

override fun onReceive(context: Context, intent: Intent) {
if (SP.bootStartup) {
context.startActivity(
Intent(context, MainActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
)
try {
context.startActivity(
Intent(context, MainActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
)
} catch (e: Exception) {
e.printStackTrace()
}
}
}

Expand Down
7 changes: 0 additions & 7 deletions app/src/main/java/com/lizongying/mytv0/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,6 @@ class MainViewModel : ViewModel() {
}

fun reset(context: Context) {
groupModel.setPosition(0)
groupModel.setPositionPlaying(0)

val tvListModel = groupModel.getCurrentList()
tvListModel?.setPosition(0)
tvListModel?.setPositionPlaying(0)

val str = context.resources.openRawResource(R.raw.channels).bufferedReader()
.use { it.readText() }

Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/lizongying/mytv0/SP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ object SP {
const val DEFAULT_COMPACT_MENU = true
const val DEFAULT_DISPLAY_SECONDS = false
const val DEFAULT_LOG_TIMES = 10
const val DEFAULT_POSITION_GROUP = 1
const val DEFAULT_POSITION = 0

private lateinit var sp: SharedPreferences

Expand Down Expand Up @@ -86,11 +88,11 @@ object SP {
set(value) = sp.edit().putBoolean(KEY_BOOT_STARTUP, value).apply()

var positionGroup: Int
get() = sp.getInt(KEY_POSITION_GROUP, 0)
get() = sp.getInt(KEY_POSITION_GROUP, DEFAULT_POSITION_GROUP)
set(value) = sp.edit().putInt(KEY_POSITION_GROUP, value).apply()

var position: Int
get() = sp.getInt(KEY_POSITION, 0)
get() = sp.getInt(KEY_POSITION, DEFAULT_POSITION)
set(value) = sp.edit().putInt(KEY_POSITION, value).apply()

var positionSub: Int
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/SettingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ class SettingFragment : Fragment() {
}

binding.clear.setOnClickListener {
SP.positionGroup = SP.DEFAULT_POSITION_GROUP
viewModel.groupModel.setPosition(SP.DEFAULT_POSITION_GROUP)
viewModel.groupModel.setPositionPlaying(SP.DEFAULT_POSITION_GROUP)

SP.position = SP.DEFAULT_POSITION
val tvListModel = viewModel.groupModel.getCurrentList()
tvListModel?.setPosition(SP.DEFAULT_POSITION)
tvListModel?.setPositionPlaying(SP.DEFAULT_POSITION)

SP.config = SP.DEFAULT_CONFIG_URL
viewModel.reset(context)
confirmConfig()
Expand Down

0 comments on commit ad9bfa8

Please sign in to comment.