diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-06-08 07:10:59 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-06-08 07:10:59 +0000 |
commit | dd8619e78316384981d9362fec06f38ffeb4008f (patch) | |
tree | 5200651eca764ec70c9b03051cb4851051a35ed7 /app/src/main/java | |
parent | 4c762f4bd9a9189166df458bb8b046958bd74d40 (diff) | |
download | infinity-for-reddit-dd8619e78316384981d9362fec06f38ffeb4008f.tar infinity-for-reddit-dd8619e78316384981d9362fec06f38ffeb4008f.tar.gz infinity-for-reddit-dd8619e78316384981d9362fec06f38ffeb4008f.tar.bz2 infinity-for-reddit-dd8619e78316384981d9362fec06f38ffeb4008f.tar.lz infinity-for-reddit-dd8619e78316384981d9362fec06f38ffeb4008f.tar.xz infinity-for-reddit-dd8619e78316384981d9362fec06f38ffeb4008f.tar.zst infinity-for-reddit-dd8619e78316384981d9362fec06f38ffeb4008f.zip |
Add a tab for multireddit list in SubscribedThingActivity. Remove Multireddit button in bottom navigation bar in ViewSubredditDetailActivity and add a go back to main page button.
Diffstat (limited to '')
7 files changed, 291 insertions, 11 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 304c0bac..08596718 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -437,7 +437,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb }); multiRedditBottomAppBar.setOnClickListener(view -> { - Intent intent = new Intent(MainActivity.this, MultiRedditListingActivity.class); + Intent intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); + intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true); startActivity(intent); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java index 1cb7303e..c1919782 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java @@ -32,14 +32,19 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; +import ml.docilealligator.infinityforreddit.AsyncTask.InsertMultiRedditAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Event.GoBackToMainPageEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchSubscribedThing; import ml.docilealligator.infinityforreddit.Fragment.FollowedUsersListingFragment; +import ml.docilealligator.infinityforreddit.Fragment.MultiRedditListingFragment; import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListingFragment; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.MultiReddit.FetchMyMultiReddits; +import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; @@ -49,7 +54,9 @@ import retrofit2.Retrofit; public class SubscribedThingListingActivity extends BaseActivity implements ActivityToolbarInterface { + public static final String EXTRA_SHOW_MULTIREDDITS = "ESM"; private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS"; + 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"; @@ -78,6 +85,8 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti private String mAccessToken; private String mAccountName; private boolean mInsertSuccess = false; + private boolean mInsertMultiredditSuccess = false; + private boolean showMultiReddits = false; private SectionsPagerAdapter sectionsPagerAdapter; @Override @@ -113,6 +122,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti if (savedInstanceState != null) { mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_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); @@ -122,6 +132,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti initializeViewPagerAndLoadSubscriptions(); } } else { + showMultiReddits = getIntent().getBooleanExtra(EXTRA_SHOW_MULTIREDDITS, false); getCurrentAccountAndInitializeViewPager(); } } @@ -158,9 +169,13 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti private void initializeViewPagerAndLoadSubscriptions() { sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(sectionsPagerAdapter); - viewPager.setOffscreenPageLimit(2); + viewPager.setOffscreenPageLimit(3); tabLayout.setupWithViewPager(viewPager); + if (showMultiReddits) { + viewPager.setCurrentItem(2); + } + loadSubscriptions(false); } @@ -178,6 +193,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess); + 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); @@ -220,6 +236,29 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti } }); } + + if (!(!forceLoad && mInsertMultiredditSuccess)) { + loadMultiReddits(); + } + } + + private void loadMultiReddits() { + FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() { + @Override + public void success(ArrayList<MultiReddit> multiReddits) { + new InsertMultiRedditAsyncTask(mRedditDataRoomDatabase, multiReddits, mAccountName, () -> { + mInsertMultiredditSuccess = true; + sectionsPagerAdapter.stopMultiRedditRefreshProgressbar(); + }).execute(); + } + + @Override + public void failed() { + mInsertMultiredditSuccess = false; + sectionsPagerAdapter.stopMultiRedditRefreshProgressbar(); + Toast.makeText(SubscribedThingListingActivity.this, R.string.error_loading_multi_reddit_list, Toast.LENGTH_SHORT).show(); + } + }); } @Subscribe @@ -227,6 +266,11 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti finish(); } + @Subscribe + public void goBackToMainPageEvent(GoBackToMainPageEvent event) { + finish(); + } + @Override public void onLongPress() { if (sectionsPagerAdapter != null) { @@ -238,6 +282,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti private SubscribedSubredditsListingFragment subscribedSubredditsListingFragment; private FollowedUsersListingFragment followedUsersListingFragment; + private MultiRedditListingFragment multiRedditListingFragment; public SectionsPagerAdapter(FragmentManager fm) { super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); @@ -255,7 +300,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti fragment.setArguments(bundle); return fragment; } - default: { + case 1: { FollowedUsersListingFragment fragment = new FollowedUsersListingFragment(); Bundle bundle = new Bundle(); bundle.putString(FollowedUsersListingFragment.EXTRA_ACCOUNT_NAME, mAccountName); @@ -263,12 +308,20 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti fragment.setArguments(bundle); return fragment; } + default: { + MultiRedditListingFragment fragment = new MultiRedditListingFragment(); + Bundle bundle = new Bundle(); + bundle.putString(MultiRedditListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + bundle.putString(MultiRedditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName); + fragment.setArguments(bundle); + return fragment; + } } } @Override public int getCount() { - return 2; + return 3; } @Override @@ -278,6 +331,8 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti return getString(R.string.subreddits); case 1: return getString(R.string.users); + case 2: + return getString(R.string.multi_reddits); } return null; @@ -291,6 +346,8 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti subscribedSubredditsListingFragment = (SubscribedSubredditsListingFragment) fragment; } else if (position == 1) { followedUsersListingFragment = (FollowedUsersListingFragment) fragment; + } else { + multiRedditListingFragment = (MultiRedditListingFragment) fragment; } return fragment; @@ -305,11 +362,19 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti } } + void stopMultiRedditRefreshProgressbar() { + if (multiRedditListingFragment != null) { + ((FragmentCommunicator) multiRedditListingFragment).stopRefreshProgressbar(); + } + } + void goBackToTop() { if (viewPager.getCurrentItem() == 0) { subscribedSubredditsListingFragment.goBackToTop(); - } else { + } else if (viewPager.getCurrentItem() == 1) { followedUsersListingFragment.goBackToTop(); + } else { + multiRedditListingFragment.goBackToTop(); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java index a026456a..19b34354 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -58,6 +58,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTa import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; +import ml.docilealligator.infinityforreddit.Event.GoBackToMainPageEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchSubredditData; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; @@ -137,8 +138,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp LinearLayout linearLayoutBottomAppBar; @BindView(R.id.subscriptions_bottom_app_bar_view_subreddit_detail_activity) ImageView subscriptionsBottomAppBar; - @BindView(R.id.multi_reddit_bottom_app_bar_view_subreddit_detail_activity) - ImageView multiRedditBottomAppBar; + @BindView(R.id.go_back_to_main_page_bottom_app_bar_view_subreddit_detail_activity) + ImageView goBackToMainPageBottomAppBar; @BindView(R.id.message_bottom_app_bar_view_subreddit_detail_activity) ImageView messageBottomAppBar; @BindView(R.id.profile_bottom_app_bar_view_subreddit_detail_activity) @@ -436,7 +437,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor(); subscriptionsBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - multiRedditBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + goBackToMainPageBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); messageBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); profileBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); applyTabLayoutTheme(tabLayout); @@ -523,11 +524,15 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp startActivity(intent); }); - multiRedditBottomAppBar.setOnClickListener(view -> { - Intent intent = new Intent(ViewSubredditDetailActivity.this, MultiRedditListingActivity.class); + subscriptionsBottomAppBar.setOnLongClickListener(view -> { + Intent intent = new Intent(ViewSubredditDetailActivity.this, SubscribedThingListingActivity.class); + intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true); startActivity(intent); + return true; }); + goBackToMainPageBottomAppBar.setOnClickListener(view -> EventBus.getDefault().post(new GoBackToMainPageEvent())); + messageBottomAppBar.setOnClickListener(view -> { Intent intent = new Intent(this, ViewMessageActivity.class); startActivity(intent); @@ -849,6 +854,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw); } + @Subscribe + public void goBackToMainPageEvent(GoBackToMainPageEvent event) { + finish(); + } + @Override public void onLongPress() { if (sectionsPagerAdapter != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 4ee9fe85..f36c1932 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -45,6 +45,7 @@ import ml.docilealligator.infinityforreddit.Activity.ViewVideoActivity; import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment; import ml.docilealligator.infinityforreddit.Fragment.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.FollowedUsersListingFragment; +import ml.docilealligator.infinityforreddit.Fragment.MultiRedditListingFragment; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.SidebarFragment; import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment; @@ -176,4 +177,6 @@ public interface AppComponent { void inject(ViewImgurVideoFragment viewImgurVideoFragment); void inject(DownloadRedditVideoService downloadRedditVideoService); + + void inject(MultiRedditListingFragment multiRedditListingFragment); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/GoBackToMainPageEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/GoBackToMainPageEvent.java new file mode 100644 index 00000000..8457d6dc --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/GoBackToMainPageEvent.java @@ -0,0 +1,4 @@ +package ml.docilealligator.infinityforreddit.Event; + +public class GoBackToMainPageEvent { +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java new file mode 100644 index 00000000..89311f15 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java @@ -0,0 +1,197 @@ +package ml.docilealligator.infinityforreddit.Fragment; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.res.ColorStateList; +import android.content.res.Resources; +import android.os.Build; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModelProvider; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestManager; +import com.google.android.material.floatingactionbutton.FloatingActionButton; + +import javax.inject.Inject; +import javax.inject.Named; + +import butterknife.BindView; +import butterknife.ButterKnife; +import me.zhanghai.android.fastscroll.FastScrollerBuilder; +import ml.docilealligator.infinityforreddit.Activity.BaseActivity; +import ml.docilealligator.infinityforreddit.Activity.CreateMultiRedditActivity; +import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity; +import ml.docilealligator.infinityforreddit.Adapter.MultiRedditListingRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditViewModel; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import retrofit2.Retrofit; + +public class MultiRedditListingFragment extends Fragment implements FragmentCommunicator { + + public static final String EXTRA_ACCOUNT_NAME = "EAN"; + public static final String EXTRA_ACCESS_TOKEN = "EAT"; + private static final String INSERT_MULTI_REDDIT_STATE = "ISSS"; + + @BindView(R.id.swipe_refresh_layout_multi_reddit_listing_fragment) + SwipeRefreshLayout mSwipeRefreshLayout; + @BindView(R.id.recycler_view_multi_reddit_listing_fragment) + RecyclerView mRecyclerView; + @BindView(R.id.fetch_multi_reddit_listing_info_linear_layout_multi_reddit_listing_fragment) + LinearLayout mErrorLinearLayout; + @BindView(R.id.fetch_multi_reddit_listing_info_image_view_multi_reddit_listing_fragment) + ImageView mErrorImageView; + @BindView(R.id.fetch_multi_reddit_listing_info_text_view_multi_reddit_listing_fragment) + TextView mErrorTextView; + @BindView(R.id.fab_multi_reddit_listing_fragment) + FloatingActionButton fab; + @Inject + RedditDataRoomDatabase mRedditDataRoomDatabase; + @Inject + @Named("default") + SharedPreferences mSharedPreferences; + @Inject + @Named("oauth") + Retrofit mOauthRetrofit; + @Inject + CustomThemeWrapper mCustomThemeWrapper; + + public MultiRedditViewModel mMultiRedditViewModel; + private AppCompatActivity mActivity; + private RequestManager mGlide; + private LinearLayoutManager mLinearLayoutManager; + private boolean mInsertSuccess = false; + + public MultiRedditListingFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_multi_reddit_listing, container, false); + + ((Infinity) mActivity.getApplication()).getAppComponent().inject(this); + + ButterKnife.bind(this, rootView); + + applyTheme(); + + if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) { + mRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight()); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + && mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) { + Resources resources = getResources(); + int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); + if (navBarResourceId > 0) { + mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId)); + } + } + + String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); + String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); + + mGlide = Glide.with(this); + + fab.setOnClickListener(view -> { + Intent intent = new Intent(mActivity, CreateMultiRedditActivity.class); + startActivity(intent); + }); + + mLinearLayoutManager = new LinearLayoutManager(mActivity); + mRecyclerView.setLayoutManager(mLinearLayoutManager); + MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(mActivity, + mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken, accountName); + mRecyclerView.setAdapter(adapter); + mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + if (dy > 0) { + fab.hide(); + } else { + fab.show(); + } + } + }); + new FastScrollerBuilder(mRecyclerView).build(); + + mMultiRedditViewModel = new ViewModelProvider(this, + new MultiRedditViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, accountName)) + .get(MultiRedditViewModel.class); + + mMultiRedditViewModel.getAllMultiReddits().observe(this, subscribedUserData -> { + if (subscribedUserData == null || subscribedUserData.size() == 0) { + mRecyclerView.setVisibility(View.GONE); + mErrorLinearLayout.setVisibility(View.VISIBLE); + mGlide.load(R.drawable.error_image).into(mErrorImageView); + } else { + mErrorLinearLayout.setVisibility(View.GONE); + mRecyclerView.setVisibility(View.VISIBLE); + mGlide.clear(mErrorImageView); + } + adapter.setMultiReddits(subscribedUserData); + }); + + mMultiRedditViewModel.getAllFavoriteMultiReddits().observe(this, favoriteSubscribedUserData -> { + if (favoriteSubscribedUserData != null && favoriteSubscribedUserData.size() > 0) { + mErrorLinearLayout.setVisibility(View.GONE); + mRecyclerView.setVisibility(View.VISIBLE); + mGlide.clear(mErrorImageView); + } + adapter.setFavoriteMultiReddits(favoriteSubscribedUserData); + }); + + return rootView; + } + + public void goBackToTop() { + if (mLinearLayoutManager != null) { + mLinearLayoutManager.scrollToPositionWithOffset(0, 0); + } + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + mActivity = (AppCompatActivity) context; + } + + @Override + public void applyTheme() { + if (mActivity instanceof SubscribedThingListingActivity) { + mSwipeRefreshLayout.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true)); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); + mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); + } else { + mSwipeRefreshLayout.setEnabled(false); + } + + mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + fab.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimaryLightTheme())); + fab.setImageTintList(ColorStateList.valueOf(mCustomThemeWrapper.getFABIconColor())); + } + + @Override + public void stopRefreshProgressbar() { + mSwipeRefreshLayout.setRefreshing(false); + } +}
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java index 8e14ce96..728b80ce 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java @@ -177,10 +177,10 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra mSwipeRefreshLayout.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true)); mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(customThemeWrapper.getCircularProgressBarBackground()); mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent()); - mErrorTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); } else { mSwipeRefreshLayout.setEnabled(false); } + mErrorTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); } public void goBackToTop() { |