mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
use nullable context
This commit is contained in:
parent
3d8a7d26c8
commit
1c31c72be4
4 changed files with 20 additions and 10 deletions
|
@ -33,7 +33,6 @@ import com.google.android.gms.cast.framework.CastState
|
|||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.lagradost.cloudstream3.APIHolder
|
||||
import com.lagradost.cloudstream3.APIHolder.updateHasTrailers
|
||||
import com.lagradost.cloudstream3.CommonActivity
|
||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||
import com.lagradost.cloudstream3.DubStatus
|
||||
import com.lagradost.cloudstream3.LoadResponse
|
||||
|
@ -448,7 +447,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
|
|||
|
||||
val name = (viewModel.page.value as? Resource.Success)?.value?.title
|
||||
?: txt(R.string.no_data).asStringNull(context) ?: ""
|
||||
CommonActivity.showToast(txt(message, name), Toast.LENGTH_SHORT)
|
||||
showToast(txt(message, name), Toast.LENGTH_SHORT)
|
||||
}
|
||||
}
|
||||
resultFavorite.setOnClickListener {
|
||||
|
@ -463,7 +462,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
|
|||
|
||||
val name = (viewModel.page.value as? Resource.Success)?.value?.title
|
||||
?: txt(R.string.no_data).asStringNull(context) ?: ""
|
||||
CommonActivity.showToast(txt(message, name), Toast.LENGTH_SHORT)
|
||||
showToast(txt(message, name), Toast.LENGTH_SHORT)
|
||||
}
|
||||
}
|
||||
mediaRouteButton.apply {
|
||||
|
@ -471,7 +470,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
|
|||
alpha = if (chromecastSupport) 1f else 0.3f
|
||||
if (!chromecastSupport) {
|
||||
setOnClickListener {
|
||||
CommonActivity.showToast(
|
||||
showToast(
|
||||
R.string.no_chromecast_support_toast,
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
|
@ -646,7 +645,8 @@ open class ResultFragmentPhone : FullScreenPlayer() {
|
|||
),
|
||||
null
|
||||
) { click ->
|
||||
openBatteryOptimizationSettings(requireContext())
|
||||
runCatching { context ?: requireContext() }.getOrNull()
|
||||
?.let { openBatteryOptimizationSettings(it) }
|
||||
|
||||
when (click.action) {
|
||||
DOWNLOAD_ACTION_DOWNLOAD -> {
|
||||
|
|
|
@ -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.setUpToolbar
|
||||
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.showDialog
|
||||
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog
|
||||
|
@ -204,8 +205,14 @@ class SettingsGeneral : PreferenceFragmentCompat() {
|
|||
}
|
||||
|
||||
getPref(R.string.battery_optimisation_key)?.setOnPreferenceClickListener {
|
||||
intentOpenAppInfo(requireContext())
|
||||
return@setOnPreferenceClickListener true
|
||||
val ctx = context ?: requireContext()
|
||||
|
||||
if (isAppRestricted(ctx)) {
|
||||
intentOpenAppInfo(ctx)
|
||||
} else {
|
||||
showToast(R.string.app_unrestricted_toast)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fun showAdd() {
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.util.Log
|
|||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.lagradost.cloudstream3.BuildConfig
|
||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||
import com.lagradost.cloudstream3.R
|
||||
|
||||
const val packageName = BuildConfig.APPLICATION_ID
|
||||
|
@ -18,7 +19,7 @@ const val TAG = "PowerManagerAPI"
|
|||
|
||||
object BatteryOptimizationChecker {
|
||||
|
||||
private fun isAppRestricted(context: Context?): Boolean {
|
||||
fun isAppRestricted(context: Context?): Boolean {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null) {
|
||||
val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||
return !powerManager.isIgnoringBatteryOptimizations(context.packageName)
|
||||
|
@ -72,7 +73,8 @@ object BatteryOptimizationChecker {
|
|||
.setData(Uri.fromParts("package", packageName, null))
|
||||
context.startActivity(intent, Bundle())
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -654,7 +654,8 @@
|
|||
<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_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_installing">Installing app update…</string>
|
||||
<string name="update_notification_failed">Could not install the new version of the app</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue