Adapt group selection UI
- Enable group deletion (including mapped countries) - If only one group exists, no need to go through the dialog
This commit is contained in:
parent
872f31746e
commit
411bd5c4de
@ -88,10 +88,15 @@ class GeolocListAdapter(
|
||||
fun addListeners(el: Pair<GeoLoc, Boolean>, expandLambda: () -> Boolean) {
|
||||
textView.setOnClickListener { expandLambda() }
|
||||
checkBox.setOnClickListener {
|
||||
val dialogFragment = EditPlaceColorFragment(this)
|
||||
selected_geoloc = el.first
|
||||
selected_group = null
|
||||
dialogFragment.show(ctx.supportFragmentManager, "AddColorDialogFragment")
|
||||
if (groups!!.size() != 1) {
|
||||
val dialogFragment = EditPlaceColorFragment(this)
|
||||
selected_group = null
|
||||
dialogFragment.show(ctx.supportFragmentManager, "AddColorDialogFragment")
|
||||
} else {
|
||||
selected_group = groups!!.getUniqueEntry()!!
|
||||
onColorDialogDismiss(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ import net.helcel.beendroid.helper.getContrastColor
|
||||
import net.helcel.beendroid.helper.groups
|
||||
import net.helcel.beendroid.helper.saveData
|
||||
import net.helcel.beendroid.helper.selected_group
|
||||
import net.helcel.beendroid.helper.visits
|
||||
|
||||
class GroupListAdapter(private val activity: FragmentActivity, private val selectDialog: DialogFragment?) : RecyclerView.Adapter<GroupListAdapter.GroupViewHolder>() {
|
||||
|
||||
@ -39,7 +40,7 @@ class GroupListAdapter(private val activity: FragmentActivity, private val selec
|
||||
color.setBackgroundColor(entry.second.color.color)
|
||||
color.setTextColor(getContrastColor(entry.second.color.color))
|
||||
color.setOnClickListener {
|
||||
if(selectDialog==null) {
|
||||
if (selectDialog == null) {
|
||||
val dialogFragment = EditGroupAddFragment(entry.first) {
|
||||
val newEntry = groups!!.getGroupFromKey(entry.first)!!
|
||||
color.text = newEntry.name
|
||||
@ -50,28 +51,30 @@ class GroupListAdapter(private val activity: FragmentActivity, private val selec
|
||||
activity.supportFragmentManager,
|
||||
"AddColorDialogFragment"
|
||||
)
|
||||
}else{
|
||||
} else {
|
||||
selected_group = entry.second
|
||||
selectDialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
color.setOnLongClickListener {
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setMessage(R.string.delete_group)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
// TODO: Remove all countries belonging to that group
|
||||
if (selectDialog == null) {
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setMessage(R.string.delete_group)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
// Remove all countries belonging to that group
|
||||
val key = entry.first
|
||||
visits!!.deleteVisited(key)
|
||||
|
||||
|
||||
// Delete the group
|
||||
val key = entry.first
|
||||
val pos = groups!!.findGroupPos(key)
|
||||
groups!!.deleteGroup(key)
|
||||
saveData()
|
||||
this@GroupListAdapter.notifyItemRemoved(pos)
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel) { _, _ -> }
|
||||
.show()
|
||||
// Delete the group
|
||||
val pos = groups!!.findGroupPos(key)
|
||||
groups!!.deleteGroup(key)
|
||||
saveData()
|
||||
this@GroupListAdapter.notifyItemRemoved(pos)
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel) { _, _ -> }
|
||||
.show()
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,15 @@ class Groups(val id: Int, private val grps: HashMap<Int,Group>) {
|
||||
return grps.size
|
||||
}
|
||||
|
||||
fun getUniqueEntry(): Group? {
|
||||
assert(size() == 1)
|
||||
return if (grps.size == 1) {
|
||||
grps[grps.keys.first()]
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun getGroupFromPos(pos: Int): Pair<Int,Group> {
|
||||
val key = grps.keys.toList()[pos]
|
||||
return Pair(key,getGroupFromKey(key)!!)
|
||||
|
@ -15,6 +15,15 @@ class Visits(val id: Int, private val locs: HashMap<String,Int>) {
|
||||
locs[key.code] = b
|
||||
}
|
||||
|
||||
fun deleteVisited(key: Int) {
|
||||
val keysToDelete = locs
|
||||
.filter { it.value == key }
|
||||
.map { it.key }
|
||||
keysToDelete.forEach {
|
||||
locs.remove(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun getVisited(key: GeoLoc): Int {
|
||||
return locs.getOrDefault(key.code,0)
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
<string name="beendroid_repo">Project repository: https://git.helcel.net/helcel/beendroid\n Feel free to report issues or contribute to the project.</string>
|
||||
<string name="foss_licenses">Free and open source dependencies and licenses</string>
|
||||
<string name="about_beendroid">About the BeenDroid application</string>
|
||||
<string name="delete_group">Do you want to delete this group?</string>
|
||||
<string name="delete_group">Are your sure you want to delete this group and remove all its country mappings?</string>
|
||||
<string name="group_add">Add</string>
|
||||
<string name="logo">Logo</string>
|
||||
<string name="name">Name</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user