-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support several sort options for lookup history (#385)
- persist
- Loading branch information
David Ly
committed
Aug 25, 2023
1 parent
5ce7b2f
commit 07a375c
Showing
16 changed files
with
271 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
data/domain/src/main/java/ly/david/data/domain/history/HistorySortOption.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ly.david.data.domain.history | ||
|
||
enum class HistorySortOption { | ||
ALPHABETICALLY, | ||
ALPHABETICALLY_REVERSE, | ||
RECENTLY_VISITED, | ||
LEAST_RECENTLY_VISITED, | ||
MOST_VISITED, | ||
LEAST_VISITED, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
ui/history/src/main/java/ly/david/ui/history/HistorySortBottomSheet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package ly.david.ui.history | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Check | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.ModalBottomSheet | ||
import androidx.compose.material3.SheetState | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.rememberModalBottomSheetState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.res.stringResource | ||
import ly.david.data.domain.history.HistorySortOption | ||
import ly.david.ui.common.R | ||
import ly.david.ui.common.component.ClickableItem | ||
import ly.david.ui.core.preview.DefaultPreviews | ||
import ly.david.ui.core.theme.PreviewTheme | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
internal fun HistorySortBottomSheet( | ||
sortOption: HistorySortOption, | ||
onSortOptionClick: (HistorySortOption) -> Unit = {}, | ||
bottomSheetState: SheetState = rememberModalBottomSheetState(), | ||
onDismiss: () -> Unit = {}, | ||
) { | ||
ModalBottomSheet( | ||
onDismissRequest = onDismiss, | ||
sheetState = bottomSheetState, | ||
) { | ||
HistorySortBottomSheetContent( | ||
sortOption = sortOption, | ||
onSortOptionClick = onSortOptionClick | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun HistorySortBottomSheetContent( | ||
sortOption: HistorySortOption = HistorySortOption.RECENTLY_VISITED, | ||
onSortOptionClick: (HistorySortOption) -> Unit = {}, | ||
) { | ||
Column { | ||
HistorySortOption.entries.forEach { | ||
ClickableItem( | ||
title = stringResource(id = it.labelRes), | ||
endIcon = if (sortOption == it) Icons.Default.Check else null, | ||
onClick = { | ||
onSortOptionClick(it) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
internal val HistorySortOption.labelRes: Int | ||
get() { | ||
return when (this) { | ||
HistorySortOption.ALPHABETICALLY -> R.string.alphabetically | ||
HistorySortOption.ALPHABETICALLY_REVERSE -> R.string.alphabetically_reverse | ||
HistorySortOption.LEAST_RECENTLY_VISITED -> R.string.least_recently_visited | ||
HistorySortOption.RECENTLY_VISITED -> R.string.recently_visited | ||
HistorySortOption.MOST_VISITED -> R.string.most_visited | ||
HistorySortOption.LEAST_VISITED -> R.string.least_visited | ||
} | ||
} | ||
|
||
@DefaultPreviews | ||
@Composable | ||
internal fun PreviewHistorySortBottomSheetContent() { | ||
PreviewTheme { | ||
Surface { | ||
HistorySortBottomSheetContent() | ||
} | ||
} | ||
} |
Oops, something went wrong.