Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Update Enable transition from session details to the search screen. #799

Merged
merged 4 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import io.github.droidkaigi.confsched2022.feature.staff.StaffNavGraph
import io.github.droidkaigi.confsched2022.feature.staff.staffNavGraph
import io.github.droidkaigi.confsched2022.impl.AndroidCalendarRegistration
import io.github.droidkaigi.confsched2022.impl.AndroidShareManager
import io.github.droidkaigi.confsched2022.model.TimetableCategory
import io.github.droidkaigi.confsched2022.model.TimetableItem
import io.github.droidkaigi.confsched2022.model.TimetableItemId
import io.github.droidkaigi.confsched2022.strings.Strings
Expand Down Expand Up @@ -125,6 +126,7 @@ fun KaigiApp(
showNavigationIcon = showNavigationIcon,
onLinkClick = kaigiExternalNavigationController::navigate,
onNavigationIconClick = kaigiAppScaffoldState::onNavigationClick,
onCategoryTagClick = kaigiAppScaffoldState::onCategoryTagClick,
onBackIconClick = kaigiAppScaffoldState::onBackIconClick,
onSearchIconClick = kaigiAppScaffoldState::onSearchClick,
onTimetableClick = kaigiAppScaffoldState::onTimeTableClick,
Expand Down Expand Up @@ -270,6 +272,14 @@ class KaigiAppScaffoldState @OptIn(ExperimentalMaterial3Api::class) constructor(
)
}

fun onCategoryTagClick(
category: TimetableCategory?
) {
navController.navigate(
route = SessionsNavGraph.sessionSearchRoute(category?.id.toString())
)
}

fun onNavigateFloorMapClick() {
navController.navigate(
route = MapNavGraph.mapRoute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import kotlinx.datetime.toLocalDateTime
@Composable
fun SearchRoot(
modifier: Modifier = Modifier,
initialCategoryId: String? = null,
viewModel: SearchViewModel = hiltViewModel(),
onBackIconClick: () -> Unit = {},
onItemClick: (TimetableItemId) -> Unit,
Expand All @@ -99,6 +100,12 @@ fun SearchRoot(

val keyboardController = LocalSoftwareKeyboardController.current

LaunchedEffect(initialCategoryId) {
if (initialCategoryId != null) {
viewModel.onCategorySelected(initialCategoryId)
}
}

LaunchedEffect(state.filterSheetState) {
when (state.filterSheetState) {
is SearchFilterSheetState.ShowDayFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ class SearchViewModel @Inject constructor(
)
}

fun onCategorySelected(categoryId: String) {
viewModelScope.launch {
val categories = sessionsRepository.getCategories()
if (categories.isEmpty())
return@launch

filters.value = filters.value.copy(
categories = listOf(
categories.first { it.id.toString() == categoryId }
)
)
}
}

fun onDaySelected(day: DroidKaigi2022Day, isSelected: Boolean) {
val selectedDays = filters.value.days.toMutableList()
filters.value = filters.value.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import io.github.droidkaigi.confsched2022.model.KaigiPlace.Prism
import io.github.droidkaigi.confsched2022.model.Lang
import io.github.droidkaigi.confsched2022.model.MultiLangText
import io.github.droidkaigi.confsched2022.model.TimetableAsset
import io.github.droidkaigi.confsched2022.model.TimetableCategory
import io.github.droidkaigi.confsched2022.model.TimetableItem
import io.github.droidkaigi.confsched2022.model.TimetableItem.Session
import io.github.droidkaigi.confsched2022.model.TimetableItemId
Expand All @@ -90,6 +91,7 @@ import java.util.Locale
fun SessionDetailScreenRoot(
timetableItemId: TimetableItemId,
onLinkClick: (url: String) -> Unit,
onCategoryTagClick: (TimetableCategory) -> Unit,
onShareClick: (TimetableItem) -> Unit,
onRegisterCalendarClick: (TimetableItem) -> Unit,
modifier: Modifier = Modifier,
Expand All @@ -105,6 +107,7 @@ fun SessionDetailScreenRoot(
onRetryButtonClick = { viewModel.onRetryButtonClick() },
onAppErrorNotified = { viewModel.onAppErrorNotified() },
onLinkClick = onLinkClick,
onCategoryTagClick = onCategoryTagClick,
onBackIconClick = onBackIconClick,
onFavoriteClick = { currentFavorite ->
viewModel.onFavoriteToggle(timetableItemId, currentFavorite)
Expand Down Expand Up @@ -148,6 +151,7 @@ fun SessionDetailScreen(
onAppErrorNotified: () -> Unit,
modifier: Modifier = Modifier,
onLinkClick: (url: String) -> Unit = { _ -> },
onCategoryTagClick: (category: TimetableCategory) -> Unit = { _ -> },
onBackIconClick: () -> Unit = {},
onFavoriteClick: (Boolean) -> Unit = {},
onShareClick: (TimetableItem) -> Unit = {},
Expand Down Expand Up @@ -202,7 +206,10 @@ fun SessionDetailScreen(
.verticalScroll(rememberScrollState())
.padding(horizontal = 16.dp)
) {
SessionDetailSessionInfo(item = item)
SessionDetailSessionInfo(
onCategoryTagClick = onCategoryTagClick,
item = item,
)

if (item is Session)
SessionDetailDescription(
Expand Down Expand Up @@ -294,6 +301,7 @@ fun SessionDetailBottomAppBar(
@Composable
fun SessionTagsLine(
item: TimetableItem,
onCategoryTagClick: (category: TimetableCategory) -> Unit,
modifier: Modifier = Modifier,
) {
val sessionMinutes =
Expand Down Expand Up @@ -336,6 +344,7 @@ fun SessionTagsLine(
Text(sessionMinutes + "min")
}
KaigiTag(
modifier = Modifier.clickable { onCategoryTagClick(item.category) },
backgroundColor = MaterialTheme.colorScheme.secondaryContainer
) {
Text(item.category.title.currentLangTitle)
Expand Down Expand Up @@ -417,6 +426,7 @@ fun SessionScheduleInfo(
@Composable
fun SessionDetailSessionInfo(
item: TimetableItem,
onCategoryTagClick: (category: TimetableCategory) -> Unit,
modifier: Modifier = Modifier,
) {
Column(modifier = modifier) {
Expand All @@ -428,7 +438,10 @@ fun SessionDetailSessionInfo(

Spacer(modifier = Modifier.padding(24.dp))

SessionTagsLine(item = item)
SessionTagsLine(
onCategoryTagClick = onCategoryTagClick,
item = item,
)

Spacer(modifier = Modifier.padding(24.dp))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import io.github.droidkaigi.confsched2022.model.TimetableCategory
import io.github.droidkaigi.confsched2022.model.TimetableItem
import io.github.droidkaigi.confsched2022.model.TimetableItemId

fun NavGraphBuilder.sessionsNavGraph(
showNavigationIcon: Boolean,
onNavigationIconClick: () -> Unit,
onCategoryTagClick: (category: TimetableCategory) -> Unit,
onLinkClick: (url: String) -> Unit,
onBackIconClick: () -> Unit,
onSearchIconClick: () -> Unit,
Expand Down Expand Up @@ -39,6 +41,7 @@ fun NavGraphBuilder.sessionsNavGraph(
val id = it.arguments?.getString("id") ?: ""
SessionDetailScreenRoot(
timetableItemId = TimetableItemId(id),
onCategoryTagClick = onCategoryTagClick,
onLinkClick = onLinkClick,
onBackIconClick = onBackIconClick,
onNavigateFloorMapClick = onNavigateFloorMapClick,
Expand All @@ -55,13 +58,33 @@ fun NavGraphBuilder.sessionsNavGraph(
onBackIconClick = onBackIconClick,
)
}

composable(
route = SessionsNavGraph.sessionSearchRoute("{id}"),
arguments = listOf(
navArgument("id") {
type = NavType.StringType
}
)
) {
val id = it.arguments?.getString("id") ?: ""
SearchRoot(
initialCategoryId = id,
onItemClick = onTimetableClick,
onBackIconClick = onBackIconClick,
)
}
}

object SessionsNavGraph {
const val sessionRoute = "sessions"
fun sessionDetailRoute(sessionId: String) =
"session/detail/$sessionId"

fun sessionSearchRoute() =
"session/search"
fun sessionSearchRoute(categoryId: String? = null) =
if (categoryId != null) {
"session/search/$categoryId"
} else {
"session/search"
}
}