Skip to content

Commit

Permalink
Merge pull request #3273 from CruGlobal/GT-2196-spotlight-tool-additi…
Browse files Browse the repository at this point in the history
…onal-language

GT-2196 Pass the filter language when opening a spotlight tool
  • Loading branch information
frett authored Jan 10, 2024
2 parents 1b5eabe + efe6d27 commit b7442ee
Show file tree
Hide file tree
Showing 28 changed files with 1,777 additions and 552 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.content.Intent
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import com.slack.circuit.foundation.Circuit
import com.slack.circuit.foundation.CircuitCompositionLocals
import dagger.Lazy
import dagger.hilt.android.AndroidEntryPoint
import java.util.Locale
Expand All @@ -27,23 +29,28 @@ class DashboardActivity : BaseActivity() {
private val viewModel: DashboardViewModel by viewModels()
private val launchTrackingViewModel: LaunchTrackingViewModel by viewModels()

@Inject
lateinit var circuit: Circuit

// region Lifecycle
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) intent?.let { processIntent(it) }
triggerOnboardingIfNecessary()
setContent {
GodToolsTheme {
DashboardLayout(
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) }
}
},
)
CircuitCompositionLocals(circuit) {
GodToolsTheme {
DashboardLayout(
onEvent = { e ->
when (e) {
is DashboardEvent.OpenTool ->
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 +95,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 @@ -35,13 +35,15 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.slack.circuit.foundation.CircuitContent
import com.slack.circuit.runtime.Navigator
import com.slack.circuit.runtime.screen.Screen
import java.util.Locale
import kotlinx.coroutines.launch
import org.ccci.gto.android.common.androidx.compose.material3.ui.navigationdrawer.toggle
import org.ccci.gto.android.common.androidx.compose.material3.ui.pullrefresh.PullRefreshIndicator
import org.ccci.gto.android.common.androidx.compose.ui.draw.autoMirror
import org.ccci.gto.android.common.androidx.lifecycle.compose.OnResume
import org.cru.godtools.BuildConfig
import org.cru.godtools.R
import org.cru.godtools.analytics.compose.RecordAnalyticsScreen
import org.cru.godtools.analytics.firebase.model.ACTION_IAM_ALL_TOOLS
Expand All @@ -59,14 +61,20 @@ import org.cru.godtools.ui.dashboard.home.DashboardHomeEvent
import org.cru.godtools.ui.dashboard.home.HomeContent
import org.cru.godtools.ui.dashboard.lessons.DashboardLessonsEvent
import org.cru.godtools.ui.dashboard.lessons.LessonsLayout
import org.cru.godtools.ui.dashboard.tools.ToolsLayout
import org.cru.godtools.ui.dashboard.tools.ToolsScreen
import org.cru.godtools.ui.drawer.DrawerMenuLayout
import org.cru.godtools.ui.tooldetails.ToolDetailsScreen
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 +129,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 +143,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,25 +154,43 @@ 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))
}
},
)

Page.ALL_TOOLS -> ToolsLayout(
onEvent = { e ->
when (e) {
is ToolCardEvent.Click -> onEvent(DashboardEvent.OpenToolDetails(e.tool))
is ToolCardEvent.OpenToolDetails ->
onEvent(DashboardEvent.OpenToolDetails(e.tool, e.additionalLocale))
is ToolCardEvent.OpenTool ->
if (BuildConfig.DEBUG) error("opening a tool from All Tools is unsupported")
Page.ALL_TOOLS -> {
val navigator = remember(onEvent) {
object : Navigator {
override fun goTo(screen: Screen) {
when (screen) {
is ToolDetailsScreen -> onEvent(
DashboardEvent.OpenToolDetails(
screen.initialTool,
screen.secondLanguage,
)
)
}
}

override fun pop() = TODO("Not yet implemented")
override fun resetRoot(newRoot: Screen) = TODO("Not yet implemented")
}
}
)
CircuitContent(
screen = ToolsScreen,
navigator = navigator,
)
}
}
}
}
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
Loading

0 comments on commit b7442ee

Please sign in to comment.