Skip to content

Commit

Permalink
Merge pull request #45 from lneugebauer/feature/30-add-tags-v2
Browse files Browse the repository at this point in the history
Add keywords
  • Loading branch information
lneugebauer committed Sep 25, 2023
2 parents dbfcc33 + 4da6976 commit 5cfb420
Show file tree
Hide file tree
Showing 20 changed files with 653 additions and 314 deletions.
39 changes: 19 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ GEM
specs:
CFPropertyList (3.0.6)
rexml
addressable (2.8.4)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
artifactory (3.0.15)
atomos (0.1.3)
aws-eventstream (1.2.0)
aws-partitions (1.786.0)
aws-sdk-core (3.178.0)
aws-partitions (1.827.0)
aws-sdk-core (3.183.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.71.0)
aws-sdk-core (~> 3, >= 3.177.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.130.0)
aws-sdk-core (~> 3, >= 3.177.0)
aws-sdk-s3 (1.135.0)
aws-sdk-core (~> 3, >= 3.181.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.6)
aws-sigv4 (1.6.0)
Expand All @@ -36,7 +36,7 @@ GEM
unf (>= 0.0.5, < 1.0.0)
dotenv (2.8.1)
emoji_regex (3.2.3)
excon (0.100.0)
excon (0.103.0)
faraday (1.10.3)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
Expand Down Expand Up @@ -66,7 +66,7 @@ GEM
faraday_middleware (1.2.0)
faraday (~> 1.0)
fastimage (2.2.7)
fastlane (2.214.0)
fastlane (2.216.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.8, < 3.0.0)
artifactory (~> 3.0)
Expand All @@ -87,6 +87,7 @@ GEM
google-apis-playcustomapp_v1 (~> 0.1)
google-cloud-storage (~> 1.31)
highline (~> 2.0)
http-cookie (~> 1.0.5)
json (< 3.0.0)
jwt (>= 2.1.0, < 3)
mini_magick (>= 4.9.4, < 5.0.0)
Expand All @@ -98,7 +99,7 @@ GEM
security (= 0.1.3)
simctl (~> 1.6.3)
terminal-notifier (>= 2.0.0, < 3.0.0)
terminal-table (>= 1.4.5, < 2.0.0)
terminal-table (~> 3)
tty-screen (>= 0.6.3, < 1.0.0)
tty-spinner (>= 0.8.0, < 1.0.0)
word_wrap (~> 1.0.0)
Expand All @@ -107,9 +108,9 @@ GEM
xcpretty-travis-formatter (>= 0.0.3)
fastlane-plugin-android_versioning (0.5.5)
gh_inspector (1.1.3)
google-apis-androidpublisher_v3 (0.45.0)
google-apis-androidpublisher_v3 (0.50.0)
google-apis-core (>= 0.11.0, < 2.a)
google-apis-core (0.11.0)
google-apis-core (0.11.1)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.16.2, < 2.a)
httpclient (>= 2.8.1, < 3.a)
Expand Down Expand Up @@ -138,10 +139,9 @@ GEM
google-cloud-core (~> 1.6)
googleauth (>= 0.16.2, < 2.a)
mini_mime (~> 1.0)
googleauth (1.6.0)
googleauth (1.8.1)
faraday (>= 0.17.3, < 3.a)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
Expand All @@ -152,9 +152,8 @@ GEM
jmespath (1.6.2)
json (2.6.3)
jwt (2.7.1)
memoist (0.16.2)
mini_magick (4.12.0)
mini_mime (1.1.2)
mini_mime (1.1.5)
multi_json (1.15.0)
multipart-post (2.3.0)
nanaimo (0.3.0)
Expand All @@ -169,12 +168,12 @@ GEM
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.2.5)
rexml (3.2.6)
rouge (2.0.7)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
security (0.1.3)
signet (0.17.0)
signet (0.18.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
Expand All @@ -183,8 +182,8 @@ GEM
CFPropertyList
naturally
terminal-notifier (2.0.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
trailblazer-option (0.1.2)
tty-cursor (0.7.1)
tty-screen (0.8.1)
Expand All @@ -194,10 +193,10 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (1.8.0)
unicode-display_width (2.4.2)
webrick (1.8.1)
word_wrap (1.0.0)
xcodeproj (1.22.0)
xcodeproj (1.23.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ dependencies {
implementation "com.mikepenz:aboutlibraries-core:$aboutlibs_version"
implementation "com.mikepenz:aboutlibraries-compose:$aboutlibs_version"

implementation 'io.github.dokar3:chiptextfield:0.4.9'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,26 @@ fun CategoryListScreen(
val uiState by viewModel.uiState.collectAsState()

Scaffold(
topBar = { CategoryListTopBar() },
topBar = { TopAppBar() },
) { innerPadding ->
when (uiState) {
is CategoryListScreenState.Initial -> Loader()
is CategoryListScreenState.Loaded -> {
val categories = (uiState as CategoryListScreenState.Loaded).data
CategoryListScreen(
data = categories,
modifier = Modifier.padding(innerPadding),
) { categoryName ->
navigator.navigate(RecipeListScreenDestination(categoryName))
if (categories.isEmpty()) {
AbstractErrorScreen(uiText = UiText.StringResource(R.string.error_no_categories_found))
} else {
CategoryListScreen(
data = categories,
modifier = Modifier.padding(innerPadding),
) { categoryName ->
navigator.navigate(
RecipeListScreenDestination(
categoryName = categoryName,
keyword = null,
),
)
}
}
}

Expand All @@ -72,47 +81,43 @@ private fun CategoryListScreen(
modifier: Modifier,
onClick: (String) -> Unit,
) {
if (data.isEmpty()) {
AbstractErrorScreen(uiText = UiText.StringResource(R.string.error_no_categories_found))
} else {
val listState = rememberLazyListState()
LazyColumn(
modifier = modifier.fillMaxSize(),
state = listState,
) {
itemsIndexed(data) { index, category ->
ListItem(
modifier = Modifier.clickable(
onClick = {
onClick.invoke(category.name)
},
),
trailing = {
Badge(backgroundColor = MaterialTheme.colors.primary) {
Text(text = category.recipeCount.toString())
}
},
text = {
val categoryName = if (category.name == "*") {
stringResource(R.string.recipe_uncategorised)
} else {
category.name
}
Text(text = categoryName)
val listState = rememberLazyListState()
LazyColumn(
modifier = modifier.fillMaxSize(),
state = listState,
) {
itemsIndexed(data) { index, category ->
ListItem(
modifier = Modifier.clickable(
onClick = {
onClick.invoke(category.name)
},
),
trailing = {
Badge(backgroundColor = MaterialTheme.colors.primary) {
Text(text = category.recipeCount.toString())
}
},
text = {
val categoryName = if (category.name == "*") {
stringResource(R.string.recipe_uncategorised)
} else {
category.name
}
Text(text = categoryName)
},
)
if (index != data.size - 1) {
Divider(
modifier = Modifier.padding(horizontal = dimensionResource(id = R.dimen.padding_m)),
)
if (index != data.size - 1) {
Divider(
modifier = Modifier.padding(horizontal = dimensionResource(id = R.dimen.padding_m)),
)
}
}
}
}
}

@Composable
fun CategoryListTopBar() {
private fun TopAppBar() {
TopAppBar(
title = { Text(text = stringResource(R.string.common_categories)) },
backgroundColor = NcBlue700,
Expand All @@ -122,7 +127,7 @@ fun CategoryListTopBar() {

@Preview
@Composable
private fun CategoryListScreen() {
private fun CategoryListScreenPreview() {
val categories = MutableList(10) {
Category(name = "Category $it", nextInt(0, 20))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sealed interface RecipeCreateEditState {
val cookTime: DurationComponents,
val totalTime: DurationComponents,
val categories: List<Category> = emptyList(),
val keywords: Set<String> = emptySet(),
) : RecipeCreateEditState
data class Updated(val recipeId: Int) : RecipeCreateEditState
data class Error(val error: UiText) : RecipeCreateEditState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import de.lukasneugebauer.nextcloudcookbook.recipe.domain.model.RecipePreview

sealed interface RecipeListScreenState {
object Initial : RecipeListScreenState
data class Loaded(val data: List<RecipePreview>) : RecipeListScreenState
data class Loaded(
val recipePreviews: List<RecipePreview>,
val keywords: Set<String>,
) : RecipeListScreenState

data class Error(val uiText: UiText) : RecipeListScreenState
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.lukasneugebauer.nextcloudcookbook.recipe.domain.usecase

import com.dropbox.android.external.store4.StoreResponse
import de.lukasneugebauer.nextcloudcookbook.recipe.domain.repository.RecipeRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.mapNotNull
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class GetAllKeywordsUseCase @Inject constructor(private val recipeRepository: RecipeRepository) {

operator fun invoke(filterByCategory: String? = null): Flow<Set<String>> {
val recipePreviewsFlow = if (filterByCategory.isNullOrBlank()) {
recipeRepository.getRecipePreviews()
} else {
recipeRepository.getRecipePreviewsByCategory(filterByCategory)
}

return recipePreviewsFlow.mapNotNull { recipePreviewsResponse ->
when (recipePreviewsResponse) {
is StoreResponse.Data -> {
recipePreviewsResponse.value
.flatMap { it.toRecipePreview().keywords }
.toSet()
}

else -> null
}
}
}
}
Loading

0 comments on commit 5cfb420

Please sign in to comment.