diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-09-14 10:58:48 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-09-14 10:58:48 +0000 |
commit | 6d66f9504e921dc6803f6bac1dec494de9635227 (patch) | |
tree | 6a5cae0b5a7a2a5cc84a9d81e756ceaf2d1b4287 /app/src/main/java/ml | |
parent | 2f15383718c72246581b1f70cb61ffb9bd12e6db (diff) | |
download | infinity-for-reddit-6d66f9504e921dc6803f6bac1dec494de9635227.tar infinity-for-reddit-6d66f9504e921dc6803f6bac1dec494de9635227.tar.gz infinity-for-reddit-6d66f9504e921dc6803f6bac1dec494de9635227.tar.bz2 infinity-for-reddit-6d66f9504e921dc6803f6bac1dec494de9635227.tar.lz infinity-for-reddit-6d66f9504e921dc6803f6bac1dec494de9635227.tar.xz infinity-for-reddit-6d66f9504e921dc6803f6bac1dec494de9635227.tar.zst infinity-for-reddit-6d66f9504e921dc6803f6bac1dec494de9635227.zip |
Refreshing subreddit and user details when click the refresh menu item in ViewSubredditDetailActivity and ViewUserDetailActivity.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java | 17 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java | 2 |
2 files changed, 15 insertions, 4 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java index fb322422..cf950b2b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java @@ -61,6 +61,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; private static final String FETCH_SUBREDDIT_INFO_STATE = "FSIS"; + private static final String CURRENT_ONLINE_SUBSCRIBERS_STATE = "COSS"; private static final String FRAGMENT_OUT_STATE_KEY = "FOSK"; private static final String IS_IN_LAZY_MODE_STATE = "IILMS"; private static final String NULL_ACCESS_TOKEN_STATE = "NATS"; @@ -87,6 +88,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So private String mAccountName; private String subredditName; private boolean mFetchSubredditInfoSuccess = false; + private int mNCurrentOnlineSubscribers = 0; private boolean subscriptionReady = false; private boolean isInLazyMode = false; private boolean showToast = false; @@ -193,6 +195,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So getCurrentAccountAndBindView(); } else { mFetchSubredditInfoSuccess = savedInstanceState.getBoolean(FETCH_SUBREDDIT_INFO_STATE); + mNCurrentOnlineSubscribers = savedInstanceState.getInt(CURRENT_ONLINE_SUBSCRIBERS_STATE); mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE); @@ -207,6 +210,10 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit(); } + + if(mFetchSubredditInfoSuccess) { + nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, mNCurrentOnlineSubscribers)); + } } fetchSubredditData(); @@ -340,10 +347,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So FetchSubredditData.fetchSubredditData(mRetrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() { @Override public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { - new InsertSubredditDataAsyncTask(mRedditDataRoomDatabase, subredditData, () -> { - nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers)); - mFetchSubredditInfoSuccess = true; - }).execute(); + mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers; + nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers)); + new InsertSubredditDataAsyncTask(mRedditDataRoomDatabase, subredditData, () -> mFetchSubredditInfoSuccess = true).execute(); } @Override @@ -483,6 +489,8 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So } if(mFragment instanceof FragmentCommunicator) { ((FragmentCommunicator) mFragment).refresh(); + mFetchSubredditInfoSuccess = false; + fetchSubredditData(); } break; case R.id.action_lazy_mode_view_subreddit_detail_activity: @@ -513,6 +521,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(FETCH_SUBREDDIT_INFO_STATE, mFetchSubredditInfoSuccess); + outState.putInt(CURRENT_ONLINE_SUBSCRIBERS_STATE, mNCurrentOnlineSubscribers); outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode); outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken); outState.putString(ACCESS_TOKEN_STATE, mAccessToken); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java index e929a101..9dbe7d9a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java @@ -537,6 +537,8 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi mMenu.findItem(R.id.action_lazy_mode_view_user_detail_activity).setTitle(R.string.action_start_lazy_mode); } sectionsPagerAdapter.refresh(); + mFetchUserInfoSuccess = false; + fetchUserInfo(); return true; case R.id.action_lazy_mode_view_user_detail_activity: MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_user_detail_activity); |