Skip to content
Snippets Groups Projects
Commit 437dcee3 authored by Taras's avatar Taras
Browse files

Handle select

parent efb3d857
No related branches found
No related tags found
No related merge requests found
......@@ -29,13 +29,9 @@ class FilterTimelinesDataSource @Inject constructor(
val timelinesLiveData = combine(
circleSummaryLiveData.asFlow(),
selectedTimelinesIds
) { circle, selectedIds ->
val children = circle.getOrNull()?.spaceChildren ?: emptyList()
val myTimelineId = getTimelineRoomFor(circleId)?.roomId
children.mapNotNull {
session.getRoom(it.childRoomId)?.roomSummary()?.takeIf { summary ->
summary.membership.isActive() && summary.roomId != myTimelineId
}?.toFilterTimelinesListItem(isTimelineSelected(selectedIds, it.childRoomId))
) { _, selectedIds ->
getAllTimelinesIds().mapNotNull {
session.getRoom(it)?.roomSummary()?.toFilterTimelinesListItem(selectedIds.contains(it))
}
}.flowOn(Dispatchers.IO).asLiveData()
......@@ -48,7 +44,7 @@ class FilterTimelinesDataSource @Inject constructor(
}
fun toggleItemSelected(roomId: String) {
val isItemSelected = isTimelineSelected(selectedTimelinesIds.value, roomId)
val isItemSelected = selectedTimelinesIds.value.contains(roomId)
selectedTimelinesIds.update { value ->
val newSet = value.toMutableSet()
if (isItemSelected) newSet.remove(roomId)
......@@ -58,18 +54,26 @@ class FilterTimelinesDataSource @Inject constructor(
}
fun selectAllTimelines() {
val ids = timelinesLiveData.value?.map { it.id }?.toSet() ?: emptySet()
selectedTimelinesIds.update { ids }
selectedTimelinesIds.update { getAllTimelinesIds() }
}
private fun isTimelineSelected(selectedIds: Set<String>, roomId: String): Boolean =
if (selectedIds.isEmpty()) true
else selectedIds.contains(roomId)
private fun getCircleFilter(): Set<String> {
val content = session.getRoom(circleId)?.roomAccountDataService()
?.getAccountDataEvent(CIRCLE_FILTER_EVENT_TYPE)?.content ?: return emptySet()
return (content[TIMELINES_KEY] as? List<*>)?.map { it.toString() }?.toSet() ?: emptySet()
?.getAccountDataEvent(CIRCLE_FILTER_EVENT_TYPE)?.content ?: return getAllTimelinesIds()
return (content[TIMELINES_KEY] as? List<*>)?.map { it.toString() }?.toSet()
?: getAllTimelinesIds()
}
private fun getAllTimelinesIds(): Set<String> {
val children = session.getRoom(circleId)?.roomSummary()?.spaceChildren ?: emptyList()
val myTimelineId = getTimelineRoomFor(circleId)?.roomId
return children.mapNotNull {
val timelineSummary =
session.getRoom(it.childRoomId)?.roomSummary()?.takeIf { summary ->
summary.membership.isActive() && summary.roomId != myTimelineId
}
timelineSummary?.roomId
}.toSet()
}
companion object {
......
......@@ -18,7 +18,10 @@ class FilterTimelinesViewHolder(
private val binding = baseBinding as ListItemTimelineFilterBinding
init {
onClick(itemView) { position -> onItemClicked(position) }
onClick(itemView) { position ->
binding.vCheck.isChecked = !binding.vCheck.isChecked
onItemClicked(position)
}
}
fun bind(data: FilterTimelinesListItem) {
......
......@@ -61,8 +61,7 @@
android:id="@+id/rvTimelines"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:paddingHorizontal="8dp" />
android:layout_marginTop="8dp" />
</LinearLayout>
\ No newline at end of file
......@@ -14,11 +14,14 @@
android:id="@+id/ivRoom"
android:layout_width="45dp"
android:layout_height="45dp"
android:padding="2dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.CornerSize50Percent"
app:strokeColor="@color/black"
app:strokeWidth="1dp"
tools:src="@color/blue" />
......@@ -55,6 +58,8 @@
android:id="@+id/vCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment