Better connectivity lost indicator when airplane mode is on

This commit is contained in:
Benoit Marty 2020-05-15 09:34:14 +02:00
parent 5fa247a0c5
commit 3185b88fe5
5 changed files with 29 additions and 5 deletions

View File

@ -5,7 +5,7 @@ Features ✨:
-
Improvements 🙌:
-
- Better connectivity lost indicator when airplane mode is on
Bugfix 🐛:
-

View File

@ -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).

View File

@ -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
}
syncStateNoNetwork.isVisible = newState == SyncState.NoNetwork
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
}
}
}

View File

@ -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" />
<TextView
android:id="@+id/syncStateNoNetworkAirplane"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/notification_accent_color"
android:gravity="center"
android:text="@string/no_connectivity_to_the_server_indicator_airplane"
android:textColor="@color/white"
android:visibility="gone"
tools:layout_marginTop="10dp"
tools:visibility="visible" />
</merge>

View File

@ -2163,6 +2163,7 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming
<string name="qr_code_scanned_by_other_no">No</string>
<string name="no_connectivity_to_the_server_indicator">Connectivity to the server has been lost</string>
<string name="no_connectivity_to_the_server_indicator_airplane">Airplane mode is on</string>
<string name="settings_dev_tools">Dev Tools</string>
<string name="settings_account_data">Account Data</string>