diff --git a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java index d5a0186b4426..b1c3505aeceb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java @@ -410,7 +410,7 @@ private void fetchInstalledThemesIfJetpackSite() { } } - private void activateTheme(String themeId) { + private void activateTheme(@NonNull String themeId) { if (!mSite.isUsingWpComRestApi()) { AppLog.i(T.THEMES, "Theme activation requires a site using WP.com REST API. Aborting request."); return; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserAdapter.java index 900feb389b1b..a4d46b6b4198 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserAdapter.java @@ -170,7 +170,10 @@ public View getView(int position, View convertView, ViewGroup parent) { } @SuppressWarnings("deprecation") - private void configureCardView(ThemeViewHolder themeViewHolder, boolean isCurrent) { + private void configureCardView( + @NonNull ThemeViewHolder themeViewHolder, + boolean isCurrent + ) { if (isCurrent) { ColorStateList color = ContextExtensionsKt.getColorStateListFromAttribute( mContext, @@ -200,10 +203,18 @@ private void configureCardView(ThemeViewHolder themeViewHolder, boolean isCurren } } - private void configureImageView(ThemeViewHolder themeViewHolder, String screenshotURL, final String themeId, - final boolean isCurrent) { - mImageManager.load(themeViewHolder.mImageView, ImageType.THEME, getUrlWithWidth(screenshotURL), - ScaleType.FIT_CENTER); + private void configureImageView( + @NonNull ThemeViewHolder themeViewHolder, + @NonNull String screenshotURL, + @NonNull final String themeId, + final boolean isCurrent + ) { + mImageManager.load( + themeViewHolder.mImageView, + ImageType.THEME, + getUrlWithWidth(screenshotURL), + ScaleType.FIT_CENTER + ); themeViewHolder.mCardView.setOnClickListener(new View.OnClickListener() { @Override @@ -217,7 +228,8 @@ public void onClick(View v) { }); } - private String getUrlWithWidth(String screenshotURL) { + @NonNull + private String getUrlWithWidth(@NonNull String screenshotURL) { if (screenshotURL.contains("?")) { return screenshotURL + "&" + THEME_IMAGE_PARAMETER + mViewWidth; } else { @@ -225,8 +237,12 @@ private String getUrlWithWidth(String screenshotURL) { } } - private void configureImageButton(ThemeViewHolder themeViewHolder, final String themeId, final boolean isPremium, - boolean isCurrent) { + private void configureImageButton( + @NonNull ThemeViewHolder themeViewHolder, + @NonNull final String themeId, + final boolean isPremium, + boolean isCurrent + ) { final PopupMenu popupMenu = new PopupMenu(mContext, themeViewHolder.mImageButton); popupMenu.getMenuInflater().inflate(R.menu.theme_more, popupMenu.getMenu()); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserFragment.kt index 39da031d1bf8..b3fc264ddf07 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserFragment.kt @@ -242,7 +242,7 @@ class ThemeBrowserFragment : Fragment(), AbsListView.RecyclerListener, } } - fun setCurrentThemeId(currentThemeId: String?) { + fun setCurrentThemeId(currentThemeId: String) { this.currentThemeId = currentThemeId refreshView() } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeWebActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeWebActivity.java index a8ea5f98baf9..c49fe76d2f01 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeWebActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeWebActivity.java @@ -54,8 +54,12 @@ public static String getSiteLoginUrl(SiteModel site) { return WPWebViewActivity.getSiteLoginUrl(site); } - public static void openTheme(Activity activity, @NonNull SiteModel site, @NonNull ThemeModel theme, - @NonNull ThemeWebActivityType type) { + public static void openTheme( + Activity activity, + @NonNull SiteModel site, + @NonNull ThemeModel theme, + @NonNull ThemeWebActivityType type + ) { String url = getUrl(site, theme, type, !theme.isFree()); if (TextUtils.isEmpty(url)) { ToastUtils.showToast(activity, R.string.could_not_load_theme); @@ -72,7 +76,12 @@ public static void openTheme(Activity activity, @NonNull SiteModel site, @NonNul } } - private static void openWPCOMURL(Activity activity, String url, ThemeModel theme, SiteModel site) { + private static void openWPCOMURL( + Activity activity, + String url, + @NonNull ThemeModel theme, + SiteModel site + ) { if (activity == null) { AppLog.e(AppLog.T.UTILS, "ThemeWebActivity requires a non-null activity"); return; @@ -95,6 +104,7 @@ private static void openWPCOMURL(Activity activity, String url, ThemeModel theme activity.startActivityForResult(intent, ThemeBrowserActivity.ACTIVATE_THEME); } + @Nullable public static String getIdentifierForCustomizer(@NonNull SiteModel site, @NonNull ThemeModel theme) { if (site.isJetpackConnected()) { return theme.getThemeId(); @@ -103,8 +113,13 @@ public static String getIdentifierForCustomizer(@NonNull SiteModel site, @NonNul } } - public static String getUrl(@NonNull SiteModel site, @NonNull ThemeModel theme, @NonNull ThemeWebActivityType type, - boolean isPremium) { + @Nullable + public static String getUrl( + @NonNull SiteModel site, + @NonNull ThemeModel theme, + @NonNull ThemeWebActivityType type, + boolean isPremium + ) { if (theme.isWpComTheme()) { switch (type) { case PREVIEW: @@ -113,10 +128,14 @@ public static String getUrl(@NonNull SiteModel site, @NonNull ThemeModel theme, .format(THEME_URL_PREVIEW, UrlUtils.getHost(site.getUrl()), domain, theme.getThemeId()); case DEMO: String url = theme.getDemoUrl(); - if (url.contains("?")) { - return url + "&" + THEME_URL_DEMO_PARAMETER; + if (url != null) { + if (url.contains("?")) { + return url + "&" + THEME_URL_DEMO_PARAMETER; + } else { + return url + "?" + THEME_URL_DEMO_PARAMETER; + } } else { - return url + "?" + THEME_URL_DEMO_PARAMETER; + return null; } case DETAILS: return String.format(THEME_URL_DETAILS, theme.getThemeId()); @@ -126,7 +145,12 @@ public static String getUrl(@NonNull SiteModel site, @NonNull ThemeModel theme, } else { switch (type) { case PREVIEW: - return site.getAdminUrl() + "customize.php?theme=" + getIdentifierForCustomizer(site, theme); + String identifier = getIdentifierForCustomizer(site, theme); + if (identifier != null) { + return site.getAdminUrl() + "customize.php?theme=" + identifier; + } else { + return null; + } case DEMO: return site.getAdminUrl() + "themes.php?theme=" + theme.getThemeId(); case DETAILS: diff --git a/build.gradle b/build.gradle index c5b57f979717..44d6b2f96300 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ ext { automatticTracksVersion = '3.3.0' gutenbergMobileVersion = 'v1.109.1' wordPressAztecVersion = 'v1.8.0' - wordPressFluxCVersion = 'trunk-cdc8effb2affbb1c6bcf01f6606c847f87071d28' + wordPressFluxCVersion = 'trunk-b4e51008f7200eba1dfdd22ca370fce450ce93b0' wordPressLoginVersion = '1.10.0' wordPressPersistentEditTextVersion = '1.0.2' wordPressUtilsVersion = '3.10.0'