mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-29 04:17:12 +01:00
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.
This commit is contained in:
parent
4c762f4bd9
commit
dd8619e783
@ -437,7 +437,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
});
|
});
|
||||||
|
|
||||||
multiRedditBottomAppBar.setOnClickListener(view -> {
|
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);
|
startActivity(intent);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -32,14 +32,19 @@ import butterknife.BindView;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
||||||
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
|
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
|
||||||
|
import ml.docilealligator.infinityforreddit.AsyncTask.InsertMultiRedditAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
|
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||||
|
import ml.docilealligator.infinityforreddit.Event.GoBackToMainPageEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.FetchSubscribedThing;
|
import ml.docilealligator.infinityforreddit.FetchSubscribedThing;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.FollowedUsersListingFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.FollowedUsersListingFragment;
|
||||||
|
import ml.docilealligator.infinityforreddit.Fragment.MultiRedditListingFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListingFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListingFragment;
|
||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
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.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
|
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
|
||||||
@ -49,7 +54,9 @@ import retrofit2.Retrofit;
|
|||||||
|
|
||||||
public class SubscribedThingListingActivity extends BaseActivity implements ActivityToolbarInterface {
|
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_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 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";
|
||||||
@ -78,6 +85,8 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
private boolean mInsertSuccess = false;
|
private boolean mInsertSuccess = false;
|
||||||
|
private boolean mInsertMultiredditSuccess = false;
|
||||||
|
private boolean showMultiReddits = false;
|
||||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -113,6 +122,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
|
|
||||||
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);
|
||||||
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
||||||
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
||||||
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
||||||
@ -122,6 +132,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
initializeViewPagerAndLoadSubscriptions();
|
initializeViewPagerAndLoadSubscriptions();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
showMultiReddits = getIntent().getBooleanExtra(EXTRA_SHOW_MULTIREDDITS, false);
|
||||||
getCurrentAccountAndInitializeViewPager();
|
getCurrentAccountAndInitializeViewPager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,9 +169,13 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
private void initializeViewPagerAndLoadSubscriptions() {
|
private void initializeViewPagerAndLoadSubscriptions() {
|
||||||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||||
viewPager.setAdapter(sectionsPagerAdapter);
|
viewPager.setAdapter(sectionsPagerAdapter);
|
||||||
viewPager.setOffscreenPageLimit(2);
|
viewPager.setOffscreenPageLimit(3);
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
|
|
||||||
|
if (showMultiReddits) {
|
||||||
|
viewPager.setCurrentItem(2);
|
||||||
|
}
|
||||||
|
|
||||||
loadSubscriptions(false);
|
loadSubscriptions(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,6 +193,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
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(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
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);
|
||||||
@ -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
|
@Subscribe
|
||||||
@ -227,6 +266,11 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void goBackToMainPageEvent(GoBackToMainPageEvent event) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLongPress() {
|
public void onLongPress() {
|
||||||
if (sectionsPagerAdapter != null) {
|
if (sectionsPagerAdapter != null) {
|
||||||
@ -238,6 +282,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
|
|
||||||
private SubscribedSubredditsListingFragment subscribedSubredditsListingFragment;
|
private SubscribedSubredditsListingFragment subscribedSubredditsListingFragment;
|
||||||
private FollowedUsersListingFragment followedUsersListingFragment;
|
private FollowedUsersListingFragment followedUsersListingFragment;
|
||||||
|
private MultiRedditListingFragment multiRedditListingFragment;
|
||||||
|
|
||||||
public SectionsPagerAdapter(FragmentManager fm) {
|
public SectionsPagerAdapter(FragmentManager fm) {
|
||||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
||||||
@ -255,7 +300,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
default: {
|
case 1: {
|
||||||
FollowedUsersListingFragment fragment = new FollowedUsersListingFragment();
|
FollowedUsersListingFragment fragment = new FollowedUsersListingFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(FollowedUsersListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
bundle.putString(FollowedUsersListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||||
@ -263,12 +308,20 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
return fragment;
|
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
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return 2;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -278,6 +331,8 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
return getString(R.string.subreddits);
|
return getString(R.string.subreddits);
|
||||||
case 1:
|
case 1:
|
||||||
return getString(R.string.users);
|
return getString(R.string.users);
|
||||||
|
case 2:
|
||||||
|
return getString(R.string.multi_reddits);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -291,6 +346,8 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
subscribedSubredditsListingFragment = (SubscribedSubredditsListingFragment) fragment;
|
subscribedSubredditsListingFragment = (SubscribedSubredditsListingFragment) fragment;
|
||||||
} else if (position == 1) {
|
} else if (position == 1) {
|
||||||
followedUsersListingFragment = (FollowedUsersListingFragment) fragment;
|
followedUsersListingFragment = (FollowedUsersListingFragment) fragment;
|
||||||
|
} else {
|
||||||
|
multiRedditListingFragment = (MultiRedditListingFragment) fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fragment;
|
return fragment;
|
||||||
@ -305,11 +362,19 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stopMultiRedditRefreshProgressbar() {
|
||||||
|
if (multiRedditListingFragment != null) {
|
||||||
|
((FragmentCommunicator) multiRedditListingFragment).stopRefreshProgressbar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void goBackToTop() {
|
void goBackToTop() {
|
||||||
if (viewPager.getCurrentItem() == 0) {
|
if (viewPager.getCurrentItem() == 0) {
|
||||||
subscribedSubredditsListingFragment.goBackToTop();
|
subscribedSubredditsListingFragment.goBackToTop();
|
||||||
} else {
|
} else if (viewPager.getCurrentItem() == 1) {
|
||||||
followedUsersListingFragment.goBackToTop();
|
followedUsersListingFragment.goBackToTop();
|
||||||
|
} else {
|
||||||
|
multiRedditListingFragment.goBackToTop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTa
|
|||||||
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask;
|
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
|
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
|
||||||
|
import ml.docilealligator.infinityforreddit.Event.GoBackToMainPageEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
|
||||||
import ml.docilealligator.infinityforreddit.FetchSubredditData;
|
import ml.docilealligator.infinityforreddit.FetchSubredditData;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
||||||
@ -137,8 +138,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
LinearLayout linearLayoutBottomAppBar;
|
LinearLayout linearLayoutBottomAppBar;
|
||||||
@BindView(R.id.subscriptions_bottom_app_bar_view_subreddit_detail_activity)
|
@BindView(R.id.subscriptions_bottom_app_bar_view_subreddit_detail_activity)
|
||||||
ImageView subscriptionsBottomAppBar;
|
ImageView subscriptionsBottomAppBar;
|
||||||
@BindView(R.id.multi_reddit_bottom_app_bar_view_subreddit_detail_activity)
|
@BindView(R.id.go_back_to_main_page_bottom_app_bar_view_subreddit_detail_activity)
|
||||||
ImageView multiRedditBottomAppBar;
|
ImageView goBackToMainPageBottomAppBar;
|
||||||
@BindView(R.id.message_bottom_app_bar_view_subreddit_detail_activity)
|
@BindView(R.id.message_bottom_app_bar_view_subreddit_detail_activity)
|
||||||
ImageView messageBottomAppBar;
|
ImageView messageBottomAppBar;
|
||||||
@BindView(R.id.profile_bottom_app_bar_view_subreddit_detail_activity)
|
@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()));
|
bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor()));
|
||||||
int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor();
|
int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor();
|
||||||
subscriptionsBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
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);
|
messageBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
profileBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
profileBottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
applyTabLayoutTheme(tabLayout);
|
applyTabLayoutTheme(tabLayout);
|
||||||
@ -523,11 +524,15 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
});
|
});
|
||||||
|
|
||||||
multiRedditBottomAppBar.setOnClickListener(view -> {
|
subscriptionsBottomAppBar.setOnLongClickListener(view -> {
|
||||||
Intent intent = new Intent(ViewSubredditDetailActivity.this, MultiRedditListingActivity.class);
|
Intent intent = new Intent(ViewSubredditDetailActivity.this, SubscribedThingListingActivity.class);
|
||||||
|
intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
goBackToMainPageBottomAppBar.setOnClickListener(view -> EventBus.getDefault().post(new GoBackToMainPageEvent()));
|
||||||
|
|
||||||
messageBottomAppBar.setOnClickListener(view -> {
|
messageBottomAppBar.setOnClickListener(view -> {
|
||||||
Intent intent = new Intent(this, ViewMessageActivity.class);
|
Intent intent = new Intent(this, ViewMessageActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
@ -849,6 +854,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
|
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void goBackToMainPageEvent(GoBackToMainPageEvent event) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLongPress() {
|
public void onLongPress() {
|
||||||
if (sectionsPagerAdapter != null) {
|
if (sectionsPagerAdapter != null) {
|
||||||
|
@ -45,6 +45,7 @@ import ml.docilealligator.infinityforreddit.Activity.ViewVideoActivity;
|
|||||||
import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.FlairBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.FlairBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.FollowedUsersListingFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.FollowedUsersListingFragment;
|
||||||
|
import ml.docilealligator.infinityforreddit.Fragment.MultiRedditListingFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.SidebarFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.SidebarFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment;
|
||||||
@ -176,4 +177,6 @@ public interface AppComponent {
|
|||||||
void inject(ViewImgurVideoFragment viewImgurVideoFragment);
|
void inject(ViewImgurVideoFragment viewImgurVideoFragment);
|
||||||
|
|
||||||
void inject(DownloadRedditVideoService downloadRedditVideoService);
|
void inject(DownloadRedditVideoService downloadRedditVideoService);
|
||||||
|
|
||||||
|
void inject(MultiRedditListingFragment multiRedditListingFragment);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.Event;
|
||||||
|
|
||||||
|
public class GoBackToMainPageEvent {
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -177,10 +177,10 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
|
|||||||
mSwipeRefreshLayout.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true));
|
mSwipeRefreshLayout.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true));
|
||||||
mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(customThemeWrapper.getCircularProgressBarBackground());
|
mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(customThemeWrapper.getCircularProgressBarBackground());
|
||||||
mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent());
|
mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent());
|
||||||
mErrorTextView.setTextColor(customThemeWrapper.getSecondaryTextColor());
|
|
||||||
} else {
|
} else {
|
||||||
mSwipeRefreshLayout.setEnabled(false);
|
mSwipeRefreshLayout.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
mErrorTextView.setTextColor(customThemeWrapper.getSecondaryTextColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void goBackToTop() {
|
public void goBackToTop() {
|
||||||
|
9
app/src/main/res/drawable/ic_home_black_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_home_black_24dp.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:pathData="M12,5.69l5,4.5V18h-2v-6H9v6H7v-7.81l5,-4.5M12,3L2,12h3v8h6v-6h2v6h6v-8h3L12,3z"
|
||||||
|
android:fillColor="#000000"/>
|
||||||
|
</vector>
|
@ -182,6 +182,17 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:weightSum="5">
|
android:weightSum="5">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/go_back_to_main_page_bottom_app_bar_view_subreddit_detail_activity"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:src="@drawable/ic_home_black_24dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/subscriptions_bottom_app_bar_view_subreddit_detail_activity"
|
android:id="@+id/subscriptions_bottom_app_bar_view_subreddit_detail_activity"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
@ -193,17 +204,6 @@
|
|||||||
android:src="@drawable/ic_subscritptions_bottom_app_bar_24dp"
|
android:src="@drawable/ic_subscritptions_bottom_app_bar_24dp"
|
||||||
android:background="?attr/selectableItemBackgroundBorderless" />
|
android:background="?attr/selectableItemBackgroundBorderless" />
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/multi_reddit_bottom_app_bar_view_subreddit_detail_activity"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="center"
|
|
||||||
android:paddingTop="8dp"
|
|
||||||
android:paddingBottom="8dp"
|
|
||||||
android:src="@drawable/ic_multi_reddit_24dp"
|
|
||||||
android:background="?attr/selectableItemBackgroundBorderless" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
55
app/src/main/res/layout/fragment_multi_reddit_listing.xml
Normal file
55
app/src/main/res/layout/fragment_multi_reddit_listing.xml
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/swipe_refresh_layout_multi_reddit_listing_fragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/recycler_view_multi_reddit_listing_fragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/fetch_multi_reddit_listing_info_linear_layout_multi_reddit_listing_fragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginBottom="48dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/fetch_multi_reddit_listing_info_image_view_multi_reddit_listing_fragment"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/fetch_multi_reddit_listing_info_text_view_multi_reddit_listing_fragment"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/no_multi_reddits"
|
||||||
|
android:textSize="?attr/font_default" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
android:id="@+id/fab_multi_reddit_listing_fragment"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/fab_margin"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
app:srcCompat="@drawable/ic_add_day_night_24dp"
|
||||||
|
app:tint="@android:color/white" />
|
||||||
|
|
||||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -175,6 +175,7 @@
|
|||||||
|
|
||||||
<string name="subreddits">Subreddits</string>
|
<string name="subreddits">Subreddits</string>
|
||||||
<string name="users">Users</string>
|
<string name="users">Users</string>
|
||||||
|
<string name="multi_reddits">MultiReddits</string>
|
||||||
|
|
||||||
<string name="bottom_sheet_post_type">Post</string>
|
<string name="bottom_sheet_post_type">Post</string>
|
||||||
<string name="bottom_sheet_post_text">Text</string>
|
<string name="bottom_sheet_post_text">Text</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user