use of com.wordpress.rest.RestRequest.Listener in project WordPress-Android by wordpress-mobile.
the class ThemeBrowserActivity method searchThemes.
public void searchThemes(String searchTerm) {
mFetchingThemes = true;
int page = 1;
if (mThemeSearchFragment != null) {
page = mThemeSearchFragment.getPage();
}
WordPress.getRestClientUtilsV1_2().getFreeSearchThemes(mSite.getSiteId(), THEME_FETCH_MAX, page, searchTerm, new Listener() {
@Override
public void onResponse(JSONObject response) {
new FetchThemesTask().execute(response);
}
}, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError response) {
if (response.toString().equals(AuthFailureError.class.getName())) {
String errorTitle = getString(R.string.theme_auth_error_title);
String errorMsg = getString(R.string.theme_auth_error_message);
if (mIsRunning) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
WPAlertDialogFragment fragment = WPAlertDialogFragment.newAlertDialog(errorMsg, errorTitle);
ft.add(fragment, ALERT_TAB);
ft.commitAllowingStateLoss();
}
AppLog.d(T.THEMES, getString(R.string.theme_auth_error_authenticate));
}
mFetchingThemes = false;
}
});
}
use of com.wordpress.rest.RestRequest.Listener in project WordPress-Android by wordpress-mobile.
the class ThemeBrowserActivity method activateTheme.
private void activateTheme(final String themeId) {
final String newThemeId = themeId;
WordPress.getRestClientUtils().setTheme(mSite.getSiteId(), themeId, new Listener() {
@Override
public void onResponse(JSONObject response) {
WordPress.wpDB.setCurrentTheme(String.valueOf(mSite.getSiteId()), newThemeId);
Theme newTheme = WordPress.wpDB.getTheme(String.valueOf(mSite.getSiteId()), newThemeId);
Map<String, Object> themeProperties = new HashMap<>();
themeProperties.put(THEME_ID, themeId);
AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.THEMES_CHANGED_THEME, mSite, themeProperties);
if (!isFinishing()) {
showAlertDialogOnNewSettingNewTheme(newTheme);
fetchCurrentTheme();
}
}
}, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), R.string.theme_activation_error, Toast.LENGTH_SHORT).show();
}
});
}
use of com.wordpress.rest.RestRequest.Listener in project WordPress-Android by wordpress-mobile.
the class ThemeBrowserActivity method fetchThemes.
public void fetchThemes() {
if (mFetchingThemes) {
return;
}
mFetchingThemes = true;
int page = 1;
if (mThemeBrowserFragment != null) {
page = mThemeBrowserFragment.getPage();
}
WordPress.getRestClientUtilsV1_2().getFreeThemes(mSite.getSiteId(), THEME_FETCH_MAX, page, new Listener() {
@Override
public void onResponse(JSONObject response) {
new FetchThemesTask().execute(response);
}
}, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError response) {
if (response.toString().equals(AuthFailureError.class.getName())) {
String errorTitle = getString(R.string.theme_auth_error_title);
String errorMsg = getString(R.string.theme_auth_error_message);
if (mIsRunning) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
WPAlertDialogFragment fragment = WPAlertDialogFragment.newAlertDialog(errorMsg, errorTitle);
ft.add(fragment, ALERT_TAB);
ft.commitAllowingStateLoss();
}
AppLog.d(T.THEMES, getString(R.string.theme_auth_error_authenticate));
} else {
Toast.makeText(ThemeBrowserActivity.this, R.string.theme_fetch_failed, Toast.LENGTH_LONG).show();
AppLog.d(T.THEMES, getString(R.string.theme_fetch_failed) + ": " + response.toString());
}
mFetchingThemes = false;
}
});
}
Aggregations