mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-09 14:18:39 +01:00
feat(explore): possibility to sort community list
This commit is contained in:
parent
b27045f43c
commit
a69c6b4029
@ -115,6 +115,7 @@ class PostListViewModel(
|
||||
private fun loadNextPage() {
|
||||
val currentState = mvi.uiState.value
|
||||
if (!currentState.canFetchMore || currentState.loading) {
|
||||
mvi.updateState { it.copy(refreshing = false) }
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -32,9 +32,7 @@ internal fun PostsTopBar(
|
||||
onSelectSortType: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.height(50.dp).padding(
|
||||
horizontal = Spacing.s,
|
||||
),
|
||||
modifier = Modifier.height(50.dp).padding(horizontal = Spacing.s),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Row(
|
||||
|
@ -45,6 +45,7 @@ class ProfileCommentsViewModel(
|
||||
private fun loadNextPage() {
|
||||
val currentState = mvi.uiState.value
|
||||
if (!currentState.canFetchMore || currentState.loading) {
|
||||
mvi.updateState { it.copy(refreshing = false) }
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ class ProfilePostsViewModel(
|
||||
private fun loadNextPage() {
|
||||
val currentState = mvi.uiState.value
|
||||
if (!currentState.canFetchMore || currentState.loading) {
|
||||
mvi.updateState { it.copy(refreshing = false) }
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ interface CommunityListMviModel :
|
||||
object LoadNextPage : Intent
|
||||
data class SetSearch(val value: String) : Intent
|
||||
data class SetListingType(val value: ListingType) : Intent
|
||||
data class SetSortType(val value: SortType) : Intent
|
||||
}
|
||||
|
||||
data class UiState(
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.feature.search.communitylist
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
@ -35,7 +33,6 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.Density
|
||||
@ -52,8 +49,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycl
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.communitydetail.CommunityDetailScreen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.CommunityItem
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.modals.ListingTypeBottomSheet
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toIcon
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toReadableName
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.modals.SortBottomSheet
|
||||
import com.github.diegoberaldin.raccoonforlemmy.feature.search.di.getSearchScreenModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
@ -71,48 +67,35 @@ class CommunityListScreen : Screen {
|
||||
Scaffold(
|
||||
modifier = Modifier.padding(Spacing.xxs),
|
||||
topBar = {
|
||||
Row(
|
||||
modifier = Modifier.height(50.dp).padding(
|
||||
horizontal = Spacing.s,
|
||||
),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.onClick {
|
||||
bottomNavigator.show(
|
||||
ListingTypeBottomSheet(
|
||||
isLogged = uiState.isLogged,
|
||||
onHide = {
|
||||
bottomNavigator.hide()
|
||||
},
|
||||
onSelected = {
|
||||
model.reduce(CommunityListMviModel.Intent.SetListingType(it))
|
||||
},
|
||||
),
|
||||
)
|
||||
},
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(Spacing.m),
|
||||
) {
|
||||
Image(
|
||||
imageVector = uiState.listingType.toIcon(),
|
||||
contentDescription = null,
|
||||
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onBackground),
|
||||
CommunityTopBar(
|
||||
listingType = uiState.listingType,
|
||||
sortType = uiState.sortType,
|
||||
onSelectListingType = {
|
||||
bottomNavigator.show(
|
||||
ListingTypeBottomSheet(
|
||||
isLogged = uiState.isLogged,
|
||||
onHide = {
|
||||
bottomNavigator.hide()
|
||||
},
|
||||
onSelected = {
|
||||
model.reduce(CommunityListMviModel.Intent.SetListingType(it))
|
||||
},
|
||||
),
|
||||
)
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(Spacing.xxs),
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(MR.strings.instance_detail_communities),
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
)
|
||||
Text(
|
||||
text = uiState.listingType.toReadableName(),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onSelectSortType = {
|
||||
bottomNavigator.show(
|
||||
SortBottomSheet(
|
||||
onHide = {
|
||||
bottomNavigator.hide()
|
||||
},
|
||||
onSelected = {
|
||||
model.reduce(CommunityListMviModel.Intent.SetSortType(it))
|
||||
},
|
||||
),
|
||||
)
|
||||
},
|
||||
)
|
||||
},
|
||||
) { padding ->
|
||||
Column(
|
||||
|
@ -8,6 +8,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.preferences.TemporaryKeySto
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.ApiConfigurationRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.identity.repository.IdentityRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.ListingType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.SortType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.CommunityRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.PostsRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -69,6 +70,7 @@ class CommunityListViewModel(
|
||||
|
||||
is CommunityListMviModel.Intent.SetSearch -> setSearch(intent.value)
|
||||
is CommunityListMviModel.Intent.SetListingType -> changeListingType(intent.value)
|
||||
is CommunityListMviModel.Intent.SetSortType -> changeSortType(intent.value)
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,6 +90,13 @@ class CommunityListViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeSortType(value: SortType) {
|
||||
mvi.updateState { it.copy(sortType = value) }
|
||||
mvi.scope.launch(Dispatchers.IO) {
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun refresh() {
|
||||
currentPage = 1
|
||||
mvi.updateState { it.copy(canFetchMore = true, refreshing = true) }
|
||||
@ -97,6 +106,7 @@ class CommunityListViewModel(
|
||||
private suspend fun loadNextPage() {
|
||||
val currentState = mvi.uiState.value
|
||||
if (!currentState.canFetchMore || currentState.loading) {
|
||||
mvi.updateState { it.copy(refreshing = false) }
|
||||
return
|
||||
}
|
||||
mvi.updateState { it.copy(loading = true) }
|
||||
|
@ -0,0 +1,74 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.feature.search.communitylist
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.github.diegoberaldin.racconforlemmy.core.utils.onClick
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.ListingType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.SortType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toIcon
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toReadableName
|
||||
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
|
||||
@Composable
|
||||
internal fun CommunityTopBar(
|
||||
listingType: ListingType,
|
||||
sortType: SortType,
|
||||
onSelectListingType: () -> Unit,
|
||||
onSelectSortType: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.height(50.dp).padding(horizontal = Spacing.s),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.onClick {
|
||||
onSelectListingType()
|
||||
},
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(Spacing.m),
|
||||
) {
|
||||
Image(
|
||||
imageVector = listingType.toIcon(),
|
||||
contentDescription = null,
|
||||
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onBackground),
|
||||
)
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(Spacing.xxs),
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(MR.strings.instance_detail_communities),
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
)
|
||||
Text(
|
||||
text = listingType.toReadableName(),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Image(
|
||||
modifier = Modifier.onClick {
|
||||
onSelectSortType()
|
||||
},
|
||||
imageVector = sortType.toIcon(),
|
||||
contentDescription = null,
|
||||
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onBackground),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user