use nullable context

This commit is contained in:
IndusAryan 2024-03-07 16:48:40 +05:30
parent 3d8a7d26c8
commit 1c31c72be4
4 changed files with 20 additions and 10 deletions

View file

@ -33,7 +33,6 @@ import com.google.android.gms.cast.framework.CastState
import com.google.android.material.bottomsheet.BottomSheetDialog 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
import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.DubStatus import com.lagradost.cloudstream3.DubStatus
import com.lagradost.cloudstream3.LoadResponse import com.lagradost.cloudstream3.LoadResponse
@ -448,7 +447,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
val name = (viewModel.page.value as? Resource.Success)?.value?.title val name = (viewModel.page.value as? Resource.Success)?.value?.title
?: txt(R.string.no_data).asStringNull(context) ?: "" ?: txt(R.string.no_data).asStringNull(context) ?: ""
CommonActivity.showToast(txt(message, name), Toast.LENGTH_SHORT) showToast(txt(message, name), Toast.LENGTH_SHORT)
} }
} }
resultFavorite.setOnClickListener { resultFavorite.setOnClickListener {
@ -463,7 +462,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
val name = (viewModel.page.value as? Resource.Success)?.value?.title val name = (viewModel.page.value as? Resource.Success)?.value?.title
?: txt(R.string.no_data).asStringNull(context) ?: "" ?: txt(R.string.no_data).asStringNull(context) ?: ""
CommonActivity.showToast(txt(message, name), Toast.LENGTH_SHORT) showToast(txt(message, name), Toast.LENGTH_SHORT)
} }
} }
mediaRouteButton.apply { mediaRouteButton.apply {
@ -471,7 +470,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
alpha = if (chromecastSupport) 1f else 0.3f alpha = if (chromecastSupport) 1f else 0.3f
if (!chromecastSupport) { if (!chromecastSupport) {
setOnClickListener { setOnClickListener {
CommonActivity.showToast( showToast(
R.string.no_chromecast_support_toast, R.string.no_chromecast_support_toast,
Toast.LENGTH_LONG Toast.LENGTH_LONG
) )
@ -646,7 +645,8 @@ open class ResultFragmentPhone : FullScreenPlayer() {
), ),
null null
) { click -> ) { click ->
openBatteryOptimizationSettings(requireContext()) runCatching { context ?: requireContext() }.getOrNull()
?.let { openBatteryOptimizationSettings(it) }
when (click.action) { when (click.action) {
DOWNLOAD_ACTION_DOWNLOAD -> { DOWNLOAD_ACTION_DOWNLOAD -> {

View file

@ -32,6 +32,7 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPadd
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.intentOpenAppInfo import com.lagradost.cloudstream3.utils.BatteryOptimizationChecker.intentOpenAppInfo
import com.lagradost.cloudstream3.utils.BatteryOptimizationChecker.isAppRestricted
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
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog
@ -204,8 +205,14 @@ class SettingsGeneral : PreferenceFragmentCompat() {
} }
getPref(R.string.battery_optimisation_key)?.setOnPreferenceClickListener { getPref(R.string.battery_optimisation_key)?.setOnPreferenceClickListener {
intentOpenAppInfo(requireContext()) val ctx = context ?: requireContext()
return@setOnPreferenceClickListener true
if (isAppRestricted(ctx)) {
intentOpenAppInfo(ctx)
} else {
showToast(R.string.app_unrestricted_toast)
}
true
} }
fun showAdd() { fun showAdd() {

View file

@ -11,6 +11,7 @@ import android.util.Log
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.lagradost.cloudstream3.BuildConfig import com.lagradost.cloudstream3.BuildConfig
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
const val packageName = BuildConfig.APPLICATION_ID const val packageName = BuildConfig.APPLICATION_ID
@ -18,7 +19,7 @@ const val TAG = "PowerManagerAPI"
object BatteryOptimizationChecker { object BatteryOptimizationChecker {
private fun isAppRestricted(context: Context?): Boolean { fun isAppRestricted(context: Context?): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null) {
val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
return !powerManager.isIgnoringBatteryOptimizations(context.packageName) return !powerManager.isIgnoringBatteryOptimizations(context.packageName)
@ -72,7 +73,8 @@ object BatteryOptimizationChecker {
.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 intent for App info.") Log.e(TAG, "Unable to invoke Intent for - CS3/App Info")
showToast(R.string.app_info_intent_error)
} }
} }
} }

View file

@ -654,7 +654,8 @@
<string name="battery_dialog_title">Disable Battery optimization</string> <string name="battery_dialog_title">Disable Battery optimization</string>
<string name="battery_dialog_message">To ensure proper downloads and notifications, please set battery optimization for CloudStream app to Unrestricted. You can change this later from General Settings.</string> <string name="battery_dialog_message">To ensure proper downloads and notifications, please set battery optimization for CloudStream app to Unrestricted. You can change this later from General Settings.</string>
<string name="battery_optimisation_key" translatable="false">battery_optimisation</string> <string name="battery_optimisation_key" translatable="false">battery_optimisation</string>
<string name="app_unrestricted_toast">App is already set to unrestricted</string> <string name="app_unrestricted_toast">App battery usage is already set to unrestricted</string>
<string name="app_info_intent_error">Unable to open CloudStream\'s App info.</string>
<string name="update_notification_downloading">Downloading app update…</string> <string name="update_notification_downloading">Downloading app update…</string>
<string name="update_notification_installing">Installing app update…</string> <string name="update_notification_installing">Installing app update…</string>
<string name="update_notification_failed">Could not install the new version of the app</string> <string name="update_notification_failed">Could not install the new version of the app</string>