Skip to content

Commit

Permalink
Merge pull request #21287 from wordpress-mobile/issue/21283-no-connec…
Browse files Browse the repository at this point in the history
…tion-message

Issue/21283 no connection message
  • Loading branch information
nbradbury authored Oct 8, 2024
2 parents 1281a8b + d1699b2 commit e3de8c4
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class GifMediaDataSource

if (!networkUtilsWrapper.isNetworkAvailable()) {
return Failure(
UiStringRes(R.string.no_network_title),
htmlSubtitle = UiStringRes(R.string.no_network_message),
UiStringRes(R.string.no_network_message),
image = R.drawable.img_illustration_cloud_off_152dp,
data = items
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class MediaLibraryDataSource(
): MediaLoadingResult {
if (!networkUtilsWrapper.isNetworkAvailable()) {
return Failure(
UiStringRes(R.string.no_network_title),
htmlSubtitle = UiStringRes(R.string.no_network_message),
UiStringRes(R.string.no_network_message),
image = R.drawable.img_illustration_cloud_off_152dp,
data = if (loadMore) get(mediaTypes, filter) else listOf()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class StockMediaDataSource
): MediaLoadingResult {
if (!networkUtilsWrapper.isNetworkAvailable()) {
return Failure(
UiStringRes(R.string.no_network_title),
htmlSubtitle = UiStringRes(R.string.no_network_message),
UiStringRes(R.string.no_network_message),
image = R.drawable.img_illustration_cloud_off_152dp,
data = if (loadMore) get() else listOf()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand All @@ -30,6 +32,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -114,46 +117,53 @@ fun LargeAvatar(avatarUrl: String) {
* A composable that displays a message when there is no network connection
*/
@Composable
fun OfflineView() {
fun OfflineView(
onRetryClick: (() -> Unit)? = null,
) {
MessageView(
R.drawable.ic_wifi_off_24px,
R.string.no_network_title,
R.string.no_network_message,
imageRes = R.drawable.img_illustration_cloud_off_152dp,
messageRes = R.string.no_network_message,
buttonRes = R.string.retry,
onButtonClick = onRetryClick
)
}

/**
* A composable that displays a title with an icon above it and an optional subtitle below it
* A composable that displays a message with an image above it and an optional button below it
*/
@Composable
fun MessageView(
@DrawableRes iconRes: Int,
@StringRes titleRes: Int,
@StringRes subtitleRes: Int? = null,
@DrawableRes imageRes: Int,
@StringRes messageRes: Int,
@StringRes buttonRes: Int? = null,
onButtonClick: (() -> Unit)? = null,
) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
Icon(
imageVector = ImageVector.vectorResource(iconRes),
imageVector = ImageVector.vectorResource(imageRes),
tint = colorResource(R.color.neutral_30),
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurface,
modifier = Modifier
.size(85.dp)
)
Text(
text = stringResource(titleRes),
text = stringResource(messageRes),
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.padding(top = 16.dp),
)
if (subtitleRes != null) {
Text(
text = stringResource(subtitleRes),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurface,
)
if (buttonRes != null && onButtonClick != null) {
Button(
modifier = Modifier.padding(top = 16.dp),
shape = RoundedCornerShape(2.dp),
onClick = onButtonClick,
) {
Text(
text = stringResource(R.string.retry).uppercase(),
)
}
}
}
}
Expand Down Expand Up @@ -214,12 +224,14 @@ fun ScreenWithTopBar(
)
private fun OfflineScreenPreview() {
val content: @Composable () -> Unit = @Composable {
OfflineView()
OfflineView(
onRetryClick = {}
)
}
ScreenWithTopBar(
title = "Title",
content = content,
onCloseClick = {},
isScrollable = false
isScrollable = false,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class SelfHostedUsersActivity : LocaleAwareActivity() {
},
onUserAvatarClick = { avatarUrl ->
viewModel.onUserAvatarClick(avatarUrl)
},
onRetryClick = {
viewModel.onRetryClick()
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fun SelfHostedUsersScreen(
onCloseClick: () -> Unit = {},
onUserClick: (UserWithEditContext) -> Unit = {},
onUserAvatarClick: (avatarUrl: String?) -> Unit = {},
onRetryClick: () -> Unit = {},
) {
val state = uiState.collectAsState().value

Expand Down Expand Up @@ -89,8 +90,8 @@ fun SelfHostedUsersScreen(

is SelfHostedUserState.EmptyUserList -> {
MessageView(
R.drawable.ic_people_white_24dp,
R.string.no_users,
imageRes = R.drawable.ic_people_white_24dp,
messageRes = R.string.no_users,
)
}

Expand All @@ -106,7 +107,9 @@ fun SelfHostedUsersScreen(
}

is SelfHostedUserState.Offline -> {
OfflineView()
OfflineView(
onRetryClick = onRetryClick
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ class SelfHostedUsersViewModel @Inject constructor(
}
}

/**
* Called when the retry button is clicked
*/
fun onRetryClick() {
_uiState.value = SelfHostedUserState.Loading
fetchUsers()
}

sealed class SelfHostedUserState {
data object Loading : SelfHostedUserState()
data object Offline : SelfHostedUserState()
Expand Down
2 changes: 1 addition & 1 deletion WordPress/src/main/res/layout/actionable_empty_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_extra_large"
android:adjustViewBounds="true"
android:contentDescription="@string/content_description_person_reading_device_notification"
android:contentDescription="@null"
android:visibility="gone" />

<ProgressBar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ class GifMediaDataSourceTest : BaseUnitTest() {
val result = gifMediaDataSource.load(forced = false, loadMore = false, filter = filter)

(result as MediaLoadingResult.Failure).apply {
Assertions.assertThat((this.title as UiStringRes).stringRes).isEqualTo(R.string.no_network_title)
Assertions.assertThat(this.htmlSubtitle).isEqualTo(UiStringRes(R.string.no_network_message))
Assertions.assertThat((this.title as UiStringRes).stringRes).isEqualTo(R.string.no_network_message)
Assertions.assertThat(this.image).isEqualTo(R.drawable.img_illustration_cloud_off_152dp)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ class MediaLibraryDataSourceTest : BaseUnitTest() {

val result = dataSource.load(forced = false, loadMore = false, filter = null) as Failure

assertThat(result.title).isEqualTo(UiStringRes(R.string.no_network_title))
assertThat(result.htmlSubtitle).isEqualTo(UiStringRes(R.string.no_network_message))
assertThat(result.title).isEqualTo(UiStringRes(R.string.no_network_message))
assertThat(result.image).isEqualTo(R.drawable.img_illustration_cloud_off_152dp)
assertThat(result.data).isEmpty()
}
Expand All @@ -96,8 +95,7 @@ class MediaLibraryDataSourceTest : BaseUnitTest() {

val result = dataSource.load(forced = false, loadMore = true, filter = null) as Failure

assertThat(result.title).isEqualTo(UiStringRes(R.string.no_network_title))
assertThat(result.htmlSubtitle).isEqualTo(UiStringRes(R.string.no_network_message))
assertThat(result.title).isEqualTo(UiStringRes(R.string.no_network_message))
assertThat(result.image).isEqualTo(R.drawable.img_illustration_cloud_off_152dp)
assertThat(result.data).hasSize(1)
result.data.assertContains(mediaModel, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ class StockMediaDataSourceTest : BaseUnitTest() {
val result = stockMediaDataSource.load(forced = false, loadMore = false, filter = filter)

(result as MediaLoadingResult.Failure).apply {
assertThat((this.title as UiStringRes).stringRes).isEqualTo(R.string.no_network_title)
assertThat(this.htmlSubtitle).isEqualTo(UiStringRes(R.string.no_network_message))
assertThat((this.title as UiStringRes).stringRes).isEqualTo(R.string.no_network_message)
assertThat(this.image).isEqualTo(R.drawable.img_illustration_cloud_off_152dp)
}
verifyNoInteractions(stockMediaStore)
Expand Down

0 comments on commit e3de8c4

Please sign in to comment.