From 1269aaafb985cd2f8b1193d55afc14d6223d9e26 Mon Sep 17 00:00:00 2001 From: Daniel Frett Date: Wed, 13 Dec 2023 08:20:18 -0700 Subject: [PATCH] update Dashboard events to only pass the tool code and type and not the entire tool object --- .../ui/dashboard/DashboardActivity.kt | 13 +++++----- .../godtools/ui/dashboard/DashboardLayout.kt | 25 +++++++++++++------ .../ui/dashboard/home/AllFavoritesLayout.kt | 4 +-- .../godtools/ui/dashboard/home/HomeLayout.kt | 19 ++++++++------ .../ui/dashboard/lessons/LessonsLayout.kt | 5 ++-- .../ui/dashboard/tools/ToolsLayout.kt | 11 +++++--- .../cru/godtools/ui/tools/ToolCardActions.kt | 2 +- .../cru/godtools/ui/tools/ToolCardLayouts.kt | 16 ++++++++---- 8 files changed, 60 insertions(+), 35 deletions(-) diff --git a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/DashboardActivity.kt b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/DashboardActivity.kt index 147d8219a9..8a50950b3b 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/DashboardActivity.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/DashboardActivity.kt @@ -38,9 +38,8 @@ class DashboardActivity : BaseActivity() { onEvent = { e -> when (e) { is DashboardEvent.OpenTool -> - openTool(e.tool, *listOfNotNull(e.lang1, e.lang2).toTypedArray()) - is DashboardEvent.OpenToolDetails -> - e.tool?.code?.let { startToolDetailsActivity(it, e.lang) } + openTool(e.tool, e.type, *listOfNotNull(e.lang1, e.lang2).toTypedArray()) + is DashboardEvent.OpenToolDetails -> e.tool?.let { startToolDetailsActivity(it, e.lang) } } }, ) @@ -88,12 +87,12 @@ class DashboardActivity : BaseActivity() { internal lateinit var lazyManifestManager: Lazy private val manifestManager get() = lazyManifestManager.get() - private fun openTool(tool: Tool?, vararg languages: Locale) { - val code = tool?.code ?: return + private fun openTool(tool: String?, type: Tool.Type?, vararg languages: Locale) { + if (tool == null || type == null) return if (languages.isEmpty()) return - languages.forEach { manifestManager.preloadLatestPublishedManifest(code, it) } - openToolActivity(code, tool.type, *languages) + languages.forEach { manifestManager.preloadLatestPublishedManifest(tool, it) } + openToolActivity(tool, type, *languages) } // endregion ToolsAdapterCallbacks // endregion UI diff --git a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/DashboardLayout.kt b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/DashboardLayout.kt index d9dbf65db6..ae4bb1fcba 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/DashboardLayout.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/DashboardLayout.kt @@ -64,9 +64,14 @@ import org.cru.godtools.ui.drawer.DrawerMenuLayout import org.cru.godtools.ui.tools.ToolCardEvent internal sealed interface DashboardEvent { - open class OpenTool(val tool: Tool?, val lang1: Locale?, val lang2: Locale?) : DashboardEvent - class OpenLesson(tool: Tool?, lang: Locale?) : OpenTool(tool, lang, null) - class OpenToolDetails(val tool: Tool?, val lang: Locale? = null) : DashboardEvent + open class OpenTool( + val tool: String?, + val type: Tool.Type?, + val lang1: Locale?, + val lang2: Locale? = null, + ) : DashboardEvent + class OpenLesson(lesson: String?, lang: Locale?) : OpenTool(lesson, Tool.Type.LESSON, lang) + class OpenToolDetails(val tool: String?, val lang: Locale? = null) : DashboardEvent } @Composable @@ -121,7 +126,7 @@ internal fun DashboardLayout(onEvent: (DashboardEvent) -> Unit, viewModel: Dashb onEvent = { when (it) { is DashboardLessonsEvent.OpenLesson -> - onEvent(DashboardEvent.OpenLesson(it.tool, it.lang)) + onEvent(DashboardEvent.OpenLesson(it.lesson, it.lang)) } }, ) @@ -135,7 +140,7 @@ internal fun DashboardLayout(onEvent: (DashboardEvent) -> Unit, viewModel: Dashb } DashboardHomeEvent.ViewAllTools -> viewModel.updateCurrentPage(Page.ALL_TOOLS) is DashboardHomeEvent.OpenTool -> - onEvent(DashboardEvent.OpenTool(it.tool, it.lang1, it.lang2)) + onEvent(DashboardEvent.OpenTool(it.tool, it.type, it.lang1, it.lang2)) is DashboardHomeEvent.OpenToolDetails -> onEvent(DashboardEvent.OpenToolDetails(it.tool)) } @@ -146,8 +151,14 @@ internal fun DashboardLayout(onEvent: (DashboardEvent) -> Unit, viewModel: Dashb onEvent = { when (it) { is ToolCardEvent.Click, - is ToolCardEvent.OpenTool -> - onEvent(DashboardEvent.OpenTool(it.tool, it.lang1, it.lang2)) + is ToolCardEvent.OpenTool, -> onEvent( + DashboardEvent.OpenTool( + tool = it.tool, + type = it.toolType, + lang1 = it.lang1, + lang2 = it.lang2, + ) + ) is ToolCardEvent.OpenToolDetails -> onEvent(DashboardEvent.OpenToolDetails(it.tool)) } diff --git a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/AllFavoritesLayout.kt b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/AllFavoritesLayout.kt index d1befb8854..b5db75750e 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/AllFavoritesLayout.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/AllFavoritesLayout.kt @@ -82,12 +82,12 @@ internal fun AllFavoritesList( is ToolCardEvent.Click, is ToolCardEvent.OpenTool -> viewModel.recordOpenClickInAnalytics( ACTION_OPEN_TOOL, - it.tool?.code, + it.tool, SOURCE_FAVORITE ) is ToolCardEvent.OpenToolDetails -> viewModel.recordOpenClickInAnalytics( ACTION_OPEN_TOOL_DETAILS, - it.tool?.code, + it.tool, SOURCE_FAVORITE ) } diff --git a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/HomeLayout.kt b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/HomeLayout.kt index 5190d14795..946ccdc006 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/HomeLayout.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/home/HomeLayout.kt @@ -52,13 +52,18 @@ import org.cru.godtools.ui.tools.ToolCardEvent private val PADDING_HORIZONTAL = 16.dp internal sealed interface DashboardHomeEvent { - open class OpenTool(val tool: Tool?, val lang1: Locale?, val lang2: Locale? = null) : DashboardHomeEvent { - constructor(event: ToolCardEvent) : this(event.tool, event.lang1, event.lang2) + open class OpenTool( + val tool: String?, + val type: Tool.Type?, + val lang1: Locale?, + val lang2: Locale? = null, + ) : DashboardHomeEvent { + constructor(event: ToolCardEvent) : this(event.tool, event.toolType, event.lang1, event.lang2) } - open class OpenToolDetails(val tool: Tool?) : DashboardHomeEvent { + open class OpenToolDetails(val tool: String?) : DashboardHomeEvent { constructor(event: ToolCardEvent.OpenToolDetails) : this(event.tool) } - class OpenLesson(event: ToolCardEvent) : OpenTool(event.tool, event.lang1, null) + class OpenLesson(event: ToolCardEvent) : OpenTool(event.tool, Tool.Type.LESSON, event.lang1) data object ViewAllFavorites : DashboardHomeEvent data object ViewAllTools : DashboardHomeEvent } @@ -111,7 +116,7 @@ internal fun HomeContent(onEvent: (DashboardHomeEvent) -> Unit, viewModel: HomeV onEvent = { when (it) { is ToolCardEvent.Click, is ToolCardEvent.OpenTool -> { - viewModel.recordOpenClickInAnalytics(ACTION_OPEN_LESSON, it.tool?.code, SOURCE_FEATURED) + viewModel.recordOpenClickInAnalytics(ACTION_OPEN_LESSON, it.tool, SOURCE_FEATURED) onEvent(DashboardHomeEvent.OpenLesson(it)) } is ToolCardEvent.OpenToolDetails -> { @@ -148,12 +153,12 @@ internal fun HomeContent(onEvent: (DashboardHomeEvent) -> Unit, viewModel: HomeV when { it is DashboardHomeEvent.OpenTool -> viewModel.recordOpenClickInAnalytics( ACTION_OPEN_TOOL, - it.tool?.code, + it.tool, SOURCE_FAVORITE ) it is DashboardHomeEvent.OpenToolDetails -> viewModel.recordOpenClickInAnalytics( ACTION_OPEN_TOOL_DETAILS, - it.tool?.code, + it.tool, SOURCE_FAVORITE ) } diff --git a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/lessons/LessonsLayout.kt b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/lessons/LessonsLayout.kt index 5c29b52a79..ec4befb066 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/lessons/LessonsLayout.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/lessons/LessonsLayout.kt @@ -19,12 +19,11 @@ import androidx.lifecycle.viewmodel.compose.viewModel import java.util.Locale import org.cru.godtools.BuildConfig import org.cru.godtools.R -import org.cru.godtools.model.Tool import org.cru.godtools.ui.tools.LessonToolCard import org.cru.godtools.ui.tools.ToolCardEvent internal sealed interface DashboardLessonsEvent { - class OpenLesson(val tool: Tool?, val lang: Locale?) : DashboardLessonsEvent + class OpenLesson(val lesson: String?, val lang: Locale?) : DashboardLessonsEvent } @Composable @@ -40,7 +39,7 @@ internal fun LessonsLayout(viewModel: LessonsViewModel = viewModel(), onEvent: ( onEvent = { when (it) { is ToolCardEvent.OpenTool, is ToolCardEvent.Click -> { - viewModel.recordOpenLessonInAnalytics(it.tool?.code) + viewModel.recordOpenLessonInAnalytics(it.tool) onEvent(DashboardLessonsEvent.OpenLesson(it.tool, it.lang1)) } is ToolCardEvent.OpenToolDetails -> { diff --git a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/tools/ToolsLayout.kt b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/tools/ToolsLayout.kt index 490968a040..80e4e0564a 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/dashboard/tools/ToolsLayout.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/dashboard/tools/ToolsLayout.kt @@ -96,8 +96,13 @@ internal fun ToolsLayout( is ToolCardEvent.Click, is ToolCardEvent.OpenTool, is ToolCardEvent.OpenToolDetails -> { - viewModel.recordOpenToolDetailsInAnalytics(it.tool?.code, SOURCE_ALL_TOOLS) - onEvent(ToolCardEvent.OpenToolDetails(it.tool, viewModel.selectedLocale.value)) + viewModel.recordOpenToolDetailsInAnalytics(it.tool, SOURCE_ALL_TOOLS) + onEvent( + ToolCardEvent.OpenToolDetails( + tool = it.tool, + additionalLocale = viewModel.selectedLocale.value, + ) + ) } } }, @@ -151,7 +156,7 @@ internal fun ToolSpotlight( is ToolCardEvent.Click, is ToolCardEvent.OpenTool, is ToolCardEvent.OpenToolDetails -> - viewModel.recordOpenToolDetailsInAnalytics(it.tool?.code, SOURCE_SPOTLIGHT) + viewModel.recordOpenToolDetailsInAnalytics(it.tool, SOURCE_SPOTLIGHT) } onEvent(it) }, diff --git a/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardActions.kt b/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardActions.kt index 2b0db1ec8e..1fff020801 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardActions.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardActions.kt @@ -42,7 +42,7 @@ internal fun ToolCardActions( ToolCard.Event.OpenTool -> onEvent( OpenToolEvent(tool, firstTranslation.value?.languageCode, secondTranslation?.languageCode) ) - ToolCard.Event.OpenToolDetails -> onEvent(ToolCardEvent.OpenToolDetails(tool)) + ToolCard.Event.OpenToolDetails -> onEvent(ToolCardEvent.OpenToolDetails(tool?.code)) ToolCard.Event.Click -> TODO() ToolCard.Event.PinTool -> TODO() ToolCard.Event.UnpinTool -> TODO() diff --git a/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardLayouts.kt b/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardLayouts.kt index 5630ce681b..1a848baf68 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardLayouts.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardLayouts.kt @@ -84,14 +84,20 @@ private val toolCardInfoLabelColor: Color @Composable get() { } private val toolCardInfoLabelStyle @Composable get() = MaterialTheme.typography.labelSmall -sealed class ToolCardEvent(val tool: Tool?, val lang1: Locale?, val lang2: Locale?) { +sealed class ToolCardEvent( + val tool: String?, + val toolType: Tool.Type?, + val lang1: Locale? = null, + val lang2: Locale? = null +) { class Click( tool: Tool?, lang1: Locale? = null, lang2: Locale? = null, - ) : ToolCardEvent(tool, lang1, lang2) - class OpenTool(tool: Tool?, lang1: Locale? = null, lang2: Locale? = null) : ToolCardEvent(tool, lang1, lang2) - class OpenToolDetails(tool: Tool?, val additionalLocale: Locale? = null) : ToolCardEvent(tool, null, null) + ) : ToolCardEvent(tool?.code, tool?.type, lang1, lang2) + class OpenTool(tool: Tool?, lang1: Locale? = null, lang2: Locale? = null) : + ToolCardEvent(tool?.code, tool?.type, lang1, lang2) + class OpenToolDetails(tool: String?, val additionalLocale: Locale? = null) : ToolCardEvent(tool, null) } @Composable @@ -262,7 +268,7 @@ fun SquareToolCard( ToolCard.Event.OpenTool -> onEvent( ToolCardEvent.OpenTool(tool, firstTranslation.value?.languageCode, secondTranslation?.languageCode) ) - ToolCard.Event.OpenToolDetails -> onEvent(ToolCardEvent.OpenToolDetails(tool)) + ToolCard.Event.OpenToolDetails -> onEvent(ToolCardEvent.OpenToolDetails(toolCode)) ToolCard.Event.PinTool -> viewModel.pinTool() ToolCard.Event.UnpinTool -> viewModel.unpinTool() }