Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class ApplicationPasswordsListActivity : BaseAppCompatActivity() {
onSortOrderClick = { order ->
viewModel.onSortOrderClick(order)
},
emptyView = viewModel.emptyView,
modifier = modifier
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import org.wordpress.android.ui.compose.components.EmptyContentM3
import org.wordpress.android.ui.dataview.DummyDataViewItems.getDummyDataViewItems
import uniffi.wp_api.WpApiParamOrder
import java.util.Locale
import org.wordpress.android.ui.dataview.DataViewViewModel.DataViewEmptyView

/**
* Provides a basic screen for displaying a list of [DataViewItem]s
Expand All @@ -68,7 +69,8 @@ fun DataViewScreen(
onSortOrderClick: (WpApiParamOrder) -> Unit,
onRefresh: () -> Unit,
onFetchMore: () -> Unit,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
emptyView: DataViewEmptyView = DataViewEmptyView(),
) {
val pullToRefreshState = rememberPullToRefreshState()

Expand Down Expand Up @@ -107,7 +109,7 @@ fun DataViewScreen(

when (uiState.value.loadingState) {
LoadingState.LOADING -> LoadingDataView()
LoadingState.EMPTY -> EmptyDataView()
LoadingState.EMPTY -> EmptyDataView(emptyView)
LoadingState.EMPTY_SEARCH -> EmptySearchDataView()
LoadingState.ERROR -> ErrorDataView(uiState.value.errorMessage)
LoadingState.OFFLINE -> OfflineDataView()
Expand All @@ -116,7 +118,7 @@ fun DataViewScreen(
items = uiState.value.items,
onItemClick = onItemClick,
onFetchMore = onFetchMore,
showProgress = uiState.value.loadingState == LoadingState.LOADING_MORE
showProgress = uiState.value.loadingState == LoadingState.LOADING_MORE,
)
}
}
Expand All @@ -137,7 +139,7 @@ private fun SearchAndFilterBar(
supportedSorts: List<DataViewDropdownItem>,
) {
var searchQuery by remember { mutableStateOf("") }

// Sync local search query with the current search query from UI state
LaunchedEffect(currentSearchQuery) {
searchQuery = currentSearchQuery
Expand Down Expand Up @@ -432,16 +434,18 @@ private fun LoadingDataView() {
}

@Composable
private fun EmptyDataView() {
private fun EmptyDataView(
emptyView: DataViewEmptyView
) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
EmptyContentM3(
title = stringResource(R.string.subscribers_empty),
image = R.drawable.img_jetpack_empty_state,
imageContentDescription = stringResource(R.string.subscribers_empty),
title = stringResource(emptyView.messageRes),
image = emptyView.imageRes,
imageContentDescription = stringResource(emptyView.messageRes),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.wordpress.android.ui.dataview

import android.content.SharedPreferences
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.content.edit
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
Expand All @@ -11,6 +13,7 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.withContext
import org.wordpress.android.R
import org.wordpress.android.fluxc.store.AccountStore
import org.wordpress.android.fluxc.utils.AppLogWrapper
import org.wordpress.android.modules.IO_THREAD
Expand Down Expand Up @@ -46,6 +49,8 @@ open class DataViewViewModel @Inject constructor(

private val debouncedQuery = MutableStateFlow("")

open val emptyView = DataViewEmptyView()

private fun updateState(update: (DataViewUiState) -> DataViewUiState) {
_uiState.update { update(it) }
}
Expand Down Expand Up @@ -315,6 +320,11 @@ open class DataViewViewModel @Inject constructor(
FILTER,
}

class DataViewEmptyView(
@StringRes val messageRes: Int = R.string.dataview_default_empty_message,
@DrawableRes val imageRes: Int = R.drawable.img_jetpack_empty_state,
)

companion object {
private const val SEARCH_DELAY_MS = 500L
const val PAGE_SIZE = 25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class SubscribersActivity : BaseAppCompatActivity() {
onSortOrderClick = { order ->
viewModel.onSortOrderClick(order)
},
emptyView = viewModel.emptyView,
modifier = modifier
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class SubscribersViewModel @Inject constructor(

private var statsJob: Job? = null

override val emptyView = DataViewEmptyView(
messageRes = R.string.subscribers_empty,
imageRes = R.drawable.img_jetpack_empty_state
)

@Inject
lateinit var dateFormatWrapper: SimpleDateFormatWrapper

Expand Down
3 changes: 3 additions & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5071,4 +5071,7 @@ translators: %s: Select control option value e.g: "Auto, 25%". -->
<string name="application_password_name_sort">Name</string>
<string name="application_password_created_sort">Created</string>
<string name="application_password_last_used_sort">Last used</string>

<!-- DataView -->
<string name="dataview_default_empty_message">There\'s nothing here</string>
</resources>