Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Commit

Permalink
Merge pull request #105 from AnyGogin31/feature/quick-search-by-tag
Browse files Browse the repository at this point in the history
feat(details, search): add navigation between details and search sect…
  • Loading branch information
AnyGogin31 authored Dec 29, 2024
2 parents 48ed8d8 + 6868878 commit d5b2e5d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions features/details/details-presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ kotlin {
implementation(projects.core.state)

implementation(projects.features.details.detailsNavigation)
implementation(projects.features.search.searchNavigation)

implementation(projects.resources)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ internal fun IllustrationDetailsView(
illustration = it,
onIllustrationDownload = viewModel::downloadIllustration,
onProfileClick = viewModel::onProfileClick,
onTagClick = viewModel::onTagClick,
)
},
)
Expand All @@ -103,6 +104,7 @@ private fun IllustrationDetailsContent(
illustration: IllustrationDetails,
onIllustrationDownload: (url: String?) -> Unit,
onProfileClick: (userId: Int) -> Unit = {},
onTagClick: (text: String) -> Unit = {},
) {
val isSinglePageEmpty = illustration.metaSinglePage.isEmpty()
val imageUrls = if (isSinglePageEmpty) illustration.metaPages else listOf(illustration.metaSinglePage)
Expand Down Expand Up @@ -187,17 +189,23 @@ private fun IllustrationDetailsContent(
modifier = Modifier.padding(horizontal = 16.dp),
) {
items(illustration.tags) { tag ->
TagChip(tag.name)
TagChip(tag.name, onTagClick)
}
}
}
}
}

@Composable
private fun TagChip(text: String) {
private fun TagChip(
text: String,
onClick: (text: String) -> Unit = {},
) {
Box(
modifier = Modifier
.clickable {
onClick(text)
}
.background(
color = MaterialTheme.colorScheme.secondary.copy(alpha = 0.2f),
shape = RoundedCornerShape(16.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import neilt.mobile.pixiv.core.state.ViewState
import neilt.mobile.pixiv.domain.repositories.details.illustration.IllustrationRepository
import neilt.mobile.pixiv.features.details.PixivDetailsSection
import neilt.mobile.pixiv.features.details.provider.ToastProvider
import neilt.mobile.pixiv.features.search.PixivSearchSection
import neilt.mobile.pixiv.resources.Res
import neilt.mobile.pixiv.resources.toast_download_complete
import neilt.mobile.pixiv.resources.toast_downloading
Expand Down Expand Up @@ -87,4 +88,10 @@ internal class IllustrationDetailsViewModel(
navigator.navigateTo(PixivDetailsSection.UserDetailScreen(userId))
}
}

fun onTagClick(text: String) {
viewModelScope.launch {
navigator.navigateTo(PixivSearchSection.ResultScreen(0, text))
}
}
}
1 change: 1 addition & 0 deletions features/search/search-presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ kotlin {
implementation(projects.core.navigation.navigationApi)
implementation(projects.core.state)

implementation(projects.features.details.detailsNavigation)
implementation(projects.features.search.searchNavigation)

implementation(projects.resources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal fun ResultView(

IllustrationsGallery(
initialItems = initialItems,
onIllustrationSelected = {},
onIllustrationSelected = viewModel::navigateToDetailsScreen,
loadMoreItems = {
viewModel.loadIllustrations(it, exploreType, keyword)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@
package neilt.mobile.pixiv.features.search.presentation.result

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import neilt.mobile.core.navigation.Navigator
import neilt.mobile.pixiv.domain.models.home.Illustration
import neilt.mobile.pixiv.domain.models.requests.SearchIllustrationsRequest
import neilt.mobile.pixiv.domain.repositories.search.SearchRepository
import neilt.mobile.pixiv.features.details.PixivDetailsSection

internal class ResultViewModel(
private val searchRepository: SearchRepository,
private val navigator: Navigator,
) : ViewModel() {
suspend fun loadIllustrations(
offset: Int = 0,
Expand All @@ -60,4 +65,10 @@ internal class ResultViewModel(
}
}
}

fun navigateToDetailsScreen(illustrationId: Int) {
viewModelScope.launch {
navigator.navigateTo(PixivDetailsSection.IllustrationDetailsScreen(illustrationId))
}
}
}

0 comments on commit d5b2e5d

Please sign in to comment.