summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorjacquarg <guillaume.jacquart@hoodbrains.com>2022-03-28 09:11:01 +0200
committerjacquarg <guillaume.jacquart@hoodbrains.com>2022-03-29 08:23:53 +0200
commit138cd2710919db4b5db55797dbdff5f4ebef3846 (patch)
treedaa95590e167c520fb9be159225a435446827bdc /app/src/main
parent668632620bc9552d89e333efa47023ebff515ce9 (diff)
5161 display message when trackers graphs empty.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt30
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt17
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt35
-rw-r--r--app/src/main/res/layout/fragment_dashboard.xml14
-rw-r--r--app/src/main/res/layout/trackers_item_graph.xml13
-rw-r--r--app/src/main/res/layout/widget.xml12
-rw-r--r--app/src/main/res/values/strings.xml1
7 files changed, 98 insertions, 24 deletions
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 f5cb2e1..dec3234 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
@@ -23,6 +23,7 @@ import android.text.Html
import android.text.Html.FROM_HTML_MODE_LEGACY
import android.view.View
import androidx.core.content.ContextCompat.getColor
+import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.add
import androidx.fragment.app.commit
@@ -216,16 +217,25 @@ class DashboardFragment :
)
)
- state.dayStatistics?.let { graphHolder.data = it }
- state.dayLabels?.let { graphHolder.labels = it }
-
- binding.graphLegend.text = Html.fromHtml(
- getString(
- R.string.dashboard_graph_trackers_legend,
- state.activeTrackersCount?.toString() ?: "No"
- ),
- FROM_HTML_MODE_LEGACY
- )
+ if (state.dayStatistics?.all { it == 0 } == true) {
+ binding.graph.visibility = View.INVISIBLE
+ binding.graphLegend.isVisible = false
+ binding.graphEmpty.isVisible = true
+ } else {
+ binding.graph.isVisible = true
+ binding.graphLegend.isVisible = true
+ binding.graphEmpty.isVisible = false
+ state.dayStatistics?.let { graphHolder.data = it }
+ state.dayLabels?.let { graphHolder.labels = it }
+
+ binding.graphLegend.text = Html.fromHtml(
+ getString(
+ R.string.dashboard_graph_trackers_legend,
+ state.activeTrackersCount?.toString() ?: "No"
+ ),
+ FROM_HTML_MODE_LEGACY
+ )
+ }
if (state.activeTrackersCount != null && state.trackersCount != null) {
binding.amITracked.subTitle = getString(R.string.dashboard_am_i_tracked_subtitle, state.trackersCount, state.activeTrackersCount)
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 0f686b4..c0212a5 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
@@ -18,9 +18,9 @@
package foundation.e.privacycentralapp.features.trackers
import android.os.Bundle
-import android.util.Log
import android.view.View
import android.widget.Toast
+import androidx.core.view.isVisible
import androidx.fragment.app.commit
import androidx.fragment.app.replace
import androidx.fragment.app.viewModels
@@ -114,7 +114,6 @@ class TrackersFragment :
}
override fun onResume() {
- Log.d("TestCounts", "OnResume")
super.onResume()
viewModel.submitAction(TrackersFeature.Action.FetchStatistics)
}
@@ -138,9 +137,17 @@ class TrackersFragment :
graphHolder: GraphHolder,
graphBinding: TrackersItemGraphBinding
) {
- graphHolder.data = statistics.calls
- graphHolder.labels = statistics.periods
- graphBinding.trackersCountLabel.text = getString(R.string.trackers_count_label, statistics.trackersCount)
+ if (statistics.calls.all { it == 0 }) {
+ graphBinding.graph.visibility = View.INVISIBLE
+ graphBinding.graphEmpty.isVisible = true
+ } else {
+ graphBinding.graph.isVisible = true
+ graphBinding.graphEmpty.isVisible = false
+ graphHolder.data = statistics.calls
+ graphHolder.labels = statistics.periods
+ graphBinding.trackersCountLabel.text =
+ getString(R.string.trackers_count_label, statistics.trackersCount)
+ }
}
override fun actions(): Flow<TrackersFeature.Action> = viewModel.actions
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 ae2238f..1196920 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt
@@ -124,16 +124,33 @@ fun render(
setViewVisibility(R.id.state_ip_address_loader, if (loading) View.VISIBLE else View.GONE)
- val graphHeightPx = 26.dpToPxF(context)
- val maxValue = state.dayStatistics.maxOrNull().let { if (it == null || it == 0) 1 else it }
- val ratio = graphHeightPx / maxValue
-
- state.dayStatistics.zip(barIds).forEach { (value, viewId) ->
- val topPadding = graphHeightPx - value * ratio
- setViewPadding(viewId, 0, topPadding.toInt(), 0, 0)
+ if (state.dayStatistics.all { it == 0 }) {
+ setViewVisibility(R.id.graph, View.GONE)
+ setViewVisibility(R.id.graph_legend, View.GONE)
+ setViewVisibility(R.id.graph_empty, View.VISIBLE)
+ } else {
+ setViewVisibility(R.id.graph, View.VISIBLE)
+ setViewVisibility(R.id.graph_legend, View.VISIBLE)
+ setViewVisibility(R.id.graph_empty, View.GONE)
+
+ val graphHeightPx = 26.dpToPxF(context)
+ val maxValue =
+ state.dayStatistics.maxOrNull().let { if (it == null || it == 0) 1 else it }
+ val ratio = graphHeightPx / maxValue
+
+ state.dayStatistics.zip(barIds).forEach { (value, viewId) ->
+ val topPadding = graphHeightPx - value * ratio
+ setViewPadding(viewId, 0, topPadding.toInt(), 0, 0)
+ }
+
+ setTextViewText(
+ R.id.graph_legend,
+ context.getString(
+ R.string.widget_graph_trackers_legend,
+ state.activeTrackersCount.toString()
+ )
+ )
}
-
- setTextViewText(R.id.graph_legend, context.getString(R.string.widget_graph_trackers_legend, state.activeTrackersCount.toString()))
}
appWidgetManager.updateAppWidget(ComponentName(context, Widget::class.java), views)
diff --git a/app/src/main/res/layout/fragment_dashboard.xml b/app/src/main/res/layout/fragment_dashboard.xml
index 97fdae3..ec69575 100644
--- a/app/src/main/res/layout/fragment_dashboard.xml
+++ b/app/src/main/res/layout/fragment_dashboard.xml
@@ -185,6 +185,20 @@ android:text="@string/dashboard_state_ipaddress_off"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/graph"
/>
+ <TextView
+ android:id="@+id/graph_empty"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="12sp"
+ android:textColor="@color/secondary_text"
+ android:layout_marginHorizontal="16dp"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintBottom_toBottomOf="parent"
+ android:text="@string/graph_empty_message"
+ android:gravity="center"
+ android:visibility="gone"
+ />
+
</androidx.constraintlayout.widget.ConstraintLayout>
<include
diff --git a/app/src/main/res/layout/trackers_item_graph.xml b/app/src/main/res/layout/trackers_item_graph.xml
index 5a2714c..5cc2d98 100644
--- a/app/src/main/res/layout/trackers_item_graph.xml
+++ b/app/src/main/res/layout/trackers_item_graph.xml
@@ -55,5 +55,18 @@
android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="@+id/graph_period_label"
/>
+ <TextView
+ android:id="@+id/graph_empty"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="12sp"
+ android:textColor="@color/secondary_text"
+ android:layout_marginHorizontal="16dp"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintBottom_toBottomOf="parent"
+ android:text="@string/graph_empty_message"
+ android:gravity="center"
+ android:visibility="gone"
+ />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout> \ No newline at end of file
diff --git a/app/src/main/res/layout/widget.xml b/app/src/main/res/layout/widget.xml
index 612221a..6930429 100644
--- a/app/src/main/res/layout/widget.xml
+++ b/app/src/main/res/layout/widget.xml
@@ -171,6 +171,7 @@
<LinearLayout
+ android:id="@+id/graph"
android:layout_width="match_parent"
android:layout_marginTop="16dp"
android:layout_marginHorizontal="24dp"
@@ -388,4 +389,15 @@
android:layout_marginBottom="24dp"
/>
+ <TextView
+ android:id="@+id/graph_empty"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="24dp"
+ android:text="@string/graph_empty_message"
+ android:textColor="@color/on_primary_disabled"
+ android:visibility="gone"
+ android:gravity="center"
+ />
+
</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d6cf817..9655487 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -3,6 +3,7 @@
<!-- Commons -->
<string name="dummy_system_app_label">System</string>
+ <string name="graph_empty_message">Congratulations! No trackers are profiling you.</string>
<!-- Dashboard -->
<string name="dashboard_title">Quick Privacy</string>