Enable percentage stats if desired
This commit is contained in:
parent
01020bdc5c
commit
71a33c4db7
@ -8,6 +8,7 @@ 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.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.checkbox.MaterialCheckBox
|
||||
@ -63,6 +64,9 @@ class GeolocListAdapter(
|
||||
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>) {
|
||||
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)
|
||||
} else {
|
||||
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)
|
||||
|
||||
|
@ -21,6 +21,16 @@ class SettingsFragment: PreferenceFragmentCompat() {
|
||||
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))
|
||||
aboutPreference?.setOnPreferenceClickListener {
|
||||
requireActivity().supportFragmentManager.beginTransaction()
|
||||
@ -30,14 +40,6 @@ class SettingsFragment: PreferenceFragmentCompat() {
|
||||
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 {
|
||||
|
14
app/src/main/res/drawable/stats.xml
Normal file
14
app/src/main/res/drawable/stats.xml
Normal 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>
|
@ -5,4 +5,9 @@
|
||||
<item>@string/light</item>
|
||||
<item>@string/dark</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="entries_stats" >
|
||||
<item>@string/counters</item>
|
||||
<item>@string/percentages</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@ -11,6 +11,9 @@
|
||||
<string name="system">System</string>
|
||||
<string name="light">Light</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="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>
|
||||
@ -22,5 +25,6 @@
|
||||
<string name="logo">Logo</string>
|
||||
<string name="name">Name</string>
|
||||
<string name="rate">%1$d/%2$d</string>
|
||||
<string name="percentage">%1$d%</string>
|
||||
<string name="color_rrggbb">RRGGBB</string>
|
||||
</resources>
|
@ -13,6 +13,16 @@
|
||||
app:entryValues="@array/entries_theme"
|
||||
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
|
||||
app:enabled="true"
|
||||
app:key="@string/licenses"
|
||||
|
Loading…
x
Reference in New Issue
Block a user