Search in sources :

Example 1 with Listener

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;
        }
    });
}
Also used : ErrorListener(com.wordpress.rest.RestRequest.ErrorListener) VolleyError(com.android.volley.VolleyError) ErrorListener(com.wordpress.rest.RestRequest.ErrorListener) Listener(com.wordpress.rest.RestRequest.Listener) FragmentTransaction(android.app.FragmentTransaction) JSONObject(org.json.JSONObject) WPAlertDialogFragment(org.wordpress.android.widgets.WPAlertDialogFragment)

Example 2 with Listener

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();
        }
    });
}
Also used : ErrorListener(com.wordpress.rest.RestRequest.ErrorListener) VolleyError(com.android.volley.VolleyError) ErrorListener(com.wordpress.rest.RestRequest.ErrorListener) Listener(com.wordpress.rest.RestRequest.Listener) JSONObject(org.json.JSONObject) Theme(org.wordpress.android.models.Theme) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Listener

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;
        }
    });
}
Also used : ErrorListener(com.wordpress.rest.RestRequest.ErrorListener) VolleyError(com.android.volley.VolleyError) ErrorListener(com.wordpress.rest.RestRequest.ErrorListener) Listener(com.wordpress.rest.RestRequest.Listener) FragmentTransaction(android.app.FragmentTransaction) JSONObject(org.json.JSONObject) WPAlertDialogFragment(org.wordpress.android.widgets.WPAlertDialogFragment)

Aggregations

VolleyError (com.android.volley.VolleyError)3 ErrorListener (com.wordpress.rest.RestRequest.ErrorListener)3 Listener (com.wordpress.rest.RestRequest.Listener)3 JSONObject (org.json.JSONObject)3 FragmentTransaction (android.app.FragmentTransaction)2 WPAlertDialogFragment (org.wordpress.android.widgets.WPAlertDialogFragment)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Theme (org.wordpress.android.models.Theme)1