Search in sources :

Example 26 with SiteModel

use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.

the class PostUploadService method onMediaUploaded.

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMediaUploaded(OnMediaUploaded event) {
    // Event for unknown media, ignoring
    if (event.media == null || mCurrentUploadingPost == null || mMediaLatchMap.get(event.media.getId()) == null) {
        AppLog.w(T.POSTS, "Media event not recognized: " + event.media);
        return;
    }
    if (event.isError()) {
        SiteModel site = mSiteStore.getSiteByLocalId(mCurrentUploadingPost.getLocalSiteId());
        // TODO: We should interpret event.error.type and pass our own string rather than use error.message
        String message = TextUtils.isEmpty(event.error.message) ? event.error.type.toString() : event.error.message;
        mPostUploadNotifier.updateNotificationError(mCurrentUploadingPost, site, message, true);
        mFirstPublishPosts.remove(mCurrentUploadingPost.getId());
        finishUpload();
        return;
    }
    if (event.canceled) {
        // Not implemented
        return;
    }
    if (event.completed) {
        AppLog.i(T.POSTS, "Media upload completed for post. Media id: " + event.media.getId() + ", post id: " + mCurrentUploadingPost.getId());
        mMediaLatchMap.get(event.media.getId()).countDown();
        mMediaLatchMap.remove(event.media.getId());
    } else {
        // Progress update
        mPostUploadNotifier.updateNotificationProgress(mCurrentUploadingPost, event.progress);
    }
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 27 with SiteModel

use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.

the class NotificationsSettingsFragment method configureBlogsSettings.

private void configureBlogsSettings(PreferenceCategory blogsCategory, boolean showAll) {
    if (!isAdded())
        return;
    List<SiteModel> sites;
    String trimmedQuery = "";
    if (mSearchView != null && !TextUtils.isEmpty(mSearchView.getQuery())) {
        trimmedQuery = mSearchView.getQuery().toString().trim();
        sites = mSiteStore.getWPComAndJetpackSitesByNameOrUrlMatching(trimmedQuery);
    } else {
        sites = mSiteStore.getWPComAndJetpackSites();
    }
    mSiteCount = sites.size();
    Context context = getActivity();
    blogsCategory.removeAll();
    int maxSitesToShow = showAll ? NO_MAXIMUM : MAX_SITES_TO_SHOW_ON_FIRST_SCREEN;
    int count = 0;
    for (SiteModel site : sites) {
        if (context == null)
            return;
        count++;
        if (maxSitesToShow != NO_MAXIMUM && count > maxSitesToShow)
            break;
        PreferenceScreen prefScreen = getPreferenceManager().createPreferenceScreen(context);
        prefScreen.setTitle(SiteUtils.getSiteNameOrHomeURL(site));
        prefScreen.setSummary(SiteUtils.getHomeURLOrHostName(site));
        addPreferencesForPreferenceScreen(prefScreen, Channel.BLOGS, site.getSiteId());
        blogsCategory.addPreference(prefScreen);
    }
    // Add a message in a preference if there are no matching search results
    if (mSiteCount == 0 && !TextUtils.isEmpty(trimmedQuery)) {
        Preference searchResultsPref = new Preference(context);
        searchResultsPref.setSummary(String.format(getString(R.string.notifications_no_search_results), trimmedQuery));
        blogsCategory.addPreference(searchResultsPref);
    }
    if (mSiteCount > maxSitesToShow && !showAll) {
        //append a "view all" option
        appendViewAllSitesOption(context);
    }
    updateSearchMenuVisibility();
}
Also used : Context(android.content.Context) PreferenceScreen(android.preference.PreferenceScreen) Preference(android.preference.Preference) SiteModel(org.wordpress.android.fluxc.model.SiteModel)

Example 28 with SiteModel

use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.

the class AddQuickPressShortcutActivity method displayAccounts.

private void displayAccounts() {
    List<SiteModel> sites = mSiteStore.getVisibleSites();
    ListView listView = (ListView) findViewById(android.R.id.list);
    ImageView iv = new ImageView(this);
    iv.setBackgroundDrawable(getResources().getDrawable(R.drawable.list_divider));
    listView.addFooterView(iv);
    listView.setVerticalFadingEdgeEnabled(false);
    listView.setVerticalScrollBarEnabled(true);
    if (sites.size() > 0) {
        ScrollView sv = new ScrollView(this);
        sv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        LinearLayout layout = new LinearLayout(this);
        layout.setPadding(10, 10, 10, 0);
        layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        layout.setOrientation(LinearLayout.VERTICAL);
        blogNames = new String[sites.size()];
        siteIds = new int[sites.size()];
        accountUsers = new String[sites.size()];
        blavatars = new String[sites.size()];
        for (int i = 0; i < sites.size(); i++) {
            SiteModel site = sites.get(i);
            blogNames[i] = SiteUtils.getSiteNameOrHomeURL(site);
            accountUsers[i] = site.getUsername();
            siteIds[i] = site.getId();
            if (site.getUrl() != null) {
                blavatars[i] = SiteUtils.getSiteIconUrl(site, 60);
            } else {
                blavatars[i] = "";
            }
            accountNames.add(i, blogNames[i]);
        }
        setListAdapter(new HomeListAdapter());
        listView.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View row, int position, long id) {
                AddQuickPressShortcutActivity.this.buildDialog(position);
            }
        });
        if (sites.size() == 1) {
            AddQuickPressShortcutActivity.this.buildDialog(0);
        }
    } else {
        // no account, load new account view
        Intent i = new Intent(AddQuickPressShortcutActivity.this, SignInActivity.class);
        startActivityForResult(i, ADD_ACCOUNT_REQUEST);
    }
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) SiteModel(org.wordpress.android.fluxc.model.SiteModel) Intent(android.content.Intent) NetworkImageView(com.android.volley.toolbox.NetworkImageView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ListView(android.widget.ListView) ListView(android.widget.ListView) ScrollView(android.widget.ScrollView) NetworkImageView(com.android.volley.toolbox.NetworkImageView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 29 with SiteModel

use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.

the class WPWebViewActivity method configureWebView.

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void configureWebView() {
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    WebViewClient webViewClient;
    Bundle extras = getIntent().getExtras();
    // Configure the allowed URLs if available
    ArrayList<String> allowedURL = null;
    if (extras.getBoolean(DISABLE_LINKS_ON_PAGE, false)) {
        String addressToLoad = extras.getString(URL_TO_LOAD);
        String authURL = extras.getString(AUTHENTICATION_URL);
        allowedURL = new ArrayList<>();
        if (!TextUtils.isEmpty(addressToLoad)) {
            allowedURL.add(addressToLoad);
        }
        if (!TextUtils.isEmpty(authURL)) {
            allowedURL.add(authURL);
        }
        if (extras.getStringArray(ALLOWED_URLS) != null) {
            String[] urls = extras.getStringArray(ALLOWED_URLS);
            for (String currentURL : urls) {
                allowedURL.add(currentURL);
            }
        }
    }
    if (getIntent().hasExtra(LOCAL_BLOG_ID)) {
        SiteModel site = mSiteStore.getSiteByLocalId(getIntent().getIntExtra(LOCAL_BLOG_ID, -1));
        if (site == null) {
            AppLog.e(AppLog.T.UTILS, "No valid blog passed to WPWebViewActivity");
            finish();
        }
        webViewClient = new WPWebViewClient(site, mAccountStore.getAccessToken(), allowedURL);
    } else {
        webViewClient = new URLFilteredWebViewClient(allowedURL);
    }
    mWebView.setWebViewClient(webViewClient);
    mWebView.setWebChromeClient(new WPWebChromeClient(this, (ProgressBar) findViewById(R.id.progress_bar)));
}
Also used : WPWebViewClient(org.wordpress.android.util.WPWebViewClient) Bundle(android.os.Bundle) SiteModel(org.wordpress.android.fluxc.model.SiteModel) URLFilteredWebViewClient(org.wordpress.android.util.URLFilteredWebViewClient) ProgressBar(android.widget.ProgressBar) WPWebChromeClient(org.wordpress.android.util.helpers.WPWebChromeClient) WebViewClient(android.webkit.WebViewClient) WPWebViewClient(org.wordpress.android.util.WPWebViewClient) URLFilteredWebViewClient(org.wordpress.android.util.URLFilteredWebViewClient) SuppressLint(android.annotation.SuppressLint)

Example 30 with SiteModel

use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.

the class ShareIntentReceiverActivity method initSiteLists.

private void initSiteLists() {
    List<SiteModel> sites = mSiteStore.getVisibleSites();
    if (sites.size() > 0) {
        mSiteNames = new String[sites.size()];
        mSiteIds = new int[sites.size()];
        int i = 0;
        for (SiteModel site : sites) {
            mSiteNames[i] = SiteUtils.getSiteNameOrHomeURL(site);
            mSiteIds[i] = site.getId();
            i += 1;
        }
        // default selected site to the first one
        mSelectedSiteLocalId = mSiteIds[0];
    }
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel)

Aggregations

SiteModel (org.wordpress.android.fluxc.model.SiteModel)40 Intent (android.content.Intent)7 Subscribe (org.greenrobot.eventbus.Subscribe)5 View (android.view.View)4 Bundle (android.os.Bundle)3 TextView (android.widget.TextView)3 VolleyError (com.android.volley.VolleyError)3 ArrayList (java.util.ArrayList)3 JSONObject (org.json.JSONObject)3 AlertDialog (android.app.AlertDialog)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 ImageView (android.widget.ImageView)2 ScrollView (android.widget.ScrollView)2 RestRequest (com.wordpress.rest.RestRequest)2 CommentModel (org.wordpress.android.fluxc.model.CommentModel)2 PostModel (org.wordpress.android.fluxc.model.PostModel)2 WPNetworkImageView (org.wordpress.android.widgets.WPNetworkImageView)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1