From 3f7183d056fe7e84ff57c6969e696c97b393877b Mon Sep 17 00:00:00 2001 From: soraefir Date: Mon, 12 Feb 2024 12:18:24 +0100 Subject: [PATCH] Added MultiColor, cleanup,... --- app/build.gradle | 2 +- .../helcel/beendroid/activity/EditActivity.kt | 25 ++++++--- .../helcel/beendroid/activity/MainActivity.kt | 9 ++- .../helcel/beendroid/activity/StatActivity.kt | 32 +++-------- .../GeolocListAdapter.kt} | 45 +++++++-------- .../activity/adapter/GroupListAdapter.kt | 48 ++++++++++++++++ .../activity/adapter/ViewPagerAdapter.kt | 34 ++++++++++++ .../activity/fragment/EditGroupAddFragment.kt | 49 +++++++++++++++++ .../activity/fragment/EditGroupFragment.kt | 44 +++++++++++++++ .../activity/fragment/EditPlaceFragment.kt | 34 ++++++++++++ .../activity/fragment/LicenseFragment.kt | 2 - .../net/helcel/beendroid/countries/Country.kt | 1 - .../net/helcel/beendroid/countries/State.kt | 2 +- .../net/helcel/beendroid/countries/Visited.kt | 40 -------------- .../java/net/helcel/beendroid/helper/Data.kt | 4 +- .../net/helcel/beendroid/helper/Groups.kt | 55 +++++++++++++++++++ .../java/net/helcel/beendroid/helper/Theme.kt | 23 +++++--- .../net/helcel/beendroid/helper/Visited.kt | 52 ++++++++++++++++++ .../net/helcel/beendroid/svg/CSSWrapper.kt | 20 ++++--- .../java/net/helcel/beendroid/svg/Level.kt | 3 +- .../net/helcel/beendroid/svg/PSVGWrapper.kt | 11 ++-- app/src/main/res/anim/slide.xml | 8 --- .../drawable-v24/ic_launcher_foreground.xml | 3 +- app/src/main/res/drawable/chevron.xml | 9 --- app/src/main/res/layout/activity_edit.xml | 37 +++++++++---- app/src/main/res/layout/fragment_about.xml | 4 +- .../main/res/layout/fragment_edit_groups.xml | 27 +++++++++ .../res/layout/fragment_edit_groups_add.xml | 22 ++++++++ .../main/res/layout/fragment_edit_places.xml | 25 +++++++++ app/src/main/res/layout/fragment_license.xml | 5 +- .../{item_list.xml => item_list_geoloc.xml} | 3 +- app/src/main/res/layout/item_list_group.xml | 27 +++++++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 1 + app/src/main/res/values/en.xml | 6 +- app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/themes.xml | 3 +- .../java/net/helcel/beendroid/CountryTest.kt | 18 +++--- 37 files changed, 549 insertions(+), 187 deletions(-) rename app/src/main/java/net/helcel/beendroid/activity/{FoldingListAdapter.kt => adapter/GeolocListAdapter.kt} (65%) create mode 100644 app/src/main/java/net/helcel/beendroid/activity/adapter/GroupListAdapter.kt create mode 100644 app/src/main/java/net/helcel/beendroid/activity/adapter/ViewPagerAdapter.kt create mode 100644 app/src/main/java/net/helcel/beendroid/activity/fragment/EditGroupAddFragment.kt create mode 100644 app/src/main/java/net/helcel/beendroid/activity/fragment/EditGroupFragment.kt create mode 100644 app/src/main/java/net/helcel/beendroid/activity/fragment/EditPlaceFragment.kt delete mode 100644 app/src/main/java/net/helcel/beendroid/countries/Visited.kt create mode 100644 app/src/main/java/net/helcel/beendroid/helper/Groups.kt create mode 100644 app/src/main/java/net/helcel/beendroid/helper/Visited.kt delete mode 100644 app/src/main/res/anim/slide.xml delete mode 100644 app/src/main/res/drawable/chevron.xml create mode 100644 app/src/main/res/layout/fragment_edit_groups.xml create mode 100644 app/src/main/res/layout/fragment_edit_groups_add.xml create mode 100644 app/src/main/res/layout/fragment_edit_places.xml rename app/src/main/res/layout/{item_list.xml => item_list_geoloc.xml} (97%) create mode 100644 app/src/main/res/layout/item_list_group.xml create mode 100644 app/src/main/res/values/strings.xml diff --git a/app/build.gradle b/app/build.gradle index c2d66b2..dae90a3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -52,7 +52,7 @@ dependencies { implementation 'com.caverock:androidsvg-aar:1.4' implementation 'com.github.chrisbanes:PhotoView:2.3.0' - implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' + implementation "com.github.AppDevNext:AndroidChart:3.1.0.20" implementation 'com.mikepenz:aboutlibraries:10.10.0' } \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/activity/EditActivity.kt b/app/src/main/java/net/helcel/beendroid/activity/EditActivity.kt index bc2b996..6340d2a 100644 --- a/app/src/main/java/net/helcel/beendroid/activity/EditActivity.kt +++ b/app/src/main/java/net/helcel/beendroid/activity/EditActivity.kt @@ -3,17 +3,18 @@ package net.helcel.beendroid.activity import android.os.Bundle import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout +import com.google.android.material.tabs.TabLayoutMediator import net.helcel.beendroid.R -import net.helcel.beendroid.countries.World +import net.helcel.beendroid.activity.adapter.ViewPagerAdapter import net.helcel.beendroid.helper.createActionBar -import net.helcel.beendroid.helper.visited class EditActivity : AppCompatActivity() { - private lateinit var list : RecyclerView + private lateinit var viewPager : ViewPager2 + private lateinit var tabLayout: TabLayout override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -21,13 +22,19 @@ class EditActivity : AppCompatActivity() { setContentView(R.layout.activity_edit) createActionBar(this, getString(R.string.action_edit)) - list = findViewById(R.id.list) - list.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) - list.adapter = FoldingListAdapter(this, World.WWW.children, visited!!) + + viewPager = findViewById(R.id.pager) + tabLayout = findViewById(R.id.tab) + + val adapter = ViewPagerAdapter(supportFragmentManager, lifecycle) + viewPager.adapter = adapter + + TabLayoutMediator(tabLayout, viewPager) { tab, position -> + tab.text = adapter.getTabs()[position] + }.attach() } override fun onOptionsItemSelected(item: MenuItem): Boolean { - // Configure on back pressed finish() return super.onOptionsItemSelected(item) } diff --git a/app/src/main/java/net/helcel/beendroid/activity/MainActivity.kt b/app/src/main/java/net/helcel/beendroid/activity/MainActivity.kt index 3e07e32..5362760 100644 --- a/app/src/main/java/net/helcel/beendroid/activity/MainActivity.kt +++ b/app/src/main/java/net/helcel/beendroid/activity/MainActivity.kt @@ -4,7 +4,6 @@ import android.content.Intent import android.content.SharedPreferences import android.graphics.drawable.PictureDrawable import android.os.Bundle -import android.util.Log import android.view.Menu import android.view.MenuInflater import android.view.MenuItem @@ -18,7 +17,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import net.helcel.beendroid.R import net.helcel.beendroid.activity.fragment.SettingsFragment -import net.helcel.beendroid.countries.Visited +import net.helcel.beendroid.helper.Visited import net.helcel.beendroid.svg.CSSWrapper import net.helcel.beendroid.svg.PSVGWrapper @@ -43,7 +42,7 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) // Create action bar - supportActionBar?.setBackgroundDrawable(colorPrimary(this)) + supportActionBar?.setBackgroundDrawable(colorWrapper(this, android.R.attr.colorPrimary)) // Fetch shared preferences to restore app theme upon startup sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) @@ -79,11 +78,11 @@ class MainActivity : AppCompatActivity() { // Restore visited countries visited = Visited(this).load() - + groups = Groups(this).load() // Wrap lists of countries psvg = PSVGWrapper(this) - css = CSSWrapper(visited!!) + css = CSSWrapper(this,visited!!) // Populate map from list of countries setContentView(R.layout.activity_main) diff --git a/app/src/main/java/net/helcel/beendroid/activity/StatActivity.kt b/app/src/main/java/net/helcel/beendroid/activity/StatActivity.kt index 582a269..52e4574 100644 --- a/app/src/main/java/net/helcel/beendroid/activity/StatActivity.kt +++ b/app/src/main/java/net/helcel/beendroid/activity/StatActivity.kt @@ -5,9 +5,7 @@ import android.os.Bundle import android.util.Log import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity -import com.github.mikephil.charting.animation.Easing import com.github.mikephil.charting.charts.PieChart -import com.github.mikephil.charting.components.Legend import com.github.mikephil.charting.data.PieData import com.github.mikephil.charting.data.PieDataSet import com.github.mikephil.charting.data.PieEntry @@ -16,6 +14,7 @@ import com.github.mikephil.charting.utils.ColorTemplate import com.github.mikephil.charting.utils.MPPointF import net.helcel.beendroid.R import net.helcel.beendroid.countries.World +import net.helcel.beendroid.helper.colorWrapper import net.helcel.beendroid.helper.createActionBar import net.helcel.beendroid.helper.visited @@ -36,36 +35,21 @@ class StatActivity : AppCompatActivity() { chart.description.isEnabled = false chart.setExtraOffsets(5F, 10F, 5F, 5F) - chart.setDragDecelerationFrictionCoef(0.95f) - chart.centerText = "Country Area" + chart.setDrawCenterText(true) chart.isDrawHoleEnabled = true chart.setTransparentCircleColor(Color.TRANSPARENT) chart.setHoleColor(Color.TRANSPARENT) - chart.setCenterTextColor(Color.WHITE) + chart.setCenterTextColor(colorWrapper(this,android.R.attr.colorForeground).color) chart.setTransparentCircleAlpha(0) chart.holeRadius = 40F - chart.transparentCircleRadius = 45F - chart.setDrawCenterText(true) - chart.setRotationAngle(0F) - chart.isRotationEnabled = true + chart.transparentCircleRadius = 40F + chart.rotationAngle = 0F + chart.isRotationEnabled = false chart.isHighlightPerTapEnabled = false - - - // chart.spin(2000, 0, 360); - val l: Legend = chart.legend - l.verticalAlignment = Legend.LegendVerticalAlignment.TOP - l.horizontalAlignment = Legend.LegendHorizontalAlignment.RIGHT - l.orientation = Legend.LegendOrientation.VERTICAL - l.setDrawInside(false) - l.xEntrySpace = 7F - l.yEntrySpace = 0F - l.yOffset = 0F - - chart.setEntryLabelColor(Color.WHITE) - chart.setEntryLabelTextSize(12f) + chart.legend.isEnabled = false bind() } @@ -82,7 +66,7 @@ class StatActivity : AppCompatActivity() { val VIS_country = World.WWW.children.map { it.children }.flatten().groupBy { visited!!.getVisited(it) }.map { Pair(it.key,it.value.map { c-> c.area }.fold(0){acc,i-> acc+i}) } val vis = VIS_country Log.d("VIS",vis.toString()) - val max = vis.fold(0,) {acc, i -> acc+i.second} + val max = vis.fold(0) {acc, i -> acc+i.second} vis.forEach { entries.add(PieEntry(it.second.toFloat().div(max.toFloat()),it.first.toString())) } diff --git a/app/src/main/java/net/helcel/beendroid/activity/FoldingListAdapter.kt b/app/src/main/java/net/helcel/beendroid/activity/adapter/GeolocListAdapter.kt similarity index 65% rename from app/src/main/java/net/helcel/beendroid/activity/FoldingListAdapter.kt rename to app/src/main/java/net/helcel/beendroid/activity/adapter/GeolocListAdapter.kt index 45878ef..18f1fec 100644 --- a/app/src/main/java/net/helcel/beendroid/activity/FoldingListAdapter.kt +++ b/app/src/main/java/net/helcel/beendroid/activity/adapter/GeolocListAdapter.kt @@ -1,4 +1,4 @@ -package net.helcel.beendroid.activity +package net.helcel.beendroid.activity.adapter import android.content.Context import android.graphics.Typeface @@ -11,16 +11,13 @@ import androidx.recyclerview.widget.RecyclerView import com.google.android.material.checkbox.MaterialCheckBox import net.helcel.beendroid.R import net.helcel.beendroid.countries.GeoLoc -import net.helcel.beendroid.countries.Visited -import net.helcel.beendroid.helper.colorBackground -import net.helcel.beendroid.helper.colorPanelBackground +import net.helcel.beendroid.helper.colorWrapper +import net.helcel.beendroid.helper.visited import java.util.* -class FoldingListAdapter( - private val ctx: Context, l: List, - private val visited: Visited, - ) : RecyclerView.Adapter() { +class GeolocListAdapter( + private val ctx: Context, l: List) : RecyclerView.Adapter() { private val cg : MutableMap = l.sortedBy { it.fullName }.fold(LinkedHashMap()) { acc, e -> acc[e] = false @@ -30,8 +27,8 @@ class FoldingListAdapter( override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): FoldingListViewHolder { val view: View = LayoutInflater .from(viewGroup.context) - .inflate(R.layout.item_list, viewGroup, false) - return FoldingListViewHolder(ctx, view, visited) + .inflate(R.layout.item_list_geoloc, viewGroup, false) + return FoldingListViewHolder(ctx, view) } override fun onBindViewHolder(holder: FoldingListViewHolder, position: Int) { @@ -45,7 +42,7 @@ class FoldingListAdapter( } !el.first.isEnd }, { - visited.setVisited(el.first, it) + visited!!.setVisited(el.first, it) }) } @@ -53,18 +50,15 @@ class FoldingListAdapter( return cg.size } - class FoldingListViewHolder(private val ctx: Context, itemView: View, - private val visited: Visited, - ) : RecyclerView.ViewHolder(itemView) { + class FoldingListViewHolder(private val ctx: Context, itemView: View) : RecyclerView.ViewHolder(itemView) { private val textView: TextView = itemView.findViewById(R.id.textView) - private val progressView: TextView = itemView.findViewById(R.id.progressView) + private val progressView: TextView = itemView.findViewById(R.id.name) private val checkBox: MaterialCheckBox = itemView.findViewById(R.id.checkBox) private val subItemView: View = itemView.findViewById(R.id.sub_item) private val list: RecyclerView = itemView.findViewById(R.id.list_list) init { list.layoutManager = LinearLayoutManager(ctx, RecyclerView.VERTICAL, false) - list.setItemAnimator(null) //TODO: Fix slow recycler expansion - //list.setHasFixedSize(true) + list.itemAnimator = null //TODO: Fix slow recycler expansion } fun bind(el: Pair) { @@ -74,29 +68,28 @@ class FoldingListAdapter( if (el.first.children.isEmpty()) { textView.backgroundTintList = null - textView.background = colorBackground(ctx) + textView.background = colorWrapper(ctx, android.R.attr.colorBackground) textView.isActivated = false }else { textView.setTypeface(null, Typeface.BOLD) - progressView.text = ctx.getString(R.string.rate,(el.first.children.map { visited.getVisited(it) }.count { it }),el.first.children.size) + progressView.text = ctx.getString(R.string.rate,(el.first.children.map { visited!!.getVisited(it)>0 }.count { it }),el.first.children.size) - textView.background = colorPanelBackground(ctx) + textView.background = colorWrapper(ctx, android.R.attr.panelColorBackground) textView.background.alpha = 128 - list.adapter = FoldingListAdapter(ctx, el.first.children, visited) + list.adapter = GeolocListAdapter(ctx, el.first.children) textView.parent.parent.requestChildFocus(textView, textView) } checkBox.checkedState = - if (visited.getVisited(el.first)) MaterialCheckBox.STATE_CHECKED - else if (el.first.children.any { visited.getVisited(it) }) MaterialCheckBox.STATE_INDETERMINATE + if (visited!!.getVisited(el.first)>0) MaterialCheckBox.STATE_CHECKED + else if (el.first.children.any { visited!!.getVisited(it)>0 }) MaterialCheckBox.STATE_INDETERMINATE else MaterialCheckBox.STATE_UNCHECKED - } - fun addListeners(expandLambda: ()->Boolean, visitedLambda: (Boolean)->Unit) { + fun addListeners(expandLambda: ()->Boolean, visitedLambda: (Int)->Unit) { textView.setOnClickListener { expandLambda() } checkBox.addOnCheckedStateChangedListener { _, e -> - visitedLambda(e == MaterialCheckBox.STATE_CHECKED) + visitedLambda( if(e == MaterialCheckBox.STATE_CHECKED) 1 else 0) } } diff --git a/app/src/main/java/net/helcel/beendroid/activity/adapter/GroupListAdapter.kt b/app/src/main/java/net/helcel/beendroid/activity/adapter/GroupListAdapter.kt new file mode 100644 index 0000000..6038a59 --- /dev/null +++ b/app/src/main/java/net/helcel/beendroid/activity/adapter/GroupListAdapter.kt @@ -0,0 +1,48 @@ +package net.helcel.beendroid.activity.adapter + +import android.graphics.drawable.ColorDrawable +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import androidx.fragment.app.FragmentActivity +import androidx.recyclerview.widget.RecyclerView +import net.helcel.beendroid.R +import net.helcel.beendroid.activity.fragment.EditGroupAddFragment +import net.helcel.beendroid.helper.getContrastColor +import net.helcel.beendroid.helper.groups + +class GroupListAdapter(val activity: FragmentActivity) : RecyclerView.Adapter() { + + 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) + } + + override fun onBindViewHolder(holder: GroupViewHolder, pos: Int) { + holder.bind(groups!!.getGroupFromPos(pos)) + } + + override fun getItemCount(): Int { + return groups!!.size() + } + + class GroupViewHolder(itemView: View, val activity: FragmentActivity) : RecyclerView.ViewHolder(itemView) { + private val color: Button = itemView.findViewById(R.id.group_color) + + fun bind(entry: Pair>) { + color.text = entry.second.first + color.setBackgroundColor(entry.second.second.color) + color.setTextColor(getContrastColor(entry.second.second.color)) + color.setOnClickListener { + val dialogFragment = EditGroupAddFragment(entry.first) { + val newEntry = groups!!.getGroupFromKey(entry.first)!! + color.text = newEntry.first + color.setBackgroundColor(newEntry.second.color) + color.setTextColor(getContrastColor(newEntry.second.color)) + } + dialogFragment.show(activity.supportFragmentManager, "AddColorDialogFragment") + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/activity/adapter/ViewPagerAdapter.kt b/app/src/main/java/net/helcel/beendroid/activity/adapter/ViewPagerAdapter.kt new file mode 100644 index 0000000..b76c6a8 --- /dev/null +++ b/app/src/main/java/net/helcel/beendroid/activity/adapter/ViewPagerAdapter.kt @@ -0,0 +1,34 @@ +package net.helcel.beendroid.activity.adapter + +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Lifecycle +import androidx.viewpager2.adapter.FragmentStateAdapter +import net.helcel.beendroid.activity.fragment.EditGroupFragment +import net.helcel.beendroid.activity.fragment.EditPlaceFragment + +private val tabArray = arrayOf( + "Groups", + "Places" +) +class ViewPagerAdapter (fragmentManager: FragmentManager, lifecycle: Lifecycle) : + FragmentStateAdapter(fragmentManager, lifecycle) { + + override fun getItemCount(): Int { + return tabArray.size + } + + fun getTabs() : Array { + return tabArray + } + + override fun createFragment(position: Int): Fragment { + when (position) { + 0 -> return EditGroupFragment() + 1 -> return EditPlaceFragment() + } + return EditGroupFragment() + } +} + + diff --git a/app/src/main/java/net/helcel/beendroid/activity/fragment/EditGroupAddFragment.kt b/app/src/main/java/net/helcel/beendroid/activity/fragment/EditGroupAddFragment.kt new file mode 100644 index 0000000..b8764e4 --- /dev/null +++ b/app/src/main/java/net/helcel/beendroid/activity/fragment/EditGroupAddFragment.kt @@ -0,0 +1,49 @@ +package net.helcel.beendroid.activity.fragment + +import android.app.Dialog +import android.content.DialogInterface +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import android.os.Bundle +import android.view.View +import android.widget.EditText +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.DialogFragment +import net.helcel.beendroid.R +import net.helcel.beendroid.helper.colorToHex6 +import net.helcel.beendroid.helper.groups + + +class EditGroupAddFragment(private val key: Int =0, val onAddCb : (Int)->Unit) : DialogFragment() { + private var colorNameEditText: EditText? = null + private var colorEditText: EditText? = null + private val grp = 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) + + colorNameEditText = view.findViewById(R.id.group_name) + colorEditText = view.findViewById(R.id.group_color) + + if(grp!=null){ + view.findViewById(R.id.group_name).setText(grp.first) + view.findViewById(R.id.group_color).setText(colorToHex6(grp.second)) + } + builder.setView(view) + .setTitle("Add Color") + .setPositiveButton("Add") { _: DialogInterface?, _: Int -> + val name = colorNameEditText!!.text.toString() + val color = colorEditText!!.text.toString() + val key = (if (key!=0) key else groups!!.genKey()) + groups!!.setGroup(key,name, ColorDrawable(Color.parseColor(color))) + onAddCb(key) + } + .setNegativeButton( + "Cancel" + ) { dialog: DialogInterface, _: Int -> dialog.cancel() } + return builder.create() + } +} \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/activity/fragment/EditGroupFragment.kt b/app/src/main/java/net/helcel/beendroid/activity/fragment/EditGroupFragment.kt new file mode 100644 index 0000000..8861cb6 --- /dev/null +++ b/app/src/main/java/net/helcel/beendroid/activity/fragment/EditGroupFragment.kt @@ -0,0 +1,44 @@ +package net.helcel.beendroid.activity.fragment + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import net.helcel.beendroid.activity.adapter.GroupListAdapter +import net.helcel.beendroid.databinding.FragmentEditGroupsBinding +import net.helcel.beendroid.helper.groups + +class EditGroupFragment : Fragment() { + private var _binding: FragmentEditGroupsBinding? = null + private val binding get() = _binding!! + private lateinit var listadapt : GroupListAdapter + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = FragmentEditGroupsBinding.inflate(inflater, container, false) + + listadapt = GroupListAdapter(requireActivity()) + binding.addGroup.setOnClickListener { + val dialogFragment = EditGroupAddFragment { + listadapt.notifyItemInserted(groups!!.findGroupPos(it)) + } + dialogFragment.show(requireActivity().supportFragmentManager, "AddColorDialogFragment") + + } + + binding.list.layoutManager = LinearLayoutManager(requireContext(), RecyclerView.VERTICAL, false) + binding.list.adapter = listadapt + return binding.root + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/activity/fragment/EditPlaceFragment.kt b/app/src/main/java/net/helcel/beendroid/activity/fragment/EditPlaceFragment.kt new file mode 100644 index 0000000..e6a3eb7 --- /dev/null +++ b/app/src/main/java/net/helcel/beendroid/activity/fragment/EditPlaceFragment.kt @@ -0,0 +1,34 @@ +package net.helcel.beendroid.activity.fragment + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import net.helcel.beendroid.activity.adapter.GeolocListAdapter +import net.helcel.beendroid.countries.World +import net.helcel.beendroid.databinding.FragmentEditPlacesBinding + +class EditPlaceFragment : Fragment() { + private var _binding: FragmentEditPlacesBinding? = null + private val binding get() = _binding!! + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = FragmentEditPlacesBinding.inflate(inflater, container, false) + + binding.list.layoutManager = LinearLayoutManager(requireContext(), RecyclerView.VERTICAL, false) + binding.list.adapter = GeolocListAdapter(requireContext(), World.WWW.children) + return binding.root + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/activity/fragment/LicenseFragment.kt b/app/src/main/java/net/helcel/beendroid/activity/fragment/LicenseFragment.kt index 6043924..4d387cb 100644 --- a/app/src/main/java/net/helcel/beendroid/activity/fragment/LicenseFragment.kt +++ b/app/src/main/java/net/helcel/beendroid/activity/fragment/LicenseFragment.kt @@ -12,8 +12,6 @@ import com.mikepenz.aboutlibraries.LibsBuilder class LicenseFragment: Fragment() { private var _binding: FragmentLicenseBinding? = null - // This property is only valid between onCreateView and - // onDestroyView. private val binding get() = _binding!! override fun onCreateView( diff --git a/app/src/main/java/net/helcel/beendroid/countries/Country.kt b/app/src/main/java/net/helcel/beendroid/countries/Country.kt index dcb31be..ef24240 100644 --- a/app/src/main/java/net/helcel/beendroid/countries/Country.kt +++ b/app/src/main/java/net/helcel/beendroid/countries/Country.kt @@ -1,6 +1,5 @@ package net.helcel.beendroid.countries -import net.helcel.beendroid.countries.Country.* import net.helcel.beendroid.countries.State.* enum class Country(override val fullName: String, override val area : Int, override val children : List) : GeoLoc { diff --git a/app/src/main/java/net/helcel/beendroid/countries/State.kt b/app/src/main/java/net/helcel/beendroid/countries/State.kt index 70a2d03..02cef7e 100644 --- a/app/src/main/java/net/helcel/beendroid/countries/State.kt +++ b/app/src/main/java/net/helcel/beendroid/countries/State.kt @@ -1,6 +1,6 @@ package net.helcel.beendroid.countries -enum class State(override val fullName: String, override val area: Int,) : GeoLoc { +enum class State(override val fullName: String, override val area: Int) : GeoLoc { AFG_BD("Badakhshan", 44851), AFG_BDG("Badghis", 22447), AFG_BGL("Baghlan", 21397), diff --git a/app/src/main/java/net/helcel/beendroid/countries/Visited.kt b/app/src/main/java/net/helcel/beendroid/countries/Visited.kt deleted file mode 100644 index 50c33cd..0000000 --- a/app/src/main/java/net/helcel/beendroid/countries/Visited.kt +++ /dev/null @@ -1,40 +0,0 @@ -package net.helcel.beendroid.countries - -import android.content.Context -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch - - -class Visited(ctx: Context) { - private var locs: MutableMap = HashMap() - private val pref = ctx.getSharedPreferences("Visited", Context.MODE_PRIVATE) - private val editor = pref.edit() - - fun load(): Visited { - Group.entries.forEach { - locs[it] = pref.getBoolean(it.code, false) - } - Country.entries.forEach { - locs[it] = pref.getBoolean(it.code, false) - } - State.entries.forEach { - locs[it] = pref.getBoolean(it.code, false) - } - editor.apply() - return this - } - - fun setVisited(key: GeoLoc, b: Boolean) { - locs[key] = b - CoroutineScope(Dispatchers.Main).launch { - editor.putBoolean(key.code, b) - editor.apply() - } - } - - fun getVisited(key: GeoLoc): Boolean { - return locs.getOrDefault(key,false) - } - -} \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/helper/Data.kt b/app/src/main/java/net/helcel/beendroid/helper/Data.kt index 6c5157b..9c184cb 100644 --- a/app/src/main/java/net/helcel/beendroid/helper/Data.kt +++ b/app/src/main/java/net/helcel/beendroid/helper/Data.kt @@ -1,7 +1,5 @@ package net.helcel.beendroid.helper -import net.helcel.beendroid.countries.Visited - var visited : Visited? = null -//= Visited(this) +var groups : Groups? = null diff --git a/app/src/main/java/net/helcel/beendroid/helper/Groups.kt b/app/src/main/java/net/helcel/beendroid/helper/Groups.kt new file mode 100644 index 0000000..450b1be --- /dev/null +++ b/app/src/main/java/net/helcel/beendroid/helper/Groups.kt @@ -0,0 +1,55 @@ +package net.helcel.beendroid.helper + +import android.content.Context +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import kotlin.random.Random + + +class Groups(ctx: Context) { + private val randSeed = 0 + private val rnd = Random(randSeed) + private var grps: MutableMap> = HashMap() + private val pref = ctx.getSharedPreferences("Groups", Context.MODE_PRIVATE) + private val editor = pref.edit() + + fun load(): Groups { + pref.all.keys.filter { !it.endsWith("_color") }.forEach { + grps[it.toInt()] = Pair(pref.getString(it, "")!!, + ColorDrawable(pref.getInt(it+"_color", Color.WHITE))) + } + editor.apply() + return this + } + + fun setGroup(key: Int, name: String, col: ColorDrawable) { + grps[key] = Pair(name,col) + editor.putString(key.toString(), name) + editor.putInt(key.toString()+"_color", col.color) + editor.apply() + } + + fun getGroupFromKey(key: Int): Pair? { + return grps.getOrDefault(key,null) + } + + fun genKey(): Int { + val key = rnd.nextInt() + if(grps.containsKey(key) || key == 0) return genKey() + return key + } + + fun size(): Int { + return grps.size + } + + fun getGroupFromPos(pos: Int): Pair> { + val key = grps.keys.toList()[pos] + return Pair(key,getGroupFromKey(key)!!) + } + + fun findGroupPos(key: Int): Int { + return grps.keys.toList().indexOf(key) + } + +} \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/helper/Theme.kt b/app/src/main/java/net/helcel/beendroid/helper/Theme.kt index 02486ce..e8a78ae 100644 --- a/app/src/main/java/net/helcel/beendroid/helper/Theme.kt +++ b/app/src/main/java/net/helcel/beendroid/helper/Theme.kt @@ -1,9 +1,11 @@ package net.helcel.beendroid.helper import android.content.Context +import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.util.TypedValue import androidx.appcompat.app.AppCompatActivity +import androidx.core.graphics.ColorUtils fun colorWrapper(ctx : Context, res: Int): ColorDrawable { val colorPrimaryTyped = TypedValue() @@ -11,20 +13,23 @@ fun colorWrapper(ctx : Context, res: Int): ColorDrawable { return ColorDrawable(colorPrimaryTyped.data) } -fun colorPrimary(ctx : Context): ColorDrawable { - return colorWrapper(ctx, android.R.attr.colorPrimary) +fun colorToHex6(c: ColorDrawable): String { + return '#'+colorToHex8(c).substring(3) } -fun colorBackground(ctx : Context): ColorDrawable { - return colorWrapper(ctx, android.R.attr.colorBackground) -} - -fun colorPanelBackground(ctx: Context): ColorDrawable { - return colorWrapper(ctx, android.R.attr.panelColorBackground) +@OptIn(ExperimentalStdlibApi::class) +fun colorToHex8(c: ColorDrawable): String { + return '#'+c.color.toHexString() } fun createActionBar(ctx: AppCompatActivity, title: String) { - ctx.supportActionBar?.setBackgroundDrawable(colorPrimary(ctx)) + ctx.supportActionBar?.setBackgroundDrawable(colorWrapper(ctx, android.R.attr.colorPrimary)) ctx.supportActionBar?.title = title ctx.supportActionBar?.setDisplayHomeAsUpEnabled(true) +} + +fun getContrastColor(color: Int): Int { + val whiteContrast = ColorUtils.calculateContrast(Color.WHITE, color) + val blackContrast = ColorUtils.calculateContrast(Color.BLACK, color) + return if (whiteContrast > blackContrast) Color.WHITE else Color.BLACK } \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/helper/Visited.kt b/app/src/main/java/net/helcel/beendroid/helper/Visited.kt new file mode 100644 index 0000000..d1c62df --- /dev/null +++ b/app/src/main/java/net/helcel/beendroid/helper/Visited.kt @@ -0,0 +1,52 @@ +package net.helcel.beendroid.helper + +import android.content.Context +import net.helcel.beendroid.countries.Country +import net.helcel.beendroid.countries.GeoLoc +import net.helcel.beendroid.countries.Group +import net.helcel.beendroid.countries.State +import java.lang.ClassCastException + + +class Visited(ctx: Context) { + private var locs: MutableMap = HashMap() + private val pref = ctx.getSharedPreferences("Visited", Context.MODE_PRIVATE) + private val editor = pref.edit() + + fun load(): Visited { + Group.entries.forEach { + try { + locs[it] = pref.getInt(it.code, 0) + }catch (e:ClassCastException){ + locs[it] = if (pref.getBoolean(it.code, false)) 1 else 0 + } + } + Country.entries.forEach { + try { + locs[it] = pref.getInt(it.code, 0) + }catch (e:ClassCastException){ + locs[it] = if (pref.getBoolean(it.code, false)) 1 else 0 + } + } + State.entries.forEach { + try { + locs[it] = pref.getInt(it.code, 0) + }catch (e:ClassCastException){ + locs[it] = if (pref.getBoolean(it.code, false)) 1 else 0 + } + } + editor.apply() + return this + } + + fun setVisited(key: GeoLoc, b: Int) { + locs[key] = b + editor.putInt(key.code, b) + editor.apply() + } + + fun getVisited(key: GeoLoc): Int { + return locs.getOrDefault(key,0) + } + +} \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/svg/CSSWrapper.kt b/app/src/main/java/net/helcel/beendroid/svg/CSSWrapper.kt index 33e96a8..b64cf9f 100644 --- a/app/src/main/java/net/helcel/beendroid/svg/CSSWrapper.kt +++ b/app/src/main/java/net/helcel/beendroid/svg/CSSWrapper.kt @@ -1,22 +1,26 @@ package net.helcel.beendroid.svg -import net.helcel.beendroid.countries.Visited +import android.content.Context +import net.helcel.beendroid.helper.Visited import net.helcel.beendroid.countries.World +import net.helcel.beendroid.helper.colorToHex6 +import net.helcel.beendroid.helper.colorWrapper -class CSSWrapper(private val visited: Visited) { +class CSSWrapper(ctx: Context, private val visited: Visited) { - private val colorPrimary = "#0187FF" + + private val visitedColor = colorToHex6(colorWrapper(ctx,android.R.attr.colorPrimary)) fun get() : String { return listOf(World.WWW.children - .filter { visited.getVisited(it)} - .map { ".${it.code}{fill:$colorPrimary;}"} + .filter { visited.getVisited(it)>0} + .map { ".${it.code}{fill:$visitedColor;}"} .fold(""){acc, s-> acc + s}, World.WWW.children - .filter { !visited.getVisited(it) } + .filter { visited.getVisited(it)==0 } .map { cg -> cg.children - .filter { visited.getVisited(it) } - .map { ".${it.code}{fill:$colorPrimary;}"} + .filter { visited.getVisited(it)>0 } + .map { ".${it.code}{fill:$visitedColor;}"} .fold(""){acc, s-> acc + s} }.fold(""){acc,s->acc+s}, ).fold(""){acc,s-> acc+s} diff --git a/app/src/main/java/net/helcel/beendroid/svg/Level.kt b/app/src/main/java/net/helcel/beendroid/svg/Level.kt index 3080e52..73a4283 100644 --- a/app/src/main/java/net/helcel/beendroid/svg/Level.kt +++ b/app/src/main/java/net/helcel/beendroid/svg/Level.kt @@ -1,7 +1,6 @@ package net.helcel.beendroid.svg -enum class Level(id: Int) { +enum class Level(val id: Int) { ZERO(0), ONE(1); - val id = id } \ No newline at end of file diff --git a/app/src/main/java/net/helcel/beendroid/svg/PSVGWrapper.kt b/app/src/main/java/net/helcel/beendroid/svg/PSVGWrapper.kt index 655fc02..be614c5 100644 --- a/app/src/main/java/net/helcel/beendroid/svg/PSVGWrapper.kt +++ b/app/src/main/java/net/helcel/beendroid/svg/PSVGWrapper.kt @@ -1,22 +1,20 @@ package net.helcel.beendroid.svg import android.content.Context -import android.util.Log import com.caverock.androidsvg.SVG -import net.helcel.beendroid.R import net.helcel.beendroid.countries.Country import net.helcel.beendroid.countries.GeoLoc import net.helcel.beendroid.countries.World +import net.helcel.beendroid.helper.colorToHex6 import net.helcel.beendroid.helper.colorWrapper -@OptIn(ExperimentalStdlibApi::class) class PSVGWrapper(ctx: Context) { private val cm = HashMap() private var fm = "" - private val colorForeground: String = colorWrapper(ctx, android.R.attr.panelColorBackground).color.toHexString().substring(2) - private val colorBackground: String = colorWrapper(ctx, android.R.attr.colorBackground).color.toHexString().substring(2) + private val colorForeground: String = colorToHex6(colorWrapper(ctx, android.R.attr.panelColorBackground)) + private val colorBackground: String = colorToHex6(colorWrapper(ctx, android.R.attr.colorBackground)) init { Country.entries.forEach { @@ -24,6 +22,7 @@ class PSVGWrapper(ctx: Context) { } build() } + fun level(el: Country, level: Level){ cm[el]?.changeLevel(level) } @@ -39,7 +38,7 @@ class PSVGWrapper(ctx: Context) { } fun get(): SVG { - return SVG.getFromString("$fm") + return SVG.getFromString("$fm") } } \ No newline at end of file diff --git a/app/src/main/res/anim/slide.xml b/app/src/main/res/anim/slide.xml deleted file mode 100644 index b4c3a07..0000000 --- a/app/src/main/res/anim/slide.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml index 8949830..d3144e3 100644 --- a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -1,9 +1,8 @@ + android:viewportHeight="1600"> - - diff --git a/app/src/main/res/layout/activity_edit.xml b/app/src/main/res/layout/activity_edit.xml index e1560d5..5d119f0 100644 --- a/app/src/main/res/layout/activity_edit.xml +++ b/app/src/main/res/layout/activity_edit.xml @@ -4,19 +4,32 @@ android:theme="@style/Theme.Beendroid" android:layout_width="match_parent" android:layout_height="match_parent"> - - + android:layout_height="wrap_content"/> + + + + + + + + + + + + + + + + + + - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml index 6445708..0d2da90 100644 --- a/app/src/main/res/layout/fragment_about.xml +++ b/app/src/main/res/layout/fragment_about.xml @@ -1,10 +1,9 @@ + tools:context=".activity.fragment.AboutFragment"> + + + + +