Added MultiColor, cleanup,...

This commit is contained in:
soraefir 2024-02-12 12:18:24 +01:00
parent 1638876f49
commit 3f7183d056
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
37 changed files with 549 additions and 187 deletions

View File

@ -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'
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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()))
}

View File

@ -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<GeoLoc>,
private val visited: Visited,
) : RecyclerView.Adapter<FoldingListAdapter.FoldingListViewHolder>() {
class GeolocListAdapter(
private val ctx: Context, l: List<GeoLoc>) : RecyclerView.Adapter<GeolocListAdapter.FoldingListViewHolder>() {
private val cg : MutableMap<GeoLoc,Boolean> = l.sortedBy { it.fullName }.fold(LinkedHashMap<GeoLoc,Boolean>()) { 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<GeoLoc, Boolean>) {
@ -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)
}
}

View File

@ -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<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)
}
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<Int, Pair<String, ColorDrawable>>) {
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")
}
}
}
}

View File

@ -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<String> {
return tabArray
}
override fun createFragment(position: Int): Fragment {
when (position) {
0 -> return EditGroupFragment()
1 -> return EditPlaceFragment()
}
return EditGroupFragment()
}
}

View File

@ -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<EditText>(R.id.group_name).setText(grp.first)
view.findViewById<EditText>(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()
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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(

View File

@ -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>) : GeoLoc {

View File

@ -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),

View File

@ -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<GeoLoc, Boolean> = 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)
}
}

View File

@ -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

View File

@ -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<Int,Pair<String, ColorDrawable>> = 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<String,ColorDrawable>? {
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<Int,Pair<String,ColorDrawable>> {
val key = grps.keys.toList()[pos]
return Pair(key,getGroupFromKey(key)!!)
}
fun findGroupPos(key: Int): Int {
return grps.keys.toList().indexOf(key)
}
}

View File

@ -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
}

View File

@ -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<GeoLoc, Int> = 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)
}
}

View File

@ -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}

View File

@ -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
}

View File

@ -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<GeoLoc, PSVGLoader>()
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("<svg id=\"map\" xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"1200\" x=\"0\" y=\"0\" fill=\"#$colorForeground\" stroke=\"#$colorBackground\" stroke-width=\"0.25px\">$fm</svg>")
return SVG.getFromString("<svg id=\"map\" xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"1200\" x=\"0\" y=\"0\" fill=\"$colorForeground\" stroke=\"$colorBackground\" stroke-width=\"0.25px\">$fm</svg>")
}
}

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromYDelta="0"
android:toYDelta="100%" />
</set>

View File

@ -1,9 +1,8 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="12dp"
android:height="12dp"
android:viewportWidth="1600"
android:viewportHeight="1600" >
android:viewportHeight="1600">
<path
android:fillColor="?attr/colorPrimary"

View File

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="320dp"
android:height="512dp"
android:viewportWidth="320"
android:viewportHeight="512">
<path
android:fillColor="?attr/colorOnBackground"
android:pathData="M310.6,233.4c12.5,12.5 12.5,32.8 0,45.3l-192,192c-12.5,12.5 -32.8,12.5 -45.3,0s-12.5,-32.8 0,-45.3L242.7,256 73.4,86.6c-12.5,-12.5 -12.5,-32.8 0,-45.3s32.8,-12.5 45.3,0l192,192z"/>
</vector>

View File

@ -4,19 +4,32 @@
android:theme="@style/Theme.Beendroid"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:id="@+id/sv"
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
android:layout_height="wrap_content"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<!-- <androidx.core.widget.NestedScrollView-->
<!-- android:id="@+id/sv"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:scrollbars="vertical">-->
<!-- <androidx.recyclerview.widget.RecyclerView-->
<!-- android:id="@+id/list"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:nestedScrollingEnabled="false"-->
<!-- android:scrollbars="vertical" />-->
<!-- </androidx.core.widget.NestedScrollView>-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:scrollbars="vertical" />
</androidx.core.widget.NestedScrollView>
</LinearLayout>

View File

@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.fragment.AboutFragment" >
tools:context=".activity.fragment.AboutFragment">
<LinearLayout
android:layout_width="match_parent"
@ -17,6 +16,7 @@
android:layout_height="250dp"
android:layout_marginTop="40dp"
android:layout_marginBottom="30dp"
android:contentDescription="@string/logo"
android:src="@mipmap/ic_launcher_round" />
<TextView

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/add_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:layout_weight="1"
android:text="@string/group_add"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/group_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name"
android:inputType="text" />
<EditText
android:id="@+id/group_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/color_rrggbb"
android:inputType="text" />
</LinearLayout>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:id="@+id/sv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:scrollbars="vertical" />
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.fragment.LicenseFragment" >
tools:context=".activity.fragment.LicenseFragment">
<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/license_fragment_view"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -30,7 +29,7 @@
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/progressView"
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="50dp"
app:layout_constraintBottom_toBottomOf="@id/checkBox"

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/group_color"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>

View File

@ -2,4 +2,5 @@
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View File

@ -13,9 +13,13 @@
<string name="dark">Dark</string>
<string name="licenses">Licenses</string>
<string name="about">About</string>
<string name="rate">%1$d/%2$d</string>
<string name="beendroid_is_foss">BeenDroid is free and open source software, licensed under the GNU General Public License (version 3 or later)</string>
<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="group_add">Add</string>
<string name="logo">Logo</string>
<string name="name">Name</string>
<string name="rate">%1$d/%2$d</string>
<string name="color_rrggbb">Color (#RRGGBB)</string>
</resources>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>

View File

@ -1,4 +1,4 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<style name="Theme.Beendroid" parent="Theme.Material3.DayNight">
<item name="colorPrimary">@color/blue</item>
<item name="background">@color/darkgray</item>
@ -11,5 +11,4 @@
<style name="Widget.App.CheckBox" parent="Widget.Material3.CompoundButton.CheckBox">
</style>
</resources>

View File

@ -32,8 +32,8 @@ class CountryTest {
@Test
fun allCountriesInAGroup() {
Country.values().forEach { c ->
val cnt = Group.values().none {
Country.entries.forEach { c ->
val cnt = Group.entries.none {
it.children.contains((c))
}
Assert.assertEquals("$c has no group !",cnt,false)
@ -42,7 +42,7 @@ class CountryTest {
@Test
fun allCountriesInASingleGroup() {
Country.values().forEach { c ->
Country.entries.forEach { c ->
val cnt = listOf(EEE,FFF,ABB,NNN,SRR,UUU,XXX,ZZZ).count {
it.children.contains((c))
}
@ -53,7 +53,7 @@ class CountryTest {
@Test
fun allCountriesFoundInEnum() {
codes.forEach {co ->
val r = Country.values().map { it.code }.contains(co)
val r = Country.entries.map { it.code }.contains(co)
Assert.assertEquals("$co not found in enum", r, true)
}
}
@ -61,7 +61,7 @@ class CountryTest {
@Test
fun allCountriesFoundInImport() {
Country.values().forEach {
Country.entries.forEach {
if(codesIgnore.contains(it.code))
return@forEach
val r = codes.contains(it.code)
@ -71,28 +71,28 @@ class CountryTest {
@Test
fun allCountriesValidName() {
Country.values().forEach {
Country.entries.forEach {
Assert.assertEquals("$it has no full_name", it.fullName.isNotEmpty(), true)
}
}
@Test
fun allCountriesValidArea() {
Country.values().forEach {
Country.entries.forEach {
Assert.assertEquals("$it has an area of 0", it.area > 0, true)
}
}
@Test
fun allCountryGroupsValidName() {
Group.values().forEach {
Group.entries.forEach {
Assert.assertEquals("$it has no full_name", it.fullName.isNotEmpty(), true)
}
}
@Test
fun allCountryGroupsValidArea() {
Group.values().forEach {
Group.entries.forEach {
Assert.assertEquals("$it has an area of 0", it.area >= 0, true)
}
}