diff --git a/app/src/main/java/net/helcel/beans/activity/EditActivity.kt b/app/src/main/java/net/helcel/beans/activity/EditActivity.kt index 525e339..d4f960b 100644 --- a/app/src/main/java/net/helcel/beans/activity/EditActivity.kt +++ b/app/src/main/java/net/helcel/beans/activity/EditActivity.kt @@ -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) } diff --git a/app/src/main/java/net/helcel/beans/activity/adapter/GeolocListAdapter.kt b/app/src/main/java/net/helcel/beans/activity/adapter/GeolocListAdapter.kt index cb5994e..5ee02cb 100644 --- a/app/src/main/java/net/helcel/beans/activity/adapter/GeolocListAdapter.kt +++ b/app/src/main/java/net/helcel/beans/activity/adapter/GeolocListAdapter.kt @@ -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() { private val sortedList = l.children.toList().sortedBy { it.fullName } + private val holders: MutableSet = 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() } diff --git a/app/src/main/java/net/helcel/beans/activity/adapter/ViewPagerAdapter.kt b/app/src/main/java/net/helcel/beans/activity/adapter/ViewPagerAdapter.kt index 01f8316..d5a7697 100644 --- a/app/src/main/java/net/helcel/beans/activity/adapter/ViewPagerAdapter.kt +++ b/app/src/main/java/net/helcel/beans/activity/adapter/ViewPagerAdapter.kt @@ -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)} + } } diff --git a/app/src/main/java/net/helcel/beans/activity/fragment/EditGroupAddFragment.kt b/app/src/main/java/net/helcel/beans/activity/fragment/EditGroupAddFragment.kt index 184ec74..80038db 100644 --- a/app/src/main/java/net/helcel/beans/activity/fragment/EditGroupAddFragment.kt +++ b/app/src/main/java/net/helcel/beans/activity/fragment/EditGroupAddFragment.kt @@ -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 } diff --git a/app/src/main/java/net/helcel/beans/activity/fragment/EditPlaceColorFragment.kt b/app/src/main/java/net/helcel/beans/activity/fragment/EditPlaceColorFragment.kt index 53d1046..58bb328 100644 --- a/app/src/main/java/net/helcel/beans/activity/fragment/EditPlaceColorFragment.kt +++ b/app/src/main/java/net/helcel/beans/activity/fragment/EditPlaceColorFragment.kt @@ -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 diff --git a/app/src/main/java/net/helcel/beans/activity/fragment/EditPlaceFragment.kt b/app/src/main/java/net/helcel/beans/activity/fragment/EditPlaceFragment.kt index ddccaac..82855ac 100644 --- a/app/src/main/java/net/helcel/beans/activity/fragment/EditPlaceFragment.kt +++ b/app/src/main/java/net/helcel/beans/activity/fragment/EditPlaceFragment.kt @@ -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) + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/color.xml b/app/src/main/res/drawable/color.xml new file mode 100644 index 0000000..90e9872 --- /dev/null +++ b/app/src/main/res/drawable/color.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/fragment_edit_places_colors.xml b/app/src/main/res/layout/fragment_edit_places_colors.xml index 5484e28..e7a11e5 100644 --- a/app/src/main/res/layout/fragment_edit_places_colors.xml +++ b/app/src/main/res/layout/fragment_edit_places_colors.xml @@ -10,8 +10,7 @@ android:id="@+id/warning_text" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="10dp" - android:visibility="gone" /> + android:layout_marginBottom="10dp" /> + + + + \ No newline at end of file diff --git a/app/src/main/res/values/en.xml b/app/src/main/res/values/en.xml index 84918ce..9c4a10f 100644 --- a/app/src/main/res/values/en.xml +++ b/app/src/main/res/values/en.xml @@ -5,6 +5,7 @@ Settings Stats Edit + Color App theme System Light @@ -20,6 +21,7 @@ Project repository: https://git.helcel.net/helcel/beans\n Feel free to report issues or contribute to the project. Free and open source dependencies and licenses About the Beans application + Select the group to assign. Long press on a group to edit its name and color. Are your sure you want to delete this group and remove all its country mappings? Select one group you want to keep. All others will be deleted and its mappings reassigned to the group you choose here. Are you sure you want to disable regions and reassign all regional mappings to the corresponding countries?