aboutsummaryrefslogtreecommitdiff
path: root/WordPress
diff options
context:
space:
mode:
authorOguz Kocer <oguz.kocer@automattic.com>2016-06-20 16:21:59 +0300
committerOguz Kocer <oguz.kocer@automattic.com>2016-06-20 16:21:59 +0300
commit7d1dd9dd6739978469b284467afa0b3c9c89cd72 (patch)
tree4085850a9274a4ce3e7e06e21f118a0840459885 /WordPress
parent1cea973a2fc5066be78c67929d9a970c9e16df66 (diff)
downloadgradle-perf-android-medium-7d1dd9dd6739978469b284467afa0b3c9c89cd72.tar.gz
Integrates email followers to people list
Diffstat (limited to 'WordPress')
-rw-r--r--WordPress/src/main/java/org/wordpress/android/datasets/PeopleTable.java26
-rw-r--r--WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java72
2 files changed, 94 insertions, 4 deletions
diff --git a/WordPress/src/main/java/org/wordpress/android/datasets/PeopleTable.java b/WordPress/src/main/java/org/wordpress/android/datasets/PeopleTable.java
index d1735c16e..542848c94 100644
--- a/WordPress/src/main/java/org/wordpress/android/datasets/PeopleTable.java
+++ b/WordPress/src/main/java/org/wordpress/android/datasets/PeopleTable.java
@@ -104,6 +104,23 @@ public class PeopleTable {
}
}
+ public static void saveEmailFollowers(List<Person> peopleList, int localTableBlogId, boolean isFreshList) {
+ getWritableDb().beginTransaction();
+ try {
+ // We have a fresh list, remove the previous list of email followers in case it was deleted on remote
+ if (isFreshList) {
+ PeopleTable.deleteEmailFollowersForLocalBlogId(localTableBlogId);
+ }
+
+ for (Person person : peopleList) {
+ PeopleTable.save(person);
+ }
+ getWritableDb().setTransactionSuccessful();
+ } finally {
+ getWritableDb().endTransaction();
+ }
+ }
+
public static void deletePeopleForLocalBlogId(int localTableBlogId) {
String[] args = new String[]{Integer.toString(localTableBlogId)};
getWritableDb().delete(PEOPLE_TABLE, "local_blog_id=?", args);
@@ -111,12 +128,17 @@ public class PeopleTable {
public static void deleteUsersForLocalBlogId(int localTableBlogId) {
String[] args = new String[]{Integer.toString(localTableBlogId), Integer.toString(0)};
- getWritableDb().delete(PEOPLE_TABLE, "local_blog_id=?&is_follower=?", args);
+ getWritableDb().delete(PEOPLE_TABLE, "local_blog_id=? AND is_follower=?", args);
}
public static void deleteFollowersForLocalBlogId(int localTableBlogId) {
String[] args = new String[]{Integer.toString(localTableBlogId), Integer.toString(1)};
- getWritableDb().delete(PEOPLE_TABLE, "local_blog_id=?&is_follower=?", args);
+ getWritableDb().delete(PEOPLE_TABLE, "local_blog_id=? AND is_follower=?", args);
+ }
+
+ public static void deleteEmailFollowersForLocalBlogId(int localTableBlogId) {
+ String[] args = new String[]{Integer.toString(localTableBlogId), Integer.toString(1)};
+ getWritableDb().delete(PEOPLE_TABLE, "local_blog_id=? AND is_email_follower=?", args);
}
public static void deleteUsersForLocalBlogIdExceptForFirstPage(int localTableBlogId) {
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java
index 6aa5cd72e..dea15a7e0 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java
@@ -40,6 +40,10 @@ public class PeopleManagementActivity extends AppCompatActivity
private static final String KEY_FOLLOWERS_FETCH_REQUEST_IN_PROGRESS = "followers-fetch-request-in-progress";
private static final String KEY_CAN_REFRESH_FOLLOWERS = "can-refresh-followers";
private static final String KEY_FOLLOWERS_LAST_FETCHED_PAGE = "followers-last-fetched-page-received";
+ private static final String KEY_EMAIL_FOLLOWERS_END_OF_LIST_REACHED = "email-followers-end-of-list-reached";
+ private static final String KEY_EMAIL_FOLLOWERS_FETCH_REQUEST_IN_PROGRESS = "email-followers-fetch-request-in-progress";
+ private static final String KEY_CAN_REFRESH_EMAIL_FOLLOWERS = "can-refresh-email-followers";
+ private static final String KEY_EMAIL_FOLLOWERS_LAST_FETCHED_PAGE = "email-followers-last-fetched-page-received";
private static final String KEY_TITLE = "page-title";
private static final String KEY_PEOPLE_INVITE_FRAGMENT = "people-invite-fragment";
@@ -50,6 +54,10 @@ public class PeopleManagementActivity extends AppCompatActivity
private boolean mFollowersFetchRequestInProgress;
private boolean mCanRefreshFollowers;
private int mFollowersLastFetchedPage;
+ private boolean mEmailFollowersEndOfListReached;
+ private boolean mEmailFollowersFetchRequestInProgress;
+ private boolean mCanRefreshEmailFollowers;
+ private int mEmailFollowersLastFetchedPage;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -95,6 +103,10 @@ public class PeopleManagementActivity extends AppCompatActivity
mFollowersFetchRequestInProgress = false;
mCanRefreshFollowers = true;
mFollowersLastFetchedPage = 0;
+ mEmailFollowersEndOfListReached = false;
+ mEmailFollowersFetchRequestInProgress = false;
+ mCanRefreshEmailFollowers = true;
+ mEmailFollowersLastFetchedPage = 0;
fragmentManager.beginTransaction()
.add(R.id.fragment_container, peopleListFragment, KEY_PEOPLE_LIST_FRAGMENT)
@@ -107,6 +119,10 @@ public class PeopleManagementActivity extends AppCompatActivity
mFollowersFetchRequestInProgress = savedInstanceState.getBoolean(KEY_FOLLOWERS_FETCH_REQUEST_IN_PROGRESS);
mCanRefreshFollowers = savedInstanceState.getBoolean(KEY_CAN_REFRESH_FOLLOWERS);
mFollowersLastFetchedPage = savedInstanceState.getInt(KEY_FOLLOWERS_LAST_FETCHED_PAGE);
+ mEmailFollowersEndOfListReached = savedInstanceState.getBoolean(KEY_EMAIL_FOLLOWERS_END_OF_LIST_REACHED);
+ mEmailFollowersFetchRequestInProgress = savedInstanceState.getBoolean(KEY_EMAIL_FOLLOWERS_FETCH_REQUEST_IN_PROGRESS);
+ mCanRefreshEmailFollowers = savedInstanceState.getBoolean(KEY_CAN_REFRESH_EMAIL_FOLLOWERS);
+ mEmailFollowersLastFetchedPage = savedInstanceState.getInt(KEY_EMAIL_FOLLOWERS_LAST_FETCHED_PAGE);
CharSequence title = savedInstanceState.getCharSequence(KEY_TITLE);
if (actionBar != null && title != null) {
@@ -136,6 +152,10 @@ public class PeopleManagementActivity extends AppCompatActivity
outState.putBoolean(KEY_FOLLOWERS_FETCH_REQUEST_IN_PROGRESS, mFollowersFetchRequestInProgress);
outState.putBoolean(KEY_CAN_REFRESH_FOLLOWERS, mCanRefreshFollowers);
outState.putInt(KEY_FOLLOWERS_LAST_FETCHED_PAGE, mFollowersLastFetchedPage);
+ outState.putBoolean(KEY_EMAIL_FOLLOWERS_END_OF_LIST_REACHED, mEmailFollowersEndOfListReached);
+ outState.putBoolean(KEY_EMAIL_FOLLOWERS_FETCH_REQUEST_IN_PROGRESS, mEmailFollowersFetchRequestInProgress);
+ outState.putBoolean(KEY_CAN_REFRESH_EMAIL_FOLLOWERS, mCanRefreshEmailFollowers);
+ outState.putInt(KEY_EMAIL_FOLLOWERS_LAST_FETCHED_PAGE, mEmailFollowersLastFetchedPage);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
outState.putCharSequence(KEY_TITLE, actionBar.getTitle());
@@ -233,7 +253,7 @@ public class PeopleManagementActivity extends AppCompatActivity
mUsersFetchRequestInProgress = false;
ToastUtils.showToast(PeopleManagementActivity.this,
R.string.error_fetch_users_list,
- ToastUtils.Duration.LONG);
+ ToastUtils.Duration.SHORT);
}
});
@@ -275,7 +295,49 @@ public class PeopleManagementActivity extends AppCompatActivity
mFollowersFetchRequestInProgress = false;
ToastUtils.showToast(PeopleManagementActivity.this,
R.string.error_fetch_followers_list,
- ToastUtils.Duration.LONG);
+ ToastUtils.Duration.SHORT);
+ }
+ });
+
+ return true;
+ }
+
+ private boolean fetchEmailFollowersList(String dotComBlogId, final int localTableBlogId, final int page) {
+ if (mEmailFollowersEndOfListReached || mEmailFollowersFetchRequestInProgress || !NetworkUtils.checkConnection(this)) {
+ return false;
+ }
+
+ mEmailFollowersFetchRequestInProgress = true;
+
+ PeopleUtils.fetchEmailFollowers(dotComBlogId, localTableBlogId, page, new PeopleUtils.FetchFollowersCallback() {
+ @Override
+ public void onSuccess(List<Person> peopleList, int pageFetched, boolean isEndOfList) {
+ boolean isFreshList = (page == 1);
+ mEmailFollowersLastFetchedPage = pageFetched;
+ mEmailFollowersEndOfListReached = isEndOfList;
+ PeopleTable.saveEmailFollowers(peopleList, localTableBlogId, isFreshList);
+
+ PeopleListFragment peopleListFragment = getListFragment();
+ if (peopleListFragment != null) {
+ boolean isFirstPage = page == 1;
+ peopleListFragment.fetchingRequestFinished(PeopleListFilter.EMAIL_FOLLOWERS, isFirstPage, true);
+ }
+
+ refreshOnScreenFragmentDetails();
+ mEmailFollowersFetchRequestInProgress = false;
+ }
+
+ @Override
+ public void onError() {
+ PeopleListFragment peopleListFragment = getListFragment();
+ if (peopleListFragment != null) {
+ boolean isFirstPage = page == 1;
+ peopleListFragment.fetchingRequestFinished(PeopleListFilter.EMAIL_FOLLOWERS, isFirstPage, false);
+ }
+ mEmailFollowersFetchRequestInProgress = false;
+ ToastUtils.showToast(PeopleManagementActivity.this,
+ R.string.error_fetch_email_followers_list,
+ ToastUtils.Duration.SHORT);
}
});
@@ -466,6 +528,8 @@ public class PeopleManagementActivity extends AppCompatActivity
return fetchUsersList(blog.getDotComBlogId(), blog.getLocalTableBlogId(), 0);
} else if (filter == PeopleListFilter.FOLLOWERS && mCanRefreshFollowers){
return fetchFollowersList(blog.getDotComBlogId(), blog.getLocalTableBlogId(), 1);
+ } else if (filter == PeopleListFilter.EMAIL_FOLLOWERS && mCanRefreshEmailFollowers){
+ return fetchEmailFollowersList(blog.getDotComBlogId(), blog.getLocalTableBlogId(), 1);
}
return false;
}
@@ -480,6 +544,10 @@ public class PeopleManagementActivity extends AppCompatActivity
Blog blog = WordPress.getCurrentBlog();
int pageToFetch = mFollowersLastFetchedPage + 1;
return fetchFollowersList(blog.getDotComBlogId(), blog.getLocalTableBlogId(), pageToFetch);
+ } else if (filter == PeopleListFilter.EMAIL_FOLLOWERS && !mEmailFollowersEndOfListReached) {
+ Blog blog = WordPress.getCurrentBlog();
+ int pageToFetch = mEmailFollowersLastFetchedPage + 1;
+ return fetchEmailFollowersList(blog.getDotComBlogId(), blog.getLocalTableBlogId(), pageToFetch);
}
return false;
}