pull/842/merge
soberGou 2 years ago committed by GitHub
commit bdd01f8c61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      app/src/main/AndroidManifest.xml
  2. 93
      app/src/main/java/com/lizongying/mytv/SettingFragment.kt
  3. 9
      app/src/main/java/com/lizongying/mytv/UpdateWorker.kt
  4. 7
      app/src/main/res/layout/setting.xml
  5. 1
      app/src/main/res/values/strings.xml

@ -12,6 +12,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

@ -54,7 +54,6 @@ class SettingFragment : DialogFragment() {
val context = requireContext() // It‘s safe to get context here.
_binding = SettingBinding.inflate(inflater, container, false)
binding.versionName.text = "当前版本: v${context.appVersionName}"
binding.version.text = "https://github.com/lizongying/my-tv"
binding.switchChannelReversal.run {
isChecked = SP.channelReversal
@ -96,6 +95,26 @@ class SettingFragment : DialogFragment() {
}
}
binding.switchUpdateUrl.run {
isChecked = SP.grid
setOnCheckedChangeListener { _, isChecked ->
SP.grid = isChecked
(activity as MainActivity).settingDelayHide()
if (true == isChecked) {
binding.version.text = "https://gitee.com/lizongying/my-tv"
} else {
binding.version.text = "https://github.com/lizongying/my-tv"
}
}
if (true == isChecked) {
binding.version.text = "https://gitee.com/lizongying/my-tv"
} else {
binding.version.text = "https://github.com/lizongying/my-tv"
}
}
binding.checkVersion.setOnClickListener {
(activity as MainActivity).settingDelayHide()
requestInstallPermissions()
@ -155,6 +174,9 @@ class SettingFragment : DialogFragment() {
binding.switchGrid.textSize = textSize
binding.switchGrid.layoutParams = layoutParamsChannelSwitch
binding.switchUpdateUrl.textSize = textSize
binding.switchUpdateUrl.layoutParams = layoutParamsChannelSwitch
binding.appreciate.layoutParams.width =
application.px2Px(binding.appreciate.layoutParams.width)
@ -183,40 +205,41 @@ class SettingFragment : DialogFragment() {
}
private fun requestInstallPermissions() {
val context = requireContext()
val permissionsList: MutableList<String> = ArrayList()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !context.packageManager.canRequestPackageInstalls()) {
permissionsList.add(Manifest.permission.REQUEST_INSTALL_PACKAGES)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
ContextCompat.checkSelfPermission(
context,
Manifest.permission.READ_EXTERNAL_STORAGE
) != PackageManager.PERMISSION_GRANTED
) {
permissionsList.add(Manifest.permission.READ_EXTERNAL_STORAGE)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
ContextCompat.checkSelfPermission(
context,
Manifest.permission.WRITE_EXTERNAL_STORAGE
) != PackageManager.PERMISSION_GRANTED
) {
permissionsList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
}
if (permissionsList.isNotEmpty()) {
ActivityCompat.requestPermissions(
requireActivity(),
permissionsList.toTypedArray<String>(),
PERMISSIONS_REQUEST_CODE
)
} else {
updateManager.checkAndUpdate()
}
// val context = requireContext()
// val permissionsList = mutableListOf<String>()
//
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !context.packageManager.canRequestPackageInstalls()) {
// permissionsList.add(Manifest.permission.REQUEST_INSTALL_PACKAGES)
// }
//
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
// ContextCompat.checkSelfPermission(
// context,
// Manifest.permission.READ_EXTERNAL_STORAGE
// ) != PackageManager.PERMISSION_GRANTED
// ) {
// permissionsList.add(Manifest.permission.READ_EXTERNAL_STORAGE)
// }
//
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
// ContextCompat.checkSelfPermission(
// context,
// Manifest.permission.WRITE_EXTERNAL_STORAGE
// ) != PackageManager.PERMISSION_GRANTED
// ) {
// permissionsList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
// }
//
// if (permissionsList.isNotEmpty()) {
// ActivityCompat.requestPermissions(
// requireActivity(),
// permissionsList.toTypedArray(),
// PERMISSIONS_REQUEST_CODE
// )
// } else {
// updateManager.checkAndUpdate()
// }
updateManager.checkAndUpdate()
}
override fun onRequestPermissionsResult(

@ -131,16 +131,13 @@ class UpdateWorker(context: Context, params: WorkerParameters) : CoroutineWorker
if (apkFile.exists()) {
val apkUri: Uri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
FileProvider.getUriForFile(context, context.packageName + ".fileprovider", apkFile)
.apply {
Intent.FLAG_GRANT_READ_URI_PERMISSION
}
FileProvider.getUriForFile(context, "${context.packageName}.provider", apkFile)
} else {
Uri.parse("file://${apkFile.absolutePath}")
// Uri.fromFile(apkFile)
}
// val apkUri = Uri.parse("file://$apkFile")
Log.i(TAG, "apkUri $apkUri")
val installIntent = Intent(Intent.ACTION_VIEW).apply {
setDataAndType(apkUri, "application/vnd.android.package-archive")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK)

@ -117,6 +117,13 @@
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Switch
android:id="@+id/switch_update_url"
android:text="@string/update_url"
android:textSize="14sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" />
</LinearLayout>
</ScrollView>
<ImageView

@ -6,6 +6,7 @@
<string name="title_boot_startup">开机自启</string>
<string name="title_grid">频道列表采用网格样式</string>
<string name="title_time">显示时间</string>
<string name="update_url">更新地址,关闭全球,打开中国</string>
<string name="clear">恢复默认</string>
<string name="exit">退出应用</string>
<string name="start_update">开始更新</string>

Loading…
Cancel
Save