mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
some refinement and improvisation
This commit is contained in:
parent
1fa4807716
commit
259661ddf8
6 changed files with 87 additions and 31 deletions
|
@ -25,6 +25,7 @@ import androidx.core.view.isVisible
|
||||||
import androidx.core.widget.NestedScrollView
|
import androidx.core.widget.NestedScrollView
|
||||||
import androidx.core.widget.doOnTextChanged
|
import androidx.core.widget.doOnTextChanged
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import com.discord.panels.OverlappingPanelsLayout
|
import com.discord.panels.OverlappingPanelsLayout
|
||||||
import com.discord.panels.PanelsChildGestureRegionObserver
|
import com.discord.panels.PanelsChildGestureRegionObserver
|
||||||
import com.google.android.gms.cast.framework.CastButtonFactory
|
import com.google.android.gms.cast.framework.CastButtonFactory
|
||||||
|
@ -33,6 +34,8 @@ 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.AcraApplication
|
||||||
|
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
||||||
import com.lagradost.cloudstream3.CommonActivity
|
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
|
||||||
|
@ -67,6 +70,7 @@ import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.loadCache
|
import com.lagradost.cloudstream3.utils.AppUtils.loadCache
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.openBrowser
|
import com.lagradost.cloudstream3.utils.AppUtils.openBrowser
|
||||||
import com.lagradost.cloudstream3.utils.BatteryOptimizationChecker
|
import com.lagradost.cloudstream3.utils.BatteryOptimizationChecker
|
||||||
|
import com.lagradost.cloudstream3.utils.DataStore.getKey
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorLink
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||||
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
|
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
|
||||||
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialogInstant
|
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialogInstant
|
||||||
|
|
|
@ -31,6 +31,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.intentOpenAppInfo
|
||||||
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
|
||||||
|
@ -44,7 +45,6 @@ import com.lagradost.safefile.SafeFile
|
||||||
|
|
||||||
// Change local language settings in the app.
|
// Change local language settings in the app.
|
||||||
fun getCurrentLocale(context: Context): String {
|
fun getCurrentLocale(context: Context): String {
|
||||||
// val dm = res.displayMetrics
|
|
||||||
val res = context.resources
|
val res = context.resources
|
||||||
val conf = res.configuration
|
val conf = res.configuration
|
||||||
|
|
||||||
|
@ -203,6 +203,11 @@ class SettingsGeneral : PreferenceFragmentCompat() {
|
||||||
return@setOnPreferenceClickListener true
|
return@setOnPreferenceClickListener true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPref(R.string.battery_optimisation_key)?.setOnPreferenceClickListener {
|
||||||
|
intentOpenAppInfo(requireContext())
|
||||||
|
return@setOnPreferenceClickListener true
|
||||||
|
}
|
||||||
|
|
||||||
fun showAdd() {
|
fun showAdd() {
|
||||||
val providers = synchronized(allProviders) { allProviders.distinctBy { it.javaClass }.sortedBy { it.name } }
|
val providers = synchronized(allProviders) { allProviders.distinctBy { it.javaClass }.sortedBy { it.name } }
|
||||||
activity?.showDialog(
|
activity?.showDialog(
|
||||||
|
|
|
@ -9,49 +9,70 @@ import android.os.PowerManager
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.context
|
import androidx.preference.PreferenceManager
|
||||||
import com.lagradost.cloudstream3.BuildConfig
|
import com.lagradost.cloudstream3.BuildConfig
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment
|
|
||||||
|
const val packageName = BuildConfig.APPLICATION_ID
|
||||||
|
const val TAG = "PowerManagerAPI"
|
||||||
|
|
||||||
object BatteryOptimizationChecker {
|
object BatteryOptimizationChecker {
|
||||||
|
|
||||||
private const val packageName = BuildConfig.APPLICATION_ID
|
|
||||||
|
|
||||||
private fun isAppRestricted(context: Context?): Boolean {
|
private 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false // below Marshmallow, it's always unrestricted
|
return false // below Marshmallow, it's always unrestricted when app is in background
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openBatteryOptimizationSettings(context: Context) {
|
fun openBatteryOptimizationSettings(context: Context) {
|
||||||
if (isPhoneAndRestricted()) {
|
if (shouldShowBatteryOptimizationDialog(context)) {
|
||||||
try {
|
showBatteryOptimizationDialog(context)
|
||||||
showBatteryOptimizationDialog(context)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("PowerManagerAPI", "Error showing battery optimization dialog", e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showBatteryOptimizationDialog(context: Context) {
|
private fun showBatteryOptimizationDialog(context: Context) {
|
||||||
AlertDialog.Builder(context)
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
.setTitle(R.string.battery_dialog_title)
|
|
||||||
.setMessage(R.string.battery_dialog_message)
|
try {
|
||||||
.setPositiveButton(R.string.ok) { _, _ ->
|
context.let {
|
||||||
val intent = Intent()
|
AlertDialog.Builder(it)
|
||||||
intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
|
.setTitle(R.string.battery_dialog_title)
|
||||||
intent.data = Uri.fromParts("package", packageName, null)
|
.setIcon(R.drawable.ic_battery)
|
||||||
context.startActivity(intent, Bundle())
|
.setMessage(R.string.battery_dialog_message)
|
||||||
|
.setCancelable(false)
|
||||||
|
.setPositiveButton(R.string.ok) { _, _ ->
|
||||||
|
intentOpenAppInfo(it)
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.cancel) { _, _ ->
|
||||||
|
settingsManager.edit()
|
||||||
|
.putBoolean(context.getString(R.string.battery_optimisation_key), false)
|
||||||
|
.apply()
|
||||||
|
}
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
.setNegativeButton(R.string.cancel, null)
|
} catch (e: Exception) {
|
||||||
.show()
|
Log.e(TAG, "Error showing battery optimization dialog")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isPhoneAndRestricted(): Boolean {
|
private fun shouldShowBatteryOptimizationDialog(context: Context): Boolean {
|
||||||
return SettingsFragment.isTruePhone() && isAppRestricted(context)
|
val isRestricted = isAppRestricted(context)
|
||||||
|
val isOptimizedShown = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
.getBoolean(context.getString(R.string.battery_optimisation_key), true)
|
||||||
|
return isRestricted && isOptimizedShown
|
||||||
|
}
|
||||||
|
|
||||||
|
fun intentOpenAppInfo(context: Context) {
|
||||||
|
try {
|
||||||
|
val intent = Intent()
|
||||||
|
.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||||
|
.setData(Uri.fromParts("package", packageName, null))
|
||||||
|
context.startActivity(intent, Bundle())
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
Log.e(TAG, "Unable to invoke intent for App info.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
app/src/main/res/drawable/ic_battery.xml
Normal file
12
app/src/main/res/drawable/ic_battery.xml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="?attr/white"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M15.67,4L14,4L14,3c0,-0.55 -0.45,-1 -1,-1h-2c-0.55,0 -1,0.45 -1,1v1L8.33,4C7.6,4 7,4.6 7,5.33v15.33C7,21.4 7.6,22 8.34,22h7.32c0.74,0 1.34,-0.6 1.34,-1.33L17,5.33C17,4.6 16.4,4 15.67,4zM13,18h-2v-2h2v2zM13,13c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1v-3c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v3z" />
|
||||||
|
|
||||||
|
</vector>
|
|
@ -651,8 +651,10 @@
|
||||||
<string name="yes">Yes</string>
|
<string name="yes">Yes</string>
|
||||||
<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">\nTo ensure proper Downloads and Notifications, please set battery optimization for CloudStream app to UNRESTRICTED.</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="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>
|
||||||
|
|
|
@ -6,10 +6,7 @@
|
||||||
android:title="@string/app_language"
|
android:title="@string/app_language"
|
||||||
android:icon="@drawable/ic_baseline_language_24" />
|
android:icon="@drawable/ic_baseline_language_24" />
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="@string/download_path_key"
|
|
||||||
android:title="@string/download_path_pref"
|
|
||||||
android:icon="@drawable/netflix_download" />
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="@string/legal_notice_key"
|
android:key="@string/legal_notice_key"
|
||||||
|
@ -23,7 +20,22 @@
|
||||||
app:summary="@string/benene_des" />
|
app:summary="@string/benene_des" />
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/pref_category_bypass">
|
android:title="@string/title_downloads">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="@string/download_path_key"
|
||||||
|
android:title="@string/download_path_pref"
|
||||||
|
android:icon="@drawable/netflix_download" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="@string/battery_optimisation_key"
|
||||||
|
android:title="@string/battery_dialog_title"
|
||||||
|
android:icon="@drawable/ic_battery" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/pref_category_bypass">
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="@string/override_site_key"
|
android:key="@string/override_site_key"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue