mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
Add favorite subreddits to the navigation drawer. Add favorite and subscriptions header to the navigation drawer.
This commit is contained in:
parent
0c251c972c
commit
73c4ead2c0
@ -678,13 +678,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
sectionsPagerAdapter.setSubscribedSubreddits(subscribedSubredditData);
|
sectionsPagerAdapter.setSubscribedSubreddits(subscribedSubredditData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (mShowFavoriteSubscribedSubreddits) {
|
subscribedSubredditViewModel.getAllFavoriteSubscribedSubreddits().observe(this, subscribedSubredditData -> {
|
||||||
subscribedSubredditViewModel.getAllFavoriteSubscribedSubreddits().observe(this, subscribedSubredditData -> {
|
adapter.setFavoriteSubscribedSubreddits(subscribedSubredditData);
|
||||||
if (sectionsPagerAdapter != null) {
|
if (mShowFavoriteSubscribedSubreddits && sectionsPagerAdapter != null) {
|
||||||
sectionsPagerAdapter.setFavoriteSubscribedSubreddits(subscribedSubredditData);
|
sectionsPagerAdapter.setFavoriteSubscribedSubreddits(subscribedSubredditData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
accountViewModel = new ViewModelProvider(this,
|
accountViewModel = new ViewModelProvider(this,
|
||||||
new AccountViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName)).get(AccountViewModel.class);
|
new AccountViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName)).get(AccountViewModel.class);
|
||||||
|
@ -50,8 +50,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
private static final int VIEW_TYPE_MENU_GROUP_TITLE = 1;
|
private static final int VIEW_TYPE_MENU_GROUP_TITLE = 1;
|
||||||
private static final int VIEW_TYPE_MENU_ITEM = 2;
|
private static final int VIEW_TYPE_MENU_ITEM = 2;
|
||||||
private static final int VIEW_TYPE_DIVIDER = 3;
|
private static final int VIEW_TYPE_DIVIDER = 3;
|
||||||
private static final int VIEW_TYPE_SUBSCRIBED_SUBREDDIT = 4;
|
private static final int VIEW_TYPE_FAVORITE_SUBSCRIBED_SUBREDDIT = 4;
|
||||||
private static final int VIEW_TYPE_ACCOUNT = 5;
|
private static final int VIEW_TYPE_SUBSCRIBED_SUBREDDIT = 5;
|
||||||
|
private static final int VIEW_TYPE_ACCOUNT = 6;
|
||||||
private static final int CURRENT_MENU_ITEMS = 17;
|
private static final int CURRENT_MENU_ITEMS = 17;
|
||||||
|
|
||||||
private AppCompatActivity appCompatActivity;
|
private AppCompatActivity appCompatActivity;
|
||||||
@ -66,6 +67,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
private ItemClickListener itemClickListener;
|
private ItemClickListener itemClickListener;
|
||||||
private boolean isLoggedIn;
|
private boolean isLoggedIn;
|
||||||
private boolean isInMainPage = true;
|
private boolean isInMainPage = true;
|
||||||
|
private ArrayList<SubscribedSubredditData> favoriteSubscribedSubreddits;
|
||||||
private ArrayList<SubscribedSubredditData> subscribedSubreddits;
|
private ArrayList<SubscribedSubredditData> subscribedSubreddits;
|
||||||
private ArrayList<Account> accounts;
|
private ArrayList<Account> accounts;
|
||||||
private int primaryTextColor;
|
private int primaryTextColor;
|
||||||
@ -94,14 +96,24 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
secondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
secondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
||||||
dividerColor = customThemeWrapper.getDividerColor();
|
dividerColor = customThemeWrapper.getDividerColor();
|
||||||
primaryIconColor = customThemeWrapper.getPrimaryIconColor();
|
primaryIconColor = customThemeWrapper.getPrimaryIconColor();
|
||||||
|
favoriteSubscribedSubreddits = new ArrayList<>();
|
||||||
|
subscribedSubreddits = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
if (isInMainPage) {
|
if (isInMainPage) {
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
if (position >= CURRENT_MENU_ITEMS) {
|
if (position == CURRENT_MENU_ITEMS) {
|
||||||
return VIEW_TYPE_SUBSCRIBED_SUBREDDIT;
|
return VIEW_TYPE_MENU_GROUP_TITLE;
|
||||||
|
} else if (!favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS + favoriteSubscribedSubreddits.size() + 1) {
|
||||||
|
return VIEW_TYPE_MENU_GROUP_TITLE;
|
||||||
|
} else if (position > CURRENT_MENU_ITEMS) {
|
||||||
|
if (!favoriteSubscribedSubreddits.isEmpty() && position <= CURRENT_MENU_ITEMS + favoriteSubscribedSubreddits.size()) {
|
||||||
|
return VIEW_TYPE_FAVORITE_SUBSCRIBED_SUBREDDIT;
|
||||||
|
} else {
|
||||||
|
return VIEW_TYPE_SUBSCRIBED_SUBREDDIT;
|
||||||
|
}
|
||||||
} else if (position == 0) {
|
} else if (position == 0) {
|
||||||
return VIEW_TYPE_NAV_HEADER;
|
return VIEW_TYPE_NAV_HEADER;
|
||||||
} else if (position == 1 || position == 6 || position == 12) {
|
} else if (position == 1 || position == 6 || position == 12) {
|
||||||
@ -153,6 +165,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
case VIEW_TYPE_ACCOUNT:
|
case VIEW_TYPE_ACCOUNT:
|
||||||
return new AccountViewHolder(LayoutInflater.from(parent.getContext())
|
return new AccountViewHolder(LayoutInflater.from(parent.getContext())
|
||||||
.inflate(R.layout.item_nav_drawer_account, parent, false));
|
.inflate(R.layout.item_nav_drawer_account, parent, false));
|
||||||
|
case VIEW_TYPE_FAVORITE_SUBSCRIBED_SUBREDDIT:
|
||||||
|
return new FavoriteSubscribedThingViewHolder(LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.item_nav_drawer_subscribed_thing, parent, false));
|
||||||
default:
|
default:
|
||||||
return new SubscribedThingViewHolder(LayoutInflater.from(parent.getContext())
|
return new SubscribedThingViewHolder(LayoutInflater.from(parent.getContext())
|
||||||
.inflate(R.layout.item_nav_drawer_subscribed_thing, parent, false));
|
.inflate(R.layout.item_nav_drawer_subscribed_thing, parent, false));
|
||||||
@ -234,6 +249,12 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_post);
|
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_post);
|
||||||
} else if (position == 12) {
|
} else if (position == 12) {
|
||||||
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_preferences);
|
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_preferences);
|
||||||
|
} else {
|
||||||
|
if (!favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS) {
|
||||||
|
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.favorites);
|
||||||
|
} else {
|
||||||
|
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.subscriptions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (holder instanceof MenuItemViewHolder) {
|
} else if (holder instanceof MenuItemViewHolder) {
|
||||||
int stringId = 0;
|
int stringId = 0;
|
||||||
@ -383,8 +404,29 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
((MenuItemViewHolder) holder).itemView.setOnClickListener(view -> itemClickListener.onMenuClick(finalStringId));
|
((MenuItemViewHolder) holder).itemView.setOnClickListener(view -> itemClickListener.onMenuClick(finalStringId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (holder instanceof FavoriteSubscribedThingViewHolder) {
|
||||||
|
SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.get(position - CURRENT_MENU_ITEMS - 1);
|
||||||
|
String subredditName = subreddit.getName();
|
||||||
|
String iconUrl = subreddit.getIconUrl();
|
||||||
|
((FavoriteSubscribedThingViewHolder) holder).subredditNameTextView.setText(subredditName);
|
||||||
|
if (iconUrl != null && !iconUrl.equals("")) {
|
||||||
|
glide.load(iconUrl)
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
|
.error(glide.load(R.drawable.subreddit_default_icon)
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
|
.into(((FavoriteSubscribedThingViewHolder) holder).iconGifImageView);
|
||||||
|
} else {
|
||||||
|
glide.load(R.drawable.subreddit_default_icon)
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
|
.into(((FavoriteSubscribedThingViewHolder) holder).iconGifImageView);
|
||||||
|
}
|
||||||
|
|
||||||
|
((FavoriteSubscribedThingViewHolder) holder).itemView.setOnClickListener(view -> {
|
||||||
|
itemClickListener.onSubscribedSubredditClick(subredditName);
|
||||||
|
});
|
||||||
} else if (holder instanceof SubscribedThingViewHolder) {
|
} else if (holder instanceof SubscribedThingViewHolder) {
|
||||||
SubscribedSubredditData subreddit = subscribedSubreddits.get(position - CURRENT_MENU_ITEMS);
|
SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.isEmpty() ? subscribedSubreddits.get(position - CURRENT_MENU_ITEMS - 1)
|
||||||
|
: subscribedSubreddits.get(position - CURRENT_MENU_ITEMS - favoriteSubscribedSubreddits.size() - 2);
|
||||||
String subredditName = subreddit.getName();
|
String subredditName = subreddit.getName();
|
||||||
String iconUrl = subreddit.getIconUrl();
|
String iconUrl = subreddit.getIconUrl();
|
||||||
((SubscribedThingViewHolder) holder).subredditNameTextView.setText(subredditName);
|
((SubscribedThingViewHolder) holder).subredditNameTextView.setText(subredditName);
|
||||||
@ -418,11 +460,8 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
if (!(checkIsInMainPage && isInMainPage)) {
|
if (!(checkIsInMainPage && isInMainPage)) {
|
||||||
notifyItemRangeRemoved(1, getItemCount() - 1);
|
notifyItemRangeRemoved(1, getItemCount() - 1);
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
if (subscribedSubreddits != null) {
|
notifyItemRangeInserted(1, (favoriteSubscribedSubreddits.isEmpty() ? 0 : favoriteSubscribedSubreddits.size() + 1)
|
||||||
notifyItemRangeInserted(1, subscribedSubreddits.size() + CURRENT_MENU_ITEMS - 1);
|
+ (subscribedSubreddits.isEmpty() ? 0 : subscribedSubreddits.size() + 1) + CURRENT_MENU_ITEMS - 1);
|
||||||
} else {
|
|
||||||
notifyItemRangeInserted(1, CURRENT_MENU_ITEMS - 1);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
notifyItemRangeInserted(1, 2);
|
notifyItemRangeInserted(1, 2);
|
||||||
}
|
}
|
||||||
@ -453,8 +492,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
if (isInMainPage) {
|
if (isInMainPage) {
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
if (subscribedSubreddits != null) {
|
if (!(favoriteSubscribedSubreddits.isEmpty() && subscribedSubreddits.isEmpty())) {
|
||||||
return CURRENT_MENU_ITEMS + subscribedSubreddits.size();
|
return CURRENT_MENU_ITEMS + (favoriteSubscribedSubreddits.isEmpty() ? 0 : favoriteSubscribedSubreddits.size() + 1)
|
||||||
|
+ (subscribedSubreddits.isEmpty() ? 0 : subscribedSubreddits.size() + 1);
|
||||||
}
|
}
|
||||||
return CURRENT_MENU_ITEMS - 1;
|
return CURRENT_MENU_ITEMS - 1;
|
||||||
} else {
|
} else {
|
||||||
@ -485,6 +525,13 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFavoriteSubscribedSubreddits(List<SubscribedSubredditData> favoriteSubscribedSubreddits) {
|
||||||
|
this.favoriteSubscribedSubreddits = (ArrayList<SubscribedSubredditData>) favoriteSubscribedSubreddits;
|
||||||
|
if (isInMainPage) {
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setSubscribedSubreddits(List<SubscribedSubredditData> subscribedSubreddits) {
|
public void setSubscribedSubreddits(List<SubscribedSubredditData> subscribedSubreddits) {
|
||||||
this.subscribedSubreddits = (ArrayList<SubscribedSubredditData>) subscribedSubreddits;
|
this.subscribedSubreddits = (ArrayList<SubscribedSubredditData>) subscribedSubreddits;
|
||||||
if (isInMainPage) {
|
if (isInMainPage) {
|
||||||
@ -564,6 +611,19 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FavoriteSubscribedThingViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
@BindView(R.id.thing_icon_gif_image_view_item_nav_drawer_subscribed_thing)
|
||||||
|
GifImageView iconGifImageView;
|
||||||
|
@BindView(R.id.thing_name_text_view_item_nav_drawer_subscribed_thing)
|
||||||
|
TextView subredditNameTextView;
|
||||||
|
|
||||||
|
FavoriteSubscribedThingViewHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
ButterKnife.bind(this, itemView);
|
||||||
|
subredditNameTextView.setTextColor(primaryTextColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SubscribedThingViewHolder extends RecyclerView.ViewHolder {
|
class SubscribedThingViewHolder extends RecyclerView.ViewHolder {
|
||||||
@BindView(R.id.thing_icon_gif_image_view_item_nav_drawer_subscribed_thing)
|
@BindView(R.id.thing_icon_gif_image_view_item_nav_drawer_subscribed_thing)
|
||||||
GifImageView iconGifImageView;
|
GifImageView iconGifImageView;
|
||||||
|
@ -99,6 +99,8 @@ public class CustomizeMainPageTabsFragment extends Fragment {
|
|||||||
View divider4;
|
View divider4;
|
||||||
@BindView(R.id.more_tabs_group_summary_customize_main_page_tabs_fragment)
|
@BindView(R.id.more_tabs_group_summary_customize_main_page_tabs_fragment)
|
||||||
TextView moreTabsGroupSummaryTextView;
|
TextView moreTabsGroupSummaryTextView;
|
||||||
|
@BindView(R.id.more_tabs_info_text_view_customize_main_page_tabs_fragment)
|
||||||
|
TextView moreTabsInfoTextView;
|
||||||
@BindView(R.id.show_subscribed_subreddits_linear_layout_customize_main_page_tabs_fragment)
|
@BindView(R.id.show_subscribed_subreddits_linear_layout_customize_main_page_tabs_fragment)
|
||||||
LinearLayout showSubscribedSubredditsLinearLayout;
|
LinearLayout showSubscribedSubredditsLinearLayout;
|
||||||
@BindView(R.id.show_subscribed_subreddits_switch_material_customize_main_page_tabs_fragment)
|
@BindView(R.id.show_subscribed_subreddits_switch_material_customize_main_page_tabs_fragment)
|
||||||
@ -156,6 +158,7 @@ public class CustomizeMainPageTabsFragment extends Fragment {
|
|||||||
tab3TypeLinearLayout.setVisibility(View.GONE);
|
tab3TypeLinearLayout.setVisibility(View.GONE);
|
||||||
divider4.setVisibility(View.GONE);
|
divider4.setVisibility(View.GONE);
|
||||||
moreTabsGroupSummaryTextView.setVisibility(View.GONE);
|
moreTabsGroupSummaryTextView.setVisibility(View.GONE);
|
||||||
|
moreTabsInfoTextView.setVisibility(View.GONE);
|
||||||
showSubscribedSubredditsLinearLayout.setVisibility(View.GONE);
|
showSubscribedSubredditsLinearLayout.setVisibility(View.GONE);
|
||||||
showFavoriteSubscribedSubredditsLinearLayout.setVisibility(View.GONE);
|
showFavoriteSubscribedSubredditsLinearLayout.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
@ -447,6 +447,19 @@
|
|||||||
android:textSize="?attr/font_default"
|
android:textSize="?attr/font_default"
|
||||||
android:fontFamily="?attr/font_family" />
|
android:fontFamily="?attr/font_family" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/more_tabs_info_text_view_customize_main_page_tabs_fragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:drawablePadding="32dp"
|
||||||
|
android:text="@string/settings_more_tabs_info_summary"
|
||||||
|
android:textColor="@color/settingsSubtitleColor"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:textSize="?attr/font_default"
|
||||||
|
android:fontFamily="?attr/font_family"
|
||||||
|
app:drawableStartCompat="@drawable/ic_info_preference_24dp" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/show_favorite_subscribed_subreddits_linear_layout_customize_main_page_tabs_fragment"
|
android:id="@+id/show_favorite_subscribed_subreddits_linear_layout_customize_main_page_tabs_fragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -341,7 +341,7 @@
|
|||||||
<string name="settings_start_autoplay_visible_area_offset_landscape_title">Autoplay Videos Visible Area Offset (Landscape)</string>
|
<string name="settings_start_autoplay_visible_area_offset_landscape_title">Autoplay Videos Visible Area Offset (Landscape)</string>
|
||||||
<string name="settings_start_autoplay_visible_area_offset_landscape_summary">Start autoplaying videos when %1$d%% of them are visible</string>
|
<string name="settings_start_autoplay_visible_area_offset_landscape_summary">Start autoplaying videos when %1$d%% of them are visible</string>
|
||||||
<string name="settings_immersive_interface_title">Immersive Interface</string>
|
<string name="settings_immersive_interface_title">Immersive Interface</string>
|
||||||
<string name="settings_immersive_interface_summary">Does Not Apply to All Pages\nMay Not Work On Android 11</string>
|
<string name="settings_immersive_interface_summary">Does Not Apply to All Pages</string>
|
||||||
<string name="settings_immersive_interface_ignore_nav_bar_title">Ignore Navigation Bar in Immersive Interface</string>
|
<string name="settings_immersive_interface_ignore_nav_bar_title">Ignore Navigation Bar in Immersive Interface</string>
|
||||||
<string name="settings_immersive_interface_ignore_nav_bar_summary">Prevent the Bottom Navigation Bar Having Extra Padding</string>
|
<string name="settings_immersive_interface_ignore_nav_bar_summary">Prevent the Bottom Navigation Bar Having Extra Padding</string>
|
||||||
<string name="settings_customize_tabs_in_main_page_title">Customize Tabs in Main Page</string>
|
<string name="settings_customize_tabs_in_main_page_title">Customize Tabs in Main Page</string>
|
||||||
@ -453,6 +453,7 @@
|
|||||||
<string name="settings_tab_2_summary">Tab 2</string>
|
<string name="settings_tab_2_summary">Tab 2</string>
|
||||||
<string name="settings_tab_3_summary">Tab 3</string>
|
<string name="settings_tab_3_summary">Tab 3</string>
|
||||||
<string name="settings_more_tabs_summary">More Tabs</string>
|
<string name="settings_more_tabs_summary">More Tabs</string>
|
||||||
|
<string name="settings_more_tabs_info_summary">Enabling the following options will cause an unintended behaviour:\nTabs may lose all the content after switching to others. This is the same as refreshing the page.</string>
|
||||||
<string name="settings_more_tabs_show_favorite_subscribed_subreddits_title">Show Favorite Subscribed Subreddits</string>
|
<string name="settings_more_tabs_show_favorite_subscribed_subreddits_title">Show Favorite Subscribed Subreddits</string>
|
||||||
<string name="settings_more_tabs_show_subscribed_subreddits_title">Show Subscribed Subreddits</string>
|
<string name="settings_more_tabs_show_subscribed_subreddits_title">Show Subscribed Subreddits</string>
|
||||||
<string name="settings_tab_title">Title</string>
|
<string name="settings_tab_title">Title</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user