Add "new color scheme" button

This commit is contained in:
MM20 2023-08-26 17:47:26 +02:00
parent 19c627e01a
commit f223e9307d
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
4 changed files with 57 additions and 1 deletions

View File

@ -4,6 +4,9 @@ import android.net.Uri
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.browser.customtabs.CustomTabColorSchemeParams import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsIntent 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.RowScope
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
@ -19,10 +22,20 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text import androidx.compose.material3.Text
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.geometry.Offset
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb 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.LocalContext
import androidx.compose.ui.platform.LocalViewConfiguration
import androidx.compose.ui.platform.ViewConfiguration
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.google.accompanist.systemuicontroller.rememberSystemUiController
@ -70,9 +83,33 @@ fun PreferenceScreen(
val colorScheme = MaterialTheme.colorScheme 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 val activity = LocalContext.current as? AppCompatActivity
Scaffold( Scaffold(
floatingActionButton = floatingActionButton, floatingActionButton = {
AnimatedVisibility(
fabVisible,
enter = scaleIn(),
exit = scaleOut(),
) {
floatingActionButton()
}
},
topBar = { topBar = {
CenterAlignedTopAppBar( CenterAlignedTopAppBar(
title = title, title = title,
@ -110,6 +147,7 @@ fun PreferenceScreen(
LazyColumn( LazyColumn(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.nestedScroll(nestedScrollConnection)
.padding(it), .padding(it),
content = content, content = content,
) )

View File

@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons 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.ContentCopy
import androidx.compose.material.icons.rounded.Delete import androidx.compose.material.icons.rounded.Delete
import androidx.compose.material.icons.rounded.Download 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.AlertDialog
import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
@ -73,6 +75,11 @@ fun ThemesSettingsScreen() {
IconButton(onClick = { importIntentLauncher.launch(arrayOf("*/*")) }) { IconButton(onClick = { importIntentLauncher.launch(arrayOf("*/*")) }) {
Icon(Icons.Rounded.Download, null) Icon(Icons.Rounded.Download, null)
} }
},
floatingActionButton = {
FloatingActionButton(onClick = { viewModel.createNew(context) }) {
Icon(Icons.Rounded.Add, null)
}
} }
) { ) {
item { item {

View File

@ -16,6 +16,7 @@ import de.mm20.launcher2.themes.Theme
import de.mm20.launcher2.themes.ThemeRepository import de.mm20.launcher2.themes.ThemeRepository
import de.mm20.launcher2.themes.fromJson import de.mm20.launcher2.themes.fromJson
import de.mm20.launcher2.themes.toJson import de.mm20.launcher2.themes.toJson
import de.mm20.launcher2.ui.R
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf 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)
)
)
}
} }

View File

@ -825,4 +825,5 @@
<string name="note_widget_file_write_error">Error saving note</string> <string name="note_widget_file_write_error">Error saving note</string>
<string name="note_widget_file_write_error_description">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.</string> <string name="note_widget_file_write_error_description">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.</string>
<string name="confirmation_delete_color_scheme">Do you really want to delete the color scheme %1$s?</string> <string name="confirmation_delete_color_scheme">Do you really want to delete the color scheme %1$s?</string>
<string name="new_color_scheme_name">New color scheme</string>
</resources> </resources>