diff --git a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_ThemeTestJetpack.java b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_ThemeTestJetpack.java index b835fe1c75..04af2487f3 100644 --- a/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_ThemeTestJetpack.java +++ b/example/src/androidTest/java/org/wordpress/android/fluxc/release/ReleaseStack_ThemeTestJetpack.java @@ -157,7 +157,7 @@ public void testInstallTheme() throws InterruptedException { } // install the theme - ThemeModel themeToInstall = new ThemeModel(); + @SuppressWarnings("deprecation") ThemeModel themeToInstall = new ThemeModel(); themeToInstall.setThemeId(themeId); installTheme(jetpackSite, themeToInstall); assertTrue(isThemeInstalled(jetpackSite, themeId)); @@ -179,7 +179,7 @@ public void testDeleteTheme() throws InterruptedException { // Install edin if necessary before attempting to delete if (!isThemeInstalled(jetpackSite, themeId)) { - ThemeModel themeToInstall = new ThemeModel(); + @SuppressWarnings("deprecation") ThemeModel themeToInstall = new ThemeModel(); themeToInstall.setThemeId(themeId); installTheme(jetpackSite, themeToInstall); @@ -189,8 +189,10 @@ public void testDeleteTheme() throws InterruptedException { // Get the theme from store to make sure the "active" state is correct, so we can deactivate it before deletion ThemeModel themeToDelete = mThemeStore.getInstalledThemeByThemeId(jetpackSite, EDIN_THEME_ID); - // if Edin is active update site's active theme to something else and delete Edin - deactivateAndDeleteTheme(jetpackSite, themeToDelete); + if (themeToDelete != null) { + // if Edin is active update site's active theme to something else and delete Edin + deactivateAndDeleteTheme(jetpackSite, themeToDelete); + } signOutWPCom(); } @@ -427,7 +429,9 @@ private void deactivateAndDeleteTheme(@NonNull SiteModel jetpackSite, @NonNull T activateTheme(jetpackSite, otherThemeToActivate); // Make sure another theme is activated - assertNotEquals(theme.getThemeId(), mThemeStore.getActiveThemeForSite(jetpackSite).getThemeId()); + ThemeModel activeTheme = mThemeStore.getActiveThemeForSite(jetpackSite); + assertNotNull(activeTheme); + assertNotEquals(theme.getThemeId(), activeTheme.getThemeId()); } // delete existing theme from site deleteTheme(jetpackSite, theme); diff --git a/example/src/main/java/org/wordpress/android/fluxc/example/ThemeFragment.kt b/example/src/main/java/org/wordpress/android/fluxc/example/ThemeFragment.kt index 3f4f32974f..bf55741d95 100644 --- a/example/src/main/java/org/wordpress/android/fluxc/example/ThemeFragment.kt +++ b/example/src/main/java/org/wordpress/android/fluxc/example/ThemeFragment.kt @@ -92,7 +92,7 @@ class ThemeFragment : Fragment() { if (site == null) { prependToLog("No WP.com site found, unable to test.") } else { - val theme = ThemeModel() + @Suppress("DEPRECATION") val theme = ThemeModel() theme.localSiteId = site.id theme.themeId = id val payload = ThemeStore.SiteThemePayload(site, theme) @@ -110,7 +110,7 @@ class ThemeFragment : Fragment() { if (site == null) { prependToLog("No Jetpack connected site found, unable to test.") } else { - val theme = ThemeModel() + @Suppress("DEPRECATION") val theme = ThemeModel() theme.localSiteId = site.id theme.themeId = id val payload = ThemeStore.SiteThemePayload(site, theme) @@ -128,7 +128,7 @@ class ThemeFragment : Fragment() { if (site == null) { prependToLog("No Jetpack connected site found, unable to test.") } else { - val theme = ThemeModel() + @Suppress("DEPRECATION") val theme = ThemeModel() theme.localSiteId = site.id theme.themeId = id val payload = ThemeStore.SiteThemePayload(site, theme) @@ -146,7 +146,7 @@ class ThemeFragment : Fragment() { if (site == null) { prependToLog("No Jetpack connected site found, unable to test.") } else { - val theme = ThemeModel() + @Suppress("DEPRECATION") val theme = ThemeModel() theme.localSiteId = site.id theme.themeId = id val payload = ThemeStore.SiteThemePayload(site, theme) diff --git a/example/src/test/java/org/wordpress/android/fluxc/theme/ThemeStoreUnitTest.java b/example/src/test/java/org/wordpress/android/fluxc/theme/ThemeStoreUnitTest.java index c18eeed79f..5cbef7bc27 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/theme/ThemeStoreUnitTest.java +++ b/example/src/test/java/org/wordpress/android/fluxc/theme/ThemeStoreUnitTest.java @@ -169,7 +169,7 @@ public void testRemoveInstalledSiteThemes() throws SiteSqlUtils.DuplicateSiteExc } private ThemeModel generateTestTheme(int siteId, String themeId, String themeName) { - ThemeModel theme = new ThemeModel(); + @SuppressWarnings("deprecation") ThemeModel theme = new ThemeModel(); theme.setLocalSiteId(siteId); theme.setThemeId(themeId); theme.setName(themeName); diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/ThemeModel.java b/fluxc/src/main/java/org/wordpress/android/fluxc/model/ThemeModel.java index 73bf119ee9..94e1890b48 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/ThemeModel.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/ThemeModel.java @@ -1,5 +1,8 @@ package org.wordpress.android.fluxc.model; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.yarolegovich.wellsql.core.Identifiable; import com.yarolegovich.wellsql.core.annotation.Column; import com.yarolegovich.wellsql.core.annotation.PrimaryKey; @@ -16,22 +19,22 @@ public class ThemeModel implements Identifiable, Serializable { @PrimaryKey @Column private int mId; @Column private int mLocalSiteId; - @Column private String mThemeId; - @Column private String mName; - @Column private String mDescription; - @Column private String mSlug; - @Column private String mVersion; - @Column private String mAuthorName; - @Column private String mAuthorUrl; - @Column private String mThemeUrl; - @Column private String mScreenshotUrl; - @Column private String mThemeType; - @Column private String mDemoUrl; - @Column private String mDownloadUrl; - @Column private String mStylesheet; - @Column private String mPriceText; - @Column private boolean mFree = true; - @Column private String mMobileFriendlyCategorySlug; + @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; @@ -40,6 +43,102 @@ public class ThemeModel implements Identifiable, Serializable { @Column private boolean mIsExternalTheme; @Column private boolean mIsWpComTheme; + @Deprecated + @SuppressWarnings("DeprecatedIsStillUsed") + public ThemeModel() { + this.mId = 0; + 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; + } + + /** + * Use when creating a WP.com theme. + */ + 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) { + 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; + } + + /** + * Use when creating a Jetpack theme. + */ + 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) { + 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 public int getId() { return mId; @@ -51,7 +150,8 @@ public void setId(int id) { } @Override - public boolean equals(Object other) { + @SuppressWarnings("ConditionCoveredByFurtherCondition") + public boolean equals(@Nullable Object other) { if (other == null || !(other instanceof ThemeModel)) { return false; } @@ -87,115 +187,129 @@ public void setLocalSiteId(int localSiteId) { this.mLocalSiteId = localSiteId; } + @NonNull public String getThemeId() { return mThemeId; } - public void setThemeId(String themeId) { + public void setThemeId(@NonNull String themeId) { mThemeId = themeId; } + @NonNull public String getName() { return mName; } - public void setName(String name) { + public void setName(@NonNull String name) { mName = name; } + @NonNull public String getDescription() { return mDescription; } - public void setDescription(String description) { + public void setDescription(@NonNull String description) { mDescription = description; } + @Nullable public String getSlug() { return mSlug; } - public void setSlug(String slug) { + public void setSlug(@Nullable String slug) { mSlug = slug; } + @Nullable public String getVersion() { return mVersion; } - public void setVersion(String version) { + public void setVersion(@Nullable String version) { mVersion = version; } + @Nullable public String getAuthorName() { return mAuthorName; } - public void setAuthorName(String authorName) { + public void setAuthorName(@Nullable String authorName) { mAuthorName = authorName; } + @Nullable public String getAuthorUrl() { return mAuthorUrl; } - public void setAuthorUrl(String authorUrl) { + public void setAuthorUrl(@Nullable String authorUrl) { mAuthorUrl = authorUrl; } + @Nullable public String getThemeUrl() { return mThemeUrl; } - public void setThemeUrl(String themeUrl) { + public void setThemeUrl(@Nullable String themeUrl) { mThemeUrl = themeUrl; } + @NonNull public String getScreenshotUrl() { return mScreenshotUrl; } - public void setScreenshotUrl(String screenshotUrl) { + public void setScreenshotUrl(@NonNull String screenshotUrl) { mScreenshotUrl = screenshotUrl; } + @Nullable public String getThemeType() { return mThemeType; } - public void setThemeType(String themeType) { + public void setThemeType(@Nullable String themeType) { mThemeType = themeType; } + @Nullable public String getDemoUrl() { return mDemoUrl; } - public void setDemoUrl(String demoUrl) { + public void setDemoUrl(@Nullable String demoUrl) { mDemoUrl = demoUrl; } + @Nullable public String getDownloadUrl() { return mDownloadUrl; } - public void setDownloadUrl(String downloadUrl) { + public void setDownloadUrl(@Nullable String downloadUrl) { mDownloadUrl = downloadUrl; } + @Nullable public String getStylesheet() { return mStylesheet; } - public void setStylesheet(String stylesheet) { + public void setStylesheet(@Nullable String stylesheet) { mStylesheet = stylesheet; } + @Nullable public String getPriceText() { return mPriceText; } - public void setPriceText(String priceText) { + public void setPriceText(@Nullable String priceText) { mPriceText = priceText; } @@ -203,11 +317,12 @@ public boolean getFree() { return mFree; } + @Nullable public String getMobileFriendlyCategorySlug() { return mMobileFriendlyCategorySlug; } - public void setMobileFriendlyCategorySlug(String mobileFriendlyCategorySlug) { + public void setMobileFriendlyCategorySlug(@Nullable String mobileFriendlyCategorySlug) { mMobileFriendlyCategorySlug = mobileFriendlyCategorySlug; } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/applicationpasswords/ApplicationPasswordsNetwork.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/applicationpasswords/ApplicationPasswordsNetwork.kt index 4fce647b70..0724312d19 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/applicationpasswords/ApplicationPasswordsNetwork.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/applicationpasswords/ApplicationPasswordsNetwork.kt @@ -187,7 +187,7 @@ private fun BaseNetworkError.toWPAPINetworkError(): WPAPINetworkError { is WPAPINetworkError -> this is WPComGsonNetworkError -> WPAPINetworkError( baseError = this, - errorCode = this.apiError.orEmpty() + errorCode = this.apiError ) else -> WPAPINetworkError(this) } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/WPComGsonRequest.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/WPComGsonRequest.java index 5848225a76..c9213375c3 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/WPComGsonRequest.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/WPComGsonRequest.java @@ -46,8 +46,8 @@ public OnJetpackTimeoutError(String apiPath, int timesRetried) { public static final String REST_AUTHORIZATION_FORMAT = "Bearer %s"; public static class WPComGsonNetworkError extends BaseNetworkError { - public String apiError; - public WPComGsonNetworkError(BaseNetworkError error) { + @NonNull public String apiError; + public WPComGsonNetworkError(@NonNull BaseNetworkError error) { super(error); this.apiError = ""; } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.java index ca2cd0aa7c..9b36d0a8d7 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/theme/ThemeRestClient.java @@ -21,6 +21,7 @@ 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; @@ -141,8 +142,7 @@ public void fetchWpComThemes(@Nullable String filter, int resultsLimit) { mDispatcher.dispatch(ThemeActionBuilder.newFetchedWpComThemesAction(payload)); }, error -> { AppLog.e(AppLog.T.API, "Received error response to WP.com themes fetch request."); - ThemesError themeError = new ThemesError( - error.apiError, error.message); + ThemesError themeError = new ThemesError(error.apiError, error.message); FetchedWpComThemesPayload payload = new FetchedWpComThemesPayload(themeError); mDispatcher.dispatch(ThemeActionBuilder.newFetchedWpComThemesAction(payload)); })); @@ -229,34 +229,42 @@ public void fetchCurrentTheme(@NonNull final SiteModel site) { @NonNull private static ThemeModel createThemeFromWPComResponse(@NonNull WPComThemeResponse response) { - ThemeModel theme = new ThemeModel(); - theme.setThemeId(response.id); - theme.setSlug(response.slug); - theme.setStylesheet(response.stylesheet); - theme.setName(response.name); - theme.setAuthorName(response.author); - theme.setAuthorUrl(response.author_uri); - theme.setThemeUrl(response.theme_uri); - theme.setDemoUrl(response.demo_uri); - theme.setVersion(response.version); - theme.setScreenshotUrl(response.screenshot); - theme.setThemeType(response.theme_type); - if (response.theme_type != null) { - theme.setIsExternalTheme(response.theme_type.equals(THEME_TYPE_EXTERNAL)); + boolean free = TextUtils.isEmpty(response.price); + String priceText = null; + if (!free) { + priceText = response.price; } - theme.setDescription(response.description); - theme.setDownloadUrl(response.download_uri); - if (TextUtils.isEmpty(response.price)) { - theme.setFree(true); - } else { - theme.setFree(false); - theme.setPriceText(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) + ); + } + @Nullable + private static String getMobileFriendlyCategorySlug(@Nullable WPComThemeTaxonomies taxonomies) { // detect the mobile-friendly category slug if there - if (response.taxonomies != null && response.taxonomies.theme_mobile_friendly != null) { + if (taxonomies != null && taxonomies.theme_mobile_friendly != null) { String category = null; - for (WPComThemeMobileFriendlyTaxonomy taxonomy : response.taxonomies.theme_mobile_friendly) { + 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. @@ -269,34 +277,31 @@ private static ThemeModel createThemeFromWPComResponse(@NonNull WPComThemeRespon // we got the category slug so, no need to continue looping break; } - theme.setMobileFriendlyCategorySlug(category); + return category; } - - return theme; + return null; } @NonNull private static ThemeModel createThemeFromJetpackResponse(@NonNull JetpackThemeResponse response) { - ThemeModel theme = new ThemeModel(); - theme.setThemeId(response.id); - theme.setName(response.name); - theme.setThemeUrl(response.theme_uri); - theme.setDescription(response.description); - theme.setAuthorName(response.author); - theme.setAuthorUrl(response.author_uri); - theme.setVersion(response.version); - theme.setActive(response.active); - theme.setAutoUpdate(response.autoupdate); - theme.setAutoUpdateTranslation(response.autoupdate_translation); - // 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; } - theme.setScreenshotUrl(screenshotUrl); - - return theme; + 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 + ); } @NonNull @@ -327,9 +332,7 @@ private static List createThemeListFromJetpackResponse(@NonNull Jetp */ @NonNull private String getThemeIdWithWpComSuffix(@NonNull ThemeModel theme) { - if (theme.getThemeId() == null) { - return ""; - } else if (theme.getThemeId().endsWith("-wpcom")) { + if (theme.getThemeId().endsWith("-wpcom")) { return theme.getThemeId(); } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ThemeSqlUtils.java b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ThemeSqlUtils.java index 5adc36ae35..bc248e5672 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ThemeSqlUtils.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/ThemeSqlUtils.java @@ -3,6 +3,7 @@ import android.text.TextUtils; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.wellsql.generated.ThemeModelTable; import com.yarolegovich.wellsql.WellSql; @@ -78,6 +79,7 @@ public static void insertOrReplaceActiveThemeForSite(@NonNull SiteModel site, @N insertOrUpdateSiteTheme(site, theme); } + @NonNull public static List getActiveThemeForSite(@NonNull SiteModel site) { return WellSql.select(ThemeModel.class) .where().beginGroup() @@ -86,6 +88,7 @@ public static List getActiveThemeForSite(@NonNull SiteModel site) { .endGroup().endWhere().getAsModel(); } + @NonNull public static List getWpComThemes() { return WellSql.select(ThemeModel.class) .where() @@ -93,6 +96,7 @@ public static List getWpComThemes() { .endWhere().getAsModel(); } + @NonNull public static List getWpComThemes(@NonNull List themeIds) { return WellSql.select(ThemeModel.class) .where() @@ -101,7 +105,8 @@ public static List getWpComThemes(@NonNull List themeIds) { .endWhere().getAsModel(); } - public static List getWpComMobileFriendlyThemes(String categorySlug) { + @NonNull + public static List getWpComMobileFriendlyThemes(@NonNull String categorySlug) { return WellSql.select(ThemeModel.class) .where() .equals(ThemeModelTable.MOBILE_FRIENDLY_CATEGORY_SLUG, categorySlug) @@ -109,6 +114,7 @@ public static List getWpComMobileFriendlyThemes(String categorySlug) .endWhere().getAsModel(); } + @NonNull public static List getThemesForSite(@NonNull SiteModel site) { return WellSql.select(ThemeModel.class) .where() @@ -116,7 +122,8 @@ public static List getThemesForSite(@NonNull SiteModel site) { .endWhere().getAsModel(); } - public static ThemeModel getWpComThemeByThemeId(String themeId) { + @Nullable + public static ThemeModel getWpComThemeByThemeId(@NonNull String themeId) { if (TextUtils.isEmpty(themeId)) { return null; } @@ -134,8 +141,9 @@ public static ThemeModel getWpComThemeByThemeId(String themeId) { return matches.get(0); } - public static ThemeModel getSiteThemeByThemeId(SiteModel siteModel, String themeId) { - if (siteModel == null || TextUtils.isEmpty(themeId)) { + @Nullable + public static ThemeModel getSiteThemeByThemeId(@NonNull SiteModel siteModel, @NonNull String themeId) { + if (TextUtils.isEmpty(themeId)) { return null; } List matches = WellSql.select(ThemeModel.class) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.java index 37d037c94d..70b80b37b0 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/ThemeStore.java @@ -151,12 +151,11 @@ public enum ThemeErrorType { UNKNOWN_THEME, MISSING_THEME; - public static ThemeErrorType fromString(String type) { - if (type != null) { - for (ThemeErrorType v : ThemeErrorType.values()) { - if (type.equalsIgnoreCase(v.name())) { - return v; - } + @NonNull + public static ThemeErrorType fromString(@NonNull String type) { + for (ThemeErrorType v : ThemeErrorType.values()) { + if (type.equalsIgnoreCase(v.name())) { + return v; } } return GENERIC_ERROR; @@ -165,15 +164,15 @@ public static ThemeErrorType fromString(String type) { @SuppressWarnings("WeakerAccess") public static class ThemesError implements OnChangedError { - public ThemeErrorType type; - public String message; + @NonNull public ThemeErrorType type; + @Nullable public String message; - public ThemesError(String type, String message) { + public ThemesError(@NonNull String type, @Nullable String message) { this.type = ThemeErrorType.fromString(type); this.message = message; } - public ThemesError(ThemeErrorType type) { + public ThemesError(@NonNull ThemeErrorType type) { this.type = type; } } @@ -206,10 +205,10 @@ public OnCurrentThemeFetched(@NonNull SiteModel site, @Nullable ThemeModel theme @SuppressWarnings("WeakerAccess") public static class OnThemeActivated extends OnChanged { - public SiteModel site; - public ThemeModel theme; + @NonNull public SiteModel site; + @NonNull public ThemeModel theme; - public OnThemeActivated(SiteModel site, ThemeModel theme) { + public OnThemeActivated(@NonNull SiteModel site, @NonNull ThemeModel theme) { this.site = site; this.theme = theme; } @@ -217,8 +216,8 @@ public OnThemeActivated(SiteModel site, ThemeModel theme) { @SuppressWarnings("WeakerAccess") public static class OnThemeRemoved extends OnChanged { - public SiteModel site; - public ThemeModel theme; + @NonNull public SiteModel site; + @NonNull public ThemeModel theme; public OnThemeRemoved(@NonNull SiteModel site, @NonNull ThemeModel theme) { this.site = site; @@ -228,10 +227,10 @@ public OnThemeRemoved(@NonNull SiteModel site, @NonNull ThemeModel theme) { @SuppressWarnings("WeakerAccess") public static class OnThemeDeleted extends OnChanged { - public SiteModel site; - public ThemeModel theme; + @NonNull public SiteModel site; + @NonNull public ThemeModel theme; - public OnThemeDeleted(SiteModel site, ThemeModel theme) { + public OnThemeDeleted(@NonNull SiteModel site, @NonNull ThemeModel theme) { this.site = site; this.theme = theme; } @@ -239,10 +238,10 @@ public OnThemeDeleted(SiteModel site, ThemeModel theme) { @SuppressWarnings("WeakerAccess") public static class OnThemeInstalled extends OnChanged { - public SiteModel site; - public ThemeModel theme; + @NonNull public SiteModel site; + @NonNull public ThemeModel theme; - public OnThemeInstalled(SiteModel site, ThemeModel theme) { + public OnThemeInstalled(@NonNull SiteModel site, @NonNull ThemeModel theme) { this.site = site; this.theme = theme; } @@ -331,37 +330,44 @@ 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); } - public List getWpComMobileFriendlyThemes(String categorySlug) { + @NonNull + public List getWpComMobileFriendlyThemes(@NonNull String categorySlug) { return ThemeSqlUtils.getWpComMobileFriendlyThemes(categorySlug); } + @NonNull public List getThemesForSite(@NonNull SiteModel site) { return ThemeSqlUtils.getThemesForSite(site); } - public ThemeModel getInstalledThemeByThemeId(SiteModel siteModel, String themeId) { - if (themeId == null || themeId.isEmpty()) { + @Nullable + public ThemeModel getInstalledThemeByThemeId(@NonNull SiteModel siteModel, @NonNull String themeId) { + if (TextUtils.isEmpty(themeId)) { return null; } return ThemeSqlUtils.getSiteThemeByThemeId(siteModel, themeId); } + @Nullable @SuppressWarnings("WeakerAccess") - public ThemeModel getWpComThemeByThemeId(String themeId) { + public ThemeModel getWpComThemeByThemeId(@NonNull String themeId) { if (TextUtils.isEmpty(themeId)) { return null; } return ThemeSqlUtils.getWpComThemeByThemeId(themeId); } + @Nullable public ThemeModel getActiveThemeForSite(@NonNull SiteModel site) { List activeTheme = ThemeSqlUtils.getActiveThemeForSite(site); return activeTheme.isEmpty() ? null : activeTheme.get(0);