Skip to content

Commit

Permalink
update Dashboard events to only pass the tool code and type and not t…
Browse files Browse the repository at this point in the history
…he entire tool object
  • Loading branch information
frett committed Dec 14, 2023
1 parent 5b14110 commit 1269aaa
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
},
)
Expand Down Expand Up @@ -88,12 +87,12 @@ class DashboardActivity : BaseActivity() {
internal lateinit var lazyManifestManager: Lazy<ManifestManager>
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
},
)
Expand All @@ -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))
}
Expand All @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
}
}
},
Expand Down Expand Up @@ -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)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 11 additions & 5 deletions app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardLayouts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 1269aaa

Please sign in to comment.