Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
circles-android
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Circles
circles-android
Commits
a44063e0
Commit
a44063e0
authored
1 year ago
by
Taras
Browse files
Options
Downloads
Patches
Plain Diff
Apply filter to timeline events
parent
353becb9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/src/main/java/org/futo/circles/core/feature/timeline/BaseTimelineViewModel.kt
+45
-2
45 additions, 2 deletions
...to/circles/core/feature/timeline/BaseTimelineViewModel.kt
with
45 additions
and
2 deletions
core/src/main/java/org/futo/circles/core/feature/timeline/BaseTimelineViewModel.kt
+
45
−
2
View file @
a44063e0
package
org.futo.circles.core.feature.timeline
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.SavedStateHandle
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.asFlow
import
androidx.lifecycle.asLiveData
import
androidx.lifecycle.map
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.flow.Flow
import
kotlinx.coroutines.flow.MutableStateFlow
import
kotlinx.coroutines.flow.combine
import
kotlinx.coroutines.flow.flowOn
import
org.futo.circles.core.extensions.getOrThrow
import
org.futo.circles.core.feature.circles.filter.CircleFilterAccountDataManager
import
org.futo.circles.core.feature.timeline.data_source.BaseTimelineDataSource
import
org.futo.circles.core.mapping.nameOrId
abstract
class
BaseTimelineViewModel
(
private
val
baseTimelineDataSource
:
BaseTimelineDataSource
savedStateHandle
:
SavedStateHandle
,
private
val
baseTimelineDataSource
:
BaseTimelineDataSource
,
private
val
filterAccountDataManager
:
CircleFilterAccountDataManager
)
:
ViewModel
()
{
protected
val
roomId
:
String
=
savedStateHandle
.
getOrThrow
(
"roomId"
)
protected
val
timelineId
:
String
?
=
savedStateHandle
[
"timelineId"
]
val
titleLiveData
=
baseTimelineDataSource
.
room
.
getRoomSummaryLive
().
map
{
it
.
getOrNull
()
?.
nameOrId
()
?:
""
}
val
timelineEventsLiveData
=
baseTimelineDataSource
.
getTimelineEventFlow
().
asLiveData
()
val
isFilterActiveLiveData
=
MutableLiveData
(
false
)
val
timelineEventsLiveData
=
combine
(
baseTimelineDataSource
.
getTimelineEventFlow
(),
getFilterFlow
()
)
{
events
,
selectedRoomIds
->
val
isActive
=
isFilterActive
(
selectedRoomIds
)
isFilterActiveLiveData
.
postValue
(
isActive
)
if
(
isActive
)
events
.
filter
{
selectedRoomIds
.
contains
(
it
.
postInfo
.
roomId
)
}
else
events
}.
flowOn
(
Dispatchers
.
IO
).
asLiveData
()
private
fun
getFilterFlow
():
Flow
<
Set
<
String
>>
{
timelineId
?:
return
MutableStateFlow
(
emptySet
())
return
filterAccountDataManager
.
getCircleFilterLive
(
roomId
)
?.
map
{
optionalEvent
->
filterAccountDataManager
.
getEventContentAsSet
(
optionalEvent
.
getOrNull
()
?.
content
,
roomId
)
}
?.
asFlow
()
?:
MutableStateFlow
(
emptySet
())
}
private
fun
isFilterActive
(
selectedRoomIds
:
Set
<
String
>):
Boolean
{
timelineId
?:
return
false
if
(
selectedRoomIds
.
isEmpty
())
return
false
return
selectedRoomIds
.
size
!=
filterAccountDataManager
.
getAllTimelinesIds
(
roomId
).
size
}
override
fun
onCleared
()
{
baseTimelineDataSource
.
clearTimeline
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment