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);
}
}
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();
}
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);
}
}
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)));
}
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];
}
}
Aggregations