Compare commits

..
Author SHA1 Message Date
makiolaj e8e8338ba9 Label the default launcher icon Bloom (#451) 2026-11-30 21:44:20 +01:00
makiolaj eeeb55988d Plain launcher icon option (#451) 2026-11-30 19:39:34 +01:00
25 changed files with 373 additions and 400 deletions

No files matched your search

+37 -5
View File
@@ -256,11 +256,11 @@
</activity>
<!-- 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
<!-- 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
MainActivity, because static shortcuts are published by whichever
component owns the MAIN/LAUNCHER filter. -->
<activity-alias
@@ -295,6 +295,38 @@
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
@@ -49,7 +49,6 @@ import de.jeanlucmakiola.calendula.ui.common.LocalTimelineZoom
import de.jeanlucmakiola.calendula.ui.common.rememberTimelineZoom
import de.jeanlucmakiola.calendula.ui.common.LocalSoftenColors
import de.jeanlucmakiola.calendula.ui.common.LocalUse24HourFormat
import de.jeanlucmakiola.calendula.ui.common.LocalWeekNumbering
import de.jeanlucmakiola.calendula.ui.WidgetNavRequest
import de.jeanlucmakiola.calendula.ui.common.CalendarView
import de.jeanlucmakiola.calendula.ui.detail.EventDetailViewModel.Companion.NO_OCCURRENCE_TIME
@@ -249,7 +248,6 @@ class MainActivity : AppCompatActivity() {
LocalTimelineZoom provides timelineZoom,
LocalMultiDayCount provides settings.multiDayCount,
LocalSoftenColors provides settings.softenColors,
LocalWeekNumbering provides settings.weekNumbering,
) {
RootScreen(
modifier = Modifier.fillMaxSize(),
@@ -1,109 +0,0 @@
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,7 +1,9 @@
package de.jeanlucmakiola.calendula.data.backup
import androidx.datastore.preferences.core.Preferences
import de.jeanlucmakiola.calendula.data.appname.LauncherName
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.calendar.ManagedCalendarRow
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefKeys
import de.jeanlucmakiola.calendula.data.prefs.FixedTimeOverride
@@ -71,12 +73,13 @@ 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]: the file didn't say. */
/** Everything a settings backup holds. Null [language]/[launcherName]/[launcherIcon]: 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)
@@ -91,7 +94,7 @@ fun buildSettingsBackup(
calendars: List<CalendarSource>,
managed: List<ManagedCalendarRow>,
language: LanguageChoice?,
launcherName: LauncherName?,
launcher: LauncherEntry?,
): SettingsBackup {
val hidden = snapshot[CalendarPrefKeys.hiddenCalendarIds]
val lastUsed = snapshot[CalendarPrefKeys.lastUsedCalendarId]
@@ -139,7 +142,8 @@ fun buildSettingsBackup(
prefs = plainSection.snapshot(snapshot),
calendars = entries,
language = language,
launcherName = launcherName,
launcherName = launcher?.name,
launcherIcon = launcher?.icon,
)
}
@@ -152,6 +156,7 @@ 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)) }
},
)
}
@@ -179,6 +184,8 @@ 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 } },
)
}
}
@@ -247,6 +254,7 @@ 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,7 +8,8 @@ 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.appname.LauncherNameManager
import de.jeanlucmakiola.calendula.data.launcher.LauncherEntry
import de.jeanlucmakiola.calendula.data.launcher.LauncherManager
import de.jeanlucmakiola.calendula.data.calendar.CalendarDataSource
import de.jeanlucmakiola.calendula.data.contacts.ContactSpecialDatesDataSource
import de.jeanlucmakiola.calendula.data.contacts.SpecialDatesScheduler
@@ -52,7 +53,7 @@ class SettingsBackupEngine @Inject constructor(
private val specialDates: SpecialDatesSyncEngine,
private val settingsPrefs: SettingsPrefs,
private val reminderScanner: ReminderScanner,
private val launcherNames: LauncherNameManager,
private val launcher: LauncherManager,
@ApplicationContext private val context: Context,
@IoDispatcher private val io: CoroutineDispatcher,
) {
@@ -67,7 +68,7 @@ class SettingsBackupEngine @Inject constructor(
calendars = list,
managed = if (list.any { it.isManaged }) calendars.findManagedCalendars() else emptyList(),
language = LanguageChoice(AppLanguage.currentTag(context, supported)),
launcherName = launcherNames.current(),
launcher = launcher.current(),
)
encodeSettingsBackup(backup, System.currentTimeMillis(), BuildConfig.VERSION_NAME)
}
@@ -135,8 +136,15 @@ class SettingsBackupEngine @Inject constructor(
val active = after[SettingsKeys.autoBackupEnabled] && after[SettingsKeys.autoBackupFolderUri] != null
if (active && before.autoBackupScheduled != after.autoBackupScheduled) BackupScheduler.runNow(context)
}
plan.launcherName?.let { name ->
step("launcher name") { if (launcherNames.current() != name) launcherNames.set(name) }
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.language?.let { choice ->
step("language") {
@@ -28,7 +28,6 @@ internal object SettingsBackupSchema {
SettingsKeys.pastEventDisplay,
SettingsKeys.dimCompletedEvents,
SettingsKeys.showWeekNumbers,
SettingsKeys.weekNumbering,
SettingsKeys.monthShowStartTimes,
SettingsKeys.monthViewStyle,
SettingsKeys.timelineScale,
@@ -2,7 +2,8 @@ package de.jeanlucmakiola.calendula.data.backup
import androidx.datastore.preferences.core.MutablePreferences
import androidx.datastore.preferences.core.Preferences
import de.jeanlucmakiola.calendula.data.appname.LauncherName
import de.jeanlucmakiola.calendula.data.launcher.LauncherIcon
import de.jeanlucmakiola.calendula.data.launcher.LauncherName
import de.jeanlucmakiola.calendula.data.calendar.ManagedCalendarRow
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefKeys
import de.jeanlucmakiola.calendula.data.prefs.FixedTimeOverride
@@ -72,6 +73,7 @@ data class SettingsImportPlan(
val pendingSpecialDates: List<CalendarSettings>,
val language: LanguageChoice?,
val launcherName: LauncherName?,
val launcherIcon: LauncherIcon?,
val skipped: List<SkippedSetting>,
)
@@ -154,6 +156,7 @@ fun planSettingsImport(
pendingSpecialDates = pending,
language = language,
launcherName = backup.launcherName,
launcherIcon = backup.launcherIcon,
skipped = skipped,
)
}
@@ -0,0 +1,76 @@
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"
}
}
@@ -90,20 +90,6 @@ sealed interface WeekStartPref {
*/
enum class TimeFormatPref { AUTO, TWELVE_HOUR, TWENTY_FOUR_HOUR }
/**
* How week numbers are counted (#493). AUTO follows the device region; ISO and
* US pin ISO 8601 or the US system. Only the number: rows still start on the
* day [WeekStartPref] picks.
*/
enum class WeekNumberingPref { AUTO, ISO, US }
/** The [WeekFields] that count weeks under this preference; AUTO reads [region]. */
fun WeekNumberingPref.weekFields(region: Locale): WeekFields = when (this) {
WeekNumberingPref.AUTO -> WeekFields.of(region)
WeekNumberingPref.ISO -> WeekFields.ISO
WeekNumberingPref.US -> WeekFields.SUNDAY_START
}
/**
* How the Agenda screen treats events that have already finished today: [SHOW]
* leaves them as-is (the historical behaviour), [DIM] fades them, [HIDE] drops
@@ -185,7 +171,6 @@ class SettingsPrefs @Inject constructor(
val pastEventDisplay: Flow<PastEventDisplay> = prefs.flow(SettingsKeys.pastEventDisplay)
val dimCompletedEvents: Flow<Boolean> = prefs.flow(SettingsKeys.dimCompletedEvents)
val showWeekNumbers: Flow<Boolean> = prefs.flow(SettingsKeys.showWeekNumbers)
val weekNumbering: Flow<WeekNumberingPref> = prefs.flow(SettingsKeys.weekNumbering)
val monthShowStartTimes: Flow<Boolean> = prefs.flow(SettingsKeys.monthShowStartTimes)
val monthViewStyle: Flow<MonthViewStyle> = prefs.flow(SettingsKeys.monthViewStyle)
val timelineScale: Flow<TimelineScale> = prefs.flow(SettingsKeys.timelineScale)
@@ -284,7 +269,6 @@ class SettingsPrefs @Inject constructor(
suspend fun setPastEventDisplay(mode: PastEventDisplay) = prefs.set(SettingsKeys.pastEventDisplay, mode)
suspend fun setDimCompletedEvents(enabled: Boolean) = prefs.set(SettingsKeys.dimCompletedEvents, enabled)
suspend fun setShowWeekNumbers(enabled: Boolean) = prefs.set(SettingsKeys.showWeekNumbers, enabled)
suspend fun setWeekNumbering(pref: WeekNumberingPref) = prefs.set(SettingsKeys.weekNumbering, pref)
suspend fun setMonthShowStartTimes(enabled: Boolean) = prefs.set(SettingsKeys.monthShowStartTimes, enabled)
suspend fun setMonthViewStyle(style: MonthViewStyle) = prefs.set(SettingsKeys.monthViewStyle, style)
suspend fun setTimelineScale(scale: TimelineScale) = prefs.set(SettingsKeys.timelineScale, scale)
@@ -724,14 +708,11 @@ object SettingsKeys {
val dimCompletedEvents: Pref<Boolean> = booleanPref("dim_completed_events", false)
/**
* Whether the Month grid shows the week number in a left gutter (#25).
* Whether the Month grid shows the ISO week number in a left gutter (#25).
* The Week view shows its number unconditionally.
*/
val showWeekNumbers: Pref<Boolean> = booleanPref("show_week_numbers", false)
/** How every week number in the app is counted (#493). */
val weekNumbering: Pref<WeekNumberingPref> = enumPref("week_numbering", WeekNumberingPref.AUTO)
/** Whether Month chips may show the start time before the title when wide enough (#219, #476). */
val monthShowStartTimes: Pref<Boolean> = booleanPref("month_show_start_times", true)
@@ -3,34 +3,19 @@ package de.jeanlucmakiola.calendula.ui.common
import android.content.res.Resources
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import de.jeanlucmakiola.calendula.data.prefs.WeekNumberingPref
import de.jeanlucmakiola.calendula.data.prefs.weekFields
import de.jeanlucmakiola.floret.time.rowWeekNumber
import kotlinx.datetime.LocalDate
import kotlinx.datetime.toJavaLocalDate
import java.util.Locale
/** The week-numbering setting (#493), provided once at the app root. */
val LocalWeekNumbering = staticCompositionLocalOf { WeekNumberingPref.AUTO }
import java.time.temporal.WeekFields
/**
* The week number of the 7-day row starting on [rowStart], counted by
* [numbering] (AUTO reads [region]). The row takes the week holding most of its
* days: that of its mid-week day in the numbering system (Thursday for ISO,
* Wednesday for US), so any "Week starts on" choice gets a consistent number.
*/
fun rowWeekNumber(rowStart: LocalDate, numbering: WeekNumberingPref, region: Locale): Int =
rowStart.toJavaLocalDate().rowWeekNumber(numbering.weekFields(region))
/**
* [rowWeekNumber] for the composition's numbering setting. AUTO follows the
* device region, not the app language: an English UI in the Netherlands still
* numbers weeks the ISO way. Shared by the Month gutter and the Week badge.
* The week number of the grid row starting on [rowStart], numbered by the
* device region's rules (#493). The region, not the app language: an English
* UI in the Netherlands still numbers weeks the ISO way. Shared by the Month
* gutter and the Week badge so the two always agree.
*/
@Composable
internal fun rememberRowWeekNumber(rowStart: LocalDate): Int {
val numbering = LocalWeekNumbering.current
val region = remember { Resources.getSystem().configuration.locales[0] }
return remember(rowStart, numbering, region) { rowWeekNumber(rowStart, numbering, region) }
val fields = remember { WeekFields.of(Resources.getSystem().configuration.locales[0]) }
return remember(rowStart, fields) { rowStart.toJavaLocalDate().rowWeekNumber(fields) }
}
@@ -2757,8 +2757,8 @@ private fun monthChipDragModifier(
* Left-gutter calendar-week cell (#25): a full-height tonal pill mirroring the
* day cells' geometry, set apart by the secondaryContainer tint (matching the
* Week view's badge), with the week number centred like a day number. It is
* numbered by the week-numbering setting from the row's mid-week day, as in the
* Week view, so it is right for any first weekday (#493).
* numbered by the device region from the row's mid-week day, as in the Week
* view, so it is right for any first weekday (#493).
*/
@Composable
private fun WeekNumberGutter(weekStart: LocalDate, modifier: Modifier = Modifier) {
@@ -48,7 +48,8 @@ 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.appname.LauncherName
import de.jeanlucmakiola.calendula.data.launcher.LauncherIcon
import de.jeanlucmakiola.calendula.data.launcher.LauncherName
import de.jeanlucmakiola.floret.prefs.ThemeMode
import de.jeanlucmakiola.calendula.domain.FontRole
import de.jeanlucmakiola.calendula.ui.theme.BundledFont
@@ -67,7 +68,7 @@ import de.jeanlucmakiola.floret.components.positionOf
/**
* Appearance: how the app itself looks — theme and colour, the two typeface
* roles, and the launcher name. Anything that only changes how a *calendar view*
* roles, and the launcher name and icon. 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).
*/
@@ -82,9 +83,10 @@ 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 launcherName by viewModel.launcherName.collectAsStateWithLifecycle()
val launcher by viewModel.launcher.collectAsStateWithLifecycle()
val context = LocalContext.current
val importFailedMessage = stringResource(R.string.settings_font_import_failed)
LaunchedEffect(Unit) {
@@ -153,14 +155,20 @@ internal fun AppearanceScreen(
Spacer(Modifier.height(16.dp))
// App name — the launcher label (#44); its own group, being a
// The launcher label (#44) and icon (#451); their own group, being a
// launcher concern rather than app styling.
GroupedRow(
title = stringResource(R.string.settings_app_name),
summary = launcherNameLabel(launcherName),
position = Position.Alone,
summary = launcherNameLabel(launcher.name),
position = Position.Top,
onClick = { showAppName = true },
)
GroupedRow(
title = stringResource(R.string.settings_app_icon),
summary = launcherIconLabel(launcher.icon),
position = Position.Bottom,
onClick = { showAppIcon = true },
)
}
if (showAppName) {
@@ -188,9 +196,10 @@ internal fun AppearanceScreen(
horizontalArrangement = Arrangement.spacedBy(16.dp),
) {
LauncherName.entries.forEach { option ->
AppNameOptionCard(
name = option,
selected = launcherName == option,
LauncherOptionCard(
icon = launcher.icon,
label = launcherNameLabel(option),
selected = launcher.name == option,
onClick = { viewModel.setLauncherName(option) },
modifier = Modifier.weight(1f),
)
@@ -198,6 +207,40 @@ 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.
@@ -275,6 +318,15 @@ 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
@@ -419,12 +471,13 @@ private fun FontOptionRow(
}
/**
* One selectable launcher-name preview in the App name picker (#44): the app's
* launcher mark over the name, framed as a card.
* One selectable launcher preview in the App name (#44) and App icon (#451)
* pickers: the launcher mark over its label, framed as a card.
*/
@Composable
private fun AppNameOptionCard(
name: LauncherName,
private fun LauncherOptionCard(
icon: LauncherIcon,
label: String,
selected: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier,
@@ -459,13 +512,18 @@ private fun AppNameOptionCard(
.background(colorResource(R.color.ic_launcher_background)),
) {
Image(
painter = painterResource(R.drawable.ic_launcher_foreground),
painter = painterResource(
when (icon) {
LauncherIcon.BLOOM -> R.drawable.ic_launcher_foreground
LauncherIcon.PLAIN -> R.drawable.ic_launcher_foreground_plain
},
),
contentDescription = null,
modifier = Modifier.fillMaxSize(),
)
}
Text(
text = launcherNameLabel(name),
text = label,
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.onSurface,
textAlign = TextAlign.Center,
@@ -9,7 +9,6 @@ import de.jeanlucmakiola.calendula.data.prefs.PastEventDisplay
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
import de.jeanlucmakiola.floret.prefs.ThemeMode
import de.jeanlucmakiola.calendula.data.prefs.TimeFormatPref
import de.jeanlucmakiola.calendula.data.prefs.WeekNumberingPref
import de.jeanlucmakiola.calendula.data.prefs.WeekStartPref
import de.jeanlucmakiola.calendula.domain.CalendarSource
import de.jeanlucmakiola.calendula.domain.EventFormField
@@ -47,8 +46,6 @@ data class SettingsUiState(
val dimCompletedEvents: Boolean = false,
/** Whether the Month grid shows calendar-week numbers in a left gutter (#25). */
val showWeekNumbers: Boolean = false,
/** How week numbers are counted in every view (#493). */
val weekNumbering: WeekNumberingPref = WeekNumberingPref.AUTO,
/** Whether Month chips may show start times before their titles (#476). */
val monthShowStartTimes: Boolean = true,
/** Whether the jump-to-today control sits in the top bar instead of the FAB (#60). */
@@ -10,8 +10,10 @@ 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.appname.LauncherName
import de.jeanlucmakiola.calendula.data.appname.LauncherNameManager
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.calendar.CalendarRepository
import de.jeanlucmakiola.calendula.data.contacts.SpecialDatesCalendarSpec
import de.jeanlucmakiola.calendula.data.contacts.SpecialDatesScheduler
@@ -42,7 +44,6 @@ import de.jeanlucmakiola.floret.prefs.get
import de.jeanlucmakiola.calendula.data.prefs.SpecialDatesStalledReason
import de.jeanlucmakiola.floret.prefs.ThemeMode
import de.jeanlucmakiola.calendula.data.prefs.TimeFormatPref
import de.jeanlucmakiola.calendula.data.prefs.WeekNumberingPref
import de.jeanlucmakiola.calendula.data.prefs.WeekStartPref
import de.jeanlucmakiola.calendula.data.reminders.ReminderChannelStatus
import de.jeanlucmakiola.calendula.data.reminders.ReminderChannels
@@ -91,7 +92,7 @@ class SettingsViewModel @Inject constructor(
repository: CalendarRepository,
private val specialDatesEngine: SpecialDatesSyncEngine,
specialDatesSpec: SpecialDatesCalendarSpec,
private val launcherNameManager: LauncherNameManager,
private val launcherManager: LauncherManager,
private val reminderScanner: ReminderScanner,
private val reminderChannels: ReminderChannels,
private val reminderNotifier: ReminderNotifier,
@@ -143,7 +144,6 @@ class SettingsViewModel @Inject constructor(
pastEventDisplay = this[SettingsKeys.pastEventDisplay],
dimCompletedEvents = this[SettingsKeys.dimCompletedEvents],
showWeekNumbers = this[SettingsKeys.showWeekNumbers],
weekNumbering = this[SettingsKeys.weekNumbering],
monthShowStartTimes = this[SettingsKeys.monthShowStartTimes],
todayButtonInToolbar = this[SettingsKeys.todayButtonInToolbar],
dragToReschedule = this[SettingsKeys.dragToReschedule],
@@ -202,17 +202,17 @@ class SettingsViewModel @Inject constructor(
)
/**
* The launcher-label choice (#44), backed by the manifest aliases'
* The launcher name (#44) and icon (#451), 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 _launcherName = MutableStateFlow(LauncherName.CALENDULA)
val launcherName: StateFlow<LauncherName> = _launcherName.asStateFlow()
private val _launcher = MutableStateFlow(LauncherEntry())
val launcher: StateFlow<LauncherEntry> = _launcher.asStateFlow()
init {
viewModelScope.launch {
_launcherName.value = withContext(io) { launcherNameManager.current() }
_launcher.value = withContext(io) { launcherManager.current() }
}
}
@@ -347,8 +347,6 @@ class SettingsViewModel @Inject constructor(
fun setShowWeekNumbers(enabled: Boolean) = save { setShowWeekNumbers(enabled) }
fun setWeekNumbering(pref: WeekNumberingPref) = save { setWeekNumbering(pref) }
fun setMonthShowStartTimes(enabled: Boolean) = save { setMonthShowStartTimes(enabled) }
fun setTodayButtonInToolbar(enabled: Boolean) = save { setTodayButtonInToolbar(enabled) }
@@ -358,16 +356,20 @@ class SettingsViewModel @Inject constructor(
fun setTapOpensEditor(enabled: Boolean) = save { setTapOpensEditor(enabled) }
/**
* 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.
* 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.
*/
fun setLauncherName(name: LauncherName) {
_launcherName.value = name
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()
viewModelScope.launch {
_launcherName.value = withContext(io) {
launcherNameManager.set(name)
launcherNameManager.current()
_launcher.value = withContext(io) {
launcherManager.write()
launcherManager.current()
}
}
}
@@ -1,6 +1,5 @@
package de.jeanlucmakiola.calendula.ui.settings
import android.content.res.Resources
import android.text.format.DateFormat
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Box
@@ -29,9 +28,7 @@ import de.jeanlucmakiola.calendula.R
import de.jeanlucmakiola.calendula.data.prefs.PastEventDisplay
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
import de.jeanlucmakiola.calendula.data.prefs.TimeFormatPref
import de.jeanlucmakiola.calendula.data.prefs.WeekNumberingPref
import de.jeanlucmakiola.calendula.data.prefs.WeekStartPref
import de.jeanlucmakiola.calendula.data.time.currentDate
import de.jeanlucmakiola.calendula.data.prefs.resolveFirstDay
import de.jeanlucmakiola.calendula.ui.common.AgendaRangePicker
import de.jeanlucmakiola.calendula.ui.common.CalendarView
@@ -46,8 +43,6 @@ import de.jeanlucmakiola.calendula.ui.common.formatTimeOfDay
import de.jeanlucmakiola.calendula.ui.common.icon
import de.jeanlucmakiola.calendula.ui.common.label
import de.jeanlucmakiola.calendula.ui.common.labelRes
import de.jeanlucmakiola.calendula.ui.common.rowWeekNumber
import de.jeanlucmakiola.calendula.ui.common.startOfWeek
import de.jeanlucmakiola.calendula.ui.month.labelRes
import de.jeanlucmakiola.floret.components.CollapsingScaffold
import de.jeanlucmakiola.floret.components.GroupedHint
@@ -82,7 +77,6 @@ internal fun ViewsScreen(
var showMonthStyle by remember { mutableStateOf(false) }
var showDefaultView by remember { mutableStateOf(false) }
var showWeekStart by remember { mutableStateOf(false) }
var showWeekNumbering by remember { mutableStateOf(false) }
var showTimeFormat by remember { mutableStateOf(false) }
var showTapOpens by remember { mutableStateOf(false) }
var showPastEvents by remember { mutableStateOf(false) }
@@ -115,12 +109,6 @@ internal fun ViewsScreen(
position = Position.Middle,
onClick = { showWeekStart = true },
)
GroupedRow(
title = stringResource(R.string.settings_week_numbering),
summary = weekNumberingLabel(state.weekNumbering),
position = Position.Middle,
onClick = { showWeekNumbering = true },
)
GroupedRow(
title = stringResource(R.string.settings_time_format),
summary = timeFormatLabel(state.timeFormat),
@@ -351,25 +339,6 @@ internal fun ViewsScreen(
onDismiss = { showWeekStart = false },
)
}
if (showWeekNumbering) {
val firstDay = state.weekStart.resolveFirstDay(currentLocale())
val rowStart = remember(firstDay) { currentDate().startOfWeek(firstDay) }
val region = remember { Resources.getSystem().configuration.locales[0] }
OptionPicker(
title = stringResource(R.string.settings_week_numbering),
header = { GroupedHint(stringResource(R.string.settings_week_numbering_hint), verticalPadding = 8.dp) },
predictiveBack = true,
options = WeekNumberingPref.entries,
selected = state.weekNumbering,
label = { weekNumberingLabel(it) },
// Each option shows the number it gives this week, so the difference is visible.
summary = {
stringResource(R.string.settings_week_numbering_this_week, rowWeekNumber(rowStart, it, region))
},
onSelect = viewModel::setWeekNumbering,
onDismiss = { showWeekNumbering = false },
)
}
if (showTimeFormat) {
val locale = currentLocale()
val systemIs24Hour = DateFormat.is24HourFormat(LocalContext.current)
@@ -538,15 +507,6 @@ private fun ViewRow(
)
}
@Composable
private fun weekNumberingLabel(pref: WeekNumberingPref): String = stringResource(
when (pref) {
WeekNumberingPref.AUTO -> R.string.settings_week_numbering_auto
WeekNumberingPref.ISO -> R.string.settings_week_numbering_iso
WeekNumberingPref.US -> R.string.settings_week_numbering_us
},
)
/** Picker options: "Follow system" first, then Monday…Sunday in ISO order. */
private val WEEK_START_OPTIONS: List<WeekStartPref> =
listOf(WeekStartPref.Auto) + DayOfWeek.entries.map { WeekStartPref.Day(it) }
@@ -0,0 +1,37 @@
<?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>
@@ -0,0 +1,6 @@
<?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>
@@ -0,0 +1,6 @@
<?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>
+4 -7
View File
@@ -614,18 +614,16 @@
<string name="settings_week_start_auto_summary">Currently %1$s</string>
<string name="settings_week_numbers">Week numbers</string>
<string name="settings_week_numbers_summary">Show calendar-week numbers in month view</string>
<string name="settings_week_numbering">Week numbering</string>
<string name="settings_week_numbering_auto">Automatic</string>
<string name="settings_week_numbering_iso">ISO 8601</string>
<string name="settings_week_numbering_us">US</string>
<!-- %1$d is the number this option gives the current week, e.g. "This week: 49". -->
<string name="settings_week_numbering_this_week">This week: %1$d</string>
<string name="settings_month_start_times">Start times</string>
<string name="settings_month_start_times_summary">Show the start time before an event\'s title when there is room</string>
<string name="settings_today_toolbar">Today button in toolbar</string>
<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>
@@ -885,7 +883,6 @@
<!-- Picker descriptions (#69) -->
<string name="settings_default_view_hint">The view Calendula opens on when you start it.</string>
<string name="settings_week_start_hint">The day every week begins on, in all views and widgets.</string>
<string name="settings_week_numbering_hint">How week numbers are counted. Automatic follows your region.</string>
<string name="settings_time_format_hint">How times are written throughout the app. Automatic follows your system setting.</string>
<string name="settings_past_events_hint">What the agenda does with events that have already ended.</string>
<string name="settings_dynamic_color_summary">Take the app\'s colours from your wallpaper.</string>
@@ -1,51 +0,0 @@
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,7 +3,9 @@ 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.appname.LauncherName
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.calendar.ManagedCalendarRow
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefKeys
import de.jeanlucmakiola.calendula.data.prefs.FixedTimeOverride
@@ -55,7 +57,7 @@ class SettingsBackupTest {
calendars = calendars,
managed = listOf(ManagedCalendarRow(3, SpecialDateType.Birthday)),
language = LanguageChoice("de"),
launcherName = LauncherName.CALENDAR,
launcher = LauncherEntry(LauncherName.CALENDAR, LauncherIcon.PLAIN),
)
val decoded = decodeSettingsBackup(encodeSettingsBackup(backup, 1_700_000_000_000, "2.25.0"))
return (decoded as BackupResult.Success).value
@@ -358,6 +360,10 @@ 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
@@ -366,7 +372,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"}}
"app":{"launcher_name":"SOMETHING_NEW","launcher_icon":"SOMETHING_NEW"}}
""".trimIndent()
val backup = (decodeSettingsBackup(text) as BackupResult.Success).value
@@ -374,6 +380,7 @@ 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()
}
@@ -0,0 +1,61 @@
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)
}
}
@@ -1,89 +0,0 @@
package de.jeanlucmakiola.calendula.ui.common
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.calendula.data.prefs.WeekNumberingPref
import de.jeanlucmakiola.calendula.data.prefs.weekFields
import kotlinx.datetime.DateTimeUnit
import kotlinx.datetime.LocalDate
import kotlinx.datetime.minus
import kotlinx.datetime.plus
import kotlinx.datetime.toJavaLocalDate
import org.junit.jupiter.api.Test
import java.util.Locale
class WeekNumberTest {
private val portugal = Locale.forLanguageTag("pt-PT")
private val germany = Locale.GERMANY
@Test
fun `1 January 2026 is week 1 under ISO for every row start`() {
val rows = (0..6).map { LocalDate(2026, 1, 1).minusDays(it) }
rows.forEach { start ->
assertThat(rowWeekNumber(start, WeekNumberingPref.ISO, portugal)).isEqualTo(1)
}
}
@Test
fun `automatic numbering in Portugal puts 1 January 2026 in week 53`() {
assertThat(rowWeekNumber(LocalDate(2025, 12, 28), WeekNumberingPref.AUTO, portugal)).isEqualTo(53)
assertThat(rowWeekNumber(LocalDate(2025, 12, 29), WeekNumberingPref.AUTO, portugal)).isEqualTo(53)
}
@Test
fun `automatic numbering in Germany matches ISO`() {
assertThat(WeekNumberingPref.AUTO.weekFields(germany)).isEqualTo(WeekNumberingPref.ISO.weekFields(germany))
}
@Test
fun `US numbering puts the week holding 1 January first`() {
assertThat(rowWeekNumber(LocalDate(2025, 12, 28), WeekNumberingPref.US, germany)).isEqualTo(1)
assertThat(rowWeekNumber(LocalDate(2026, 12, 27), WeekNumberingPref.US, germany)).isEqualTo(1)
assertThat(rowWeekNumber(LocalDate(2026, 12, 27), WeekNumberingPref.ISO, germany)).isEqualTo(53)
}
@Test
fun `US numbering with Monday rows`() {
// Mon 2025-12-29 .. Sun 2026-01-04: its Wednesday is in the US week holding 1 January.
assertThat(rowWeekNumber(LocalDate(2025, 12, 29), WeekNumberingPref.US, germany)).isEqualTo(1)
assertThat(rowWeekNumber(LocalDate(2026, 11, 30), WeekNumberingPref.US, germany)).isEqualTo(49)
}
@Test
fun `numbering ignores the region unless automatic`() {
val start = LocalDate(2025, 12, 28)
assertThat(rowWeekNumber(start, WeekNumberingPref.ISO, portugal))
.isEqualTo(rowWeekNumber(start, WeekNumberingPref.ISO, Locale.US))
assertThat(rowWeekNumber(start, WeekNumberingPref.US, portugal))
.isEqualTo(rowWeekNumber(start, WeekNumberingPref.US, Locale.US))
}
@Test
fun `ISO numbering with Sunday and Saturday rows takes the week holding most of the row`() {
// Sun 01-04 .. Sat 01-10: six days in ISO week 2.
assertThat(rowWeekNumber(LocalDate(2026, 1, 4), WeekNumberingPref.ISO, germany)).isEqualTo(2)
// Sat 01-03 .. Fri 01-09: Monday to Friday are ISO week 2.
assertThat(rowWeekNumber(LocalDate(2026, 1, 3), WeekNumberingPref.ISO, germany)).isEqualTo(2)
// Fri 01-02 .. Thu 01-08: Friday to Sunday are week 1, Monday to Thursday week 2.
assertThat(rowWeekNumber(LocalDate(2026, 1, 2), WeekNumberingPref.ISO, germany)).isEqualTo(2)
}
@Test
fun `every row gets the number of the week holding at least four of its days`() {
val regions = listOf(germany, Locale.US, portugal)
var start = LocalDate(2019, 12, 20)
while (start < LocalDate(2028, 1, 10)) {
for (numbering in WeekNumberingPref.entries) for (region in regions) {
val fields = numbering.weekFields(region)
val days = (0..6).map { start.plusDays(it).toJavaLocalDate() }
val majority = days.groupingBy { it.get(fields.weekOfWeekBasedYear()) }.eachCount()
.filterValues { it >= 4 }.keys.single()
assertThat(rowWeekNumber(start, numbering, region)).isEqualTo(majority)
}
start = start.plusDays(1)
}
}
private fun LocalDate.minusDays(days: Int) = minus(days, DateTimeUnit.DAY)
private fun LocalDate.plusDays(days: Int) = plus(days, DateTimeUnit.DAY)
}
+2 -1
View File
@@ -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 the app language. Theme and widgets follow the stored
launcher name and icon and the app language. Theme and widgets follow the stored
values on their own. A summary lists what could not be imported.
## `settings`
@@ -116,6 +116,7 @@ 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