fix some issues

This commit is contained in:
IndusAryan 2024-03-23 12:38:11 +05:30
parent 2c6c5cdc03
commit c560246b8c
3 changed files with 10 additions and 17 deletions

View file

@ -31,7 +31,6 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
import com.lagradost.cloudstream3.APIHolder import com.lagradost.cloudstream3.APIHolder
import com.lagradost.cloudstream3.APIHolder.updateHasTrailers import com.lagradost.cloudstream3.APIHolder.updateHasTrailers
import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.CommonActivity
import com.lagradost.cloudstream3.DubStatus import com.lagradost.cloudstream3.DubStatus
import com.lagradost.cloudstream3.LoadResponse import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent

View file

@ -34,10 +34,7 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setToolBarScrollFlags import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setToolBarScrollFlags
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
import com.lagradost.cloudstream3.utils.BatteryOptimizationChecker
import com.lagradost.cloudstream3.utils.BatteryOptimizationChecker.intentOpenAppInfo
import com.lagradost.cloudstream3.utils.BatteryOptimizationChecker.isAppRestricted import com.lagradost.cloudstream3.utils.BatteryOptimizationChecker.isAppRestricted
import com.lagradost.cloudstream3.utils.BatteryOptimizationChecker.openBatteryOptimizationSettings
import com.lagradost.cloudstream3.utils.BatteryOptimizationChecker.showBatteryOptimizationDialog import com.lagradost.cloudstream3.utils.BatteryOptimizationChecker.showBatteryOptimizationDialog
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog
@ -210,10 +207,8 @@ class SettingsGeneral : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true return@setOnPreferenceClickListener true
} }
// hide preference on tvs and emulators // disable preference on tvs and emulators
if (!isLayout(PHONE)) { getPref(R.string.battery_optimisation_key)?.isEnabled = isLayout(PHONE)
getPref(R.string.battery_optimisation_key)?.isEnabled = false
}
getPref(R.string.battery_optimisation_key)?.setOnPreferenceClickListener { getPref(R.string.battery_optimisation_key)?.setOnPreferenceClickListener {
val ctx = context ?: return@setOnPreferenceClickListener false val ctx = context ?: return@setOnPreferenceClickListener false
@ -222,6 +217,7 @@ class SettingsGeneral : PreferenceFragmentCompat() {
} else { } else {
showToast(R.string.app_unrestricted_toast) showToast(R.string.app_unrestricted_toast)
} }
true true
} }

View file

@ -56,30 +56,28 @@ object BatteryOptimizationChecker {
} }
.show() .show()
} }
} catch (e: Exception) { } catch (t: Throwable) {
Log.e(TAG, "Error showing battery optimization dialog", e) Log.e(TAG, "Error showing battery optimization dialog", t)
} }
} }
private fun shouldShowBatteryOptimizationDialog(context: Context): Boolean { private fun shouldShowBatteryOptimizationDialog(context: Context): Boolean {
val isRestricted = isAppRestricted(context) val isRestricted = isAppRestricted(context)
val isOptimizedShown = PreferenceManager.getDefaultSharedPreferences(context) val isOptimizedNotShown = PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.battery_optimisation_key), true) .getBoolean(context.getString(R.string.battery_optimisation_key), true)
return isRestricted && isOptimizedShown && isLayout(PHONE) return isRestricted && isOptimizedNotShown && isLayout(PHONE)
} }
fun intentOpenAppInfo(context: Context) { private fun intentOpenAppInfo(context: Context) {
val intent = Intent() val intent = Intent()
try { try {
intent intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
.setData(Uri.fromParts("package", packageName, null)) .setData(Uri.fromParts("package", packageName, null))
context.startActivity(intent, Bundle()) context.startActivity(intent, Bundle())
} catch (t: Throwable) { } catch (t: Throwable) {
Log.e(TAG, "Unable to invoke any intent", t) Log.e(TAG, "Unable to invoke any intent", t)
if (t is ActivityNotFoundException) { if (t is ActivityNotFoundException) {
showToast("ActivityNotFoundException") showToast("Exception: Activity Not Found")
} else { } else {
showToast(R.string.app_info_intent_error) showToast(R.string.app_info_intent_error)
} }