diff options
Diffstat (limited to 'app/src/main/java')
7 files changed, 56 insertions, 27 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java index 1ac3b368..588d4041 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java @@ -39,7 +39,12 @@ class AccessTokenAuthenticator implements Authenticator { @Override public Request authenticate(Route route, @NonNull Response response) { if (response.code() == 401) { - String accessToken = response.request().header(APIUtils.AUTHORIZATION_KEY).substring(APIUtils.AUTHORIZATION_BASE.length()); + String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY); + if (accessTokenHeader == null) { + return null; + } + + String accessToken = accessTokenHeader.substring(APIUtils.AUTHORIZATION_BASE.length()); synchronized (this) { Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AnyAccountAccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AnyAccountAccessTokenAuthenticator.java index 4cedc8e9..9bd31c2d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AnyAccountAccessTokenAuthenticator.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AnyAccountAccessTokenAuthenticator.java @@ -42,7 +42,12 @@ public class AnyAccountAccessTokenAuthenticator implements Authenticator { @Override public Request authenticate(Route route, @NonNull Response response) { if (response.code() == 401) { - String accessToken = response.request().header(APIUtils.AUTHORIZATION_KEY).substring(APIUtils.AUTHORIZATION_BASE.length()); + String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY); + if (accessTokenHeader == null) { + return null; + } + + String accessToken = accessTokenHeader.substring(APIUtils.AUTHORIZATION_BASE.length()); synchronized (this) { if (mAccount == null) { return null; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java index 36438c02..1d59eb8d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java @@ -7,7 +7,6 @@ import android.os.Bundle; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; -import android.view.View; import android.view.Window; import android.view.WindowManager; @@ -356,10 +355,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec } else if (itemId == R.id.action_sort_filtered_thing_activity) { switch (postType) { case PostPagingSource.TYPE_FRONT_PAGE: - SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); - Bundle bestBundle = new Bundle(); - bestBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, false); - bestSortTypeBottomSheetFragment.setArguments(bestBundle); + SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(false, mFragment.getSortType().getType().fullName); bestSortTypeBottomSheetFragment.show(getSupportFragmentManager(), bestSortTypeBottomSheetFragment.getTag()); break; case PostPagingSource.TYPE_SEARCH: @@ -372,10 +368,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec case PostPagingSource.TYPE_MULTI_REDDIT: case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT: case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE: - SortTypeBottomSheetFragment sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); - Bundle popularBundle = new Bundle(); - popularBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); - sortTypeBottomSheetFragment.setArguments(popularBundle); + SortTypeBottomSheetFragment sortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(true, mFragment.getSortType().getType().fullName); sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); break; case PostPagingSource.TYPE_USER: diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index ebe833a4..1a453f35 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -1065,11 +1065,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb private void changeSortType() { int currentPostType = sectionsPagerAdapter.getCurrentPostType(); - Bundle bundle = new Bundle(); - bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, currentPostType != PostPagingSource.TYPE_FRONT_PAGE); - SortTypeBottomSheetFragment sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); - sortTypeBottomSheetFragment.setArguments(bundle); - sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); + PostFragment postFragment = sectionsPagerAdapter.getCurrentFragment(); + if (postFragment != null) { + SortTypeBottomSheetFragment sortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(currentPostType != PostPagingSource.TYPE_FRONT_PAGE, postFragment.getSortType().getType().fullName); + sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java index 31c0a19f..e3cf7c63 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java @@ -575,11 +575,10 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT } private void showSortTypeBottomSheetFragment() { - SortTypeBottomSheetFragment sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); - Bundle bottomSheetBundle = new Bundle(); - bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); - sortTypeBottomSheetFragment.setArguments(bottomSheetBundle); - sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); + if (mFragment instanceof PostFragment) { + SortTypeBottomSheetFragment sortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(true, ((PostFragment) mFragment).getSortType().getType().fullName); + sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); + } } private void showPostLayoutBottomSheetFragment() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index af31b76a..d266145a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -1091,11 +1091,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } private void displaySortTypeBottomSheetFragment() { - SortTypeBottomSheetFragment sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); - Bundle bottomSheetBundle = new Bundle(); - bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); - sortTypeBottomSheetFragment.setArguments(bottomSheetBundle); - sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); + Fragment fragment = fragmentManager.findFragmentByTag("f0"); + if (fragment instanceof PostFragment) { + SortTypeBottomSheetFragment sortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(true, ((PostFragment) fragment).getSortType().getType().fullName); + sortTypeBottomSheetFragment.show(fragmentManager, sortTypeBottomSheetFragment.getTag()); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTypeBottomSheetFragment.java index f2d50c38..881b1910 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTypeBottomSheetFragment.java @@ -11,6 +11,7 @@ import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.appcompat.content.res.AppCompatResources; import androidx.fragment.app.Fragment; import butterknife.BindView; @@ -29,6 +30,8 @@ import ml.docilealligator.infinityforreddit.utils.Utils; public class SortTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { public static final String EXTRA_NO_BEST_TYPE = "ENBT"; + public static final String EXTRA_CURRENT_SORT_TYPE = "ECST"; + @BindView(R.id.best_type_text_view_sort_type_bottom_sheet_fragment) TextView bestTypeTextView; @BindView(R.id.hot_type_text_view_sort_type_bottom_sheet_fragment) @@ -46,6 +49,15 @@ public class SortTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS // Required empty public constructor } + public static SortTypeBottomSheetFragment getNewInstance(boolean isNoBestType, String currentSortType) { + SortTypeBottomSheetFragment fragment = new SortTypeBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putBoolean(EXTRA_NO_BEST_TYPE, isNoBestType); + bundle.putString(EXTRA_CURRENT_SORT_TYPE, currentSortType); + fragment.setArguments(bundle); + return fragment; + } + @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -57,7 +69,7 @@ public class SortTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); } - if (getArguments() == null || getArguments().getBoolean(EXTRA_NO_BEST_TYPE)) { + if (getArguments().getBoolean(EXTRA_NO_BEST_TYPE)) { bestTypeTextView.setVisibility(View.GONE); } else { bestTypeTextView.setOnClickListener(view -> { @@ -66,6 +78,21 @@ public class SortTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS }); } + String currentSortType = getArguments().getString(EXTRA_CURRENT_SORT_TYPE); + if (currentSortType.equals(SortType.Type.BEST.fullName)) { + bestTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(bestTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); + } else if (currentSortType.equals(SortType.Type.HOT.fullName)) { + hotTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(hotTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); + } else if (currentSortType.equals(SortType.Type.NEW.fullName)) { + newTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(newTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); + } else if (currentSortType.equals(SortType.Type.RISING.fullName)) { + risingTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(risingTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); + } else if (currentSortType.equals(SortType.Type.TOP.fullName)) { + topTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(topTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); + } else if (currentSortType.equals(SortType.Type.CONTROVERSIAL.fullName)) { + controversialTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(controversialTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); + } + hotTypeTextView.setOnClickListener(view -> { ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.HOT)); dismiss(); |