mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-08 16:28:45 +01:00
fix: add event filters based on screen (#596)
This commit is contained in:
parent
cf299afdcb
commit
68bf38f423
@ -34,6 +34,7 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toReadableName
|
||||
|
||||
class ListingTypeBottomSheet(
|
||||
private val isLogged: Boolean = false,
|
||||
private val screenKey: String? = null,
|
||||
) : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
@ -88,6 +89,7 @@ class ListingTypeBottomSheet(
|
||||
notificationCenter.send(
|
||||
NotificationCenterEvent.ChangeFeedType(
|
||||
value = value,
|
||||
screenKey = screenKey,
|
||||
)
|
||||
)
|
||||
navigationCoordinator.hideBottomSheet()
|
||||
|
@ -46,6 +46,7 @@ class SortBottomSheet(
|
||||
private val comments: Boolean = false,
|
||||
private val defaultForCommunity: Boolean = false,
|
||||
private val expandTop: Boolean = false,
|
||||
private val screenKey: String? = null,
|
||||
) : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
@ -69,6 +70,7 @@ class SortBottomSheet(
|
||||
expandTop = expandTop,
|
||||
comments = comments,
|
||||
defaultForCommunity = defaultForCommunity,
|
||||
screenKey = screenKey,
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -80,6 +82,7 @@ internal class SortBottomSheetMain(
|
||||
private val values: List<Int>,
|
||||
private val expandTop: Boolean = false,
|
||||
private val defaultForCommunity: Boolean = false,
|
||||
private val screenKey: String?,
|
||||
) : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
@ -119,17 +122,20 @@ internal class SortBottomSheetMain(
|
||||
SortBottomSheetTop(
|
||||
comments = comments,
|
||||
defaultForCommunity = defaultForCommunity,
|
||||
screenKey = screenKey,
|
||||
)
|
||||
)
|
||||
} else {
|
||||
val event = if (comments) {
|
||||
NotificationCenterEvent.ChangeCommentSortType(
|
||||
value = sortValue,
|
||||
screenKey = screenKey,
|
||||
)
|
||||
} else {
|
||||
NotificationCenterEvent.ChangeSortType(
|
||||
value = sortValue,
|
||||
defaultForCommunity = defaultForCommunity,
|
||||
screenKey = screenKey,
|
||||
)
|
||||
}
|
||||
notificationCenter.send(event)
|
||||
@ -177,6 +183,7 @@ internal class SortBottomSheetTop(
|
||||
SortType.Top.Year,
|
||||
).map { it.toInt() },
|
||||
private val defaultForCommunity: Boolean = false,
|
||||
private val screenKey: String?,
|
||||
) : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
@ -228,11 +235,13 @@ internal class SortBottomSheetTop(
|
||||
val event = if (comments) {
|
||||
NotificationCenterEvent.ChangeCommentSortType(
|
||||
value = sortValue,
|
||||
screenKey = screenKey,
|
||||
)
|
||||
} else {
|
||||
NotificationCenterEvent.ChangeSortType(
|
||||
value = sortValue,
|
||||
defaultForCommunity = defaultForCommunity,
|
||||
screenKey = screenKey,
|
||||
)
|
||||
}
|
||||
notificationCenter.send(event)
|
||||
|
@ -21,13 +21,13 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
|
||||
import kotlin.time.Duration
|
||||
|
||||
sealed interface NotificationCenterEvent {
|
||||
data class ChangeSortType(val value: SortType, val defaultForCommunity: Boolean) :
|
||||
data class ChangeSortType(val value: SortType, val defaultForCommunity: Boolean, val screenKey: String?) :
|
||||
NotificationCenterEvent
|
||||
|
||||
data class ChangeCommentSortType(val value: SortType) :
|
||||
data class ChangeCommentSortType(val value: SortType, val screenKey: String?) :
|
||||
NotificationCenterEvent
|
||||
|
||||
data class ChangeFeedType(val value: ListingType) :
|
||||
data class ChangeFeedType(val value: ListingType, val screenKey: String?) :
|
||||
NotificationCenterEvent
|
||||
|
||||
data class ChangeInboxType(val unreadOnly: Boolean) : NotificationCenterEvent
|
||||
|
@ -168,6 +168,7 @@ class ExploreScreen : Screen {
|
||||
focusManager.clearFocus()
|
||||
val sheet = ListingTypeBottomSheet(
|
||||
isLogged = uiState.isLogged,
|
||||
screenKey = "explore",
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
@ -176,6 +177,7 @@ class ExploreScreen : Screen {
|
||||
val sheet = SortBottomSheet(
|
||||
values = uiState.availableSortTypes.map { it.toInt() },
|
||||
expandTop = true,
|
||||
screenKey = "explore",
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
|
@ -99,12 +99,16 @@ class ExploreViewModel(
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeFeedType::class)
|
||||
.onEach { evt ->
|
||||
changeListingType(evt.value)
|
||||
if (evt.screenKey == "explore") {
|
||||
changeListingType(evt.value)
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeSortType::class)
|
||||
.onEach { evt ->
|
||||
changeSortType(evt.value)
|
||||
if (evt.screenKey == "explore") {
|
||||
changeSortType(evt.value)
|
||||
}
|
||||
}.launchIn(this)
|
||||
}
|
||||
|
||||
|
@ -172,10 +172,13 @@ class AdvancedSettingsScreen : Screen {
|
||||
)
|
||||
// default explore type
|
||||
SettingsRow(
|
||||
title = LocalXmlStrings.current.settingsDefaultExploreType,
|
||||
title = LocalXmlStrings.current.settingsDefaultExploreType,
|
||||
value = uiState.defaultExploreType.toReadableName(),
|
||||
onTap = rememberCallback {
|
||||
val sheet = ListingTypeBottomSheet(isLogged = uiState.isLogged)
|
||||
val sheet = ListingTypeBottomSheet(
|
||||
isLogged = uiState.isLogged,
|
||||
screenKey = "advancedSettings",
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
)
|
||||
|
@ -53,7 +53,9 @@ class AdvancedSettingsViewModel(
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeFeedType::class)
|
||||
.onEach { evt ->
|
||||
changeExploreType(evt.value)
|
||||
if (evt.screenKey == "advancedSettings") {
|
||||
changeExploreType(evt.value)
|
||||
}
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeZombieScrollAmount::class)
|
||||
.onEach { evt ->
|
||||
|
@ -205,6 +205,7 @@ class SettingsScreen : Screen {
|
||||
onTap = rememberCallback {
|
||||
val sheet = ListingTypeBottomSheet(
|
||||
isLogged = uiState.isLogged,
|
||||
screenKey = "settings",
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
@ -218,6 +219,7 @@ class SettingsScreen : Screen {
|
||||
val sheet = SortBottomSheet(
|
||||
values = uiState.availableSortTypesForPosts.map { it.toInt() },
|
||||
expandTop = true,
|
||||
screenKey = "settings",
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
@ -231,6 +233,7 @@ class SettingsScreen : Screen {
|
||||
val sheet = SortBottomSheet(
|
||||
comments = true,
|
||||
values = uiState.availableSortTypesForComments.map { it.toInt() },
|
||||
screenKey = "settings",
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
|
@ -67,15 +67,21 @@ class SettingsViewModel(
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeFeedType::class)
|
||||
.onEach { evt ->
|
||||
changeDefaultListingType(evt.value)
|
||||
if (evt.screenKey == "settings") {
|
||||
changeDefaultListingType(evt.value)
|
||||
}
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeSortType::class)
|
||||
.onEach { evt ->
|
||||
changeDefaultPostSortType(evt.value)
|
||||
if (evt.screenKey == "settings") {
|
||||
changeDefaultPostSortType(evt.value)
|
||||
}
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeCommentSortType::class)
|
||||
.onEach { evt ->
|
||||
changeDefaultCommentSortType(evt.value)
|
||||
if (evt.screenKey == "settings") {
|
||||
changeDefaultCommentSortType(evt.value)
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
val availableSortTypesForPosts = getSortTypesUseCase.getTypesForPosts()
|
||||
|
@ -134,7 +134,7 @@ internal object MainScreen : Screen {
|
||||
when (evt) {
|
||||
is DrawerEvent.ChangeListingType -> {
|
||||
if (tabNavigator.current == HomeTab) {
|
||||
notificationCenter.send(NotificationCenterEvent.ChangeFeedType(evt.value))
|
||||
notificationCenter.send(NotificationCenterEvent.ChangeFeedType(evt.value, "postList"))
|
||||
} else {
|
||||
with(navigationCoordinator) {
|
||||
changeTab(HomeTab)
|
||||
@ -144,7 +144,7 @@ internal object MainScreen : Screen {
|
||||
// wait for transition to finish
|
||||
delay(750)
|
||||
notificationCenter.send(
|
||||
NotificationCenterEvent.ChangeFeedType(evt.value)
|
||||
NotificationCenterEvent.ChangeFeedType(evt.value, "postList")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -304,6 +304,7 @@ class AccountSettingsScreen : Screen {
|
||||
onTap = rememberCallback {
|
||||
val sheet = ListingTypeBottomSheet(
|
||||
isLogged = true,
|
||||
screenKey = "accountSettings",
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
@ -317,6 +318,7 @@ class AccountSettingsScreen : Screen {
|
||||
val sheet = SortBottomSheet(
|
||||
values = uiState.availableSortTypes.map { it.toInt() },
|
||||
expandTop = true,
|
||||
screenKey = "accountSettings",
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
|
@ -35,11 +35,15 @@ class AccountSettingsViewModel(
|
||||
screenModelScope.launch {
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeSortType::class)
|
||||
.onEach { evt ->
|
||||
updateState { it.copy(defaultSortType = evt.value) }
|
||||
if (evt.screenKey == "accountSettings") {
|
||||
updateState { it.copy(defaultSortType = evt.value) }
|
||||
}
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeFeedType::class)
|
||||
.onEach { evt ->
|
||||
updateState { it.copy(defaultListingType = evt.value) }
|
||||
if (evt.screenKey == "accountSettings") {
|
||||
updateState { it.copy(defaultListingType = evt.value) }
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
if (accountSettings == null) {
|
||||
|
@ -289,6 +289,7 @@ class CommunityDetailScreen(
|
||||
val sheet = SortBottomSheet(
|
||||
values = uiState.availableSortTypes.map { it.toInt() },
|
||||
expandTop = true,
|
||||
screenKey = uiState.community.readableHandle,
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
@ -461,6 +462,7 @@ class CommunityDetailScreen(
|
||||
values = uiState.availableSortTypes.map { it.toInt() },
|
||||
defaultForCommunity = true,
|
||||
expandTop = true,
|
||||
screenKey = uiState.community.readableHandle,
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(screen)
|
||||
}
|
||||
|
@ -151,11 +151,13 @@ class CommunityDetailViewModel(
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeSortType::class)
|
||||
.onEach { evt ->
|
||||
if (evt.defaultForCommunity) {
|
||||
val handle = uiState.value.community.readableHandle
|
||||
communitySortRepository.saveSort(handle, evt.value.toInt())
|
||||
if (evt.screenKey == uiState.value.community.readableHandle) {
|
||||
if (evt.defaultForCommunity) {
|
||||
val handle = uiState.value.community.readableHandle
|
||||
communitySortRepository.saveSort(handle, evt.value.toInt())
|
||||
}
|
||||
applySortType(evt.value)
|
||||
}
|
||||
applySortType(evt.value)
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.Share::class).onEach { evt ->
|
||||
shareHelper.share(evt.url)
|
||||
|
@ -134,6 +134,7 @@ class InstanceInfoScreen(
|
||||
val sheet = SortBottomSheet(
|
||||
values = uiState.availableSortTypes.map { it.toInt() },
|
||||
expandTop = true,
|
||||
screenKey = "instanceInfo",
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
|
@ -42,7 +42,9 @@ class InstanceInfoViewModel(
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeSortType::class)
|
||||
.onEach { evt ->
|
||||
changeSortType(evt.value)
|
||||
if (evt.screenKey == "instanceInfo") {
|
||||
changeSortType(evt.value)
|
||||
}
|
||||
}.launchIn(this)
|
||||
|
||||
val metadata = siteRepository.getMetadata(url)
|
||||
|
@ -185,6 +185,7 @@ class MultiCommunityScreen(
|
||||
val sheet = SortBottomSheet(
|
||||
values = uiState.availableSortTypes.map { it.toInt() },
|
||||
expandTop = true,
|
||||
screenKey = "multiCommunity",
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
|
@ -79,7 +79,9 @@ class MultiCommunityViewModel(
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeSortType::class)
|
||||
.onEach { evt ->
|
||||
applySortType(evt.value)
|
||||
if (evt.screenKey == "multiCommunity") {
|
||||
applySortType(evt.value)
|
||||
}
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.Share::class).onEach { evt ->
|
||||
shareHelper.share(evt.url)
|
||||
|
@ -195,6 +195,7 @@ class PostListScreen : Screen {
|
||||
onSelectListingType = rememberCallback {
|
||||
val sheet = ListingTypeBottomSheet(
|
||||
isLogged = uiState.isLogged,
|
||||
screenKey = "postList"
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
@ -207,6 +208,7 @@ class PostListScreen : Screen {
|
||||
val sheet = SortBottomSheet(
|
||||
values = uiState.availableSortTypes.map { it.toInt() },
|
||||
expandTop = true,
|
||||
screenKey = "postList",
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
|
@ -103,11 +103,15 @@ class PostListViewModel(
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeFeedType::class)
|
||||
.onEach { evt ->
|
||||
applyListingType(evt.value)
|
||||
if (evt.screenKey == "postList") {
|
||||
applyListingType(evt.value)
|
||||
}
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeSortType::class)
|
||||
.onEach { evt ->
|
||||
applySortType(evt.value)
|
||||
if (evt.screenKey == "postList") {
|
||||
applySortType(evt.value)
|
||||
}
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.Logout::class).onEach {
|
||||
handleLogout()
|
||||
|
@ -112,6 +112,7 @@ class SavedItemsScreen : Screen {
|
||||
onClick = rememberCallback {
|
||||
val sheet = SortBottomSheet(
|
||||
values = uiState.availableSortTypes.map { it.toInt() },
|
||||
screenKey = "savedItems",
|
||||
)
|
||||
navigatorCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
|
@ -69,7 +69,9 @@ class SavedItemsViewModel(
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeSortType::class)
|
||||
.onEach { evt ->
|
||||
applySortType(evt.value)
|
||||
if (evt.screenKey == "savedItems") {
|
||||
applySortType(evt.value)
|
||||
}
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.Share::class).onEach { evt ->
|
||||
shareHelper.share(evt.url)
|
||||
|
@ -222,6 +222,7 @@ class UserDetailScreen(
|
||||
val sheet = SortBottomSheet(
|
||||
values = uiState.availableSortTypes.map { it.toInt() },
|
||||
expandTop = true,
|
||||
screenKey = uiState.user.readableHandle,
|
||||
)
|
||||
navigationCoordinator.showBottomSheet(sheet)
|
||||
},
|
||||
|
@ -17,6 +17,7 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PostModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.SortType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.imageUrl
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableHandle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toSortType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.CommentRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.repository.GetSortTypesUseCase
|
||||
@ -79,7 +80,9 @@ class UserDetailViewModel(
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.ChangeSortType::class)
|
||||
.onEach { evt ->
|
||||
applySortType(evt.value)
|
||||
if (evt.screenKey == uiState.value.user.readableHandle) {
|
||||
applySortType(evt.value)
|
||||
}
|
||||
}.launchIn(this)
|
||||
notificationCenter.subscribe(NotificationCenterEvent.Share::class).onEach { evt ->
|
||||
shareHelper.share(evt.url)
|
||||
|
Loading…
x
Reference in New Issue
Block a user