Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nullability Annotations to Java Classes] Use Updated and Null Proof ThemeModel Class (breaking) #19583

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -217,16 +228,21 @@ 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 {
return screenshotURL + "?" + THEME_IMAGE_PARAMETER + mViewWidth;
}
}

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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class ThemeBrowserFragment : Fragment(), AbsListView.RecyclerListener,
}
}

fun setCurrentThemeId(currentThemeId: String?) {
fun setCurrentThemeId(currentThemeId: String) {
this.currentThemeId = currentThemeId
refreshView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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:
Expand All @@ -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());
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ext {
automatticTracksVersion = '3.3.0'
gutenbergMobileVersion = 'v1.109.1'
wordPressAztecVersion = 'v1.8.0'
wordPressFluxCVersion = 'trunk-cdc8effb2affbb1c6bcf01f6606c847f87071d28'
wordPressFluxCVersion = '2897-6a898de293734581716dd45b6bfa1612d7196bf6'
wordPressLoginVersion = '1.10.0'
wordPressPersistentEditTextVersion = '1.0.2'
wordPressUtilsVersion = '3.10.0'
Expand Down