[m] Prepare Release
This commit is contained in:
@@ -4,36 +4,31 @@ import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import androidx.activity.addCallback
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
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.EditPlaceFragment
|
||||
import net.helcel.beans.countries.World
|
||||
import net.helcel.beans.databinding.ActivityEditBinding
|
||||
import net.helcel.beans.helper.Theme.createActionBar
|
||||
|
||||
|
||||
class EditActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var viewPager: ViewPager2
|
||||
private lateinit var tabLayout: TabLayout
|
||||
private lateinit var _binding: ActivityEditBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
_binding = ActivityEditBinding.inflate(layoutInflater)
|
||||
|
||||
setContentView(R.layout.activity_edit)
|
||||
setContentView(_binding.root)
|
||||
createActionBar(this, getString(R.string.action_edit))
|
||||
|
||||
|
||||
viewPager = findViewById(R.id.pager)
|
||||
tabLayout = findViewById(R.id.tab)
|
||||
|
||||
val adapter = ViewPagerAdapter(supportFragmentManager, lifecycle, viewPager)
|
||||
viewPager.adapter = adapter
|
||||
val adapter = ViewPagerAdapter(supportFragmentManager, lifecycle, _binding.pager)
|
||||
_binding.pager.adapter = adapter
|
||||
adapter.addFragment(null, EditPlaceFragment(World.WWW, adapter))
|
||||
|
||||
TabLayoutMediator(tabLayout, viewPager) { tab, position ->
|
||||
TabLayoutMediator(_binding.tab, _binding.pager) { tab, position ->
|
||||
tab.text = adapter.getLabel(position)
|
||||
}.attach()
|
||||
|
||||
|
@@ -4,15 +4,13 @@ import android.content.Intent
|
||||
import android.graphics.drawable.PictureDrawable
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.MenuProvider
|
||||
import com.caverock.androidsvg.RenderOptions
|
||||
import com.github.chrisbanes.photoview.PhotoView
|
||||
import net.helcel.beans.R
|
||||
import net.helcel.beans.countries.GeoLocImporter
|
||||
import net.helcel.beans.helper.Data.loadData
|
||||
import net.helcel.beans.databinding.ActivityMainBinding
|
||||
import net.helcel.beans.helper.Data
|
||||
import net.helcel.beans.helper.Settings
|
||||
import net.helcel.beans.helper.Theme.colorWrapper
|
||||
import net.helcel.beans.svg.CSSWrapper
|
||||
@@ -20,8 +18,7 @@ import net.helcel.beans.svg.SVGWrapper
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var photoView: PhotoView
|
||||
private lateinit var _binding: ActivityMainBinding
|
||||
|
||||
private lateinit var psvg: SVGWrapper
|
||||
private lateinit var css: CSSWrapper
|
||||
@@ -31,55 +28,36 @@ class MainActivity : AppCompatActivity() {
|
||||
super.onRestart()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_main, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
val d = when (item.itemId) {
|
||||
R.id.action_edit -> EditActivity::class.java
|
||||
R.id.action_stats -> StatActivity::class.java
|
||||
R.id.action_settings -> SettingsActivity::class.java
|
||||
else -> throw Exception("Non Existent Menu Item")
|
||||
}
|
||||
startActivity(Intent(this@MainActivity, d))
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Create action bar
|
||||
_binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
Settings.start(this)
|
||||
supportActionBar?.setBackgroundDrawable(colorWrapper(this, android.R.attr.colorPrimary))
|
||||
|
||||
// restore app theme & settings upon startup
|
||||
Settings.start(this)
|
||||
|
||||
// Create menu in action bar
|
||||
addMenuProvider(object : MenuProvider {
|
||||
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
||||
menuInflater.inflate(R.menu.menu_main, menu)
|
||||
}
|
||||
setContentView(_binding.root)
|
||||
|
||||
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
||||
return when (menuItem.itemId) {
|
||||
R.id.action_edit -> {
|
||||
startActivity(Intent(this@MainActivity, EditActivity::class.java))
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_stats -> {
|
||||
startActivity(Intent(this@MainActivity, StatActivity::class.java))
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_settings -> {
|
||||
startActivity(Intent(this@MainActivity, SettingsActivity::class.java))
|
||||
true
|
||||
}
|
||||
|
||||
else -> {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
// Populate map from list of countries
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
photoView = findViewById(R.id.photo_view)
|
||||
photoView.minimumScale = 1f
|
||||
photoView.maximumScale = 40f
|
||||
_binding.photoView.minimumScale = 1f
|
||||
_binding.photoView.maximumScale = 40f
|
||||
|
||||
GeoLocImporter.importStates(this)
|
||||
loadData(this, Int.MIN_VALUE)
|
||||
Data.loadData(this, Int.MIN_VALUE)
|
||||
psvg = SVGWrapper(this)
|
||||
css = CSSWrapper(this)
|
||||
|
||||
@@ -88,9 +66,8 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
private fun refreshMap() {
|
||||
val opt: RenderOptions = RenderOptions.create()
|
||||
css.refresh()
|
||||
opt.css(css.get())
|
||||
photoView.setImageDrawable(PictureDrawable(psvg.get()?.renderToPicture(opt)))
|
||||
_binding.photoView.setImageDrawable(PictureDrawable(psvg.get()?.renderToPicture(opt)))
|
||||
}
|
||||
|
||||
}
|
@@ -4,32 +4,30 @@ import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.checkbox.MaterialCheckBox
|
||||
import net.helcel.beans.R
|
||||
import net.helcel.beans.activity.fragment.EditPlaceColorFragment
|
||||
import net.helcel.beans.activity.fragment.EditPlaceFragment
|
||||
import net.helcel.beans.countries.GeoLoc
|
||||
import net.helcel.beans.databinding.ItemListGeolocBinding
|
||||
import net.helcel.beans.helper.Data
|
||||
import net.helcel.beans.helper.Settings
|
||||
import net.helcel.beans.helper.Theme.colorWrapper
|
||||
|
||||
class GeolocListAdapter(
|
||||
private val ctx: EditPlaceFragment, val l: GeoLoc, private val pager: ViewPagerAdapter
|
||||
private val ctx: EditPlaceFragment, private val l: GeoLoc, private val pager: ViewPagerAdapter
|
||||
) : RecyclerView.Adapter<GeolocListAdapter.FoldingListViewHolder>() {
|
||||
|
||||
private lateinit var view: View
|
||||
|
||||
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): FoldingListViewHolder {
|
||||
view = LayoutInflater
|
||||
.from(viewGroup.context)
|
||||
.inflate(R.layout.item_list_geoloc, viewGroup, false)
|
||||
return FoldingListViewHolder(ctx.requireActivity(), view)
|
||||
val binding = ItemListGeolocBinding.inflate(
|
||||
LayoutInflater.from(viewGroup.context),
|
||||
viewGroup,
|
||||
false
|
||||
)
|
||||
return FoldingListViewHolder(ctx.requireActivity(), binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: FoldingListViewHolder, position: Int) {
|
||||
@@ -46,56 +44,51 @@ class GeolocListAdapter(
|
||||
return l.children.size
|
||||
}
|
||||
|
||||
class FoldingListViewHolder(private val ctx: FragmentActivity, itemView: View) :
|
||||
RecyclerView.ViewHolder(itemView) {
|
||||
private val textView: TextView = itemView.findViewById(R.id.textView)
|
||||
private val progressView: TextView = itemView.findViewById(R.id.name)
|
||||
private val checkBox: MaterialCheckBox = itemView.findViewById(R.id.checkBox)
|
||||
class FoldingListViewHolder(
|
||||
private val ctx: FragmentActivity,
|
||||
private val _binding: ItemListGeolocBinding
|
||||
) : RecyclerView.ViewHolder(_binding.root) {
|
||||
|
||||
private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx)
|
||||
private val statsPref = sharedPreferences.getString(
|
||||
ctx.getString(R.string.key_stats),
|
||||
ctx.getString(R.string.counters)
|
||||
)
|
||||
private fun bindGroup(el: GeoLoc) {
|
||||
val numerator = el.children.map { Data.visits.getVisited(it) != 0 }.count { it }
|
||||
val denominator = el.children.size
|
||||
|
||||
_binding.count.text = when (Settings.getStatPref(ctx)) {
|
||||
ctx.getString(R.string.percentages) -> ctx.getString(
|
||||
R.string.percentage,
|
||||
(100 * (numerator.toFloat() / denominator.toFloat())).toInt()
|
||||
)
|
||||
|
||||
else -> ctx.getString(R.string.rate, numerator, denominator)
|
||||
}
|
||||
_binding.textView.setTypeface(null, Typeface.BOLD)
|
||||
_binding.textView.backgroundTintList = ColorStateList.valueOf(
|
||||
colorWrapper(
|
||||
ctx,
|
||||
android.R.attr.panelColorBackground
|
||||
).color
|
||||
).withAlpha(64)
|
||||
}
|
||||
|
||||
fun bind(el: GeoLoc) {
|
||||
textView.text = el.fullName
|
||||
if (el.shouldShowChildren(ctx)) {
|
||||
textView.setTypeface(null, Typeface.BOLD)
|
||||
_binding.textView.text = el.fullName
|
||||
_binding.textView.backgroundTintList =
|
||||
ColorStateList.valueOf(colorWrapper(ctx, android.R.attr.colorBackground).color)
|
||||
|
||||
val numerator = el.children.map { Data.visits.getVisited(it) != 0 }.count { it }
|
||||
val denominator = el.children.size
|
||||
if (el.shouldShowChildren(ctx))
|
||||
bindGroup(el)
|
||||
|
||||
progressView.text = when (statsPref) {
|
||||
ctx.getString(R.string.percentages) -> ctx.getString(
|
||||
R.string.percentage,
|
||||
(100 * (numerator.toFloat() / denominator.toFloat())).toInt()
|
||||
)
|
||||
|
||||
else -> ctx.getString(R.string.rate, numerator, denominator)
|
||||
}
|
||||
textView.backgroundTintList = ColorStateList.valueOf(
|
||||
colorWrapper(
|
||||
ctx,
|
||||
android.R.attr.panelColorBackground
|
||||
).color
|
||||
).withAlpha(128)
|
||||
textView.parent.parent.requestChildFocus(textView, textView)
|
||||
} else {
|
||||
textView.backgroundTintList =
|
||||
ColorStateList.valueOf(colorWrapper(ctx, android.R.attr.colorBackground).color)
|
||||
}
|
||||
refreshCheck(el)
|
||||
}
|
||||
|
||||
fun addListeners(el: GeoLoc, expandLambda: () -> Boolean) {
|
||||
if (el.shouldShowChildren(ctx)) {
|
||||
textView.setOnClickListener { expandLambda() }
|
||||
_binding.textView.setOnClickListener { expandLambda() }
|
||||
}
|
||||
checkBox.setOnClickListener {
|
||||
_binding.checkBox.setOnClickListener {
|
||||
Data.selected_geoloc = el
|
||||
if (Data.groups.size() == 1 && Settings.isSingleGroup(ctx)) {
|
||||
if (checkBox.isChecked) {
|
||||
if (_binding.checkBox.isChecked) {
|
||||
// If one has just checked the box (assign unique group)
|
||||
Data.selected_group = Data.groups.getUniqueEntry()
|
||||
onColorDialogDismiss(false)
|
||||
@@ -129,21 +122,20 @@ class GeolocListAdapter(
|
||||
}
|
||||
|
||||
private fun refreshCheck(geoLoc: GeoLoc) {
|
||||
var col = Data.groups.getGroupFromKey(Data.visits.getVisited(geoLoc)).color.color
|
||||
if (col == Color.TRANSPARENT)
|
||||
col = Color.GRAY
|
||||
checkBox.checkedState =
|
||||
var col = Data.groups.getGroupFromKey(Data.visits.getVisited(geoLoc)).color
|
||||
if (col.color == Color.TRANSPARENT) {
|
||||
col = colorWrapper(
|
||||
ctx,
|
||||
android.R.attr.panelColorBackground
|
||||
)
|
||||
col.alpha = 64
|
||||
}
|
||||
_binding.checkBox.checkedState =
|
||||
if (Data.visits.getVisited(geoLoc) != 0) MaterialCheckBox.STATE_CHECKED
|
||||
else if (geoLoc.children.any { Data.visits.getVisited(it) != 0 }) MaterialCheckBox.STATE_INDETERMINATE
|
||||
else MaterialCheckBox.STATE_UNCHECKED
|
||||
|
||||
checkBox.buttonTintList = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(-android.R.attr.state_checked),
|
||||
intArrayOf(android.R.attr.state_checked)
|
||||
),
|
||||
intArrayOf(col, col)
|
||||
)
|
||||
_binding.checkBox.buttonTintList = ColorStateList.valueOf(col.color)
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,15 +1,12 @@
|
||||
package net.helcel.beans.activity.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import net.helcel.beans.R
|
||||
import net.helcel.beans.activity.fragment.EditGroupAddFragment
|
||||
import net.helcel.beans.databinding.ItemListGroupBinding
|
||||
import net.helcel.beans.helper.Data
|
||||
import net.helcel.beans.helper.Groups
|
||||
import net.helcel.beans.helper.Theme.getContrastColor
|
||||
@@ -20,9 +17,9 @@ class GroupListAdapter(
|
||||
) : RecyclerView.Adapter<GroupListAdapter.GroupViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GroupViewHolder {
|
||||
val view: View =
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.item_list_group, parent, false)
|
||||
return GroupViewHolder(view, activity, selectDialog)
|
||||
val binding =
|
||||
ItemListGroupBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return GroupViewHolder(binding, activity, selectDialog)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: GroupViewHolder, pos: Int) {
|
||||
@@ -34,41 +31,39 @@ class GroupListAdapter(
|
||||
}
|
||||
|
||||
inner class GroupViewHolder(
|
||||
itemView: View,
|
||||
private val _binding: ItemListGroupBinding,
|
||||
private val activity: FragmentActivity,
|
||||
private val selectDialog: DialogFragment
|
||||
) : RecyclerView.ViewHolder(itemView) {
|
||||
private val color: Button = itemView.findViewById(R.id.group_color)
|
||||
private val entries: TextView = itemView.findViewById(R.id.name)
|
||||
) : RecyclerView.ViewHolder(_binding.root) {
|
||||
private lateinit var dialogFragment: EditGroupAddFragment
|
||||
fun bind(entry: Pair<Int, Groups.Group>) {
|
||||
color.text = entry.second.name
|
||||
_binding.groupColor.text = entry.second.name
|
||||
dialogFragment = EditGroupAddFragment(entry.first, {
|
||||
val newEntry = Data.groups.getGroupFromKey(entry.first)
|
||||
color.text = newEntry.name
|
||||
_binding.groupColor.text = newEntry.name
|
||||
val newEntryColor = newEntry.color.color
|
||||
val contrastNewEntryColor =
|
||||
getContrastColor(newEntryColor)
|
||||
color.setBackgroundColor(newEntryColor)
|
||||
color.setTextColor(contrastNewEntryColor)
|
||||
entries.setTextColor(contrastNewEntryColor)
|
||||
entries.text = "0"
|
||||
_binding.groupColor.setBackgroundColor(newEntryColor)
|
||||
_binding.groupColor.setTextColor(contrastNewEntryColor)
|
||||
_binding.name.setTextColor(contrastNewEntryColor)
|
||||
_binding.name.text = "0"
|
||||
}, {
|
||||
notifyItemRemoved(it)
|
||||
})
|
||||
|
||||
val entryColor = entry.second.color.color
|
||||
val contrastEntryColor = getContrastColor(entryColor)
|
||||
color.setBackgroundColor(entryColor)
|
||||
color.setTextColor(contrastEntryColor)
|
||||
entries.setTextColor(contrastEntryColor)
|
||||
entries.text = Data.visits.countVisited(entry.first).toString()
|
||||
_binding.groupColor.setBackgroundColor(entryColor)
|
||||
_binding.groupColor.setTextColor(contrastEntryColor)
|
||||
_binding.name.setTextColor(contrastEntryColor)
|
||||
_binding.name.text = Data.visits.countVisited(entry.first).toString()
|
||||
|
||||
color.setOnClickListener {
|
||||
_binding.groupColor.setOnClickListener {
|
||||
Data.selected_group = entry.second
|
||||
selectDialog.dismiss()
|
||||
}
|
||||
color.setOnLongClickListener {
|
||||
_binding.groupColor.setOnLongClickListener {
|
||||
dialogFragment.show(
|
||||
activity.supportFragmentManager,
|
||||
"AddColorDialogFragment"
|
||||
|
@@ -7,8 +7,6 @@ import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.AppCompatButton
|
||||
import androidx.core.graphics.blue
|
||||
import androidx.core.graphics.green
|
||||
import androidx.core.graphics.red
|
||||
@@ -17,6 +15,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.slider.Slider
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import net.helcel.beans.R
|
||||
import net.helcel.beans.databinding.FragmentEditGroupsAddBinding
|
||||
import net.helcel.beans.helper.Data
|
||||
import net.helcel.beans.helper.Groups
|
||||
import net.helcel.beans.helper.Theme.colorToHex6
|
||||
@@ -26,51 +25,28 @@ class EditGroupAddFragment(
|
||||
private val key: Int = 0,
|
||||
val onAddCb: (Int) -> Unit,
|
||||
val onDelCb: (Int) -> Unit
|
||||
) :
|
||||
DialogFragment() {
|
||||
private lateinit var colorNameEditText: TextInputEditText
|
||||
private lateinit var colorEditText: TextInputEditText
|
||||
|
||||
private lateinit var colorView: View
|
||||
|
||||
private lateinit var colorEditR: Slider
|
||||
private lateinit var colorEditG: Slider
|
||||
private lateinit var colorEditB: Slider
|
||||
|
||||
private lateinit var btnDelete: AppCompatButton
|
||||
private lateinit var btnCancel: AppCompatButton
|
||||
private lateinit var btnOk: AppCompatButton
|
||||
) : DialogFragment() {
|
||||
|
||||
private lateinit var _binding: FragmentEditGroupsAddBinding
|
||||
private val grp = Data.groups.getGroupFromKey(key)
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val builder = AlertDialog.Builder(requireActivity())
|
||||
val inflater = requireActivity().layoutInflater
|
||||
val view: View = inflater.inflate(R.layout.fragment_edit_groups_add, null)
|
||||
val builder = MaterialAlertDialogBuilder(requireContext())
|
||||
_binding = FragmentEditGroupsAddBinding.inflate(layoutInflater)
|
||||
|
||||
colorNameEditText = view.findViewById(R.id.group_name)
|
||||
colorEditText = view.findViewById(R.id.group_color)
|
||||
colorView = view.findViewById(R.id.colorView)
|
||||
colorEditR = view.findViewById(R.id.colorR)
|
||||
colorEditG = view.findViewById(R.id.colorG)
|
||||
colorEditB = view.findViewById(R.id.colorB)
|
||||
setupSlider(_binding.colorR, grp.color.color.red / 255F)
|
||||
setupSlider(_binding.colorG, grp.color.color.green / 255F)
|
||||
setupSlider(_binding.colorB, grp.color.color.blue / 255F)
|
||||
setupText(_binding.groupColor, grp)
|
||||
|
||||
setupSlider(colorEditR, grp.color.color.red / 255F)
|
||||
setupSlider(colorEditG, grp.color.color.green / 255F)
|
||||
setupSlider(colorEditB, grp.color.color.blue / 255F)
|
||||
_binding.colorView.background = ColorDrawable(grp.color.color)
|
||||
|
||||
setupText(colorEditText, grp)
|
||||
|
||||
colorView.background = ColorDrawable(grp.color.color)
|
||||
|
||||
btnDelete = view.findViewById(R.id.btnDelete)
|
||||
btnCancel = view.findViewById(R.id.btnCancel)
|
||||
btnOk = view.findViewById(R.id.btnOk)
|
||||
|
||||
if (key == 0) {
|
||||
btnDelete.visibility = View.INVISIBLE
|
||||
btnDelete.isEnabled = false
|
||||
_binding.btnDelete.visibility = View.INVISIBLE
|
||||
_binding.btnDelete.isEnabled = false
|
||||
}
|
||||
btnDelete.setOnClickListener {
|
||||
_binding.btnDelete.setOnClickListener {
|
||||
MaterialAlertDialogBuilder(requireActivity())
|
||||
.setMessage(R.string.delete_group)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
@@ -87,9 +63,9 @@ class EditGroupAddFragment(
|
||||
.show()
|
||||
}
|
||||
|
||||
btnOk.setOnClickListener {
|
||||
val name = colorNameEditText.text.toString()
|
||||
val color = colorEditText.text.toString()
|
||||
_binding.btnOk.setOnClickListener {
|
||||
val name = _binding.groupName.text.toString()
|
||||
val color = _binding.groupColor.text.toString()
|
||||
val key = (if (key != 0) key else Data.groups.genKey())
|
||||
Data.groups.setGroup(key, name, ColorDrawable(Color.parseColor("#$color")))
|
||||
Data.saveData()
|
||||
@@ -97,12 +73,12 @@ class EditGroupAddFragment(
|
||||
dialog?.dismiss()
|
||||
}
|
||||
|
||||
btnCancel.setOnClickListener {
|
||||
_binding.btnCancel.setOnClickListener {
|
||||
dialog?.cancel()
|
||||
}
|
||||
|
||||
colorNameEditText.setText(grp.name)
|
||||
builder.setView(view)
|
||||
_binding.groupName.setText(grp.name)
|
||||
builder.setView(_binding.root)
|
||||
return builder.create()
|
||||
}
|
||||
|
||||
@@ -110,11 +86,11 @@ class EditGroupAddFragment(
|
||||
s.setText(colorToHex6(ColorDrawable(grp?.color?.color ?: 0)).substring(1))
|
||||
s.addTextChangedListener(
|
||||
EditTextListener(
|
||||
colorEditR,
|
||||
colorEditG,
|
||||
colorEditB,
|
||||
colorEditText,
|
||||
colorView
|
||||
_binding.colorR,
|
||||
_binding.colorG,
|
||||
_binding.colorB,
|
||||
_binding.groupColor,
|
||||
_binding.colorView
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -125,11 +101,11 @@ class EditGroupAddFragment(
|
||||
s.value = v
|
||||
s.addOnChangeListener(
|
||||
SliderOnChangeListener(
|
||||
colorEditR,
|
||||
colorEditG,
|
||||
colorEditB,
|
||||
colorEditText,
|
||||
colorView
|
||||
_binding.colorR,
|
||||
_binding.colorG,
|
||||
_binding.colorB,
|
||||
_binding.groupColor,
|
||||
_binding.colorView
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@@ -3,48 +3,41 @@ package net.helcel.beans.activity.fragment
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.AppCompatButton
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import net.helcel.beans.R
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import net.helcel.beans.activity.adapter.GeolocListAdapter
|
||||
import net.helcel.beans.activity.adapter.GroupListAdapter
|
||||
import net.helcel.beans.databinding.FragmentEditPlacesColorsBinding
|
||||
import net.helcel.beans.helper.Data
|
||||
|
||||
|
||||
class EditPlaceColorFragment(private val parent: GeolocListAdapter.FoldingListViewHolder) :
|
||||
DialogFragment() {
|
||||
|
||||
private lateinit var _binding: FragmentEditPlacesColorsBinding
|
||||
private lateinit var listAdapt: GroupListAdapter
|
||||
private lateinit var list: RecyclerView
|
||||
private var clear: Boolean = false
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val builder = AlertDialog.Builder(
|
||||
requireActivity()
|
||||
)
|
||||
val inflater = requireActivity().layoutInflater
|
||||
val view: View = inflater.inflate(R.layout.fragment_edit_places_colors, null)
|
||||
|
||||
val btnAdd: AppCompatButton = view.findViewById(R.id.btnAdd)
|
||||
val btnClear: AppCompatButton = view.findViewById(R.id.btnClear)
|
||||
btnAdd.setOnClickListener {
|
||||
val builder = MaterialAlertDialogBuilder(requireContext())
|
||||
_binding = FragmentEditPlacesColorsBinding.inflate(layoutInflater)
|
||||
_binding.btnAdd.setOnClickListener {
|
||||
EditGroupAddFragment(0, {
|
||||
listAdapt.notifyItemInserted(Data.groups.findGroupPos(it))
|
||||
}, {}).show(requireActivity().supportFragmentManager, "AddColorDialogFragment")
|
||||
}
|
||||
btnClear.setOnClickListener {
|
||||
_binding.btnClear.setOnClickListener {
|
||||
clear = true
|
||||
dialog?.dismiss()
|
||||
}
|
||||
|
||||
val dialog = builder.setView(view).create()
|
||||
val dialog = builder.setView(_binding.root).create()
|
||||
listAdapt = GroupListAdapter(requireActivity(), this)
|
||||
list = view.findViewById(R.id.groups_color)!!
|
||||
list.layoutManager = LinearLayoutManager(requireContext(), RecyclerView.VERTICAL, false)
|
||||
list.adapter = listAdapt
|
||||
_binding.groupsColor.layoutManager =
|
||||
LinearLayoutManager(requireContext(), RecyclerView.VERTICAL, false)
|
||||
_binding.groupsColor.adapter = listAdapt
|
||||
|
||||
return dialog
|
||||
}
|
||||
|
@@ -12,11 +12,12 @@ import kotlin.random.Random
|
||||
|
||||
private const val randSeed = 0
|
||||
private val rnd = Random(randSeed)
|
||||
|
||||
@Serializable
|
||||
class Groups(val id: Int, private val grps: HashMap<Int,Group>) {
|
||||
class Groups(val id: Int, private val grps: HashMap<Int, Group>) {
|
||||
|
||||
fun setGroup(key: Int, name: String, col: ColorDrawable) {
|
||||
grps[key] = Group(key,name,col)
|
||||
grps[key] = Group(key, name, col)
|
||||
}
|
||||
|
||||
fun deleteGroup(key: Int) {
|
||||
@@ -24,12 +25,12 @@ class Groups(val id: Int, private val grps: HashMap<Int,Group>) {
|
||||
}
|
||||
|
||||
fun getGroupFromKey(key: Int): Group {
|
||||
return grps.getOrDefault(key,EmptyGroup())
|
||||
return grps.getOrDefault(key, EmptyGroup())
|
||||
}
|
||||
|
||||
fun genKey(): Int {
|
||||
val key = rnd.nextInt()
|
||||
if(grps.containsKey(key) || key == 0) return genKey()
|
||||
if (grps.containsKey(key) || key == 0) return genKey()
|
||||
return key
|
||||
}
|
||||
|
||||
@@ -46,32 +47,38 @@ class Groups(val id: Int, private val grps: HashMap<Int,Group>) {
|
||||
}
|
||||
}
|
||||
|
||||
fun getGroupFromPos(pos: Int): Pair<Int,Group> {
|
||||
fun getGroupFromPos(pos: Int): Pair<Int, Group> {
|
||||
val key = grps.keys.toList()[pos]
|
||||
return Pair(key,getGroupFromKey(key))
|
||||
return Pair(key, getGroupFromKey(key))
|
||||
}
|
||||
|
||||
fun findGroupPos(key: Int): Int {
|
||||
return grps.keys.toList().indexOf(key)
|
||||
}
|
||||
|
||||
class EmptyGroup: Group(0,"")
|
||||
class EmptyGroup : Group(0, "")
|
||||
|
||||
@Serializable
|
||||
open class Group(val key: Int, val name: String, @Serializable(with = ColorDrawableSerializer::class) val color: ColorDrawable = ColorDrawable(Color.TRANSPARENT))
|
||||
open class Group(
|
||||
val key: Int,
|
||||
val name: String,
|
||||
@Serializable(with = Theme.ColorDrawableSerializer::class) val color: ColorDrawable = ColorDrawable(
|
||||
Color.TRANSPARENT
|
||||
)
|
||||
)
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@Serializer(Groups::class)
|
||||
class GroupsSerializer{
|
||||
class GroupsSerializer {
|
||||
val defaultValue: Groups
|
||||
get() = Groups(Int.MIN_VALUE,hashMapOf())
|
||||
get() = Groups(Int.MIN_VALUE, hashMapOf())
|
||||
|
||||
fun readFrom(input: InputStream): Groups {
|
||||
return Json.decodeFromString(serializer(),input.readBytes().decodeToString())
|
||||
return Json.decodeFromString(serializer(), input.readBytes().decodeToString())
|
||||
}
|
||||
|
||||
fun writeTo(t: Groups): String {
|
||||
return Json.encodeToString(serializer(),t).encodeToByteArray().decodeToString()
|
||||
return Json.encodeToString(serializer(), t).encodeToByteArray().decodeToString()
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -30,6 +30,13 @@ object Settings {
|
||||
)
|
||||
}
|
||||
|
||||
fun getStatPref(ctx: Context): String? {
|
||||
return sp.getString(
|
||||
ctx.getString(R.string.key_stats),
|
||||
ctx.getString(R.string.counters)
|
||||
)
|
||||
}
|
||||
|
||||
private fun getBooleanValue(ctx: Context, key: String?): Boolean {
|
||||
return when (key) {
|
||||
ctx.getString(R.string.on) -> true
|
||||
|
@@ -6,6 +6,11 @@ import android.graphics.drawable.ColorDrawable
|
||||
import android.util.TypedValue
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
object Theme {
|
||||
fun colorWrapper(ctx: Context, res: Int): ColorDrawable {
|
||||
@@ -34,4 +39,17 @@ object Theme {
|
||||
val blackContrast = ColorUtils.calculateContrast(Color.BLACK, color)
|
||||
return if (whiteContrast > blackContrast) Color.WHITE else Color.BLACK
|
||||
}
|
||||
}
|
||||
|
||||
object ColorDrawableSerializer : KSerializer<ColorDrawable> {
|
||||
override val descriptor = PrimitiveSerialDescriptor("ColorDrawable", PrimitiveKind.INT)
|
||||
|
||||
override fun deserialize(decoder: Decoder): ColorDrawable {
|
||||
return ColorDrawable(decoder.decodeInt())
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ColorDrawable) {
|
||||
encoder.encodeInt(value.color)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,20 +0,0 @@
|
||||
package net.helcel.beans.helper
|
||||
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
object ColorDrawableSerializer : KSerializer<ColorDrawable> {
|
||||
override val descriptor = PrimitiveSerialDescriptor("ColorDrawable", PrimitiveKind.INT)
|
||||
|
||||
override fun deserialize(decoder: Decoder): ColorDrawable {
|
||||
return ColorDrawable(decoder.decodeInt())
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ColorDrawable) {
|
||||
encoder.encodeInt(value.color)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user