summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--app/src/main/res/layout/apptrackers_item_tracker_toggle.xml1
-rw-r--r--app/src/main/res/layout/widget.xml24
6 files changed, 126 insertions, 14 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
diff --git a/app/src/main/res/layout/apptrackers_item_tracker_toggle.xml b/app/src/main/res/layout/apptrackers_item_tracker_toggle.xml
index 8cf7b2e..0371390 100644
--- a/app/src/main/res/layout/apptrackers_item_tracker_toggle.xml
+++ b/app/src/main/res/layout/apptrackers_item_tracker_toggle.xml
@@ -20,7 +20,6 @@
android:textSize="14sp"
tools:text="Body sensor"
/>
-
<Switch
android:id="@+id/toggle"
android:layout_width="wrap_content"
diff --git a/app/src/main/res/layout/widget.xml b/app/src/main/res/layout/widget.xml
index ae5bfe7..e55d8a3 100644
--- a/app/src/main/res/layout/widget.xml
+++ b/app/src/main/res/layout/widget.xml
@@ -179,6 +179,7 @@
android:layout_height="26dp"
>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_0"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -199,6 +200,7 @@
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -219,6 +221,7 @@
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -238,6 +241,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_3"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -257,6 +261,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_4"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -276,6 +281,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_5"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -295,6 +301,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_6"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -314,6 +321,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_7"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -333,6 +341,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_8"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -352,6 +361,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_9"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -372,6 +382,7 @@
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_10"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -392,6 +403,7 @@
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_11"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -412,6 +424,7 @@
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_12"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -431,6 +444,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_13"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -450,6 +464,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_14"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -469,6 +484,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_15"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -488,6 +504,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_16"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -507,6 +524,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_17"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -526,6 +544,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_18"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -545,6 +564,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_19"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -564,6 +584,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_20"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -584,6 +605,7 @@
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_21"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -604,6 +626,7 @@
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_22"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
@@ -623,6 +646,7 @@
/>
</FrameLayout>
<FrameLayout
+ android:id="@+id/widget_graph_bar_container_23"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"