Skip to content

Commit e462819

Browse files
authored
Merge pull request #14812 from wordpress-mobile/feature/updates-to-site-store
Updates to site store
2 parents 309911a + e8e432e commit e462819

File tree

12 files changed

+33
-55
lines changed

12 files changed

+33
-55
lines changed

WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class JetpackRemoteInstallViewModel
139139
) {
140140
mutableActionOnResult.postValue(
141141
JetpackResultActionData(
142-
siteStore.getSiteByLocalId(siteId),
142+
siteStore.getSiteByLocalId(siteId)!!,
143143
hasAccessToken,
144144
action
145145
)

WordPress/src/main/java/org/wordpress/android/ui/posts/PublishSettingsViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ constructor(
190190
val description = resourceProvider.getString(
191191
R.string.calendar_scheduled_post_description,
192192
postRepository.title,
193-
site.name ?: site.url,
193+
site?.name ?: site?.url ?: "",
194194
postRepository.link
195195
)
196196
_onAddToCalendar.value = Event(CalendarEvent(title, description, startTime))

WordPress/src/main/java/org/wordpress/android/ui/posts/editor/StorePostViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class StorePostViewModel
8181
return if (networkUtils.isNetworkAvailable()) {
8282
postUtils.trackSavePostAnalytics(
8383
editPostRepository.getPost(),
84-
siteStore.getSiteByLocalId(editPostRepository.localSiteId)
84+
requireNotNull(siteStore.getSiteByLocalId(editPostRepository.localSiteId))
8585
)
8686
uploadService.uploadPost(context, editPostRepository.id, isFirstTimePublish)
8787
SAVED_ONLINE

WordPress/src/main/java/org/wordpress/android/ui/sitecreation/usecases/FetchDomainsUseCase.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,19 @@ class FetchDomainsUseCase @Inject constructor(
3838
includeDotBlog: Boolean = false,
3939
size: Int = FETCH_DOMAINS_SIZE
4040
): OnSuggestedDomains {
41-
val payload = SuggestDomainsPayload(
42-
query,
43-
segmentId,
44-
size,
45-
includeVendorDot
46-
)
47-
4841
/**
4942
* Depending on the payload the server may override the following values. Setting this values here to get
5043
* reasonable results in case SKIP button is pressed ("default" template)
5144
*/
52-
payload.includeWordpressCom = true
53-
payload.onlyWordpressCom = true
54-
payload.includeDotBlogSubdomain = includeDotBlog
45+
val payload = SuggestDomainsPayload(
46+
query = query,
47+
segmentId = segmentId,
48+
quantity = size,
49+
includeVendorDot = includeVendorDot,
50+
includeWordpressCom = true,
51+
onlyWordpressCom = true,
52+
includeDotBlogSubdomain = includeDotBlog
53+
)
5554

5655
return suspendCancellableCoroutine { cont ->
5756
pair = Pair(payload.query, cont)

WordPress/src/main/java/org/wordpress/android/viewmodel/domains/DomainRegistrationDetailsViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class DomainRegistrationDetailsViewModel @Inject constructor(
284284
val updatedSite = siteStore.getSiteByLocalId(site.id)
285285

286286
// New domain is not is not reflected in SiteModel yet, try refreshing a site until we get it
287-
if (updatedSite.url.endsWith(".wordpress.com") && siteCheckTries < MAX_SITE_CHECK_TRIES) {
287+
if (updatedSite?.url?.endsWith(".wordpress.com") == true && siteCheckTries < MAX_SITE_CHECK_TRIES) {
288288
AppLog.v(
289289
T.DOMAIN_REGISTRATION,
290290
"Newly registered domain is still not reflected in site model. Refreshing site model..."

WordPress/src/main/java/org/wordpress/android/viewmodel/mlp/ModalLayoutPickerViewModel.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class ModalLayoutPickerViewModel @Inject constructor(
6161
private val _onCreateNewPageRequested = SingleLiveEvent<PageRequest.Create>()
6262
val onCreateNewPageRequested: LiveData<PageRequest.Create> = _onCreateNewPageRequested
6363

64-
private val site: SiteModel by lazy { siteStore.getSiteByLocalId(appPrefsWrapper.getSelectedSite()) }
64+
private val site: SiteModel by lazy {
65+
requireNotNull(siteStore.getSiteByLocalId(appPrefsWrapper.getSelectedSite()))
66+
}
6567

6668
override val useCachedData: Boolean = true
6769

@@ -115,7 +117,10 @@ class ModalLayoutPickerViewModel @Inject constructor(
115117
if (event.isError) {
116118
setErrorState()
117119
} else {
118-
handleResponse(event.layouts.toLayoutModels(), event.categories.toLayoutCategories())
120+
handleResponse(
121+
(event.layouts ?: listOf()).toLayoutModels(),
122+
(event.categories ?: listOf()).toLayoutCategories()
123+
)
119124
}
120125
}
121126

WordPress/src/main/java/org/wordpress/android/viewmodel/pages/PageListEventListener.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,12 @@ class PageListEventListener(
174174
@Subscribe(threadMode = MAIN)
175175
fun onSiteChanged(event: OnSiteChanged) {
176176
if (!event.isError) {
177-
val updatedSite = siteStore.getSiteByLocalId(site.id)
178-
if (updatedSite.showOnFront != site.showOnFront ||
179-
updatedSite.pageForPosts != site.pageForPosts ||
180-
updatedSite.pageOnFront != site.pageForPosts) {
181-
handleHomepageSettingsChange(updatedSite)
177+
siteStore.getSiteByLocalId(site.id)?.let { updatedSite ->
178+
if (updatedSite.showOnFront != site.showOnFront ||
179+
updatedSite.pageForPosts != site.pageForPosts ||
180+
updatedSite.pageOnFront != site.pageForPosts) {
181+
handleHomepageSettingsChange(updatedSite)
182+
}
182183
}
183184
}
184185
}

WordPress/src/main/java/org/wordpress/android/viewmodel/plugins/PluginBrowserViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class PluginBrowserViewModel @Inject constructor(
336336
return
337337
}
338338

339-
site = mSiteStore.getSiteBySiteId(site.siteId)
339+
site = requireNotNull(mSiteStore.getSiteBySiteId(site.siteId))
340340
}
341341

342342
// Keeping the data up to date

WordPress/src/test/java/org/wordpress/android/ui/reader/reblog/ReblogUseCaseTest.kt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import org.wordpress.android.test
1818
import org.wordpress.android.ui.reader.reblog.ReblogState.MultipleSites
1919
import org.wordpress.android.ui.reader.reblog.ReblogState.NoSite
2020
import org.wordpress.android.ui.reader.reblog.ReblogState.SingleSite
21-
import org.wordpress.android.ui.reader.reblog.ReblogState.Unknown
2221

2322
@InternalCoroutinesApi
2423
@RunWith(MockitoJUnitRunner::class)
@@ -102,29 +101,4 @@ class ReblogUseCaseTest {
102101
Assertions.assertThat(peState?.site).isEqualTo(site)
103102
Assertions.assertThat(peState?.post).isEqualTo(post)
104103
}
105-
106-
@Test
107-
fun `when user has only one visible WPCOM site but the selected site is not retrieved an error occurs`() = test {
108-
val post = ReaderPost()
109-
val visibleWPComSites = listOf(null) // One site
110-
111-
whenever(siteStore.visibleSitesAccessedViaWPCom).thenReturn(visibleWPComSites)
112-
113-
val state = reblogUseCase.onReblogButtonClicked(post)
114-
115-
Assertions.assertThat(state).isInstanceOf(Unknown::class.java)
116-
}
117-
118-
@Test
119-
fun `when user has more than one visible WPCOM sites but the selected site is not retrieved an error occurs`() =
120-
test {
121-
val post = ReaderPost()
122-
val visibleWPComSites = listOf(null, null) // More sites
123-
124-
whenever(siteStore.visibleSitesAccessedViaWPCom).thenReturn(visibleWPComSites)
125-
126-
val state = reblogUseCase.onReblogButtonClicked(post)
127-
128-
Assertions.assertThat(state).isInstanceOf(Unknown::class.java)
129-
}
130104
}

WordPress/src/test/java/org/wordpress/android/ui/sitecreation/previews/CreateSiteUseCaseTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ class CreateSiteUseCaseTest {
4545
@Before
4646
fun setUp() {
4747
useCase = CreateSiteUseCase(dispatcher, store, urlUtilsWrapper)
48-
event = OnNewSiteCreated()
49-
event.newSiteRemoteId = 123
48+
event = OnNewSiteCreated(newSiteRemoteId = 123)
5049
}
5150

5251
@Test

0 commit comments

Comments
 (0)