Search in sources :

Example 1 with Theme

use of org.wordpress.android.models.Theme in project WordPress-Android by wordpress-mobile.

the class WordPressDB method getTheme.

public Theme getTheme(String blogId, String themeId) {
    String[] columns = { COLUMN_NAME_ID, Theme.ID, Theme.AUTHOR, Theme.SCREENSHOT, Theme.AUTHOR_URI, Theme.DEMO_URI, Theme.NAME, Theme.STYLESHEET, Theme.PRICE, Theme.IS_CURRENT };
    String[] selection = { blogId, themeId };
    Cursor cursor = db.query(THEMES_TABLE, columns, Theme.BLOG_ID + "=? AND " + Theme.ID + "=?", selection, null, null, null);
    if (cursor.moveToFirst()) {
        String id = cursor.getString(cursor.getColumnIndex(Theme.ID));
        String author = cursor.getString(cursor.getColumnIndex(Theme.AUTHOR));
        String screenshot = cursor.getString(cursor.getColumnIndex(Theme.SCREENSHOT));
        String authorURI = cursor.getString(cursor.getColumnIndex(Theme.AUTHOR_URI));
        String demoURI = cursor.getString(cursor.getColumnIndex(Theme.DEMO_URI));
        String name = cursor.getString(cursor.getColumnIndex(Theme.NAME));
        String stylesheet = cursor.getString(cursor.getColumnIndex(Theme.STYLESHEET));
        String price = cursor.getString(cursor.getColumnIndex(Theme.PRICE));
        boolean isCurrent = cursor.getInt(cursor.getColumnIndex(Theme.IS_CURRENT)) > 0;
        Theme theme = new Theme(id, author, screenshot, authorURI, demoURI, name, stylesheet, price, blogId, isCurrent);
        cursor.close();
        return theme;
    } else {
        cursor.close();
        return null;
    }
}
Also used : Theme(org.wordpress.android.models.Theme) Cursor(android.database.Cursor)

Example 2 with Theme

use of org.wordpress.android.models.Theme 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 Theme

use of org.wordpress.android.models.Theme in project WordPress-Android by wordpress-mobile.

the class ThemeWebActivity method openTheme.

public static void openTheme(Activity activity, SiteModel site, String themeId, ThemeWebActivityType type, boolean isCurrentTheme) {
    Theme currentTheme = WordPress.wpDB.getTheme(String.valueOf(site.getSiteId()), themeId);
    if (currentTheme == null) {
        ToastUtils.showToast(activity, R.string.could_not_load_theme);
        return;
    }
    String url = getUrl(site, currentTheme, type, currentTheme.isPremium());
    if (type == ThemeWebActivityType.PREVIEW) {
        // Do not open the Customizer with the in-app browser.
        // Customizer may need to access local files (mostly pictures) on the device storage,
        // and our internal webview doesn't handle this feature yet.
        // Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/4934
        ActivityLauncher.openUrlExternal(activity, url);
    } else {
        openWPCOMURL(activity, url, currentTheme, site, isCurrentTheme);
    }
}
Also used : Theme(org.wordpress.android.models.Theme)

Aggregations

Theme (org.wordpress.android.models.Theme)3 Cursor (android.database.Cursor)1 VolleyError (com.android.volley.VolleyError)1 ErrorListener (com.wordpress.rest.RestRequest.ErrorListener)1 Listener (com.wordpress.rest.RestRequest.Listener)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JSONObject (org.json.JSONObject)1