diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/component/preferences/PreferenceScreen.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/component/preferences/PreferenceScreen.kt index 4a5689d4..e74698bd 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/component/preferences/PreferenceScreen.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/component/preferences/PreferenceScreen.kt @@ -4,6 +4,9 @@ import android.net.Uri import androidx.appcompat.app.AppCompatActivity import androidx.browser.customtabs.CustomTabColorSchemeParams import androidx.browser.customtabs.CustomTabsIntent +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.scaleIn +import androidx.compose.animation.scaleOut import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding @@ -19,10 +22,20 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Text 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.geometry.Offset import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.input.nestedscroll.NestedScrollConnection +import androidx.compose.ui.input.nestedscroll.NestedScrollSource +import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalViewConfiguration +import androidx.compose.ui.platform.ViewConfiguration import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.google.accompanist.systemuicontroller.rememberSystemUiController @@ -70,9 +83,33 @@ fun PreferenceScreen( val colorScheme = MaterialTheme.colorScheme + val touchSlop = LocalViewConfiguration.current.touchSlop + var fabVisible by remember { mutableStateOf(true) } + val nestedScrollConnection = remember { + object: NestedScrollConnection { + override fun onPostScroll( + consumed: Offset, + available: Offset, + source: NestedScrollSource + ): Offset { + if (consumed.y < -touchSlop) fabVisible = false + else if (consumed.y > touchSlop) fabVisible = true + return super.onPostScroll(consumed, available, source) + } + } + } + val activity = LocalContext.current as? AppCompatActivity Scaffold( - floatingActionButton = floatingActionButton, + floatingActionButton = { + AnimatedVisibility( + fabVisible, + enter = scaleIn(), + exit = scaleOut(), + ) { + floatingActionButton() + } + }, topBar = { CenterAlignedTopAppBar( title = title, @@ -110,6 +147,7 @@ fun PreferenceScreen( LazyColumn( modifier = Modifier .fillMaxSize() + .nestedScroll(nestedScrollConnection) .padding(it), content = content, ) diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreen.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreen.kt index 080c6b35..747b2364 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreen.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreen.kt @@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.Add import androidx.compose.material.icons.rounded.ContentCopy import androidx.compose.material.icons.rounded.Delete import androidx.compose.material.icons.rounded.Download @@ -24,6 +25,7 @@ import androidx.compose.material.icons.rounded.Share import androidx.compose.material3.AlertDialog import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem +import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme @@ -73,6 +75,11 @@ fun ThemesSettingsScreen() { IconButton(onClick = { importIntentLauncher.launch(arrayOf("*/*")) }) { Icon(Icons.Rounded.Download, null) } + }, + floatingActionButton = { + FloatingActionButton(onClick = { viewModel.createNew(context) }) { + Icon(Icons.Rounded.Add, null) + } } ) { item { diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreenVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreenVM.kt index 83f639a2..91008d22 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreenVM.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreenVM.kt @@ -16,6 +16,7 @@ import de.mm20.launcher2.themes.Theme import de.mm20.launcher2.themes.ThemeRepository import de.mm20.launcher2.themes.fromJson import de.mm20.launcher2.themes.toJson +import de.mm20.launcher2.ui.R import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf @@ -96,4 +97,13 @@ class ThemesSettingsScreenVM : ViewModel(), KoinComponent { } } } + + fun createNew(context: Context) { + themeRepository.createTheme( + Theme( + id = UUID.randomUUID(), + name = context.getString(R.string.new_color_scheme_name) + ) + ) + } } \ No newline at end of file diff --git a/core/i18n/src/main/res/values/strings.xml b/core/i18n/src/main/res/values/strings.xml index 39487279..7c33ee01 100644 --- a/core/i18n/src/main/res/values/strings.xml +++ b/core/i18n/src/main/res/values/strings.xml @@ -825,4 +825,5 @@ Error saving note The note could not be written to the linked file. Possibly, it has been moved or deleted. A copy has been saved to the launcher\'s internal storage. Do you really want to delete the color scheme %1$s? + New color scheme \ No newline at end of file