@@ -17,6 +17,7 @@ import androidx.compose.ui.window.Dialog
|
||||
fun <T> ListPreference(
|
||||
title: String,
|
||||
icon: ImageVector? = null,
|
||||
iconPadding: Boolean = true,
|
||||
items: List<ListPreferenceItem<T>>,
|
||||
value: T,
|
||||
summary: String? = items.firstOrNull { value == it.value }?.label,
|
||||
@@ -33,6 +34,7 @@ fun <T> ListPreference(
|
||||
title = title,
|
||||
summary = summary,
|
||||
icon = icon,
|
||||
iconPadding = iconPadding,
|
||||
enabled = enabled,
|
||||
onClick = {
|
||||
showDialog = true
|
||||
|
||||
@@ -16,6 +16,7 @@ import androidx.compose.ui.unit.dp
|
||||
fun Preference(
|
||||
title: String,
|
||||
icon: @Composable (() -> Unit),
|
||||
iconPadding: Boolean = true,
|
||||
summary: String? = null,
|
||||
onClick: () -> Unit = {},
|
||||
controls: @Composable (() -> Unit)? = null,
|
||||
@@ -29,13 +30,17 @@ fun Preference(
|
||||
.padding(horizontal = 16.dp)
|
||||
.alpha(if (enabled) 1f else 0.38f),
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.width(56.dp)
|
||||
.padding(start = 4.dp),
|
||||
contentAlignment = Alignment.CenterStart
|
||||
) {
|
||||
icon()
|
||||
if (iconPadding) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.width(56.dp)
|
||||
.padding(start = 4.dp),
|
||||
contentAlignment = Alignment.CenterStart
|
||||
) {
|
||||
icon()
|
||||
}
|
||||
} else {
|
||||
Box(modifier = Modifier.size(0.dp))
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier.weight(1f).padding(vertical = 16.dp)
|
||||
@@ -63,13 +68,15 @@ fun Preference(
|
||||
fun Preference(
|
||||
title: String,
|
||||
icon: ImageVector? = null,
|
||||
iconPadding: Boolean = true,
|
||||
summary: String? = null,
|
||||
onClick: () -> Unit = {},
|
||||
controls: @Composable (() -> Unit)? = null,
|
||||
enabled: Boolean = true
|
||||
) {
|
||||
Preference(
|
||||
title, icon = {
|
||||
title,
|
||||
icon = {
|
||||
if (icon != null) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
@@ -77,6 +84,6 @@ fun Preference(
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
}
|
||||
}, summary, onClick, controls, enabled
|
||||
}, iconPadding, summary, onClick, controls, enabled
|
||||
)
|
||||
}
|
||||
+84
-7
@@ -3,22 +3,65 @@ package de.mm20.launcher2.ui.settings.websearch
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.sizeIn
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.material.icons.rounded.Add
|
||||
import androidx.compose.material.icons.rounded.ArrowForward
|
||||
import androidx.compose.material.icons.rounded.Check
|
||||
import androidx.compose.material.icons.rounded.CloudDownload
|
||||
import androidx.compose.material.icons.rounded.MoreVert
|
||||
import androidx.compose.material.icons.rounded.Search
|
||||
import androidx.compose.material.icons.rounded.Tag
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Divider
|
||||
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
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.*
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.luminance
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -28,6 +71,7 @@ import com.godaddy.android.colorpicker.ClassicColorPicker
|
||||
import de.mm20.launcher2.search.data.Websearch
|
||||
import de.mm20.launcher2.ui.R
|
||||
import de.mm20.launcher2.ui.component.BottomSheetDialog
|
||||
import de.mm20.launcher2.ui.component.preferences.ListPreference
|
||||
import de.mm20.launcher2.ui.component.preferences.Preference
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceCategory
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceScreen
|
||||
@@ -146,6 +190,7 @@ fun EditWebsearchDialog(
|
||||
var label by remember { mutableStateOf(value.label) }
|
||||
var showError by remember { mutableStateOf(false) }
|
||||
var urlTemplate by remember { mutableStateOf(value.urlTemplate) }
|
||||
var encoding by remember { mutableStateOf(value.encoding) }
|
||||
var color by remember { mutableStateOf(value.color) }
|
||||
var icon by remember { mutableStateOf(value.icon) }
|
||||
|
||||
@@ -226,6 +271,7 @@ fun EditWebsearchDialog(
|
||||
}
|
||||
value.icon = icon
|
||||
value.color = color
|
||||
value.encoding = encoding
|
||||
onValueSaved(value)
|
||||
} else {
|
||||
showError = true
|
||||
@@ -426,6 +472,37 @@ fun EditWebsearchDialog(
|
||||
text = stringResource(R.string.websearch_dialog_url_description),
|
||||
style = MaterialTheme.typography.labelMedium
|
||||
)
|
||||
|
||||
var showAdvanced by remember { mutableStateOf(false) }
|
||||
|
||||
AnimatedVisibility(!showAdvanced) {
|
||||
TextButton(
|
||||
modifier = Modifier.padding(vertical = 16.dp).align(Alignment.End),
|
||||
onClick = { showAdvanced = true }) {
|
||||
Text(stringResource(R.string.websearch_dialog_advanced))
|
||||
}
|
||||
}
|
||||
|
||||
AnimatedVisibility(showAdvanced) {
|
||||
Column(
|
||||
modifier = Modifier.padding(top = 16.dp)
|
||||
) {
|
||||
Divider()
|
||||
ListPreference(
|
||||
title = stringResource(R.string.websearch_dialog_query_endcoding),
|
||||
items = listOf(
|
||||
stringResource(R.string.websearch_dialog_query_endcoding_url) to Websearch.QueryEncoding.UrlEncode,
|
||||
stringResource(R.string.websearch_dialog_query_endcoding_form) to Websearch.QueryEncoding.FormData,
|
||||
stringResource(R.string.websearch_dialog_query_endcoding_none) to Websearch.QueryEncoding.None,
|
||||
),
|
||||
iconPadding = false,
|
||||
value = encoding,
|
||||
onValueChanged = {
|
||||
encoding = it
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user