diff --git a/libs/fluxc-tests/src/test/java/org/wordpress/android/fluxc/theme/ThemeStoreUnitTest.java b/libs/fluxc-tests/src/test/java/org/wordpress/android/fluxc/theme/ThemeStoreUnitTest.java index 5cbef7bc27a8..4139ee4b974f 100644 --- a/libs/fluxc-tests/src/test/java/org/wordpress/android/fluxc/theme/ThemeStoreUnitTest.java +++ b/libs/fluxc-tests/src/test/java/org/wordpress/android/fluxc/theme/ThemeStoreUnitTest.java @@ -1,5 +1,10 @@ package org.wordpress.android.fluxc.theme; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + import android.content.Context; import com.yarolegovich.wellsql.WellSql; @@ -24,10 +29,6 @@ import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - @RunWith(RobolectricTestRunner.class) public class ThemeStoreUnitTest { private final ThemeStore mThemeStore = new ThemeStore(new Dispatcher(), Mockito.mock(ThemeRestClient.class)); @@ -44,7 +45,7 @@ public void setUp() { public void testActiveTheme() throws SiteSqlUtils.DuplicateSiteException { final SiteModel site = SiteUtils.generateWPComSite(); TestSiteSqlUtils.INSTANCE.getSiteSqlUtils().insertOrUpdateSite(site); - assertNull(mThemeStore.getActiveThemeForSite(site)); + assertThat(ThemeSqlUtils.getActiveThemeForSite(site)).isEmpty(); final ThemeModel firstTheme = generateTestTheme(site.getId(), "first-active", "First Active"); final ThemeModel secondTheme = generateTestTheme(site.getId(), "second-active", "Second Active"); @@ -105,67 +106,30 @@ public void testInsertOrReplaceWpThemes() { // first add 20 themes and make sure the count is correct ThemeSqlUtils.insertOrReplaceWpComThemes(firstTestThemes); - assertEquals(20, mThemeStore.getWpComThemes().size()); + assertEquals(20, mThemeStore.getWpComThemes(ids(firstTestThemes)).size()); // next add a larger list of themes (with 20 being duplicates) and make sure the count is correct ThemeSqlUtils.insertOrReplaceWpComThemes(secondTestThemes); - assertEquals(30, mThemeStore.getWpComThemes().size()); + assertEquals(30, mThemeStore.getWpComThemes(ids(secondTestThemes)).size()); // lastly add a smaller list of themes (all duplicates) and make sure count is correct ThemeSqlUtils.insertOrReplaceWpComThemes(thirdTestThemes); - assertEquals(10, mThemeStore.getWpComThemes().size()); - } - - @Test - public void testInsertOrReplaceInstalledThemes() throws SiteSqlUtils.DuplicateSiteException { - final SiteModel site = SiteUtils.generateJetpackSiteOverRestOnly(); - TestSiteSqlUtils.INSTANCE.getSiteSqlUtils().insertOrUpdateSite(site); - - final List firstTestThemes = generateThemesTestList(5); - final List secondTestThemes = generateThemesTestList(10); - final List thirdTestThemes = generateThemesTestList(1); - - // first add 5 installed themes - ThemeSqlUtils.insertOrReplaceInstalledThemes(site, firstTestThemes); - assertEquals(firstTestThemes.size(), mThemeStore.getThemesForSite(site).size()); - - // then replace them all with a new list of 10 - ThemeSqlUtils.insertOrReplaceInstalledThemes(site, secondTestThemes); - assertEquals(secondTestThemes.size(), mThemeStore.getThemesForSite(site).size()); - - // then replace them all with a single theme - ThemeSqlUtils.insertOrReplaceInstalledThemes(site, thirdTestThemes); - assertEquals(thirdTestThemes.size(), mThemeStore.getThemesForSite(site).size()); + assertEquals(10, mThemeStore.getWpComThemes(ids(thirdTestThemes)).size()); } @Test public void testRemoveThemesWithNoSite() { final List testThemes = generateThemesTestList(20); + final List themeIds = ids(testThemes); // insert and verify count - assertEquals(0, mThemeStore.getWpComThemes().size()); + assertEquals(0, mThemeStore.getWpComThemes(themeIds).size()); ThemeSqlUtils.insertOrReplaceWpComThemes(testThemes); - assertEquals(testThemes.size(), mThemeStore.getWpComThemes().size()); + assertEquals(testThemes.size(), mThemeStore.getWpComThemes(themeIds).size()); // remove and verify count ThemeSqlUtils.removeWpComThemes(); - assertEquals(0, mThemeStore.getWpComThemes().size()); - } - - @Test - public void testRemoveInstalledSiteThemes() throws SiteSqlUtils.DuplicateSiteException { - final SiteModel site = SiteUtils.generateJetpackSiteOverRestOnly(); - TestSiteSqlUtils.INSTANCE.getSiteSqlUtils().insertOrUpdateSite(site); - - final List testThemes = generateThemesTestList(5); - - // add site themes and verify count - ThemeSqlUtils.insertOrReplaceInstalledThemes(site, testThemes); - assertEquals(testThemes.size(), mThemeStore.getThemesForSite(site).size()); - - // remove and verify count - ThemeSqlUtils.removeSiteThemes(site); - assertEquals(0, mThemeStore.getThemesForSite(site).size()); + assertEquals(0, mThemeStore.getWpComThemes(themeIds).size()); } private ThemeModel generateTestTheme(int siteId, String themeId, String themeName) { @@ -183,4 +147,12 @@ private List generateThemesTestList(int num) { } return testThemes; } + + private List ids(List themes) { + List themeIds = new ArrayList<>(); + for (ThemeModel theme : themes) { + themeIds.add(theme.getThemeId()); + } + return themeIds; + } } diff --git a/libs/fluxc/src/main/java/org/wordpress/android/fluxc/action/ThemeAction.java b/libs/fluxc/src/main/java/org/wordpress/android/fluxc/action/ThemeAction.java index 22265308b8a9..e5cdaebd44b5 100644 --- a/libs/fluxc/src/main/java/org/wordpress/android/fluxc/action/ThemeAction.java +++ b/libs/fluxc/src/main/java/org/wordpress/android/fluxc/action/ThemeAction.java @@ -4,11 +4,8 @@ import org.wordpress.android.fluxc.annotations.ActionEnum; import org.wordpress.android.fluxc.annotations.action.IAction; import org.wordpress.android.fluxc.model.SiteModel; -import org.wordpress.android.fluxc.store.ThemeStore.FetchStarterDesignsPayload; import org.wordpress.android.fluxc.store.ThemeStore.FetchWPComThemesPayload; import org.wordpress.android.fluxc.store.ThemeStore.FetchedCurrentThemePayload; -import org.wordpress.android.fluxc.store.ThemeStore.FetchedSiteThemesPayload; -import org.wordpress.android.fluxc.store.ThemeStore.FetchedStarterDesignsPayload; import org.wordpress.android.fluxc.store.ThemeStore.FetchedWpComThemesPayload; import org.wordpress.android.fluxc.store.ThemeStore.SiteThemePayload; @@ -17,36 +14,20 @@ public enum ThemeAction implements IAction { // Remote actions @Action(payloadType = FetchWPComThemesPayload.class) FETCH_WP_COM_THEMES, - @Action(payloadType = FetchStarterDesignsPayload.class) - FETCH_STARTER_DESIGNS, - @Action(payloadType = SiteModel.class) - FETCH_INSTALLED_THEMES, // Jetpack only @Action(payloadType = SiteModel.class) FETCH_CURRENT_THEME, @Action(payloadType = SiteThemePayload.class) ACTIVATE_THEME, @Action(payloadType = SiteThemePayload.class) INSTALL_THEME, - @Action(payloadType = SiteThemePayload.class) - DELETE_THEME, // Remote responses @Action(payloadType = FetchedWpComThemesPayload.class) FETCHED_WP_COM_THEMES, - @Action(payloadType = FetchedStarterDesignsPayload.class) - FETCHED_STARTER_DESIGNS, - @Action(payloadType = FetchedSiteThemesPayload.class) - FETCHED_INSTALLED_THEMES, @Action(payloadType = FetchedCurrentThemePayload.class) FETCHED_CURRENT_THEME, @Action(payloadType = SiteThemePayload.class) ACTIVATED_THEME, @Action(payloadType = SiteThemePayload.class) - INSTALLED_THEME, - @Action(payloadType = SiteThemePayload.class) - DELETED_THEME, - - // Local actions - @Action(payloadType = SiteModel.class) - REMOVE_SITE_THEMES + INSTALLED_THEME } diff --git a/libs/fluxc/src/main/java/org/wordpress/android/fluxc/model/ThemeModel.java b/libs/fluxc/src/main/java/org/wordpress/android/fluxc/model/ThemeModel.java index 94e1890b4829..5492a60694f1 100644 --- a/libs/fluxc/src/main/java/org/wordpress/android/fluxc/model/ThemeModel.java +++ b/libs/fluxc/src/main/java/org/wordpress/android/fluxc/model/ThemeModel.java @@ -21,26 +21,8 @@ public class ThemeModel implements Identifiable, Serializable { @Column private int mLocalSiteId; @NonNull @Column private String mThemeId; @NonNull @Column private String mName; - @NonNull @Column private String mDescription; - @Nullable @Column private String mSlug; - @Nullable @Column private String mVersion; - @Nullable @Column private String mAuthorName; - @Nullable @Column private String mAuthorUrl; - @Nullable @Column private String mThemeUrl; - @Nullable @Column private String mThemeType; - @NonNull @Column private String mScreenshotUrl; @Nullable @Column private String mDemoUrl; - @Nullable @Column private String mDownloadUrl; - @Nullable @Column private String mStylesheet; - @Nullable @Column private String mPriceText; - @Column private boolean mFree; - @Nullable @Column private String mMobileFriendlyCategorySlug; @Column private boolean mActive; - @Column private boolean mAutoUpdate; - @Column private boolean mAutoUpdateTranslation; - - // local use only - @Column private boolean mIsExternalTheme; @Column private boolean mIsWpComTheme; @Deprecated @@ -50,24 +32,8 @@ public ThemeModel() { this.mLocalSiteId = 0; this.mThemeId = ""; this.mName = ""; - this.mDescription = ""; - this.mSlug = null; - this.mVersion = null; - this.mAuthorName = null; - this.mAuthorUrl = null; - this.mThemeUrl = null; - this.mThemeType = null; - this.mScreenshotUrl = ""; this.mDemoUrl = null; - this.mDownloadUrl = null; - this.mStylesheet = null; - this.mPriceText = null; - this.mFree = true; - this.mMobileFriendlyCategorySlug = null; this.mActive = false; - this.mAutoUpdate = false; - this.mAutoUpdateTranslation = false; - this.mIsExternalTheme = false; this.mIsWpComTheme = false; } @@ -77,38 +43,10 @@ public ThemeModel() { public ThemeModel( @NonNull String themeId, @NonNull String name, - @NonNull String description, - @Nullable String slug, - @Nullable String version, - @Nullable String authorName, - @Nullable String authorUrl, - @Nullable String themeUrl, - @Nullable String themeType, - @NonNull String screenshotUrl, - @Nullable String demoUrl, - @Nullable String downloadUrl, - @Nullable String stylesheet, - @Nullable String priceText, - boolean isExternalTheme, - boolean free, - @Nullable String mobileFriendlyCategorySlug) { + @Nullable String demoUrl) { this.mThemeId = themeId; this.mName = name; - this.mDescription = description; - this.mSlug = slug; - this.mVersion = version; - this.mAuthorName = authorName; - this.mAuthorUrl = authorUrl; - this.mThemeUrl = themeUrl; - this.mThemeType = themeType; - this.mScreenshotUrl = screenshotUrl; this.mDemoUrl = demoUrl; - this.mDownloadUrl = downloadUrl; - this.mStylesheet = stylesheet; - this.mPriceText = priceText; - this.mIsExternalTheme = isExternalTheme; - this.mFree = free; - this.mMobileFriendlyCategorySlug = mobileFriendlyCategorySlug; } /** @@ -117,26 +55,11 @@ public ThemeModel( public ThemeModel( @NonNull String themeId, @NonNull String name, - @NonNull String description, - @Nullable String version, - @Nullable String authorName, - @Nullable String authorUrl, - @Nullable String themeUrl, - @NonNull String screenshotUrl, - boolean active, - boolean autoUpdate, - boolean autoUpdateTranslation) { + boolean active + ) { this.mThemeId = themeId; this.mName = name; - this.mDescription = description; - this.mVersion = version; - this.mAuthorName = authorName; - this.mAuthorUrl = authorUrl; - this.mThemeUrl = themeUrl; - this.mScreenshotUrl = screenshotUrl; this.mActive = active; - this.mAutoUpdate = autoUpdate; - this.mAutoUpdateTranslation = autoUpdateTranslation; } @Override @@ -160,22 +83,8 @@ public boolean equals(@Nullable Object other) { && getLocalSiteId() == otherTheme.getLocalSiteId() && StringUtils.equals(getThemeId(), otherTheme.getThemeId()) && StringUtils.equals(getName(), otherTheme.getName()) - && StringUtils.equals(getDescription(), otherTheme.getDescription()) - && StringUtils.equals(getVersion(), otherTheme.getVersion()) - && StringUtils.equals(getAuthorName(), otherTheme.getAuthorName()) - && StringUtils.equals(getAuthorUrl(), otherTheme.getAuthorUrl()) - && StringUtils.equals(getThemeUrl(), otherTheme.getThemeUrl()) - && StringUtils.equals(getScreenshotUrl(), otherTheme.getScreenshotUrl()) && StringUtils.equals(getDemoUrl(), otherTheme.getDemoUrl()) - && StringUtils.equals(getSlug(), otherTheme.getSlug()) - && StringUtils.equals(getDownloadUrl(), otherTheme.getDownloadUrl()) - && StringUtils.equals(getStylesheet(), otherTheme.getStylesheet()) - && StringUtils.equals(getPriceText(), otherTheme.getPriceText()) - && getFree() == otherTheme.getFree() - && StringUtils.equals(getMobileFriendlyCategorySlug(), otherTheme.getMobileFriendlyCategorySlug()) && getActive() == otherTheme.getActive() - && getAutoUpdate() == otherTheme.getAutoUpdate() - && getAutoUpdateTranslation() == otherTheme.getAutoUpdateTranslation() && isWpComTheme() == otherTheme.isWpComTheme(); } @@ -205,78 +114,6 @@ public void setName(@NonNull String name) { mName = name; } - @NonNull - public String getDescription() { - return mDescription; - } - - public void setDescription(@NonNull String description) { - mDescription = description; - } - - @Nullable - public String getSlug() { - return mSlug; - } - - public void setSlug(@Nullable String slug) { - mSlug = slug; - } - - @Nullable - public String getVersion() { - return mVersion; - } - - public void setVersion(@Nullable String version) { - mVersion = version; - } - - @Nullable - public String getAuthorName() { - return mAuthorName; - } - - public void setAuthorName(@Nullable String authorName) { - mAuthorName = authorName; - } - - @Nullable - public String getAuthorUrl() { - return mAuthorUrl; - } - - public void setAuthorUrl(@Nullable String authorUrl) { - mAuthorUrl = authorUrl; - } - - @Nullable - public String getThemeUrl() { - return mThemeUrl; - } - - public void setThemeUrl(@Nullable String themeUrl) { - mThemeUrl = themeUrl; - } - - @NonNull - public String getScreenshotUrl() { - return mScreenshotUrl; - } - - public void setScreenshotUrl(@NonNull String screenshotUrl) { - mScreenshotUrl = screenshotUrl; - } - - @Nullable - public String getThemeType() { - return mThemeType; - } - - public void setThemeType(@Nullable String themeType) { - mThemeType = themeType; - } - @Nullable public String getDemoUrl() { return mDemoUrl; @@ -286,54 +123,6 @@ public void setDemoUrl(@Nullable String demoUrl) { mDemoUrl = demoUrl; } - @Nullable - public String getDownloadUrl() { - return mDownloadUrl; - } - - public void setDownloadUrl(@Nullable String downloadUrl) { - mDownloadUrl = downloadUrl; - } - - @Nullable - public String getStylesheet() { - return mStylesheet; - } - - public void setStylesheet(@Nullable String stylesheet) { - mStylesheet = stylesheet; - } - - @Nullable - public String getPriceText() { - return mPriceText; - } - - public void setPriceText(@Nullable String priceText) { - mPriceText = priceText; - } - - public boolean getFree() { - return mFree; - } - - @Nullable - public String getMobileFriendlyCategorySlug() { - return mMobileFriendlyCategorySlug; - } - - public void setMobileFriendlyCategorySlug(@Nullable String mobileFriendlyCategorySlug) { - mMobileFriendlyCategorySlug = mobileFriendlyCategorySlug; - } - - public boolean isFree() { - return getFree(); - } - - public void setFree(boolean free) { - mFree = free; - } - public boolean getActive() { return mActive; } @@ -342,30 +131,6 @@ public void setActive(boolean active) { mActive = active; } - public boolean getAutoUpdate() { - return mAutoUpdate; - } - - public void setAutoUpdate(boolean autoUpdate) { - mAutoUpdate = autoUpdate; - } - - public boolean getAutoUpdateTranslation() { - return mAutoUpdateTranslation; - } - - public void setAutoUpdateTranslation(boolean autoUpdateTranslation) { - mAutoUpdateTranslation = autoUpdateTranslation; - } - - public boolean isExternalTheme() { - return mIsExternalTheme; - } - - public void setIsExternalTheme(boolean isExternalTheme) { - mIsExternalTheme = isExternalTheme; - } - public boolean isWpComTheme() { return mIsWpComTheme; } diff --git a/libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/StarterDesignsResponse.kt b/libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/StarterDesignsResponse.kt deleted file mode 100644 index 5f8cb8c8a7e9..000000000000 --- a/libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/StarterDesignsResponse.kt +++ /dev/null @@ -1,33 +0,0 @@ -package org.wordpress.android.fluxc.network.rest.wpcom.theme - -import android.os.Parcelable -import com.google.gson.annotations.SerializedName -import kotlinx.parcelize.Parcelize -import org.wordpress.android.fluxc.network.Response - -data class StarterDesignsResponse( - val designs: List, - val categories: List -) : Response - -@Parcelize -data class StarterDesign( - val slug: String, - val title: String, - @SerializedName("segment_id") val segmentId: Long?, - val categories: List, - @SerializedName("demo_url") val demoUrl: String, - val theme: String?, - val group: List, - val preview: String, - @SerializedName("preview_tablet") val previewTablet: String, - @SerializedName("preview_mobile") val previewMobile: String -) : Parcelable - -@Parcelize -data class StarterDesignCategory( - val slug: String, - val title: String, - val description: String, - val emoji: String? -) : Parcelable diff --git a/libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.java b/libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.java index c733e2a6cb15..03b6bd5a440c 100644 --- a/libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.java +++ b/libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.java @@ -1,27 +1,23 @@ package org.wordpress.android.fluxc.network.rest.wpcom.theme; import android.content.Context; -import android.text.TextUtils; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.android.volley.RequestQueue; import org.wordpress.android.fluxc.Dispatcher; import org.wordpress.android.fluxc.generated.ThemeActionBuilder; import org.wordpress.android.fluxc.generated.endpoint.WPCOMREST; -import org.wordpress.android.fluxc.generated.endpoint.WPCOMV2; import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.fluxc.model.ThemeModel; import org.wordpress.android.fluxc.network.UserAgent; import org.wordpress.android.fluxc.network.rest.wpcom.BaseWPComRestClient; import org.wordpress.android.fluxc.network.rest.wpcom.WPComGsonRequest; import org.wordpress.android.fluxc.network.rest.wpcom.auth.AccessToken; -import org.wordpress.android.fluxc.network.rest.wpcom.theme.JetpackThemeResponse.JetpackThemeListResponse; import org.wordpress.android.fluxc.network.rest.wpcom.theme.WPComThemeResponse.WPComThemeListResponse; -import org.wordpress.android.fluxc.network.rest.wpcom.theme.WPComThemeResponse.WPComThemeMobileFriendlyTaxonomy; -import org.wordpress.android.fluxc.network.rest.wpcom.theme.WPComThemeResponse.WPComThemeTaxonomies; import org.wordpress.android.fluxc.store.ThemeStore.FetchedCurrentThemePayload; -import org.wordpress.android.fluxc.store.ThemeStore.FetchedSiteThemesPayload; -import org.wordpress.android.fluxc.store.ThemeStore.FetchedStarterDesignsPayload; import org.wordpress.android.fluxc.store.ThemeStore.FetchedWpComThemesPayload; import org.wordpress.android.fluxc.store.ThemeStore.SiteThemePayload; import org.wordpress.android.fluxc.store.ThemeStore.ThemesError; @@ -31,21 +27,14 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - @Singleton public class ThemeRestClient extends BaseWPComRestClient { - private static final String WPCOM_MOBILE_FRIENDLY_TAXONOMY_SLUG = "mobile-friendly"; - private static final String THEME_TYPE_EXTERNAL = "managed-external"; - @Inject public ThemeRestClient( Context appContext, Dispatcher dispatcher, @@ -55,26 +44,6 @@ public class ThemeRestClient extends BaseWPComRestClient { super(appContext, dispatcher, requestQueue, accessToken, userAgent); } - /** - * [Undocumented!] Endpoint: v1.1/sites/$siteId/themes/$themeId/delete - */ - public void deleteTheme(@NonNull final SiteModel site, @NonNull final ThemeModel theme) { - String url = WPCOMREST.sites.site(site.getSiteId()).themes.theme(theme.getThemeId()).delete.getUrlV1_1(); - add(WPComGsonRequest.buildPostRequest(url, null, JetpackThemeResponse.class, - (response, headers) -> { - AppLog.d(AppLog.T.API, "Received response to Jetpack theme deletion request."); - ThemeModel responseTheme = createThemeFromJetpackResponse(response); - responseTheme.setId(theme.getId()); - SiteThemePayload payload = new SiteThemePayload(site, responseTheme); - mDispatcher.dispatch(ThemeActionBuilder.newDeletedThemeAction(payload)); - }, error -> { - AppLog.d(AppLog.T.API, "Received error response to Jetpack theme deletion request."); - SiteThemePayload payload = new SiteThemePayload(site, theme); - payload.error = new ThemesError(error.apiError, error.message); - mDispatcher.dispatch(ThemeActionBuilder.newDeletedThemeAction(payload)); - })); - } - /** * [Undocumented!] Endpoint: v1.1/sites/$siteId/themes/$themeId/install */ @@ -148,64 +117,6 @@ public void fetchWpComThemes(@Nullable String filter, int resultsLimit) { })); } - /** - * Endpoint: v2/common-starter-site-designs - */ - public void fetchStarterDesigns( - @Nullable Float previewWidth, - @Nullable Float previewHeight, - @Nullable Float scale, - @Nullable String[] groups) { - Map params = new HashMap<>(); - params.put("type", "mobile"); - if (previewWidth != null) { - params.put("preview_width", String.format(Locale.US, "%.1f", previewWidth)); - } - if (previewHeight != null) { - params.put("preview_height", String.format(Locale.US, "%.1f", previewHeight)); - } - if (scale != null) { - params.put("scale", String.format(Locale.US, "%.1f", scale)); - } - if (groups != null && groups.length > 0) { - params.put("group", TextUtils.join(",", groups)); - } - String url = WPCOMV2.common_starter_site_designs.getUrl(); - add(WPComGsonRequest.buildGetRequest(url, params, StarterDesignsResponse.class, - (response, headers) -> { - AppLog.d(AppLog.T.API, "Received response to WP.com starter designs fetch request."); - FetchedStarterDesignsPayload payload = - new FetchedStarterDesignsPayload(response.getDesigns(), response.getCategories()); - mDispatcher.dispatch(ThemeActionBuilder.newFetchedStarterDesignsAction(payload)); - }, error -> { - AppLog.e(AppLog.T.API, "Received error response to WP.com starter designs fetch request."); - ThemesError themeError = new ThemesError(error.apiError, error.message); - FetchedStarterDesignsPayload payload = new FetchedStarterDesignsPayload(themeError); - mDispatcher.dispatch(ThemeActionBuilder.newFetchedStarterDesignsAction(payload)); - })); - } - - /** - * [Undocumented!] Endpoint: v1/sites/$siteId/themes - * - * @see Similar endpoint - */ - public void fetchJetpackInstalledThemes(@NonNull final SiteModel site) { - String url = WPCOMREST.sites.site(site.getSiteId()).themes.getUrlV1(); - add(WPComGsonRequest.buildGetRequest(url, null, JetpackThemeListResponse.class, - (response, headers) -> { - AppLog.d(AppLog.T.API, "Received response to Jetpack installed themes fetch request."); - List themes = createThemeListFromJetpackResponse(response); - FetchedSiteThemesPayload payload = new FetchedSiteThemesPayload(site, themes); - mDispatcher.dispatch(ThemeActionBuilder.newFetchedInstalledThemesAction(payload)); - }, error -> { - AppLog.e(AppLog.T.API, "Received error response to Jetpack installed themes fetch request."); - ThemesError themeError = new ThemesError(error.apiError, error.message); - FetchedSiteThemesPayload payload = new FetchedSiteThemesPayload(site, themeError); - mDispatcher.dispatch(ThemeActionBuilder.newFetchedInstalledThemesAction(payload)); - })); - } - /** * Endpoint: v1.1/sites/$siteId/themes/mine; same endpoint for both Jetpack and WP.com sites! * @@ -229,79 +140,19 @@ public void fetchCurrentTheme(@NonNull final SiteModel site) { @NonNull private static ThemeModel createThemeFromWPComResponse(@NonNull WPComThemeResponse response) { - boolean free = response.theme_tier == null || response.theme_tier.slug == null - || response.theme_tier.slug.equalsIgnoreCase("free"); - String priceText = null; - if (!free) { - priceText = response.price; - } - boolean isExternalTheme = false; - if (response.theme_type != null) { - isExternalTheme = response.theme_type.equals(THEME_TYPE_EXTERNAL); - } return new ThemeModel( response.id, response.name, - response.description, - response.slug, - response.version, - response.author, - response.author_uri, - response.theme_uri, - response.theme_type, - response.screenshot, - response.demo_uri, - response.download_uri, - response.stylesheet, - priceText, - isExternalTheme, - free, - getMobileFriendlyCategorySlug(response.taxonomies) + response.demo_uri ); } - @Nullable - private static String getMobileFriendlyCategorySlug(@Nullable WPComThemeTaxonomies taxonomies) { - // detect the mobile-friendly category slug if there - if (taxonomies != null && taxonomies.theme_mobile_friendly != null) { - String category = null; - for (WPComThemeMobileFriendlyTaxonomy taxonomy : taxonomies.theme_mobile_friendly) { - // The server response has two taxonomies defined here. One is named "mobile-friendly" and the other is - // a more specific category the theme belongs to. We're only interested in the specific one here so, - // ignore the "mobile-friendly" one. - if (taxonomy.slug.equals(WPCOM_MOBILE_FRIENDLY_TAXONOMY_SLUG)) { - continue; - } - - category = taxonomy.slug; - - // we got the category slug so, no need to continue looping - break; - } - return category; - } - return null; - } - @NonNull private static ThemeModel createThemeFromJetpackResponse(@NonNull JetpackThemeResponse response) { - // the screenshot field in Jetpack responses does not contain a protocol so we'll prepend 'https' - String screenshotUrl = response.screenshot; - if (screenshotUrl.startsWith("//")) { - screenshotUrl = "https:" + screenshotUrl; - } return new ThemeModel( response.id, response.name, - response.description, - response.version, - response.author, - response.author_uri, - response.theme_uri, - screenshotUrl, - response.active, - response.autoupdate, - response.autoupdate_translation + response.active ); } @@ -314,18 +165,6 @@ private static List createThemeListFromArrayResponse(@NonNull WPComT return themeList; } - /** - * Creates a list of ThemeModels from the Jetpack /v1/sites/$siteId/themes REST response. - */ - @NonNull - private static List createThemeListFromJetpackResponse(@NonNull JetpackThemeListResponse response) { - final List themeList = new ArrayList<>(); - for (JetpackThemeResponse item : response.themes) { - themeList.add(createThemeFromJetpackResponse(item)); - } - return themeList; - } - /** * Must provide theme slug with -wpcom suffix to install a WP.com theme on a Jetpack site. * diff --git a/libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ThemeSqlUtils.java b/libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ThemeSqlUtils.java index bc248e567270..865ce41c51e2 100644 --- a/libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ThemeSqlUtils.java +++ b/libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ThemeSqlUtils.java @@ -50,18 +50,6 @@ public static void insertOrReplaceWpComThemes(@NonNull List themes) WellSql.insert(themes).asSingleTransaction(true).execute(); } - public static void insertOrReplaceInstalledThemes(@NonNull SiteModel site, @NonNull List themes) { - // remove existing installed themes - removeSiteThemes(site); - - // ensure site ID is set before inserting - for (ThemeModel theme : themes) { - theme.setLocalSiteId(site.getId()); - } - - WellSql.insert(themes).asSingleTransaction(true).execute(); - } - public static void insertOrReplaceActiveThemeForSite(@NonNull SiteModel site, @NonNull ThemeModel theme) { // find any existing active theme for the site and unset active flag List existing = getActiveThemeForSite(site); @@ -88,14 +76,6 @@ public static List getActiveThemeForSite(@NonNull SiteModel site) { .endGroup().endWhere().getAsModel(); } - @NonNull - public static List getWpComThemes() { - return WellSql.select(ThemeModel.class) - .where() - .equals(ThemeModelTable.IS_WP_COM_THEME, true) - .endWhere().getAsModel(); - } - @NonNull public static List getWpComThemes(@NonNull List themeIds) { return WellSql.select(ThemeModel.class) @@ -105,23 +85,6 @@ public static List getWpComThemes(@NonNull List themeIds) { .endWhere().getAsModel(); } - @NonNull - public static List getWpComMobileFriendlyThemes(@NonNull String categorySlug) { - return WellSql.select(ThemeModel.class) - .where() - .equals(ThemeModelTable.MOBILE_FRIENDLY_CATEGORY_SLUG, categorySlug) - .equals(ThemeModelTable.IS_WP_COM_THEME, true) - .endWhere().getAsModel(); - } - - @NonNull - public static List getThemesForSite(@NonNull SiteModel site) { - return WellSql.select(ThemeModel.class) - .where() - .equals(ThemeModelTable.LOCAL_SITE_ID, site.getId()) - .endWhere().getAsModel(); - } - @Nullable public static ThemeModel getWpComThemeByThemeId(@NonNull String themeId) { if (TextUtils.isEmpty(themeId)) { @@ -166,21 +129,4 @@ public static void removeWpComThemes() { .equals(ThemeModelTable.IS_WP_COM_THEME, true) .endWhere().execute(); } - - public static void removeSiteTheme(@NonNull SiteModel site, @NonNull ThemeModel theme) { - WellSql.delete(ThemeModel.class) - .where() - .equals(ThemeModelTable.LOCAL_SITE_ID, site.getId()) - .equals(ThemeModelTable.THEME_ID, theme.getThemeId()) - .equals(ThemeModelTable.IS_WP_COM_THEME, false) - .endWhere().execute(); - } - - public static void removeSiteThemes(@NonNull SiteModel site) { - WellSql.delete(ThemeModel.class) - .where() - .equals(ThemeModelTable.LOCAL_SITE_ID, site.getId()) - .equals(ThemeModelTable.IS_WP_COM_THEME, false) - .endWhere().execute(); - } } diff --git a/libs/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.java b/libs/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.java index 70b80b37b09d..2122ed7e6c14 100644 --- a/libs/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.java +++ b/libs/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.java @@ -15,8 +15,6 @@ import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.fluxc.model.ThemeModel; import org.wordpress.android.fluxc.network.BaseRequest.BaseNetworkError; -import org.wordpress.android.fluxc.network.rest.wpcom.theme.StarterDesign; -import org.wordpress.android.fluxc.network.rest.wpcom.theme.StarterDesignCategory; import org.wordpress.android.fluxc.network.rest.wpcom.theme.ThemeRestClient; import org.wordpress.android.fluxc.persistence.ThemeSqlUtils; import org.wordpress.android.util.AppLog; @@ -29,23 +27,10 @@ @Singleton public class ThemeStore extends Store { - public static final String MOBILE_FRIENDLY_CATEGORY_BLOG = "starting-blog"; - public static final String MOBILE_FRIENDLY_CATEGORY_WEBSITE = "starting-website"; - public static final String MOBILE_FRIENDLY_CATEGORY_PORTFOLIO = "starting-portfolio"; - - // A high number to ensure we get all themes in one request - private static final int DEFAULT_LIMIT_OF_THEME_RESULTS = 500; - // Payloads public static class FetchWPComThemesPayload extends Payload { @Nullable public String filter; - public int resultsLimit = DEFAULT_LIMIT_OF_THEME_RESULTS; - - public FetchWPComThemesPayload() {} - - public FetchWPComThemesPayload(@Nullable String filter) { - this.filter = filter; - } + public int resultsLimit; public FetchWPComThemesPayload(@Nullable String filter, int resultsLimit) { this.filter = filter; @@ -68,21 +53,6 @@ public FetchedCurrentThemePayload(@NonNull SiteModel site, @NonNull ThemeModel t } } - public static class FetchedSiteThemesPayload extends Payload { - @NonNull public SiteModel site; - @Nullable public List themes; - - public FetchedSiteThemesPayload(@NonNull SiteModel site, @NonNull ThemesError error) { - this.site = site; - this.error = error; - } - - public FetchedSiteThemesPayload(@NonNull SiteModel site, @NonNull List themes) { - this.site = site; - this.themes = themes; - } - } - public static class FetchedWpComThemesPayload extends Payload { @NonNull public List themes; @@ -106,42 +76,6 @@ public SiteThemePayload(@NonNull SiteModel site, @NonNull ThemeModel theme) { } } - public static class FetchStarterDesignsPayload extends Payload { - @Nullable public Float previewWidth; - @Nullable public Float previewHeight; - @Nullable public Float scale; - @Nullable public String[] groups; - - public FetchStarterDesignsPayload( - @Nullable Float previewWidth, - @Nullable Float previewHeight, - @Nullable Float scale, - @Nullable String... groups) { - this.previewWidth = previewWidth; - this.previewHeight = previewHeight; - this.scale = scale; - this.groups = groups; - } - } - - public static class FetchedStarterDesignsPayload extends Payload { - @NonNull public List designs; - @NonNull public List categories; - - public FetchedStarterDesignsPayload(@NonNull ThemesError error) { - this.error = error; - this.designs = new ArrayList<>(); - this.categories = new ArrayList<>(); - } - - public FetchedStarterDesignsPayload( - @NonNull List designs, - @NonNull List categories) { - this.designs = designs; - this.categories = categories; - } - } - public enum ThemeErrorType { GENERIC_ERROR, UNAUTHORIZED, @@ -177,18 +111,6 @@ public ThemesError(@NonNull ThemeErrorType type) { } } - // OnChanged events - @SuppressWarnings("WeakerAccess") - public static class OnSiteThemesChanged extends OnChanged { - @NonNull public SiteModel site; - @NonNull public ThemeAction origin; - - public OnSiteThemesChanged(@NonNull SiteModel site, @NonNull ThemeAction origin) { - this.site = site; - this.origin = origin; - } - } - public static class OnWpComThemesChanged extends OnChanged { } @@ -214,28 +136,6 @@ public OnThemeActivated(@NonNull SiteModel site, @NonNull ThemeModel theme) { } } - @SuppressWarnings("WeakerAccess") - public static class OnThemeRemoved extends OnChanged { - @NonNull public SiteModel site; - @NonNull public ThemeModel theme; - - public OnThemeRemoved(@NonNull SiteModel site, @NonNull ThemeModel theme) { - this.site = site; - this.theme = theme; - } - } - - @SuppressWarnings("WeakerAccess") - public static class OnThemeDeleted extends OnChanged { - @NonNull public SiteModel site; - @NonNull public ThemeModel theme; - - public OnThemeDeleted(@NonNull SiteModel site, @NonNull ThemeModel theme) { - this.site = site; - this.theme = theme; - } - } - @SuppressWarnings("WeakerAccess") public static class OnThemeInstalled extends OnChanged { @NonNull public SiteModel site; @@ -247,20 +147,6 @@ public OnThemeInstalled(@NonNull SiteModel site, @NonNull ThemeModel theme) { } } - public static class OnStarterDesignsFetched extends OnChanged { - @NonNull public List designs; - @NonNull public List categories; - - public OnStarterDesignsFetched( - @NonNull List designs, - @NonNull List categories, - @Nullable ThemesError error) { - this.designs = designs; - this.categories = categories; - this.error = error; - } - } - private final ThemeRestClient mThemeRestClient; @Inject public ThemeStore(Dispatcher dispatcher, ThemeRestClient themeRestClient) { @@ -283,12 +169,6 @@ public void onAction(Action action) { case FETCHED_WP_COM_THEMES: handleWpComThemesFetched((FetchedWpComThemesPayload) action.getPayload()); break; - case FETCH_INSTALLED_THEMES: - fetchInstalledThemes((SiteModel) action.getPayload()); - break; - case FETCHED_INSTALLED_THEMES: - handleInstalledThemesFetched((FetchedSiteThemesPayload) action.getPayload()); - break; case FETCH_CURRENT_THEME: fetchCurrentTheme((SiteModel) action.getPayload()); break; @@ -307,21 +187,6 @@ public void onAction(Action action) { case INSTALLED_THEME: handleThemeInstalled((SiteThemePayload) action.getPayload()); break; - case DELETE_THEME: - deleteTheme((SiteThemePayload) action.getPayload()); - break; - case DELETED_THEME: - handleThemeDeleted((SiteThemePayload) action.getPayload()); - break; - case REMOVE_SITE_THEMES: - removeSiteThemes((SiteModel) action.getPayload()); - break; - case FETCH_STARTER_DESIGNS: - fetchStarterDesigns((FetchStarterDesignsPayload) action.getPayload()); - break; - case FETCHED_STARTER_DESIGNS: - handleStarterDesignsFetched((FetchedStarterDesignsPayload) action.getPayload()); - break; } } @@ -330,26 +195,11 @@ public void onRegister() { AppLog.d(AppLog.T.API, "ThemeStore onRegister"); } - @NonNull - public List getWpComThemes() { - return ThemeSqlUtils.getWpComThemes(); - } - @NonNull public List getWpComThemes(@NonNull List themeIds) { return ThemeSqlUtils.getWpComThemes(themeIds); } - @NonNull - public List getWpComMobileFriendlyThemes(@NonNull String categorySlug) { - return ThemeSqlUtils.getWpComMobileFriendlyThemes(categorySlug); - } - - @NonNull - public List getThemesForSite(@NonNull SiteModel site) { - return ThemeSqlUtils.getThemesForSite(site); - } - @Nullable public ThemeModel getInstalledThemeByThemeId(@NonNull SiteModel siteModel, @NonNull String themeId) { if (TextUtils.isEmpty(themeId)) { @@ -367,12 +217,6 @@ public ThemeModel getWpComThemeByThemeId(@NonNull String themeId) { return ThemeSqlUtils.getWpComThemeByThemeId(themeId); } - @Nullable - public ThemeModel getActiveThemeForSite(@NonNull SiteModel site) { - List activeTheme = ThemeSqlUtils.getActiveThemeForSite(site); - return activeTheme.isEmpty() ? null : activeTheme.get(0); - } - public void setActiveThemeForSite(@NonNull SiteModel site, @NonNull ThemeModel theme) { ThemeSqlUtils.insertOrReplaceActiveThemeForSite(site, theme); } @@ -381,14 +225,6 @@ private void fetchWpComThemes(@NonNull FetchWPComThemesPayload payload) { mThemeRestClient.fetchWpComThemes(payload.filter, payload.resultsLimit); } - private void fetchStarterDesigns(@NonNull FetchStarterDesignsPayload payload) { - mThemeRestClient.fetchStarterDesigns( - payload.previewWidth, - payload.previewHeight, - payload.scale, - payload.groups); - } - private void handleWpComThemesFetched(@NonNull FetchedWpComThemesPayload payload) { OnWpComThemesChanged event = new OnWpComThemesChanged(); if (payload.isError()) { @@ -399,30 +235,6 @@ private void handleWpComThemesFetched(@NonNull FetchedWpComThemesPayload payload emitChange(event); } - private void fetchInstalledThemes(@NonNull SiteModel site) { - if (site.isJetpackConnected() && site.isUsingWpComRestApi()) { - mThemeRestClient.fetchJetpackInstalledThemes(site); - } else { - ThemesError error = new ThemesError(ThemeErrorType.NOT_AVAILABLE); - FetchedSiteThemesPayload payload = new FetchedSiteThemesPayload(site, error); - handleInstalledThemesFetched(payload); - } - } - - private void handleInstalledThemesFetched(@NonNull FetchedSiteThemesPayload payload) { - OnSiteThemesChanged event = new OnSiteThemesChanged(payload.site, ThemeAction.FETCH_INSTALLED_THEMES); - if (payload.isError()) { - event.error = payload.error; - } else { - if (payload.themes != null) { - ThemeSqlUtils.insertOrReplaceInstalledThemes(payload.site, payload.themes); - } else { - AppLog.w(AppLog.T.THEMES, "Fetched site themes payload themes is null."); - } - } - emitChange(event); - } - private void fetchCurrentTheme(@NonNull SiteModel site) { if (site.isUsingWpComRestApi()) { mThemeRestClient.fetchCurrentTheme(site); @@ -493,33 +305,4 @@ private void handleThemeActivated(@NonNull SiteThemePayload payload) { } emitChange(event); } - - private void deleteTheme(@NonNull SiteThemePayload payload) { - if (payload.site.isJetpackConnected() && payload.site.isUsingWpComRestApi()) { - mThemeRestClient.deleteTheme(payload.site, payload.theme); - } else { - payload.error = new ThemesError(ThemeErrorType.NOT_AVAILABLE); - handleThemeDeleted(payload); - } - } - - private void handleThemeDeleted(@NonNull SiteThemePayload payload) { - OnThemeDeleted event = new OnThemeDeleted(payload.site, payload.theme); - if (payload.isError()) { - event.error = payload.error; - } else { - ThemeSqlUtils.removeSiteTheme(payload.site, payload.theme); - } - emitChange(event); - } - - private void removeSiteThemes(@NonNull SiteModel site) { - ThemeSqlUtils.removeSiteThemes(site); - emitChange(new OnSiteThemesChanged(site, ThemeAction.REMOVE_SITE_THEMES)); - } - - private void handleStarterDesignsFetched(@NonNull FetchedStarterDesignsPayload payload) { - OnStarterDesignsFetched event = new OnStarterDesignsFetched(payload.designs, payload.categories, payload.error); - emitChange(event); - } }