Add "new color scheme" button
This commit is contained in:
parent
19c627e01a
commit
f223e9307d
@ -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,
|
||||
)
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -825,4 +825,5 @@
|
||||
<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="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>
|
||||
Loading…
x
Reference in New Issue
Block a user