-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue/11750 dashboard big screen support #13488
Open
JorgeMucientes
wants to merge
14
commits into
trunk
Choose a base branch
from
issue/11750-dashboard-big-screen-support
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+252
−159
Open
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9939969
Adds grid layout for bigger screens
JorgeMucientes 83227a1
Extract dashboard container out of the xml NestedScroll and SwipeToRe…
JorgeMucientes 0eca83c
Add a composable implementation of swipe to refresh
JorgeMucientes 2b7fbfc
Clean xml layout and ensure we keep the same logic in the DashboardFr…
JorgeMucientes 8d9bedf
Merge branch 'trunk' into issue/11750-dashboard-big-screen-support
JorgeMucientes 86bb062
Merge branch 'trunk' into issue/11750-dashboard-big-screen-support
JorgeMucientes 4bbe083
Refactor: Adapt Dashboard card columns to Window Size Classes
JorgeMucientes c72ece0
Fix unit tests after adding composable pull to refresh implementation
JorgeMucientes 3189ad8
Remove animation when cards are displayed in multiple columns
JorgeMucientes 5244644
Update release notes
JorgeMucientes 8c52d0c
Adjust dashboard card paddings
JorgeMucientes 581d2e9
Fix the unexisting UI component reference.
pachlava 42aa734
Merge branch 'trunk' into issue/11750-dashboard-big-screen-support
JorgeMucientes 3259fb8
Update release notes
JorgeMucientes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,34 +5,50 @@ | |
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.pullrefresh.PullRefreshIndicator | ||
import androidx.compose.material.pullrefresh.pullRefresh | ||
import androidx.compose.material.pullrefresh.rememberPullRefreshState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.livedata.observeAsState | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.input.nestedscroll.nestedScroll | ||
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.res.dimensionResource | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.window.core.layout.WindowSizeClass | ||
import androidx.window.core.layout.WindowWidthSizeClass | ||
import com.woocommerce.android.R | ||
import com.woocommerce.android.model.DashboardWidget | ||
import com.woocommerce.android.ui.blaze.creation.BlazeCampaignCreationDispatcher | ||
import com.woocommerce.android.ui.compose.component.WCColoredButton | ||
import com.woocommerce.android.ui.compose.component.WCOutlinedButton | ||
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardEvent.OpenRangePicker | ||
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardWidgetUiModel | ||
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardWidgetUiModel.ConfigurableWidget | ||
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardWidgetUiModel.FeedbackWidget | ||
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardWidgetUiModel.NewWidgetsCard | ||
import com.woocommerce.android.ui.dashboard.DashboardViewModel.DashboardWidgetUiModel.ShareStoreWidget | ||
import com.woocommerce.android.ui.dashboard.blaze.DashboardBlazeCard | ||
import com.woocommerce.android.ui.dashboard.coupons.DashboardCouponsCard | ||
import com.woocommerce.android.ui.dashboard.google.DashboardGoogleAdsCard | ||
|
@@ -45,81 +61,166 @@ | |
import com.woocommerce.android.ui.dashboard.topperformers.DashboardTopPerformersWidgetCard | ||
import com.woocommerce.android.ui.main.MainActivityViewModel | ||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
fun DashboardContainer( | ||
mainActivityViewModel: MainActivityViewModel, | ||
dashboardViewModel: DashboardViewModel, | ||
blazeCampaignCreationDispatcher: BlazeCampaignCreationDispatcher | ||
blazeCampaignCreationDispatcher: BlazeCampaignCreationDispatcher, | ||
windowSizeClass: WindowSizeClass, | ||
) { | ||
dashboardViewModel.dashboardWidgets.observeAsState().value?.let { widgets -> | ||
WidgetList( | ||
widgetUiModels = widgets, | ||
mainActivityViewModel = mainActivityViewModel, | ||
dashboardViewModel = dashboardViewModel, | ||
blazeCampaignCreationDispatcher = blazeCampaignCreationDispatcher | ||
) | ||
dashboardViewModel.dashboardCardsState.observeAsState().value?.let { state -> | ||
|
||
val pullRefreshState = rememberPullRefreshState(state.isRefreshing, dashboardViewModel::onPullToRefresh) | ||
Box(Modifier.pullRefresh(pullRefreshState)) { | ||
DashboardWidgets( | ||
widgetUiModels = state.widgets, | ||
mainActivityViewModel = mainActivityViewModel, | ||
dashboardViewModel = dashboardViewModel, | ||
blazeCampaignCreationDispatcher = blazeCampaignCreationDispatcher, | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(MaterialTheme.colors.surface) | ||
.padding(vertical = dimensionResource(id = R.dimen.major_100)), | ||
numberOfColumns = when (windowSizeClass.windowWidthSizeClass) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
WindowWidthSizeClass.COMPACT -> 1 | ||
WindowWidthSizeClass.MEDIUM -> 2 | ||
WindowWidthSizeClass.EXPANDED -> 3 | ||
else -> 1 | ||
} | ||
) | ||
|
||
PullRefreshIndicator( | ||
refreshing = state.isRefreshing, | ||
state = pullRefreshState, | ||
modifier = Modifier.align(Alignment.TopCenter), | ||
contentColor = MaterialTheme.colors.primary, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun WidgetList( | ||
widgetUiModels: List<DashboardViewModel.DashboardWidgetUiModel>, | ||
private fun DashboardWidgets( | ||
widgetUiModels: List<DashboardWidgetUiModel>, | ||
mainActivityViewModel: MainActivityViewModel, | ||
dashboardViewModel: DashboardViewModel, | ||
blazeCampaignCreationDispatcher: BlazeCampaignCreationDispatcher | ||
blazeCampaignCreationDispatcher: BlazeCampaignCreationDispatcher, | ||
modifier: Modifier = Modifier, | ||
numberOfColumns: Int = 1 | ||
) { | ||
Column( | ||
verticalArrangement = Arrangement.spacedBy(dimensionResource(id = R.dimen.major_100)), | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(MaterialTheme.colors.surface) | ||
.padding(vertical = dimensionResource(id = R.dimen.major_100)) | ||
) { | ||
val widgetModifier = Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = 16.dp) | ||
widgetUiModels.forEach { | ||
AnimatedVisibility(it.isVisible) { | ||
when (it) { | ||
is DashboardViewModel.DashboardWidgetUiModel.ConfigurableWidget -> { | ||
ConfigurableWidgetCard( | ||
widgetUiModel = it, | ||
mainActivityViewModel = mainActivityViewModel, | ||
dashboardViewModel = dashboardViewModel, | ||
blazeCampaignCreationDispatcher = blazeCampaignCreationDispatcher, | ||
modifier = widgetModifier | ||
) | ||
} | ||
val widgetModifier = Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = 16.dp) | ||
val nestedScrollInterop = rememberNestedScrollInteropConnection() | ||
|
||
is DashboardViewModel.DashboardWidgetUiModel.ShareStoreWidget -> { | ||
ShareStoreCard( | ||
onShareClicked = it.onShareClicked, | ||
modifier = widgetModifier | ||
) | ||
} | ||
|
||
is DashboardViewModel.DashboardWidgetUiModel.FeedbackWidget -> { | ||
FeedbackCard( | ||
widget = it, | ||
modifier = widgetModifier | ||
) | ||
} | ||
|
||
is DashboardViewModel.DashboardWidgetUiModel.NewWidgetsCard -> { | ||
NewWidgetsCard( | ||
state = it, | ||
modifier = widgetModifier | ||
) | ||
if (numberOfColumns == 1) { | ||
Column( | ||
modifier = modifier | ||
.nestedScroll(nestedScrollInterop) | ||
.verticalScroll(rememberScrollState()), | ||
verticalArrangement = Arrangement.spacedBy(16.dp), | ||
) { | ||
widgetUiModels.forEach { widget -> | ||
AnimatedVisibility(widget.isVisible) { | ||
DashboardWidgetCard( | ||
widget, | ||
mainActivityViewModel, | ||
dashboardViewModel, | ||
blazeCampaignCreationDispatcher, | ||
widgetModifier | ||
) | ||
} | ||
} | ||
} | ||
} else { | ||
val widgetColumns = splitWidgetsIntoColumns( | ||
numberOfColumns = numberOfColumns, | ||
visibleUiWidgets = widgetUiModels.filter { it.isVisible } | ||
) | ||
Row( | ||
modifier = modifier | ||
.nestedScroll(nestedScrollInterop) | ||
.verticalScroll(rememberScrollState()) | ||
) { | ||
widgetColumns.forEach { columnWidgets -> | ||
Column( | ||
modifier = Modifier.weight(1f), | ||
verticalArrangement = Arrangement.spacedBy(8.dp) | ||
) { | ||
columnWidgets.forEach { widget -> | ||
AnimatedVisibility(widget.isVisible) { | ||
DashboardWidgetCard( | ||
widget, | ||
mainActivityViewModel, | ||
dashboardViewModel, | ||
blazeCampaignCreationDispatcher, | ||
widgetModifier | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun splitWidgetsIntoColumns( | ||
numberOfColumns: Int, | ||
visibleUiWidgets: List<DashboardWidgetUiModel> | ||
): MutableList<MutableList<DashboardWidgetUiModel>> { | ||
val widgetColumns = MutableList<MutableList<DashboardWidgetUiModel>>(numberOfColumns) { mutableListOf() } | ||
for ((index, item) in visibleUiWidgets.withIndex()) { | ||
widgetColumns[index % numberOfColumns].add(item) | ||
} | ||
return widgetColumns | ||
} | ||
|
||
@Composable | ||
private fun DashboardWidgetCard( | ||
it: DashboardWidgetUiModel, | ||
mainActivityViewModel: MainActivityViewModel, | ||
dashboardViewModel: DashboardViewModel, | ||
blazeCampaignCreationDispatcher: BlazeCampaignCreationDispatcher, | ||
widgetModifier: Modifier | ||
Check warning Code scanning / Android Lint Guidelines for Modifier parameters in a Composable function Warning
Modifier parameter should be named modifier
|
||
) { | ||
when (it) { | ||
is ConfigurableWidget -> { | ||
ConfigurableWidgetCard( | ||
widgetUiModel = it, | ||
mainActivityViewModel = mainActivityViewModel, | ||
dashboardViewModel = dashboardViewModel, | ||
blazeCampaignCreationDispatcher = blazeCampaignCreationDispatcher, | ||
modifier = widgetModifier | ||
) | ||
} | ||
|
||
is ShareStoreWidget -> { | ||
ShareStoreCard( | ||
onShareClicked = it.onShareClicked, | ||
modifier = widgetModifier | ||
) | ||
} | ||
|
||
is FeedbackWidget -> { | ||
FeedbackCard( | ||
widget = it, | ||
modifier = widgetModifier | ||
) | ||
} | ||
|
||
is NewWidgetsCard -> { | ||
NewWidgetsCard( | ||
state = it, | ||
modifier = widgetModifier | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ConfigurableWidgetCard( | ||
widgetUiModel: DashboardViewModel.DashboardWidgetUiModel.ConfigurableWidget, | ||
widgetUiModel: DashboardWidgetUiModel.ConfigurableWidget, | ||
mainActivityViewModel: MainActivityViewModel, | ||
dashboardViewModel: DashboardViewModel, | ||
blazeCampaignCreationDispatcher: BlazeCampaignCreationDispatcher, | ||
|
@@ -227,7 +328,7 @@ | |
|
||
@Composable | ||
private fun FeedbackCard( | ||
widget: DashboardViewModel.DashboardWidgetUiModel.FeedbackWidget, | ||
widget: DashboardWidgetUiModel.FeedbackWidget, | ||
modifier: Modifier | ||
) { | ||
LaunchedEffect(Unit) { | ||
|
@@ -271,7 +372,7 @@ | |
|
||
@Composable | ||
private fun NewWidgetsCard( | ||
state: DashboardViewModel.DashboardWidgetUiModel.NewWidgetsCard, | ||
state: DashboardWidgetUiModel.NewWidgetsCard, | ||
modifier: Modifier | ||
) { | ||
Column( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this dependency to rely on official library to categorize screen size. We currently have a custom implmentation of WindowSizeClass but I think we should be using the official one. Also the custom implementation of
WindowSizeClass
currently only exposeswindowHeightSizeClass
but notwindowWidthSizeClass
. So instead of manually addingwindowWidthSizeClass
, I figured we could use the official size class library for it.