diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/FilterSheetFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/FilterSheetFragment.kt
index 21652fd..5ae9317 100644
--- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/FilterSheetFragment.kt
+++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/FilterSheetFragment.kt
@@ -39,8 +39,7 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
private val repository: Repository by instance()
private val appSettingsService: AppSettingsService by instance()
- private var tagChip: Chip? = null
- private var sourceChip: Chip? = null
+ private var selectedChip: Chip? = null
@SuppressLint("ResourceAsColor")
override fun onCreateView(
@@ -56,10 +55,14 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
)
val tagGroup = binding.tagsGroup
+ val hiddenTagGroup = binding.hiddenTagsGroup
val sourceGroup = binding.sourcesGroup
CoroutineScope(Dispatchers.Main).launch {
- repository.getTags().forEach { tag ->
+ val tags = repository.getTags()
+ val hiddenTags = appSettingsService.getHiddenTags()
+
+ tags.filterNot { hiddenTags.contains(it.tag) }.forEach { tag ->
val c = Chip(requireContext())
c.text = tag.tag
@@ -78,31 +81,76 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
c.setOnCloseIconClickListener {
(it as Chip).isCloseIconVisible = false
- tagChip = null
+ selectedChip = null
repository.setTagFilter(null)
}
c.setOnClickListener {
- if (tagChip != null) {
- tagChip!!.isCloseIconVisible = false
+ if (selectedChip != null) {
+ selectedChip!!.isCloseIconVisible = false
}
(it as Chip).isCloseIconVisible = true
- tagChip = it
+ selectedChip = it
repository.setTagFilter(tag)
- sourceChip?.isCloseIconVisible = false
- sourceChip = null
repository.setSourceFilter(null)
}
if (repository.tagFilter.value?.equals(tag) == true) {
c.isCloseIconVisible = true
- tagChip = c
+ selectedChip = c
}
tagGroup.addView(c)
}
+ if (hiddenTags.isNotEmpty()) {
+ binding.filterHiddenTagsTitle.visibility = VISIBLE
+ binding.hiddenTagsGroup.visibility = VISIBLE
+
+ tags.filter { hiddenTags.contains(it.tag) }.forEach { tag ->
+ val c = Chip(requireContext())
+ c.text = tag.tag
+
+ val gd = GradientDrawable()
+ val gdColor = try {
+ Color.parseColor(tag.color)
+ } catch (e: IllegalArgumentException) {
+ e.sendSilentlyWithAcraWithName("color issue " + tag.color)
+ resources.getColor(R.color.colorPrimary)
+ }
+ gd.setColor(gdColor)
+ gd.shape = GradientDrawable.RECTANGLE
+ gd.setSize(30, 30)
+ gd.cornerRadius = 30F
+ c.chipIcon = gd
+
+ c.setOnCloseIconClickListener {
+ (it as Chip).isCloseIconVisible = false
+ selectedChip = null
+ repository.setTagFilter(null)
+ }
+
+ c.setOnClickListener {
+ if (selectedChip != null) {
+ selectedChip!!.isCloseIconVisible = false
+ }
+ (it as Chip).isCloseIconVisible = true
+ selectedChip = it
+ repository.setTagFilter(tag)
+
+ repository.setSourceFilter(null)
+ }
+
+ if (repository.tagFilter.value?.equals(tag) == true) {
+ c.isCloseIconVisible = true
+ selectedChip = c
+ }
+
+ hiddenTagGroup.addView(c)
+ }
+ }
+
repository.getSources().forEach { source ->
val c = Chip(requireContext())
@@ -134,28 +182,25 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
c.setOnCloseIconClickListener {
(it as Chip).isCloseIconVisible = false
- sourceChip = null
+ selectedChip = null
repository.setSourceFilter(null)
}
c.setOnClickListener {
- if (sourceChip != null) {
- sourceChip!!.isCloseIconVisible = false
+ if (selectedChip != null) {
+ selectedChip!!.isCloseIconVisible = false
}
(it as Chip).isCloseIconVisible = true
- sourceChip = it
+ selectedChip = it
repository.setSourceFilter(source)
-
- tagChip?.isCloseIconVisible = false
- tagChip = null
repository.setTagFilter(null)
}
if (repository.sourceFilter.value?.equals(source) == true) {
c.isCloseIconVisible = true
- sourceChip = c
+ selectedChip = c
}
sourceGroup.addView(c)
diff --git a/androidApp/src/main/res/layout/filter_fragment.xml b/androidApp/src/main/res/layout/filter_fragment.xml
index e4ca520..b9e8b3e 100644
--- a/androidApp/src/main/res/layout/filter_fragment.xml
+++ b/androidApp/src/main/res/layout/filter_fragment.xml
@@ -49,17 +49,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
-
-
+
+
+
+
+
+
+
+
+
+