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

[Android] Search filters #642

Merged
merged 10 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 9 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 @@ -3,6 +3,7 @@ package io.github.droidkaigi.confsched2022.data.sessions
import io.github.droidkaigi.confsched2022.data.SettingsDatastore
import io.github.droidkaigi.confsched2022.model.DroidKaigiSchedule
import io.github.droidkaigi.confsched2022.model.SessionsRepository
import io.github.droidkaigi.confsched2022.model.TimetableCategory
import io.github.droidkaigi.confsched2022.model.TimetableItemId
import kotlinx.collections.immutable.toPersistentSet
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -30,6 +31,10 @@ public class DataSessionsRepository(
}
}

override suspend fun getCategories(): List<TimetableCategory> {
return sessionsDao.selectAllCategories()
}

override suspend fun refresh() {
val timetable = sessionsApi.timetable()
sessionsDao.deleteAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.droidkaigi.confsched2022.data.sessions
import io.github.droidkaigi.confsched2022.model.DroidKaigiSchedule
import io.github.droidkaigi.confsched2022.model.SessionsRepository
import io.github.droidkaigi.confsched2022.model.Timetable
import io.github.droidkaigi.confsched2022.model.TimetableCategory
import io.github.droidkaigi.confsched2022.model.TimetableItemId
import io.github.droidkaigi.confsched2022.model.fake
import kotlinx.collections.immutable.PersistentSet
Expand All @@ -27,6 +28,10 @@ public class FakeSessionsRepository : SessionsRepository {
override suspend fun refresh() {
}

override suspend fun getCategories(): List<TimetableCategory> {
return emptyList()
}

override suspend fun setFavorite(sessionId: TimetableItemId, favorite: Boolean) {
if (favorite) {
favorites.value = favorites.value.add(sessionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ public class SessionsDao(
timetableItemSessionSpeakersQueries.deleteAll()
}

public fun selectAllCategories(): List<TimetableCategory> {
return timetableItemSessionQueries.selectAllCategories { id, titleJa, titleEn ->
TimetableCategory(
id = id,
title = MultiLangText(
jaTitle = titleJa,
enTitle = titleEn
)
)
}.executeAsList()
}

private fun TimetableItem.Session.toModel(): TimetableItemSession {
return TimetableItemSession(
id = id.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ INSERT INTO timetableItemSession (
) VALUES ?;

deleteAll:
DELETE FROM timetableItemSession;
DELETE FROM timetableItemSession;

selectAllCategories:
SELECT DISTINCT categoryId, categoryTitleJa, categoryTitleEn
FROM timetableItemSession;
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.droidkaigi.confsched2022.model

public data class Filters(
val day: DroidKaigi2022Day? = null,
val categories: List<TimetableCategory> = emptyList(),
val filterFavorite: Boolean = false,
val filterSession: Boolean = false,
val searchWord: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface SessionsRepository {
.map { it.findTimetableItem(timetableItemId) }
}

public suspend fun getCategories(): List<TimetableCategory>

public suspend fun refresh()
public suspend fun setFavorite(sessionId: TimetableItemId, favorite: Boolean)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public data class Timetable(

public fun filtered(filters: Filters): Timetable {
var timetableItems = timetableItems.toList()
if (filters.day != null) {
timetableItems = timetableItems.filter { timetableItem ->
timetableItem.day == filters.day
}
}
if (filters.categories.isNotEmpty()) {
timetableItems = timetableItems.filter { timetableItem ->
filters.categories.contains(timetableItem.category)
}
}
if (filters.filterFavorite) {
timetableItems = timetableItems.filter { timetableItem ->
favorites.contains(timetableItem.id)
Expand Down
5 changes: 5 additions & 0 deletions core/model/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<!-- Contributors -->
<string name="contributors_top_app_bar_title">コントリビューター</string>

<!-- Search -->
<string name="search_filter_select_day">開催日</string>
<string name="search_filter_select_category">カテゴリ</string>
<string name="search_filter_favorites">お気に入り済み</string>

<!-- Map -->

<!-- Sessions -->
Expand Down
5 changes: 5 additions & 0 deletions core/model/src/commonMain/resources/MR/en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<!-- Contributors -->
<string name="contributors_top_app_bar_title">Contributors</string>

<!-- Search -->
<string name="search_filter_select_day">Day</string>
<string name="search_filter_select_category">Category</string>
<string name="search_filter_favorites">Favorites</string>

<!-- Map -->

<!-- Sessions -->
Expand Down
5 changes: 5 additions & 0 deletions core/model/src/commonMain/resources/MR/zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<!-- Contributors -->
<string name="contributors_top_app_bar_title">贡献者</string>

<!-- Search -->
<string name="search_filter_select_day">Day</string>
<string name="search_filter_select_category">Category</string>
<string name="search_filter_favorites">Favorites</string>

<!-- Map -->

<!-- Sessions -->
Expand Down
1 change: 1 addition & 0 deletions feature/sessions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
implementation(libs.androidxCoreKtx)
implementation(libs.composeUi)
implementation(libs.accompanistFlowlayout)
implementation(libs.composeMaterial)
implementation(libs.composeMaterial3)
implementation(libs.composeUiToolingPreview)
implementation(libs.androidxLifecycleLifecycleRuntimeKtx)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package io.github.droidkaigi.confsched2022.feature.sessions

import androidx.compose.animation.animateColor
import androidx.compose.animation.core.animateDp
import androidx.compose.animation.core.tween
import androidx.compose.animation.core.updateTransition
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.width
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.OutlinedButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp

private const val TransitionAnimationDuration = 300

@Composable
fun FilterButton(
isSelected: Boolean,
isDropDown: Boolean,
text: String,
modifier: Modifier = Modifier,
onClicked: () -> Unit
) {
val transition = updateTransition(targetState = isSelected)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒


val backgroundColor by transition.animateColor(
label = "backgroundColor",
transitionSpec = { tween(durationMillis = TransitionAnimationDuration) }
) {
if (it)
MaterialTheme.colorScheme.secondaryContainer
else MaterialTheme.colorScheme.surface
}

val strokeColor by transition.animateColor(
label = "strokeColor",
transitionSpec = { tween(durationMillis = TransitionAnimationDuration) }
) {
if (it)
MaterialTheme.colorScheme.secondaryContainer
else MaterialTheme.colorScheme.outline
}

val contentColor by transition.animateColor(
label = "textColor",
transitionSpec = { tween(durationMillis = TransitionAnimationDuration) }
) {
if (it)
MaterialTheme.colorScheme.onSecondaryContainer
else MaterialTheme.colorScheme.onSurface
}

val checkIconWidth by transition.animateDp(
label = "checkIconWidth",
transitionSpec = { tween(durationMillis = TransitionAnimationDuration) }
) { if (it) 16.dp else 0.dp }

OutlinedButton(
modifier = modifier,
onClick = onClicked,
colors = ButtonDefaults.outlinedButtonColors(
backgroundColor = backgroundColor
),
contentPadding = PaddingValues(
horizontal = 16.dp,
vertical = 6.dp
),
border = BorderStroke(
width = 1.dp,
color = strokeColor
),
shape = MaterialTheme.shapes.small
) {
if (isSelected) {
Icon(
modifier = Modifier.width(width = checkIconWidth),
painter = painterResource(id = R.drawable.ic_filter_selected),
contentDescription = null,
tint = MaterialTheme.colorScheme.onSecondaryContainer
)
Spacer(modifier = Modifier.width(8.dp))
}

Text(
text = text,
style = MaterialTheme.typography.labelLarge,
color = contentColor
)

if (isDropDown) {
Spacer(modifier = Modifier.width(8.dp))

Icon(
painter = painterResource(id = R.drawable.ic_filter_dropdown),
contentDescription = null,
tint = contentColor
)
}
}
}
Loading