mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-02 14:27:10 +01:00
Save current account info to SharedPreferences. Remove GetCurrentAccountAsyncTask.
This commit is contained in:
parent
53d2cd14c3
commit
178b524e4b
@ -1,6 +1,7 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
@ -100,6 +101,7 @@ public class FetchGfycatOrRedgifsVideoLinks {
|
|||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = new JSONObject(response);
|
JSONObject jsonObject = new JSONObject(response);
|
||||||
|
Log.i("adasdfasdf", "s " + jsonObject);
|
||||||
webm = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getString(JSONUtils.WEBM_URL_KEY);
|
webm = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getString(JSONUtils.WEBM_URL_KEY);
|
||||||
mp4 = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getString(JSONUtils.MP4_URL_KEY);
|
mp4 = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getString(JSONUtils.MP4_URL_KEY);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.activities;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -37,7 +36,6 @@ import ml.docilealligator.infinityforreddit.R;
|
|||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SortType;
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent;
|
import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent;
|
||||||
@ -52,9 +50,6 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
|
|||||||
static final String EXTRA_USER_WHERE = "EUW";
|
static final String EXTRA_USER_WHERE = "EUW";
|
||||||
|
|
||||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
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 FRAGMENT_OUT_STATE = "FOS";
|
private static final String FRAGMENT_OUT_STATE = "FOS";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_account_posts_activity)
|
@BindView(R.id.coordinator_layout_account_posts_activity)
|
||||||
@ -74,11 +69,13 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
|
|||||||
@Named("post_layout")
|
@Named("post_layout")
|
||||||
SharedPreferences mPostLayoutSharedPreferences;
|
SharedPreferences mPostLayoutSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean isInLazyMode = false;
|
private boolean isInLazyMode = false;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private String mUserWhere;
|
private String mUserWhere;
|
||||||
@ -143,20 +140,16 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
|
|||||||
|
|
||||||
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
|
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
||||||
getCurrentAccountAndInitializeFragment();
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_account_posts_activity, mFragment).commit();
|
||||||
} else {
|
|
||||||
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_account_posts_activity, mFragment).commit();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
getCurrentAccountAndInitializeFragment();
|
initializeFragment();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,18 +178,6 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
|
|||||||
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndInitializeFragment() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
initializeFragment();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeFragment() {
|
private void initializeFragment() {
|
||||||
mFragment = new PostFragment();
|
mFragment = new PostFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
@ -271,9 +252,6 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
|
|||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
||||||
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.activities;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -44,7 +43,6 @@ import ml.docilealligator.infinityforreddit.Infinity;
|
|||||||
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
|
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent;
|
import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent;
|
||||||
@ -60,9 +58,6 @@ import retrofit2.Retrofit;
|
|||||||
public class AccountSavedThingActivity extends BaseActivity implements ActivityToolbarInterface,
|
public class AccountSavedThingActivity extends BaseActivity implements ActivityToolbarInterface,
|
||||||
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, MarkPostAsReadInterface {
|
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, MarkPostAsReadInterface {
|
||||||
|
|
||||||
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 IS_IN_LAZY_MODE_STATE = "IILMS";
|
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_account_saved_thing_activity)
|
@BindView(R.id.coordinator_layout_account_saved_thing_activity)
|
||||||
@ -89,6 +84,9 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
|||||||
@Named("post_layout")
|
@Named("post_layout")
|
||||||
SharedPreferences mPostLayoutSharedPreferences;
|
SharedPreferences mPostLayoutSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
@ -97,7 +95,6 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
|||||||
private SlidrInterface mSlidrInterface;
|
private SlidrInterface mSlidrInterface;
|
||||||
private Menu mMenu;
|
private Menu mMenu;
|
||||||
private AppBarLayout.LayoutParams params;
|
private AppBarLayout.LayoutParams params;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private boolean isInLazyMode = false;
|
private boolean isInLazyMode = false;
|
||||||
@ -150,19 +147,13 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
|||||||
|
|
||||||
fragmentManager = getSupportFragmentManager();
|
fragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccountAndInitializeViewPager();
|
|
||||||
} else {
|
|
||||||
initializeViewPager();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
getCurrentAccountAndInitializeViewPager();
|
|
||||||
}
|
}
|
||||||
|
initializeViewPager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -191,18 +182,6 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
|||||||
applyTabLayoutTheme(tabLayout);
|
applyTabLayoutTheme(tabLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndInitializeViewPager() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
initializeViewPager();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeViewPager() {
|
private void initializeViewPager() {
|
||||||
sectionsPagerAdapter = new SectionsPagerAdapter(this);
|
sectionsPagerAdapter = new SectionsPagerAdapter(this);
|
||||||
viewPager2.setAdapter(sectionsPagerAdapter);
|
viewPager2.setAdapter(sectionsPagerAdapter);
|
||||||
@ -295,9 +274,6 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
|||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
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, mAccountName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,7 +6,6 @@ import android.content.SharedPreferences;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.style.SuperscriptSpan;
|
import android.text.style.SuperscriptSpan;
|
||||||
import android.text.util.Linkify;
|
import android.text.util.Linkify;
|
||||||
@ -50,16 +49,15 @@ import io.noties.markwon.recycler.MarkwonAdapter;
|
|||||||
import io.noties.markwon.recycler.table.TableEntry;
|
import io.noties.markwon.recycler.table.TableEntry;
|
||||||
import io.noties.markwon.recycler.table.TableEntryPlugin;
|
import io.noties.markwon.recycler.table.TableEntryPlugin;
|
||||||
import io.noties.markwon.simple.ext.SimpleExtPlugin;
|
import io.noties.markwon.simple.ext.SimpleExtPlugin;
|
||||||
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.comment.Comment;
|
import ml.docilealligator.infinityforreddit.comment.Comment;
|
||||||
import ml.docilealligator.infinityforreddit.comment.SendComment;
|
import ml.docilealligator.infinityforreddit.comment.SendComment;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
|
||||||
import ml.docilealligator.infinityforreddit.utils.Utils;
|
import ml.docilealligator.infinityforreddit.utils.Utils;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
@ -76,9 +74,6 @@ public class CommentActivity extends BaseActivity {
|
|||||||
public static final String RETURN_EXTRA_COMMENT_DATA_KEY = "RECDK";
|
public static final String RETURN_EXTRA_COMMENT_DATA_KEY = "RECDK";
|
||||||
public static final int WRITE_COMMENT_REQUEST_CODE = 1;
|
public static final int WRITE_COMMENT_REQUEST_CODE = 1;
|
||||||
|
|
||||||
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
|
||||||
private static final String ACCESS_TOKEN_STATE = "ATS";
|
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_comment_activity)
|
@BindView(R.id.coordinator_layout_comment_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@BindView(R.id.appbar_layout_comment_activity)
|
@BindView(R.id.appbar_layout_comment_activity)
|
||||||
@ -99,15 +94,15 @@ public class CommentActivity extends BaseActivity {
|
|||||||
@Named("oauth")
|
@Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
@Inject
|
@Inject
|
||||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
|
||||||
@Inject
|
|
||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String parentFullname;
|
private String parentFullname;
|
||||||
private int parentDepth;
|
private int parentDepth;
|
||||||
@ -136,15 +131,7 @@ public class CommentActivity extends BaseActivity {
|
|||||||
addOnOffsetChangedListener(appBarLayout);
|
addOnOffsetChangedListener(appBarLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
getCurrentAccount();
|
|
||||||
} else {
|
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
String parentTextMarkdown = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY);
|
String parentTextMarkdown = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY);
|
||||||
@ -296,16 +283,6 @@ public class CommentActivity extends BaseActivity {
|
|||||||
markdownColor = secondaryTextColor;
|
markdownColor = secondaryTextColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccount() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
@ -397,13 +374,6 @@ public class CommentActivity extends BaseActivity {
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (isSubmitting) {
|
if (isSubmitting) {
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -34,7 +33,6 @@ import butterknife.ButterKnife;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.multireddit.CreateMultiReddit;
|
import ml.docilealligator.infinityforreddit.multireddit.CreateMultiReddit;
|
||||||
import ml.docilealligator.infinityforreddit.multireddit.MultiRedditJSONModel;
|
import ml.docilealligator.infinityforreddit.multireddit.MultiRedditJSONModel;
|
||||||
@ -44,9 +42,6 @@ import retrofit2.Retrofit;
|
|||||||
public class CreateMultiRedditActivity extends BaseActivity {
|
public class CreateMultiRedditActivity extends BaseActivity {
|
||||||
|
|
||||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 1;
|
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 1;
|
||||||
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 SELECTED_SUBREDDITS_STATE = "SSS";
|
private static final String SELECTED_SUBREDDITS_STATE = "SSS";
|
||||||
@BindView(R.id.coordinator_layout_create_multi_reddit_activity)
|
@BindView(R.id.coordinator_layout_create_multi_reddit_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@ -79,10 +74,12 @@ public class CreateMultiRedditActivity extends BaseActivity {
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private ArrayList<String> mSubreddits;
|
private ArrayList<String> mSubreddits;
|
||||||
@ -111,35 +108,21 @@ public class CreateMultiRedditActivity extends BaseActivity {
|
|||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
mSubreddits = savedInstanceState.getStringArrayList(SELECTED_SUBREDDITS_STATE);
|
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccountName == null) {
|
if (mAccessToken == null) {
|
||||||
getCurrentAccountAndBindView();
|
Toast.makeText(this, R.string.logged_out, Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
finish();
|
||||||
bindView();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
mSubreddits = savedInstanceState.getStringArrayList(SELECTED_SUBREDDITS_STATE);
|
||||||
} else {
|
} else {
|
||||||
mSubreddits = new ArrayList<>();
|
mSubreddits = new ArrayList<>();
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
}
|
}
|
||||||
}
|
bindView();
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
Toast.makeText(this, R.string.logged_out, Toast.LENGTH_SHORT).show();
|
|
||||||
finish();
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
@ -210,9 +193,6 @@ public class CreateMultiRedditActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
outState.putStringArrayList(SELECTED_SUBREDDITS_STATE, mSubreddits);
|
outState.putStringArrayList(SELECTED_SUBREDDITS_STATE, mSubreddits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -35,7 +34,6 @@ import butterknife.ButterKnife;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.multireddit.EditMultiReddit;
|
import ml.docilealligator.infinityforreddit.multireddit.EditMultiReddit;
|
||||||
import ml.docilealligator.infinityforreddit.multireddit.FetchMultiRedditInfo;
|
import ml.docilealligator.infinityforreddit.multireddit.FetchMultiRedditInfo;
|
||||||
@ -47,9 +45,6 @@ import retrofit2.Retrofit;
|
|||||||
public class EditMultiRedditActivity extends BaseActivity {
|
public class EditMultiRedditActivity extends BaseActivity {
|
||||||
public static final String EXTRA_MULTI_PATH = "EMP";
|
public static final String EXTRA_MULTI_PATH = "EMP";
|
||||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 1;
|
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 1;
|
||||||
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 MULTI_REDDIT_STATE = "MRS";
|
private static final String MULTI_REDDIT_STATE = "MRS";
|
||||||
private static final String MULTI_PATH_STATE = "MPS";
|
private static final String MULTI_PATH_STATE = "MPS";
|
||||||
@BindView(R.id.coordinator_layout_edit_multi_reddit_activity)
|
@BindView(R.id.coordinator_layout_edit_multi_reddit_activity)
|
||||||
@ -87,10 +82,12 @@ public class EditMultiRedditActivity extends BaseActivity {
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private MultiReddit multiReddit;
|
private MultiReddit multiReddit;
|
||||||
@ -120,36 +117,22 @@ public class EditMultiRedditActivity extends BaseActivity {
|
|||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
|
if (mAccessToken == null) {
|
||||||
|
Toast.makeText(this, R.string.logged_out, Toast.LENGTH_SHORT).show();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
multiReddit = savedInstanceState.getParcelable(MULTI_REDDIT_STATE);
|
multiReddit = savedInstanceState.getParcelable(MULTI_REDDIT_STATE);
|
||||||
multipath = savedInstanceState.getString(MULTI_PATH_STATE);
|
multipath = savedInstanceState.getString(MULTI_PATH_STATE);
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccountName == null) {
|
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
} else {
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
multipath = getIntent().getStringExtra(EXTRA_MULTI_PATH);
|
multipath = getIntent().getStringExtra(EXTRA_MULTI_PATH);
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
bindView();
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
Toast.makeText(this, R.string.logged_out, Toast.LENGTH_SHORT).show();
|
|
||||||
finish();
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
@ -242,9 +225,6 @@ public class EditMultiRedditActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
outState.putParcelable(MULTI_REDDIT_STATE, multiReddit);
|
outState.putParcelable(MULTI_REDDIT_STATE, multiReddit);
|
||||||
outState.putString(MULTI_PATH_STATE, multipath);
|
outState.putString(MULTI_PATH_STATE, multipath);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -36,12 +35,11 @@ import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
|||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
|
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
|
||||||
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
|
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SortType;
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FilteredThingFABMoreOptionsBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FilteredThingFABMoreOptionsBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.SearchPostSortTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.SearchPostSortTypeBottomSheetFragment;
|
||||||
@ -69,9 +67,6 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
|||||||
public static final String EXTRA_USER_WHERE = "EUW";
|
public static final String EXTRA_USER_WHERE = "EUW";
|
||||||
|
|
||||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
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 FRAGMENT_OUT_STATE = "FOS";
|
private static final String FRAGMENT_OUT_STATE = "FOS";
|
||||||
private static final int CUSTOMIZE_POST_FILTER_ACTIVITY_REQUEST_CODE = 1000;
|
private static final int CUSTOMIZE_POST_FILTER_ACTIVITY_REQUEST_CODE = 1000;
|
||||||
|
|
||||||
@ -94,11 +89,13 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
|||||||
@Named("post_layout")
|
@Named("post_layout")
|
||||||
SharedPreferences mPostLayoutSharedPreferences;
|
SharedPreferences mPostLayoutSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean isInLazyMode = false;
|
private boolean isInLazyMode = false;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private String name;
|
private String name;
|
||||||
@ -223,21 +220,16 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
mFragment = (PostFragment) getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
bindView(postFilter, false);
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccountAndBindView(postFilter);
|
|
||||||
} else {
|
|
||||||
mFragment = (PostFragment) getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();
|
|
||||||
bindView(postFilter, false);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
getCurrentAccountAndBindView(postFilter);
|
bindView(postFilter, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,18 +259,6 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
|||||||
applyFABTheme(fab);
|
applyFABTheme(fab);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView(PostFilter postFilter) {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
bindView(postFilter, true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bindView(PostFilter postFilter, boolean initializeFragment) {
|
private void bindView(PostFilter postFilter, boolean initializeFragment) {
|
||||||
switch (postType) {
|
switch (postType) {
|
||||||
case PostDataSource.TYPE_FRONT_PAGE:
|
case PostDataSource.TYPE_FRONT_PAGE:
|
||||||
@ -467,9 +447,6 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
|||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
||||||
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,7 +7,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -37,7 +36,6 @@ import ml.docilealligator.infinityforreddit.Infinity;
|
|||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.AwardRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.AwardRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.award.GiveAward;
|
import ml.docilealligator.infinityforreddit.award.GiveAward;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
@ -50,8 +48,6 @@ public class GiveAwardActivity extends BaseActivity {
|
|||||||
public static final String EXTRA_RETURN_ITEM_POSITION = "ERIP";
|
public static final String EXTRA_RETURN_ITEM_POSITION = "ERIP";
|
||||||
public static final String EXTRA_RETURN_NEW_AWARDS = "ERNA";
|
public static final String EXTRA_RETURN_NEW_AWARDS = "ERNA";
|
||||||
public static final String EXTRA_RETURN_NEW_AWARDS_COUNT = "ERNAC";
|
public static final String EXTRA_RETURN_NEW_AWARDS_COUNT = "ERNAC";
|
||||||
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
|
||||||
private static final String ACCESS_TOKEN_STATE = "ATS";
|
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_give_award_activity)
|
@BindView(R.id.coordinator_layout_give_award_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@ -70,12 +66,14 @@ public class GiveAwardActivity extends BaseActivity {
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private String thingFullname;
|
private String thingFullname;
|
||||||
private int itemPosition;
|
private int itemPosition;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private AwardRecyclerViewAdapter adapter;
|
private AwardRecyclerViewAdapter adapter;
|
||||||
|
|
||||||
@ -108,29 +106,9 @@ public class GiveAwardActivity extends BaseActivity {
|
|||||||
thingFullname = getIntent().getStringExtra(EXTRA_THING_FULLNAME);
|
thingFullname = getIntent().getStringExtra(EXTRA_THING_FULLNAME);
|
||||||
itemPosition = getIntent().getIntExtra(EXTRA_ITEM_POSITION, 0);
|
itemPosition = getIntent().getIntExtra(EXTRA_ITEM_POSITION, 0);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
bindView();
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
} else {
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
}
|
|
||||||
bindView();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
|
@ -49,7 +49,6 @@ import ml.docilealligator.infinityforreddit.R;
|
|||||||
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
|
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
|
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
|
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||||
@ -67,8 +66,6 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
|||||||
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
|
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
|
||||||
public static final String EXTRA_VIEW_MESSAGE = "EVM";
|
public static final String EXTRA_VIEW_MESSAGE = "EVM";
|
||||||
|
|
||||||
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
|
||||||
private static final String ACCESS_TOKEN_STATE = "ATS";
|
|
||||||
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
|
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
|
||||||
private static final int SEARCH_USER_REQUEST_CODE = 1;
|
private static final int SEARCH_USER_REQUEST_CODE = 1;
|
||||||
|
|
||||||
@ -103,8 +100,8 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
|||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private SlidrInterface mSlidrInterface;
|
private SlidrInterface mSlidrInterface;
|
||||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
|
private String mAccountName;
|
||||||
private String mNewAccountName;
|
private String mNewAccountName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -155,20 +152,15 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
|||||||
setSupportActionBar(mToolbar);
|
setSupportActionBar(mToolbar);
|
||||||
setToolbarGoToTop(mToolbar);
|
setToolbarGoToTop(mToolbar);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
|
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
if (savedInstanceState != null) {
|
||||||
getCurrentAccountAndFetchMessage(savedInstanceState);
|
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
|
||||||
} else {
|
|
||||||
bindView(savedInstanceState);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
|
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
|
||||||
getCurrentAccountAndFetchMessage(savedInstanceState);
|
|
||||||
}
|
}
|
||||||
|
getCurrentAccountAndFetchMessage(savedInstanceState);
|
||||||
|
|
||||||
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
|
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
|
||||||
@Override
|
@Override
|
||||||
@ -235,37 +227,26 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndFetchMessage(Bundle savedInstanceState) {
|
private void getCurrentAccountAndFetchMessage(Bundle savedInstanceState) {
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
if (mNewAccountName != null) {
|
||||||
if (mNewAccountName != null) {
|
if (mAccountName == null || !mAccountName.equals(mNewAccountName)) {
|
||||||
if (account == null || !account.getAccountName().equals(mNewAccountName)) {
|
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences,
|
||||||
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences,
|
mExecutor, new Handler(), mNewAccountName, newAccount -> {
|
||||||
mExecutor, new Handler(), mNewAccountName, newAccount -> {
|
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
|
||||||
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
|
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
|
||||||
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
mNewAccountName = null;
|
mNewAccountName = null;
|
||||||
if (newAccount == null) {
|
if (newAccount != null) {
|
||||||
mNullAccessToken = true;
|
mAccessToken = newAccount.getAccessToken();
|
||||||
} else {
|
}
|
||||||
mAccessToken = newAccount.getAccessToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
bindView(savedInstanceState);
|
bindView(savedInstanceState);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
bindView(savedInstanceState);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
bindView(savedInstanceState);
|
bindView(savedInstanceState);
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
bindView(savedInstanceState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindView(Bundle savedInstanceState) {
|
private void bindView(Bundle savedInstanceState) {
|
||||||
@ -350,8 +331,6 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,6 @@ import ml.docilealligator.infinityforreddit.SortType;
|
|||||||
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||||
import ml.docilealligator.infinityforreddit.account.AccountViewModel;
|
import ml.docilealligator.infinityforreddit.account.AccountViewModel;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.NavigationDrawerRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.NavigationDrawerRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThingsAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThingsAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
|
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.SwitchToAnonymousMode;
|
import ml.docilealligator.infinityforreddit.asynctasks.SwitchToAnonymousMode;
|
||||||
@ -127,12 +126,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
private static final String FETCH_SUBSCRIPTIONS_STATE = "FSS";
|
private static final String FETCH_SUBSCRIPTIONS_STATE = "FSS";
|
||||||
private static final String DRAWER_ON_ACCOUNT_SWITCH_STATE = "DOASS";
|
private static final String DRAWER_ON_ACCOUNT_SWITCH_STATE = "DOASS";
|
||||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
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 ACCESS_TOKEN_STATE = "ATS";
|
||||||
private static final String ACCOUNT_NAME_STATE = "ANS";
|
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 String MESSAGE_FULLNAME_STATE = "MFS";
|
private static final String MESSAGE_FULLNAME_STATE = "MFS";
|
||||||
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
|
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
|
||||||
|
|
||||||
@ -197,10 +192,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
SharedPreferences mNsfwAndSpoilerSharedPreferences;
|
SharedPreferences mNsfwAndSpoilerSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("bottom_app_bar")
|
@Named("bottom_app_bar")
|
||||||
SharedPreferences bottomAppBarSharedPreference;
|
SharedPreferences mBottomAppBarSharedPreference;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("current_account")
|
@Named("current_account")
|
||||||
SharedPreferences currentAccountSharedPreferences;
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
@ -209,12 +204,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||||
private AppBarLayout.LayoutParams params;
|
private AppBarLayout.LayoutParams params;
|
||||||
private NavigationDrawerRecyclerViewAdapter adapter;
|
private NavigationDrawerRecyclerViewAdapter adapter;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private String mProfileImageUrl;
|
|
||||||
private String mBannerImageUrl;
|
|
||||||
private int mKarma;
|
|
||||||
private boolean mFetchUserInfoSuccess = false;
|
private boolean mFetchUserInfoSuccess = false;
|
||||||
private boolean mFetchSubscriptionsSuccess = false;
|
private boolean mFetchSubscriptionsSuccess = false;
|
||||||
private boolean mDrawerOnAccountSwitch = false;
|
private boolean mDrawerOnAccountSwitch = false;
|
||||||
@ -309,29 +300,21 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
|
|
||||||
fragmentManager = getSupportFragmentManager();
|
fragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
|
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
|
||||||
mFetchSubscriptionsSuccess = savedInstanceState.getBoolean(FETCH_SUBSCRIPTIONS_STATE);
|
mFetchSubscriptionsSuccess = savedInstanceState.getBoolean(FETCH_SUBSCRIPTIONS_STATE);
|
||||||
mDrawerOnAccountSwitch = savedInstanceState.getBoolean(DRAWER_ON_ACCOUNT_SWITCH_STATE);
|
mDrawerOnAccountSwitch = savedInstanceState.getBoolean(DRAWER_ON_ACCOUNT_SWITCH_STATE);
|
||||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
mProfileImageUrl = savedInstanceState.getString(ACCOUNT_PROFILE_IMAGE_URL_STATE);
|
|
||||||
mBannerImageUrl = savedInstanceState.getString(ACCOUNT_BANNER_IMAGE_URL_STATE);
|
|
||||||
mKarma = savedInstanceState.getInt(ACCOUNT_KARMA_STATE);
|
|
||||||
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
|
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
|
||||||
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
|
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
|
||||||
|
initializeNotificationAndBindView(true);
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
} else {
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
mMessageFullname = getIntent().getStringExtra(EXTRA_MESSSAGE_FULLNAME);
|
mMessageFullname = getIntent().getStringExtra(EXTRA_MESSSAGE_FULLNAME);
|
||||||
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
|
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
|
||||||
getCurrentAccountAndBindView();
|
initializeNotificationAndBindView(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,108 +344,62 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
applyFABTheme(fab);
|
applyFABTheme(fab);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
private void initializeNotificationAndBindView(boolean doNotInitializeNotificationIfNoNewAccount) {
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
boolean enableNotification = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY, true);
|
||||||
boolean enableNotification = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY, true);
|
long notificationInterval = Long.parseLong(mSharedPreferences.getString(SharedPreferencesUtils.NOTIFICATION_INTERVAL_KEY, "1"));
|
||||||
long notificationInterval = Long.parseLong(mSharedPreferences.getString(SharedPreferencesUtils.NOTIFICATION_INTERVAL_KEY, "1"));
|
TimeUnit timeUnit = (notificationInterval == 15 || notificationInterval == 30) ? TimeUnit.MINUTES : TimeUnit.HOURS;
|
||||||
TimeUnit timeUnit = (notificationInterval == 15 || notificationInterval == 30) ? TimeUnit.MINUTES : TimeUnit.HOURS;
|
|
||||||
|
|
||||||
WorkManager workManager = WorkManager.getInstance(this);
|
WorkManager workManager = WorkManager.getInstance(this);
|
||||||
|
|
||||||
if (mNewAccountName != null) {
|
if (mNewAccountName != null) {
|
||||||
if (account == null || !account.getAccountName().equals(mNewAccountName)) {
|
if (mAccountName == null || !mAccountName.equals(mNewAccountName)) {
|
||||||
SwitchAccount.switchAccount(mRedditDataRoomDatabase, currentAccountSharedPreferences,
|
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences,
|
||||||
mExecutor, new Handler(), mNewAccountName, newAccount -> {
|
mExecutor, new Handler(), mNewAccountName, newAccount -> {
|
||||||
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
|
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
|
||||||
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
mNewAccountName = null;
|
mNewAccountName = null;
|
||||||
if (newAccount == null) {
|
if (newAccount != null) {
|
||||||
mNullAccessToken = true;
|
mAccessToken = newAccount.getAccessToken();
|
||||||
} else {
|
mAccountName = newAccount.getAccountName();
|
||||||
mAccessToken = newAccount.getAccessToken();
|
}
|
||||||
mAccountName = newAccount.getAccountName();
|
|
||||||
mProfileImageUrl = newAccount.getProfileImageUrl();
|
|
||||||
mBannerImageUrl = newAccount.getBannerImageUrl();
|
|
||||||
mKarma = newAccount.getKarma();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enableNotification) {
|
setNotification(workManager, notificationInterval, timeUnit, enableNotification);
|
||||||
Constraints constraints = new Constraints.Builder()
|
|
||||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
PeriodicWorkRequest pullNotificationRequest =
|
bindView();
|
||||||
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
});
|
||||||
notificationInterval, timeUnit)
|
|
||||||
.setConstraints(constraints)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME,
|
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
|
||||||
} else {
|
|
||||||
workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
bindView();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
mProfileImageUrl = account.getProfileImageUrl();
|
|
||||||
mBannerImageUrl = account.getBannerImageUrl();
|
|
||||||
mKarma = account.getKarma();
|
|
||||||
|
|
||||||
if (enableNotification) {
|
|
||||||
Constraints constraints = new Constraints.Builder()
|
|
||||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
PeriodicWorkRequest pullNotificationRequest =
|
|
||||||
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
|
||||||
notificationInterval, timeUnit)
|
|
||||||
.setConstraints(constraints)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME,
|
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
|
||||||
} else {
|
|
||||||
workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (account == null) {
|
setNotification(workManager, notificationInterval, timeUnit, enableNotification);
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
mProfileImageUrl = account.getProfileImageUrl();
|
|
||||||
mBannerImageUrl = account.getBannerImageUrl();
|
|
||||||
mKarma = account.getKarma();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enableNotification) {
|
|
||||||
Constraints constraints = new Constraints.Builder()
|
|
||||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
PeriodicWorkRequest pullNotificationRequest =
|
|
||||||
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
|
||||||
notificationInterval, timeUnit)
|
|
||||||
.setConstraints(constraints)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME,
|
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
|
||||||
} else {
|
|
||||||
workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
if (doNotInitializeNotificationIfNoNewAccount) {
|
||||||
|
setNotification(workManager, notificationInterval, timeUnit, enableNotification);
|
||||||
|
}
|
||||||
|
|
||||||
|
bindView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNotification(WorkManager workManager, long notificationInterval, TimeUnit timeUnit,
|
||||||
|
boolean enableNotification) {
|
||||||
|
if (enableNotification) {
|
||||||
|
Constraints constraints = new Constraints.Builder()
|
||||||
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
PeriodicWorkRequest pullNotificationRequest =
|
||||||
|
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
|
||||||
|
notificationInterval, timeUnit)
|
||||||
|
.setConstraints(constraints)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
workManager.enqueueUniquePeriodicWork(PullNotificationWorker.UNIQUE_WORKER_NAME,
|
||||||
|
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
||||||
|
} else {
|
||||||
|
workManager.cancelUniqueWork(PullNotificationWorker.UNIQUE_WORKER_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bottomAppBarOptionAction(int option) {
|
private void bottomAppBarOptionAction(int option) {
|
||||||
@ -582,9 +519,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
bottomAppBar.setVisibility(View.GONE);
|
bottomAppBar.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
if (showBottomAppBar) {
|
if (showBottomAppBar) {
|
||||||
int optionCount = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, 4);
|
int optionCount = mBottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_COUNT, 4);
|
||||||
int option1 = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS);
|
int option1 = mBottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_1, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_SUBSCRIPTIONS);
|
||||||
int option2 = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS);
|
int option2 = mBottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_2, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_MULTIREDDITS);
|
||||||
|
|
||||||
bottomAppBar.setVisibility(View.VISIBLE);
|
bottomAppBar.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
@ -604,8 +541,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
bottomAppBarOptionAction(option2);
|
bottomAppBarOptionAction(option2);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
int option3 = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_INBOX);
|
int option3 = mBottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_3, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_INBOX);
|
||||||
int option4 = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_PROFILE);
|
int option4 = mBottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_4, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_OPTION_PROFILE);
|
||||||
|
|
||||||
option1BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option1));
|
option1BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option1));
|
||||||
option2BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2));
|
option2BottomAppBar.setImageResource(getBottomAppBarOptionDrawableResource(option2));
|
||||||
@ -636,7 +573,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fabOption = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB,
|
fabOption = mBottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB,
|
||||||
SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS);
|
SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS);
|
||||||
switch (fabOption) {
|
switch (fabOption) {
|
||||||
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_REFRESH:
|
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_REFRESH:
|
||||||
@ -739,7 +676,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
|
|
||||||
adapter = new NavigationDrawerRecyclerViewAdapter(this, mSharedPreferences,
|
adapter = new NavigationDrawerRecyclerViewAdapter(this, mSharedPreferences,
|
||||||
mNsfwAndSpoilerSharedPreferences, mCustomThemeWrapper, mAccountName,
|
mNsfwAndSpoilerSharedPreferences, mCustomThemeWrapper, mAccountName,
|
||||||
mProfileImageUrl, mBannerImageUrl, mKarma,
|
|
||||||
new NavigationDrawerRecyclerViewAdapter.ItemClickListener() {
|
new NavigationDrawerRecyclerViewAdapter.ItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onMenuClick(int stringId) {
|
public void onMenuClick(int stringId) {
|
||||||
@ -796,14 +732,14 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
Intent addAccountIntent = new Intent(MainActivity.this, LoginActivity.class);
|
Intent addAccountIntent = new Intent(MainActivity.this, LoginActivity.class);
|
||||||
startActivityForResult(addAccountIntent, LOGIN_ACTIVITY_REQUEST_CODE);
|
startActivityForResult(addAccountIntent, LOGIN_ACTIVITY_REQUEST_CODE);
|
||||||
} else if (stringId == R.string.anonymous_account) {
|
} else if (stringId == R.string.anonymous_account) {
|
||||||
SwitchToAnonymousMode.switchToAnonymousMode(mRedditDataRoomDatabase, currentAccountSharedPreferences,
|
SwitchToAnonymousMode.switchToAnonymousMode(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences,
|
||||||
mExecutor, new Handler(), false, () -> {
|
mExecutor, new Handler(), false, () -> {
|
||||||
Intent anonymousIntent = new Intent(MainActivity.this, MainActivity.class);
|
Intent anonymousIntent = new Intent(MainActivity.this, MainActivity.class);
|
||||||
startActivity(anonymousIntent);
|
startActivity(anonymousIntent);
|
||||||
finish();
|
finish();
|
||||||
});
|
});
|
||||||
} else if (stringId == R.string.log_out) {
|
} else if (stringId == R.string.log_out) {
|
||||||
SwitchToAnonymousMode.switchToAnonymousMode(mRedditDataRoomDatabase, currentAccountSharedPreferences,
|
SwitchToAnonymousMode.switchToAnonymousMode(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences,
|
||||||
mExecutor, new Handler(), true,
|
mExecutor, new Handler(), true,
|
||||||
() -> {
|
() -> {
|
||||||
Intent logOutIntent = new Intent(MainActivity.this, MainActivity.class);
|
Intent logOutIntent = new Intent(MainActivity.this, MainActivity.class);
|
||||||
@ -826,7 +762,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccountClick(String accountName) {
|
public void onAccountClick(String accountName) {
|
||||||
SwitchAccount.switchAccount(mRedditDataRoomDatabase, currentAccountSharedPreferences,
|
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences,
|
||||||
mExecutor, new Handler(), accountName, newAccount -> {
|
mExecutor, new Handler(), accountName, newAccount -> {
|
||||||
Intent intent = new Intent(MainActivity.this, MainActivity.class);
|
Intent intent = new Intent(MainActivity.this, MainActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
@ -927,7 +863,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
accountViewModel.getAccountsExceptCurrentAccountLiveData().observe(this, adapter::changeAccountsDataset);
|
accountViewModel.getAccountsExceptCurrentAccountLiveData().observe(this, adapter::changeAccountsDataset);
|
||||||
accountViewModel.getCurrentAccountLiveData().observe(this, account -> {
|
accountViewModel.getCurrentAccountLiveData().observe(this, account -> {
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
adapter.updateKarma(account.getKarma());
|
adapter.updateAccountInfo(account.getProfileImageUrl(), account.getBannerImageUrl(),
|
||||||
|
account.getKarma());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -984,9 +921,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
@Override
|
@Override
|
||||||
public void onFetchMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) {
|
public void onFetchMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) {
|
||||||
mAccountName = name;
|
mAccountName = name;
|
||||||
mProfileImageUrl = profileImageUrl;
|
|
||||||
mBannerImageUrl = bannerImageUrl;
|
|
||||||
mKarma = karma;
|
|
||||||
mFetchUserInfoSuccess = true;
|
mFetchUserInfoSuccess = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1119,12 +1053,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
outState.putBoolean(FETCH_SUBSCRIPTIONS_STATE, mFetchSubscriptionsSuccess);
|
outState.putBoolean(FETCH_SUBSCRIPTIONS_STATE, mFetchSubscriptionsSuccess);
|
||||||
outState.putBoolean(DRAWER_ON_ACCOUNT_SWITCH_STATE, mDrawerOnAccountSwitch);
|
outState.putBoolean(DRAWER_ON_ACCOUNT_SWITCH_STATE, mDrawerOnAccountSwitch);
|
||||||
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
||||||
outState.putString(ACCOUNT_PROFILE_IMAGE_URL_STATE, mProfileImageUrl);
|
|
||||||
outState.putString(ACCOUNT_BANNER_IMAGE_URL_STATE, mBannerImageUrl);
|
|
||||||
outState.putInt(ACCOUNT_KARMA_STATE, mKarma);
|
|
||||||
outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
|
outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
|
||||||
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
@ -35,7 +34,6 @@ import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.InsertMultiRedditAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.InsertMultiRedditAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||||
@ -50,9 +48,6 @@ public class MultiredditSelectionActivity extends BaseActivity implements Activi
|
|||||||
static final String EXTRA_RETURN_MULTIREDDIT = "ERM";
|
static final String EXTRA_RETURN_MULTIREDDIT = "ERM";
|
||||||
|
|
||||||
private static final String INSERT_SUBSCRIBED_MULTIREDDIT_STATE = "ISSS";
|
private static final String INSERT_SUBSCRIBED_MULTIREDDIT_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 FRAGMENT_OUT_STATE = "FOS";
|
private static final String FRAGMENT_OUT_STATE = "FOS";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_multireddit_selection_activity)
|
@BindView(R.id.coordinator_layout_multireddit_selection_activity)
|
||||||
@ -70,10 +65,12 @@ public class MultiredditSelectionActivity extends BaseActivity implements Activi
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private boolean mInsertSuccess = false;
|
private boolean mInsertSuccess = false;
|
||||||
@ -118,21 +115,16 @@ public class MultiredditSelectionActivity extends BaseActivity implements Activi
|
|||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
getCurrentAccountAndBindView();
|
bindView(true);
|
||||||
} else {
|
} else {
|
||||||
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_MULTIREDDIT_STATE);
|
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_MULTIREDDIT_STATE);
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_multireddit_selection_activity, mFragment).commit();
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
bindView(false);
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccountName == null) {
|
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
} else {
|
|
||||||
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_multireddit_selection_activity, mFragment).commit();
|
|
||||||
bindView(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,18 +144,6 @@ public class MultiredditSelectionActivity extends BaseActivity implements Activi
|
|||||||
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
bindView(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bindView(boolean initializeFragment) {
|
private void bindView(boolean initializeFragment) {
|
||||||
if (isFinishing() || isDestroyed()) {
|
if (isFinishing() || isDestroyed()) {
|
||||||
return;
|
return;
|
||||||
@ -225,9 +205,6 @@ public class MultiredditSelectionActivity extends BaseActivity implements Activi
|
|||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
||||||
outState.putBoolean(INSERT_SUBSCRIBED_MULTIREDDIT_STATE, mInsertSuccess);
|
outState.putBoolean(INSERT_SUBSCRIBED_MULTIREDDIT_STATE, mInsertSuccess);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,7 +8,6 @@ import android.net.Uri;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -52,7 +51,6 @@ import ml.docilealligator.infinityforreddit.Flair;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
@ -60,6 +58,7 @@ import ml.docilealligator.infinityforreddit.events.SubmitImagePostEvent;
|
|||||||
import ml.docilealligator.infinityforreddit.events.SubmitVideoOrGifPostEvent;
|
import ml.docilealligator.infinityforreddit.events.SubmitVideoOrGifPostEvent;
|
||||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
|
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
|
||||||
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
import pl.droidsonroids.gif.GifImageView;
|
import pl.droidsonroids.gif.GifImageView;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
@ -77,9 +76,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
private static final String FLAIR_STATE = "FS";
|
private static final String FLAIR_STATE = "FS";
|
||||||
private static final String IS_SPOILER_STATE = "ISS";
|
private static final String IS_SPOILER_STATE = "ISS";
|
||||||
private static final String IS_NSFW_STATE = "INS";
|
private static final String IS_NSFW_STATE = "INS";
|
||||||
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 int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||||
private static final int PICK_IMAGE_REQUEST_CODE = 1;
|
private static final int PICK_IMAGE_REQUEST_CODE = 1;
|
||||||
@ -136,10 +132,12 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private String iconUrl;
|
private String iconUrl;
|
||||||
@ -194,15 +192,10 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
|
|
||||||
resources = getResources();
|
resources = getResources();
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccount();
|
|
||||||
}
|
|
||||||
|
|
||||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||||
@ -249,8 +242,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
nsfwTextView.setTextColor(nsfwTextColor);
|
nsfwTextView.setTextColor(nsfwTextColor);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCurrentAccount();
|
|
||||||
|
|
||||||
isPosting = false;
|
isPosting = false;
|
||||||
|
|
||||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||||
@ -410,17 +401,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
selectAgainTextView.setTextColor(mCustomThemeWrapper.getColorAccent());
|
selectAgainTextView.setTextColor(mCustomThemeWrapper.getColorAccent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccount() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadImage() {
|
private void loadImage() {
|
||||||
constraintLayout.setVisibility(View.GONE);
|
constraintLayout.setVisibility(View.GONE);
|
||||||
imageView.setVisibility(View.VISIBLE);
|
imageView.setVisibility(View.VISIBLE);
|
||||||
@ -569,9 +549,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
outState.putParcelable(FLAIR_STATE, flair);
|
outState.putParcelable(FLAIR_STATE, flair);
|
||||||
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
||||||
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,7 +6,6 @@ import android.content.res.ColorStateList;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -43,7 +42,6 @@ import ml.docilealligator.infinityforreddit.Flair;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
@ -51,6 +49,7 @@ import ml.docilealligator.infinityforreddit.events.SubmitTextOrLinkPostEvent;
|
|||||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
|
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
|
||||||
import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
||||||
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
import pl.droidsonroids.gif.GifImageView;
|
import pl.droidsonroids.gif.GifImageView;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
@ -68,8 +67,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
|||||||
private static final String FLAIR_STATE = "FS";
|
private static final String FLAIR_STATE = "FS";
|
||||||
private static final String IS_SPOILER_STATE = "ISS";
|
private static final String IS_SPOILER_STATE = "ISS";
|
||||||
private static final String IS_NSFW_STATE = "INS";
|
private static final String IS_NSFW_STATE = "INS";
|
||||||
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
|
||||||
private static final String ACCESS_TOKEN_STATE = "ATS";
|
|
||||||
|
|
||||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||||
|
|
||||||
@ -113,10 +110,12 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String iconUrl;
|
private String iconUrl;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
@ -169,14 +168,9 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
|||||||
|
|
||||||
resources = getResources();
|
resources = getResources();
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccount();
|
|
||||||
}
|
|
||||||
|
|
||||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||||
@ -218,8 +212,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
|||||||
nsfwTextView.setTextColor(nsfwTextColor);
|
nsfwTextView.setTextColor(nsfwTextColor);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCurrentAccount();
|
|
||||||
|
|
||||||
isPosting = false;
|
isPosting = false;
|
||||||
|
|
||||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||||
@ -347,16 +339,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
|||||||
linkEditText.setHintTextColor(secondaryTextColor);
|
linkEditText.setHintTextColor(secondaryTextColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccount() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void displaySubredditIcon() {
|
private void displaySubredditIcon() {
|
||||||
if (iconUrl != null && !iconUrl.equals("")) {
|
if (iconUrl != null && !iconUrl.equals("")) {
|
||||||
mGlide.load(iconUrl)
|
mGlide.load(iconUrl)
|
||||||
@ -488,8 +470,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
|||||||
outState.putParcelable(FLAIR_STATE, flair);
|
outState.putParcelable(FLAIR_STATE, flair);
|
||||||
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
||||||
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,7 +6,6 @@ import android.content.res.ColorStateList;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -46,7 +45,6 @@ import ml.docilealligator.infinityforreddit.Infinity;
|
|||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
@ -54,6 +52,7 @@ import ml.docilealligator.infinityforreddit.events.SubmitTextOrLinkPostEvent;
|
|||||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
|
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
|
||||||
import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
||||||
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
import pl.droidsonroids.gif.GifImageView;
|
import pl.droidsonroids.gif.GifImageView;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
@ -71,8 +70,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
|||||||
private static final String FLAIR_STATE = "FS";
|
private static final String FLAIR_STATE = "FS";
|
||||||
private static final String IS_SPOILER_STATE = "ISS";
|
private static final String IS_SPOILER_STATE = "ISS";
|
||||||
private static final String IS_NSFW_STATE = "INS";
|
private static final String IS_NSFW_STATE = "INS";
|
||||||
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
|
||||||
private static final String ACCESS_TOKEN_STATE = "ATS";
|
|
||||||
|
|
||||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||||
|
|
||||||
@ -118,10 +115,12 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String iconUrl;
|
private String iconUrl;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
@ -174,14 +173,9 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
|||||||
|
|
||||||
resources = getResources();
|
resources = getResources();
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccount();
|
|
||||||
}
|
|
||||||
|
|
||||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||||
@ -223,8 +217,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
|||||||
nsfwTextView.setTextColor(nsfwTextColor);
|
nsfwTextView.setTextColor(nsfwTextColor);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCurrentAccount();
|
|
||||||
|
|
||||||
isPosting = false;
|
isPosting = false;
|
||||||
|
|
||||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||||
@ -364,16 +356,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
|||||||
contentEditText.setHintTextColor(secondaryTextColor);
|
contentEditText.setHintTextColor(secondaryTextColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccount() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void displaySubredditIcon() {
|
private void displaySubredditIcon() {
|
||||||
if (iconUrl != null && !iconUrl.equals("")) {
|
if (iconUrl != null && !iconUrl.equals("")) {
|
||||||
mGlide.load(iconUrl)
|
mGlide.load(iconUrl)
|
||||||
@ -505,8 +487,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
|||||||
outState.putParcelable(FLAIR_STATE, flair);
|
outState.putParcelable(FLAIR_STATE, flair);
|
||||||
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
||||||
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,7 +7,6 @@ import android.content.res.Resources;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -55,13 +54,13 @@ import ml.docilealligator.infinityforreddit.Flair;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.events.SubmitVideoOrGifPostEvent;
|
import ml.docilealligator.infinityforreddit.events.SubmitVideoOrGifPostEvent;
|
||||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
|
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
|
||||||
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
import pl.droidsonroids.gif.GifImageView;
|
import pl.droidsonroids.gif.GifImageView;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
@ -79,9 +78,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
private static final String FLAIR_STATE = "FS";
|
private static final String FLAIR_STATE = "FS";
|
||||||
private static final String IS_SPOILER_STATE = "ISS";
|
private static final String IS_SPOILER_STATE = "ISS";
|
||||||
private static final String IS_NSFW_STATE = "INS";
|
private static final String IS_NSFW_STATE = "INS";
|
||||||
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 int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||||
private static final int PICK_VIDEO_REQUEST_CODE = 1;
|
private static final int PICK_VIDEO_REQUEST_CODE = 1;
|
||||||
@ -141,10 +137,12 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private String iconUrl;
|
private String iconUrl;
|
||||||
@ -208,6 +206,9 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
|
|
||||||
resources = getResources();
|
resources = getResources();
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||||
@ -218,13 +219,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
flair = savedInstanceState.getParcelable(FLAIR_STATE);
|
flair = savedInstanceState.getParcelable(FLAIR_STATE);
|
||||||
isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE);
|
isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE);
|
||||||
isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE);
|
isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE);
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccount();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (savedInstanceState.getString(VIDEO_URI_STATE) != null) {
|
if (savedInstanceState.getString(VIDEO_URI_STATE) != null) {
|
||||||
videoUri = Uri.parse(savedInstanceState.getString(VIDEO_URI_STATE));
|
videoUri = Uri.parse(savedInstanceState.getString(VIDEO_URI_STATE));
|
||||||
@ -262,8 +256,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
nsfwTextView.setTextColor(nsfwTextColor);
|
nsfwTextView.setTextColor(nsfwTextColor);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCurrentAccount();
|
|
||||||
|
|
||||||
isPosting = false;
|
isPosting = false;
|
||||||
|
|
||||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||||
@ -415,17 +407,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
selectAgainTextView.setTextColor(mCustomThemeWrapper.getColorAccent());
|
selectAgainTextView.setTextColor(mCustomThemeWrapper.getColorAccent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccount() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadVideo() {
|
private void loadVideo() {
|
||||||
constraintLayout.setVisibility(View.GONE);
|
constraintLayout.setVisibility(View.GONE);
|
||||||
selectAgainTextView.setVisibility(View.VISIBLE);
|
selectAgainTextView.setVisibility(View.VISIBLE);
|
||||||
@ -584,9 +565,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
|||||||
outState.putParcelable(FLAIR_STATE, flair);
|
outState.putParcelable(FLAIR_STATE, flair);
|
||||||
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
||||||
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.activities;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -34,7 +33,6 @@ import ml.docilealligator.infinityforreddit.ReportReason;
|
|||||||
import ml.docilealligator.infinityforreddit.ReportThing;
|
import ml.docilealligator.infinityforreddit.ReportThing;
|
||||||
import ml.docilealligator.infinityforreddit.Rule;
|
import ml.docilealligator.infinityforreddit.Rule;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.ReportReasonRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.ReportReasonRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
@ -43,8 +41,6 @@ public class ReportActivity extends BaseActivity {
|
|||||||
|
|
||||||
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||||
public static final String EXTRA_THING_FULLNAME = "ETF";
|
public static final String EXTRA_THING_FULLNAME = "ETF";
|
||||||
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
|
||||||
private static final String ACCESS_TOKEN_STATE = "ATS";
|
|
||||||
private static final String GENERAL_REASONS_STATE = "GRS";
|
private static final String GENERAL_REASONS_STATE = "GRS";
|
||||||
private static final String RULES_REASON_STATE = "RRS";
|
private static final String RULES_REASON_STATE = "RRS";
|
||||||
|
|
||||||
@ -66,12 +62,14 @@ public class ReportActivity extends BaseActivity {
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
@Inject
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mFullname;
|
private String mFullname;
|
||||||
private String mSubredditName;
|
private String mSubredditName;
|
||||||
@ -106,18 +104,11 @@ public class ReportActivity extends BaseActivity {
|
|||||||
mFullname = getIntent().getStringExtra(EXTRA_THING_FULLNAME);
|
mFullname = getIntent().getStringExtra(EXTRA_THING_FULLNAME);
|
||||||
mSubredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
mSubredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccount();
|
|
||||||
}
|
|
||||||
|
|
||||||
generalReasons = savedInstanceState.getParcelableArrayList(GENERAL_REASONS_STATE);
|
generalReasons = savedInstanceState.getParcelableArrayList(GENERAL_REASONS_STATE);
|
||||||
rulesReasons = savedInstanceState.getParcelableArrayList(RULES_REASON_STATE);
|
rulesReasons = savedInstanceState.getParcelableArrayList(RULES_REASON_STATE);
|
||||||
} else {
|
|
||||||
getCurrentAccount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generalReasons != null) {
|
if (generalReasons != null) {
|
||||||
@ -145,16 +136,6 @@ public class ReportActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccount() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.report_activity, menu);
|
getMenuInflater().inflate(R.menu.report_activity, menu);
|
||||||
@ -164,31 +145,31 @@ public class ReportActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
int itemId = item.getItemId();
|
||||||
case android.R.id.home:
|
if (itemId == android.R.id.home) {
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_send_report_activity:
|
} else if (itemId == R.id.action_send_report_activity) {
|
||||||
ReportReason reportReason = mAdapter.getSelectedReason();
|
ReportReason reportReason = mAdapter.getSelectedReason();
|
||||||
if (reportReason != null) {
|
if (reportReason != null) {
|
||||||
Toast.makeText(ReportActivity.this, R.string.reporting, Toast.LENGTH_SHORT).show();
|
Toast.makeText(ReportActivity.this, R.string.reporting, Toast.LENGTH_SHORT).show();
|
||||||
ReportThing.reportThing(mOauthRetrofit, mAccessToken, mFullname, mSubredditName,
|
ReportThing.reportThing(mOauthRetrofit, mAccessToken, mFullname, mSubredditName,
|
||||||
reportReason.getReasonType(), reportReason.getReportReason(), new ReportThing.ReportThingListener() {
|
reportReason.getReasonType(), reportReason.getReportReason(), new ReportThing.ReportThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success() {
|
||||||
Toast.makeText(ReportActivity.this, R.string.report_successful, Toast.LENGTH_SHORT).show();
|
Toast.makeText(ReportActivity.this, R.string.report_successful, Toast.LENGTH_SHORT).show();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void failed() {
|
public void failed() {
|
||||||
Toast.makeText(ReportActivity.this, R.string.report_failed, Toast.LENGTH_SHORT).show();
|
Toast.makeText(ReportActivity.this, R.string.report_failed, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(ReportActivity.this, R.string.report_reason_not_selected, Toast.LENGTH_SHORT).show();
|
Toast.makeText(ReportActivity.this, R.string.report_reason_not_selected, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -197,8 +178,6 @@ public class ReportActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
if (mAdapter != null) {
|
if (mAdapter != null) {
|
||||||
outState.putParcelableArrayList(GENERAL_REASONS_STATE, mAdapter.getGeneralReasons());
|
outState.putParcelableArrayList(GENERAL_REASONS_STATE, mAdapter.getGeneralReasons());
|
||||||
outState.putParcelableArrayList(RULES_REASON_STATE, mAdapter.getRules());
|
outState.putParcelableArrayList(RULES_REASON_STATE, mAdapter.getRules());
|
||||||
|
@ -6,7 +6,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -29,8 +28,6 @@ import com.r0adkll.slidr.Slidr;
|
|||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
@ -40,7 +37,6 @@ import ml.docilealligator.infinityforreddit.Infinity;
|
|||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.SearchActivityRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.SearchActivityRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.recentsearchquery.DeleteRecentSearchQuery;
|
import ml.docilealligator.infinityforreddit.recentsearchquery.DeleteRecentSearchQuery;
|
||||||
@ -60,8 +56,6 @@ public class SearchActivity extends BaseActivity {
|
|||||||
static final String EXTRA_RETURN_USER_NAME = "ERUN";
|
static final String EXTRA_RETURN_USER_NAME = "ERUN";
|
||||||
static final String EXTRA_RETURN_USER_ICON_URL = "ERUIU";
|
static final String EXTRA_RETURN_USER_ICON_URL = "ERUIU";
|
||||||
|
|
||||||
private static final String NULL_ACCOUNT_NAME_STATE = "NANS";
|
|
||||||
private static final String ACCOUNT_NAME_STATE = "ANS";
|
|
||||||
private static final String SUBREDDIT_NAME_STATE = "SNS";
|
private static final String SUBREDDIT_NAME_STATE = "SNS";
|
||||||
private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
|
private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
|
||||||
|
|
||||||
@ -95,10 +89,10 @@ public class SearchActivity extends BaseActivity {
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
private boolean mNullAccountName = false;
|
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private String query;
|
private String query;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
@ -179,9 +173,9 @@ public class SearchActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mNullAccountName = savedInstanceState.getBoolean(NULL_ACCOUNT_NAME_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||||
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
|
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
|
||||||
|
|
||||||
@ -190,15 +184,10 @@ public class SearchActivity extends BaseActivity {
|
|||||||
} else {
|
} else {
|
||||||
subredditNameTextView.setText(subredditName);
|
subredditNameTextView.setText(subredditName);
|
||||||
}
|
}
|
||||||
|
bindView();
|
||||||
if (!mNullAccountName && mAccountName == null) {
|
|
||||||
getCurrentAccountAndInitializeViewPager();
|
|
||||||
} else {
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
query = getIntent().getStringExtra(EXTRA_QUERY);
|
query = getIntent().getStringExtra(EXTRA_QUERY);
|
||||||
getCurrentAccountAndInitializeViewPager();
|
bindView();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (searchOnlySubreddits || searchOnlyUsers) {
|
if (searchOnlySubreddits || searchOnlyUsers) {
|
||||||
@ -219,17 +208,6 @@ public class SearchActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndInitializeViewPager() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccountName = true;
|
|
||||||
} else {
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
bindView();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
if (mAccountName != null) {
|
if (mAccountName != null) {
|
||||||
adapter = new SearchActivityRecyclerViewAdapter(this, mCustomThemeWrapper, new SearchActivityRecyclerViewAdapter.ItemOnClickListener() {
|
adapter = new SearchActivityRecyclerViewAdapter(this, mCustomThemeWrapper, new SearchActivityRecyclerViewAdapter.ItemOnClickListener() {
|
||||||
@ -403,8 +381,6 @@ public class SearchActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(NULL_ACCOUNT_NAME_STATE, mNullAccountName);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||||
outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser);
|
outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -46,12 +45,11 @@ import butterknife.ButterKnife;
|
|||||||
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
|
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SortType;
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostTypeBottomSheetFragment;
|
||||||
@ -77,9 +75,6 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
static final String EXTRA_QUERY = "QK";
|
static final String EXTRA_QUERY = "QK";
|
||||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||||
|
|
||||||
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 INSERT_SEARCH_QUERY_SUCCESS_STATE = "ISQSS";
|
private static final String INSERT_SEARCH_QUERY_SUCCESS_STATE = "ISQSS";
|
||||||
@BindView(R.id.coordinator_layout_search_result_activity)
|
@BindView(R.id.coordinator_layout_search_result_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@ -111,10 +106,12 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
@Named("nsfw_and_spoiler")
|
@Named("nsfw_and_spoiler")
|
||||||
SharedPreferences mNsfwAndSpoilerSharedPreferences;
|
SharedPreferences mNsfwAndSpoilerSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private String mQuery;
|
private String mQuery;
|
||||||
@ -186,19 +183,13 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
|
|
||||||
fragmentManager = getSupportFragmentManager();
|
fragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
getCurrentAccountAndInitializeViewPager();
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
} else {
|
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
if (savedInstanceState != null) {
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
mInsertSearchQuerySuccess = savedInstanceState.getBoolean(INSERT_SEARCH_QUERY_SUCCESS_STATE);
|
mInsertSearchQuerySuccess = savedInstanceState.getBoolean(INSERT_SEARCH_QUERY_SUCCESS_STATE);
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccountAndInitializeViewPager();
|
|
||||||
} else {
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
bindView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -227,18 +218,6 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
applyFABTheme(fab);
|
applyFABTheme(fab);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndInitializeViewPager() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
bindView();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
sectionsPagerAdapter = new SectionsPagerAdapter(this);
|
sectionsPagerAdapter = new SectionsPagerAdapter(this);
|
||||||
viewPager2.setAdapter(sectionsPagerAdapter);
|
viewPager2.setAdapter(sectionsPagerAdapter);
|
||||||
@ -440,9 +419,6 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
outState.putBoolean(INSERT_SEARCH_QUERY_SUCCESS_STATE, mInsertSearchQuerySuccess);
|
outState.putBoolean(INSERT_SEARCH_QUERY_SUCCESS_STATE, mInsertSearchQuerySuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
@ -33,7 +32,6 @@ import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.fragments.SubredditListingFragment;
|
import ml.docilealligator.infinityforreddit.fragments.SubredditListingFragment;
|
||||||
@ -45,9 +43,6 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
|||||||
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
|
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
|
||||||
static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIU";
|
static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIU";
|
||||||
|
|
||||||
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 FRAGMENT_OUT_STATE = "FOS";
|
private static final String FRAGMENT_OUT_STATE = "FOS";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_search_subreddits_result_activity)
|
@BindView(R.id.coordinator_layout_search_subreddits_result_activity)
|
||||||
@ -63,10 +58,12 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
|
|
||||||
@ -113,19 +110,21 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
|||||||
|
|
||||||
String query = getIntent().getExtras().getString(EXTRA_QUERY);
|
String query = getIntent().getExtras().getString(EXTRA_QUERY);
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
getCurrentAccountAndInitializeFragment(query);
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
} else {
|
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
if (savedInstanceState == null) {
|
||||||
getCurrentAccountAndInitializeFragment(query);
|
mFragment = new SubredditListingFragment();
|
||||||
} else {
|
Bundle bundle = new Bundle();
|
||||||
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
bundle.putString(SubredditListingFragment.EXTRA_QUERY, query);
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_subreddits_result_activity, mFragment).commit();
|
bundle.putBoolean(SubredditListingFragment.EXTRA_IS_GETTING_SUBREDDIT_INFO, true);
|
||||||
}
|
bundle.putString(SubredditListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
|
bundle.putString(SubredditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||||
|
mFragment.setArguments(bundle);
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_subreddits_result_activity, mFragment).commit();
|
||||||
|
} else {
|
||||||
|
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_subreddits_result_activity, mFragment).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,26 +144,6 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
|||||||
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndInitializeFragment(String query) {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
|
|
||||||
mFragment = new SubredditListingFragment();
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString(SubredditListingFragment.EXTRA_QUERY, query);
|
|
||||||
bundle.putBoolean(SubredditListingFragment.EXTRA_IS_GETTING_SUBREDDIT_INFO, true);
|
|
||||||
bundle.putString(SubredditListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
|
||||||
bundle.putString(SubredditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
|
||||||
mFragment.setArguments(bundle);
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_subreddits_result_activity, mFragment).commit();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getSelectedSubreddit(String name, String iconUrl) {
|
public void getSelectedSubreddit(String name, String iconUrl) {
|
||||||
Intent returnIntent = new Intent();
|
Intent returnIntent = new Intent();
|
||||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
|
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
|
||||||
@ -186,9 +165,6 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
|||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,7 +5,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
@ -21,8 +20,6 @@ import com.r0adkll.slidr.Slidr;
|
|||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
@ -31,8 +28,6 @@ import butterknife.ButterKnife;
|
|||||||
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.fragments.UserListingFragment;
|
import ml.docilealligator.infinityforreddit.fragments.UserListingFragment;
|
||||||
@ -44,9 +39,6 @@ public class SearchUsersResultActivity extends BaseActivity implements ActivityT
|
|||||||
static final String EXTRA_RETURN_USER_NAME = "ERUN";
|
static final String EXTRA_RETURN_USER_NAME = "ERUN";
|
||||||
static final String EXTRA_RETURN_USER_ICON_URL = "ERUIU";
|
static final String EXTRA_RETURN_USER_ICON_URL = "ERUIU";
|
||||||
|
|
||||||
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 FRAGMENT_OUT_STATE = "FOS";
|
private static final String FRAGMENT_OUT_STATE = "FOS";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_search_users_result_activity)
|
@BindView(R.id.coordinator_layout_search_users_result_activity)
|
||||||
@ -57,15 +49,13 @@ public class SearchUsersResultActivity extends BaseActivity implements ActivityT
|
|||||||
Toolbar toolbar;
|
Toolbar toolbar;
|
||||||
Fragment mFragment;
|
Fragment mFragment;
|
||||||
@Inject
|
@Inject
|
||||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
|
||||||
@Inject
|
|
||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
|
|
||||||
@ -111,19 +101,21 @@ public class SearchUsersResultActivity extends BaseActivity implements ActivityT
|
|||||||
|
|
||||||
String query = getIntent().getExtras().getString(EXTRA_QUERY);
|
String query = getIntent().getExtras().getString(EXTRA_QUERY);
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
getCurrentAccountAndInitializeFragment(query);
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
} else {
|
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
if (savedInstanceState == null) {
|
||||||
getCurrentAccountAndInitializeFragment(query);
|
mFragment = new UserListingFragment();
|
||||||
} else {
|
Bundle bundle = new Bundle();
|
||||||
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
bundle.putString(UserListingFragment.EXTRA_QUERY, query);
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_users_result_activity, mFragment).commit();
|
bundle.putBoolean(UserListingFragment.EXTRA_IS_GETTING_USER_INFO, true);
|
||||||
}
|
bundle.putString(UserListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
|
bundle.putString(UserListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||||
|
mFragment.setArguments(bundle);
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_users_result_activity, mFragment).commit();
|
||||||
|
} else {
|
||||||
|
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_users_result_activity, mFragment).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,26 +135,6 @@ public class SearchUsersResultActivity extends BaseActivity implements ActivityT
|
|||||||
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndInitializeFragment(String query) {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
|
|
||||||
mFragment = new UserListingFragment();
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString(UserListingFragment.EXTRA_QUERY, query);
|
|
||||||
bundle.putBoolean(UserListingFragment.EXTRA_IS_GETTING_USER_INFO, true);
|
|
||||||
bundle.putString(UserListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
|
||||||
bundle.putString(UserListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
|
||||||
mFragment.setArguments(bundle);
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_users_result_activity, mFragment).commit();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getSelectedUser(String name, String iconUrl) {
|
public void getSelectedUser(String name, String iconUrl) {
|
||||||
Intent returnIntent = new Intent();
|
Intent returnIntent = new Intent();
|
||||||
returnIntent.putExtra(EXTRA_RETURN_USER_NAME, name);
|
returnIntent.putExtra(EXTRA_RETURN_USER_NAME, name);
|
||||||
@ -175,9 +147,6 @@ public class SearchUsersResultActivity extends BaseActivity implements ActivityT
|
|||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
@ -38,7 +37,6 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
|||||||
import ml.docilealligator.infinityforreddit.SelectUserFlair;
|
import ml.docilealligator.infinityforreddit.SelectUserFlair;
|
||||||
import ml.docilealligator.infinityforreddit.UserFlair;
|
import ml.docilealligator.infinityforreddit.UserFlair;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.UserFlairRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.UserFlairRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
@ -46,9 +44,6 @@ import retrofit2.Retrofit;
|
|||||||
public class SelectUserFlairActivity extends BaseActivity implements ActivityToolbarInterface {
|
public class SelectUserFlairActivity extends BaseActivity implements ActivityToolbarInterface {
|
||||||
|
|
||||||
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||||
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 USER_FLAIRS_STATE = "UFS";
|
private static final String USER_FLAIRS_STATE = "UFS";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_select_user_flair_activity)
|
@BindView(R.id.coordinator_layout_select_user_flair_activity)
|
||||||
@ -68,6 +63,9 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
@ -107,32 +105,13 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo
|
|||||||
mSubredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
mSubredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||||
setTitle(mSubredditName);
|
setTitle(mSubredditName);
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
mUserFlairs = savedInstanceState.getParcelableArrayList(USER_FLAIRS_STATE);
|
mUserFlairs = savedInstanceState.getParcelableArrayList(USER_FLAIRS_STATE);
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
} else {
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
}
|
}
|
||||||
}
|
bindView();
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
bindView();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
@ -234,9 +213,6 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
outState.putParcelableArrayList(USER_FLAIRS_STATE, mUserFlairs);
|
outState.putParcelableArrayList(USER_FLAIRS_STATE, mUserFlairs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.activities;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -27,15 +26,13 @@ import butterknife.ButterKnife;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.message.ComposeMessage;
|
import ml.docilealligator.infinityforreddit.message.ComposeMessage;
|
||||||
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
public class SendPrivateMessageActivity extends BaseActivity {
|
public class SendPrivateMessageActivity extends BaseActivity {
|
||||||
public static final String EXTRA_RECIPIENT_USERNAME = "ERU";
|
public static final String EXTRA_RECIPIENT_USERNAME = "ERU";
|
||||||
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
|
||||||
private static final String ACCESS_TOKEN_STATE = "ATS";
|
|
||||||
@BindView(R.id.coordinator_layout_send_private_message_activity)
|
@BindView(R.id.coordinator_layout_send_private_message_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@BindView(R.id.appbar_layout_send_private_message_activity)
|
@BindView(R.id.appbar_layout_send_private_message_activity)
|
||||||
@ -61,10 +58,12 @@ public class SendPrivateMessageActivity extends BaseActivity {
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private boolean isSubmitting = false;
|
private boolean isSubmitting = false;
|
||||||
|
|
||||||
@ -85,15 +84,7 @@ public class SendPrivateMessageActivity extends BaseActivity {
|
|||||||
addOnOffsetChangedListener(appBarLayout);
|
addOnOffsetChangedListener(appBarLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
getCurrentAccount();
|
|
||||||
} else {
|
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
@ -103,16 +94,6 @@ public class SendPrivateMessageActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccount() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.send_private_message_activity, menu);
|
getMenuInflater().inflate(R.menu.send_private_message_activity, menu);
|
||||||
@ -185,8 +166,6 @@ public class SendPrivateMessageActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.activities;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -28,7 +27,6 @@ import butterknife.ButterKnife;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent;
|
import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent;
|
||||||
import ml.docilealligator.infinityforreddit.settings.AboutPreferenceFragment;
|
import ml.docilealligator.infinityforreddit.settings.AboutPreferenceFragment;
|
||||||
@ -40,6 +38,7 @@ import ml.docilealligator.infinityforreddit.settings.InterfacePreferenceFragment
|
|||||||
import ml.docilealligator.infinityforreddit.settings.MainPreferenceFragment;
|
import ml.docilealligator.infinityforreddit.settings.MainPreferenceFragment;
|
||||||
import ml.docilealligator.infinityforreddit.settings.NsfwAndBlurringFragment;
|
import ml.docilealligator.infinityforreddit.settings.NsfwAndBlurringFragment;
|
||||||
import ml.docilealligator.infinityforreddit.settings.PostHistoryFragment;
|
import ml.docilealligator.infinityforreddit.settings.PostHistoryFragment;
|
||||||
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
|
|
||||||
public class SettingsActivity extends BaseActivity implements
|
public class SettingsActivity extends BaseActivity implements
|
||||||
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
|
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
|
||||||
@ -50,13 +49,15 @@ public class SettingsActivity extends BaseActivity implements
|
|||||||
AppBarLayout appBarLayout;
|
AppBarLayout appBarLayout;
|
||||||
@BindView(R.id.toolbar_settings_activity)
|
@BindView(R.id.toolbar_settings_activity)
|
||||||
Toolbar toolbar;
|
Toolbar toolbar;
|
||||||
private boolean mNullAccountName;
|
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
@Inject
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@ -85,7 +86,16 @@ public class SettingsActivity extends BaseActivity implements
|
|||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
getCurrentAccountAndBindView(savedInstanceState);
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
getSupportFragmentManager()
|
||||||
|
.beginTransaction()
|
||||||
|
.replace(R.id.frame_layout_settings_activity, new MainPreferenceFragment())
|
||||||
|
.commit();
|
||||||
|
} else {
|
||||||
|
setTitle(savedInstanceState.getCharSequence(TITLE_STATE));
|
||||||
|
}
|
||||||
|
|
||||||
getSupportFragmentManager().addOnBackStackChangedListener(() -> {
|
getSupportFragmentManager().addOnBackStackChangedListener(() -> {
|
||||||
if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
|
if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
|
||||||
@ -105,28 +115,6 @@ public class SettingsActivity extends BaseActivity implements
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView(Bundle savedInstanceState) {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (getSupportFragmentManager().isDestroyed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccountName = true;
|
|
||||||
} else {
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
|
||||||
getSupportFragmentManager()
|
|
||||||
.beginTransaction()
|
|
||||||
.replace(R.id.frame_layout_settings_activity, new MainPreferenceFragment())
|
|
||||||
.commit();
|
|
||||||
} else {
|
|
||||||
setTitle(savedInstanceState.getCharSequence(TITLE_STATE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SharedPreferences getDefaultSharedPreferences() {
|
public SharedPreferences getDefaultSharedPreferences() {
|
||||||
return mSharedPreferences;
|
return mSharedPreferences;
|
||||||
|
@ -8,7 +8,6 @@ import android.graphics.Bitmap;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -52,7 +51,6 @@ import ml.docilealligator.infinityforreddit.Flair;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIconAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
@ -61,6 +59,7 @@ import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
|||||||
import ml.docilealligator.infinityforreddit.post.Post;
|
import ml.docilealligator.infinityforreddit.post.Post;
|
||||||
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
|
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
|
||||||
import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
||||||
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
import pl.droidsonroids.gif.GifImageView;
|
import pl.droidsonroids.gif.GifImageView;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
@ -77,8 +76,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
|||||||
private static final String FLAIR_STATE = "FS";
|
private static final String FLAIR_STATE = "FS";
|
||||||
private static final String IS_SPOILER_STATE = "ISS";
|
private static final String IS_SPOILER_STATE = "ISS";
|
||||||
private static final String IS_NSFW_STATE = "INS";
|
private static final String IS_NSFW_STATE = "INS";
|
||||||
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
|
||||||
private static final String ACCESS_TOKEN_STATE = "ATS";
|
|
||||||
|
|
||||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||||
|
|
||||||
@ -128,10 +125,12 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private Post post;
|
private Post post;
|
||||||
private String iconUrl;
|
private String iconUrl;
|
||||||
@ -186,14 +185,9 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
|||||||
|
|
||||||
post = getIntent().getParcelableExtra(EXTRA_POST);
|
post = getIntent().getParcelableExtra(EXTRA_POST);
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccount();
|
|
||||||
}
|
|
||||||
|
|
||||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||||
@ -235,8 +229,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
|||||||
nsfwTextView.setTextColor(nsfwTextColor);
|
nsfwTextView.setTextColor(nsfwTextColor);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCurrentAccount();
|
|
||||||
|
|
||||||
isPosting = false;
|
isPosting = false;
|
||||||
|
|
||||||
mGlide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
@ -417,16 +409,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
|||||||
contentTextView.setHintTextColor(secondaryTextColor);
|
contentTextView.setHintTextColor(secondaryTextColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccount() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void displaySubredditIcon() {
|
private void displaySubredditIcon() {
|
||||||
if (iconUrl != null && !iconUrl.equals("")) {
|
if (iconUrl != null && !iconUrl.equals("")) {
|
||||||
mGlide.load(iconUrl)
|
mGlide.load(iconUrl)
|
||||||
@ -558,8 +540,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
|||||||
outState.putParcelable(FLAIR_STATE, flair);
|
outState.putParcelable(FLAIR_STATE, flair);
|
||||||
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
||||||
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -42,7 +41,6 @@ import ml.docilealligator.infinityforreddit.Infinity;
|
|||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.SubredditMultiselectionRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.SubredditMultiselectionRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditViewModel;
|
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditViewModel;
|
||||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
@ -53,9 +51,6 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
|
|||||||
static final String EXTRA_RETURN_SELECTED_SUBREDDITS = "ERSS";
|
static final String EXTRA_RETURN_SELECTED_SUBREDDITS = "ERSS";
|
||||||
|
|
||||||
private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 1;
|
private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 1;
|
||||||
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";
|
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_subreddits_multiselection_activity)
|
@BindView(R.id.coordinator_layout_subreddits_multiselection_activity)
|
||||||
CoordinatorLayout mCoordinatorLayout;
|
CoordinatorLayout mCoordinatorLayout;
|
||||||
@ -82,11 +77,13 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
public SubscribedSubredditViewModel mSubscribedSubredditViewModel;
|
public SubscribedSubredditViewModel mSubscribedSubredditViewModel;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private LinearLayoutManager mLinearLayoutManager;
|
private LinearLayoutManager mLinearLayoutManager;
|
||||||
@ -138,33 +135,13 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
|
|||||||
|
|
||||||
mSwipeRefreshLayout.setEnabled(false);
|
mSwipeRefreshLayout.setEnabled(false);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
if (mAccessToken == null) {
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
Toast.makeText(this, R.string.logged_out, Toast.LENGTH_SHORT).show();
|
||||||
|
finish();
|
||||||
if (!mNullAccessToken && mAccountName == null) {
|
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
} else {
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
}
|
}
|
||||||
}
|
bindView();
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
Toast.makeText(this, R.string.logged_out, Toast.LENGTH_SHORT).show();
|
|
||||||
finish();
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
@ -239,9 +216,6 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,7 +5,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -37,7 +36,6 @@ import ml.docilealligator.infinityforreddit.FetchSubscribedThing;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThingsAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThingsAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
||||||
@ -57,10 +55,6 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
|||||||
|
|
||||||
private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 0;
|
private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 0;
|
||||||
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
|
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";
|
private static final String FRAGMENT_OUT_STATE = "FOS";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_subreddit_selection_activity)
|
@BindView(R.id.coordinator_layout_subreddit_selection_activity)
|
||||||
@ -78,10 +72,12 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private String mAccountProfileImageUrl;
|
private String mAccountProfileImageUrl;
|
||||||
@ -128,22 +124,18 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
|||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
getCurrentAccountAndBindView();
|
bindView(true);
|
||||||
} else {
|
} else {
|
||||||
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_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 (!mNullAccessToken && mAccountName == null) {
|
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
||||||
getCurrentAccountAndBindView();
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_subreddit_selection_activity, mFragment).commit();
|
||||||
} else {
|
bindView(false);
|
||||||
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_subreddit_selection_activity, mFragment).commit();
|
|
||||||
bindView(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,19 +155,6 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
|||||||
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
mAccountProfileImageUrl = account.getProfileImageUrl();
|
|
||||||
}
|
|
||||||
bindView(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bindView(boolean initializeFragment) {
|
private void bindView(boolean initializeFragment) {
|
||||||
if (isFinishing() || isDestroyed()) {
|
if (isFinishing() || isDestroyed()) {
|
||||||
return;
|
return;
|
||||||
@ -279,10 +258,6 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
|||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
||||||
outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -44,7 +43,6 @@ import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
|||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.InsertMultiRedditAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.InsertMultiRedditAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThingsAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThingsAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
@ -68,9 +66,6 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
public static final String EXTRA_SHOW_MULTIREDDITS = "ESM";
|
public static final String EXTRA_SHOW_MULTIREDDITS = "ESM";
|
||||||
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
|
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
|
||||||
private static final String INSERT_MULTIREDDIT_STATE = "IMS";
|
private static final String INSERT_MULTIREDDIT_STATE = "IMS";
|
||||||
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";
|
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_subscribed_thing_listing_activity)
|
@BindView(R.id.coordinator_layout_subscribed_thing_listing_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@ -93,11 +88,13 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private SlidrInterface mSlidrInterface;
|
private SlidrInterface mSlidrInterface;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private boolean mInsertSuccess = false;
|
private boolean mInsertSuccess = false;
|
||||||
@ -153,21 +150,16 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
setToolbarGoToTop(toolbar);
|
setToolbarGoToTop(toolbar);
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
|
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
|
||||||
mInsertMultiredditSuccess = savedInstanceState.getBoolean(INSERT_MULTIREDDIT_STATE);
|
mInsertMultiredditSuccess = savedInstanceState.getBoolean(INSERT_MULTIREDDIT_STATE);
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccountAndInitializeViewPager();
|
|
||||||
} else {
|
|
||||||
initializeViewPagerAndLoadSubscriptions();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
showMultiReddits = getIntent().getBooleanExtra(EXTRA_SHOW_MULTIREDDITS, false);
|
showMultiReddits = getIntent().getBooleanExtra(EXTRA_SHOW_MULTIREDDITS, false);
|
||||||
getCurrentAccountAndInitializeViewPager();
|
|
||||||
}
|
}
|
||||||
|
initializeViewPagerAndLoadSubscriptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -188,18 +180,6 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
applyFABTheme(fab);
|
applyFABTheme(fab);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndInitializeViewPager() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
initializeViewPagerAndLoadSubscriptions();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeViewPagerAndLoadSubscriptions() {
|
private void initializeViewPagerAndLoadSubscriptions() {
|
||||||
fab.setOnClickListener(view -> {
|
fab.setOnClickListener(view -> {
|
||||||
Intent intent = new Intent(this, CreateMultiRedditActivity.class);
|
Intent intent = new Intent(this, CreateMultiRedditActivity.class);
|
||||||
@ -248,9 +228,6 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess);
|
outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess);
|
||||||
outState.putBoolean(INSERT_MULTIREDDIT_STATE, mInsertMultiredditSuccess);
|
outState.putBoolean(INSERT_MULTIREDDIT_STATE, mInsertMultiredditSuccess);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -39,7 +38,6 @@ import ml.docilealligator.infinityforreddit.R;
|
|||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SortType;
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTimeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTimeBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTypeBottomSheetFragment;
|
||||||
@ -63,9 +61,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
|||||||
|
|
||||||
private static final String FRAGMENT_OUT_STATE_KEY = "FOSK";
|
private static final String FRAGMENT_OUT_STATE_KEY = "FOSK";
|
||||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
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";
|
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_view_multi_reddit_detail_activity)
|
@BindView(R.id.coordinator_layout_view_multi_reddit_detail_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@ -93,10 +88,12 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
|||||||
@Named("post_layout")
|
@Named("post_layout")
|
||||||
SharedPreferences mPostLayoutSharedPreferences;
|
SharedPreferences mPostLayoutSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private String multiPath;
|
private String multiPath;
|
||||||
@ -160,20 +157,16 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
|||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
setToolbarGoToTop(toolbar);
|
setToolbarGoToTop(toolbar);
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY);
|
||||||
getCurrentAccountAndInitializeFragment();
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_multi_reddit_detail_activity, mFragment).commit();
|
||||||
} else {
|
|
||||||
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY);
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_multi_reddit_detail_activity, mFragment).commit();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
getCurrentAccountAndInitializeFragment();
|
initializeFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
|
sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
|
||||||
@ -188,18 +181,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
|||||||
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndInitializeFragment() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
initializeFragment();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeFragment() {
|
private void initializeFragment() {
|
||||||
mFragment = new PostFragment();
|
mFragment = new PostFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
@ -231,77 +212,77 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
int itemId = item.getItemId();
|
||||||
case android.R.id.home:
|
if (itemId == android.R.id.home) {
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_sort_view_multi_reddit_detail_activity:
|
} else if (itemId == R.id.action_sort_view_multi_reddit_detail_activity) {
|
||||||
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag());
|
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag());
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_search_view_multi_reddit_detail_activity:
|
} else if (itemId == R.id.action_search_view_multi_reddit_detail_activity) {
|
||||||
Intent intent = new Intent(this, SearchActivity.class);
|
Intent intent = new Intent(this, SearchActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_refresh_view_multi_reddit_detail_activity:
|
} else if (itemId == R.id.action_refresh_view_multi_reddit_detail_activity) {
|
||||||
if (mMenu != null) {
|
if (mMenu != null) {
|
||||||
mMenu.findItem(R.id.action_lazy_mode_view_multi_reddit_detail_activity).setTitle(R.string.action_start_lazy_mode);
|
mMenu.findItem(R.id.action_lazy_mode_view_multi_reddit_detail_activity).setTitle(R.string.action_start_lazy_mode);
|
||||||
}
|
}
|
||||||
if (mFragment instanceof FragmentCommunicator) {
|
if (mFragment instanceof FragmentCommunicator) {
|
||||||
((FragmentCommunicator) mFragment).refresh();
|
((FragmentCommunicator) mFragment).refresh();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_lazy_mode_view_multi_reddit_detail_activity:
|
} else if (itemId == R.id.action_lazy_mode_view_multi_reddit_detail_activity) {
|
||||||
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_multi_reddit_detail_activity);
|
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_multi_reddit_detail_activity);
|
||||||
if (isInLazyMode) {
|
if (isInLazyMode) {
|
||||||
isInLazyMode = false;
|
isInLazyMode = false;
|
||||||
((FragmentCommunicator) mFragment).stopLazyMode();
|
((FragmentCommunicator) mFragment).stopLazyMode();
|
||||||
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
|
lazyModeItem.setTitle(R.string.action_start_lazy_mode);
|
||||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
|
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
|
||||||
|
collapsingToolbarLayout.setLayoutParams(params);
|
||||||
|
} else {
|
||||||
|
isInLazyMode = true;
|
||||||
|
if (((FragmentCommunicator) mFragment).startLazyMode()) {
|
||||||
|
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||||
|
appBarLayout.setExpanded(false);
|
||||||
|
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
|
||||||
collapsingToolbarLayout.setLayoutParams(params);
|
collapsingToolbarLayout.setLayoutParams(params);
|
||||||
} else {
|
} else {
|
||||||
isInLazyMode = true;
|
isInLazyMode = false;
|
||||||
if (((FragmentCommunicator) mFragment).startLazyMode()) {
|
|
||||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
|
||||||
appBarLayout.setExpanded(false);
|
|
||||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
|
|
||||||
collapsingToolbarLayout.setLayoutParams(params);
|
|
||||||
} else {
|
|
||||||
isInLazyMode = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
case R.id.action_change_post_layout_view_multi_reddit_detail_activity:
|
return true;
|
||||||
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
|
} else if (itemId == R.id.action_change_post_layout_view_multi_reddit_detail_activity) {
|
||||||
return true;
|
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
|
||||||
case R.id.action_edit_view_multi_reddit_detail_activity:
|
return true;
|
||||||
Intent editIntent = new Intent(this, EditMultiRedditActivity.class);
|
} else if (itemId == R.id.action_edit_view_multi_reddit_detail_activity) {
|
||||||
editIntent.putExtra(EditMultiRedditActivity.EXTRA_MULTI_PATH, multiPath);
|
Intent editIntent = new Intent(this, EditMultiRedditActivity.class);
|
||||||
startActivity(editIntent);
|
editIntent.putExtra(EditMultiRedditActivity.EXTRA_MULTI_PATH, multiPath);
|
||||||
return true;
|
startActivity(editIntent);
|
||||||
case R.id.action_delete_view_multi_reddit_detail_activity:
|
return true;
|
||||||
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
|
} else if (itemId == R.id.action_delete_view_multi_reddit_detail_activity) {
|
||||||
.setTitle(R.string.delete)
|
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
|
||||||
.setMessage(R.string.delete_multi_reddit_dialog_message)
|
.setTitle(R.string.delete)
|
||||||
.setPositiveButton(R.string.delete, (dialogInterface, i)
|
.setMessage(R.string.delete_multi_reddit_dialog_message)
|
||||||
-> DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
|
.setPositiveButton(R.string.delete, (dialogInterface, i)
|
||||||
mAccessToken, mAccountName, multiPath, new DeleteMultiReddit.DeleteMultiRedditListener() {
|
-> DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
|
||||||
@Override
|
mAccessToken, mAccountName, multiPath, new DeleteMultiReddit.DeleteMultiRedditListener() {
|
||||||
public void success() {
|
@Override
|
||||||
Toast.makeText(ViewMultiRedditDetailActivity.this,
|
public void success() {
|
||||||
R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show();
|
Toast.makeText(ViewMultiRedditDetailActivity.this,
|
||||||
EventBus.getDefault().post(new RefreshMultiRedditsEvent());
|
R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show();
|
||||||
finish();
|
EventBus.getDefault().post(new RefreshMultiRedditsEvent());
|
||||||
}
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void failed() {
|
public void failed() {
|
||||||
Toast.makeText(ViewMultiRedditDetailActivity.this,
|
Toast.makeText(ViewMultiRedditDetailActivity.this,
|
||||||
R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show();
|
R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.show();
|
.show();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -310,9 +291,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
|||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
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, mAccountName);
|
|
||||||
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment);
|
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,6 @@ import ml.docilealligator.infinityforreddit.SortType;
|
|||||||
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.CommentAndPostRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.CommentAndPostRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
|
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
|
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostCommentSortTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostCommentSortTypeBottomSheetFragment;
|
||||||
@ -126,9 +125,6 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
|
|||||||
public static final int EDIT_COMMENT_REQUEST_CODE = 3;
|
public static final int EDIT_COMMENT_REQUEST_CODE = 3;
|
||||||
public static final int GIVE_AWARD_REQUEST_CODE = 100;
|
public static final int GIVE_AWARD_REQUEST_CODE = 100;
|
||||||
private static final int EDIT_POST_REQUEST_CODE = 2;
|
private static final int EDIT_POST_REQUEST_CODE = 2;
|
||||||
@State
|
|
||||||
boolean mNullAccessToken = false;
|
|
||||||
@State
|
|
||||||
String mAccessToken;
|
String mAccessToken;
|
||||||
@State
|
@State
|
||||||
String mAccountName;
|
String mAccountName;
|
||||||
@ -528,11 +524,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
|
|||||||
|
|
||||||
orientation = resources.getConfiguration().orientation;
|
orientation = resources.getConfiguration().orientation;
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
getCurrentAccountAndBindView();
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
} else {
|
|
||||||
bindView();
|
checkNewAccountAndBindView();
|
||||||
}
|
|
||||||
|
|
||||||
if (getIntent().hasExtra(EXTRA_POST_LIST_POSITION)) {
|
if (getIntent().hasExtra(EXTRA_POST_LIST_POSITION)) {
|
||||||
postListPosition = getIntent().getIntExtra(EXTRA_POST_LIST_POSITION, -1);
|
postListPosition = getIntent().getIntExtra(EXTRA_POST_LIST_POSITION, -1);
|
||||||
@ -595,41 +590,28 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
|
|||||||
applyFABTheme(fab);
|
applyFABTheme(fab);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
private void checkNewAccountAndBindView() {
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
if (mNewAccountName != null) {
|
||||||
if (mNewAccountName != null) {
|
if (mAccountName == null || !mAccountName.equals(mNewAccountName)) {
|
||||||
if (account == null || !account.getAccountName().equals(mNewAccountName)) {
|
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences,
|
||||||
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences,
|
mExecutor, new Handler(), mNewAccountName, newAccount -> {
|
||||||
mExecutor, new Handler(), mNewAccountName, newAccount -> {
|
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
|
||||||
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
|
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
|
||||||
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
mNewAccountName = null;
|
mNewAccountName = null;
|
||||||
if (newAccount == null) {
|
if (newAccount != null) {
|
||||||
mNullAccessToken = true;
|
mAccessToken = newAccount.getAccessToken();
|
||||||
} else {
|
mAccountName = newAccount.getAccountName();
|
||||||
mAccessToken = newAccount.getAccessToken();
|
}
|
||||||
mAccountName = newAccount.getAccountName();
|
|
||||||
}
|
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
bindView();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
|
@ -4,7 +4,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
@ -37,22 +36,19 @@ import ml.docilealligator.infinityforreddit.Infinity;
|
|||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.PrivateMessagesDetailRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.PrivateMessagesDetailRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.LoadUserDataAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.LoadUserDataAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.events.RepliedToPrivateMessageEvent;
|
import ml.docilealligator.infinityforreddit.events.RepliedToPrivateMessageEvent;
|
||||||
import ml.docilealligator.infinityforreddit.message.Message;
|
import ml.docilealligator.infinityforreddit.message.Message;
|
||||||
import ml.docilealligator.infinityforreddit.message.ReadMessage;
|
import ml.docilealligator.infinityforreddit.message.ReadMessage;
|
||||||
import ml.docilealligator.infinityforreddit.message.ReplyMessage;
|
import ml.docilealligator.infinityforreddit.message.ReplyMessage;
|
||||||
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
public class ViewPrivateMessagesActivity extends BaseActivity implements ActivityToolbarInterface {
|
public class ViewPrivateMessagesActivity extends BaseActivity implements ActivityToolbarInterface {
|
||||||
|
|
||||||
public static final String EXTRA_PRIVATE_MESSAGE = "EPM";
|
public static final String EXTRA_PRIVATE_MESSAGE = "EPM";
|
||||||
public static final String EXTRA_MESSAGE_POSITION = "EMP";
|
public static final String EXTRA_MESSAGE_POSITION = "EMP";
|
||||||
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 USER_AVATAR_STATE = "UAS";
|
private static final String USER_AVATAR_STATE = "UAS";
|
||||||
@BindView(R.id.linear_layout_view_private_messages_activity)
|
@BindView(R.id.linear_layout_view_private_messages_activity)
|
||||||
LinearLayout mLinearLayout;
|
LinearLayout mLinearLayout;
|
||||||
@ -84,13 +80,15 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private LinearLayoutManager mLinearLayoutManager;
|
private LinearLayoutManager mLinearLayoutManager;
|
||||||
private PrivateMessagesDetailRecyclerViewAdapter mAdapter;
|
private PrivateMessagesDetailRecyclerViewAdapter mAdapter;
|
||||||
private Message privateMessage;
|
private Message privateMessage;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private String mUserAvatar;
|
private String mUserAvatar;
|
||||||
@ -126,32 +124,13 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
|||||||
|
|
||||||
mProvideUserAvatarCallbacks = new ArrayList<>();
|
mProvideUserAvatarCallbacks = new ArrayList<>();
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
mUserAvatar = savedInstanceState.getString(USER_AVATAR_STATE);
|
mUserAvatar = savedInstanceState.getString(USER_AVATAR_STATE);
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
} else {
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
}
|
}
|
||||||
}
|
bindView();
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
bindView();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
@ -293,9 +272,6 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
|
||||||
outState.putString(USER_AVATAR_STATE, mUserAvatar);
|
outState.putString(USER_AVATAR_STATE, mUserAvatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,14 +65,13 @@ import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
|
|||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
|
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
|
||||||
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
|
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SortType;
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.AddSubredditOrUserToMultiReddit;
|
import ml.docilealligator.infinityforreddit.asynctasks.AddSubredditOrUserToMultiReddit;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubredditAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubredditAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditDataAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditDataAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
|
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsBottomSheetFragment;
|
||||||
@ -114,9 +113,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
private static final String FETCH_SUBREDDIT_INFO_STATE = "FSIS";
|
private static final String FETCH_SUBREDDIT_INFO_STATE = "FSIS";
|
||||||
private static final String CURRENT_ONLINE_SUBSCRIBERS_STATE = "COSS";
|
private static final String CURRENT_ONLINE_SUBSCRIBERS_STATE = "COSS";
|
||||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
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 MESSAGE_FULLNAME_STATE = "MFS";
|
private static final String MESSAGE_FULLNAME_STATE = "MFS";
|
||||||
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
|
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
|
||||||
private static final int ADD_TO_MULTIREDDIT_REQUEST_CODE = 1;
|
private static final int ADD_TO_MULTIREDDIT_REQUEST_CODE = 1;
|
||||||
@ -200,7 +196,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
public SubredditViewModel mSubredditViewModel;
|
public SubredditViewModel mSubredditViewModel;
|
||||||
private FragmentManager fragmentManager;
|
private FragmentManager fragmentManager;
|
||||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
@ -329,31 +324,26 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
|
|
||||||
fragmentManager = getSupportFragmentManager();
|
fragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME);
|
mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME);
|
||||||
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
|
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
} else {
|
} else {
|
||||||
mFetchSubredditInfoSuccess = savedInstanceState.getBoolean(FETCH_SUBREDDIT_INFO_STATE);
|
mFetchSubredditInfoSuccess = savedInstanceState.getBoolean(FETCH_SUBREDDIT_INFO_STATE);
|
||||||
mNCurrentOnlineSubscribers = savedInstanceState.getInt(CURRENT_ONLINE_SUBSCRIBERS_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);
|
|
||||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||||
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
|
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
|
||||||
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
|
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccountAndBindView();
|
|
||||||
} else {
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mFetchSubredditInfoSuccess) {
|
if (mFetchSubredditInfoSuccess) {
|
||||||
nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, mNCurrentOnlineSubscribers));
|
nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, mNCurrentOnlineSubscribers));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkNewAccountAndBindView();
|
||||||
|
|
||||||
fetchSubredditData();
|
fetchSubredditData();
|
||||||
|
|
||||||
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
||||||
@ -494,41 +484,28 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
subscribedColor = mCustomThemeWrapper.getSubscribed();
|
subscribedColor = mCustomThemeWrapper.getSubscribed();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
private void checkNewAccountAndBindView() {
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
if (mNewAccountName != null) {
|
||||||
if (mNewAccountName != null) {
|
if (mAccountName == null || !mAccountName.equals(mNewAccountName)) {
|
||||||
if (account == null || !account.getAccountName().equals(mNewAccountName)) {
|
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences,
|
||||||
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences,
|
mExecutor, new Handler(), mNewAccountName, newAccount -> {
|
||||||
mExecutor, new Handler(), mNewAccountName, newAccount -> {
|
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
|
||||||
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
|
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
|
||||||
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
mNewAccountName = null;
|
mNewAccountName = null;
|
||||||
if (newAccount == null) {
|
if (newAccount != null) {
|
||||||
mNullAccessToken = true;
|
mAccessToken = newAccount.getAccessToken();
|
||||||
} else {
|
mAccountName = newAccount.getAccountName();
|
||||||
mAccessToken = newAccount.getAccessToken();
|
}
|
||||||
mAccountName = newAccount.getAccountName();
|
|
||||||
}
|
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
bindView();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchSubredditData() {
|
private void fetchSubredditData() {
|
||||||
@ -1084,9 +1061,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
outState.putBoolean(FETCH_SUBREDDIT_INFO_STATE, mFetchSubredditInfoSuccess);
|
outState.putBoolean(FETCH_SUBREDDIT_INFO_STATE, mFetchSubredditInfoSuccess);
|
||||||
outState.putInt(CURRENT_ONLINE_SUBSCRIBERS_STATE, mNCurrentOnlineSubscribers);
|
outState.putInt(CURRENT_ONLINE_SUBSCRIBERS_STATE, mNCurrentOnlineSubscribers);
|
||||||
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
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, mAccountName);
|
|
||||||
outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
|
outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
|
||||||
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,6 @@ import ml.docilealligator.infinityforreddit.SortType;
|
|||||||
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.AddSubredditOrUserToMultiReddit;
|
import ml.docilealligator.infinityforreddit.asynctasks.AddSubredditOrUserToMultiReddit;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.CheckIsFollowingUserAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.CheckIsFollowingUserAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
|
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
|
||||||
@ -120,9 +119,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
public static final int ADD_TO_MULTIREDDIT_REQUEST_CODE = 400;
|
public static final int ADD_TO_MULTIREDDIT_REQUEST_CODE = 400;
|
||||||
|
|
||||||
private static final String FETCH_USER_INFO_STATE = "FSIS";
|
private static final String FETCH_USER_INFO_STATE = "FSIS";
|
||||||
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 IS_IN_LAZY_MODE_STATE = "IILMS";
|
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
||||||
private static final String MESSAGE_FULLNAME_STATE = "MFS";
|
private static final String MESSAGE_FULLNAME_STATE = "MFS";
|
||||||
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
|
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
|
||||||
@ -256,26 +252,21 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
|
|
||||||
fragmentManager = getSupportFragmentManager();
|
fragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME);
|
mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME);
|
||||||
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
|
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
|
||||||
getCurrentAccountAndInitializeViewPager();
|
|
||||||
} else {
|
} else {
|
||||||
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
|
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
|
||||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||||
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
|
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
|
||||||
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
|
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
|
||||||
getCurrentAccountAndInitializeViewPager();
|
|
||||||
} else {
|
|
||||||
initializeViewPager();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkNewAccountAndInitializeViewPager();
|
||||||
|
|
||||||
fetchUserInfo();
|
fetchUserInfo();
|
||||||
|
|
||||||
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
||||||
@ -563,41 +554,28 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
applyTabLayoutTheme(tabLayout);
|
applyTabLayoutTheme(tabLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndInitializeViewPager() {
|
private void checkNewAccountAndInitializeViewPager() {
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
if (mNewAccountName != null) {
|
||||||
if (mNewAccountName != null) {
|
if (mAccountName == null || !mAccountName.equals(mNewAccountName)) {
|
||||||
if (account == null || !account.getAccountName().equals(mNewAccountName)) {
|
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences,
|
||||||
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mCurrentAccountSharedPreferences,
|
mExecutor, new Handler(), mNewAccountName, newAccount -> {
|
||||||
mExecutor, new Handler(), mNewAccountName, newAccount -> {
|
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
|
||||||
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
|
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
|
||||||
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
mNewAccountName = null;
|
mNewAccountName = null;
|
||||||
if (newAccount == null) {
|
if (newAccount != null) {
|
||||||
mNullAccessToken = true;
|
mAccessToken = newAccount.getAccessToken();
|
||||||
} else {
|
mAccountName = newAccount.getAccountName();
|
||||||
mAccessToken = newAccount.getAccessToken();
|
}
|
||||||
mAccountName = newAccount.getAccountName();
|
|
||||||
}
|
|
||||||
|
|
||||||
initializeViewPager();
|
initializeViewPager();
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
initializeViewPager();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getAccountName();
|
|
||||||
}
|
|
||||||
|
|
||||||
initializeViewPager();
|
initializeViewPager();
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
initializeViewPager();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeViewPager() {
|
private void initializeViewPager() {
|
||||||
@ -1075,9 +1053,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess);
|
outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess);
|
||||||
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
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, mAccountName);
|
|
||||||
outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
|
outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
|
||||||
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
||||||
}
|
}
|
||||||
|
@ -59,8 +59,8 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
private Resources resources;
|
private Resources resources;
|
||||||
private RequestManager glide;
|
private RequestManager glide;
|
||||||
private String accountName;
|
private String accountName;
|
||||||
private String userIconUrl;
|
private String profileImageUrl;
|
||||||
private String userBannerUrl;
|
private String bannerImageUrl;
|
||||||
private int karma;
|
private int karma;
|
||||||
private boolean isNSFWEnabled;
|
private boolean isNSFWEnabled;
|
||||||
private boolean requireAuthToAccountSection;
|
private boolean requireAuthToAccountSection;
|
||||||
@ -78,16 +78,12 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
public NavigationDrawerRecyclerViewAdapter(AppCompatActivity appCompatActivity, SharedPreferences sharedPreferences,
|
public NavigationDrawerRecyclerViewAdapter(AppCompatActivity appCompatActivity, SharedPreferences sharedPreferences,
|
||||||
SharedPreferences nsfwAndSpoilerSharedPreferences,
|
SharedPreferences nsfwAndSpoilerSharedPreferences,
|
||||||
CustomThemeWrapper customThemeWrapper,
|
CustomThemeWrapper customThemeWrapper,
|
||||||
String accountName, String userIconUrl,
|
String accountName,
|
||||||
String userBannerUrl, int karma,
|
|
||||||
ItemClickListener itemClickListener) {
|
ItemClickListener itemClickListener) {
|
||||||
this.appCompatActivity = appCompatActivity;
|
this.appCompatActivity = appCompatActivity;
|
||||||
resources = appCompatActivity.getResources();
|
resources = appCompatActivity.getResources();
|
||||||
glide = Glide.with(appCompatActivity);
|
glide = Glide.with(appCompatActivity);
|
||||||
this.accountName = accountName;
|
this.accountName = accountName;
|
||||||
this.userIconUrl = userIconUrl;
|
|
||||||
this.userBannerUrl = userBannerUrl;
|
|
||||||
this.karma = karma;
|
|
||||||
isNSFWEnabled = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
|
isNSFWEnabled = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
requireAuthToAccountSection = sharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false);
|
requireAuthToAccountSection = sharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false);
|
||||||
isLoggedIn = accountName != null;
|
isLoggedIn = accountName != null;
|
||||||
@ -180,8 +176,8 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
((NavHeaderViewHolder) holder).karmaTextView.setText(appCompatActivity.getString(R.string.karma_info, karma));
|
((NavHeaderViewHolder) holder).karmaTextView.setText(appCompatActivity.getString(R.string.karma_info, karma));
|
||||||
((NavHeaderViewHolder) holder).accountNameTextView.setText(accountName);
|
((NavHeaderViewHolder) holder).accountNameTextView.setText(accountName);
|
||||||
if (userIconUrl != null && !userIconUrl.equals("")) {
|
if (profileImageUrl != null && !profileImageUrl.equals("")) {
|
||||||
glide.load(userIconUrl)
|
glide.load(profileImageUrl)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0)))
|
||||||
.error(glide.load(R.drawable.subreddit_default_icon)
|
.error(glide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0))))
|
||||||
@ -192,8 +188,8 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
.into(((NavHeaderViewHolder) holder).profileImageView);
|
.into(((NavHeaderViewHolder) holder).profileImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userBannerUrl != null && !userBannerUrl.equals("")) {
|
if (bannerImageUrl != null && !bannerImageUrl.equals("")) {
|
||||||
glide.load(userBannerUrl).into(((NavHeaderViewHolder) holder).bannerImageView);
|
glide.load(bannerImageUrl).into(((NavHeaderViewHolder) holder).bannerImageView);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
((NavHeaderViewHolder) holder).karmaTextView.setText(R.string.press_here_to_login);
|
((NavHeaderViewHolder) holder).karmaTextView.setText(R.string.press_here_to_login);
|
||||||
@ -546,7 +542,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateKarma(int karma) {
|
public void updateAccountInfo(String profileImageUrl, String bannerImageUrl, int karma) {
|
||||||
|
this.profileImageUrl = profileImageUrl;
|
||||||
|
this.bannerImageUrl = bannerImageUrl;
|
||||||
this.karma = karma;
|
this.karma = karma;
|
||||||
notifyItemChanged(0);
|
notifyItemChanged(0);
|
||||||
}
|
}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
package ml.docilealligator.infinityforreddit.asynctasks;
|
|
||||||
|
|
||||||
import android.os.Handler;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
|
||||||
import ml.docilealligator.infinityforreddit.account.Account;
|
|
||||||
|
|
||||||
public class GetCurrentAccount {
|
|
||||||
|
|
||||||
public static void getCurrentAccount(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase,
|
|
||||||
GetCurrentAccountAsyncTaskListener getCurrentAccountAsyncTaskListener) {
|
|
||||||
executor.execute(() -> {
|
|
||||||
Account account = redditDataRoomDatabase.accountDao().getCurrentAccount();
|
|
||||||
handler.post(() -> getCurrentAccountAsyncTaskListener.success(account));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface GetCurrentAccountAsyncTaskListener {
|
|
||||||
void success(Account account);
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,7 +20,8 @@ public class SwitchAccount {
|
|||||||
Account account = redditDataRoomDatabase.accountDao().getCurrentAccount();
|
Account account = redditDataRoomDatabase.accountDao().getCurrentAccount();
|
||||||
currentAccountSharedPreferences.edit()
|
currentAccountSharedPreferences.edit()
|
||||||
.putString(SharedPreferencesUtils.ACCESS_TOKEN, account.getAccessToken())
|
.putString(SharedPreferencesUtils.ACCESS_TOKEN, account.getAccessToken())
|
||||||
.putString(SharedPreferencesUtils.ACCOUNT_NAME, account.getAccountName()).apply();
|
.putString(SharedPreferencesUtils.ACCOUNT_NAME, account.getAccountName())
|
||||||
|
.putString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, account.getProfileImageUrl()).apply();
|
||||||
handler.post(() -> switchAccountListener.switched(account));
|
handler.post(() -> switchAccountListener.switched(account));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import java.util.concurrent.Executor;
|
|||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.account.AccountDao;
|
import ml.docilealligator.infinityforreddit.account.AccountDao;
|
||||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
|
||||||
|
|
||||||
public class SwitchToAnonymousMode {
|
public class SwitchToAnonymousMode {
|
||||||
public static void switchToAnonymousMode(RedditDataRoomDatabase redditDataRoomDatabase, SharedPreferences currentAccountSharedPreferences,
|
public static void switchToAnonymousMode(RedditDataRoomDatabase redditDataRoomDatabase, SharedPreferences currentAccountSharedPreferences,
|
||||||
@ -20,7 +19,7 @@ public class SwitchToAnonymousMode {
|
|||||||
}
|
}
|
||||||
accountDao.markAllAccountsNonCurrent();
|
accountDao.markAllAccountsNonCurrent();
|
||||||
|
|
||||||
currentAccountSharedPreferences.edit().remove(SharedPreferencesUtils.ACCESS_TOKEN).remove(SharedPreferencesUtils.ACCOUNT_NAME).apply();
|
currentAccountSharedPreferences.edit().clear().apply();
|
||||||
|
|
||||||
handler.post(switchToAnonymousAccountAsyncTaskListener::logoutSuccess);
|
handler.post(switchToAnonymousAccountAsyncTaskListener::logoutSuccess);
|
||||||
});
|
});
|
||||||
|
@ -9,7 +9,6 @@ import android.graphics.drawable.ColorDrawable;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.HapticFeedbackConstants;
|
import android.view.HapticFeedbackConstants;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -42,13 +41,12 @@ import butterknife.ButterKnife;
|
|||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.NetworkState;
|
import ml.docilealligator.infinityforreddit.NetworkState;
|
||||||
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
|
import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SortType;
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
|
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.CommentsListingRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.CommentsListingRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
|
||||||
import ml.docilealligator.infinityforreddit.comment.CommentViewModel;
|
import ml.docilealligator.infinityforreddit.comment.CommentViewModel;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
@ -66,9 +64,6 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
|||||||
public static final String EXTRA_ACCOUNT_NAME = "EAN";
|
public static final String EXTRA_ACCOUNT_NAME = "EAN";
|
||||||
public static final String EXTRA_ARE_SAVED_COMMENTS = "EISC";
|
public static final String EXTRA_ARE_SAVED_COMMENTS = "EISC";
|
||||||
|
|
||||||
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
|
||||||
private static final String ACCESS_TOKEN_STATE = "ATS";
|
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_comments_listing_fragment)
|
@BindView(R.id.coordinator_layout_comments_listing_fragment)
|
||||||
CoordinatorLayout mCoordinatorLayout;
|
CoordinatorLayout mCoordinatorLayout;
|
||||||
@BindView(R.id.swipe_refresh_layout_view_comments_listing_fragment)
|
@BindView(R.id.swipe_refresh_layout_view_comments_listing_fragment)
|
||||||
@ -100,10 +95,12 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
|||||||
@Named("post_layout")
|
@Named("post_layout")
|
||||||
SharedPreferences mPostLayoutSharedPreferences;
|
SharedPreferences mPostLayoutSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper customThemeWrapper;
|
CustomThemeWrapper customThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
private boolean mNullAccessToken = false;
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private RequestManager mGlide;
|
private RequestManager mGlide;
|
||||||
private AppCompatActivity mActivity;
|
private AppCompatActivity mActivity;
|
||||||
@ -248,33 +245,13 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
|||||||
touchHelper.attachToRecyclerView(mCommentRecyclerView);
|
touchHelper.attachToRecyclerView(mCommentRecyclerView);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
getCurrentAccountAndBindView(resources);
|
|
||||||
} else {
|
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
|
||||||
|
|
||||||
if (!mNullAccessToken && mAccessToken == null) {
|
bindView(resources);
|
||||||
getCurrentAccountAndBindView(resources);
|
|
||||||
} else {
|
|
||||||
bindView(resources);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView(Resources resources) {
|
|
||||||
GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
}
|
|
||||||
bindView(resources);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bindView(Resources resources) {
|
private void bindView(Resources resources) {
|
||||||
mLinearLayoutManager = new LinearLayoutManager(mActivity);
|
mLinearLayoutManager = new LinearLayoutManager(mActivity);
|
||||||
mCommentRecyclerView.setLayoutManager(mLinearLayoutManager);
|
mCommentRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||||
@ -381,13 +358,6 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
|||||||
this.mActivity = (AppCompatActivity) context;
|
this.mActivity = (AppCompatActivity) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
|
||||||
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
|
mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
|
||||||
|
@ -259,6 +259,7 @@ public class SharedPreferencesUtils {
|
|||||||
public static final String CURRENT_ACCOUNT_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.current_account";
|
public static final String CURRENT_ACCOUNT_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.current_account";
|
||||||
public static final String ACCOUNT_NAME = "account_name";
|
public static final String ACCOUNT_NAME = "account_name";
|
||||||
public static final String ACCESS_TOKEN = "access_token";
|
public static final String ACCESS_TOKEN = "access_token";
|
||||||
|
public static final String ACCOUNT_IMAGE_URL = "account_image_url";
|
||||||
|
|
||||||
//Legacy Settings
|
//Legacy Settings
|
||||||
public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title";
|
public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title";
|
||||||
|
Loading…
Reference in New Issue
Block a user