mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-04-30 05:54:26 +02:00
fix: move battery warning to dashboard
This commit is contained in:
parent
1ee1330e47
commit
a995f43b7b
@ -1,5 +1,9 @@
|
|||||||
package app.revanced.manager.ui.screen
|
package app.revanced.manager.ui.screen
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.provider.Settings
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
@ -10,6 +14,7 @@ import androidx.compose.foundation.pager.HorizontalPager
|
|||||||
import androidx.compose.foundation.pager.rememberPagerState
|
import androidx.compose.foundation.pager.rememberPagerState
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
|
import androidx.compose.material.icons.filled.BatteryAlert
|
||||||
import androidx.compose.material.icons.filled.Close
|
import androidx.compose.material.icons.filled.Close
|
||||||
import androidx.compose.material.icons.outlined.Apps
|
import androidx.compose.material.icons.outlined.Apps
|
||||||
import androidx.compose.material.icons.outlined.DeleteOutline
|
import androidx.compose.material.icons.outlined.DeleteOutline
|
||||||
@ -69,6 +74,7 @@ enum class DashboardPage(
|
|||||||
BUNDLES(R.string.tab_bundles, Icons.Outlined.Source),
|
BUNDLES(R.string.tab_bundles, Icons.Outlined.Source),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("BatteryLife")
|
||||||
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun DashboardScreen(
|
fun DashboardScreen(
|
||||||
@ -229,6 +235,21 @@ fun DashboardScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else null,
|
} else null,
|
||||||
|
if (vm.showBatteryOptimizationsWarning) {
|
||||||
|
{
|
||||||
|
NotificationCard(
|
||||||
|
modifier = Modifier.padding(16.dp),
|
||||||
|
isWarning = true,
|
||||||
|
icon = Icons.Default.BatteryAlert,
|
||||||
|
text = stringResource(R.string.battery_optimization_notification),
|
||||||
|
onClick = {
|
||||||
|
androidContext.startActivity(Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
|
||||||
|
data = Uri.parse("package:${androidContext.packageName}")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else null,
|
||||||
vm.updatedManagerVersion?.let {
|
vm.updatedManagerVersion?.let {
|
||||||
{
|
{
|
||||||
NotificationCard(
|
NotificationCard(
|
||||||
|
@ -1,32 +1,17 @@
|
|||||||
package app.revanced.manager.ui.screen
|
package app.revanced.manager.ui.screen
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.net.Uri
|
|
||||||
import android.os.PowerManager
|
|
||||||
import android.provider.Settings
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.BatteryAlert
|
|
||||||
import androidx.compose.material.icons.outlined.*
|
import androidx.compose.material.icons.outlined.*
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import app.revanced.manager.R
|
import app.revanced.manager.R
|
||||||
import app.revanced.manager.ui.component.AppTopBar
|
import app.revanced.manager.ui.component.AppTopBar
|
||||||
import app.revanced.manager.ui.component.ColumnWithScrollbar
|
import app.revanced.manager.ui.component.ColumnWithScrollbar
|
||||||
import app.revanced.manager.ui.component.NotificationCard
|
|
||||||
import app.revanced.manager.ui.component.settings.SettingsListItem
|
import app.revanced.manager.ui.component.settings.SettingsListItem
|
||||||
import app.revanced.manager.ui.destination.SettingsDestination
|
import app.revanced.manager.ui.destination.SettingsDestination
|
||||||
import app.revanced.manager.ui.screen.settings.*
|
import app.revanced.manager.ui.screen.settings.*
|
||||||
@ -38,7 +23,6 @@ import dev.olshevski.navigation.reimagined.*
|
|||||||
import org.koin.androidx.compose.koinViewModel
|
import org.koin.androidx.compose.koinViewModel
|
||||||
import org.koin.core.parameter.parametersOf
|
import org.koin.core.parameter.parametersOf
|
||||||
|
|
||||||
@SuppressLint("BatteryLife")
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsScreen(
|
fun SettingsScreen(
|
||||||
@ -54,10 +38,6 @@ fun SettingsScreen(
|
|||||||
else navController.pop()
|
else navController.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
val context = LocalContext.current
|
|
||||||
val pm = context.getSystemService(Context.POWER_SERVICE) as PowerManager
|
|
||||||
var showBatteryButton by remember { mutableStateOf(!pm.isIgnoringBatteryOptimizations(context.packageName)) }
|
|
||||||
|
|
||||||
val settingsSections = listOf(
|
val settingsSections = listOf(
|
||||||
Triple(
|
Triple(
|
||||||
R.string.general,
|
R.string.general,
|
||||||
@ -163,21 +143,6 @@ fun SettingsScreen(
|
|||||||
.padding(paddingValues)
|
.padding(paddingValues)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
) {
|
) {
|
||||||
AnimatedVisibility(visible = showBatteryButton) {
|
|
||||||
NotificationCard(
|
|
||||||
modifier = Modifier.padding(16.dp),
|
|
||||||
isWarning = true,
|
|
||||||
icon = Icons.Default.BatteryAlert,
|
|
||||||
text = stringResource(R.string.battery_optimization_notification),
|
|
||||||
onClick = {
|
|
||||||
context.startActivity(Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
|
|
||||||
data = Uri.parse("package:${context.packageName}")
|
|
||||||
})
|
|
||||||
showBatteryButton =
|
|
||||||
!pm.isIgnoringBatteryOptimizations(context.packageName)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
settingsSections.forEach { (titleDescIcon, destination) ->
|
settingsSections.forEach { (titleDescIcon, destination) ->
|
||||||
SettingsListItem(
|
SettingsListItem(
|
||||||
modifier = Modifier.clickable { navController.navigate(destination) },
|
modifier = Modifier.clickable { navController.navigate(destination) },
|
||||||
|
@ -3,10 +3,12 @@ package app.revanced.manager.ui.viewmodel
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.PowerManager
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.core.content.getSystemService
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import app.revanced.manager.R
|
import app.revanced.manager.R
|
||||||
@ -33,15 +35,21 @@ class DashboardViewModel(
|
|||||||
val availablePatches =
|
val availablePatches =
|
||||||
patchBundleRepository.bundles.map { it.values.sumOf { bundle -> bundle.patches.size } }
|
patchBundleRepository.bundles.map { it.values.sumOf { bundle -> bundle.patches.size } }
|
||||||
private val contentResolver: ContentResolver = app.contentResolver
|
private val contentResolver: ContentResolver = app.contentResolver
|
||||||
|
private val powerManager = app.getSystemService<PowerManager>()!!
|
||||||
val sources = patchBundleRepository.sources
|
val sources = patchBundleRepository.sources
|
||||||
val selectedSources = mutableStateListOf<PatchBundleSource>()
|
val selectedSources = mutableStateListOf<PatchBundleSource>()
|
||||||
|
|
||||||
|
|
||||||
var updatedManagerVersion: String? by mutableStateOf(null)
|
var updatedManagerVersion: String? by mutableStateOf(null)
|
||||||
private set
|
private set
|
||||||
|
var showBatteryOptimizationsWarning by mutableStateOf(false)
|
||||||
|
private set
|
||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch { checkForManagerUpdates() }
|
viewModelScope.launch {
|
||||||
|
checkForManagerUpdates()
|
||||||
|
showBatteryOptimizationsWarning =
|
||||||
|
!powerManager.isIgnoringBatteryOptimizations(app.packageName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dismissUpdateDialog() {
|
fun dismissUpdateDialog() {
|
||||||
@ -80,10 +88,12 @@ class DashboardViewModel(
|
|||||||
fun cancelSourceSelection() {
|
fun cancelSourceSelection() {
|
||||||
selectedSources.clear()
|
selectedSources.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createLocalSource(patchBundle: Uri, integrations: Uri?) =
|
fun createLocalSource(patchBundle: Uri, integrations: Uri?) =
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
contentResolver.openInputStream(patchBundle)!!.use { patchesStream ->
|
contentResolver.openInputStream(patchBundle)!!.use { patchesStream ->
|
||||||
integrations?.let { contentResolver.openInputStream(it) }.use { integrationsStream ->
|
integrations?.let { contentResolver.openInputStream(it) }
|
||||||
|
.use { integrationsStream ->
|
||||||
patchBundleRepository.createLocal(patchesStream, integrationsStream)
|
patchBundleRepository.createLocal(patchesStream, integrationsStream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,7 +323,7 @@
|
|||||||
<string name="changelog_loading">Loading changelog</string>
|
<string name="changelog_loading">Loading changelog</string>
|
||||||
<string name="changelog_download_fail">Failed to download changelog: %s</string>
|
<string name="changelog_download_fail">Failed to download changelog: %s</string>
|
||||||
<string name="changelog_description">Check out the latest changes in this update</string>
|
<string name="changelog_description">Check out the latest changes in this update</string>
|
||||||
<string name="battery_optimization_notification">Battery optimization must be turned off in order for ReVanced Manager to work correctly in the background. Click here to turn off.</string>
|
<string name="battery_optimization_notification">Battery optimizations must be turned off in order for ReVanced Manager to work correctly in the background. Click here to turn off optimizations.</string>
|
||||||
<string name="installing_manager_update">Installing update…</string>
|
<string name="installing_manager_update">Installing update…</string>
|
||||||
<string name="downloading_manager_update">Downloading update…</string>
|
<string name="downloading_manager_update">Downloading update…</string>
|
||||||
<string name="download_manager_failed">Failed to download update: %s</string>
|
<string name="download_manager_failed">Failed to download update: %s</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user