use of org.wordpress.android.fluxc.model.PostModel in project WordPress-Android by wordpress-mobile.
the class PostsListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
// nothing to do if this is the static endlist indicator
if (getItemViewType(position) == VIEW_TYPE_ENDLIST_INDICATOR) {
return;
}
final PostModel post = mPosts.get(position);
Context context = holder.itemView.getContext();
if (holder instanceof PostViewHolder) {
PostViewHolder postHolder = (PostViewHolder) holder;
if (StringUtils.isNotEmpty(post.getTitle())) {
postHolder.txtTitle.setText(post.getTitle());
} else {
postHolder.txtTitle.setText("(" + context.getResources().getText(R.string.untitled) + ")");
}
String cleanPostExcerpt = PostUtils.getPostListExcerptFromPost(post);
if (StringUtils.isNotEmpty(cleanPostExcerpt)) {
postHolder.txtExcerpt.setVisibility(View.VISIBLE);
postHolder.txtExcerpt.setText(PostUtils.collapseShortcodes(cleanPostExcerpt));
} else {
postHolder.txtExcerpt.setVisibility(View.GONE);
}
if (post.getFeaturedImageId() > 0 || mFeaturedImageUrls.containsKey(post.getId())) {
postHolder.imgFeatured.setVisibility(View.VISIBLE);
postHolder.imgFeatured.setImageUrl(mFeaturedImageUrls.get(post.getId()), WPNetworkImageView.ImageType.PHOTO);
} else {
postHolder.imgFeatured.setVisibility(View.GONE);
}
// local drafts say "delete" instead of "trash"
if (post.isLocalDraft()) {
postHolder.txtDate.setVisibility(View.GONE);
postHolder.btnTrash.setButtonType(PostListButton.BUTTON_DELETE);
} else {
postHolder.txtDate.setText(PostUtils.getFormattedDate(post));
postHolder.txtDate.setVisibility(View.VISIBLE);
postHolder.btnTrash.setButtonType(PostListButton.BUTTON_TRASH);
}
if (PostUploadService.isPostUploading(post)) {
postHolder.disabledOverlay.setVisibility(View.VISIBLE);
} else {
postHolder.disabledOverlay.setVisibility(View.GONE);
}
updateStatusText(postHolder.txtStatus, post);
configurePostButtons(postHolder, post);
} else if (holder instanceof PageViewHolder) {
PageViewHolder pageHolder = (PageViewHolder) holder;
if (StringUtils.isNotEmpty(post.getTitle())) {
pageHolder.txtTitle.setText(post.getTitle());
} else {
pageHolder.txtTitle.setText("(" + context.getResources().getText(R.string.untitled) + ")");
}
String dateStr = getPageDateHeaderText(context, post);
pageHolder.txtDate.setText(dateStr);
updateStatusText(pageHolder.txtStatus, post);
// don't show date header if same as previous
boolean showDate;
if (position > 0) {
String prevDateStr = getPageDateHeaderText(context, mPosts.get(position - 1));
showDate = !prevDateStr.equals(dateStr);
} else {
showDate = true;
}
pageHolder.dateHeader.setVisibility(showDate ? View.VISIBLE : View.GONE);
// no "..." more button when uploading
pageHolder.btnMore.setVisibility(PostUploadService.isPostUploading(post) ? View.GONE : View.VISIBLE);
pageHolder.btnMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showPagePopupMenu(v, post);
}
});
// only show the top divider for the first item
pageHolder.dividerTop.setVisibility(position == 0 ? View.VISIBLE : View.GONE);
if (PostUploadService.isPostUploading(post)) {
pageHolder.disabledOverlay.setVisibility(View.VISIBLE);
} else {
pageHolder.disabledOverlay.setVisibility(View.GONE);
}
}
// load more posts when we near the end
if (mOnLoadMoreListener != null && position >= mPosts.size() - 1 && position >= PostsListFragment.POSTS_REQUEST_COUNT - 1) {
mOnLoadMoreListener.onLoadMore();
}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mOnPostSelectedListener != null) {
mOnPostSelectedListener.onPostSelected(post);
}
}
});
}
use of org.wordpress.android.fluxc.model.PostModel in project WordPress-Android by wordpress-mobile.
the class PostUtils method postListsAreEqual.
public static boolean postListsAreEqual(List<PostModel> lhs, List<PostModel> rhs) {
if (lhs == null || rhs == null || lhs.size() != rhs.size()) {
return false;
}
for (int i = 0; i < rhs.size(); i++) {
PostModel newPost = rhs.get(i);
PostModel currentPost = lhs.get(i);
if (!newPost.equals(currentPost)) {
return false;
}
}
return true;
}
use of org.wordpress.android.fluxc.model.PostModel in project WordPress-Android by wordpress-mobile.
the class SelectCategoriesActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((WordPress) getApplication()).component().inject(this);
mDispatcher.register(this);
if (savedInstanceState == null) {
mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE);
} else {
mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
}
if (mSite == null) {
ToastUtils.showToast(this, R.string.blog_not_found, ToastUtils.Duration.SHORT);
finish();
return;
}
setContentView(R.layout.select_categories);
setTitle(getResources().getString(R.string.select_categories));
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
mListView = (ListView) findViewById(android.R.id.list);
mListScrollPositionManager = new ListScrollPositionManager(mListView, false);
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
mListView.setItemsCanFocus(false);
mEmptyView = (TextView) findViewById(R.id.empty_view);
mListView.setEmptyView(mEmptyView);
mSelectedCategories = new HashSet<>();
Bundle extras = getIntent().getExtras();
if (extras != null) {
if (extras.containsKey(KEY_POST)) {
PostModel post = (PostModel) extras.getSerializable(KEY_POST);
if (post != null) {
for (Long categoryId : post.getCategoryIdList()) {
mSelectedCategories.add(categoryId);
}
}
}
}
// swipe to refresh setup
mSwipeToRefreshHelper = new SwipeToRefreshHelper(this, (CustomSwipeRefreshLayout) findViewById(R.id.ptr_layout), new RefreshListener() {
@Override
public void onRefreshStarted() {
if (!NetworkUtils.checkConnection(getBaseContext())) {
mSwipeToRefreshHelper.setRefreshing(false);
return;
}
refreshCategories();
}
});
populateCategoryList();
if (NetworkUtils.isNetworkAvailable(this)) {
mEmptyView.setText(R.string.empty_list_default);
if (isCategoryListEmpty()) {
refreshCategories();
}
} else {
mEmptyView.setText(R.string.no_network_title);
}
}
use of org.wordpress.android.fluxc.model.PostModel in project WordPress-Android by wordpress-mobile.
the class WPLegacyMigrationUtils method migrateDraftsFromDeprecatedDB.
/**
* Copies existing drafts and locally changed posts from a previous version of WPAndroid into FluxC's PostStore.
* Existing posts are retained in the deprecated posts table after migration.
*/
public static void migrateDraftsFromDeprecatedDB(Context context, Dispatcher dispatcher, SiteStore siteStore) {
List<PostModel> postList = getDraftsFromDeprecatedDB(context.getApplicationContext(), siteStore);
if (postList != null) {
AppLog.i(T.DB, "Starting migration of " + postList.size() + " drafts to FluxC");
for (PostModel postModel : postList) {
AppLog.i(T.DB, "Migrating draft with title: " + postModel.getTitle() + " and local site ID: " + postModel.getLocalSiteId());
dispatcher.dispatch(PostActionBuilder.newUpdatePostAction(postModel));
}
}
}
use of org.wordpress.android.fluxc.model.PostModel in project WordPress-Android by wordpress-mobile.
the class EditPostActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((WordPress) getApplication()).component().inject(this);
mDispatcher.register(this);
setContentView(R.layout.new_edit_post_activity);
if (savedInstanceState == null) {
mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE);
} else {
mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
}
// Check whether to show the visual editor
PreferenceManager.setDefaultValues(this, R.xml.account_settings, false);
//AppPrefs.setAztecEditorAvailable(true);
//AppPrefs.setAztecEditorEnabled(true);
mShowAztecEditor = AppPrefs.isAztecEditorEnabled();
mShowNewEditor = AppPrefs.isVisualEditorEnabled();
// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
FragmentManager fragmentManager = getFragmentManager();
Bundle extras = getIntent().getExtras();
String action = getIntent().getAction();
if (savedInstanceState == null) {
if (!getIntent().hasExtra(EXTRA_POST) || Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action) || NEW_MEDIA_POST.equals(action) || getIntent().hasExtra(EXTRA_IS_QUICKPRESS)) {
if (getIntent().hasExtra(EXTRA_QUICKPRESS_BLOG_ID)) {
// QuickPress might want to use a different blog than the current blog
int localSiteId = getIntent().getIntExtra(EXTRA_QUICKPRESS_BLOG_ID, -1);
mSite = mSiteStore.getSiteByLocalId(localSiteId);
}
mIsPage = extras.getBoolean(EXTRA_IS_PAGE);
mIsNewPost = true;
if (mSite == null) {
showErrorAndFinish(R.string.blog_not_found);
return;
}
if (!mSite.isVisible()) {
showErrorAndFinish(R.string.error_blog_hidden);
return;
}
// Create a new post
List<Long> categories = new ArrayList<>();
categories.add((long) SiteSettingsInterface.getDefaultCategory(WordPress.getContext()));
String postFormat = SiteSettingsInterface.getDefaultFormat(WordPress.getContext());
mPost = mPostStore.instantiatePostModel(mSite, mIsPage, categories, postFormat);
} else if (extras != null) {
// Load post passed in extras
mPost = (PostModel) extras.getSerializable(EXTRA_POST);
if (mPost != null) {
mOriginalPost = mPost.clone();
mIsPage = mPost.isPage();
}
} else {
// A postId extra must be passed to this activity
showErrorAndFinish(R.string.post_not_found);
return;
}
} else {
mDroppedMediaUris = savedInstanceState.getParcelable(STATE_KEY_DROPPED_MEDIA_URIS);
if (savedInstanceState.containsKey(STATE_KEY_ORIGINAL_POST)) {
try {
mPost = (PostModel) savedInstanceState.getSerializable(STATE_KEY_CURRENT_POST);
mOriginalPost = (PostModel) savedInstanceState.getSerializable(STATE_KEY_ORIGINAL_POST);
} catch (ClassCastException e) {
mPost = null;
}
}
mEditorFragment = (EditorFragmentAbstract) fragmentManager.getFragment(savedInstanceState, STATE_KEY_EDITOR_FRAGMENT);
if (mEditorFragment instanceof EditorMediaUploadListener) {
mEditorMediaUploadListener = (EditorMediaUploadListener) mEditorFragment;
}
}
if (mSite == null) {
ToastUtils.showToast(this, R.string.blog_not_found, ToastUtils.Duration.SHORT);
finish();
return;
}
if (mHasSetPostContent = mEditorFragment != null) {
mEditorFragment.setImageLoader(mImageLoader);
}
// Ensure we have a valid post
if (mPost == null) {
showErrorAndFinish(R.string.post_not_found);
return;
}
if (mIsNewPost) {
trackEditorCreatedPost(action, getIntent());
}
setTitle(StringUtils.unescapeHTML(SiteUtils.getSiteNameOrHomeURL(mSite)));
mSectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager);
// Set up the ViewPager with the sections adapter.
mViewPager = (WPViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOffscreenPageLimit(2);
mViewPager.setPagingEnabled(false);
// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
invalidateOptionsMenu();
if (position == PAGE_CONTENT) {
setTitle(StringUtils.unescapeHTML(SiteUtils.getSiteNameOrHomeURL(mSite)));
} else if (position == PAGE_SETTINGS) {
setTitle(mPost.isPage() ? R.string.page_settings : R.string.post_settings);
hidePhotoChooser();
} else if (position == PAGE_PREVIEW) {
setTitle(mPost.isPage() ? R.string.preview_page : R.string.preview_post);
hidePhotoChooser();
savePostAsync(new AfterSavePostListener() {
@Override
public void onPostSave() {
if (mEditPostPreviewFragment != null) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (mEditPostPreviewFragment != null) {
mEditPostPreviewFragment.loadPost();
}
}
});
}
}
});
}
}
});
ActivityId.trackLastActivity(ActivityId.POST_EDITOR);
}
Aggregations