Skip to content

Commit

Permalink
Merge branch 'develop' into gutenberg/release_1.33_integration
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioEstevao committed Jul 23, 2020
2 parents 4647bda + d0707b1 commit f2a0ccd
Show file tree
Hide file tree
Showing 48 changed files with 1,797 additions and 158 deletions.
2 changes: 1 addition & 1 deletion WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ dependencies {
implementation 'com.android.installreferrer:installreferrer:1.0'
implementation 'com.github.chrisbanes.photoview:library:1.2.4'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation ('com.automattic:rest:1.0.7') {
implementation ('com.automattic:rest:1.0.8') {
exclude group: 'com.mcxiaoke.volley'
}
implementation 'org.wordpress:graphview:3.4.0'
Expand Down
22 changes: 16 additions & 6 deletions WordPress/src/main/java/org/wordpress/android/WordPress.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Application;
import android.app.NotificationChannel;
Expand Down Expand Up @@ -131,16 +132,17 @@ public class WordPress extends MultiDexApplication implements HasServiceInjector
public static WordPressDB wpDB;
public static boolean sAppIsInTheBackground = true;

private static RestClientUtils sRestClientUtils;
private static RestClientUtils sRestClientUtilsVersion1p1;
private static RestClientUtils sRestClientUtilsVersion1p2;
private static RestClientUtils sRestClientUtilsVersion1p3;
private static RestClientUtils sRestClientUtilsVersion0;
@SuppressLint("StaticFieldLeak") private static RestClientUtils sRestClientUtils;
@SuppressLint("StaticFieldLeak") private static RestClientUtils sRestClientUtilsVersion1p1;
@SuppressLint("StaticFieldLeak") private static RestClientUtils sRestClientUtilsVersion1p2;
@SuppressLint("StaticFieldLeak") private static RestClientUtils sRestClientUtilsVersion1p3;
@SuppressLint("StaticFieldLeak") private static RestClientUtils sRestClientUtilsVersion2p1;
@SuppressLint("StaticFieldLeak") private static RestClientUtils sRestClientUtilsVersion0;

private static final int SECONDS_BETWEEN_SITE_UPDATE = 60 * 60; // 1 hour
private static final int SECONDS_BETWEEN_BLOGLIST_UPDATE = 15 * 60; // 15 minutes

private static Context mContext;
@SuppressLint("StaticFieldLeak") private static Context mContext;
private static BitmapLruCache mBitmapCache;
private static ApplicationLifecycleMonitor mApplicationLifecycleMonitor;

Expand Down Expand Up @@ -512,6 +514,14 @@ public static RestClientUtils getRestClientUtilsV1_3() {
return sRestClientUtilsVersion1p3;
}

public static RestClientUtils getRestClientUtilsV2() {
if (sRestClientUtilsVersion2p1 == null) {
sRestClientUtilsVersion2p1 = new RestClientUtils(mContext, sRequestQueue, sOAuthAuthenticator,
null, RestClient.REST_CLIENT_VERSIONS.V2);
}
return sRestClientUtilsVersion2p1;
}

public static RestClientUtils getRestClientUtilsV0() {
if (sRestClientUtilsVersion0 == null) {
sRestClientUtilsVersion0 = new RestClientUtils(mContext, sRequestQueue, sOAuthAuthenticator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class ReaderBlogTableWrapper
fun getFollowedBlogs(): List<ReaderBlog> = ReaderBlogTable.getFollowedBlogs()!!
fun getBlogInfo(blogId: Long): ReaderBlog? = ReaderBlogTable.getBlogInfo(blogId)
fun getFeedInfo(feedId: Long): ReaderBlog? = ReaderBlogTable.getFeedInfo(feedId)
fun isNotificationsEnabled(blogId: Long): Boolean = ReaderBlogTable.isNotificationsEnabled(blogId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.wordpress.android.datasets.wrappers

import dagger.Reusable
import org.wordpress.android.datasets.ReaderPostTable
import org.wordpress.android.models.ReaderPost
import javax.inject.Inject

@Reusable
class ReaderPostTableWrapper @Inject constructor() {
fun getBlogPost(blogId: Long, postId: Long, excludeTextColumn: Boolean): ReaderPost? =
ReaderPostTable.getBlogPost(blogId, postId, excludeTextColumn)

fun isPostFollowed(post: ReaderPost): Boolean = ReaderPostTable.isPostFollowed(post)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.wordpress.android.ui.reader.utils.ReaderImageScanner;
import org.wordpress.android.ui.reader.utils.ReaderUtils;
import org.wordpress.android.util.DateTimeUtils;
import org.wordpress.android.util.DateTimeUtilsWrapper;
import org.wordpress.android.util.GravatarUtils;
import org.wordpress.android.util.HtmlUtils;
import org.wordpress.android.util.JSONUtils;
Expand Down Expand Up @@ -773,6 +774,13 @@ public java.util.Date getDisplayDate() {
return mDateDisplay;
}

public java.util.Date getDisplayDate(DateTimeUtilsWrapper dateTimeUtilsWrapper) {
if (mDateDisplay == null) {
mDateDisplay = dateTimeUtilsWrapper.dateFromIso8601(this.mDatePublished);
}
return mDateDisplay;
}

/*
* used when a unique numeric id is required by an adapter (when hasStableIds() = true)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ public enum ReaderTagType {
BOOKMARKED,
RECOMMENDED,
CUSTOM_LIST,
SEARCH;
SEARCH,
INTERESTS;

private static final int INT_DEFAULT = 0;
private static final int INT_FOLLOWED = 1;
private static final int INT_RECOMMENDED = 2;
private static final int INT_CUSTOM_LIST = 3;
private static final int INT_SEARCH = 4;
private static final int INT_BOOKMARKED = 5;
private static final int INT_INTERESTS = 6;


public static ReaderTagType fromInt(int value) {
Expand All @@ -28,6 +30,8 @@ public static ReaderTagType fromInt(int value) {
return SEARCH;
case INT_BOOKMARKED:
return BOOKMARKED;
case INT_INTERESTS:
return INTERESTS;
default:
return DEFAULT;
}
Expand All @@ -45,6 +49,8 @@ public int toInt() {
return INT_SEARCH;
case BOOKMARKED:
return INT_BOOKMARKED;
case INTERESTS:
return INT_INTERESTS;
case DEFAULT:
default:
return INT_DEFAULT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import org.wordpress.android.R;
import org.wordpress.android.fluxc.model.AccountModel;
import org.wordpress.android.fluxc.model.SiteModel;
import org.wordpress.android.login.util.AvatarHelper.FakeGravatarUtils;
import org.wordpress.android.util.GravatarUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.image.ImageManager;

import static org.wordpress.android.login.util.AvatarHelper.FakeGravatarUtils.DefaultImage.STATUS_404;
import static org.wordpress.android.util.GravatarUtils.DefaultImage.STATUS_404;
import static org.wordpress.android.util.image.ImageType.AVATAR_WITHOUT_BACKGROUND;

/**
Expand Down Expand Up @@ -75,10 +75,10 @@ private int getAvatarSize(Context context) {
}

private String constructGravatarUrl(Context context, AccountModel account) {
return FakeGravatarUtils.fixGravatarUrl(account.getAvatarUrl(), getAvatarSize(context), STATUS_404);
return GravatarUtils.fixGravatarUrl(account.getAvatarUrl(), getAvatarSize(context), STATUS_404);
}

private String constructGravatarUrl(Context context, SiteModel site) {
return FakeGravatarUtils.gravatarFromEmail(site.getEmail(), getAvatarSize(context), STATUS_404);
return GravatarUtils.gravatarFromEmail(site.getEmail(), getAvatarSize(context), STATUS_404);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class MySiteFragment : Fragment(),
.setNegativeButton(
getString(R.string.quick_start_button_negative)
) {
AppPrefs.setLastSkippedQuickStartTask(taskToPrompt)
AnalyticsTracker.track(
QUICK_START_TASK_DIALOG_NEGATIVE_TAPPED
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ public void onClick(View v) {
}
QuickStartUtils.cancelQuickStartReminder(this);
AppPrefs.setQuickStartNoticeRequired(false);
AppPrefs.setLastSkippedQuickStartTask(null);

// Enable the block editor on sites created on mobile
if (data != null) {
Expand Down Expand Up @@ -955,6 +956,7 @@ public void onClick(View v) {
if (!isSameSiteSelected) {
QuickStartUtils.cancelQuickStartReminder(this);
AppPrefs.setQuickStartNoticeRequired(false);
AppPrefs.setLastSkippedQuickStartTask(null);
mPrivateAtomicCookie.clearCookie();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.wordpress.android.BuildConfig;
import org.wordpress.android.WordPress;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.analytics.AnalyticsTracker.Stat;
import org.wordpress.android.fluxc.model.PostModel;
import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTask;
import org.wordpress.android.models.PeopleListFilter;
import org.wordpress.android.models.ReaderTag;
import org.wordpress.android.models.ReaderTagType;
Expand Down Expand Up @@ -128,6 +130,7 @@ public enum DeletablePrefKey implements PrefKey {
GUTENBERG_STARTER_PAGE_TEMPLATES_TOOLTIP_SHOWN,

IS_QUICK_START_NOTICE_REQUIRED,
LAST_SKIPPED_QUICK_START_TASK,

POST_LIST_AUTHOR_FILTER,
POST_LIST_VIEW_LAYOUT_TYPE,
Expand Down Expand Up @@ -1147,6 +1150,22 @@ public static void setReaderCssUpdatedTimestamp(long timestamp) {
setLong(DeletablePrefKey.READER_CSS_UPDATED_TIMESTAMP, timestamp);
}

public static QuickStartTask getLastSkippedQuickStartTask() {
String taskName = getString(DeletablePrefKey.LAST_SKIPPED_QUICK_START_TASK);
if (TextUtils.isEmpty(taskName)) {
return null;
}
return QuickStartTask.Companion.fromString(taskName);
}

public static void setLastSkippedQuickStartTask(@Nullable QuickStartTask task) {
if (task == null) {
remove(DeletablePrefKey.LAST_SKIPPED_QUICK_START_TASK);
return;
}
setString(DeletablePrefKey.LAST_SKIPPED_QUICK_START_TASK, task.toString());
}

/*
* adds a local site ID to the top of list of recently chosen sites
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.wordpress.android.models.ReaderPost;
import org.wordpress.android.models.ReaderTag;
import org.wordpress.android.models.ReaderTagList;
import org.wordpress.android.ui.reader.actions.ReaderActions;
import org.wordpress.android.ui.reader.models.ReaderSimplePostList;
import org.wordpress.android.ui.reader.services.post.ReaderPostServiceStarter;
Expand Down Expand Up @@ -42,6 +43,18 @@ public static class FollowedBlogsChanged {
public static class RecommendedBlogsChanged {
}

public static class InterestTagsFetched {
private final ReaderTagList mInterestTags;

public InterestTagsFetched(ReaderTagList interestTags) {
mInterestTags = interestTags;
}

public ReaderTagList getInterestTags() {
return mInterestTags;
}
}

public static class SinglePostDownloaded {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,11 @@ && isAdded() && getActivity() instanceof WPMainActivity) {
getResources().getInteger(R.integer.quick_start_snackbar_duration_ms));

((WPMainActivity) getActivity()).showQuickStartSnackBar(snackbar);

if (getSelectedSite() != null) {
QuickStartUtils.completeTaskAndRemindNextOne(mQuickStartStore, QuickStartTask.FOLLOW_SITE,
mDispatcher, getSelectedSite(), mQuickStartEvent, getContext());
}
}
}

Expand Down Expand Up @@ -1173,11 +1178,6 @@ public boolean onMenuItemActionExpand(MenuItem item) {
mBottomNavController.onRequestHideBottomNavigation();
}

if (getSelectedSite() != null) {
QuickStartUtils.completeTaskAndRemindNextOne(mQuickStartStore, QuickStartTask.FOLLOW_SITE,
mDispatcher, getSelectedSite(), mQuickStartEvent, getContext());
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
import org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResultListener;
import org.wordpress.android.ui.reader.models.ReaderSimplePost;
import org.wordpress.android.ui.reader.models.ReaderSimplePostList;
import org.wordpress.android.ui.reader.repository.ReaderRepositoryEvent;
import org.wordpress.android.ui.reader.repository.ReaderRepositoryEvent.PostLikeEnded.PostLikeFailure;
import org.wordpress.android.ui.reader.repository.ReaderRepositoryEvent.PostLikeEnded.PostLikeSuccess;
import org.wordpress.android.ui.reader.repository.ReaderRepositoryEvent.PostLikeEnded.PostLikeUnChanged;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.DateTimeUtils;
Expand Down Expand Up @@ -67,6 +71,10 @@ public static boolean performLikeAction(final ReaderPost post,
boolean isCurrentlyLiked = ReaderPostTable.isPostLikedByCurrentUser(post);
if (isCurrentlyLiked == isAskingToLike) {
AppLog.w(T.READER, "post like unchanged");
final PostLikeUnChanged onPostLikeUnChanged =
new ReaderRepositoryEvent.PostLikeEnded.PostLikeUnChanged(
post.postId, post.blogId, isAskingToLike, wpComUserId);
EventBus.getDefault().post(onPostLikeUnChanged);
return false;
}

Expand All @@ -91,6 +99,10 @@ public static boolean performLikeAction(final ReaderPost post,
@Override
public void onResponse(JSONObject jsonObject) {
AppLog.d(T.READER, String.format("post %s succeeded", actionName));
final PostLikeSuccess onPostLikeSuccess =
new ReaderRepositoryEvent.PostLikeEnded.PostLikeSuccess(
post.postId, post.blogId, isAskingToLike, wpComUserId);
EventBus.getDefault().post(onPostLikeSuccess);
}
};

Expand All @@ -106,13 +118,18 @@ public void onErrorResponse(VolleyError volleyError) {
AppLog.e(T.READER, volleyError);
ReaderPostTable.setLikesForPost(post, post.numLikes, post.isLikedByCurrentUser);
ReaderLikeTable.setCurrentUserLikesPost(post, post.isLikedByCurrentUser, wpComUserId);
final PostLikeFailure onPostLikeFailure =
new ReaderRepositoryEvent.PostLikeEnded.PostLikeFailure(
post.postId, post.blogId, isAskingToLike, wpComUserId);
EventBus.getDefault().post(onPostLikeFailure);
}
};

WordPress.getRestClientUtilsV1_1().post(path, listener, errorListener);
return true;
}


/*
* get the latest version of this post - note that the post is only considered changed if the
* like/comment count has changed, or if the current user's like/follow status has changed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.wordpress.android.ui.reader.actions

import dagger.Reusable
import org.wordpress.android.models.ReaderPost
import javax.inject.Inject

@Reusable
class ReaderPostActionsWrapper @Inject constructor() {
fun addToBookmarked(post: ReaderPost) = ReaderPostActions.addToBookmarked(post)
fun removeFromBookmarked(post: ReaderPost) = ReaderPostActions.removeFromBookmarked(post)
}
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private void toggleFollowButton(
}

if (success) {
renderTagHeader(currentTag, tagHolder, false, true);
renderTagHeader(currentTag, tagHolder, false, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package org.wordpress.android.ui.reader.discover

import dagger.Reusable
import org.wordpress.android.R
import org.wordpress.android.datasets.ReaderBlogTable
import org.wordpress.android.datasets.ReaderPostTable
import org.wordpress.android.datasets.ReaderBlogTableWrapper
import org.wordpress.android.datasets.wrappers.ReaderPostTableWrapper
import org.wordpress.android.models.ReaderPost
import org.wordpress.android.ui.reader.ReaderTypes.ReaderPostListType
import org.wordpress.android.ui.reader.ReaderTypes.ReaderPostListType.TAG_FOLLOWED
Expand All @@ -17,14 +17,17 @@ import org.wordpress.android.ui.utils.UiString.UiStringRes
import javax.inject.Inject

@Reusable
class ReaderPostMoreButtonUiStateBuilder @Inject constructor() {
class ReaderPostMoreButtonUiStateBuilder @Inject constructor(
private val readerPostTableWrapper: ReaderPostTableWrapper,
private val readerBlogTableWrapper: ReaderBlogTableWrapper
) {
fun buildMoreMenuItems(
post: ReaderPost,
postListType: ReaderPostListType,
onButtonClicked: (Long, Long, ReaderPostCardActionType) -> Unit
): List<SecondaryAction> {
val menuItems = mutableListOf<SecondaryAction>()
if (ReaderPostTable.isPostFollowed(post)) {
if (readerPostTableWrapper.isPostFollowed(post)) {
menuItems.add(
SecondaryAction(
type = FOLLOW,
Expand All @@ -38,7 +41,7 @@ class ReaderPostMoreButtonUiStateBuilder @Inject constructor() {

// When blogId and feedId are not equal, post is not a feed so show notifications option.
if (post.blogId != post.feedId) {
if (ReaderBlogTable.isNotificationsEnabled(post.blogId)) {
if (readerBlogTableWrapper.isNotificationsEnabled(post.blogId)) {
menuItems.add(
SecondaryAction(
type = SITE_NOTIFICATIONS,
Expand Down
Loading

0 comments on commit f2a0ccd

Please sign in to comment.