mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 04:09:03 +00:00
Add task tag filters
This commit is contained in:
parent
31a597d6b4
commit
3bace6ffcb
3 changed files with 75 additions and 22 deletions
|
|
@ -337,6 +337,9 @@
|
|||
<string name="edit_tag_btn_edit">Edit</string>
|
||||
<string name="confirm_delete_tag_title">Are you sure?</string>
|
||||
<string name="confirm_delete_tag_message">Do you really want to delete?</string>
|
||||
<string name="your_tags">Your Tags</string>
|
||||
<string name="challenge_tags">Challenge Tags</string>
|
||||
<string name="group_tags">Group Tags</string>
|
||||
|
||||
<!-- QR Strings -->
|
||||
<string name="choose_recipient_title">Choose Message Recipient</string>
|
||||
|
|
@ -1455,6 +1458,7 @@
|
|||
<string name="preference_push_joined_group_plan_mention">\@Mentions in Group Plans</string>
|
||||
<string name="subscribe_incentive_button_faint">Subscribe to hold on with 1HP!</string>
|
||||
|
||||
|
||||
<plurals name="you_x_others">
|
||||
<item quantity="zero">You</item>
|
||||
<item quantity="one">You, %d other</item>
|
||||
|
|
|
|||
|
|
@ -546,13 +546,13 @@ class TaskFormActivity : BaseActivity() {
|
|||
}
|
||||
}
|
||||
val challengesTagTitle = Tag().apply {
|
||||
name = getString(R.string.challenges)
|
||||
name = getString(R.string.challenge_tags)
|
||||
}
|
||||
val groupsTagTitle = Tag().apply {
|
||||
name = getString(R.string.groups)
|
||||
name = getString(R.string.group_tags)
|
||||
}
|
||||
val otherTagTitle = Tag().apply {
|
||||
name = getString(R.string.tags)
|
||||
name = getString(R.string.your_tags)
|
||||
}
|
||||
if (challengeTagList.isNotEmpty()) {
|
||||
sortedTagList.add(challengesTagTitle)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import android.view.LayoutInflater
|
|||
import android.view.WindowManager
|
||||
import android.widget.Button
|
||||
import android.widget.RadioGroup
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.appcompat.widget.AppCompatCheckBox
|
||||
import androidx.core.content.ContextCompat
|
||||
|
|
@ -135,28 +136,38 @@ class TaskFilterDialog(context: Context, private val repository: TagRepository,
|
|||
)
|
||||
val leftPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12f, context.resources.displayMetrics).toInt()
|
||||
val verticalPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8f, context.resources.displayMetrics).toInt()
|
||||
sortTagPositions()
|
||||
for (tag in tags) {
|
||||
val tagCheckbox = AppCompatCheckBox(context)
|
||||
tagCheckbox.text = tag.name
|
||||
tagCheckbox.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
|
||||
tagCheckbox.isChecked = viewModel.tags.contains(tag.id)
|
||||
tagCheckbox.setPadding(
|
||||
tagCheckbox.paddingLeft + leftPadding,
|
||||
verticalPadding,
|
||||
tagCheckbox.paddingRight,
|
||||
verticalPadding
|
||||
)
|
||||
tagCheckbox.setTextColor(ContextCompat.getColor(context, R.color.text_secondary))
|
||||
CompoundButtonCompat.setButtonTintList(tagCheckbox, colorStateList)
|
||||
tagCheckbox.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
viewModel.addActiveTag(tag.id)
|
||||
} else {
|
||||
viewModel.removeActiveTag(tag.id)
|
||||
if (tag.id.isBlank()) {
|
||||
// This is a title for a tag group
|
||||
val view = TextView(context)
|
||||
view.setPadding(0, view.paddingTop, view.paddingRight, view.paddingBottom)
|
||||
view.text = tag.name
|
||||
view.setTextColor(context.getThemeColor(R.attr.textColorTintedPrimary))
|
||||
binding.tagsList.addView(view)
|
||||
} else {
|
||||
val tagCheckbox = AppCompatCheckBox(context)
|
||||
tagCheckbox.text = tag.name
|
||||
tagCheckbox.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
|
||||
tagCheckbox.isChecked = viewModel.tags.contains(tag.id)
|
||||
tagCheckbox.setPadding(
|
||||
tagCheckbox.paddingLeft + leftPadding,
|
||||
verticalPadding,
|
||||
tagCheckbox.paddingRight,
|
||||
verticalPadding
|
||||
)
|
||||
tagCheckbox.setTextColor(ContextCompat.getColor(context, R.color.text_secondary))
|
||||
CompoundButtonCompat.setButtonTintList(tagCheckbox, colorStateList)
|
||||
tagCheckbox.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
viewModel.addActiveTag(tag.id)
|
||||
} else {
|
||||
viewModel.removeActiveTag(tag.id)
|
||||
}
|
||||
filtersChanged()
|
||||
}
|
||||
filtersChanged()
|
||||
binding.tagsList.addView(tagCheckbox)
|
||||
}
|
||||
binding.tagsList.addView(tagCheckbox)
|
||||
}
|
||||
createAddTagButton()
|
||||
}
|
||||
|
|
@ -320,6 +331,44 @@ class TaskFilterDialog(context: Context, private val repository: TagRepository,
|
|||
filtersChanged()
|
||||
}
|
||||
|
||||
private fun sortTagPositions() {
|
||||
val sortedTagList = arrayListOf<Tag>()
|
||||
val challengeTagList = arrayListOf<Tag>()
|
||||
val groupTagList = arrayListOf<Tag>()
|
||||
val otherTagList = arrayListOf<Tag>()
|
||||
tags.forEach {
|
||||
if (it.challenge) {
|
||||
challengeTagList.add(it)
|
||||
} else if (it.group != null) {
|
||||
groupTagList.add(it)
|
||||
} else {
|
||||
otherTagList.add(it)
|
||||
}
|
||||
}
|
||||
val challengesTagTitle = Tag().apply {
|
||||
name = context.getString(R.string.challenge_tags)
|
||||
}
|
||||
val groupsTagTitle = Tag().apply {
|
||||
name = context.getString(R.string.group_tags)
|
||||
}
|
||||
val otherTagTitle = Tag().apply {
|
||||
name = context.getString(R.string.your_tags)
|
||||
}
|
||||
if (challengeTagList.isNotEmpty()) {
|
||||
sortedTagList.add(challengesTagTitle)
|
||||
sortedTagList.addAll(challengeTagList)
|
||||
}
|
||||
if (groupTagList.isNotEmpty()) {
|
||||
sortedTagList.add(groupsTagTitle)
|
||||
sortedTagList.addAll(groupTagList)
|
||||
}
|
||||
if (otherTagList.isNotEmpty()) {
|
||||
sortedTagList.add(otherTagTitle)
|
||||
sortedTagList.addAll(otherTagList)
|
||||
}
|
||||
tags = sortedTagList
|
||||
}
|
||||
|
||||
private fun editButtonClicked() {
|
||||
isEditing = !isEditing
|
||||
if (isEditing) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue