summaryrefslogtreecommitdiff
path: root/app/src/main/java/foundation
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/foundation')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/common/GraphHolder.kt27
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt19
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt24
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt45
4 files changed, 102 insertions, 13 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/GraphHolder.kt b/app/src/main/java/foundation/e/privacycentralapp/common/GraphHolder.kt
index aba3a95..32766ca 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/common/GraphHolder.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/common/GraphHolder.kt
@@ -31,6 +31,7 @@ import androidx.core.view.isVisible
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.components.MarkerView
import com.github.mikephil.charting.components.XAxis
+import com.github.mikephil.charting.components.YAxis
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.BarEntry
@@ -87,7 +88,7 @@ class GraphHolder(val barChart: BarChart, val context: Context, val isMarkerAbov
override fun onValueSelected(e: Entry?, h: Highlight?) {
h?.let {
val index = it.x.toInt()
- if (index > 0 &&
+ if (index >= 0 &&
index < labels.size &&
index < this@GraphHolder.data.size
) {
@@ -97,17 +98,30 @@ class GraphHolder(val barChart: BarChart, val context: Context, val isMarkerAbov
}
}
isHighlighted = true
- refreshDataSet()
}
override fun onNothingSelected() {
isHighlighted = false
- refreshDataSet()
}
})
}
}
+ fun highlightIndex(index: Int) {
+ if (index >= 0 && index < data.size) {
+ val xPx = barChart.getTransformer(YAxis.AxisDependency.LEFT)
+ .getPixelForValues(index.toFloat(), 0f)
+ .x
+ val highlight = Highlight(
+ index.toFloat(), 0f,
+ xPx.toFloat(), 0f,
+ 0, YAxis.AxisDependency.LEFT
+ )
+
+ barChart.highlightValue(highlight, true)
+ }
+ }
+
private fun refreshDataSet() {
val trackersDataSet = BarDataSet(
data.mapIndexed { index, value ->
@@ -122,19 +136,12 @@ class GraphHolder(val barChart: BarChart, val context: Context, val isMarkerAbov
val blockedColor = ContextCompat.getColor(context, R.color.accent)
val leakedColor = ContextCompat.getColor(context, R.color.red_off)
- // ColorUtils.setAlphaComponent()
colors = listOf(
blockedColor,
- // if (isHighlighted) R.color.blue_unselected else R.color.accent
leakedColor
)
setDrawValues(false)
-
- // highLightColor = ContextCompat.getColor(
- // context, R.color.accent
- // )
- // highLightAlpha = 255
}
barChart.data = BarData(trackersDataSet)
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 32549c9..3f849a6 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
@@ -24,6 +24,7 @@ import android.text.Html.FROM_HTML_MODE_LEGACY
import android.view.View
import android.widget.Toast
import androidx.core.content.ContextCompat.getColor
+import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.commit
@@ -56,6 +57,13 @@ class DashboardFragment :
NavToolbarFragment(R.layout.fragment_dashboard),
MVIView<DashboardFeature.State, DashboardFeature.Action> {
+ companion object {
+ private const val PARAM_HIGHLIGHT_INDEX = "PARAM_HIGHLIGHT_INDEX"
+ fun buildArgs(highlightIndex: Int): Bundle = bundleOf(
+ PARAM_HIGHLIGHT_INDEX to highlightIndex
+ )
+ }
+
private val dependencyContainer: DependencyContainer by lazy {
(this.requireActivity().application as PrivacyCentralApplication).dependencyContainer
}
@@ -69,11 +77,15 @@ class DashboardFragment :
private var qpDisabledSnackbar: Snackbar? = null
+ private var highlightIndexOnStart: Int? = null
+
private var updateUIJob: Job? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ highlightIndexOnStart = arguments?.getInt(PARAM_HIGHLIGHT_INDEX, -1)
+
updateUIJob = lifecycleScope.launchWhenStarted {
viewModel.dashboardFeature.takeView(this, this@DashboardFragment)
}
@@ -250,6 +262,13 @@ class DashboardFragment :
),
FROM_HTML_MODE_LEGACY
)
+
+ highlightIndexOnStart?.let {
+ binding.graph.post {
+ graphHolder.highlightIndex(it)
+ }
+ highlightIndexOnStart = null
+ }
}
if (state.allowedTrackersCount != null && state.trackersCount != null) {
diff --git a/app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt b/app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt
index 910385e..5159827 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt
@@ -18,6 +18,7 @@
package foundation.e.privacycentralapp.main
import android.app.Activity
+import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.FragmentActivity
@@ -56,7 +57,18 @@ open class MainActivity : FragmentActivity(R.layout.activity_main) {
handleIntent(intent)
}
- open fun handleIntent(intent: Intent) {}
+ open fun handleIntent(intent: Intent) {
+ supportFragmentManager.commit {
+ setReorderingAllowed(true)
+ when (intent.action) {
+ ACTION_HIGHLIGHT_LEAKS -> add<DashboardFragment>(
+ containerViewId = R.id.container,
+ args = intent.extras
+ )
+ else -> add<DashboardFragment>(R.id.container)
+ }
+ }
+ }
override fun finishAfterTransition() {
val resultData = Intent()
@@ -67,4 +79,14 @@ open class MainActivity : FragmentActivity(R.layout.activity_main) {
}
open fun onPopulateResultIntent(intent: Intent): Int = Activity.RESULT_OK
+
+ companion object {
+ private const val ACTION_HIGHLIGHT_LEAKS = "ACTION_HIGHLIGHT_LEAKS"
+
+ fun createHighlightLeaksIntent(context: Context, highlightIndex: Int) =
+ Intent(context, MainActivity::class.java).apply {
+ action = ACTION_HIGHLIGHT_LEAKS
+ putExtras(DashboardFragment.buildArgs(highlightIndex))
+ }
+ }
}
diff --git a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt
index 57ddd0c..81859e6 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt
@@ -51,7 +51,10 @@ fun render(
val views = RemoteViews(context.packageName, R.layout.widget)
views.apply {
val openPIntent = PendingIntent.getActivity(
- context, 0, Intent(context, MainActivity::class.java), FLAG_UPDATE_CURRENT
+ context,
+ REQUEST_CODE_DASHBOARD,
+ Intent(context, MainActivity::class.java),
+ FLAG_UPDATE_CURRENT
)
setOnClickPendingIntent(R.id.settings_btn, openPIntent)
setOnClickPendingIntent(R.id.widget_container, openPIntent)
@@ -81,7 +84,7 @@ fun render(
R.id.toggle_privacy_central,
PendingIntent.getBroadcast(
context,
- 0,
+ REQUEST_CODE_TOGGLE,
Intent(context, WidgetCommandReceiver::class.java).apply {
action = ACTION_TOGGLE_PRIVACY
},
@@ -146,6 +149,13 @@ fun render(
// leacked (the bar above)
val topPadding = graphHeightPx - (blocked + leaked) * ratio
setViewPadding(leakedBarIds[index], 0, topPadding.toInt(), 0, 0)
+
+ val highlightPIntent = PendingIntent.getActivity(
+ context, REQUEST_CODE_HIGHLIGHT + index,
+ MainActivity.createHighlightLeaksIntent(context, index),
+ FLAG_UPDATE_CURRENT
+ )
+ setOnClickPendingIntent(containerBarIds[index], highlightPIntent)
}
setTextViewText(
@@ -161,6 +171,33 @@ fun render(
appWidgetManager.updateAppWidget(ComponentName(context, Widget::class.java), views)
}
+private val containerBarIds = listOf(
+ R.id.widget_graph_bar_container_0,
+ R.id.widget_graph_bar_container_1,
+ R.id.widget_graph_bar_container_2,
+ R.id.widget_graph_bar_container_3,
+ R.id.widget_graph_bar_container_4,
+ R.id.widget_graph_bar_container_5,
+ R.id.widget_graph_bar_container_6,
+ R.id.widget_graph_bar_container_7,
+ R.id.widget_graph_bar_container_8,
+ R.id.widget_graph_bar_container_9,
+ R.id.widget_graph_bar_container_10,
+ R.id.widget_graph_bar_container_11,
+ R.id.widget_graph_bar_container_12,
+ R.id.widget_graph_bar_container_13,
+ R.id.widget_graph_bar_container_14,
+ R.id.widget_graph_bar_container_15,
+ R.id.widget_graph_bar_container_16,
+ R.id.widget_graph_bar_container_17,
+ R.id.widget_graph_bar_container_18,
+ R.id.widget_graph_bar_container_19,
+ R.id.widget_graph_bar_container_20,
+ R.id.widget_graph_bar_container_21,
+ R.id.widget_graph_bar_container_22,
+ R.id.widget_graph_bar_container_23,
+)
+
private val blockedBarIds = listOf(
R.id.widget_graph_bar_0,
R.id.widget_graph_bar_1,
@@ -214,3 +251,7 @@ private val leakedBarIds = listOf(
R.id.widget_leaked_graph_bar_22,
R.id.widget_leaked_graph_bar_23
)
+
+private const val REQUEST_CODE_DASHBOARD = 1
+private const val REQUEST_CODE_TOGGLE = 2
+private const val REQUEST_CODE_HIGHLIGHT = 100