11package org.qownnotes.mobile
22
3+ import android.app.Activity
4+ import android.content.Context
5+ import android.content.ContextWrapper
36import androidx.compose.foundation.background
47import androidx.compose.foundation.border
8+ import androidx.compose.foundation.isSystemInDarkTheme
59import androidx.compose.foundation.layout.Arrangement
610import androidx.compose.foundation.layout.Box
711import androidx.compose.foundation.layout.Column
@@ -25,11 +29,13 @@ import androidx.compose.material3.Slider
2529import androidx.compose.material3.Switch
2630import androidx.compose.material3.Text
2731import androidx.compose.runtime.Composable
32+ import androidx.compose.runtime.DisposableEffect
2833import androidx.compose.ui.Alignment
2934import androidx.compose.ui.Modifier
3035import androidx.compose.ui.draw.clip
3136import androidx.compose.ui.graphics.Color
3237import androidx.compose.ui.graphics.toArgb
38+ import androidx.compose.ui.platform.LocalView
3339import androidx.compose.ui.platform.testTag
3440import androidx.compose.ui.res.colorResource
3541import androidx.compose.ui.semantics.Role
@@ -39,6 +45,7 @@ import androidx.compose.ui.text.font.FontWeight
3945import androidx.compose.ui.text.style.TextOverflow
4046import androidx.compose.ui.unit.dp
4147import androidx.compose.ui.unit.sp
48+ import androidx.core.view.WindowCompat
4249import kotlin.math.roundToInt
4350
4451/* * Test tag suffix for a palette color, such as `light-blue`. */
@@ -147,6 +154,165 @@ internal fun SwitchRow(
147154 }
148155}
149156
157+ /* * Editor for the note list's header, row, and category colors. */
158+ @Composable
159+ internal fun AppAppearanceEditor (
160+ appearance : AppAppearance ,
161+ onChange : (AppAppearance ) -> Unit ,
162+ modifier : Modifier = Modifier
163+ ) {
164+ Column (modifier = modifier.fillMaxWidth()) {
165+ SwitchRow (
166+ label = " Show list header" ,
167+ checked = appearance.showListHeader,
168+ onCheckedChange = { onChange(appearance.copy(showListHeader = it)) },
169+ testTag = " toggle-list-header"
170+ )
171+ Text (
172+ " Shows the listed category and the account name below the search bar." ,
173+ style = MaterialTheme .typography.bodySmall,
174+ color = MaterialTheme .colorScheme.onSurfaceVariant
175+ )
176+ ColorChoice (
177+ label = " Header color" ,
178+ selected = appearance.headerColor,
179+ onSelect = { onChange(appearance.copy(headerColor = it)) },
180+ testTag = " app-header" ,
181+ defaultLabel = " Default header" ,
182+ defaultColor = MaterialTheme .colorScheme.surface
183+ )
184+ ColorChoice (
185+ label = " Note background" ,
186+ selected = appearance.noteBackground,
187+ onSelect = { onChange(appearance.copy(noteBackground = it)) },
188+ testTag = " app-note-background" ,
189+ defaultLabel = " Default note background" ,
190+ defaultColor = MaterialTheme .colorScheme.surface
191+ )
192+ SwitchRow (
193+ label = " Highlight categories" ,
194+ checked = appearance.highlightCategories,
195+ onCheckedChange = { onChange(appearance.copy(highlightCategories = it)) },
196+ testTag = " toggle-highlight-categories"
197+ )
198+ Text (
199+ " Applies when \" Show category\" is on." ,
200+ style = MaterialTheme .typography.bodySmall,
201+ color = MaterialTheme .colorScheme.onSurfaceVariant
202+ )
203+ if (appearance.highlightCategories) {
204+ ColorChoice (
205+ label = " Category highlight color" ,
206+ selected = appearance.categoryHighlight,
207+ onSelect = { onChange(appearance.copy(categoryHighlight = it)) },
208+ testTag = " app-category-highlight" ,
209+ defaultLabel = " Default category highlight" ,
210+ defaultColor = MaterialTheme .colorScheme.secondaryContainer
211+ )
212+ }
213+ Text (
214+ " Custom colors stay the same in light and dark mode. Text color adjusts " +
215+ " automatically for readability." ,
216+ style = MaterialTheme .typography.bodySmall,
217+ color = MaterialTheme .colorScheme.onSurfaceVariant,
218+ modifier = Modifier .padding(top = 8 .dp)
219+ )
220+ }
221+ }
222+
223+ /* *
224+ * A note's category, either as plain text or as a tinted label. The label uses
225+ * [highlightColor] when set and the theme's secondary container otherwise.
226+ */
227+ @Composable
228+ internal fun NoteCategoryLabel (
229+ category : String ,
230+ highlight : Boolean ,
231+ highlightColor : Int? ,
232+ testTag : String
233+ ) {
234+ if (! highlight) {
235+ Text (
236+ category,
237+ style = MaterialTheme .typography.bodySmall,
238+ modifier = Modifier .testTag(testTag)
239+ )
240+ return
241+ }
242+ val background = highlightColor?.let (::Color ) ? : MaterialTheme .colorScheme.secondaryContainer
243+ val content = highlightColor?.let { Color (AppearanceColors .contentColor(it)) }
244+ ? : MaterialTheme .colorScheme.onSecondaryContainer
245+ Text (
246+ category,
247+ style = MaterialTheme .typography.labelMedium,
248+ color = content,
249+ maxLines = 1 ,
250+ overflow = TextOverflow .Ellipsis ,
251+ modifier = Modifier .padding(vertical = 2 .dp)
252+ .clip(RoundedCornerShape (6 .dp))
253+ .background(background)
254+ .padding(horizontal = 6 .dp, vertical = 1 .dp)
255+ .testTag(testTag)
256+ )
257+ }
258+
259+ /* * Optional two-line header under the search bar: what is listed, then whose notes they are. */
260+ @Composable
261+ internal fun NoteListHeader (
262+ title : String ,
263+ accountName : String ,
264+ contentColor : Color ,
265+ secondaryColor : Color
266+ ) {
267+ Column (
268+ modifier = Modifier .fillMaxWidth()
269+ .padding(start = 20 .dp, end = 16 .dp, bottom = 8 .dp)
270+ .testTag(" note-list-header" )
271+ ) {
272+ Text (
273+ title,
274+ style = MaterialTheme .typography.titleMedium,
275+ fontWeight = FontWeight .Bold ,
276+ color = contentColor,
277+ maxLines = 1 ,
278+ overflow = TextOverflow .Ellipsis ,
279+ modifier = Modifier .testTag(" note-list-header-title" )
280+ )
281+ Text (
282+ accountName,
283+ style = MaterialTheme .typography.bodySmall,
284+ color = secondaryColor,
285+ maxLines = 1 ,
286+ overflow = TextOverflow .Ellipsis ,
287+ modifier = Modifier .testTag(" note-list-header-account" )
288+ )
289+ }
290+ }
291+
292+ /* *
293+ * Keeps status bar icons readable over a custom header color and restores the theme default when
294+ * the screen leaves or the color is cleared.
295+ */
296+ @Composable
297+ internal fun StatusBarIconsFor (headerColor : Int? ) {
298+ val view = LocalView .current
299+ val darkTheme = isSystemInDarkTheme()
300+ DisposableEffect (view, headerColor, darkTheme) {
301+ val window = view.context.findActivity()?.window
302+ val controller = window?.let { WindowCompat .getInsetsController(it, view) }
303+ controller?.isAppearanceLightStatusBars = headerColor
304+ ?.let { AppearanceColors .contentColor(it) == AppearanceColors .DARK_CONTENT }
305+ ? : ! darkTheme
306+ onDispose { controller?.isAppearanceLightStatusBars = ! darkTheme }
307+ }
308+ }
309+
310+ private tailrec fun Context.findActivity (): Activity ? = when (this ) {
311+ is Activity -> this
312+ is ContextWrapper -> baseContext.findActivity()
313+ else -> null
314+ }
315+
150316/* * Editor for one widget's colors, opacity, and frame, with a live approximation above it. */
151317@Composable
152318internal fun WidgetAppearanceEditor (
0 commit comments