From 3185b88fe525bc20a7bb86614bbba38b46d4acd9 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 15 May 2020 09:34:14 +0200 Subject: [PATCH] Better connectivity lost indicator when airplane mode is on --- CHANGES.md | 2 +- .../java/im/vector/riotx/core/utils/SystemUtils.kt | 4 ++++ .../riotx/features/sync/widget/SyncStateView.kt | 14 ++++++++++---- vector/src/main/res/layout/view_sync_state.xml | 13 +++++++++++++ vector/src/main/res/values/strings.xml | 1 + 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 099e4cf5f4..37cdfba1f5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Features ✨: - Improvements 🙌: - - + - Better connectivity lost indicator when airplane mode is on Bugfix 🐛: - diff --git a/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt b/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt index d82134caf5..23f3cbc875 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt @@ -53,6 +53,10 @@ fun isIgnoringBatteryOptimizations(context: Context): Boolean { || (context.getSystemService(Context.POWER_SERVICE) as PowerManager?)?.isIgnoringBatteryOptimizations(context.packageName) == true } +fun isAirplaneModeOn(context: Context): Boolean { + return Settings.Global.getInt(context.contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0) != 0 +} + /** * display the system dialog for granting this permission. If previously granted, the * system will not show it (so you should call this method). diff --git a/vector/src/main/java/im/vector/riotx/features/sync/widget/SyncStateView.kt b/vector/src/main/java/im/vector/riotx/features/sync/widget/SyncStateView.kt index b8856dddb1..fa392a10ad 100755 --- a/vector/src/main/java/im/vector/riotx/features/sync/widget/SyncStateView.kt +++ b/vector/src/main/java/im/vector/riotx/features/sync/widget/SyncStateView.kt @@ -23,6 +23,7 @@ import android.widget.FrameLayout import androidx.core.view.isVisible import im.vector.matrix.android.api.session.sync.SyncState import im.vector.riotx.R +import im.vector.riotx.core.utils.isAirplaneModeOn import kotlinx.android.synthetic.main.view_sync_state.view.* class SyncStateView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) @@ -33,10 +34,15 @@ class SyncStateView @JvmOverloads constructor(context: Context, attrs: Attribute } fun render(newState: SyncState) { - syncStateProgressBar.visibility = when (newState) { - is SyncState.Running -> if (newState.afterPause) View.VISIBLE else View.GONE - else -> View.GONE + syncStateProgressBar.isVisible = newState is SyncState.Running && newState.afterPause + + if (newState == SyncState.NoNetwork) { + val isAirplaneModeOn = isAirplaneModeOn(context) + syncStateNoNetwork.isVisible = isAirplaneModeOn.not() + syncStateNoNetworkAirplane.isVisible = isAirplaneModeOn + } else { + syncStateNoNetwork.isVisible = false + syncStateNoNetworkAirplane.isVisible = false } - syncStateNoNetwork.isVisible = newState == SyncState.NoNetwork } } diff --git a/vector/src/main/res/layout/view_sync_state.xml b/vector/src/main/res/layout/view_sync_state.xml index bc828045fe..0e7ddabc21 100644 --- a/vector/src/main/res/layout/view_sync_state.xml +++ b/vector/src/main/res/layout/view_sync_state.xml @@ -33,6 +33,19 @@ android:text="@string/no_connectivity_to_the_server_indicator" android:textColor="@color/white" android:visibility="gone" + tools:layout_marginTop="10dp" + tools:visibility="visible" /> + + \ No newline at end of file diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 89cbc9a856..0158c61fcc 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -2163,6 +2163,7 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming No Connectivity to the server has been lost + Airplane mode is on Dev Tools Account Data