Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d45bb64f0 |
No files matched your search
@@ -116,8 +116,8 @@
|
||||
</intent-filter>
|
||||
<!-- A launcher/clock date tap fires ACTION_VIEW on the provider's
|
||||
time Uri (content://com.android.calendar/time/<epochMillis>);
|
||||
some surfaces use the time/epoch mime type. We open the day view
|
||||
on that date (MainActivity.calendarTimeDateOrNull). -->
|
||||
some surfaces use the time/epoch mime type. We open the day view,
|
||||
or the default view per setting, on that date (viewTimeRequest). -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
@@ -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
|
||||
|
||||
@@ -49,7 +49,9 @@ 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.CALENDAR_PROVIDER_HOST
|
||||
import de.jeanlucmakiola.calendula.ui.WidgetNavRequest
|
||||
import de.jeanlucmakiola.calendula.ui.viewTimeRequest
|
||||
import de.jeanlucmakiola.calendula.ui.common.CalendarView
|
||||
import de.jeanlucmakiola.calendula.ui.detail.EventDetailViewModel.Companion.NO_OCCURRENCE_TIME
|
||||
import de.jeanlucmakiola.calendula.ui.edit.ImportSource
|
||||
@@ -73,9 +75,7 @@ import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.datetime.LocalTime
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.toInstant
|
||||
import kotlinx.datetime.toLocalDateTime
|
||||
import kotlin.time.Clock
|
||||
import kotlin.time.Instant
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
@@ -473,26 +473,22 @@ class MainActivity : AppCompatActivity() {
|
||||
}?.takeIf { it > 0 }
|
||||
|
||||
/**
|
||||
* The date a launcher/clock date tap points at, parsed from the AOSP calendar
|
||||
* "view time" intent: ACTION_VIEW on `content://com.android.calendar/time/
|
||||
* <epochMillis>`. Null for any other intent. The matching manifest filter is
|
||||
* what lets users pick Calendula from the system calendar chooser (issue #9).
|
||||
* A launcher/clock date tap: the AOSP calendar "view time" intent. The
|
||||
* matching manifest filter is what lets users pick Calendula from the system
|
||||
* calendar chooser (issue #9). Our own daily summary speaks it too (#459).
|
||||
*/
|
||||
private fun Intent.calendarTimeDateOrNull(): LocalDate? {
|
||||
if (action != Intent.ACTION_VIEW) return null
|
||||
val uri = data ?: return null
|
||||
if (uri.host != CALENDAR_PROVIDER_HOST) return null
|
||||
val segments = uri.pathSegments
|
||||
if (segments.firstOrNull() != "time") return null
|
||||
val millis = segments.getOrNull(1)?.toLongOrNull() ?: return null
|
||||
return Instant.fromEpochMilliseconds(millis)
|
||||
.toLocalDateTime(TimeZone.currentSystemDefault()).date
|
||||
}
|
||||
private fun Intent.viewTimeRequestOrNull(): WidgetNavRequest.OpenDate? = viewTimeRequest(
|
||||
action = action,
|
||||
host = data?.host,
|
||||
pathSegments = data?.pathSegments.orEmpty(),
|
||||
zone = TimeZone.currentSystemDefault(),
|
||||
ownDayTap = getBooleanExtra(EXTRA_OWN_DAY_TAP, false),
|
||||
)
|
||||
|
||||
private fun Intent.navRequestOrNull(): WidgetNavRequest? {
|
||||
// An external date tap (launcher/clock) opens the day view over the default
|
||||
// home view, and backs out to it.
|
||||
calendarTimeDateOrNull()?.let { return WidgetNavRequest.OpenDate(it.toString(), fromWidget = false) }
|
||||
// An external date tap (launcher/clock) opens the day view or the default
|
||||
// view on that date (#524), and backs out to the default view.
|
||||
viewTimeRequestOrNull()?.let { return it }
|
||||
// A widget header tap: open a top-level view with no date drill-in. The
|
||||
// empty string carried by [openViewIntent] means "the default home view".
|
||||
if (hasExtra(EXTRA_OPEN_VIEW)) {
|
||||
@@ -590,9 +586,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
// The calendar provider's authority/host. A date tap arrives as
|
||||
// ACTION_VIEW on content://com.android.calendar/time/<epochMillis>.
|
||||
private const val CALENDAR_PROVIDER_HOST = "com.android.calendar"
|
||||
private const val SHARED_TEXT_TYPE = "text/plain"
|
||||
private val CALENDAR_TYPES = setOf("text/calendar", "text/x-vcalendar", "application/ics")
|
||||
private val CALENDAR_EXTENSIONS = listOf(".ics", ".vcs")
|
||||
@@ -608,6 +601,9 @@ class MainActivity : AppCompatActivity() {
|
||||
private const val EXTRA_DATE_ISO = "de.jeanlucmakiola.calendula.extra.DATE_ISO"
|
||||
private const val EXTRA_CREATE = "de.jeanlucmakiola.calendula.extra.CREATE"
|
||||
|
||||
// Marks the daily summary's own "view time" tap, which keeps the day view (#524).
|
||||
private const val EXTRA_OWN_DAY_TAP = "de.jeanlucmakiola.calendula.extra.OWN_DAY_TAP"
|
||||
|
||||
// A widget header tap asking to open a top-level view (no date drill-in).
|
||||
// Its value is the target [CalendarView] name, or "" for the default view.
|
||||
private const val EXTRA_OPEN_VIEW = "de.jeanlucmakiola.calendula.extra.OPEN_VIEW"
|
||||
@@ -677,6 +673,7 @@ class MainActivity : AppCompatActivity() {
|
||||
.toEpochMilliseconds()
|
||||
return Intent(Intent.ACTION_VIEW, "content://$CALENDAR_PROVIDER_HOST/time/$noon".toUri())
|
||||
.setClass(context, MainActivity::class.java)
|
||||
.putExtra(EXTRA_OWN_DAY_TAP, true)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -42,6 +42,7 @@ internal object SettingsBackupSchema {
|
||||
SettingsKeys.agendaShowRangeBar,
|
||||
SettingsKeys.agendaShowToday,
|
||||
SettingsKeys.defaultView,
|
||||
SettingsKeys.externalDateView,
|
||||
SettingsKeys.quickSwitchConfig,
|
||||
SettingsKeys.drawerViewOrder,
|
||||
SettingsKeys.defaultFormFields,
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,9 @@ enum class TimeFormatPref { AUTO, TWELVE_HOUR, TWENTY_FOUR_HOUR }
|
||||
*/
|
||||
enum class PastEventDisplay { SHOW, DIM, HIDE }
|
||||
|
||||
/** What a date another app opens in Calendula lands on (#524): the day view, or the default view on that date. */
|
||||
enum class ExternalDateView { DAY, DEFAULT }
|
||||
|
||||
/** Parse a stored [PastEventDisplay.name]; unknown/null falls back to [default]. */
|
||||
fun parsePastEventDisplay(
|
||||
stored: String?,
|
||||
@@ -183,6 +186,7 @@ class SettingsPrefs @Inject constructor(
|
||||
val agendaShowRangeBar: Flow<Boolean> = prefs.flow(SettingsKeys.agendaShowRangeBar)
|
||||
val agendaShowToday: Flow<Boolean> = prefs.flow(SettingsKeys.agendaShowToday)
|
||||
val defaultView: Flow<CalendarView> = prefs.flow(SettingsKeys.defaultView)
|
||||
val externalDateView: Flow<ExternalDateView> = prefs.flow(SettingsKeys.externalDateView)
|
||||
val quickSwitchConfig: Flow<QuickSwitchConfig> = prefs.flow(SettingsKeys.quickSwitchConfig)
|
||||
val drawerViewOrder: Flow<List<CalendarView>> = prefs.flow(SettingsKeys.drawerViewOrder)
|
||||
val defaultFormFields: Flow<Set<EventFormField>> = prefs.flow(SettingsKeys.defaultFormFields)
|
||||
@@ -290,6 +294,7 @@ class SettingsPrefs @Inject constructor(
|
||||
suspend fun setAgendaShowRangeBar(enabled: Boolean) = prefs.set(SettingsKeys.agendaShowRangeBar, enabled)
|
||||
suspend fun setAgendaShowToday(enabled: Boolean) = prefs.set(SettingsKeys.agendaShowToday, enabled)
|
||||
suspend fun setDefaultView(view: CalendarView) = prefs.set(SettingsKeys.defaultView, view)
|
||||
suspend fun setExternalDateView(view: ExternalDateView) = prefs.set(SettingsKeys.externalDateView, view)
|
||||
|
||||
/**
|
||||
* Atomic read-modify-write of the quick-switch config: [transform] sees the
|
||||
@@ -792,6 +797,9 @@ object SettingsKeys {
|
||||
*/
|
||||
val defaultView: Pref<CalendarView> = enumPref("default_view", CalendarView.Week)
|
||||
|
||||
/** What a launcher or clock date tap opens (#524); our own notifications and widgets keep the day view. */
|
||||
val externalDateView: Pref<ExternalDateView> = enumPref("external_date_view", ExternalDateView.DAY)
|
||||
|
||||
/**
|
||||
* Quick-switch button customisation (#24): the ordered full view list plus
|
||||
* which views are enabled in the cycle. Stored comma-joined by enum name, a
|
||||
|
||||
@@ -44,6 +44,7 @@ import androidx.compose.ui.layout.positionInWindow
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import de.jeanlucmakiola.calendula.data.prefs.ExternalDateView
|
||||
import de.jeanlucmakiola.calendula.data.time.currentDate
|
||||
import de.jeanlucmakiola.calendula.domain.EventForm
|
||||
import de.jeanlucmakiola.calendula.domain.EventInstance
|
||||
@@ -431,11 +432,17 @@ fun CalendarHost(
|
||||
}
|
||||
when (val req = widgetNavRequest) {
|
||||
is WidgetNavRequest.OpenDate -> {
|
||||
// Drop any overlay that would cover the day, so the open doesn't
|
||||
// Another app's date tap opens the day view or the default view (#524).
|
||||
val stack = req.stack(
|
||||
defaultView,
|
||||
if (req.external) viewModel.externalDateView() else ExternalDateView.DAY,
|
||||
)
|
||||
// Drop any overlay that would cover the date, so the open doesn't
|
||||
// land under Settings/form.
|
||||
dismissCoveringOverlays()
|
||||
focus.navigateTo(LocalDate.parse(req.dateIso))
|
||||
viewStack = listOf(defaultView).drillToDay()
|
||||
val date = LocalDate.parse(req.dateIso)
|
||||
if (stack.last() == CalendarView.Day) focus.navigateTo(date) else focus.showDate(date)
|
||||
viewStack = stack
|
||||
requests.leaveTarget = req.leaveTarget
|
||||
requests.nav = null
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.jeanlucmakiola.calendula.ui
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import de.jeanlucmakiola.calendula.data.prefs.ExternalDateView
|
||||
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
||||
import de.jeanlucmakiola.calendula.data.time.TodaySource
|
||||
import de.jeanlucmakiola.calendula.data.time.currentDate
|
||||
@@ -77,4 +78,9 @@ class CalendarHostViewModel @Inject constructor(
|
||||
|
||||
/** Whether tapping an event opens the edit form rather than the detail screen (#178). */
|
||||
suspend fun tapOpensEditor(): Boolean = tapOpensEditorPref.first()
|
||||
|
||||
private val externalDateViewPref = prefs.externalDateView
|
||||
|
||||
/** What another app's date tap opens (#524). */
|
||||
suspend fun externalDateView(): ExternalDateView = externalDateViewPref.first()
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
package de.jeanlucmakiola.calendula.ui
|
||||
|
||||
import android.content.Intent
|
||||
import de.jeanlucmakiola.calendula.data.prefs.ExternalDateView
|
||||
import de.jeanlucmakiola.calendula.ui.common.CalendarView
|
||||
import de.jeanlucmakiola.calendula.ui.common.drillToDay
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.toLocalDateTime
|
||||
import java.io.Serializable
|
||||
import kotlin.time.Instant
|
||||
|
||||
/**
|
||||
* A navigation a home-screen widget asked the app to perform when launched.
|
||||
@@ -16,8 +22,13 @@ sealed interface WidgetNavRequest : Serializable {
|
||||
* Open the day view anchored on [dateIso] (an ISO `yyyy-MM-dd` date), over the
|
||||
* default home view. [fromWidget] makes back leave the app at once (#530); a
|
||||
* launcher/clock date tap (issue #9) or the daily summary backs out to home.
|
||||
* [external] marks another app's date tap, which follows [ExternalDateView] (#524).
|
||||
*/
|
||||
data class OpenDate(val dateIso: String, val fromWidget: Boolean) : WidgetNavRequest
|
||||
data class OpenDate(
|
||||
val dateIso: String,
|
||||
val fromWidget: Boolean,
|
||||
val external: Boolean = false,
|
||||
) : WidgetNavRequest
|
||||
|
||||
/** Open one occurrence's detail (a widget event tap), over [source]; back leaves the app (#530). */
|
||||
data class OpenEvent(
|
||||
@@ -40,6 +51,33 @@ sealed interface WidgetNavRequest : Serializable {
|
||||
data class OpenView(val view: CalendarView?) : WidgetNavRequest
|
||||
}
|
||||
|
||||
/** The view stack [this] lands on over [defaultView]: the day view, unless another app's date tap is set to the default view (#524). */
|
||||
fun WidgetNavRequest.OpenDate.stack(defaultView: CalendarView, externalView: ExternalDateView): List<CalendarView> =
|
||||
if (external && externalView == ExternalDateView.DEFAULT) listOf(defaultView) else listOf(defaultView).drillToDay()
|
||||
|
||||
/**
|
||||
* The date request of the system "view time" intent (#9): ACTION_VIEW on
|
||||
* `content://com.android.calendar/time/<epochMillis>`, dated in [zone]. [ownDayTap]
|
||||
* marks our own daily summary's tap (#459), which stays on the day view. Null for
|
||||
* any other intent.
|
||||
*/
|
||||
fun viewTimeRequest(
|
||||
action: String?,
|
||||
host: String?,
|
||||
pathSegments: List<String>,
|
||||
zone: TimeZone,
|
||||
ownDayTap: Boolean,
|
||||
): WidgetNavRequest.OpenDate? {
|
||||
if (action != Intent.ACTION_VIEW || host != CALENDAR_PROVIDER_HOST) return null
|
||||
if (pathSegments.firstOrNull() != "time") return null
|
||||
val millis = pathSegments.getOrNull(1)?.toLongOrNull() ?: return null
|
||||
val date = Instant.fromEpochMilliseconds(millis).toLocalDateTime(zone).date
|
||||
return WidgetNavRequest.OpenDate(date.toString(), fromWidget = false, external = !ownDayTap)
|
||||
}
|
||||
|
||||
/** The calendar provider's authority, which the system's calendar intents address. */
|
||||
const val CALENDAR_PROVIDER_HOST = "com.android.calendar"
|
||||
|
||||
/** What back leaves the app from (#530): a widget's day, or a widget's event detail. */
|
||||
sealed interface LeaveTarget : Serializable {
|
||||
/** The view a widget opened, while no overlay covers it. */
|
||||
|
||||
@@ -6,6 +6,7 @@ import de.jeanlucmakiola.calendula.ui.common.ScreenActions
|
||||
import de.jeanlucmakiola.calendula.ui.common.ScreenBody
|
||||
import de.jeanlucmakiola.calendula.ui.common.ScreenChrome
|
||||
import de.jeanlucmakiola.calendula.ui.common.LocalViewFocus
|
||||
import de.jeanlucmakiola.calendula.ui.common.TakeDateRequest
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.setValue
|
||||
@@ -93,12 +94,31 @@ fun AgendaScreen(
|
||||
// the top. The top day still goes back to the shared focus.
|
||||
val focus = LocalViewFocus.current
|
||||
val opened = rememberSaveable { mutableStateOf(false) }
|
||||
val restoreTop = remember(viewModel) {
|
||||
if (restorePosition || opened.value) {
|
||||
viewModel.lastTopDate
|
||||
val scope = rememberCoroutineScope()
|
||||
val listState = rememberLazyListState()
|
||||
// Past days load above the anchor (#367), so the anchor's row counts as the
|
||||
// start of the list.
|
||||
val anchorIndex = remember { mutableIntStateOf(0) }
|
||||
// Another app's date (#524) is where it opens; one asked for while it is up moves it there.
|
||||
val requestedDate = TakeDateRequest(viewModel) { date ->
|
||||
focus?.date = date
|
||||
if (viewModel.anchor.value == date) {
|
||||
scope.launch { listState.animateScrollToItem(anchorIndex.intValue) }
|
||||
} else {
|
||||
viewModel.goToToday()
|
||||
null
|
||||
viewModel.goToDate(date)
|
||||
}
|
||||
}
|
||||
val restoreTop = remember(viewModel) {
|
||||
when {
|
||||
requestedDate != null -> {
|
||||
viewModel.goToDate(requestedDate)
|
||||
null
|
||||
}
|
||||
restorePosition || opened.value -> viewModel.lastTopDate
|
||||
else -> {
|
||||
viewModel.goToToday()
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
SideEffect { opened.value = true }
|
||||
@@ -108,7 +128,6 @@ fun AgendaScreen(
|
||||
val showToday by viewModel.showToday.collectAsStateWithLifecycle()
|
||||
val weekStart by viewModel.weekStart.collectAsStateWithLifecycle()
|
||||
|
||||
val scope = rememberCoroutineScope()
|
||||
var showRangePicker by remember { mutableStateOf(false) }
|
||||
|
||||
val isOnToday = when (val s = state) {
|
||||
@@ -120,10 +139,6 @@ fun AgendaScreen(
|
||||
// The agenda window always starts at the anchor, so moving through it is a
|
||||
// list scroll, not an anchor change — "today" has to bring the list back to
|
||||
// the top as well, and stay offered while it is scrolled away (#305).
|
||||
val listState = rememberLazyListState()
|
||||
// Past days load above the anchor (#367), so the anchor's row counts as the
|
||||
// start of the list.
|
||||
val anchorIndex = remember { mutableIntStateOf(0) }
|
||||
val scrolledAway by remember {
|
||||
derivedStateOf {
|
||||
listState.firstVisibleItemIndex != anchorIndex.intValue ||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package de.jeanlucmakiola.calendula.ui.common
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.saveable.Saver
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
@@ -29,8 +31,20 @@ class ViewFocus(initial: LocalDate) {
|
||||
date = target
|
||||
navigationVersion++
|
||||
}
|
||||
|
||||
/** A date another app asked to see (#524), until the screen on show takes it. */
|
||||
var dateRequest by mutableStateOf<DateRequest?>(null)
|
||||
|
||||
/** [navigateTo], also moving a screen that is already on show, the agenda included. */
|
||||
fun showDate(target: LocalDate) {
|
||||
navigateTo(target)
|
||||
dateRequest = DateRequest(target)
|
||||
}
|
||||
}
|
||||
|
||||
/** One [ViewFocus.showDate]; compared by identity, so asking for the same date twice is two requests. */
|
||||
class DateRequest(val date: LocalDate)
|
||||
|
||||
val ViewFocusSaver: Saver<ViewFocus, String> = Saver(
|
||||
save = { it.date.toString() },
|
||||
restore = { ViewFocus(LocalDate.parse(it)) },
|
||||
@@ -47,3 +61,23 @@ fun <T : Any> EnterOnFocus(key: T, enter: (LocalDate) -> Unit) {
|
||||
val focus = LocalViewFocus.current
|
||||
remember(key) { focus?.date?.also(enter) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a pending [ViewFocus.dateRequest] while this screen is the one on show.
|
||||
* Returns the date asked for as the screen came on ([key]), for it to open on;
|
||||
* one arriving while it is already up goes to [onShown] instead.
|
||||
*/
|
||||
@Composable
|
||||
fun <T : Any> TakeDateRequest(key: T, onShown: (LocalDate) -> Unit = {}): LocalDate? {
|
||||
val focus = LocalViewFocus.current ?: return null
|
||||
val current = LocalChromeSlot.current?.current ?: true
|
||||
val request = focus.dateRequest?.takeIf { current }
|
||||
val atEntry = remember(key) { request }
|
||||
val shown by rememberUpdatedState(onShown)
|
||||
LaunchedEffect(request) {
|
||||
if (request == null) return@LaunchedEffect
|
||||
focus.dateRequest = null
|
||||
if (request !== atEntry) shown(request.date)
|
||||
}
|
||||
return atEntry?.date
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import de.jeanlucmakiola.calendula.ui.common.ScreenChrome
|
||||
import de.jeanlucmakiola.calendula.ui.common.LocalViewMorph
|
||||
import de.jeanlucmakiola.calendula.ui.common.EnterOnFocus
|
||||
import de.jeanlucmakiola.calendula.ui.common.LocalViewFocus
|
||||
import de.jeanlucmakiola.calendula.ui.common.TakeDateRequest
|
||||
import de.jeanlucmakiola.calendula.ui.common.ViewMorphKey
|
||||
import de.jeanlucmakiola.calendula.ui.common.morphDay
|
||||
import de.jeanlucmakiola.calendula.ui.common.morphEvent
|
||||
@@ -480,6 +481,8 @@ fun MonthScreen(
|
||||
jumpToMonth(target.yearMonth)
|
||||
}
|
||||
}
|
||||
// Another app's date asked for while the month is already up (#524); on entry the focus did it.
|
||||
TakeDateRequest(viewModel, onShown = jumpToDate)
|
||||
|
||||
PublishChrome(
|
||||
ScreenChrome(
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -5,6 +5,7 @@ import de.jeanlucmakiola.calendula.domain.reminders.DailyDigestSettings
|
||||
import de.jeanlucmakiola.calendula.domain.reminders.FixedTimeReminder
|
||||
import android.net.Uri
|
||||
import de.jeanlucmakiola.floret.reminders.ReminderOverride
|
||||
import de.jeanlucmakiola.calendula.data.prefs.ExternalDateView
|
||||
import de.jeanlucmakiola.calendula.data.prefs.PastEventDisplay
|
||||
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
||||
import de.jeanlucmakiola.floret.prefs.ThemeMode
|
||||
@@ -62,6 +63,8 @@ data class SettingsUiState(
|
||||
val agendaShowRangeBar: Boolean = true,
|
||||
/** The calendar view the app opens on, and the home of the view back stack (M1). */
|
||||
val defaultView: CalendarView = CalendarView.Week,
|
||||
/** What a date tap from another app opens (#524). */
|
||||
val externalDateView: ExternalDateView = ExternalDateView.DAY,
|
||||
/** Which views the top-bar quick-switch button cycles through, and their order (#24). */
|
||||
val quickSwitchConfig: QuickSwitchConfig = QuickSwitchConfig.Default,
|
||||
/** How the Month view lays itself out: pages, continuous scroll, or split (#38, #53). */
|
||||
|
||||
@@ -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
|
||||
@@ -32,6 +30,7 @@ import de.jeanlucmakiola.calendula.domain.reminders.FixedTimeReminder
|
||||
import de.jeanlucmakiola.floret.reminders.ReminderOverride
|
||||
import de.jeanlucmakiola.floret.reminders.reminderOverrideFor
|
||||
import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs
|
||||
import de.jeanlucmakiola.calendula.data.prefs.ExternalDateView
|
||||
import de.jeanlucmakiola.calendula.data.prefs.PastEventDisplay
|
||||
import de.jeanlucmakiola.calendula.data.prefs.SettingsKeys
|
||||
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
||||
@@ -92,7 +91,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,
|
||||
@@ -152,6 +151,7 @@ class SettingsViewModel @Inject constructor(
|
||||
agendaShowToday = this[SettingsKeys.agendaShowToday],
|
||||
agendaShowRangeBar = this[SettingsKeys.agendaShowRangeBar],
|
||||
defaultView = this[SettingsKeys.defaultView],
|
||||
externalDateView = this[SettingsKeys.externalDateView],
|
||||
quickSwitchConfig = this[SettingsKeys.quickSwitchConfig],
|
||||
monthViewStyle = this[SettingsKeys.monthViewStyle],
|
||||
timelineScale = this[SettingsKeys.timelineScale],
|
||||
@@ -202,17 +202,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 +356,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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -379,6 +375,7 @@ class SettingsViewModel @Inject constructor(
|
||||
fun setDimCompletedEvents(enabled: Boolean) = save { setDimCompletedEvents(enabled) }
|
||||
|
||||
fun setDefaultView(view: CalendarView) = save { setDefaultView(view) }
|
||||
fun setExternalDateView(view: ExternalDateView) = save { setExternalDateView(view) }
|
||||
|
||||
fun setFormFieldDefault(field: EventFormField, enabled: Boolean) = save { setFormFieldDefault(field, enabled) }
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import de.jeanlucmakiola.calendula.R
|
||||
import de.jeanlucmakiola.calendula.data.prefs.ExternalDateView
|
||||
import de.jeanlucmakiola.calendula.data.prefs.PastEventDisplay
|
||||
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
||||
import de.jeanlucmakiola.calendula.data.prefs.TimeFormatPref
|
||||
@@ -76,6 +77,7 @@ internal fun ViewsScreen(
|
||||
) {
|
||||
var showMonthStyle by remember { mutableStateOf(false) }
|
||||
var showDefaultView by remember { mutableStateOf(false) }
|
||||
var showExternalDateView by remember { mutableStateOf(false) }
|
||||
var showWeekStart by remember { mutableStateOf(false) }
|
||||
var showTimeFormat by remember { mutableStateOf(false) }
|
||||
var showTapOpens by remember { mutableStateOf(false) }
|
||||
@@ -103,6 +105,12 @@ internal fun ViewsScreen(
|
||||
position = Position.Top,
|
||||
onClick = { showDefaultView = true },
|
||||
)
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.settings_external_date_view),
|
||||
summary = externalDateViewLabel(state.externalDateView),
|
||||
position = Position.Middle,
|
||||
onClick = { showExternalDateView = true },
|
||||
)
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.settings_week_start),
|
||||
summary = weekStartLabel(state.weekStart).capitalizeStart(currentLocale()),
|
||||
@@ -328,6 +336,17 @@ internal fun ViewsScreen(
|
||||
onDismiss = { showDefaultView = false },
|
||||
)
|
||||
}
|
||||
if (showExternalDateView) {
|
||||
OptionPicker(
|
||||
title = stringResource(R.string.settings_external_date_view),
|
||||
predictiveBack = true,
|
||||
options = ExternalDateView.entries,
|
||||
selected = state.externalDateView,
|
||||
label = { externalDateViewLabel(it) },
|
||||
onSelect = viewModel::setExternalDateView,
|
||||
onDismiss = { showExternalDateView = false },
|
||||
)
|
||||
}
|
||||
if (showWeekStart) {
|
||||
WeekStartPicker(
|
||||
selected = state.weekStart,
|
||||
@@ -519,6 +538,14 @@ internal fun weekStartLabel(pref: WeekStartPref): String = when (pref) {
|
||||
.getDisplayName(JavaTextStyle.FULL, currentLocale())
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun externalDateViewLabel(view: ExternalDateView): String = stringResource(
|
||||
when (view) {
|
||||
ExternalDateView.DAY -> R.string.settings_external_date_day
|
||||
ExternalDateView.DEFAULT -> R.string.settings_external_date_default
|
||||
},
|
||||
)
|
||||
|
||||
@Composable
|
||||
private fun tapOpensLabel(editor: Boolean): String = stringResource(
|
||||
if (editor) R.string.settings_tap_opens_editor else R.string.settings_tap_opens_details,
|
||||
|
||||
@@ -184,6 +184,7 @@ import de.jeanlucmakiola.calendula.ui.common.rememberOutOfViewEdges
|
||||
import de.jeanlucmakiola.calendula.ui.common.rememberCurrentMinute
|
||||
import de.jeanlucmakiola.calendula.ui.common.EnterOnFocus
|
||||
import de.jeanlucmakiola.calendula.ui.common.LocalViewFocus
|
||||
import de.jeanlucmakiola.calendula.ui.common.TakeDateRequest
|
||||
import de.jeanlucmakiola.calendula.ui.common.rememberCalendarFadeSpec
|
||||
import de.jeanlucmakiola.calendula.ui.common.ViewMorphKey
|
||||
import de.jeanlucmakiola.calendula.ui.common.ViewMorphPage
|
||||
@@ -354,6 +355,8 @@ private fun PagedTimelineScreen(
|
||||
val navigationVersion = focus?.navigationVersion ?: 0
|
||||
var handledNavigation by remember { mutableIntStateOf(navigationVersion) }
|
||||
EnterOnFocus(viewModel) { viewModel.jumpTo(it) }
|
||||
// The focus moves the timeline already; this only clears another app's date request (#524).
|
||||
TakeDateRequest(Unit)
|
||||
// Keyed on the view model: collected unkeyed, a switch would read the view
|
||||
// before's anchor and grid for a frame and open its pager.
|
||||
val loadedState by key(viewModel) { viewModel.state.collectAsStateWithLifecycle() }
|
||||
|
||||
@@ -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>
|
||||
@@ -591,6 +591,9 @@
|
||||
<!-- %1$s is the theme the system currently resolves to, e.g. "Dark". -->
|
||||
<string name="settings_theme_system_summary">Currently %1$s</string>
|
||||
<string name="settings_default_view">Default view</string>
|
||||
<string name="settings_external_date_view">Dates opened from other apps</string>
|
||||
<string name="settings_external_date_day">Day view</string>
|
||||
<string name="settings_external_date_default">Default view</string>
|
||||
<string name="settings_dynamic_color">Dynamic colour</string>
|
||||
<string name="settings_dynamic_color_unavailable">Requires Android 12 or newer</string>
|
||||
<string name="settings_soften_colors">Harmonise calendar colours</string>
|
||||
@@ -620,10 +623,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>
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package de.jeanlucmakiola.calendula.ui
|
||||
|
||||
import android.content.Intent
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.data.prefs.ExternalDateView
|
||||
import de.jeanlucmakiola.calendula.ui.common.CalendarView
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.toInstant
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class ExternalDateTapTest {
|
||||
|
||||
private val zone = TimeZone.of("Europe/Berlin")
|
||||
private val lateEvening = LocalDateTime(2026, 11, 30, 23, 30).toInstant(zone).toEpochMilliseconds()
|
||||
|
||||
private fun request(
|
||||
action: String? = Intent.ACTION_VIEW,
|
||||
host: String? = CALENDAR_PROVIDER_HOST,
|
||||
segments: List<String> = listOf("time", lateEvening.toString()),
|
||||
ownDayTap: Boolean = false,
|
||||
) = viewTimeRequest(action, host, segments, zone, ownDayTap)
|
||||
|
||||
@Test
|
||||
fun `a launcher date tap opens its local date and follows the setting`() {
|
||||
assertThat(request()).isEqualTo(WidgetNavRequest.OpenDate("2026-11-30", fromWidget = false, external = true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the daily summary's own tap stays on the day view`() {
|
||||
assertThat(request(ownDayTap = true)?.external).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `other intents are no date tap`() {
|
||||
assertThat(request(action = Intent.ACTION_EDIT)).isNull()
|
||||
assertThat(request(host = "com.example")).isNull()
|
||||
assertThat(request(segments = listOf("events", "12"))).isNull()
|
||||
assertThat(request(segments = listOf("time"))).isNull()
|
||||
assertThat(request(segments = listOf("time", "noon"))).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an external tap set to the default view lands on it`() {
|
||||
val tap = request()!!
|
||||
for (view in CalendarView.entries) {
|
||||
assertThat(tap.stack(view, ExternalDateView.DEFAULT)).containsExactly(view)
|
||||
}
|
||||
assertThat(tap.stack(CalendarView.Month, ExternalDateView.DAY))
|
||||
.containsExactly(CalendarView.Month, CalendarView.Day).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `our own date opens always drill into the day`() {
|
||||
val own = request(ownDayTap = true)!!
|
||||
val widget = WidgetNavRequest.OpenDate("2026-11-30", fromWidget = true)
|
||||
for (open in listOf(own, widget)) {
|
||||
assertThat(open.stack(CalendarView.Agenda, ExternalDateView.DEFAULT))
|
||||
.containsExactly(CalendarView.Agenda, CalendarView.Day).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
|
||||
|
||||
|
||||
+1
-1
Submodule floret-kit updated: 61cad7e560...751d0af2ea.
Reference in new issue
Block a user