From 76a4d5959df5ec80725a34dd087ac45751c3105f Mon Sep 17 00:00:00 2001 From: Hamza417 <23103729+Hamza417@users.noreply.github.com> Date: Fri, 3 Jan 2025 07:18:09 +0530 Subject: [PATCH] add: option to toggle chart labels in analytics --- app/src/main/assets/html/changelogs.html | 1 + .../decorations/theme/ThemePieChart.java | 54 ++++++++++++++++--- .../inure/dialogs/analytics/AnalyticsMenu.kt | 15 ++++++ .../inure/preferences/AnalyticsPreferences.kt | 11 ++++ .../app/simple/inure/ui/panels/Analytics.kt | 32 ++++++----- .../main/res/layout/dialog_menu_analytics.xml | 33 +++++++++++- app/src/main/res/values/strings.xml | 1 + 7 files changed, 127 insertions(+), 20 deletions(-) diff --git a/app/src/main/assets/html/changelogs.html b/app/src/main/assets/html/changelogs.html index 61f97ad51..65461f987 100644 --- a/app/src/main/assets/html/changelogs.html +++ b/app/src/main/assets/html/changelogs.html @@ -69,6 +69,7 @@

Analytics

  • Updated longpress behavior legend to highlight the pie slices and clicking should lead to the respective data panels on any chart.
  • +
  • Added option to toggle chart labels in Analytics panel.

  • diff --git a/app/src/main/java/app/simple/inure/decorations/theme/ThemePieChart.java b/app/src/main/java/app/simple/inure/decorations/theme/ThemePieChart.java index 8ba0eeba5..c16bcfc21 100644 --- a/app/src/main/java/app/simple/inure/decorations/theme/ThemePieChart.java +++ b/app/src/main/java/app/simple/inure/decorations/theme/ThemePieChart.java @@ -9,6 +9,8 @@ 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.PieDataSet; +import com.github.mikephil.charting.formatter.PercentFormatter; import androidx.annotation.NonNull; import app.simple.inure.R; @@ -52,21 +54,21 @@ private void initProps() { setNoDataTextColor(ThemeManager.INSTANCE.getTheme().getTextViewTheme().getSecondaryTextColor()); setNoDataTextTypeface(TypeFace.INSTANCE.getMediumTypeFace(getContext())); } - + setHoleColor(Color.TRANSPARENT); setUsePercentValues(false); setDragDecelerationFrictionCoef(0.95F); setHighlightPerTapEnabled(true); getDescription().setEnabled(false); setDrawCenterText(false); - + if (StatusBarHeight.isLandscape(getContext())) { setExtraOffsets(chartOffset * 2F, chartOffset * 2F, chartOffset * 2F, chartOffset * 2F); setExtraRightOffset(chartOffset * 4F); } else { setExtraOffsets(chartOffset, chartOffset, chartOffset, chartOffset); } - + /* * Legend's props */ @@ -77,13 +79,13 @@ private void initProps() { getLegend().setTextColor(ThemeManager.INSTANCE.getTheme().getTextViewTheme().getSecondaryTextColor()); getLegend().setXEntrySpace(20F); getLegend().setYEntrySpace(5F); - + if (!isInEditMode()) { getLegend().setTypeface(TypeFace.INSTANCE.getMediumTypeFace(getContext())); } - + getLegend().setWordWrapEnabled(true); - + if (StatusBarHeight.isLandscape(getContext())) { getLegend().setXOffset(chartOffset * 3F); getLegend().setOrientation(Legend.LegendOrientation.VERTICAL); @@ -171,4 +173,44 @@ private void animateHoleRadius(float value) { public void setAnimation(boolean animate) { this.animate = animate; } + + public void enableChartLabels(PieDataSet dataSet) { + dataSet.setValueTextColor(ThemeManager.INSTANCE.getTheme().getTextViewTheme().getPrimaryTextColor()); + dataSet.setValueTextSize(9F); + dataSet.setValueTypeface(TypeFace.INSTANCE.getRegularTypeFace(getContext())); + dataSet.setValueLineColor(ThemeManager.INSTANCE.getTheme().getTextViewTheme().getPrimaryTextColor()); + dataSet.setValueLinePart1OffsetPercentage(80F); + setEntryLabelColor(ThemeManager.INSTANCE.getTheme().getTextViewTheme().getPrimaryTextColor()); + setEntryLabelTextSize(9F); + setEntryLabelTypeface(TypeFace.INSTANCE.getRegularTypeFace(getContext())); + dataSet.setValueFormatter(new PercentFormatter(this)); + dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); + dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); + dataSet.setDrawIcons(true); + setUsePercentValues(true); + notifyDataSetChanged(); + invalidate(); + } + + public void disableChartLabels(PieDataSet dataSet) { + dataSet.setValueTextColor(Color.TRANSPARENT); + dataSet.setValueTextSize(0F); + dataSet.setValueTypeface(TypeFace.INSTANCE.getRegularTypeFace(getContext())); + dataSet.setValueLineColor(Color.TRANSPARENT); + dataSet.setValueLinePart1OffsetPercentage(80F); + setEntryLabelColor(Color.TRANSPARENT); + setEntryLabelTextSize(0F); + setEntryLabelTypeface(TypeFace.INSTANCE.getRegularTypeFace(getContext())); + dataSet.setValueFormatter(null); + dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); + dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); + dataSet.setDrawIcons(false); + setUsePercentValues(false); + notifyDataSetChanged(); + invalidate(); + } + + public PieDataSet getExistingDataSet() { + return (PieDataSet) getData().getDataSet(); + } } diff --git a/app/src/main/java/app/simple/inure/dialogs/analytics/AnalyticsMenu.kt b/app/src/main/java/app/simple/inure/dialogs/analytics/AnalyticsMenu.kt index 6fd96ec75..db5eef6c0 100644 --- a/app/src/main/java/app/simple/inure/dialogs/analytics/AnalyticsMenu.kt +++ b/app/src/main/java/app/simple/inure/dialogs/analytics/AnalyticsMenu.kt @@ -5,8 +5,10 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.FragmentManager import app.simple.inure.R import app.simple.inure.decorations.ripple.DynamicRippleTextView +import app.simple.inure.decorations.toggles.Switch import app.simple.inure.extensions.fragments.ScopedBottomSheetFragment import app.simple.inure.popups.analytics.PopupSdkValue import app.simple.inure.preferences.AnalyticsPreferences @@ -15,6 +17,7 @@ class AnalyticsMenu : ScopedBottomSheetFragment() { private lateinit var sdkValue: DynamicRippleTextView private lateinit var pieHoleRadius: DynamicRippleTextView + private lateinit var chartLabelsSwitch: Switch private lateinit var settings: DynamicRippleTextView override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -22,6 +25,7 @@ class AnalyticsMenu : ScopedBottomSheetFragment() { sdkValue = view.findViewById(R.id.sdk_value) pieHoleRadius = view.findViewById(R.id.dialog_open_pie_hole) + chartLabelsSwitch = view.findViewById(R.id.chart_labels_switch) settings = view.findViewById(R.id.dialog_open_apps_settings) return view @@ -31,6 +35,7 @@ class AnalyticsMenu : ScopedBottomSheetFragment() { super.onViewCreated(view, savedInstanceState) setSdkValue() + chartLabelsSwitch.isChecked = AnalyticsPreferences.getChartLabel() sdkValue.setOnClickListener { PopupSdkValue(it) @@ -43,6 +48,10 @@ class AnalyticsMenu : ScopedBottomSheetFragment() { } } + chartLabelsSwitch.setOnSwitchCheckedChangeListener { + AnalyticsPreferences.setChartLabel(it) + } + settings.setOnClickListener { openSettings() } @@ -71,5 +80,11 @@ class AnalyticsMenu : ScopedBottomSheetFragment() { fragment.arguments = args return fragment } + + const val TAG = "analytics_menu" + + fun FragmentManager.showAnalyticsMenu() { + newInstance().show(this, TAG) + } } } diff --git a/app/src/main/java/app/simple/inure/preferences/AnalyticsPreferences.kt b/app/src/main/java/app/simple/inure/preferences/AnalyticsPreferences.kt index e118882a7..0d8264f4d 100644 --- a/app/src/main/java/app/simple/inure/preferences/AnalyticsPreferences.kt +++ b/app/src/main/java/app/simple/inure/preferences/AnalyticsPreferences.kt @@ -7,6 +7,7 @@ object AnalyticsPreferences { const val SDK_VALUE = "analytics_sdk_value" const val PIE_HOLE_RADIUS = "pie_hole_radius" const val APPLICATION_TYPE = "application_type_analytics" + const val CHART_LABEL = "analytics_chart_label" // ---------------------------------------------------------------------------------------------------------- // @@ -37,4 +38,14 @@ object AnalyticsPreferences { fun getApplicationType(): String { return SharedPreferences.getSharedPreferences().getString(APPLICATION_TYPE, SortConstant.BOTH)!! } + + // ---------------------------------------------------------------------------------------------------------- // + + fun setChartLabel(value: Boolean) { + SharedPreferences.getSharedPreferences().edit().putBoolean(CHART_LABEL, value).apply() + } + + fun getChartLabel(): Boolean { + return SharedPreferences.getSharedPreferences().getBoolean(CHART_LABEL, true) + } } diff --git a/app/src/main/java/app/simple/inure/ui/panels/Analytics.kt b/app/src/main/java/app/simple/inure/ui/panels/Analytics.kt index 454b435f8..d50fb6267 100644 --- a/app/src/main/java/app/simple/inure/ui/panels/Analytics.kt +++ b/app/src/main/java/app/simple/inure/ui/panels/Analytics.kt @@ -1,7 +1,6 @@ package app.simple.inure.ui.panels import android.content.SharedPreferences -import android.graphics.Color import android.os.Build import android.os.Bundle import android.view.LayoutInflater @@ -17,7 +16,7 @@ import app.simple.inure.decorations.padding.PaddingAwareNestedScrollView import app.simple.inure.decorations.theme.ThemePieChart import app.simple.inure.decorations.typeface.TypeFaceTextView import app.simple.inure.decorations.views.LegendRecyclerView -import app.simple.inure.dialogs.analytics.AnalyticsMenu +import app.simple.inure.dialogs.analytics.AnalyticsMenu.Companion.showAnalyticsMenu import app.simple.inure.dialogs.analytics.AnalyticsSort.Companion.showAnalyticsSort import app.simple.inure.extensions.fragments.ScopedFragment import app.simple.inure.popups.charts.PopupChartEntry @@ -92,8 +91,7 @@ class Analytics : ScopedFragment() { BottomMenuConstants.getAllAppsBottomMenuItems(), scrollView) { id, _ -> when (id) { R.drawable.ic_settings -> { - AnalyticsMenu.newInstance() - .show(childFragmentManager, "analytics_menu") + childFragmentManager.showAnalyticsMenu() } R.drawable.ic_search -> { openFragmentSlide(Search.newInstance(true), "search") @@ -115,8 +113,7 @@ class Analytics : ScopedFragment() { PieDataSet(pieData.first, "").apply { data = PieData(this) colors = pieData.second - valueTextColor = Color.TRANSPARENT - setEntryLabelColor(Color.TRANSPARENT) + checkLabelState() } setOnChartValueSelectedListener(object : OnChartValueSelectedListener { @@ -167,8 +164,7 @@ class Analytics : ScopedFragment() { PieDataSet(it.first, "").apply { data = PieData(this) colors = it.second - valueTextColor = Color.TRANSPARENT - setEntryLabelColor(Color.TRANSPARENT) + checkLabelState() } setOnChartValueSelectedListener(object : OnChartValueSelectedListener { @@ -216,8 +212,7 @@ class Analytics : ScopedFragment() { PieDataSet(it.first, "").apply { data = PieData(this) colors = ColorTemplate.PASTEL_COLORS.toMutableList() - valueTextColor = Color.TRANSPARENT - setEntryLabelColor(Color.TRANSPARENT) + checkLabelState() } setOnChartValueSelectedListener(object : OnChartValueSelectedListener { @@ -267,8 +262,7 @@ class Analytics : ScopedFragment() { PieDataSet(it.first, "").apply { data = PieData(this) colors = it.second - valueTextColor = Color.TRANSPARENT - setEntryLabelColor(Color.TRANSPARENT) + checkLabelState() } setOnChartValueSelectedListener(object : OnChartValueSelectedListener { @@ -342,6 +336,20 @@ class Analytics : ScopedFragment() { analyticsViewModel.refreshPackageData() setFilterStyle() } + AnalyticsPreferences.CHART_LABEL -> { + minimumOsPie.checkLabelState() + targetOsPie.checkLabelState() + packageTypePie.checkLabelState() + installerPie.checkLabelState() + } + } + } + + private fun ThemePieChart.checkLabelState() { + if (AnalyticsPreferences.getChartLabel()) { + enableChartLabels(existingDataSet) + } else { + disableChartLabels(existingDataSet) } } diff --git a/app/src/main/res/layout/dialog_menu_analytics.xml b/app/src/main/res/layout/dialog_menu_analytics.xml index 8cc65b812..fe3cd0c11 100644 --- a/app/src/main/res/layout/dialog_menu_analytics.xml +++ b/app/src/main/res/layout/dialog_menu_analytics.xml @@ -5,6 +5,7 @@ android:layout_height="wrap_content" android:clipChildren="false" android:clipToPadding="false" + android:layout_gravity="bottom" android:padding="@dimen/dialog_padding"> + + + + + + + + + android:layout_margin="@dimen/dialog_padding" /> Launchable Stopped Provider + Chart Labels