diff --git a/app/src/main/java/net/helcel/beendroid/activity/adapter/GeolocListAdapter.kt b/app/src/main/java/net/helcel/beendroid/activity/adapter/GeolocListAdapter.kt index 0381eb9..69b5e5a 100644 --- a/app/src/main/java/net/helcel/beendroid/activity/adapter/GeolocListAdapter.kt +++ b/app/src/main/java/net/helcel/beendroid/activity/adapter/GeolocListAdapter.kt @@ -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) { 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) diff --git a/app/src/main/java/net/helcel/beendroid/activity/fragment/SettingsFragment.kt b/app/src/main/java/net/helcel/beendroid/activity/fragment/SettingsFragment.kt index 4f7685f..88a0b57 100644 --- a/app/src/main/java/net/helcel/beendroid/activity/fragment/SettingsFragment.kt +++ b/app/src/main/java/net/helcel/beendroid/activity/fragment/SettingsFragment.kt @@ -21,6 +21,16 @@ class SettingsFragment: PreferenceFragmentCompat() { setTheme(requireContext(), key as String) } + // Open license fragment + val licensesPreference = findPreference(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(getString(R.string.about)) aboutPreference?.setOnPreferenceClickListener { requireActivity().supportFragmentManager.beginTransaction() @@ -30,14 +40,6 @@ class SettingsFragment: PreferenceFragmentCompat() { true } - val licensesPreference = findPreference(getString(R.string.licenses)) - licensesPreference?.setOnPreferenceClickListener { - requireActivity().supportFragmentManager.beginTransaction() - .replace(R.id.fragment_view, LicenseFragment(), getString(R.string.licenses)) - .commit() - true - } - } companion object { diff --git a/app/src/main/res/drawable/stats.xml b/app/src/main/res/drawable/stats.xml new file mode 100644 index 0000000..29c544b --- /dev/null +++ b/app/src/main/res/drawable/stats.xml @@ -0,0 +1,14 @@ + + + + + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index f5052d1..a179a1b 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -5,4 +5,9 @@ @string/light @string/dark + + + @string/counters + @string/percentages + diff --git a/app/src/main/res/values/en.xml b/app/src/main/res/values/en.xml index e7270d3..00327e2 100644 --- a/app/src/main/res/values/en.xml +++ b/app/src/main/res/values/en.xml @@ -11,6 +11,9 @@ System Light Dark + Statistics + Prefer counters (#) + Prefer percentages (%) Licenses About BeenDroid is free and open source software, licensed under the GNU General Public License (version 3 or later) @@ -22,5 +25,6 @@ Logo Name %1$d/%2$d + %1$d% RRGGBB \ No newline at end of file diff --git a/app/src/main/res/xml/fragment_settings.xml b/app/src/main/res/xml/fragment_settings.xml index f13adda..0eea219 100644 --- a/app/src/main/res/xml/fragment_settings.xml +++ b/app/src/main/res/xml/fragment_settings.xml @@ -13,6 +13,16 @@ app:entryValues="@array/entries_theme" app:defaultValue="@string/system" /> + +