mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
more improvements
This commit is contained in:
parent
86165a23c8
commit
7cfb097993
4 changed files with 25 additions and 9 deletions
|
@ -449,6 +449,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
|
||||||
?: txt(R.string.no_data).asStringNull(context) ?: ""
|
?: txt(R.string.no_data).asStringNull(context) ?: ""
|
||||||
showToast(txt(message, name), Toast.LENGTH_SHORT)
|
showToast(txt(message, name), Toast.LENGTH_SHORT)
|
||||||
}
|
}
|
||||||
|
context?.let { openBatteryOptimizationSettings(it) }
|
||||||
}
|
}
|
||||||
resultFavorite.setOnClickListener {
|
resultFavorite.setOnClickListener {
|
||||||
viewModel.toggleFavoriteStatus(context) { newStatus: Boolean? ->
|
viewModel.toggleFavoriteStatus(context) { newStatus: Boolean? ->
|
||||||
|
|
|
@ -31,8 +31,11 @@ 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.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.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
|
||||||
|
@ -208,7 +211,7 @@ class SettingsGeneral : PreferenceFragmentCompat() {
|
||||||
val ctx = context ?: return@setOnPreferenceClickListener false
|
val ctx = context ?: return@setOnPreferenceClickListener false
|
||||||
|
|
||||||
if (isAppRestricted(ctx)) {
|
if (isAppRestricted(ctx)) {
|
||||||
intentOpenAppInfo(ctx)
|
showBatteryOptimizationDialog(ctx)
|
||||||
} else {
|
} else {
|
||||||
showToast(R.string.app_unrestricted_toast)
|
showToast(R.string.app_unrestricted_toast)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.lagradost.cloudstream3.utils
|
package com.lagradost.cloudstream3.utils
|
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
@ -13,6 +14,7 @@ import androidx.preference.PreferenceManager
|
||||||
import com.lagradost.cloudstream3.BuildConfig
|
import com.lagradost.cloudstream3.BuildConfig
|
||||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTruePhone
|
||||||
|
|
||||||
const val packageName = BuildConfig.APPLICATION_ID
|
const val packageName = BuildConfig.APPLICATION_ID
|
||||||
const val TAG = "PowerManagerAPI"
|
const val TAG = "PowerManagerAPI"
|
||||||
|
@ -34,7 +36,7 @@ object BatteryOptimizationChecker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showBatteryOptimizationDialog(context: Context) {
|
fun showBatteryOptimizationDialog(context: Context) {
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -43,7 +45,6 @@ object BatteryOptimizationChecker {
|
||||||
.setTitle(R.string.battery_dialog_title)
|
.setTitle(R.string.battery_dialog_title)
|
||||||
.setIcon(R.drawable.ic_battery)
|
.setIcon(R.drawable.ic_battery)
|
||||||
.setMessage(R.string.battery_dialog_message)
|
.setMessage(R.string.battery_dialog_message)
|
||||||
.setCancelable(false)
|
|
||||||
.setPositiveButton(R.string.ok) { _, _ ->
|
.setPositiveButton(R.string.ok) { _, _ ->
|
||||||
intentOpenAppInfo(it)
|
intentOpenAppInfo(it)
|
||||||
}
|
}
|
||||||
|
@ -55,7 +56,7 @@ object BatteryOptimizationChecker {
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Error showing battery optimization dialog")
|
Log.e(TAG, "Error showing battery optimization dialog", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,18 +64,24 @@ object BatteryOptimizationChecker {
|
||||||
val isRestricted = isAppRestricted(context)
|
val isRestricted = isAppRestricted(context)
|
||||||
val isOptimizedShown = PreferenceManager.getDefaultSharedPreferences(context)
|
val isOptimizedShown = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
.getBoolean(context.getString(R.string.battery_optimisation_key), true)
|
.getBoolean(context.getString(R.string.battery_optimisation_key), true)
|
||||||
return isRestricted && isOptimizedShown
|
return isRestricted && isOptimizedShown && isTruePhone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun intentOpenAppInfo(context: Context) {
|
fun intentOpenAppInfo(context: Context) {
|
||||||
|
val intent = Intent()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val intent = 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 intent for - CS3/App Info", t)
|
Log.e(TAG, "Unable to invoke any intent", t)
|
||||||
showToast(R.string.app_info_intent_error)
|
if (t is ActivityNotFoundException) {
|
||||||
|
showToast("ActivityNotFoundException")
|
||||||
|
} else {
|
||||||
|
showToast(R.string.app_info_intent_error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -652,7 +652,12 @@
|
||||||
<string name="no">No</string>
|
<string name="no">No</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<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 uninterrupted downloads and notifications for subscribed
|
||||||
|
TV shows, CloudStream needs permission to run in background. By pressing "OK", you\'ll be directed to App info.
|
||||||
|
There, scroll to 𝘼𝙥𝙥 𝙗𝙖𝙩𝙩𝙚𝙧𝙮 𝙪𝙨𝙖𝙜𝙚 and set battery usage to 𝙐𝙣𝙧𝙚𝙨𝙩𝙧𝙞𝙘𝙩𝙚𝙙. Please note, this permission
|
||||||
|
does not mean CS3 will drain your battery. It will only operate in the background when necessary, such as
|
||||||
|
when receiving notifications or downloading videos from official extensions. If you choose to cancel,
|
||||||
|
you can adjust this setting later in 𝙂𝙚𝙣𝙚𝙧𝙖𝙡 𝙎𝙚𝙩𝙩𝙞𝙣𝙜𝙨.</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 battery usage 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="app_info_intent_error">Unable to open CloudStream\'s App info.</string>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue