commit
d944777fc6
|
|
@ -7,6 +7,7 @@
|
|||
android:name="android.software.leanback"
|
||||
android:required="true" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:largeHeap="true"
|
||||
|
|
@ -29,5 +30,13 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<receiver
|
||||
android:name=".BootReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -46,6 +46,7 @@ class MainActivity : FragmentActivity() {
|
|||
lateinit var sharedPref: SharedPreferences
|
||||
private var channelReversal = false
|
||||
private var channelNum = true
|
||||
private var bootStartup = true
|
||||
|
||||
private var versionName = ""
|
||||
|
||||
|
|
@ -82,9 +83,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) {
|
||||
|
|
@ -237,6 +239,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
|
||||
|
|
@ -525,5 +535,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"
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,12 @@
|
|||
android:layout_marginTop="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<Switch
|
||||
android:id="@+id/switch_boot_startup"
|
||||
android:text="@string/title_boot_startup"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:layout_width="300dp"
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@
|
|||
<string name="app_name">我的电视</string>
|
||||
<string name="title_channel_reversal">换台反转</string>
|
||||
<string name="title_channel_num">数字选台</string>
|
||||
<string name="title_boot_startup">开机自启</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue