Display a no network indicator when there is no network (#559)

This commit is contained in:
Benoit Marty 2019-09-17 10:59:58 +02:00
parent 6249a59203
commit 695d8cce00
8 changed files with 50 additions and 17 deletions

View File

@ -6,6 +6,7 @@ Features:
Improvements:
- Reduce default release build log level, and lab option to enable more logs.
- Display a no network indicator when there is no network (#559)
Other changes:
-

View File

@ -22,4 +22,5 @@ sealed class SyncState {
object PAUSED : SyncState()
object KILLING : SyncState()
object KILLED : SyncState()
object NO_NETWORK : SyncState()
}

View File

@ -97,6 +97,8 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
if (!networkConnectivityChecker.isConnected() || state == SyncState.PAUSED) {
Timber.v("No network or sync is Paused. Waiting...")
updateStateTo(SyncState.NO_NETWORK)
synchronized(lock) {
lock.wait()
}

View File

@ -3,4 +3,7 @@
<string name="no_network_indicator">There is no network connection right now</string>
</resources>

View File

@ -21,6 +21,7 @@ import android.os.Parcelable
import android.view.LayoutInflater
import android.view.View
import androidx.core.view.forEachIndexed
import androidx.core.view.isVisible
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.airbnb.mvrx.args
@ -208,11 +209,12 @@ class HomeDetailFragment : VectorBaseFragment(), KeysBackupBanner.Delegate {
unreadCounterBadgeViews[INDEX_CATCHUP].render(UnreadCounterBadgeView.State(it.notificationCountCatchup, it.notificationHighlightCatchup))
unreadCounterBadgeViews[INDEX_PEOPLE].render(UnreadCounterBadgeView.State(it.notificationCountPeople, it.notificationHighlightPeople))
unreadCounterBadgeViews[INDEX_ROOMS].render(UnreadCounterBadgeView.State(it.notificationCountRooms, it.notificationHighlightRooms))
syncProgressBar.visibility = when (it.syncState) {
syncProgressBarWrap.visibility = when (it.syncState) {
is SyncState.RUNNING -> if (it.syncState.afterPause) View.VISIBLE else View.GONE
else -> View.GONE
}
syncProgressBarWrap.visibility = syncProgressBar.visibility
// TODO Create a View
noNetworkBanner.isVisible = it.syncState is SyncState.NO_NETWORK
}
companion object {

View File

@ -39,6 +39,7 @@ import androidx.core.content.ContextCompat
import androidx.core.util.Pair
import androidx.core.view.ViewCompat
import androidx.core.view.forEach
import androidx.core.view.isVisible
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
@ -77,8 +78,8 @@ import im.vector.riotx.core.extensions.observeEvent
import im.vector.riotx.core.extensions.setTextOrHide
import im.vector.riotx.core.files.addEntryToDownloadManager
import im.vector.riotx.core.glide.GlideApp
import im.vector.riotx.core.ui.views.NotificationAreaView
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.core.ui.views.NotificationAreaView
import im.vector.riotx.core.utils.*
import im.vector.riotx.features.autocomplete.command.AutocompleteCommandPresenter
import im.vector.riotx.features.autocomplete.command.CommandAutocompletePolicy
@ -251,11 +252,12 @@ class RoomDetailFragment :
}
roomDetailViewModel.selectSubscribe(RoomDetailViewState::syncState) { syncState ->
syncProgressBar.visibility = when (syncState) {
syncProgressBarWrap.visibility = when (syncState) {
is SyncState.RUNNING -> if (syncState.afterPause) View.VISIBLE else View.GONE
else -> View.GONE
}
syncProgressBarWrap.visibility = syncProgressBar.visibility
// TODO Create a View
noNetworkBanner.isVisible = syncState is SyncState.NO_NETWORK
}
}

View File

@ -44,7 +44,7 @@
</androidx.appcompat.widget.Toolbar>
<!-- Trick to remove surrounding padding (clip frome wrapping frame) -->
<!-- Trick to remove surrounding padding (clip from wrapping frame) -->
<FrameLayout
android:id="@+id/syncProgressBarWrap"
android:layout_width="match_parent"
@ -56,17 +56,27 @@
tools:visibility="visible">
<ProgressBar
android:id="@+id/syncProgressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="14dp"
android:layout_gravity="center"
android:background="?riotx_header_panel_background"
android:indeterminate="true"
android:visibility="gone"
tools:visibility="visible" />
android:indeterminate="true" />
</FrameLayout>
<TextView
android:id="@+id/noNetworkBanner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/vector_warning_color"
android:gravity="center"
android:text="@string/no_network_indicator"
android:textColor="@color/white"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/syncProgressBarWrap"
tools:visibility="visible" />
<im.vector.riotx.core.ui.views.KeysBackupBanner
android:id="@+id/homeKeysBackupBanner"
@ -76,7 +86,7 @@
android:minHeight="67dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/syncProgressBarWrap" />
app:layout_constraintTop_toBottomOf="@id/noNetworkBanner" />
<FrameLayout
android:id="@+id/roomListContainer"

View File

@ -71,7 +71,7 @@
</androidx.appcompat.widget.Toolbar>
<!-- Trick to remove surrounding padding (clip frome wrapping frame) -->
<!-- Trick to remove surrounding padding (clip from wrapping frame) -->
<FrameLayout
android:id="@+id/syncProgressBarWrap"
android:layout_width="match_parent"
@ -83,17 +83,29 @@
tools:visibility="visible">
<ProgressBar
android:id="@+id/syncProgressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="14dp"
android:layout_gravity="center"
android:background="?riotx_header_panel_background"
android:indeterminate="true"
android:visibility="gone"
tools:visibility="visible" />
android:indeterminate="true" />
</FrameLayout>
<TextView
android:id="@+id/noNetworkBanner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/vector_warning_color"
android:gravity="center"
android:text="@string/no_network_indicator"
android:textColor="@color/white"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/syncProgressBarWrap"
tools:visibility="visible" />
<com.airbnb.epoxy.EpoxyRecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp"
@ -102,7 +114,7 @@
app:layout_constraintBottom_toTopOf="@+id/recyclerViewBarrier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/syncProgressBarWrap"
app:layout_constraintTop_toBottomOf="@id/noNetworkBanner"
tools:listitem="@layout/item_timeline_event_base" />
<androidx.constraintlayout.widget.Barrier