aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-08 05:44:27 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-08 05:44:27 +0000
commit5b5da3d3fd44d79bc301546b7be94de0a206e020 (patch)
tree3bf6fc281788039ff3f49525d3d7d90f389493de /app/src
parenteb1d243f2c7e9d73a3863bcd21119095d0241acc (diff)
downloadinfinity-for-reddit-5b5da3d3fd44d79bc301546b7be94de0a206e020.tar
infinity-for-reddit-5b5da3d3fd44d79bc301546b7be94de0a206e020.tar.gz
infinity-for-reddit-5b5da3d3fd44d79bc301546b7be94de0a206e020.tar.bz2
infinity-for-reddit-5b5da3d3fd44d79bc301546b7be94de0a206e020.tar.lz
infinity-for-reddit-5b5da3d3fd44d79bc301546b7be94de0a206e020.tar.xz
infinity-for-reddit-5b5da3d3fd44d79bc301546b7be94de0a206e020.tar.zst
infinity-for-reddit-5b5da3d3fd44d79bc301546b7be94de0a206e020.zip
Load subscriptions in SubredditSelectionActivity. Minor bugs fixed.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java74
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java1
3 files changed, 74 insertions, 13 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index e467035b..caf3ff63 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -48,6 +48,10 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
private static final String ACCESS_TOKEN_STATE = "ATS";
+ private static final String ACCOUNT_NAME_STATE = "ANS";
+ private static final String ACCOUNT_PROFILE_IMAGE_URL_STATE = "APIUS";
+ private static final String ACCOUNT_BANNER_IMAGE_URL_STATE = "ABIUS";
+ private static final String ACCOUNT_KARMA_STATE = "AKS";
private static final int LOGIN_ACTIVITY_REQUEST_CODE = 0;
@@ -129,6 +133,10 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
+ mName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
+ mProfileImageUrl = savedInstanceState.getString(ACCOUNT_PROFILE_IMAGE_URL_STATE);
+ mBannerImageUrl = savedInstanceState.getString(ACCOUNT_BANNER_IMAGE_URL_STATE);
+ mKarma = savedInstanceState.getString(ACCOUNT_KARMA_STATE);
if(!mNullAccessToken && mAccessToken == null) {
getCurrentAccountAndBindView();
} else {
@@ -353,6 +361,10 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
+ outState.putString(ACCOUNT_NAME_STATE, mName);
+ outState.putString(ACCOUNT_PROFILE_IMAGE_URL_STATE, mProfileImageUrl);
+ outState.putString(ACCOUNT_BANNER_IMAGE_URL_STATE, mBannerImageUrl);
+ outState.putString(ACCOUNT_KARMA_STATE, mKarma);
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java
index 3c054b1f..8069499c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java
@@ -12,10 +12,17 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
+import java.util.ArrayList;
+
import javax.inject.Inject;
+import javax.inject.Named;
+import SubredditDatabase.SubredditData;
+import SubscribedSubredditDatabase.SubscribedSubredditData;
+import SubscribedUserDatabase.SubscribedUserData;
import butterknife.BindView;
import butterknife.ButterKnife;
+import retrofit2.Retrofit;
public class SubredditSelectionActivity extends AppCompatActivity {
@@ -25,20 +32,28 @@ public class SubredditSelectionActivity extends AppCompatActivity {
static final String EXTRA_RETURN_SUBREDDIT_IS_USER = "ERSIU";
private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 0;
- private static final String NULL_ACCOUNT_NAME_STATE = "NATS";
- private static final String ACCOUNT_NAME_STATE = "ATS";
+ private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
+ private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
+ private static final String ACCESS_TOKEN_STATE = "ATS";
+ private static final String ACCOUNT_NAME_STATE = "ANS";
private static final String ACCOUNT_PROFILE_IMAGE_URL = "APIU";
private static final String FRAGMENT_OUT_STATE = "FOS";
@BindView(R.id.toolbar_subreddit_selection_activity) Toolbar toolbar;
- private boolean mNullAccountName = false;
+ private boolean mNullAccessToken = false;
+ private String mAccessToken;
private String mAccountName;
private String mAccountProfileImageUrl;
+ private boolean mInsertSuccess = false;
private Fragment mFragment;
@Inject
+ @Named("oauth")
+ Retrofit mOauthRetrofit;
+
+ @Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Override
@@ -54,14 +69,16 @@ public class SubredditSelectionActivity extends AppCompatActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if(savedInstanceState == null) {
- getCurrentAccountAndInitializeFragment();
+ getCurrentAccountAndBindView();
} else {
- mNullAccountName = savedInstanceState.getBoolean(NULL_ACCOUNT_NAME_STATE);
+ mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
+ mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
+ mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
mAccountProfileImageUrl = savedInstanceState.getString(ACCOUNT_PROFILE_IMAGE_URL);
- if(!mNullAccountName && mAccountName == null) {
- getCurrentAccountAndInitializeFragment();
+ if(!mNullAccessToken && mAccountName == null) {
+ getCurrentAccountAndBindView();
} else {
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_subreddit_selection_activity, mFragment).commit();
@@ -69,19 +86,22 @@ public class SubredditSelectionActivity extends AppCompatActivity {
}
}
- private void getCurrentAccountAndInitializeFragment() {
+ private void getCurrentAccountAndBindView() {
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
if(account == null) {
- mNullAccountName = true;
+ mNullAccessToken = true;
} else {
+ mAccessToken = account.getAccessToken();
mAccountName = account.getUsername();
mAccountProfileImageUrl = account.getProfileImageUrl();
}
- initializeFragment();
+ bindView();
}).execute();
}
- private void initializeFragment() {
+ private void bindView() {
+ loadSubscriptions();
+
mFragment = new SubscribedSubredditsListingFragment();
Bundle bundle = new Bundle();
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
@@ -95,6 +115,34 @@ public class SubredditSelectionActivity extends AppCompatActivity {
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_subreddit_selection_activity, mFragment).commit();
}
+ private void loadSubscriptions() {
+ if (!mInsertSuccess) {
+ FetchSubscribedThing.fetchSubscribedThing(mOauthRetrofit, mAccessToken, mAccountName, null,
+ new ArrayList<>(), new ArrayList<>(),
+ new ArrayList<>(),
+ new FetchSubscribedThing.FetchSubscribedThingListener() {
+ @Override
+ public void onFetchSubscribedThingSuccess(ArrayList<SubscribedSubredditData> subscribedSubredditData,
+ ArrayList<SubscribedUserData> subscribedUserData,
+ ArrayList<SubredditData> subredditData) {
+ new InsertSubscribedThingsAsyncTask(
+ mRedditDataRoomDatabase.subscribedSubredditDao(),
+ mRedditDataRoomDatabase.subscribedUserDao(),
+ mRedditDataRoomDatabase.subredditDao(),
+ subscribedSubredditData,
+ subscribedUserData,
+ subredditData,
+ () -> mInsertSuccess = true).execute();
+ }
+
+ @Override
+ public void onFetchSubscribedThingFail() {
+ mInsertSuccess = false;
+ }
+ });
+ }
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.subreddit_selection_activity, menu);
@@ -149,7 +197,9 @@ public class SubredditSelectionActivity extends AppCompatActivity {
if (mFragment != null) {
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
}
- outState.putBoolean(NULL_ACCOUNT_NAME_STATE, mNullAccountName);
+ outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess);
+ outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
+ outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
outState.putString(ACCOUNT_PROFILE_IMAGE_URL, mAccountProfileImageUrl);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java
index 0696b8d1..1f35288d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java
@@ -29,7 +29,6 @@ import retrofit2.Retrofit;
public class SubscribedThingListingActivity extends AppCompatActivity {
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
-
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
private static final String ACCESS_TOKEN_STATE = "ATS";
private static final String ACCOUNT_NAME_STATE = "ANS";