diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 5a058f9..43b8090 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -7,6 +7,7 @@
android:name="android.software.leanback"
android:required="true" />
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/lizongying/mytv/BootReceiver.kt b/app/src/main/java/com/lizongying/mytv/BootReceiver.kt
new file mode 100644
index 0000000..773c3b6
--- /dev/null
+++ b/app/src/main/java/com/lizongying/mytv/BootReceiver.kt
@@ -0,0 +1,19 @@
+package com.lizongying.mytv
+
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+
+class BootReceiver : BroadcastReceiver() {
+
+ override fun onReceive(context: Context, intent: Intent) {
+ val sp = context.getSharedPreferences("MainActivity", Context.MODE_PRIVATE)
+ if (sp.getBoolean(MainActivity.BOOT_STARTUP, true)) {
+ context.startActivity(
+ Intent(context, MainActivity::class.java)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ )
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/lizongying/mytv/MainActivity.kt b/app/src/main/java/com/lizongying/mytv/MainActivity.kt
index f9ed1e4..7dd9434 100644
--- a/app/src/main/java/com/lizongying/mytv/MainActivity.kt
+++ b/app/src/main/java/com/lizongying/mytv/MainActivity.kt
@@ -41,6 +41,7 @@ class MainActivity : FragmentActivity() {
lateinit var sharedPref: SharedPreferences
private var channelReversal = false
private var channelNum = true
+ private var bootStartup = true
private var versionName = ""
@@ -67,9 +68,10 @@ class MainActivity : FragmentActivity() {
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)
+ settingFragment = SettingFragment(versionName, channelReversal, channelNum, bootStartup)
}
fun showInfoFragment(tvViewModel: TVViewModel) {
@@ -222,6 +224,14 @@ class MainActivity : FragmentActivity() {
this.channelNum = channelNum
}
+ fun saveBootStartup(bootStartup: Boolean) {
+ with(sharedPref.edit()) {
+ putBoolean(CHANNEL_NUM, channelNum)
+ apply()
+ }
+ this.bootStartup = bootStartup
+ }
+
private fun showSetting() {
if (!mainFragment.isHidden) {
return
@@ -510,5 +520,6 @@ class MainActivity : FragmentActivity() {
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"
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/lizongying/mytv/SettingFragment.kt b/app/src/main/java/com/lizongying/mytv/SettingFragment.kt
index 94c0e94..8a55c50 100644
--- a/app/src/main/java/com/lizongying/mytv/SettingFragment.kt
+++ b/app/src/main/java/com/lizongying/mytv/SettingFragment.kt
@@ -11,6 +11,7 @@ import com.lizongying.mytv.databinding.DialogBinding
class SettingFragment(private val versionName: String,
private val channelReversal: Boolean,
private val channelNum: Boolean,
+ private val bootStartup: Boolean,
) :
DialogFragment() {
@@ -43,6 +44,12 @@ class SettingFragment(private val versionName: String,
(activity as MainActivity).saveChannelNum(isChecked)
}
+ val switchBootStartup = _binding?.switchBootStartup
+ switchBootStartup?.isChecked = bootStartup
+ switchBootStartup?.setOnCheckedChangeListener { _, isChecked ->
+ (activity as MainActivity).saveBootStartup(isChecked)
+ }
+
return binding.root
}
diff --git a/app/src/main/res/layout/dialog.xml b/app/src/main/res/layout/dialog.xml
index 75c8c46..819e99d 100644
--- a/app/src/main/res/layout/dialog.xml
+++ b/app/src/main/res/layout/dialog.xml
@@ -40,6 +40,12 @@
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
+
我的电视
换台反转
数字选台
+ 开机自启
\ No newline at end of file