fix issues caused by the compose m3 update

This commit is contained in:
Ax333l 2024-07-19 16:57:22 +02:00
parent f9e8d30ff6
commit 6fcc2ff07f
No known key found for this signature in database
GPG Key ID: D2B4D85271127D23
8 changed files with 84 additions and 36 deletions

View File

@ -7,6 +7,7 @@ import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.getValue
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import app.revanced.manager.ui.destination.Destination
import app.revanced.manager.ui.destination.SettingsDestination
import app.revanced.manager.ui.model.SelectedApp
@ -35,6 +36,8 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
installSplashScreen()
val vm: MainViewModel = getAndroidViewModel()

View File

@ -24,6 +24,7 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.revanced.manager.R
import app.revanced.manager.util.transparentListItemColors
@Composable
fun AutoUpdatesDialog(onSubmit: (Boolean, Boolean) -> Unit) {
@ -77,5 +78,6 @@ private fun AutoUpdatesItem(
leadingContent = { Icon(icon, null) },
headlineContent = { Text(stringResource(headline)) },
trailingContent = { Checkbox(checked = checked, onCheckedChange = null) },
modifier = Modifier.clickable { onCheckedChange(!checked) }
modifier = Modifier.clickable { onCheckedChange(!checked) },
colors = transparentListItemColors
)

View File

@ -1,13 +1,15 @@
package app.revanced.manager.ui.component
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SearchBar
import androidx.compose.material3.SearchBarColors
import androidx.compose.material3.SearchBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
@ -27,29 +29,38 @@ fun SearchView(
placeholder: (@Composable () -> Unit)? = null,
content: @Composable ColumnScope.() -> Unit
) {
val colors = SearchBarColors(
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,
dividerColor = MaterialTheme.colorScheme.outline
)
val focusRequester = remember { FocusRequester() }
val keyboardController = LocalSoftwareKeyboardController.current
SearchBar(
inputField = {
SearchBarDefaults.InputField(
query = query,
onQueryChange = onQueryChange,
onSearch = {
keyboardController?.hide()
},
active = true,
onActiveChange = onActiveChange,
modifier = Modifier
.fillMaxSize()
.focusRequester(focusRequester),
expanded = true,
onExpandedChange = onActiveChange,
placeholder = placeholder,
leadingIcon = {
IconButton({ onActiveChange(false) }) {
IconButton(onClick = { onActiveChange(false) }) {
Icon(
Icons.AutoMirrored.Filled.ArrowBack,
stringResource(R.string.back)
)
}
}
)
},
expanded = true,
onExpandedChange = onActiveChange,
modifier = Modifier.focusRequester(focusRequester),
colors = colors,
content = content
)

View File

@ -16,6 +16,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import app.revanced.manager.R
import app.revanced.manager.data.room.apps.installed.InstallType
import app.revanced.manager.util.transparentListItemColors
@Composable
fun InstallPickerDialog(
@ -44,7 +45,7 @@ fun InstallPickerDialog(
title = { Text(stringResource(R.string.select_install_type)) },
text = {
Column {
InstallType.values().forEach {
InstallType.entries.forEach {
ListItem(
modifier = Modifier.clickable { selectedInstallType = it },
leadingContent = {
@ -53,7 +54,8 @@ fun InstallPickerDialog(
onClick = null
)
},
headlineContent = { Text(stringResource(it.stringResource)) }
headlineContent = { Text(stringResource(it.stringResource)) },
colors = transparentListItemColors
)
}
}

View File

@ -72,6 +72,7 @@ import app.revanced.manager.util.mutableStateSetOf
import app.revanced.manager.util.saver.snapshotStateListSaver
import app.revanced.manager.util.saver.snapshotStateSetSaver
import app.revanced.manager.util.toast
import app.revanced.manager.util.transparentListItemColors
import kotlinx.parcelize.Parcelize
import org.koin.compose.koinInject
import org.koin.core.component.KoinComponent
@ -426,7 +427,8 @@ private class PresetOptionEditor<T : Any>(private val innerEditor: OptionEditor<
selected = selectedPreset == presetKey,
onClick = { selectedPreset = presetKey }
)
}
},
colors = transparentListItemColors
)
}

View File

@ -33,6 +33,7 @@ import app.revanced.manager.ui.component.SearchView
import app.revanced.manager.ui.model.SelectedApp
import app.revanced.manager.ui.viewmodel.AppSelectorViewModel
import app.revanced.manager.util.APK_MIMETYPE
import app.revanced.manager.util.transparentListItemColors
import org.koin.androidx.compose.koinViewModel
@OptIn(ExperimentalMaterial3Api::class)
@ -74,7 +75,7 @@ fun AppSelectorScreen(
)
}
if (search) {
if (search)
SearchView(
query = filterText,
onQueryChange = { filterText = it },
@ -82,9 +83,7 @@ fun AppSelectorScreen(
placeholder = { Text(stringResource(R.string.search_apps)) }
) {
if (appList.isNotEmpty() && filterText.isNotEmpty()) {
LazyColumnWithScrollbar(
modifier = Modifier.fillMaxSize()
) {
LazyColumnWithScrollbar(modifier = Modifier.fillMaxSize()) {
items(
items = filteredAppList,
key = { it.packageName }
@ -115,7 +114,8 @@ fun AppSelectorScreen(
)
)
}
}
},
colors = transparentListItemColors
)
}
@ -129,17 +129,18 @@ fun AppSelectorScreen(
Icon(
imageVector = Icons.Outlined.Search,
contentDescription = stringResource(R.string.search),
modifier = Modifier.size(64.dp)
modifier = Modifier.size(64.dp),
tint = MaterialTheme.colorScheme.onSurfaceVariant
)
Text(
text = stringResource(R.string.type_anything),
style = MaterialTheme.typography.bodyLarge
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
}
}
Scaffold(
topBar = {

View File

@ -68,6 +68,7 @@ import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel.Companion.SHOW
import app.revanced.manager.util.Options
import app.revanced.manager.util.PatchSelection
import app.revanced.manager.util.isScrollingUp
import app.revanced.manager.util.transparentListItemColors
import kotlinx.coroutines.launch
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@ -440,7 +441,8 @@ fun PatchItem(
Icon(Icons.Outlined.Settings, null)
}
}
}
},
colors = transparentListItemColors
)
@Composable
@ -465,7 +467,8 @@ fun ListHeader(
)
}
}
}
},
colors = transparentListItemColors
)
}

View File

@ -13,6 +13,9 @@ import android.widget.Toast
import androidx.annotation.StringRes
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material3.ListItemColors
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.LocalContentColor
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
@ -156,9 +159,21 @@ fun String.relativeTime(context: Context): String {
return when {
duration.toMinutes() < 1 -> context.getString(R.string.just_now)
duration.toMinutes() < 60 -> context.getString(R.string.minutes_ago, duration.toMinutes().toString())
duration.toHours() < 24 -> context.getString(R.string.hours_ago, duration.toHours().toString())
duration.toDays() < 30 -> context.getString(R.string.days_ago, duration.toDays().toString())
duration.toMinutes() < 60 -> context.getString(
R.string.minutes_ago,
duration.toMinutes().toString()
)
duration.toHours() < 24 -> context.getString(
R.string.hours_ago,
duration.toHours().toString()
)
duration.toDays() < 30 -> context.getString(
R.string.days_ago,
duration.toDays().toString()
)
else -> {
val formatter = DateTimeFormatter.ofPattern("MMM d")
val formattedDate = inputDateTime.format(formatter)
@ -176,6 +191,15 @@ fun String.relativeTime(context: Context): String {
}
}
private var transparentListItemColorsCached: ListItemColors? = null
/**
* The default ListItem colors, but with [ListItemColors.containerColor] set to [Color.Transparent].
*/
val transparentListItemColors
@Composable get() = transparentListItemColorsCached
?: ListItemDefaults.colors(containerColor = Color.Transparent)
.also { transparentListItemColorsCached = it }
const val isScrollingUpSensitivity = 10