Hidden tags.
This commit is contained in:
parent
477883ed39
commit
7b088d7bb4
@ -39,8 +39,7 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
|||||||
private val repository: Repository by instance()
|
private val repository: Repository by instance()
|
||||||
private val appSettingsService: AppSettingsService by instance()
|
private val appSettingsService: AppSettingsService by instance()
|
||||||
|
|
||||||
private var tagChip: Chip? = null
|
private var selectedChip: Chip? = null
|
||||||
private var sourceChip: Chip? = null
|
|
||||||
|
|
||||||
@SuppressLint("ResourceAsColor")
|
@SuppressLint("ResourceAsColor")
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
@ -56,10 +55,14 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val tagGroup = binding.tagsGroup
|
val tagGroup = binding.tagsGroup
|
||||||
|
val hiddenTagGroup = binding.hiddenTagsGroup
|
||||||
val sourceGroup = binding.sourcesGroup
|
val sourceGroup = binding.sourcesGroup
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
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())
|
val c = Chip(requireContext())
|
||||||
c.text = tag.tag
|
c.text = tag.tag
|
||||||
|
|
||||||
@ -78,31 +81,76 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
|||||||
|
|
||||||
c.setOnCloseIconClickListener {
|
c.setOnCloseIconClickListener {
|
||||||
(it as Chip).isCloseIconVisible = false
|
(it as Chip).isCloseIconVisible = false
|
||||||
tagChip = null
|
selectedChip = null
|
||||||
repository.setTagFilter(null)
|
repository.setTagFilter(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.setOnClickListener {
|
c.setOnClickListener {
|
||||||
if (tagChip != null) {
|
if (selectedChip != null) {
|
||||||
tagChip!!.isCloseIconVisible = false
|
selectedChip!!.isCloseIconVisible = false
|
||||||
}
|
}
|
||||||
(it as Chip).isCloseIconVisible = true
|
(it as Chip).isCloseIconVisible = true
|
||||||
tagChip = it
|
selectedChip = it
|
||||||
repository.setTagFilter(tag)
|
repository.setTagFilter(tag)
|
||||||
|
|
||||||
sourceChip?.isCloseIconVisible = false
|
|
||||||
sourceChip = null
|
|
||||||
repository.setSourceFilter(null)
|
repository.setSourceFilter(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (repository.tagFilter.value?.equals(tag) == true) {
|
if (repository.tagFilter.value?.equals(tag) == true) {
|
||||||
c.isCloseIconVisible = true
|
c.isCloseIconVisible = true
|
||||||
tagChip = c
|
selectedChip = c
|
||||||
}
|
}
|
||||||
|
|
||||||
tagGroup.addView(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 ->
|
repository.getSources().forEach { source ->
|
||||||
val c = Chip(requireContext())
|
val c = Chip(requireContext())
|
||||||
|
|
||||||
@ -134,28 +182,25 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
|||||||
|
|
||||||
c.setOnCloseIconClickListener {
|
c.setOnCloseIconClickListener {
|
||||||
(it as Chip).isCloseIconVisible = false
|
(it as Chip).isCloseIconVisible = false
|
||||||
sourceChip = null
|
selectedChip = null
|
||||||
repository.setSourceFilter(null)
|
repository.setSourceFilter(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.setOnClickListener {
|
c.setOnClickListener {
|
||||||
if (sourceChip != null) {
|
if (selectedChip != null) {
|
||||||
sourceChip!!.isCloseIconVisible = false
|
selectedChip!!.isCloseIconVisible = false
|
||||||
}
|
}
|
||||||
(it as Chip).isCloseIconVisible = true
|
(it as Chip).isCloseIconVisible = true
|
||||||
sourceChip = it
|
selectedChip = it
|
||||||
repository.setSourceFilter(source)
|
repository.setSourceFilter(source)
|
||||||
|
|
||||||
|
|
||||||
tagChip?.isCloseIconVisible = false
|
|
||||||
tagChip = null
|
|
||||||
repository.setTagFilter(null)
|
repository.setTagFilter(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (repository.sourceFilter.value?.equals(source) == true) {
|
if (repository.sourceFilter.value?.equals(source) == true) {
|
||||||
c.isCloseIconVisible = true
|
c.isCloseIconVisible = true
|
||||||
sourceChip = c
|
selectedChip = c
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceGroup.addView(c)
|
sourceGroup.addView(c)
|
||||||
|
@ -49,17 +49,6 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="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
|
<com.google.android.material.chip.ChipGroup
|
||||||
android:id="@+id/tagsGroup"
|
android:id="@+id/tagsGroup"
|
||||||
@ -73,6 +62,44 @@
|
|||||||
|
|
||||||
</com.google.android.material.chip.ChipGroup>
|
</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
|
<com.google.android.material.chip.ChipGroup
|
||||||
android:id="@+id/sourcesGroup"
|
android:id="@+id/sourcesGroup"
|
||||||
|
Loading…
Reference in New Issue
Block a user