use of org.wordpress.android.fluxc.model.PostModel in project WordPress-Android by wordpress-mobile.
the class FluxCMigrationTest method testDraftMigration.
public void testDraftMigration() throws DuplicateSiteException {
TestUtils.loadDBFromDump(mRenamingTargetAppContext, mTestContext, "FluxC-migration.sql");
// Migrate sites first so that SiteStore is populated
List<SiteModel> sites = WPLegacyMigrationUtils.getSelfHostedSitesFromDeprecatedDB(mRenamingTargetAppContext);
for (SiteModel site : sites) {
SiteSqlUtils.insertOrUpdateSite(site);
}
AppLog.d(AppLog.T.DB, "Added " + mSiteStore.getSitesCount() + " sites to SiteStore");
List<PostModel> posts = WPLegacyMigrationUtils.getDraftsFromDeprecatedDB(mRenamingTargetAppContext, mSiteStore);
AppLog.d(AppLog.T.DB, "Extracted " + posts.size() + " drafts from legacy DB");
assertEquals(3, posts.size());
assertEquals("", posts.get(0).getTitle());
assertEquals("This is a title", posts.get(1).getTitle());
assertEquals("This is a title also", posts.get(2).getTitle());
}
use of org.wordpress.android.fluxc.model.PostModel in project WordPress-Android by wordpress-mobile.
the class WPMainActivity method launchWithPostId.
/**
* called from an internal pending draft notification, so the user can land in the local draft and take action
* such as finish editing and publish, or delete the post, etc.
*/
private void launchWithPostId(int postId, boolean isPage) {
if (isFinishing() || getIntent() == null)
return;
AnalyticsTracker.track(AnalyticsTracker.Stat.NOTIFICATION_PENDING_DRAFTS_TAPPED);
NativeNotificationsUtils.dismissNotification(PendingDraftsNotificationsUtils.makePendingDraftNotificationId(postId), this);
// if no specific post id passed, show the list
if (postId == 0) {
// show list
if (isPage) {
ActivityLauncher.viewCurrentBlogPages(this, getSelectedSite());
} else {
ActivityLauncher.viewCurrentBlogPosts(this, getSelectedSite());
}
} else {
PostModel post = mPostStore.getPostByLocalPostId(postId);
ActivityLauncher.editPostOrPageForResult(this, getSelectedSite(), post);
}
}
use of org.wordpress.android.fluxc.model.PostModel in project WordPress-Android by wordpress-mobile.
the class NotificationsPendingDraftsReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
((WordPress) context.getApplicationContext()).component().inject(this);
// for the case of being spanned after device restarts, get the latest drafts
// and check the lastUpdated
String action = intent.getAction();
if (action != null && action.equals("android.intent.action.BOOT_COMPLETED")) {
AppLog.i(AppLog.T.NOTIFS, "entering Pending Drafts Receiver from BOOT_COMPLETED");
// build notifications for existing local drafts
int siteLocalId = AppPrefs.getSelectedSite();
SiteModel site = mSiteStore.getSiteByLocalId(siteLocalId);
if (site != null) {
List<PostModel> draftPosts = mPostStore.getPostsForSite(site);
for (PostModel post : draftPosts) {
// reschedule next notifications for each local draft post we have, as we have
// just been rebooted
PendingDraftsNotificationsUtils.scheduleNextNotifications(context, post);
}
}
} else {
AppLog.i(AppLog.T.NOTIFS, "entering Pending Drafts Receiver from alarm");
// get extras from intent in order to build notification
buildNotificationForPostId(intent.getIntExtra(POST_ID_EXTRA, 0), context);
}
}
use of org.wordpress.android.fluxc.model.PostModel in project WordPress-Android by wordpress-mobile.
the class NotificationsPendingDraftsReceiver method buildNotificationForPostId.
private void buildNotificationForPostId(int postId, Context context) {
if (postId != 0) {
PostModel post = mPostStore.getPostByLocalPostId(postId);
if (post != null) {
long now = System.currentTimeMillis();
long dateLastUpdated = DateTimeUtils.timestampFromIso8601(post.getDateLocallyChanged());
long daysInDraft = (now - dateLastUpdated) / ONE_DAY;
boolean isPage = post.isPage();
if (daysInDraft < MAX_DAYS_TO_SHOW_DAYS_IN_MESSAGE) {
String formattedString = context.getString(R.string.pending_draft_one_generic);
long one_day_ago = now - ONE_DAY;
long one_week_ago = now - ONE_WEEK;
long one_month_ago = now - ONE_MONTH;
if (dateLastUpdated < one_month_ago) {
formattedString = context.getString(R.string.pending_draft_one_month);
} else if (dateLastUpdated < one_week_ago) {
// use any of the available 2 string formats, randomly
Random randomNum = new Random();
int result = randomNum.nextInt(2);
if (result == 0)
formattedString = context.getString(R.string.pending_draft_one_week_1);
else
formattedString = context.getString(R.string.pending_draft_one_week_2);
} else if (dateLastUpdated < one_day_ago) {
// use any of the available 2 string formats, randomly
Random randomNum = new Random();
int result = randomNum.nextInt(2);
if (result == 0)
formattedString = context.getString(R.string.pending_draft_one_day_1);
else
formattedString = context.getString(R.string.pending_draft_one_day_2);
}
buildSinglePendingDraftNotification(context, post.getTitle(), formattedString, postId, isPage);
} else {
// if it's been more than MAX_DAYS_TO_SHOW_DAYS_IN_MESSAGE days, or if we don't know (i.e. value for lastUpdated
// is zero) then just show a generic message
buildSinglePendingDraftNotificationGeneric(context, post.getTitle(), postId, isPage);
}
}
}
}
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);
}
}
});
}
Aggregations