Compare commits

...

2 Commits

Author SHA1 Message Date
fgerber
968f4206cc Add counter for group view 2024-03-07 12:37:17 +01:00
fgerber
71a33c4db7 Enable percentage stats if desired 2024-03-07 12:13:52 +01:00
9 changed files with 89 additions and 13 deletions

View File

@ -8,6 +8,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.checkbox.MaterialCheckBox import com.google.android.material.checkbox.MaterialCheckBox
@ -63,6 +64,9 @@ class GeolocListAdapter(
list.itemAnimator = null //TODO: Fix slow recycler expansion list.itemAnimator = null //TODO: Fix slow recycler expansion
} }
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx)
val statsPref = sharedPreferences.getString(ctx.getString(R.string.key_stats), ctx.getString(R.string.counters))
fun bind(el: Pair<GeoLoc, Boolean>) { fun bind(el: Pair<GeoLoc, Boolean>) {
subItemView.visibility = if (el.second) View.VISIBLE else View.GONE subItemView.visibility = if (el.second) View.VISIBLE else View.GONE
@ -71,7 +75,15 @@ class GeolocListAdapter(
textView.backgroundTintList = ColorStateList.valueOf(colorWrapper(ctx, android.R.attr.colorBackground).color) textView.backgroundTintList = ColorStateList.valueOf(colorWrapper(ctx, android.R.attr.colorBackground).color)
} else { } else {
textView.setTypeface(null, Typeface.BOLD) textView.setTypeface(null, Typeface.BOLD)
progressView.text = ctx.getString(R.string.rate,(el.first.children.map { visits!!.getVisited(it) != 0 }.count { it }), el.first.children.size)
val numerator = el.first.children.map { visits!!.getVisited(it) != 0 }.count { it }
val denominator = el.first.children.size
println(100 * (numerator / denominator.toFloat()).toInt())
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.backgroundTintList = ColorStateList.valueOf(colorWrapper(ctx, android.R.attr.panelColorBackground).color).withAlpha(128)

View File

@ -4,6 +4,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button import android.widget.Button
import android.widget.TextView
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -34,18 +35,28 @@ class GroupListAdapter(private val activity: FragmentActivity, private val selec
inner class GroupViewHolder(itemView: View, private val activity: FragmentActivity, private val selectDialog: DialogFragment?) : RecyclerView.ViewHolder(itemView) { inner class GroupViewHolder(itemView: View, private val activity: FragmentActivity, private val selectDialog: DialogFragment?) : RecyclerView.ViewHolder(itemView) {
private val color: Button = itemView.findViewById(R.id.group_color) private val color: Button = itemView.findViewById(R.id.group_color)
private val entries: TextView = itemView.findViewById(R.id.name)
fun bind(entry: Pair<Int, Groups.Group>) { fun bind(entry: Pair<Int, Groups.Group>) {
color.text = entry.second.name color.text = entry.second.name
color.setBackgroundColor(entry.second.color.color) val entryColor = entry.second.color.color
color.setTextColor(getContrastColor(entry.second.color.color)) val contrastEntryColor = getContrastColor(entryColor)
color.setBackgroundColor(entryColor)
color.setTextColor(contrastEntryColor)
entries.setTextColor(contrastEntryColor)
entries.text = visits!!.countVisited(entry.first).toString()
color.setOnClickListener { color.setOnClickListener {
if (selectDialog == null) { if (selectDialog == null) {
val dialogFragment = EditGroupAddFragment(entry.first) { val dialogFragment = EditGroupAddFragment(entry.first) {
val newEntry = groups!!.getGroupFromKey(entry.first)!! val newEntry = groups!!.getGroupFromKey(entry.first)!!
color.text = newEntry.name color.text = newEntry.name
color.setBackgroundColor(newEntry.color.color) val newEntryColor = newEntry.color.color
color.setTextColor(getContrastColor(newEntry.color.color)) val contrastNewEntryColor = getContrastColor(newEntryColor)
color.setBackgroundColor(newEntryColor)
color.setTextColor(contrastNewEntryColor)
entries.setTextColor(contrastNewEntryColor)
entries.text = "0"
} }
dialogFragment.show( dialogFragment.show(
activity.supportFragmentManager, activity.supportFragmentManager,

View File

@ -21,6 +21,16 @@ class SettingsFragment: PreferenceFragmentCompat() {
setTheme(requireContext(), key as String) setTheme(requireContext(), key as String)
} }
// Open license fragment
val licensesPreference = findPreference<Preference>(getString(R.string.licenses))
licensesPreference?.setOnPreferenceClickListener {
requireActivity().supportFragmentManager.beginTransaction()
.replace(R.id.fragment_view, LicenseFragment(), getString(R.string.licenses))
.commit()
true
}
// Open about fragment
val aboutPreference = findPreference<Preference>(getString(R.string.about)) val aboutPreference = findPreference<Preference>(getString(R.string.about))
aboutPreference?.setOnPreferenceClickListener { aboutPreference?.setOnPreferenceClickListener {
requireActivity().supportFragmentManager.beginTransaction() requireActivity().supportFragmentManager.beginTransaction()
@ -30,14 +40,6 @@ class SettingsFragment: PreferenceFragmentCompat() {
true true
} }
val licensesPreference = findPreference<Preference>(getString(R.string.licenses))
licensesPreference?.setOnPreferenceClickListener {
requireActivity().supportFragmentManager.beginTransaction()
.replace(R.id.fragment_view, LicenseFragment(), getString(R.string.licenses))
.commit()
true
}
} }
companion object { companion object {

View File

@ -28,6 +28,10 @@ class Visits(val id: Int, private val locs: HashMap<String,Int>) {
return locs.getOrDefault(key.code,0) return locs.getOrDefault(key.code,0)
} }
fun countVisited(key: Int): Int {
return locs.filter { it.value == key }.size
}
@OptIn(ExperimentalSerializationApi::class) @OptIn(ExperimentalSerializationApi::class)
@Serializer(Visits::class) @Serializer(Visits::class)
class VisitsSerializer { class VisitsSerializer {

View File

@ -0,0 +1,14 @@
<vector
android:height="24dp"
android:viewportHeight="960"
android:viewportWidth="960"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android" >
<path
android:fillColor="?attr/colorOnBackground"
android:pathData="M105,727L40,680L240,360L360,500L520,240L629,403Q606,404 585.5,408.5Q565,413 545,421L523,388L371,635L250,494L105,727ZM732,423Q713,415 692.5,410Q672,405 650,404L855,80L920,127L732,423Z" />
<path
android:fillColor="?attr/colorPrimary"
android:pathData="M863,920L738,795Q718,809 693.5,816Q669,823 643,823Q568,823 515.5,770.5Q463,718 463,643Q463,568 515.5,515.5Q568,463 643,463Q718,463 770.5,515.5Q823,568 823,643Q823,669 816,693.5Q809,718 795,739L920,863L863,920ZM643,743Q685,743 714,714Q743,685 743,643Q743,601 714,572Q685,543 643,543Q601,543 572,572Q543,601 543,643Q543,685 572,714Q601,743 643,743Z" />
</vector>

View File

@ -16,11 +16,25 @@
android:layout_marginTop="2dp" android:layout_marginTop="2dp"
android:layout_marginEnd="32dp" android:layout_marginEnd="32dp"
android:layout_marginBottom="2dp" android:layout_marginBottom="2dp"
android:textAlignment="textStart"
android:textColor="?attr/colorOnPrimary"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="start|center_vertical"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:textColor="?attr/colorOnPrimary"
app:layout_constraintTop_toTopOf="@id/group_color"
app:layout_constraintBottom_toBottomOf="@id/group_color"
app:layout_constraintEnd_toEndOf="@id/group_color" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -5,4 +5,9 @@
<item>@string/light</item> <item>@string/light</item>
<item>@string/dark</item> <item>@string/dark</item>
</string-array> </string-array>
<string-array name="entries_stats" >
<item>@string/counters</item>
<item>@string/percentages</item>
</string-array>
</resources> </resources>

View File

@ -11,6 +11,9 @@
<string name="system">System</string> <string name="system">System</string>
<string name="light">Light</string> <string name="light">Light</string>
<string name="dark">Dark</string> <string name="dark">Dark</string>
<string name="key_stats">Statistics</string>
<string name="counters">Prefer counters (#)</string>
<string name="percentages">Prefer percentages (%)</string>
<string name="licenses">Licenses</string> <string name="licenses">Licenses</string>
<string name="about">About</string> <string name="about">About</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_is_foss">BeenDroid is free and open source software, licensed under the GNU General Public License (version 3 or later)</string>
@ -22,5 +25,6 @@
<string name="logo">Logo</string> <string name="logo">Logo</string>
<string name="name">Name</string> <string name="name">Name</string>
<string name="rate">%1$d/%2$d</string> <string name="rate">%1$d/%2$d</string>
<string name="percentage">%1$d&#65285;</string>
<string name="color_rrggbb">RRGGBB</string> <string name="color_rrggbb">RRGGBB</string>
</resources> </resources>

View File

@ -13,6 +13,16 @@
app:entryValues="@array/entries_theme" app:entryValues="@array/entries_theme"
app:defaultValue="@string/system" /> app:defaultValue="@string/system" />
<ListPreference
app:enabled="true"
app:key="@string/key_stats"
app:icon="@drawable/stats"
app:title="@string/key_stats"
app:useSimpleSummaryProvider="true"
app:entries="@array/entries_stats"
app:entryValues="@array/entries_stats"
app:defaultValue="@string/counters" />
<Preference <Preference
app:enabled="true" app:enabled="true"
app:key="@string/licenses" app:key="@string/licenses"