Filters working.
This commit is contained in:
parent
86c50d4881
commit
748ed41096
@ -662,7 +662,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchOnEmptyList() {
|
fun fetchOnEmptyList() {
|
||||||
binding.recyclerView.doOnNextLayout {
|
binding.recyclerView.doOnNextLayout {
|
||||||
// TODO: do if last element (or is empty ?)
|
// TODO: do if last element (or is empty ?)
|
||||||
getElementsAccordingToTab(true)
|
getElementsAccordingToTab(true)
|
||||||
@ -703,7 +703,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
binding.emptyText.visibility = View.GONE
|
binding.emptyText.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getElementsAccordingToTab(
|
fun getElementsAccordingToTab(
|
||||||
appendResults: Boolean = false
|
appendResults: Boolean = false
|
||||||
) {
|
) {
|
||||||
offset = if (appendResults && items.size > 0) {
|
offset = if (appendResults && items.size > 0) {
|
||||||
|
@ -10,6 +10,7 @@ import android.view.View
|
|||||||
import android.view.View.GONE
|
import android.view.View.GONE
|
||||||
import android.view.View.VISIBLE
|
import android.view.View.VISIBLE
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import bou.amine.apps.readerforselfossv2.android.HomeActivity
|
||||||
import bou.amine.apps.readerforselfossv2.android.R
|
import bou.amine.apps.readerforselfossv2.android.R
|
||||||
import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName
|
import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
@ -78,6 +79,7 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
|||||||
c.setOnCloseIconClickListener {
|
c.setOnCloseIconClickListener {
|
||||||
(it as Chip).isCloseIconVisible = false
|
(it as Chip).isCloseIconVisible = false
|
||||||
tagChip = null
|
tagChip = null
|
||||||
|
repository.setTagFilter(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.setOnClickListener {
|
c.setOnClickListener {
|
||||||
@ -86,7 +88,14 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
|||||||
}
|
}
|
||||||
(it as Chip).isCloseIconVisible = true
|
(it as Chip).isCloseIconVisible = true
|
||||||
tagChip = it
|
tagChip = it
|
||||||
|
repository.setTagFilter(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (repository.tagFilter.value?.equals(tag) == true) {
|
||||||
|
c.isCloseIconVisible = true
|
||||||
|
tagChip = c
|
||||||
|
}
|
||||||
|
|
||||||
tagGroup.addView(c)
|
tagGroup.addView(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,6 +131,7 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
|||||||
c.setOnCloseIconClickListener {
|
c.setOnCloseIconClickListener {
|
||||||
(it as Chip).isCloseIconVisible = false
|
(it as Chip).isCloseIconVisible = false
|
||||||
sourceChip = null
|
sourceChip = null
|
||||||
|
repository.setSourceFilter(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.setOnClickListener {
|
c.setOnClickListener {
|
||||||
@ -130,7 +140,15 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
|||||||
}
|
}
|
||||||
(it as Chip).isCloseIconVisible = true
|
(it as Chip).isCloseIconVisible = true
|
||||||
sourceChip = it
|
sourceChip = it
|
||||||
|
repository.setSourceFilter(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (repository.sourceFilter.value?.equals(source) == true) {
|
||||||
|
c.isCloseIconVisible = true
|
||||||
|
sourceChip = c
|
||||||
|
}
|
||||||
|
|
||||||
sourceGroup.addView(c)
|
sourceGroup.addView(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +156,11 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
|||||||
binding.filterView.visibility = VISIBLE
|
binding.filterView.visibility = VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.floatingActionButton2.setOnClickListener {
|
||||||
|
(activity as HomeActivity).getElementsAccordingToTab()
|
||||||
|
(activity as HomeActivity).fetchOnEmptyList()
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
@ -13,13 +14,29 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:visibility="gone" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/filterView"
|
android:id="@+id/filterView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="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
|
<TextView
|
||||||
android:id="@+id/filterTagsTitle"
|
android:id="@+id/filterTagsTitle"
|
||||||
@ -32,19 +49,6 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="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
|
<TextView
|
||||||
android:id="@+id/filterSourcesTitle"
|
android:id="@+id/filterSourcesTitle"
|
||||||
style="@style/MaterialAlertDialog.MaterialComponents.Title.Text"
|
style="@style/MaterialAlertDialog.MaterialComponents.Title.Text"
|
||||||
@ -57,6 +61,19 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/tagsGroup" />
|
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
|
<com.google.android.material.chip.ChipGroup
|
||||||
android:id="@+id/sourcesGroup"
|
android:id="@+id/sourcesGroup"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -23,8 +23,10 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
var displayedItems = ItemType.UNREAD
|
var displayedItems = ItemType.UNREAD
|
||||||
|
|
||||||
var tagFilter: SelfossModel.Tag? = null
|
private var _tagFilter = MutableStateFlow<SelfossModel.Tag?>(null)
|
||||||
var sourceFilter: SelfossModel.Source? = null
|
var tagFilter = _tagFilter.asStateFlow()
|
||||||
|
private var _sourceFilter = MutableStateFlow<SelfossModel.Source?>(null)
|
||||||
|
var sourceFilter = _sourceFilter.asStateFlow()
|
||||||
var searchFilter: String? = null
|
var searchFilter: String? = null
|
||||||
|
|
||||||
var offlineOverride = false
|
var offlineOverride = false
|
||||||
@ -47,8 +49,8 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
fetchedItems = api.getItems(
|
fetchedItems = api.getItems(
|
||||||
displayedItems.type,
|
displayedItems.type,
|
||||||
offset = 0,
|
offset = 0,
|
||||||
tagFilter?.tag,
|
tagFilter.value?.tag,
|
||||||
sourceFilter?.id?.toLong(),
|
sourceFilter.value?.id?.toLong(),
|
||||||
searchFilter,
|
searchFilter,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
@ -61,10 +63,10 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
(it.starred && displayedItems == ItemType.STARRED)
|
(it.starred && displayedItems == ItemType.STARRED)
|
||||||
}
|
}
|
||||||
if (tagFilter != null) {
|
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) {
|
if (sourceFilter != null) {
|
||||||
dbItems = dbItems.filter { it.sourcetitle == sourceFilter!!.title }
|
dbItems = dbItems.filter { it.sourcetitle == sourceFilter.value?.title }
|
||||||
}
|
}
|
||||||
fetchedItems = StatusAndData.succes(
|
fetchedItems = StatusAndData.succes(
|
||||||
dbItems.map { it.toView() }
|
dbItems.map { it.toView() }
|
||||||
@ -88,8 +90,8 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
fetchedItems = api.getItems(
|
fetchedItems = api.getItems(
|
||||||
displayedItems.type,
|
displayedItems.type,
|
||||||
offset,
|
offset,
|
||||||
tagFilter?.tag,
|
tagFilter.value?.tag,
|
||||||
sourceFilter?.id?.toLong(),
|
sourceFilter.value?.id?.toLong(),
|
||||||
searchFilter,
|
searchFilter,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
@ -505,4 +507,12 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
deleteDBAction(action)
|
deleteDBAction(action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setTagFilter(tag: SelfossModel.Tag?) {
|
||||||
|
_tagFilter.value = tag
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setSourceFilter(source: SelfossModel.Source?) {
|
||||||
|
_sourceFilter.value = source
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user