Filters working.

This commit is contained in:
aminecmi 2022-12-05 22:29:06 +01:00
parent 86c50d4881
commit 748ed41096
4 changed files with 75 additions and 25 deletions

View File

@ -662,7 +662,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
})
}
private fun fetchOnEmptyList() {
fun fetchOnEmptyList() {
binding.recyclerView.doOnNextLayout {
// TODO: do if last element (or is empty ?)
getElementsAccordingToTab(true)
@ -703,7 +703,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
binding.emptyText.visibility = View.GONE
}
private fun getElementsAccordingToTab(
fun getElementsAccordingToTab(
appendResults: Boolean = false
) {
offset = if (appendResults && items.size > 0) {

View File

@ -10,6 +10,7 @@ import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewGroup
import bou.amine.apps.readerforselfossv2.android.HomeActivity
import bou.amine.apps.readerforselfossv2.android.R
import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName
import bou.amine.apps.readerforselfossv2.repository.Repository
@ -78,6 +79,7 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
c.setOnCloseIconClickListener {
(it as Chip).isCloseIconVisible = false
tagChip = null
repository.setTagFilter(null)
}
c.setOnClickListener {
@ -86,7 +88,14 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
}
(it as Chip).isCloseIconVisible = true
tagChip = it
repository.setTagFilter(tag)
}
if (repository.tagFilter.value?.equals(tag) == true) {
c.isCloseIconVisible = true
tagChip = c
}
tagGroup.addView(c)
}
@ -122,6 +131,7 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
c.setOnCloseIconClickListener {
(it as Chip).isCloseIconVisible = false
sourceChip = null
repository.setSourceFilter(null)
}
c.setOnClickListener {
@ -130,7 +140,15 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
}
(it as Chip).isCloseIconVisible = true
sourceChip = it
repository.setSourceFilter(source)
}
if (repository.sourceFilter.value?.equals(source) == true) {
c.isCloseIconVisible = true
sourceChip = c
}
sourceGroup.addView(c)
}
@ -138,6 +156,11 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
binding.filterView.visibility = VISIBLE
}
binding.floatingActionButton2.setOnClickListener {
(activity as HomeActivity).getElementsAccordingToTab()
(activity as HomeActivity).fetchOnEmptyList()
dismiss()
}
return binding.root
}

View File

@ -2,6 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -13,13 +14,29 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
tools:visibility="gone" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/filterView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
android:visibility="gone"
tools:visibility="visible">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:clickable="true"
app:backgroundTint="@color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:rippleColor="@color/colorAccentDark"
app:srcCompat="@drawable/ic_menu_search_white_24dp" />
<TextView
android:id="@+id/filterTagsTitle"
@ -32,19 +49,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.chip.ChipGroup
app:singleSelection="true"
android:id="@+id/tagsGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/filterTagsTitle">
</com.google.android.material.chip.ChipGroup>
<TextView
android:id="@+id/filterSourcesTitle"
style="@style/MaterialAlertDialog.MaterialComponents.Title.Text"
@ -57,6 +61,19 @@
app:layout_constraintTop_toBottomOf="@+id/tagsGroup" />
<com.google.android.material.chip.ChipGroup
android:id="@+id/tagsGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/filterTagsTitle"
app:singleSelection="true">
</com.google.android.material.chip.ChipGroup>
<com.google.android.material.chip.ChipGroup
android:id="@+id/sourcesGroup"
android:layout_width="match_parent"

View File

@ -23,8 +23,10 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
var displayedItems = ItemType.UNREAD
var tagFilter: SelfossModel.Tag? = null
var sourceFilter: SelfossModel.Source? = null
private var _tagFilter = MutableStateFlow<SelfossModel.Tag?>(null)
var tagFilter = _tagFilter.asStateFlow()
private var _sourceFilter = MutableStateFlow<SelfossModel.Source?>(null)
var sourceFilter = _sourceFilter.asStateFlow()
var searchFilter: String? = null
var offlineOverride = false
@ -47,8 +49,8 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
fetchedItems = api.getItems(
displayedItems.type,
offset = 0,
tagFilter?.tag,
sourceFilter?.id?.toLong(),
tagFilter.value?.tag,
sourceFilter.value?.id?.toLong(),
searchFilter,
null
)
@ -61,10 +63,10 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
(it.starred && displayedItems == ItemType.STARRED)
}
if (tagFilter != null) {
dbItems = dbItems.filter { it.tags.split(',').contains(tagFilter!!.tag) }
dbItems = dbItems.filter { it.tags.split(',').contains(tagFilter.value?.tag) }
}
if (sourceFilter != null) {
dbItems = dbItems.filter { it.sourcetitle == sourceFilter!!.title }
dbItems = dbItems.filter { it.sourcetitle == sourceFilter.value?.title }
}
fetchedItems = StatusAndData.succes(
dbItems.map { it.toView() }
@ -88,8 +90,8 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
fetchedItems = api.getItems(
displayedItems.type,
offset,
tagFilter?.tag,
sourceFilter?.id?.toLong(),
tagFilter.value?.tag,
sourceFilter.value?.id?.toLong(),
searchFilter,
null
)
@ -505,4 +507,12 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
deleteDBAction(action)
}
}
fun setTagFilter(tag: SelfossModel.Tag?) {
_tagFilter.value = tag
}
fun setSourceFilter(source: SelfossModel.Source?) {
_sourceFilter.value = source
}
}