summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/common/GraphStyle.kt62
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt21
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt27
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt27
4 files changed, 87 insertions, 50 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/GraphStyle.kt b/app/src/main/java/foundation/e/privacycentralapp/common/GraphStyle.kt
new file mode 100644
index 0000000..63a0f3f
--- /dev/null
+++ b/app/src/main/java/foundation/e/privacycentralapp/common/GraphStyle.kt
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2021 E FOUNDATION
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package foundation.e.privacycentralapp.common
+
+import androidx.annotation.ColorInt
+import com.github.mikephil.charting.charts.BarChart
+import com.github.mikephil.charting.components.XAxis
+import com.github.mikephil.charting.data.BarData
+import com.github.mikephil.charting.data.BarDataSet
+import com.github.mikephil.charting.data.BarEntry
+
+fun customizeBarChart(barChart: BarChart) {
+ barChart.apply {
+ description = null
+ setTouchEnabled(false)
+ setDrawGridBackground(false)
+ setDrawBorders(false)
+ axisLeft.isEnabled = false
+ axisRight.isEnabled = false
+
+ legend.isEnabled = false
+
+ xAxis.apply {
+ isEnabled = true
+ position = XAxis.XAxisPosition.BOTH_SIDED
+ setDrawGridLines(false)
+ yOffset = 32f
+ setDrawLabels(false)
+ // setDrawLimitLinesBehindData(true)
+ setDrawValueAboveBar(false)
+ }
+ }
+}
+
+fun updateGraphData(values: List<Int>, graph: BarChart, @ColorInt graphColor: Int) {
+
+ val trackersDataSet = BarDataSet(
+ values.mapIndexed { index, value -> BarEntry(index.toFloat(), value.toFloat()) },
+ ""
+ ).apply {
+ color = graphColor
+ setDrawValues(false)
+ }
+
+ graph.data = BarData(trackersDataSet)
+ graph.invalidate()
+}
diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt
index ae820f1..fcc3676 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt
@@ -24,14 +24,14 @@ class TrackersStatisticsUseCase(
) {
fun getPastDayTrackersCalls(): List<Int> {
- return trackTrackersPrivacyModule.getPastDayTrackersCalls()
+ return trackTrackersPrivacyModule.getPastDayTrackersCalls().pruneEmptyHistoric()
}
fun getDayMonthYearStatistics(): Triple<List<Int>, List<Int>, List<Int>> {
return Triple(
- trackTrackersPrivacyModule.getPastDayTrackersCalls(),
- trackTrackersPrivacyModule.getPastMonthTrackersCalls(),
- trackTrackersPrivacyModule.getPastYearTrackersCalls()
+ trackTrackersPrivacyModule.getPastDayTrackersCalls().pruneEmptyHistoric(),
+ trackTrackersPrivacyModule.getPastMonthTrackersCalls().pruneEmptyHistoric(),
+ trackTrackersPrivacyModule.getPastYearTrackersCalls().pruneEmptyHistoric()
)
}
@@ -50,4 +50,17 @@ class TrackersStatisticsUseCase(
fun getTrackersCount(): Int {
return trackTrackersPrivacyModule.getTrackersCount()
}
+
+ private fun List<Int>.pruneEmptyHistoric(): List<Int> {
+ val result = mutableListOf<Int>()
+ reversed().forEach {
+ if (result.isNotEmpty() || it != 0) {
+ result.add(it)
+ }
+ }
+ if (result.isEmpty() && !isEmpty()) {
+ result.add(last())
+ }
+ return result
+ }
}
diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt
index a7c14ad..142ab0c 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt
@@ -25,14 +25,13 @@ import androidx.fragment.app.activityViewModels
import androidx.fragment.app.add
import androidx.fragment.app.commit
import androidx.lifecycle.lifecycleScope
-import com.github.mikephil.charting.data.BarData
-import com.github.mikephil.charting.data.BarDataSet
-import com.github.mikephil.charting.data.BarEntry
import foundation.e.flowmvi.MVIView
import foundation.e.privacycentralapp.DependencyContainer
import foundation.e.privacycentralapp.PrivacyCentralApplication
import foundation.e.privacycentralapp.R
import foundation.e.privacycentralapp.common.NavToolbarFragment
+import foundation.e.privacycentralapp.common.customizeBarChart
+import foundation.e.privacycentralapp.common.updateGraphData
import foundation.e.privacycentralapp.databinding.FragmentDashboardBinding
import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode
import foundation.e.privacycentralapp.domain.entities.LocationMode
@@ -103,16 +102,7 @@ class DashboardFragment :
super.onViewCreated(view, savedInstanceState)
binding = FragmentDashboardBinding.bind(view)
- binding.graph.apply {
- description = null
- setTouchEnabled(false)
- setDrawGridBackground(false)
- setDrawBorders(false)
- axisLeft.isEnabled = false
- axisRight.isEnabled = false
- xAxis.isEnabled = false
- legend.isEnabled = false
- }
+ customizeBarChart(binding.graph)
binding.togglePrivacyCentral.setOnClickListener {
viewModel.submitAction(DashboardFeature.Action.TogglePrivacyAction)
@@ -203,16 +193,7 @@ class DashboardFragment :
)
state.dayStatistics?.let {
- val trackersDataSet = BarDataSet(
- it.mapIndexed { index, value -> BarEntry(index.toFloat(), value.toFloat()) },
- getString(R.string.dashboard_graph_trackers_legend)
- ).apply {
- color = getColor(requireContext(), R.color.e_blue2)
- setDrawValues(false)
- }
-
- binding.graph.data = BarData(trackersDataSet)
- binding.graph.invalidate()
+ updateGraphData(it, binding.graph, getColor(requireContext(), R.color.e_blue2))
}
binding.graphLegend.text = getString(R.string.dashboard_graph_trackers_legend, state.dayTrackersCount?.toString() ?: "No")
diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt
index 25f6d59..fed5fe9 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt
@@ -26,15 +26,14 @@ import androidx.fragment.app.commit
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
-import com.github.mikephil.charting.data.BarData
-import com.github.mikephil.charting.data.BarDataSet
-import com.github.mikephil.charting.data.BarEntry
import foundation.e.flowmvi.MVIView
import foundation.e.privacycentralapp.DependencyContainer
import foundation.e.privacycentralapp.PrivacyCentralApplication
import foundation.e.privacycentralapp.R
import foundation.e.privacycentralapp.common.AppsAdapter
import foundation.e.privacycentralapp.common.NavToolbarFragment
+import foundation.e.privacycentralapp.common.customizeBarChart
+import foundation.e.privacycentralapp.common.updateGraphData
import foundation.e.privacycentralapp.databinding.FragmentTrackersBinding
import foundation.e.privacycentralapp.databinding.TrackersItemGraphBinding
import foundation.e.privacycentralapp.extensions.viewModelProviderFactoryOf
@@ -94,16 +93,7 @@ class TrackersFragment :
binding = FragmentTrackersBinding.bind(view)
listOf(binding.graphDay, binding.graphMonth, binding.graphYear).forEach {
- it.graph.apply {
- description = null
- setTouchEnabled(false)
- setDrawGridBackground(false)
- setDrawBorders(false)
- axisLeft.isEnabled = false
- axisRight.isEnabled = false
- xAxis.isEnabled = false
- legend.isEnabled = false
- }
+ customizeBarChart(it.graph)
}
binding.apps.apply {
@@ -140,16 +130,7 @@ class TrackersFragment :
}
private fun renderGraph(trackersCount: Int, data: List<Int>, graphBinding: TrackersItemGraphBinding) {
- val trackersDataSet = BarDataSet(
- data.mapIndexed { index, value -> BarEntry(index.toFloat(), value.toFloat()) },
- getString(R.string.trackers_count_label)
- ).apply {
- color = ContextCompat.getColor(requireContext(), R.color.e_blue2)
- setDrawValues(false)
- }
-
- graphBinding.graph.data = BarData(trackersDataSet)
- graphBinding.graph.invalidate()
+ updateGraphData(data, graphBinding.graph, ContextCompat.getColor(requireContext(), R.color.e_blue2))
graphBinding.trackersCountLabel.text = getString(R.string.trackers_count_label, trackersCount)
}