forked from Louvorg/ReaderForSelfoss-multiplatform
		
	Hidden tags.
This commit is contained in:
		| @@ -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) | ||||
|   | ||||
| @@ -49,17 +49,6 @@ | ||||
|             app:layout_constraintStart_toStartOf="parent" | ||||
|             app:layout_constraintTop_toTopOf="parent" /> | ||||
|  | ||||
|         <TextView | ||||
|             android:id="@+id/filterSourcesTitle" | ||||
|             style="@style/MaterialAlertDialog.MaterialComponents.Title.Text" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_marginStart="24dp" | ||||
|             android:layout_marginTop="24dp" | ||||
|             android:text="@string/filter_sources_title" | ||||
|             app:layout_constraintStart_toStartOf="parent" | ||||
|             app:layout_constraintTop_toBottomOf="@+id/tagsGroup" /> | ||||
|  | ||||
|  | ||||
|         <com.google.android.material.chip.ChipGroup | ||||
|             android:id="@+id/tagsGroup" | ||||
| @@ -73,6 +62,44 @@ | ||||
|  | ||||
|         </com.google.android.material.chip.ChipGroup> | ||||
|  | ||||
|         <TextView | ||||
|             android:id="@+id/filterHiddenTagsTitle" | ||||
|             style="@style/MaterialAlertDialog.MaterialComponents.Title.Text" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_marginStart="24dp" | ||||
|             android:layout_marginTop="24dp" | ||||
|             android:text="@string/drawer_item_hidden_tags" | ||||
|             android:visibility="gone" | ||||
|             app:layout_constraintStart_toStartOf="parent" | ||||
|             app:layout_constraintTop_toBottomOf="@+id/tagsGroup" /> | ||||
|  | ||||
|  | ||||
|         <com.google.android.material.chip.ChipGroup | ||||
|             android:id="@+id/hiddenTagsGroup" | ||||
|             android:layout_width="match_parent" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_marginStart="16dp" | ||||
|             android:layout_marginTop="24dp" | ||||
|             android:visibility="gone" | ||||
|             app:layout_constraintStart_toStartOf="parent" | ||||
|             app:layout_constraintTop_toBottomOf="@+id/filterHiddenTagsTitle" | ||||
|             app:singleSelection="true"> | ||||
|  | ||||
|         </com.google.android.material.chip.ChipGroup> | ||||
|  | ||||
|  | ||||
|         <TextView | ||||
|             android:id="@+id/filterSourcesTitle" | ||||
|             style="@style/MaterialAlertDialog.MaterialComponents.Title.Text" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_marginStart="24dp" | ||||
|             android:layout_marginTop="24dp" | ||||
|             android:text="@string/filter_sources_title" | ||||
|             app:layout_constraintStart_toStartOf="parent" | ||||
|             app:layout_constraintTop_toBottomOf="@+id/hiddenTagsGroup" /> | ||||
|  | ||||
|  | ||||
|         <com.google.android.material.chip.ChipGroup | ||||
|             android:id="@+id/sourcesGroup" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user