Enable group color change in single group setting
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
package net.helcel.beans.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.activity.addCallback
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import net.helcel.beans.R
|
||||
import net.helcel.beans.activity.adapter.ViewPagerAdapter
|
||||
import net.helcel.beans.activity.fragment.EditGroupAddFragment
|
||||
import net.helcel.beans.activity.fragment.EditPlaceColorFragment
|
||||
import net.helcel.beans.activity.fragment.EditPlaceFragment
|
||||
import net.helcel.beans.countries.World
|
||||
import net.helcel.beans.databinding.ActivityEditBinding
|
||||
import net.helcel.beans.helper.Data
|
||||
import net.helcel.beans.helper.DialogCloser
|
||||
import net.helcel.beans.helper.Settings
|
||||
import net.helcel.beans.helper.Theme.createActionBar
|
||||
|
||||
|
||||
@@ -39,8 +46,24 @@ class EditActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
if (Settings.isSingleGroup(this)) {
|
||||
menuInflater.inflate(R.menu.menu_edit, menu)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
finish()
|
||||
when (item.itemId) {
|
||||
R.id.action_color -> {
|
||||
Data.groups.getUniqueEntry()?.let { group ->
|
||||
EditGroupAddFragment(group.key, {
|
||||
(_binding.pager.adapter as ViewPagerAdapter?)?.refreshColors(group.color)
|
||||
}, {}, false).show(supportFragmentManager, "AddColorDialogFragment")
|
||||
}
|
||||
}
|
||||
else -> finish()
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,7 @@ package net.helcel.beans.activity.adapter
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
@@ -22,6 +23,7 @@ class GeolocListAdapter(
|
||||
) : RecyclerView.Adapter<GeolocListAdapter.FoldingListViewHolder>() {
|
||||
|
||||
private val sortedList = l.children.toList().sortedBy { it.fullName }
|
||||
private val holders: MutableSet<FoldingListViewHolder> = mutableSetOf()
|
||||
|
||||
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): FoldingListViewHolder {
|
||||
val binding = ItemListGeolocBinding.inflate(
|
||||
@@ -29,7 +31,9 @@ class GeolocListAdapter(
|
||||
viewGroup,
|
||||
false
|
||||
)
|
||||
return FoldingListViewHolder(ctx.requireActivity(), binding, parentHolder, l)
|
||||
val holder = FoldingListViewHolder(ctx.requireActivity(), binding, parentHolder, l)
|
||||
holders.add(holder)
|
||||
return holder
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: FoldingListViewHolder, position: Int) {
|
||||
@@ -46,12 +50,17 @@ class GeolocListAdapter(
|
||||
return l.children.size
|
||||
}
|
||||
|
||||
fun refreshColors(colorDrawable: ColorDrawable) {
|
||||
holders.forEach { it.refreshColor(colorDrawable) }
|
||||
}
|
||||
|
||||
class FoldingListViewHolder(
|
||||
private val ctx: FragmentActivity,
|
||||
private val _binding: ItemListGeolocBinding,
|
||||
private val _parentHolder: FoldingListViewHolder? = null,
|
||||
private val _parentGeoLoc: GeoLoc,
|
||||
) : RecyclerView.ViewHolder(_binding.root), DialogCloser {
|
||||
private lateinit var el: GeoLoc
|
||||
|
||||
private fun bindGroup(el: GeoLoc) {
|
||||
refreshCount(el)
|
||||
@@ -65,6 +74,7 @@ class GeolocListAdapter(
|
||||
}
|
||||
|
||||
fun bind(el: GeoLoc) {
|
||||
this.el = el
|
||||
_binding.textView.text = el.fullName
|
||||
_binding.textView.backgroundTintList =
|
||||
ColorStateList.valueOf(colorWrapper(ctx, android.R.attr.colorBackground).color)
|
||||
@@ -75,6 +85,14 @@ class GeolocListAdapter(
|
||||
refreshCheck(el)
|
||||
}
|
||||
|
||||
fun refreshColor(colorDrawable: ColorDrawable) {
|
||||
if (Data.visits.getVisited(el) !in listOf(NO_GROUP, AUTO_GROUP)) {
|
||||
_binding.checkBox.buttonTintList =
|
||||
ColorStateList.valueOf(colorDrawable.color)
|
||||
refreshCheck(el)
|
||||
}
|
||||
}
|
||||
|
||||
fun addListeners(el: GeoLoc, expandLambda: () -> Boolean) {
|
||||
if (el.shouldShowChildren(ctx)) {
|
||||
_binding.textView.setOnClickListener { expandLambda() }
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package net.helcel.beans.activity.adapter
|
||||
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.Lifecycle
|
||||
@@ -51,6 +52,10 @@ class ViewPagerAdapter(
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
return fragmentList[position]
|
||||
}
|
||||
|
||||
fun refreshColors(colorDrawable: ColorDrawable) {
|
||||
fragmentList.forEach{ it.refreshColors(colorDrawable)}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -24,7 +24,8 @@ import net.helcel.beans.helper.Theme.colorToHex6
|
||||
class EditGroupAddFragment(
|
||||
private val key: Int = 0,
|
||||
val onAddCb: (Int) -> Unit,
|
||||
val onDelCb: (Int) -> Unit
|
||||
val onDelCb: (Int) -> Unit,
|
||||
private val deleteEnabled: Boolean = true
|
||||
) : DialogFragment() {
|
||||
|
||||
private lateinit var _binding: FragmentEditGroupsAddBinding
|
||||
@@ -42,7 +43,7 @@ class EditGroupAddFragment(
|
||||
_binding.colorView.background = ColorDrawable(grp.color.color)
|
||||
|
||||
|
||||
if (key == 0) {
|
||||
if (key == 0 || !deleteEnabled) {
|
||||
_binding.btnDelete.visibility = View.INVISIBLE
|
||||
_binding.btnDelete.isEnabled = false
|
||||
}
|
||||
|
@@ -45,10 +45,9 @@ class EditPlaceColorFragment(private val parent: DialogCloser, private val delet
|
||||
if (delete) {
|
||||
_binding.btnAdd.visibility = View.GONE
|
||||
_binding.btnClear.text = ctx.getString(R.string.cancel)
|
||||
with (_binding.warningText) {
|
||||
visibility = View.VISIBLE
|
||||
text = ctx.getString(R.string.select_group)
|
||||
}
|
||||
_binding.warningText.text = ctx.getString(R.string.select_group)
|
||||
} else {
|
||||
_binding.warningText.text = ctx.getString(R.string.edit_group)
|
||||
}
|
||||
|
||||
return dialog
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package net.helcel.beans.activity.fragment
|
||||
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -30,4 +31,8 @@ class EditPlaceFragment(val loc: GeoLoc, private val pager: ViewPagerAdapter, pr
|
||||
_binding.list.adapter = GeolocListAdapter(this, loc, pager, holder)
|
||||
return _binding.root
|
||||
}
|
||||
|
||||
fun refreshColors(colorDrawable: ColorDrawable) {
|
||||
(_binding.list.adapter as GeolocListAdapter?)?.refreshColors(colorDrawable)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user