Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32213d46f8 | ||
|
|
f0492cae3a |
No files matched your search
@@ -256,11 +256,11 @@
|
||||
|
||||
</activity>
|
||||
|
||||
<!-- Launcher entry for MainActivity: one alias per launcher name
|
||||
("Calendula" / "Calendar", #44) x icon (bloom / plain, #451).
|
||||
Exactly one is enabled at a time (LauncherManager). The first two
|
||||
keep their pre-#451 names so existing launcher positions and pinned
|
||||
shortcuts survive. The shortcuts meta-data lives here, not on
|
||||
<!-- Launcher entry for MainActivity, split into two aliases so the app's
|
||||
launcher name can be switched at runtime between "Calendula" and
|
||||
"Calendar" (issue #44). Exactly one is enabled at a time; the app
|
||||
flips them via PackageManager.setComponentEnabledSetting
|
||||
(LauncherNameManager). The shortcuts meta-data lives here, not on
|
||||
MainActivity, because static shortcuts are published by whichever
|
||||
component owns the MAIN/LAUNCHER filter. -->
|
||||
<activity-alias
|
||||
@@ -295,38 +295,6 @@
|
||||
android:name="android.app.shortcuts"
|
||||
android:resource="@xml/shortcuts" />
|
||||
</activity-alias>
|
||||
<activity-alias
|
||||
android:name=".PlainIconAlias"
|
||||
android:enabled="false"
|
||||
android:exported="true"
|
||||
android:icon="@mipmap/ic_launcher_plain"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_plain_round"
|
||||
android:targetActivity=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:resource="@xml/shortcuts" />
|
||||
</activity-alias>
|
||||
<activity-alias
|
||||
android:name=".CalendarNamePlainIconAlias"
|
||||
android:enabled="false"
|
||||
android:exported="true"
|
||||
android:icon="@mipmap/ic_launcher_plain"
|
||||
android:label="@string/app_name_calendar_alias"
|
||||
android:roundIcon="@mipmap/ic_launcher_plain_round"
|
||||
android:targetActivity=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:resource="@xml/shortcuts" />
|
||||
</activity-alias>
|
||||
|
||||
<!-- Standalone surface for a captured crash report. MainActivity routes
|
||||
here on a startup crash-loop, so it stays clear of the app's Hilt
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package de.jeanlucmakiola.calendula.data.appname
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/** The launcher label the app shows for itself (issue #44). */
|
||||
enum class LauncherName { CALENDULA, CALENDAR }
|
||||
|
||||
/** The two launcher aliases declared in the manifest. */
|
||||
enum class LauncherAlias { DEFAULT, CALENDAR }
|
||||
|
||||
/** One component-enable change in a [aliasWritePlan]. */
|
||||
data class AliasStateChange(val alias: LauncherAlias, val enabled: Boolean)
|
||||
|
||||
/**
|
||||
* Interpret the `CalendarNameAlias` component-enabled state as a [LauncherName].
|
||||
* Only [PackageManager.COMPONENT_ENABLED_STATE_ENABLED] means the "Calendar"
|
||||
* name is active; `DEFAULT` (never toggled) and `DISABLED` both resolve to the
|
||||
* manifest default, "Calendula".
|
||||
*/
|
||||
fun launcherNameFor(calendarAliasState: Int): LauncherName =
|
||||
if (calendarAliasState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
|
||||
LauncherName.CALENDAR
|
||||
} else {
|
||||
LauncherName.CALENDULA
|
||||
}
|
||||
|
||||
/**
|
||||
* The ordered enable/disable steps to switch the launcher name to [target].
|
||||
* Always **enables the target alias first, then disables the other** — the two
|
||||
* `setComponentEnabledSetting` calls are not atomic, and this ordering means the
|
||||
* only transient the launcher can observe is a harmless two-entry state, never a
|
||||
* zero-entry one (which would briefly drop the app from the launcher).
|
||||
*/
|
||||
fun aliasWritePlan(target: LauncherName): List<AliasStateChange> = when (target) {
|
||||
LauncherName.CALENDAR -> listOf(
|
||||
AliasStateChange(LauncherAlias.CALENDAR, enabled = true),
|
||||
AliasStateChange(LauncherAlias.DEFAULT, enabled = false),
|
||||
)
|
||||
LauncherName.CALENDULA -> listOf(
|
||||
AliasStateChange(LauncherAlias.DEFAULT, enabled = true),
|
||||
AliasStateChange(LauncherAlias.CALENDAR, enabled = false),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches the app's launcher label between "Calendula" and "Calendar" by
|
||||
* enabling/disabling the two `<activity-alias>` components (issue #44). The
|
||||
* component-enabled state is the single source of truth — there is no persisted
|
||||
* preference — so [current] reads it straight from [PackageManager] and the two
|
||||
* always agree.
|
||||
*
|
||||
* The decision logic lives in the pure [launcherNameFor] / [aliasWritePlan]
|
||||
* functions above (JVM-tested); this class is only the thin framework seam.
|
||||
*/
|
||||
@Singleton
|
||||
class LauncherNameManager @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
) {
|
||||
private val packageManager: PackageManager get() = context.packageManager
|
||||
|
||||
// The class portion is namespace-qualified (suffix-free), the package portion
|
||||
// is the applicationId (which carries the .debug / .releasetest suffix). The
|
||||
// manifest's ".CalendarNameAlias" resolves its class against the namespace, so
|
||||
// the real component is <namespace>.CalendarNameAlias registered under the
|
||||
// suffixed applicationId. Do NOT use ComponentName(context, ".CalendarNameAlias")
|
||||
// — its leading-dot form prepends the applicationId to the class too, producing
|
||||
// "<appId>.CalendarNameAlias" and failing on every debug / releaseTest build.
|
||||
private fun component(alias: LauncherAlias): ComponentName {
|
||||
val simpleName = when (alias) {
|
||||
LauncherAlias.DEFAULT -> "DefaultNameAlias"
|
||||
LauncherAlias.CALENDAR -> "CalendarNameAlias"
|
||||
}
|
||||
return ComponentName(context.packageName, "$NAMESPACE.$simpleName")
|
||||
}
|
||||
|
||||
/** The launcher name currently in effect. */
|
||||
fun current(): LauncherName =
|
||||
launcherNameFor(packageManager.getComponentEnabledSetting(component(LauncherAlias.CALENDAR)))
|
||||
|
||||
/** Switch the launcher name to [name] (no-op cost if already active). */
|
||||
fun set(name: LauncherName) {
|
||||
for (change in aliasWritePlan(name)) {
|
||||
val state = if (change.enabled) {
|
||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED
|
||||
} else {
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
||||
}
|
||||
packageManager.setComponentEnabledSetting(
|
||||
component(change.alias),
|
||||
state,
|
||||
PackageManager.DONT_KILL_APP,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
/**
|
||||
* The app's namespace (R-class package) — NOT `applicationId`, which
|
||||
* carries the build-type suffix. Kept in sync with `namespace` in
|
||||
* `app/build.gradle.kts`.
|
||||
*/
|
||||
const val NAMESPACE = "de.jeanlucmakiola.calendula"
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
package de.jeanlucmakiola.calendula.data.backup
|
||||
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherEntry
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherIcon
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherName
|
||||
import de.jeanlucmakiola.calendula.data.appname.LauncherName
|
||||
import de.jeanlucmakiola.calendula.data.calendar.ManagedCalendarRow
|
||||
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefKeys
|
||||
import de.jeanlucmakiola.calendula.data.prefs.FixedTimeOverride
|
||||
@@ -73,13 +71,12 @@ data class CalendarSettings(
|
||||
/** The app language a file carries; [tag] null follows the system. */
|
||||
data class LanguageChoice(val tag: String?)
|
||||
|
||||
/** Everything a settings backup holds. Null [language]/[launcherName]/[launcherIcon]: the file didn't say. */
|
||||
/** Everything a settings backup holds. Null [language]/[launcherName]: the file didn't say. */
|
||||
data class SettingsBackup(
|
||||
val prefs: Map<Pref<*>, Any>,
|
||||
val calendars: List<CalendarSettings>,
|
||||
val language: LanguageChoice? = null,
|
||||
val launcherName: LauncherName? = null,
|
||||
val launcherIcon: LauncherIcon? = null,
|
||||
)
|
||||
|
||||
internal val plainSection = PrefsSection(SettingsBackupSchema.plain)
|
||||
@@ -94,7 +91,7 @@ fun buildSettingsBackup(
|
||||
calendars: List<CalendarSource>,
|
||||
managed: List<ManagedCalendarRow>,
|
||||
language: LanguageChoice?,
|
||||
launcher: LauncherEntry?,
|
||||
launcherName: LauncherName?,
|
||||
): SettingsBackup {
|
||||
val hidden = snapshot[CalendarPrefKeys.hiddenCalendarIds]
|
||||
val lastUsed = snapshot[CalendarPrefKeys.lastUsedCalendarId]
|
||||
@@ -142,8 +139,7 @@ fun buildSettingsBackup(
|
||||
prefs = plainSection.snapshot(snapshot),
|
||||
calendars = entries,
|
||||
language = language,
|
||||
launcherName = launcher?.name,
|
||||
launcherIcon = launcher?.icon,
|
||||
launcherName = launcherName,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -156,7 +152,6 @@ fun encodeSettingsBackup(backup: SettingsBackup, exportedAtMillis: Long, appVers
|
||||
buildJsonObject {
|
||||
backup.language?.let { put(KEY_LANGUAGE, it.tag?.let(::JsonPrimitive) ?: JsonNull) }
|
||||
backup.launcherName?.let { put(KEY_LAUNCHER_NAME, JsonPrimitive(it.name)) }
|
||||
backup.launcherIcon?.let { put(KEY_LAUNCHER_ICON, JsonPrimitive(it.name)) }
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -184,8 +179,6 @@ fun decodeSettingsBackup(text: String): BackupResult<SettingsBackup> {
|
||||
language = app?.takeIf { KEY_LANGUAGE in it }?.let { LanguageChoice(it.optString(KEY_LANGUAGE)) },
|
||||
launcherName = app?.optString(KEY_LAUNCHER_NAME)
|
||||
?.let { name -> LauncherName.entries.firstOrNull { it.name == name } },
|
||||
launcherIcon = app?.optString(KEY_LAUNCHER_ICON)
|
||||
?.let { icon -> LauncherIcon.entries.firstOrNull { it.name == icon } },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -254,7 +247,6 @@ private const val KEY_CALENDARS = "calendars"
|
||||
private const val KEY_APP = "app"
|
||||
private const val KEY_LANGUAGE = "language"
|
||||
private const val KEY_LAUNCHER_NAME = "launcher_name"
|
||||
private const val KEY_LAUNCHER_ICON = "launcher_icon"
|
||||
private const val KEY_ACCOUNT_NAME = "account_name"
|
||||
private const val KEY_ACCOUNT_TYPE = "account_type"
|
||||
private const val KEY_DISPLAY_NAME = "display_name"
|
||||
|
||||
@@ -8,8 +8,7 @@ import androidx.datastore.preferences.core.edit
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import de.jeanlucmakiola.calendula.BuildConfig
|
||||
import de.jeanlucmakiola.calendula.R
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherEntry
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherManager
|
||||
import de.jeanlucmakiola.calendula.data.appname.LauncherNameManager
|
||||
import de.jeanlucmakiola.calendula.data.calendar.CalendarDataSource
|
||||
import de.jeanlucmakiola.calendula.data.contacts.ContactSpecialDatesDataSource
|
||||
import de.jeanlucmakiola.calendula.data.contacts.SpecialDatesScheduler
|
||||
@@ -53,7 +52,7 @@ class SettingsBackupEngine @Inject constructor(
|
||||
private val specialDates: SpecialDatesSyncEngine,
|
||||
private val settingsPrefs: SettingsPrefs,
|
||||
private val reminderScanner: ReminderScanner,
|
||||
private val launcher: LauncherManager,
|
||||
private val launcherNames: LauncherNameManager,
|
||||
@ApplicationContext private val context: Context,
|
||||
@IoDispatcher private val io: CoroutineDispatcher,
|
||||
) {
|
||||
@@ -68,7 +67,7 @@ class SettingsBackupEngine @Inject constructor(
|
||||
calendars = list,
|
||||
managed = if (list.any { it.isManaged }) calendars.findManagedCalendars() else emptyList(),
|
||||
language = LanguageChoice(AppLanguage.currentTag(context, supported)),
|
||||
launcher = launcher.current(),
|
||||
launcherName = launcherNames.current(),
|
||||
)
|
||||
encodeSettingsBackup(backup, System.currentTimeMillis(), BuildConfig.VERSION_NAME)
|
||||
}
|
||||
@@ -136,15 +135,8 @@ class SettingsBackupEngine @Inject constructor(
|
||||
val active = after[SettingsKeys.autoBackupEnabled] && after[SettingsKeys.autoBackupFolderUri] != null
|
||||
if (active && before.autoBackupScheduled != after.autoBackupScheduled) BackupScheduler.runNow(context)
|
||||
}
|
||||
if (plan.launcherName != null || plan.launcherIcon != null) {
|
||||
step("launcher") {
|
||||
val current = launcher.current()
|
||||
val target = LauncherEntry(
|
||||
name = plan.launcherName ?: current.name,
|
||||
icon = plan.launcherIcon ?: current.icon,
|
||||
)
|
||||
if (current != target) launcher.set(target)
|
||||
}
|
||||
plan.launcherName?.let { name ->
|
||||
step("launcher name") { if (launcherNames.current() != name) launcherNames.set(name) }
|
||||
}
|
||||
plan.language?.let { choice ->
|
||||
step("language") {
|
||||
|
||||
@@ -100,6 +100,7 @@ internal object SettingsBackupSchema {
|
||||
// Usage history, not a setting.
|
||||
SettingsKeys.recentTimeZones,
|
||||
SettingsKeys.recentFixedTimeReminders,
|
||||
SettingsKeys.recentCustomColors,
|
||||
// A dismissed hint of this install.
|
||||
SettingsKeys.notificationCategoryHintDismissed,
|
||||
// This device's notification channels.
|
||||
|
||||
@@ -2,8 +2,7 @@ package de.jeanlucmakiola.calendula.data.backup
|
||||
|
||||
import androidx.datastore.preferences.core.MutablePreferences
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherIcon
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherName
|
||||
import de.jeanlucmakiola.calendula.data.appname.LauncherName
|
||||
import de.jeanlucmakiola.calendula.data.calendar.ManagedCalendarRow
|
||||
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefKeys
|
||||
import de.jeanlucmakiola.calendula.data.prefs.FixedTimeOverride
|
||||
@@ -73,7 +72,6 @@ data class SettingsImportPlan(
|
||||
val pendingSpecialDates: List<CalendarSettings>,
|
||||
val language: LanguageChoice?,
|
||||
val launcherName: LauncherName?,
|
||||
val launcherIcon: LauncherIcon?,
|
||||
val skipped: List<SkippedSetting>,
|
||||
)
|
||||
|
||||
@@ -156,7 +154,6 @@ fun planSettingsImport(
|
||||
pendingSpecialDates = pending,
|
||||
language = language,
|
||||
launcherName = backup.launcherName,
|
||||
launcherIcon = backup.launcherIcon,
|
||||
skipped = skipped,
|
||||
)
|
||||
}
|
||||
|
||||
+21
-23
@@ -1,35 +1,33 @@
|
||||
package de.jeanlucmakiola.calendula.data.calendar
|
||||
|
||||
import de.jeanlucmakiola.floret.components.PresetColors
|
||||
|
||||
/**
|
||||
* The colours offered when creating or editing a calendar; ARGB ints for a raw
|
||||
* `CALENDAR_COLOR` / `EVENT_COLOR`.
|
||||
*
|
||||
* Hues rather than final fills: every surface that draws a calendar colour runs
|
||||
* it through the app's own tone pass first, so these are chosen to stay
|
||||
* distinguishable after it. Shared with Agendula, whose list palette these are —
|
||||
* the two apps are the same family and a calendar and a task list picked from
|
||||
* different-looking sets read as different products.
|
||||
* `CALENDAR_COLOR` / `EVENT_COLOR`. The values are floret-kit's [PresetColors],
|
||||
* shared with Agendula; distinctness after this app's tone pass is checked by
|
||||
* `CalendarColorPaletteTest`.
|
||||
*
|
||||
* The named entries exist for callers that need one specific hue (the managed
|
||||
* special-dates calendars), so they can't drift from the swatches on offer.
|
||||
*/
|
||||
object CalendarColorPalette {
|
||||
val Mauve = 0xFF7A5C6B.toInt()
|
||||
val Red = 0xFFD7484A.toInt()
|
||||
val Orange = 0xFFE8743B.toInt()
|
||||
val Amber = 0xFFE0A32E.toInt()
|
||||
val Olive = 0xFF7CA83E.toInt()
|
||||
val Green = 0xFF35A06A.toInt()
|
||||
val Teal = 0xFF19938C.toInt()
|
||||
val Cyan = 0xFF2A9BC4.toInt()
|
||||
val Blue = 0xFF3C74C8.toInt()
|
||||
val Indigo = 0xFF6A5CC0.toInt()
|
||||
val Purple = 0xFF9455B8.toInt()
|
||||
val Pink = 0xFFC94F8E.toInt()
|
||||
val Mauve = PresetColors.Mauve
|
||||
val Red = PresetColors.Red
|
||||
val Orange = PresetColors.Orange
|
||||
val Amber = PresetColors.Amber
|
||||
val Olive = PresetColors.Olive
|
||||
val Green = PresetColors.Green
|
||||
val Teal = PresetColors.Teal
|
||||
val Cyan = PresetColors.Cyan
|
||||
val Blue = PresetColors.Blue
|
||||
val Indigo = PresetColors.Indigo
|
||||
val Purple = PresetColors.Purple
|
||||
val Pink = PresetColors.Pink
|
||||
|
||||
/** The full palette, in swatch-grid order. */
|
||||
val all: List<Int> = listOf(
|
||||
Mauve, Red, Orange, Amber, Olive, Green,
|
||||
Teal, Cyan, Blue, Indigo, Purple, Pink,
|
||||
)
|
||||
val all: List<Int> = PresetColors.all
|
||||
|
||||
/** The preset [argb] is, or null when it is a custom colour (never rewritten to match). */
|
||||
fun presetOf(argb: Int?): Int? = PresetColors.presetOf(argb)
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package de.jeanlucmakiola.calendula.data.launcher
|
||||
|
||||
import android.content.Context
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import de.jeanlucmakiola.floret.android.LauncherAliasSwitcher
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/** The launcher label the app shows for itself (issue #44). */
|
||||
enum class LauncherName { CALENDULA, CALENDAR }
|
||||
|
||||
/** The launcher icon the app shows for itself (issue #451). */
|
||||
enum class LauncherIcon { BLOOM, PLAIN }
|
||||
|
||||
/** What the launcher shows: a name and an icon, chosen independently. */
|
||||
data class LauncherEntry(
|
||||
val name: LauncherName = LauncherName.CALENDULA,
|
||||
val icon: LauncherIcon = LauncherIcon.BLOOM,
|
||||
)
|
||||
|
||||
/**
|
||||
* The four `<activity-alias>` launcher entries, one per name × icon. The two
|
||||
* bloom-icon aliases keep their pre-#451 component names, so users on those
|
||||
* keep their launcher position and pinned shortcuts across the update.
|
||||
*/
|
||||
enum class LauncherAlias(val className: String, val entry: LauncherEntry) {
|
||||
DEFAULT("DefaultNameAlias", LauncherEntry(LauncherName.CALENDULA, LauncherIcon.BLOOM)),
|
||||
CALENDAR("CalendarNameAlias", LauncherEntry(LauncherName.CALENDAR, LauncherIcon.BLOOM)),
|
||||
PLAIN("PlainIconAlias", LauncherEntry(LauncherName.CALENDULA, LauncherIcon.PLAIN)),
|
||||
CALENDAR_PLAIN("CalendarNamePlainIconAlias", LauncherEntry(LauncherName.CALENDAR, LauncherIcon.PLAIN)),
|
||||
;
|
||||
|
||||
companion object {
|
||||
/** The alias that shows [entry]. */
|
||||
fun of(entry: LauncherEntry): LauncherAlias = entries.first { it.entry == entry }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches the launcher name and icon by enabling exactly one [LauncherAlias].
|
||||
* The component-enabled state is the single source of truth, so there is no
|
||||
* stored preference to drift from it.
|
||||
*/
|
||||
@Singleton
|
||||
class LauncherManager @Inject constructor(
|
||||
@ApplicationContext context: Context,
|
||||
) {
|
||||
private val switcher = LauncherAliasSwitcher(
|
||||
context = context,
|
||||
namespace = NAMESPACE,
|
||||
aliases = LauncherAlias.entries.associateWith { it.className },
|
||||
default = LauncherAlias.DEFAULT,
|
||||
)
|
||||
|
||||
/** What the launcher currently shows. Blocking. */
|
||||
fun current(): LauncherEntry = switcher.current().entry
|
||||
|
||||
/** Switch to [entry] (cheap if already active). Blocking. */
|
||||
@Synchronized
|
||||
fun set(entry: LauncherEntry) {
|
||||
switcher.set(LauncherAlias.of(entry))
|
||||
}
|
||||
|
||||
/** Change only the name, keeping the icon. Blocking. */
|
||||
@Synchronized
|
||||
fun setName(name: LauncherName) = set(current().copy(name = name))
|
||||
|
||||
/** Change only the icon, keeping the name. Blocking. */
|
||||
@Synchronized
|
||||
fun setIcon(icon: LauncherIcon) = set(current().copy(icon = icon))
|
||||
|
||||
private companion object {
|
||||
/** The app's namespace, not its suffixed applicationId. Kept in sync with `app/build.gradle.kts`. */
|
||||
const val NAMESPACE = "de.jeanlucmakiola.calendula"
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,8 @@ import de.jeanlucmakiola.calendula.ui.onboarding.OnboardingStep
|
||||
import de.jeanlucmakiola.calendula.ui.theme.FONT_SYSTEM_TOKEN
|
||||
import de.jeanlucmakiola.calendula.widget.WidgetSize
|
||||
import de.jeanlucmakiola.floret.android.stateWhileSubscribed
|
||||
import de.jeanlucmakiola.floret.components.hexDigitsOf
|
||||
import de.jeanlucmakiola.floret.components.parseHexColor
|
||||
import de.jeanlucmakiola.floret.prefs.AppearancePrefs
|
||||
import de.jeanlucmakiola.floret.prefs.Pref
|
||||
import de.jeanlucmakiola.floret.prefs.PrefStore
|
||||
@@ -187,6 +189,7 @@ class SettingsPrefs @Inject constructor(
|
||||
val drawerViewOrder: Flow<List<CalendarView>> = prefs.flow(SettingsKeys.drawerViewOrder)
|
||||
val defaultFormFields: Flow<Set<EventFormField>> = prefs.flow(SettingsKeys.defaultFormFields)
|
||||
val recentTimeZones: Flow<List<String>> = prefs.flow(SettingsKeys.recentTimeZones)
|
||||
val recentCustomColors: Flow<List<Int>> = prefs.flow(SettingsKeys.recentCustomColors)
|
||||
val autofocusEventTitle: Flow<Boolean> = prefs.flow(SettingsKeys.autofocusEventTitle)
|
||||
val defaultNewEventCalendar: Flow<DefaultCalendarRef?> = prefs.flow(SettingsKeys.defaultNewEventCalendar)
|
||||
val defaultEventDurationMinutes: Flow<Int> = prefs.flow(SettingsKeys.defaultEventDurationMinutes)
|
||||
@@ -311,6 +314,11 @@ class SettingsPrefs @Inject constructor(
|
||||
prefs.update(SettingsKeys.recentTimeZones) { (listOf(zoneId) + it).distinct() }
|
||||
}
|
||||
|
||||
/** Moves [argb] to the front of the custom-colour recents shared by the colour pickers. */
|
||||
suspend fun addRecentCustomColor(argb: Int) {
|
||||
prefs.update(SettingsKeys.recentCustomColors) { withRecentColor(it, argb) }
|
||||
}
|
||||
|
||||
suspend fun setAutofocusEventTitle(enabled: Boolean) = prefs.set(SettingsKeys.autofocusEventTitle, enabled)
|
||||
|
||||
/** [calendar] null goes back to Automatic. */
|
||||
@@ -647,6 +655,8 @@ class SettingsPrefs @Inject constructor(
|
||||
setOf(EventFormField.Location, EventFormField.Description)
|
||||
/** Enough to cover the zones a user actually recurs to, without a wall of rows. */
|
||||
internal const val MAX_RECENT_TIME_ZONES = 5
|
||||
/** One row of swatches in the colour pickers. */
|
||||
internal const val MAX_RECENT_CUSTOM_COLORS = 8
|
||||
/** Default automatic-backup interval: daily. */
|
||||
const val DEFAULT_BACKUP_INTERVAL = 1_440L
|
||||
/** Floor for the automatic-backup interval (also above WorkManager's 15-min limit). */
|
||||
@@ -830,6 +840,15 @@ object SettingsKeys {
|
||||
zones.take(SettingsPrefs.MAX_RECENT_TIME_ZONES).joinToString(",")
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom colours the user picked recently, most recent first, as `RRGGBB`
|
||||
* hex joined by commas; unreadable entries are dropped on read.
|
||||
*/
|
||||
val recentCustomColors: Pref<List<Int>> =
|
||||
nullableStringPref("recent_custom_colors").map(::parseRecentColors) { colors ->
|
||||
colors.take(SettingsPrefs.MAX_RECENT_CUSTOM_COLORS).joinToString(LIST_SEP, transform = ::hexDigitsOf)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether opening the new-event form focuses the title field and raises the
|
||||
* keyboard straight away (issue #10). Only the create form auto-focuses.
|
||||
@@ -1251,6 +1270,25 @@ private fun parseRecentTimeZones(stored: String?): List<String> =
|
||||
.distinct()
|
||||
.take(SettingsPrefs.MAX_RECENT_TIME_ZONES)
|
||||
|
||||
private fun parseRecentColors(stored: String?): List<Int> =
|
||||
stored?.split(LIST_SEP).orEmpty()
|
||||
.mapNotNull(::parseHexColor)
|
||||
.distinct()
|
||||
.take(SettingsPrefs.MAX_RECENT_CUSTOM_COLORS)
|
||||
|
||||
/**
|
||||
* [recents] with [argb] (made opaque) moved to the front: an earlier copy is
|
||||
* dropped rather than repeated, and the list stays at most
|
||||
* [SettingsPrefs.MAX_RECENT_CUSTOM_COLORS] long.
|
||||
*/
|
||||
internal fun withRecentColor(recents: List<Int>, argb: Int): List<Int> {
|
||||
val opaque = argb or OPAQUE_ALPHA
|
||||
return (listOf(opaque) + recents.filter { (it or OPAQUE_ALPHA) != opaque })
|
||||
.take(SettingsPrefs.MAX_RECENT_CUSTOM_COLORS)
|
||||
}
|
||||
|
||||
private const val OPAQUE_ALPHA = 0xFF shl 24
|
||||
|
||||
private fun parseFormFields(stored: String?): Set<EventFormField> = when (stored) {
|
||||
null -> SettingsPrefs.DEFAULT_FORM_FIELDS
|
||||
else -> stored.split(',')
|
||||
|
||||
@@ -73,6 +73,10 @@ import de.jeanlucmakiola.calendula.domain.isNotSynced
|
||||
import de.jeanlucmakiola.calendula.domain.orderedForManager
|
||||
import de.jeanlucmakiola.calendula.domain.stateLabels
|
||||
import de.jeanlucmakiola.calendula.data.calendar.CalendarColorPalette
|
||||
import de.jeanlucmakiola.floret.components.sameColor
|
||||
import de.jeanlucmakiola.calendula.ui.common.CustomColorPicker
|
||||
import de.jeanlucmakiola.calendula.ui.common.CustomColorRow
|
||||
import de.jeanlucmakiola.calendula.ui.common.RecentColorsRow
|
||||
import de.jeanlucmakiola.calendula.ui.common.AccountKey
|
||||
import de.jeanlucmakiola.calendula.ui.common.CalendarColorChip
|
||||
import de.jeanlucmakiola.calendula.ui.common.CalendarView
|
||||
@@ -144,6 +148,7 @@ fun CalendarsScreen(
|
||||
val deleteLockedIds by viewModel.deleteLockedCalendarIds.collectAsStateWithLifecycle()
|
||||
val error by viewModel.error.collectAsStateWithLifecycle()
|
||||
val syncAccessDismissed by viewModel.syncAccessDismissed.collectAsStateWithLifecycle()
|
||||
val recentCustomColors by viewModel.recentCustomColors.collectAsStateWithLifecycle()
|
||||
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) { viewModel.refreshAccess() }
|
||||
val loadedHiddenViews by viewModel.hiddenViews.collectAsStateWithLifecycle()
|
||||
val hiddenViews = loadedHiddenViews.orEmpty()
|
||||
@@ -168,6 +173,8 @@ fun CalendarsScreen(
|
||||
showHiddenViews = true,
|
||||
initialHiddenViews = editing?.let { hiddenViews[it.id] }.orEmpty(),
|
||||
deleteLocked = editing != null && editing.id in deleteLockedIds,
|
||||
recentColors = recentCustomColors,
|
||||
onCustomColorUsed = viewModel::addRecentCustomColor,
|
||||
onSave = { name, color, description, views ->
|
||||
val id = editorId
|
||||
if (id == null || id == NEW_CALENDAR_ID) {
|
||||
@@ -408,12 +415,15 @@ internal fun CalendarEditor(
|
||||
deleteLocked: Boolean = false,
|
||||
showHiddenViews: Boolean = false,
|
||||
initialHiddenViews: Set<CalendarView> = emptySet(),
|
||||
recentColors: List<Int> = emptyList(),
|
||||
onCustomColorUsed: (Int) -> Unit = {},
|
||||
) {
|
||||
var name by rememberSaveable(sessionKey) { mutableStateOf(initialName) }
|
||||
val seededHiddenViews = rememberSaveable(sessionKey) { initialHiddenViews }
|
||||
var hiddenViews by rememberSaveable(sessionKey) { mutableStateOf(initialHiddenViews) }
|
||||
var pickHiddenViews by rememberSaveable(sessionKey) { mutableStateOf(false) }
|
||||
var color by rememberSaveable(sessionKey) { mutableStateOf(initialColor) }
|
||||
var pickCustomColor by rememberSaveable(sessionKey) { mutableStateOf(false) }
|
||||
var description by rememberSaveable(sessionKey) { mutableStateOf(initialDescription) }
|
||||
var confirmDelete by remember { mutableStateOf(false) }
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
@@ -462,7 +472,19 @@ internal fun CalendarEditor(
|
||||
|
||||
Spacer(Modifier.height(20.dp))
|
||||
EditorSectionLabel(stringResource(R.string.calendars_color_label))
|
||||
CalendarColorGrid(selected = color, onSelect = { color = it })
|
||||
// A stored colour that is no preset stays as it is and shows as custom.
|
||||
val customColor = color.takeIf { CalendarColorPalette.presetOf(it) == null }
|
||||
CalendarColorGrid(
|
||||
selected = color,
|
||||
recents = recentColors,
|
||||
onSelect = { color = it },
|
||||
onSelectRecent = {
|
||||
color = it
|
||||
onCustomColorUsed(it)
|
||||
},
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
CustomColorRow(customColor = customColor, onClick = { pickCustomColor = true })
|
||||
|
||||
Spacer(Modifier.height(20.dp))
|
||||
EditorSectionLabel(stringResource(R.string.calendars_description_label))
|
||||
@@ -496,6 +518,18 @@ internal fun CalendarEditor(
|
||||
Spacer(Modifier.height(24.dp))
|
||||
}
|
||||
|
||||
if (pickCustomColor) {
|
||||
CustomColorPicker(
|
||||
initial = color,
|
||||
onPick = {
|
||||
color = it
|
||||
onCustomColorUsed(it)
|
||||
pickCustomColor = false
|
||||
},
|
||||
onDismiss = { pickCustomColor = false },
|
||||
)
|
||||
}
|
||||
|
||||
if (pickHiddenViews) {
|
||||
HiddenViewsPicker(
|
||||
calendarName = name.trim().orUnnamed(),
|
||||
@@ -581,7 +615,12 @@ private fun CalendarNameField(
|
||||
* colours" preference included.
|
||||
*/
|
||||
@Composable
|
||||
private fun CalendarColorGrid(selected: Int, onSelect: (Int) -> Unit) {
|
||||
private fun CalendarColorGrid(
|
||||
selected: Int,
|
||||
recents: List<Int>,
|
||||
onSelect: (Int) -> Unit,
|
||||
onSelectRecent: (Int) -> Unit,
|
||||
) {
|
||||
val dark = LocalFloretDarkTheme.current
|
||||
val soften = LocalSoftenColors.current
|
||||
GroupedSurface(position = Position.Alone, modifier = Modifier.padding(horizontal = 16.dp)) {
|
||||
@@ -600,7 +639,7 @@ private fun CalendarColorGrid(selected: Int, onSelect: (Int) -> Unit) {
|
||||
ColorSwatch(
|
||||
fill = eventFill(swatch, dark, soften),
|
||||
label = stringResource(swatchLabel(swatch)),
|
||||
selected = swatch == selected,
|
||||
selected = sameColor(swatch, selected),
|
||||
onClick = { onSelect(swatch) },
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
@@ -610,6 +649,12 @@ private fun CalendarColorGrid(selected: Int, onSelect: (Int) -> Unit) {
|
||||
repeat(SWATCHES_PER_ROW - row.size) { Spacer(Modifier.weight(1f)) }
|
||||
}
|
||||
}
|
||||
RecentColorsRow(
|
||||
recents = recents,
|
||||
selected = selected.takeIf { CalendarColorPalette.presetOf(it) == null },
|
||||
onSelect = onSelectRecent,
|
||||
modifier = Modifier.padding(horizontal = 4.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +150,14 @@ class CalendarsViewModel @Inject constructor(
|
||||
settingsPrefs.setCalendarHiddenIn(id, view, hidden)
|
||||
}
|
||||
|
||||
/** Recently used custom colours, shared with the event-colour picker. */
|
||||
val recentCustomColors: StateFlow<List<Int>> =
|
||||
settingsPrefs.recentCustomColors
|
||||
.catch { emit(emptyList()) }
|
||||
.stateWhileSubscribed(scope = viewModelScope, initialValue = emptyList())
|
||||
|
||||
fun addRecentCustomColor(argb: Int) = write { settingsPrefs.addRecentCustomColor(argb) }
|
||||
|
||||
private val _error = MutableStateFlow(false)
|
||||
val error: StateFlow<Boolean> = _error.asStateFlow()
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package de.jeanlucmakiola.calendula.ui.common
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||
@@ -18,7 +17,13 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import de.jeanlucmakiola.floret.components.sameColor
|
||||
import de.jeanlucmakiola.floret.components.formatHexColor
|
||||
|
||||
/**
|
||||
* A wrapping row of round colour swatches; the one matching [selected] is
|
||||
@@ -39,7 +44,7 @@ fun ColorSwatchRow(
|
||||
val soften = LocalSoftenColors.current
|
||||
FlowRow(modifier = modifier, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
colors.forEach { argb ->
|
||||
val isSelected = argb == selected
|
||||
val isSelected = sameColor(argb, selected)
|
||||
val fill = eventFill(argb, dark, soften)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
@@ -55,7 +60,8 @@ fun ColorSwatchRow(
|
||||
Modifier
|
||||
},
|
||||
)
|
||||
.clickable { onSelect(argb) },
|
||||
.selectable(selected = isSelected, role = Role.RadioButton) { onSelect(argb) }
|
||||
.semantics { contentDescription = formatHexColor(argb) },
|
||||
) {
|
||||
if (isSelected) {
|
||||
Icon(
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
package de.jeanlucmakiola.calendula.ui.common
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
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.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Palette
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import de.jeanlucmakiola.calendula.R
|
||||
import de.jeanlucmakiola.floret.components.ColorPicker
|
||||
import de.jeanlucmakiola.floret.components.FullScreenPicker
|
||||
import de.jeanlucmakiola.floret.components.GroupedRow
|
||||
import de.jeanlucmakiola.floret.components.GroupedSurface
|
||||
import de.jeanlucmakiola.floret.components.Position
|
||||
import de.jeanlucmakiola.floret.components.formatHexColor
|
||||
import de.jeanlucmakiola.floret.identity.LocalFloretDarkTheme
|
||||
|
||||
/**
|
||||
* The recently used custom colours under a "Recent" label; nothing when there
|
||||
* are none. Shared by the calendar editor and the event-colour picker.
|
||||
*/
|
||||
@Composable
|
||||
fun RecentColorsRow(
|
||||
recents: List<Int>,
|
||||
selected: Int?,
|
||||
onSelect: (Int) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
if (recents.isEmpty()) return
|
||||
Column(modifier) {
|
||||
Text(
|
||||
text = stringResource(R.string.color_custom_recent),
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
ColorSwatchRow(
|
||||
colors = recents,
|
||||
selected = selected,
|
||||
onSelect = onSelect,
|
||||
dark = LocalFloretDarkTheme.current,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The entry that opens [CustomColorPicker]. When the current colour is a custom
|
||||
* one ([customColor] non-null) the row is the selection: it carries that
|
||||
* colour's swatch and hex code.
|
||||
*/
|
||||
@Composable
|
||||
fun CustomColorRow(
|
||||
customColor: Int?,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.color_custom),
|
||||
summary = customColor?.let(::formatHexColor),
|
||||
position = Position.Alone,
|
||||
selected = customColor != null,
|
||||
modifier = modifier,
|
||||
leading = {
|
||||
if (customColor != null) {
|
||||
Box(
|
||||
Modifier
|
||||
.size(32.dp)
|
||||
.clip(CircleShape)
|
||||
.background(
|
||||
eventFill(customColor, LocalFloretDarkTheme.current, LocalSoftenColors.current),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
Icon(Icons.Default.Palette, contentDescription = null)
|
||||
}
|
||||
},
|
||||
onClick = onClick,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Full-screen custom-colour surface: a preview painted the way the app will
|
||||
* paint the colour, over the hue/saturation/brightness picker and hex field.
|
||||
* The colour is committed through Select in the title bar.
|
||||
*/
|
||||
@Composable
|
||||
fun CustomColorPicker(
|
||||
initial: Int,
|
||||
onPick: (Int) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
var color by rememberSaveable { mutableIntStateOf(initial or (0xFF shl 24)) }
|
||||
FullScreenPicker(
|
||||
title = stringResource(R.string.color_custom),
|
||||
onDismiss = onDismiss,
|
||||
predictiveBack = true,
|
||||
actions = {
|
||||
Button(
|
||||
onClick = { onPick(color) },
|
||||
modifier = Modifier.padding(end = 12.dp),
|
||||
) { Text(stringResource(R.string.color_custom_select)) }
|
||||
},
|
||||
) {
|
||||
val fill = eventFill(color, LocalFloretDarkTheme.current, LocalSoftenColors.current)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp)
|
||||
.fillMaxWidth()
|
||||
.height(72.dp)
|
||||
.clip(RoundedCornerShape(22.dp))
|
||||
.background(fill)
|
||||
.padding(horizontal = 20.dp),
|
||||
contentAlignment = Alignment.CenterStart,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.color_custom_preview),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
color = eventInk(fill),
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.height(16.dp))
|
||||
GroupedSurface(position = Position.Alone, modifier = Modifier.padding(horizontal = 16.dp)) {
|
||||
ColorPicker(
|
||||
color = color,
|
||||
onColorChange = { color = it },
|
||||
hueLabel = stringResource(R.string.color_custom_hue),
|
||||
saturationLabel = stringResource(R.string.color_custom_saturation),
|
||||
brightnessLabel = stringResource(R.string.color_custom_brightness),
|
||||
hexLabel = stringResource(R.string.color_custom_hex),
|
||||
hexError = stringResource(R.string.color_custom_hex_error),
|
||||
modifier = Modifier.padding(20.dp),
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.height(24.dp))
|
||||
}
|
||||
}
|
||||
@@ -151,6 +151,9 @@ import de.jeanlucmakiola.calendula.ui.common.RecurringScopeDialog
|
||||
import de.jeanlucmakiola.calendula.ui.common.CalendarPickerGroups
|
||||
import de.jeanlucmakiola.calendula.ui.common.CalendarDatePickerDialog
|
||||
import de.jeanlucmakiola.calendula.ui.common.ColorSwatchRow
|
||||
import de.jeanlucmakiola.calendula.ui.common.CustomColorPicker
|
||||
import de.jeanlucmakiola.calendula.ui.common.CustomColorRow
|
||||
import de.jeanlucmakiola.calendula.ui.common.RecentColorsRow
|
||||
import de.jeanlucmakiola.calendula.ui.common.TimeZonePickerDialog
|
||||
import de.jeanlucmakiola.calendula.ui.common.icuTimeZoneRegion
|
||||
import de.jeanlucmakiola.calendula.ui.common.LocalSoftenColors
|
||||
@@ -1557,6 +1560,7 @@ private fun EditSheetHost(
|
||||
selected = form.color,
|
||||
hasExplicitColor = form.color != null,
|
||||
syncWarning = colorSyncRisk,
|
||||
recents = state.recentCustomColors,
|
||||
onPickKey = { key, argb ->
|
||||
viewModel.setColorKey(key, argb)
|
||||
onClose()
|
||||
@@ -1565,6 +1569,10 @@ private fun EditSheetHost(
|
||||
viewModel.setColorRaw(argb)
|
||||
onClose()
|
||||
},
|
||||
onPickCustom = { argb ->
|
||||
viewModel.setCustomColor(argb)
|
||||
onClose()
|
||||
},
|
||||
onClear = {
|
||||
viewModel.clearColor()
|
||||
onClose()
|
||||
@@ -2388,11 +2396,13 @@ private fun VisibilityPickerDialog(
|
||||
}
|
||||
|
||||
/**
|
||||
* Event-colour picker: just the swatches. A non-empty [palette] (the calendar
|
||||
* account's published colours) picks by key so the colour round-trips through
|
||||
* sync; otherwise the app's own palette writes a raw colour, with a
|
||||
* [syncWarning] when that calendar may not keep it. The "Reset" button (shown
|
||||
* only once a colour is set) drops back to the calendar's own colour.
|
||||
* Event-colour picker. A non-empty [palette] (the calendar account's published
|
||||
* colours) picks by key so the colour round-trips through sync; such an account
|
||||
* rejects any other colour, so there is no custom entry. Otherwise the app's
|
||||
* own presets, the recent custom colours and a custom entry write a raw colour,
|
||||
* with a [syncWarning] when that calendar may not keep it. A raw colour that is
|
||||
* no preset shows as the custom selection. "Reset" (shown only once a colour is
|
||||
* set) drops back to the calendar's own colour.
|
||||
*/
|
||||
@Composable
|
||||
private fun ColorPickerDialog(
|
||||
@@ -2400,12 +2410,16 @@ private fun ColorPickerDialog(
|
||||
selected: Int?,
|
||||
hasExplicitColor: Boolean,
|
||||
syncWarning: Boolean,
|
||||
recents: List<Int>,
|
||||
onPickKey: (String, Int) -> Unit,
|
||||
onPickRaw: (Int) -> Unit,
|
||||
onPickCustom: (Int) -> Unit,
|
||||
onClear: () -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
val dark = LocalFloretDarkTheme.current
|
||||
var pickCustom by rememberSaveable { mutableStateOf(false) }
|
||||
val customColor = selected?.takeIf { palette.isEmpty() && CalendarColorPalette.presetOf(it) == null }
|
||||
FullScreenPicker(
|
||||
title = stringResource(R.string.event_edit_color),
|
||||
onDismiss = onDismiss,
|
||||
@@ -2440,6 +2454,11 @@ private fun ColorPickerDialog(
|
||||
},
|
||||
dark = dark,
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.color_custom_keyed_only),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
} else {
|
||||
ColorSwatchRow(
|
||||
colors = CalendarColorPalette.all,
|
||||
@@ -2447,15 +2466,31 @@ private fun ColorPickerDialog(
|
||||
onSelect = onPickRaw,
|
||||
dark = dark,
|
||||
)
|
||||
if (syncWarning) {
|
||||
Text(
|
||||
text = stringResource(R.string.event_edit_color_sync_warning),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
RecentColorsRow(recents = recents, selected = customColor, onSelect = onPickCustom)
|
||||
}
|
||||
}
|
||||
if (palette.isEmpty()) {
|
||||
Spacer(Modifier.height(4.dp))
|
||||
CustomColorRow(customColor = customColor, onClick = { pickCustom = true })
|
||||
if (syncWarning) {
|
||||
Text(
|
||||
text = stringResource(R.string.event_edit_color_sync_warning),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(horizontal = 24.dp, vertical = 12.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pickCustom) {
|
||||
CustomColorPicker(
|
||||
initial = selected ?: recents.firstOrNull() ?: CalendarColorPalette.Blue,
|
||||
onPick = {
|
||||
pickCustom = false
|
||||
onPickCustom(it)
|
||||
},
|
||||
onDismiss = { pickCustom = false },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ data class EventEditUiState(
|
||||
val hiddenFields: List<EventFormField> = emptyList(),
|
||||
/** Recently picked zones, most recent first — the zone picker's shortlist. */
|
||||
val recentTimeZones: List<String> = emptyList(),
|
||||
/** Recently used custom colours, most recent first; shared with the calendar editor. */
|
||||
val recentCustomColors: List<Int> = emptyList(),
|
||||
/** True while editing an existing event (the calendar is then fixed). */
|
||||
val isEditing: Boolean = false,
|
||||
/**
|
||||
|
||||
@@ -318,8 +318,8 @@ class EventEditViewModel @Inject constructor(
|
||||
).flowOn(io),
|
||||
colorPalette,
|
||||
allCalendars,
|
||||
settingsPrefs.recentTimeZones.flowOn(io),
|
||||
) { local, external, palette, allCalendars, recentTimeZones ->
|
||||
combine(settingsPrefs.recentTimeZones, settingsPrefs.recentCustomColors, ::Pair).flowOn(io),
|
||||
) { local, external, palette, allCalendars, (recentTimeZones, recentCustomColors) ->
|
||||
val form = local.form ?: return@combine null
|
||||
val resolvedId = resolveEventCalendar(form.calendarId, external.hints, allCalendars)
|
||||
// A colour is scoped to the calendar it came from, so one that came with
|
||||
@@ -359,6 +359,7 @@ class EventEditViewModel @Inject constructor(
|
||||
visibleFields = visibleFields,
|
||||
hiddenFields = (offerableFields - visibleFields).sorted(),
|
||||
recentTimeZones = recentTimeZones,
|
||||
recentCustomColors = recentCustomColors,
|
||||
isEditing = local.editTarget != null,
|
||||
isManaged = isManaged,
|
||||
autofocusTitle = external.autofocusTitle,
|
||||
@@ -742,6 +743,12 @@ class EventEditViewModel @Inject constructor(
|
||||
edit { it.copy(colorKey = null, color = argb) }
|
||||
}
|
||||
|
||||
/** Pick a custom raw colour, which also goes to the front of the custom-colour recents. */
|
||||
fun setCustomColor(argb: Int) {
|
||||
setColorRaw(argb)
|
||||
viewModelScope.launch { withContext(io) { settingsPrefs.addRecentCustomColor(argb) } }
|
||||
}
|
||||
|
||||
/** Clear the colour so the event inherits its calendar's. */
|
||||
fun clearColor() {
|
||||
pinShownCalendar()
|
||||
|
||||
@@ -48,8 +48,7 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import de.jeanlucmakiola.calendula.R
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherIcon
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherName
|
||||
import de.jeanlucmakiola.calendula.data.appname.LauncherName
|
||||
import de.jeanlucmakiola.floret.prefs.ThemeMode
|
||||
import de.jeanlucmakiola.calendula.domain.FontRole
|
||||
import de.jeanlucmakiola.calendula.ui.theme.BundledFont
|
||||
@@ -68,7 +67,7 @@ import de.jeanlucmakiola.floret.components.positionOf
|
||||
|
||||
/**
|
||||
* Appearance: how the app itself looks — theme and colour, the two typeface
|
||||
* roles, and the launcher name and icon. Anything that only changes how a *calendar view*
|
||||
* roles, and the launcher name. Anything that only changes how a *calendar view*
|
||||
* reads (week start, time format, grid options) lives in [ViewsScreen] instead,
|
||||
* and the widget-only settings in [WidgetsScreen] (#69).
|
||||
*/
|
||||
@@ -83,10 +82,9 @@ internal fun AppearanceScreen(
|
||||
var showBrandFont by remember { mutableStateOf(false) }
|
||||
var showPlainFont by remember { mutableStateOf(false) }
|
||||
var showAppName by remember { mutableStateOf(false) }
|
||||
var showAppIcon by remember { mutableStateOf(false) }
|
||||
|
||||
val fonts by viewModel.fontState.collectAsStateWithLifecycle()
|
||||
val launcher by viewModel.launcher.collectAsStateWithLifecycle()
|
||||
val launcherName by viewModel.launcherName.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
val importFailedMessage = stringResource(R.string.settings_font_import_failed)
|
||||
LaunchedEffect(Unit) {
|
||||
@@ -155,20 +153,14 @@ internal fun AppearanceScreen(
|
||||
|
||||
Spacer(Modifier.height(16.dp))
|
||||
|
||||
// The launcher label (#44) and icon (#451); their own group, being a
|
||||
// App name — the launcher label (#44); its own group, being a
|
||||
// launcher concern rather than app styling.
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.settings_app_name),
|
||||
summary = launcherNameLabel(launcher.name),
|
||||
position = Position.Top,
|
||||
summary = launcherNameLabel(launcherName),
|
||||
position = Position.Alone,
|
||||
onClick = { showAppName = true },
|
||||
)
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.settings_app_icon),
|
||||
summary = launcherIconLabel(launcher.icon),
|
||||
position = Position.Bottom,
|
||||
onClick = { showAppIcon = true },
|
||||
)
|
||||
}
|
||||
|
||||
if (showAppName) {
|
||||
@@ -196,10 +188,9 @@ internal fun AppearanceScreen(
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
LauncherName.entries.forEach { option ->
|
||||
LauncherOptionCard(
|
||||
icon = launcher.icon,
|
||||
label = launcherNameLabel(option),
|
||||
selected = launcher.name == option,
|
||||
AppNameOptionCard(
|
||||
name = option,
|
||||
selected = launcherName == option,
|
||||
onClick = { viewModel.setLauncherName(option) },
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
@@ -207,40 +198,6 @@ internal fun AppearanceScreen(
|
||||
}
|
||||
}
|
||||
}
|
||||
if (showAppIcon) {
|
||||
FullScreenPicker(
|
||||
title = stringResource(R.string.settings_app_icon),
|
||||
onDismiss = { showAppIcon = false },
|
||||
predictiveBack = true,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.settings_app_icon_summary),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 24.dp),
|
||||
)
|
||||
Spacer(Modifier.height(24.dp))
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
LauncherIcon.entries.forEach { option ->
|
||||
LauncherOptionCard(
|
||||
icon = option,
|
||||
label = launcherIconLabel(option),
|
||||
selected = launcher.icon == option,
|
||||
onClick = { viewModel.setLauncherIcon(option) },
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (showTheme) {
|
||||
// No thumbnails: picking a theme repaints the app itself. Only which
|
||||
// way "Follow the system" currently falls needs spelling out.
|
||||
@@ -318,15 +275,6 @@ private fun launcherNameLabel(name: LauncherName): String = stringResource(
|
||||
},
|
||||
)
|
||||
|
||||
/** The display name for a launcher-icon choice (issue #451). */
|
||||
@Composable
|
||||
private fun launcherIconLabel(icon: LauncherIcon): String = stringResource(
|
||||
when (icon) {
|
||||
LauncherIcon.BLOOM -> R.string.settings_app_icon_bloom
|
||||
LauncherIcon.PLAIN -> R.string.settings_app_icon_plain
|
||||
},
|
||||
)
|
||||
|
||||
/**
|
||||
* MIME types offered to the document picker so it lists only font files. Covers
|
||||
* the modern `font/` types plus the legacy `application/` font aliases some
|
||||
@@ -471,13 +419,12 @@ private fun FontOptionRow(
|
||||
}
|
||||
|
||||
/**
|
||||
* One selectable launcher preview in the App name (#44) and App icon (#451)
|
||||
* pickers: the launcher mark over its label, framed as a card.
|
||||
* One selectable launcher-name preview in the App name picker (#44): the app's
|
||||
* launcher mark over the name, framed as a card.
|
||||
*/
|
||||
@Composable
|
||||
private fun LauncherOptionCard(
|
||||
icon: LauncherIcon,
|
||||
label: String,
|
||||
private fun AppNameOptionCard(
|
||||
name: LauncherName,
|
||||
selected: Boolean,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
@@ -512,18 +459,13 @@ private fun LauncherOptionCard(
|
||||
.background(colorResource(R.color.ic_launcher_background)),
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(
|
||||
when (icon) {
|
||||
LauncherIcon.BLOOM -> R.drawable.ic_launcher_foreground
|
||||
LauncherIcon.PLAIN -> R.drawable.ic_launcher_foreground_plain
|
||||
},
|
||||
),
|
||||
painter = painterResource(R.drawable.ic_launcher_foreground),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = label,
|
||||
text = launcherNameLabel(name),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
textAlign = TextAlign.Center,
|
||||
|
||||
@@ -10,10 +10,8 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherName
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherEntry
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherIcon
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherManager
|
||||
import de.jeanlucmakiola.calendula.data.appname.LauncherName
|
||||
import de.jeanlucmakiola.calendula.data.appname.LauncherNameManager
|
||||
import de.jeanlucmakiola.calendula.data.calendar.CalendarRepository
|
||||
import de.jeanlucmakiola.calendula.data.contacts.SpecialDatesCalendarSpec
|
||||
import de.jeanlucmakiola.calendula.data.contacts.SpecialDatesScheduler
|
||||
@@ -92,7 +90,7 @@ class SettingsViewModel @Inject constructor(
|
||||
repository: CalendarRepository,
|
||||
private val specialDatesEngine: SpecialDatesSyncEngine,
|
||||
specialDatesSpec: SpecialDatesCalendarSpec,
|
||||
private val launcherManager: LauncherManager,
|
||||
private val launcherNameManager: LauncherNameManager,
|
||||
private val reminderScanner: ReminderScanner,
|
||||
private val reminderChannels: ReminderChannels,
|
||||
private val reminderNotifier: ReminderNotifier,
|
||||
@@ -202,17 +200,17 @@ class SettingsViewModel @Inject constructor(
|
||||
)
|
||||
|
||||
/**
|
||||
* The launcher name (#44) and icon (#451), backed by the manifest aliases'
|
||||
* The launcher-label choice (#44), backed by the manifest aliases'
|
||||
* component-enabled state rather than a preference. Seeded with the manifest
|
||||
* default and corrected off-thread — `getComponentEnabledSetting` is a
|
||||
* binder round-trip and this ViewModel is built on the main thread.
|
||||
*/
|
||||
private val _launcher = MutableStateFlow(LauncherEntry())
|
||||
val launcher: StateFlow<LauncherEntry> = _launcher.asStateFlow()
|
||||
private val _launcherName = MutableStateFlow(LauncherName.CALENDULA)
|
||||
val launcherName: StateFlow<LauncherName> = _launcherName.asStateFlow()
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
_launcher.value = withContext(io) { launcherManager.current() }
|
||||
_launcherName.value = withContext(io) { launcherNameManager.current() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,20 +354,16 @@ class SettingsViewModel @Inject constructor(
|
||||
fun setTapOpensEditor(enabled: Boolean) = save { setTapOpensEditor(enabled) }
|
||||
|
||||
/**
|
||||
* Switch the launcher label (#44) or icon (#451). The card highlights at
|
||||
* once, then settles on what the component state reports; the writes are
|
||||
* binder round-trips and run off the main thread.
|
||||
* Switch the launcher label (#44). The card highlights at once, then settles
|
||||
* on what the component state reports; the writes are binder round-trips and
|
||||
* run off the main thread.
|
||||
*/
|
||||
fun setLauncherName(name: LauncherName) = updateLauncher({ copy(name = name) }) { setName(name) }
|
||||
|
||||
fun setLauncherIcon(icon: LauncherIcon) = updateLauncher({ copy(icon = icon) }) { setIcon(icon) }
|
||||
|
||||
private fun updateLauncher(optimistic: LauncherEntry.() -> LauncherEntry, write: LauncherManager.() -> Unit) {
|
||||
_launcher.value = _launcher.value.optimistic()
|
||||
fun setLauncherName(name: LauncherName) {
|
||||
_launcherName.value = name
|
||||
viewModelScope.launch {
|
||||
_launcher.value = withContext(io) {
|
||||
launcherManager.write()
|
||||
launcherManager.current()
|
||||
_launcherName.value = withContext(io) {
|
||||
launcherNameManager.set(name)
|
||||
launcherNameManager.current()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
The plain launcher icon foreground (issue #451): the Calendula mark's
|
||||
calendar and "1" without the bloom badge, the bottom-right corner closed.
|
||||
Offered in Settings > Appearance > App icon (LauncherManager) and reused
|
||||
as the <monochrome> slot for themed-icon launchers.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="232"
|
||||
android:viewportHeight="232">
|
||||
<!-- Same centring and 0.50 scale as ic_launcher_foreground. -->
|
||||
<group
|
||||
android:pivotX="114"
|
||||
android:pivotY="108"
|
||||
android:scaleX="0.50"
|
||||
android:scaleY="0.50"
|
||||
android:translateX="2"
|
||||
android:translateY="8">
|
||||
<!-- Calendar body (rounded square with horizontal header divider) -->
|
||||
<path
|
||||
android:strokeColor="#FFFAF6F0"
|
||||
android:strokeWidth="12"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeMiterLimit="12"
|
||||
android:pathData="M43,69H185M185,153V63C185,48.64 173.359,37 159,37H69C54.64,37 43,48.64 43,63V153C43,167.359 54.64,179 69,179H159C173.359,179 185,167.359 185,153Z" />
|
||||
<!-- Numeral "1" inside the calendar body -->
|
||||
<path
|
||||
android:strokeColor="#FFFAF6F0"
|
||||
android:strokeWidth="12"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"
|
||||
android:pathData="M103,110L113.999,99V142.428" />
|
||||
</group>
|
||||
</vector>
|
||||
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground_plain" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground_plain" />
|
||||
</adaptive-icon>
|
||||
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground_plain" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground_plain" />
|
||||
</adaptive-icon>
|
||||
@@ -620,10 +620,6 @@
|
||||
<string name="settings_today_toolbar_summary">Show a jump-to-today button in the toolbar instead of a floating button</string>
|
||||
<string name="settings_app_name">App name</string>
|
||||
<string name="settings_app_name_summary">Show Calendula as “Calendar” in your launcher. Only the launcher name changes; the icon may move to a new spot after switching.</string>
|
||||
<string name="settings_app_icon">App icon</string>
|
||||
<string name="settings_app_icon_summary">The icon your launcher shows. After switching, the icon may move to a new spot.</string>
|
||||
<string name="settings_app_icon_bloom">Bloom</string>
|
||||
<string name="settings_app_icon_plain">Plain</string>
|
||||
<string name="settings_time_format">Time format</string>
|
||||
<string name="settings_time_format_auto">Automatic</string>
|
||||
<string name="settings_time_format_12h">12-hour (2:00 PM)</string>
|
||||
@@ -998,6 +994,16 @@
|
||||
<string name="color_name_indigo">Indigo</string>
|
||||
<string name="color_name_purple">Purple</string>
|
||||
<string name="color_name_pink">Pink</string>
|
||||
<string name="color_custom">Custom color</string>
|
||||
<string name="color_custom_recent">Recent</string>
|
||||
<string name="color_custom_hue">Hue</string>
|
||||
<string name="color_custom_saturation">Saturation</string>
|
||||
<string name="color_custom_brightness">Brightness</string>
|
||||
<string name="color_custom_hex">Hex code</string>
|
||||
<string name="color_custom_hex_error">Enter a 6-digit hex code</string>
|
||||
<string name="color_custom_select">Select</string>
|
||||
<string name="color_custom_preview">Preview</string>
|
||||
<string name="color_custom_keyed_only">This calendar\'s account only allows its own colors.</string>
|
||||
<string name="calendars_delete_confirm_title">Delete calendar?</string>
|
||||
<string name="calendars_delete_confirm_message">\"%1$s\" and all of its events will be permanently removed from this device.</string>
|
||||
<string name="calendars_write_error">Couldn\'t save the change.</string>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package de.jeanlucmakiola.calendula.data.appname
|
||||
|
||||
import android.content.pm.PackageManager
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/**
|
||||
* Pure decision logic behind the app-name toggle (issue #44). The framework seam
|
||||
* ([LauncherNameManager.set]/[current], which call `PackageManager`) is covered
|
||||
* on-device; these tests pin the read interpretation and the write ordering.
|
||||
*/
|
||||
class LauncherNameManagerTest {
|
||||
|
||||
@Test
|
||||
fun `enabled calendar alias reads as CALENDAR`() {
|
||||
assertThat(launcherNameFor(PackageManager.COMPONENT_ENABLED_STATE_ENABLED))
|
||||
.isEqualTo(LauncherName.CALENDAR)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `default and disabled calendar alias read as CALENDULA`() {
|
||||
assertThat(launcherNameFor(PackageManager.COMPONENT_ENABLED_STATE_DEFAULT))
|
||||
.isEqualTo(LauncherName.CALENDULA)
|
||||
assertThat(launcherNameFor(PackageManager.COMPONENT_ENABLED_STATE_DISABLED))
|
||||
.isEqualTo(LauncherName.CALENDULA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `write plan enables the target alias before disabling the other`() {
|
||||
val toCalendar = aliasWritePlan(LauncherName.CALENDAR)
|
||||
assertThat(toCalendar).containsExactly(
|
||||
AliasStateChange(LauncherAlias.CALENDAR, enabled = true),
|
||||
AliasStateChange(LauncherAlias.DEFAULT, enabled = false),
|
||||
).inOrder()
|
||||
|
||||
val toCalendula = aliasWritePlan(LauncherName.CALENDULA)
|
||||
assertThat(toCalendula).containsExactly(
|
||||
AliasStateChange(LauncherAlias.DEFAULT, enabled = true),
|
||||
AliasStateChange(LauncherAlias.CALENDAR, enabled = false),
|
||||
).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `write plan never disables both aliases in the same step`() {
|
||||
// The first step is always an enable, so the launcher can never observe a
|
||||
// zero-entry transient regardless of switch direction.
|
||||
for (target in LauncherName.entries) {
|
||||
assertThat(aliasWritePlan(target).first().enabled).isTrue()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,7 @@ package de.jeanlucmakiola.calendula.data.backup
|
||||
import androidx.datastore.preferences.core.MutablePreferences
|
||||
import androidx.datastore.preferences.core.mutablePreferencesOf
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherEntry
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherIcon
|
||||
import de.jeanlucmakiola.calendula.data.launcher.LauncherName
|
||||
import de.jeanlucmakiola.calendula.data.appname.LauncherName
|
||||
import de.jeanlucmakiola.calendula.data.calendar.ManagedCalendarRow
|
||||
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefKeys
|
||||
import de.jeanlucmakiola.calendula.data.prefs.FixedTimeOverride
|
||||
@@ -57,7 +55,7 @@ class SettingsBackupTest {
|
||||
calendars = calendars,
|
||||
managed = listOf(ManagedCalendarRow(3, SpecialDateType.Birthday)),
|
||||
language = LanguageChoice("de"),
|
||||
launcher = LauncherEntry(LauncherName.CALENDAR, LauncherIcon.PLAIN),
|
||||
launcherName = LauncherName.CALENDAR,
|
||||
)
|
||||
val decoded = decodeSettingsBackup(encodeSettingsBackup(backup, 1_700_000_000_000, "2.25.0"))
|
||||
return (decoded as BackupResult.Success).value
|
||||
@@ -360,10 +358,6 @@ class SettingsBackupTest {
|
||||
|
||||
assertThat(backup.language).isEqualTo(LanguageChoice("de"))
|
||||
assertThat(backup.launcherName).isEqualTo(LauncherName.CALENDAR)
|
||||
assertThat(backup.launcherIcon).isEqualTo(LauncherIcon.PLAIN)
|
||||
val plan = planSettingsImport(backup, mutablePreferencesOf(), environment())
|
||||
assertThat(plan.launcherName).isEqualTo(LauncherName.CALENDAR)
|
||||
assertThat(plan.launcherIcon).isEqualTo(LauncherIcon.PLAIN)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -372,7 +366,7 @@ class SettingsBackupTest {
|
||||
{"format":"calendula-settings","version":1,"exportedAt":1,"future":{"x":1},
|
||||
"settings":{"multi_day_count":4,"some_new_key":true},
|
||||
"calendars":[{"account_name":"a","account_type":"t","display_name":"d","colour":"red"}],
|
||||
"app":{"launcher_name":"SOMETHING_NEW","launcher_icon":"SOMETHING_NEW"}}
|
||||
"app":{"launcher_name":"SOMETHING_NEW"}}
|
||||
""".trimIndent()
|
||||
|
||||
val backup = (decodeSettingsBackup(text) as BackupResult.Success).value
|
||||
@@ -380,7 +374,6 @@ class SettingsBackupTest {
|
||||
assertThat(backup.prefs.values).containsExactly(4)
|
||||
assertThat(backup.calendars).hasSize(1)
|
||||
assertThat(backup.launcherName).isNull()
|
||||
assertThat(backup.launcherIcon).isNull()
|
||||
assertThat(backup.language).isNull()
|
||||
}
|
||||
|
||||
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package de.jeanlucmakiola.calendula.data.calendar
|
||||
|
||||
import com.google.common.truth.Truth.assertWithMessage
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.domain.color.eventTone
|
||||
import de.jeanlucmakiola.calendula.domain.color.oklchOf
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.math.pow
|
||||
|
||||
class CalendarColorPaletteTest {
|
||||
|
||||
private val palette = CalendarColorPalette.all
|
||||
|
||||
@Test
|
||||
fun `painted swatches stay apart in both themes`() {
|
||||
assertMinDistance("light fill", MIN_FILL_DISTANCE) { eventTone(it, dark = false, harmonise = true).container }
|
||||
assertMinDistance("dark fill", MIN_FILL_DISTANCE) { eventTone(it, dark = true, harmonise = true).container }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `raw swatches stay apart with softening off`() {
|
||||
assertMinDistance("raw", MIN_FILL_DISTANCE) { it }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `accents (dots, stripes) stay apart in both themes`() {
|
||||
assertMinDistance("light accent", MIN_ACCENT_DISTANCE) { eventTone(it, dark = false, harmonise = true).accent }
|
||||
assertMinDistance("dark accent", MIN_ACCENT_DISTANCE) { eventTone(it, dark = true, harmonise = true).accent }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `no two painted swatches merge under a colour-vision deficiency`() {
|
||||
for ((name, matrix) in CVD) {
|
||||
for (dark in listOf(false, true)) {
|
||||
assertMinDistance("$name dark=$dark", MIN_CVD_DISTANCE) {
|
||||
simulate(eventTone(it, dark, harmonise = true).container, matrix)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a stored preset matches regardless of alpha`() {
|
||||
assertThat(CalendarColorPalette.presetOf(CalendarColorPalette.Green)).isEqualTo(CalendarColorPalette.Green)
|
||||
val translucentBlue = CalendarColorPalette.Blue and 0x00FFFFFF
|
||||
assertThat(CalendarColorPalette.presetOf(translucentBlue)).isEqualTo(CalendarColorPalette.Blue)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a colour from the old palette or anywhere else is custom`() {
|
||||
val oldGreen = 0xFF35A06A.toInt()
|
||||
assertThat(CalendarColorPalette.presetOf(oldGreen)).isNull()
|
||||
assertThat(CalendarColorPalette.presetOf(0xFF123456.toInt())).isNull()
|
||||
assertThat(CalendarColorPalette.presetOf(null)).isNull()
|
||||
}
|
||||
|
||||
private fun assertMinDistance(label: String, min: Float, paint: (Int) -> Int) {
|
||||
val painted = palette.map(paint).map(::oklchOf)
|
||||
for (i in painted.indices) for (j in i + 1 until painted.size) {
|
||||
assertWithMessage("$label: ${hex(palette[i])} vs ${hex(palette[j])}")
|
||||
.that(painted[i].distanceTo(painted[j]))
|
||||
.isAtLeast(min)
|
||||
}
|
||||
}
|
||||
|
||||
private fun hex(argb: Int) = "#%06X".format(argb and 0xFFFFFF)
|
||||
|
||||
/** [argb] as seen with a dichromacy, via a Machado et al. (2009) severity-1 matrix on linear RGB. */
|
||||
private fun simulate(argb: Int, m: Array<DoubleArray>): Int {
|
||||
val rgb = listOf(16, 8, 0).map { toLinear(((argb shr it) and 0xFF) / 255.0) }
|
||||
val out = m.map { row -> row.indices.sumOf { row[it] * rgb[it] } }
|
||||
.map { (toSrgb(it.coerceIn(0.0, 1.0)) * 255.0).toInt().coerceIn(0, 255) }
|
||||
return (0xFF shl 24) or (out[0] shl 16) or (out[1] shl 8) or out[2]
|
||||
}
|
||||
|
||||
private fun toLinear(c: Double) = if (c <= 0.04045) c / 12.92 else ((c + 0.055) / 1.055).pow(2.4)
|
||||
private fun toSrgb(c: Double) = if (c <= 0.0031308) 12.92 * c else 1.055 * c.pow(1 / 2.4) - 0.055
|
||||
|
||||
private companion object {
|
||||
/** Oklab distance; the palette before #198 had Olive/Green and Teal/Cyan at 0.056. */
|
||||
const val MIN_FILL_DISTANCE = 0.075f
|
||||
/** Accents share one lightness per theme, so only hue and chroma separate them. */
|
||||
const val MIN_ACCENT_DISTANCE = 0.04f
|
||||
/**
|
||||
* Twelve hues at two lightness levels can't all stay far apart for a
|
||||
* dichromat; this only rules out two swatches turning into one.
|
||||
*/
|
||||
const val MIN_CVD_DISTANCE = 0.01f
|
||||
|
||||
val CVD = mapOf(
|
||||
"protanopia" to arrayOf(
|
||||
doubleArrayOf(0.152286, 1.052583, -0.204868),
|
||||
doubleArrayOf(0.114503, 0.786281, 0.099216),
|
||||
doubleArrayOf(-0.003882, -0.048116, 1.051998),
|
||||
),
|
||||
"deuteranopia" to arrayOf(
|
||||
doubleArrayOf(0.367322, 0.860646, -0.227968),
|
||||
doubleArrayOf(0.280085, 0.672501, 0.047413),
|
||||
doubleArrayOf(-0.011820, 0.042940, 0.968881),
|
||||
),
|
||||
"tritanopia" to arrayOf(
|
||||
doubleArrayOf(1.255528, -0.076749, -0.178779),
|
||||
doubleArrayOf(-0.078411, 0.930809, 0.147602),
|
||||
doubleArrayOf(0.004733, 0.691367, 0.303900),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package de.jeanlucmakiola.calendula.data.launcher
|
||||
|
||||
import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
|
||||
import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
||||
import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.floret.android.activeLauncherAlias
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/** Which alias carries each name × icon combination (#44, #451). */
|
||||
class LauncherAliasTest {
|
||||
|
||||
@Test
|
||||
fun `each combination maps to its alias`() {
|
||||
assertThat(LauncherAlias.of(LauncherEntry(LauncherName.CALENDULA, LauncherIcon.BLOOM)))
|
||||
.isEqualTo(LauncherAlias.DEFAULT)
|
||||
assertThat(LauncherAlias.of(LauncherEntry(LauncherName.CALENDAR, LauncherIcon.BLOOM)))
|
||||
.isEqualTo(LauncherAlias.CALENDAR)
|
||||
assertThat(LauncherAlias.of(LauncherEntry(LauncherName.CALENDULA, LauncherIcon.PLAIN)))
|
||||
.isEqualTo(LauncherAlias.PLAIN)
|
||||
assertThat(LauncherAlias.of(LauncherEntry(LauncherName.CALENDAR, LauncherIcon.PLAIN)))
|
||||
.isEqualTo(LauncherAlias.CALENDAR_PLAIN)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `every combination has exactly one alias`() {
|
||||
val combinations = LauncherName.entries.flatMap { name ->
|
||||
LauncherIcon.entries.map { LauncherEntry(name, it) }
|
||||
}
|
||||
assertThat(LauncherAlias.entries.map { it.entry }).containsExactlyElementsIn(combinations)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `pre-451 component names are kept`() {
|
||||
assertThat(LauncherAlias.DEFAULT.className).isEqualTo("DefaultNameAlias")
|
||||
assertThat(LauncherAlias.CALENDAR.className).isEqualTo("CalendarNameAlias")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the default combination is the manifest default`() {
|
||||
assertThat(LauncherAlias.of(LauncherEntry())).isEqualTo(LauncherAlias.DEFAULT)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a device switched to Calendar before 451 still reads as Calendar with the bloom`() {
|
||||
val states = mapOf(
|
||||
LauncherAlias.DEFAULT to COMPONENT_ENABLED_STATE_DISABLED,
|
||||
LauncherAlias.CALENDAR to COMPONENT_ENABLED_STATE_ENABLED,
|
||||
LauncherAlias.PLAIN to COMPONENT_ENABLED_STATE_DEFAULT,
|
||||
LauncherAlias.CALENDAR_PLAIN to COMPONENT_ENABLED_STATE_DEFAULT,
|
||||
)
|
||||
assertThat(activeLauncherAlias(states, LauncherAlias.DEFAULT).entry)
|
||||
.isEqualTo(LauncherEntry(LauncherName.CALENDAR, LauncherIcon.BLOOM))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `changing the icon keeps the name`() {
|
||||
val entry = LauncherEntry(LauncherName.CALENDAR, LauncherIcon.BLOOM)
|
||||
assertThat(LauncherAlias.of(entry.copy(icon = LauncherIcon.PLAIN))).isEqualTo(LauncherAlias.CALENDAR_PLAIN)
|
||||
}
|
||||
}
|
||||
@@ -1022,5 +1022,39 @@ class SettingsPrefsTest {
|
||||
canModifyContents = true,
|
||||
isLocal = local,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a recent colour goes to the front, once, made opaque`() {
|
||||
val recents = listOf(0xFF111111.toInt(), 0xFF222222.toInt())
|
||||
assertThat(withRecentColor(recents, 0x00222222))
|
||||
.containsExactly(0xFF222222.toInt(), 0xFF111111.toInt()).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `recent colours are capped, dropping the oldest`() {
|
||||
val full = (1..SettingsPrefs.MAX_RECENT_CUSTOM_COLORS).map { (0xFF shl 24) or it }
|
||||
val next = withRecentColor(full, 0xFFABCDEF.toInt())
|
||||
assertThat(next).hasSize(SettingsPrefs.MAX_RECENT_CUSTOM_COLORS)
|
||||
assertThat(next.first()).isEqualTo(0xFFABCDEF.toInt())
|
||||
assertThat(next).doesNotContain(full.last())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `recent custom colours round-trip most recent first`(@TempDir tempDir: Path) = runTest {
|
||||
val prefs = testSettings(tempDir)
|
||||
assertThat(prefs.recentCustomColors.first()).isEmpty()
|
||||
prefs.addRecentCustomColor(0xFF112233.toInt())
|
||||
prefs.addRecentCustomColor(0xFFAABBCC.toInt())
|
||||
prefs.addRecentCustomColor(0xFF112233.toInt())
|
||||
assertThat(prefs.recentCustomColors.first())
|
||||
.containsExactly(0xFF112233.toInt(), 0xFFAABBCC.toInt()).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `unreadable stored recent colours are dropped`(@TempDir tempDir: Path) = runTest {
|
||||
val store = testDataStore(tempDir, "test_settings")
|
||||
store.updateData { it.toMutablePreferences().apply { this[stringPreferencesKey("recent_custom_colors")] = "112233,zz,ABC,445566" } }
|
||||
assertThat(SettingsPrefs(store).recentCustomColors.first())
|
||||
.containsExactly(0xFF112233.toInt(), 0xFFAABBCC.toInt(), 0xFF445566.toInt()).inOrder()
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ the exporting install had). Everything is written in one DataStore edit. After
|
||||
that the import refreshes what reads settings outside DataStore: the
|
||||
contact-dates mirror (turned on and synced, or off and torn down, as the
|
||||
settings toggle does), the reminder scan, the automatic-backup schedule, the
|
||||
launcher name and icon and the app language. Theme and widgets follow the stored
|
||||
launcher name and the app language. Theme and widgets follow the stored
|
||||
values on their own. A summary lists what could not be imported.
|
||||
|
||||
## `settings`
|
||||
@@ -116,7 +116,6 @@ than writing a file without them.
|
||||
|---|---|---|
|
||||
| `language` | String? | The app language tag; `null` follows the system. Absent: left as is. A language this build doesn't ship is skipped. |
|
||||
| `launcher_name` | String? | `CALENDULA` or `CALENDAR`. Unknown: left as is. |
|
||||
| `launcher_icon` | String? | `BLOOM` or `PLAIN`. Unknown: left as is. |
|
||||
|
||||
## Not exported
|
||||
|
||||
@@ -126,7 +125,8 @@ bookkeeping, or meaningless on another device.
|
||||
- Font stamps (`*_font_stamp`): cache keys for the local font file.
|
||||
- `agenda_widget_range`, `widget_size`: legacy defaults for unconfigured
|
||||
widgets. Widget configuration is not part of the backup at all.
|
||||
- `recent_time_zones`, `recent_fixed_time_reminders`: usage history.
|
||||
- `recent_time_zones`, `recent_fixed_time_reminders`, `recent_custom_colors`: usage
|
||||
history.
|
||||
- `notification_category_hint_dismissed`, `reminder_channel_versions`:
|
||||
this install's notification hint and channels.
|
||||
- `sync_access_dismissed`: sync-request grants of this device's accounts.
|
||||
|
||||
+1
-1
Submodule floret-kit updated: 61cad7e560...dea52a9eb6.
Reference in new issue
Block a user