Skip to content

Commit 51c5206

Browse files
authored
Merge pull request #19624 from wordpress-mobile/merge/23.6-final-to-trunk
Merge 23.6 final to trunk
2 parents 66a2015 + e2e1a1a commit 51c5206

102 files changed

Lines changed: 2239 additions & 1583 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment),
382382
private fun MySiteFragmentBinding.setupObservers() {
383383
viewModel.uiModel.observe(viewLifecycleOwner) { uiModel ->
384384
hideRefreshIndicatorIfNeeded()
385-
when (val state = uiModel) {
386-
is State.SiteSelected -> loadData(state)
387-
is State.NoSites -> loadEmptyView(state)
385+
when (uiModel) {
386+
is State.SiteSelected -> loadData(uiModel)
387+
is State.NoSites -> loadEmptyView(uiModel)
388388
}
389389
}
390390
viewModel.onBasicDialogShown.observeEvent(viewLifecycleOwner) { model ->
@@ -523,6 +523,7 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment),
523523
private fun MySiteFragmentBinding.loadData(state: State.SiteSelected) {
524524
appbarMain.visibility = View.VISIBLE
525525
siteInfo.loadMySiteDetails(state.siteInfoHeader)
526+
appbarMain.setExpanded(true, true)
526527

527528
recyclerView.setVisible(true)
528529
(recyclerView.adapter as? MySiteAdapter)?.submitList(state.dashboardData)
@@ -560,10 +561,14 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment),
560561
siteInfoContainer.subtitle.text = siteInfoHeader.url
561562
siteInfoContainer.subtitle.setOnClickListener { siteInfoHeader.onUrlClick.click() }
562563
switchSite.setOnClickListener { siteInfoHeader.onSwitchSiteClick.click() }
564+
siteInfoCard.visibility = View.VISIBLE
563565
}
564566

565567

566568
private fun MySiteFragmentBinding.loadEmptyView(state: State.NoSites) {
569+
recyclerView.setVisible(false)
570+
siteInfo.siteInfoCard.setVisible(false)
571+
567572
if (!noSitesView.actionableEmptyView.isVisible) {
568573
noSitesView.actionableEmptyView.setVisible(true)
569574
noSitesView.actionableEmptyView.image.setVisible(state.shouldShowImage)
@@ -715,7 +720,7 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment),
715720
action.activityId,
716721
action.isRewindable
717722
)
718-
is SiteNavigationAction.TriggerCreatePageFlow -> Unit // no-op
723+
is SiteNavigationAction.TriggerCreatePageFlow -> wpMainActivityViewModel.triggerCreatePageFlow()
719724
is SiteNavigationAction.OpenPagesDraftsTab -> ActivityLauncher.viewCurrentBlogPagesOfType(
720725
requireActivity(),
721726
action.site,

WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class MySiteViewModel @Inject constructor(
267267
}
268268

269269
val uiModel: LiveData<State> = merge(state, quickLinks) { cards, quickLinks ->
270-
val nonNullCards = cards ?: return@merge buildNoSiteState(cards?.currentAvatarUrl, cards?.avatarName)
270+
val nonNullCards = cards ?: return@merge buildNoSiteState(null, null)
271271
with(nonNullCards) {
272272
val state = if (site != null) {
273273
cardsUpdate?.checkAndShowSnackbarError()
@@ -360,7 +360,7 @@ class MySiteViewModel @Inject constructor(
360360
getPositionOfQuickStartItem(siteItems)
361361
)
362362
}
363-
// It is okay to use !! here because we are explicitly creating the lists
363+
364364
return SiteSelected(
365365
siteInfoHeader = siteInfo,
366366
dashboardData = siteItems

WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksitem/QuickLinksItemViewModelSlice.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import kotlinx.coroutines.CoroutineScope
77
import kotlinx.coroutines.launch
88
import org.wordpress.android.R
99
import org.wordpress.android.analytics.AnalyticsTracker
10+
import org.wordpress.android.fluxc.model.SiteModel
1011
import org.wordpress.android.fluxc.store.QuickStartStore
1112
import org.wordpress.android.modules.BG_THREAD
1213
import org.wordpress.android.ui.blaze.BlazeFeatureUtils
@@ -76,14 +77,14 @@ class QuickLinksItemViewModelSlice @Inject constructor(
7677
site()?.let { site ->
7778
jetpackCapabilitiesUseCase.getJetpackPurchasedProducts(site.siteId).collect {
7879
_uiState.postValue(
79-
convertToQuickLinkRibbonItem(
80+
convertToQuickLinkRibbonItem(site,
8081
siteItemsBuilder.build(
8182
MySiteCardAndItemBuilderParams.SiteItemsBuilderParams(
8283
site = site,
8384
enableFocusPoints = true,
8485
activeTask = null,
8586
onClick = this@QuickLinksItemViewModelSlice::onClick,
86-
isBlazeEligible = isSiteBlazeEligible(),
87+
isBlazeEligible = isSiteBlazeEligible(site),
8788
backupAvailable = it.backup,
8889
scanAvailable = (it.scan && !site.isWPCom && !site.isWPComAtomic)
8990
)
@@ -96,9 +97,10 @@ class QuickLinksItemViewModelSlice @Inject constructor(
9697
}
9798

9899
private fun convertToQuickLinkRibbonItem(
100+
site: SiteModel,
99101
listItems: List<MySiteCardAndItem>,
100102
): MySiteCardAndItem.Card.QuickLinksItem {
101-
val siteId = selectedSiteRepository.getSelectedSite()!!.siteId
103+
val siteId = site.siteId
102104
val activeListItems = listItems.filterIsInstance(MySiteCardAndItem.Item.ListItem::class.java)
103105
.filter { isActiveQuickLink(it.listItemAction, siteId = siteId) }
104106
val activeQuickLinks = activeListItems.map { listItem ->
@@ -122,8 +124,8 @@ class QuickLinksItemViewModelSlice @Inject constructor(
122124
)
123125
}
124126

125-
private fun isSiteBlazeEligible() =
126-
blazeFeatureUtils.isSiteBlazeEligible(selectedSiteRepository.getSelectedSite()!!)
127+
private fun isSiteBlazeEligible(site: SiteModel) =
128+
blazeFeatureUtils.isSiteBlazeEligible(site)
127129

128130

129131
private fun onClick(action: ListItemAction) {

WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.wordpress.android.ui.mysite.menu
22

33
import android.annotation.SuppressLint
4+
import android.content.Intent
45
import android.os.Bundle
56
import android.view.LayoutInflater
67
import android.view.View
@@ -61,6 +62,7 @@ import org.wordpress.android.ui.compose.utils.uiStringText
6162
import org.wordpress.android.ui.mysite.SiteNavigationAction
6263
import org.wordpress.android.ui.mysite.items.listitem.ListItemAction
6364
import org.wordpress.android.ui.pages.SnackbarMessageHolder
65+
import org.wordpress.android.ui.prefs.SiteSettingsFragment
6466
import org.wordpress.android.ui.quickstart.QuickStartMySitePrompts
6567
import org.wordpress.android.ui.utils.ListItemInteraction
6668
import org.wordpress.android.ui.utils.UiString
@@ -103,10 +105,19 @@ class MenuActivity : AppCompatActivity() {
103105
}
104106
}
105107

108+
@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION")
109+
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
110+
super.onActivityResult(requestCode, resultCode, data)
111+
if (resultCode == SiteSettingsFragment.RESULT_BLOG_REMOVED) {
112+
viewModel.handleSiteRemoved()
113+
}
114+
}
115+
106116
private fun initObservers() {
107117
viewModel.navigation.observe(this) { handleNavigationAction(it.getContentIfNotHandled()) }
108118
viewModel.onSnackbarMessage.observe(this) { showSnackbar(it.getContentIfNotHandled()) }
109119
viewModel.onQuickStartMySitePrompts.observe(this) { handleActiveTutorialPrompt(it.getContentIfNotHandled()) }
120+
viewModel.onSelectedSiteMissing.observe(this) { finish() }
110121

111122
// Set the Compose callback for SnackbarSequencer
112123
snackbarSequencer.setComposeSnackbarCallback { item ->

WordPress/src/main/java/org/wordpress/android/ui/mysite/menu/MenuViewModel.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ class MenuViewModel @Inject constructor(
7575
private val _snackbar = MutableSharedFlow<SnackbarMessage>()
7676
val snackBar = _snackbar.asSharedFlow()
7777

78+
79+
private val _onSelectedSiteMissing = MutableLiveData<Unit>()
80+
val onSelectedSiteMissing = _onSelectedSiteMissing as LiveData<Unit>
81+
7882
private var quickStartEvent: QuickStartEvent? = null
7983
private var isStarted = false
8084

@@ -86,7 +90,13 @@ class MenuViewModel @Inject constructor(
8690
if (isStarted) {
8791
return
8892
}
89-
val site = selectedSiteRepository.getSelectedSite()!!
93+
94+
val site = selectedSiteRepository.getSelectedSite()
95+
if (site == null) {
96+
_onSelectedSiteMissing.value = Unit
97+
return
98+
}
99+
90100
this.quickStartEvent = quickStartEvent
91101
if (quickStartEvent != null) {
92102
quickStartRepository.setActiveTask(quickStartEvent.task, true)
@@ -272,6 +282,12 @@ class MenuViewModel @Inject constructor(
272282
removeFocusPoints()
273283
}
274284

285+
fun handleSiteRemoved() {
286+
selectedSiteRepository.removeSite()
287+
_onSelectedSiteMissing.value = Unit
288+
return
289+
}
290+
275291
data class SnackbarMessage(
276292
val message: String,
277293
val actionLabel: String? = null,

WordPress/src/main/java/org/wordpress/android/ui/mysite/personalization/DashboardCardPersonalizationViewModelSlice.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DashboardCardPersonalizationViewModelSlice @Inject constructor(
6161
}
6262

6363
private suspend fun getBloggingPromptCardState(): DashboardCardState? {
64-
return if (bloggingPromptsSettingsHelper.shouldShowPromptsFeature()) {
64+
return if (bloggingPromptsSettingsHelper.shouldShowPromptsSetting()) {
6565
DashboardCardState(
6666
title = R.string.personalization_screen_blogging_prompts_card_title,
6767
description = R.string.personalization_screen_blogging_prompts_card_description,
@@ -179,9 +179,12 @@ class DashboardCardPersonalizationViewModelSlice @Inject constructor(
179179

180180
private fun updateCardState(cardType: CardType, enabled: Boolean) {
181181
val currentCards: MutableList<DashboardCardState> = _uiState.value!!.toMutableList()
182-
val updated = currentCards.find { it.cardType == cardType }!!.copy(enabled = enabled)
183-
currentCards[cardType.order] = updated
184-
_uiState.postValue(currentCards)
182+
val cardIndex = currentCards.indexOfFirst { it.cardType == cardType }
183+
if (cardIndex != -1) {
184+
val updated = currentCards[cardIndex].copy(enabled = enabled)
185+
currentCards[cardIndex] = updated
186+
_uiState.postValue(currentCards)
187+
}
185188
}
186189

187190
private fun isStatsCardShown(siteId: Long) = !appPrefsWrapper.getShouldHideTodaysStatsDashboardCard(siteId)

WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SiteCreationPreviewFragment.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import android.view.View.OnLayoutChangeListener
1414
import android.view.animation.DecelerateInterpolator
1515
import androidx.appcompat.app.AppCompatActivity
1616
import androidx.core.content.ContextCompat
17+
import androidx.core.view.isVisible
1718
import androidx.fragment.app.activityViewModels
1819
import dagger.hilt.android.AndroidEntryPoint
1920
import org.wordpress.android.R
@@ -85,7 +86,8 @@ class SiteCreationPreviewFragment : SiteCreationBaseFormFragment(),
8586
viewModel.uiState.observe(this@SiteCreationPreviewFragment) {
8687
it?.let { ui ->
8788
uiHelpers.setTextOrHide(siteCreationPreviewHeaderItem.sitePreviewSubtitle, ui.subtitle)
88-
uiHelpers.setTextOrHide(sitePreviewCaption, ui.caption)
89+
uiHelpers.setTextOrHide(sitePreviewCaptionText, ui.caption)
90+
sitePreviewCaption.isVisible = ui.caption != null
8991
updateContentLayout(ui.urlData, isFirstContent = ui is SitePreviewLoadingShimmerState)
9092
siteCreationPreviewWebViewContainer.apply {
9193
uiHelpers.updateVisibility(sitePreviewWebView, ui.webViewVisibility)

WordPress/src/main/res/layout-land/site_creation_preview_screen_default.xml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
45
android:id="@+id/content_layout"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent"
@@ -23,12 +24,28 @@
2324
android:id="@+id/site_creation_preview_header_item"
2425
layout="@layout/site_creation_preview_header_item" />
2526

26-
<TextView
27+
<com.google.android.material.card.MaterialCardView
2728
android:id="@+id/sitePreviewCaption"
28-
style="@style/SiteCreationHeaderV2Subtitle"
29-
android:lineSpacingExtra="@null"
30-
android:paddingBottom="@null"
31-
android:text="@string/new_site_creation_preview_caption_paid" />
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
android:layout_marginTop="@dimen/margin_large"
32+
app:cardBackgroundColor="@color/dashboard_card_plans_info_background"
33+
app:cardCornerRadius="8dp">
34+
35+
<TextView
36+
android:id="@+id/sitePreviewCaptionText"
37+
android:layout_width="match_parent"
38+
android:layout_height="wrap_content"
39+
android:drawablePadding="@dimen/margin_extra_large"
40+
android:padding="@dimen/margin_extra_large"
41+
android:text="@string/new_site_creation_preview_caption_paid"
42+
android:textAlignment="viewStart"
43+
android:textColor="@color/dashboard_card_plans_info_text_color"
44+
android:textSize="@dimen/text_sz_small"
45+
app:drawableStartCompat="@drawable/ic_info_outline_grey_dark_24dp"
46+
app:drawableTint="@color/gray_20" />
47+
48+
</com.google.android.material.card.MaterialCardView>
3249

3350
<com.google.android.material.button.MaterialButton
3451
android:id="@+id/okButton"

WordPress/src/main/res/layout/site_creation_preview_screen_default.xml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,39 @@
1616
android:layout_marginHorizontal="@dimen/margin_extra_large"
1717
android:layout_marginVertical="@dimen/margin_large" />
1818

19+
<com.google.android.material.card.MaterialCardView
20+
android:id="@+id/sitePreviewCaption"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content"
23+
android:layout_below="@id/site_creation_preview_header_item"
24+
android:layout_marginHorizontal="@dimen/margin_extra_large"
25+
app:cardBackgroundColor="@color/dashboard_card_plans_info_background"
26+
app:cardCornerRadius="8dp">
27+
28+
<TextView
29+
android:id="@+id/sitePreviewCaptionText"
30+
android:layout_width="match_parent"
31+
android:layout_height="wrap_content"
32+
android:drawablePadding="@dimen/margin_extra_large"
33+
android:padding="@dimen/margin_extra_large"
34+
android:text="@string/new_site_creation_preview_caption_paid"
35+
android:textAlignment="viewStart"
36+
android:textColor="@color/dashboard_card_plans_info_text_color"
37+
android:textSize="@dimen/text_sz_small"
38+
app:drawableStartCompat="@drawable/ic_info_outline_grey_dark_24dp"
39+
app:drawableTint="@color/gray_20" />
40+
41+
</com.google.android.material.card.MaterialCardView>
42+
1943
<include
2044
android:id="@+id/site_creation_preview_web_view_container"
2145
layout="@layout/site_creation_preview_web_view_container"
2246
android:layout_width="match_parent"
2347
android:layout_height="match_parent"
24-
android:layout_above="@+id/sitePreviewCaption"
25-
android:layout_below="@id/site_creation_preview_header_item"
26-
android:layout_marginHorizontal="@dimen/margin_extra_large" />
27-
28-
<TextView
29-
android:id="@+id/sitePreviewCaption"
30-
style="@style/SiteCreationHeaderV2Subtitle"
31-
android:layout_above="@+id/sitePreviewOkButtonContainer"
32-
android:lineSpacingExtra="@null"
48+
android:layout_above="@id/sitePreviewOkButtonContainer"
49+
android:layout_below="@id/sitePreviewCaption"
3350
android:layout_marginHorizontal="@dimen/margin_extra_large"
34-
android:layout_marginTop="@dimen/margin_large"
35-
android:paddingBottom="@null"
36-
android:text="@string/new_site_creation_preview_caption_paid" />
51+
android:layout_marginTop="@dimen/margin_large" />
3752

3853
<com.google.android.material.card.MaterialCardView
3954
android:id="@+id/sitePreviewOkButtonContainer"

0 commit comments

Comments
 (0)