mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 11:17:25 +01:00
Start implementing showing subscribed subreddits in the nav drawer. Use a RecyclerView to display all the items in the nav drawer.
This commit is contained in:
parent
8c454d52c7
commit
248aca0fb9
@ -18,16 +18,13 @@ import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.core.widget.NestedScrollView;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
@ -44,7 +41,6 @@ import androidx.work.WorkManager;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestManager;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
import com.google.android.material.bottomappbar.BottomAppBar;
|
||||
@ -63,15 +59,12 @@ import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import ml.docilealligator.infinityforreddit.Account.Account;
|
||||
import ml.docilealligator.infinityforreddit.Account.AccountViewModel;
|
||||
import ml.docilealligator.infinityforreddit.Adapter.AccountRecyclerViewAdapter;
|
||||
import ml.docilealligator.infinityforreddit.Adapter.NavigationDrawerRecyclerViewAdapter;
|
||||
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
|
||||
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
|
||||
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
|
||||
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask;
|
||||
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchToAnonymousAccountAsyncTask;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeConfirmToExitEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeLockBottomAppBarEvent;
|
||||
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
|
||||
@ -95,14 +88,11 @@ import ml.docilealligator.infinityforreddit.SortType;
|
||||
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
|
||||
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
|
||||
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel;
|
||||
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
|
||||
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
|
||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
|
||||
|
||||
public class MainActivity extends BaseActivity implements SortTypeSelectionCallback,
|
||||
PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
|
||||
|
||||
@ -137,7 +127,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
CollapsingToolbarLayout collapsingToolbarLayout;
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@BindView(R.id.nested_scroll_view_main_activity)
|
||||
@BindView(R.id.nav_drawer_recycler_view_main_activity)
|
||||
RecyclerView navDrawerRecyclerView;
|
||||
/*@BindView(R.id.nested_scroll_view_main_activity)
|
||||
NestedScrollView nestedScrollView;
|
||||
@BindView(R.id.all_drawer_items_linear_layout_main_activity)
|
||||
LinearLayout allDrawerItemsLinearLayout;
|
||||
@ -170,7 +162,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
@BindView(R.id.settings_text_view_main_activity)
|
||||
TextView settingsTextView;
|
||||
@BindView(R.id.account_recycler_view_main_activity)
|
||||
RecyclerView accountRecyclerView;
|
||||
RecyclerView accountRecyclerView;*/
|
||||
@BindView(R.id.tab_layout_main_activity)
|
||||
TabLayout tabLayout;
|
||||
@BindView(R.id.bottom_navigation_main_activity)
|
||||
@ -187,6 +179,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
ImageView profileBottomAppBar;
|
||||
@BindView(R.id.fab_main_activity)
|
||||
FloatingActionButton fab;
|
||||
SubscribedSubredditViewModel subscribedSubredditViewModel;
|
||||
AccountViewModel accountViewModel;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
@ -196,11 +189,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
@Inject
|
||||
SharedPreferences mSharedPreferences;
|
||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||
private TextView mAccountNameTextView;
|
||||
/*private TextView mAccountNameTextView;
|
||||
private TextView mKarmaTextView;
|
||||
private GifImageView mProfileImageView;
|
||||
private ImageView mBannerImageView;
|
||||
private ImageView mDropIconImageView;
|
||||
private ImageView mDropIconImageView;*/
|
||||
private RequestManager glide;
|
||||
private AppBarLayout.LayoutParams params;
|
||||
private PostTypeBottomSheetFragment postTypeBottomSheetFragment;
|
||||
@ -208,6 +201,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
private SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment;
|
||||
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
|
||||
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
|
||||
private NavigationDrawerRecyclerViewAdapter adapter;
|
||||
private boolean mNullAccessToken = false;
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
@ -292,7 +286,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
int navBarHeight = resources.getDimensionPixelSize(navBarResourceId);
|
||||
linearLayoutBottomAppBar.setPadding(0,
|
||||
(int) (6 * resources.getDisplayMetrics().density), 0, navBarHeight);
|
||||
nestedScrollView.setPadding(0, 0, 0, navBarHeight);
|
||||
//nestedScrollView.setPadding(0, 0, 0, navBarHeight);
|
||||
navDrawerRecyclerView.setPadding(0, 0, 0, navBarHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -502,6 +497,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
fab.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
adapter = new NavigationDrawerRecyclerViewAdapter(this, mAccountName, mProfileImageUrl, mBannerImageUrl, mKarma);
|
||||
navDrawerRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
navDrawerRecyclerView.setAdapter(adapter);
|
||||
|
||||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
viewPager.setAdapter(sectionsPagerAdapter);
|
||||
viewPager.setOffscreenPageLimit(3);
|
||||
@ -538,7 +537,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
|
||||
glide = Glide.with(this);
|
||||
|
||||
AccountRecyclerViewAdapter adapter = new AccountRecyclerViewAdapter(this, glide, mAccountName,
|
||||
/*AccountRecyclerViewAdapter adapter = new AccountRecyclerViewAdapter(this, glide, mAccountName,
|
||||
new AccountRecyclerViewAdapter.ItemSelectedListener() {
|
||||
@Override
|
||||
public void accountSelected(Account account) {
|
||||
@ -574,11 +573,17 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
finish();
|
||||
}).execute();
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
accountRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
/*accountRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
accountRecyclerView.setNestedScrollingEnabled(false);
|
||||
accountRecyclerView.setAdapter(adapter);
|
||||
accountRecyclerView.setAdapter(adapter);*/
|
||||
|
||||
subscribedSubredditViewModel = new ViewModelProvider(this,
|
||||
new SubscribedSubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName))
|
||||
.get(SubscribedSubredditViewModel.class);
|
||||
subscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this,
|
||||
subscribedSubredditData -> adapter.setSubscribedSubreddits(subscribedSubredditData));
|
||||
|
||||
accountViewModel = new ViewModelProvider(this,
|
||||
new AccountViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName)).get(AccountViewModel.class);
|
||||
@ -593,7 +598,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
}
|
||||
}
|
||||
|
||||
View header = findViewById(R.id.nav_header_main_activity);
|
||||
/*View header = findViewById(R.id.nav_header_main_activity);
|
||||
mAccountNameTextView = header.findViewById(R.id.name_text_view_nav_header_main);
|
||||
mKarmaTextView = header.findViewById(R.id.karma_text_view_nav_header_main);
|
||||
mProfileImageView = header.findViewById(R.id.profile_image_view_nav_header_main);
|
||||
@ -622,13 +627,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
accountRecyclerView.setVisibility(View.VISIBLE);
|
||||
allDrawerItemsLinearLayout.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
loadUserData();
|
||||
|
||||
if (mAccessToken != null) {
|
||||
mKarmaTextView.setText(getString(R.string.karma_info, mKarma));
|
||||
mAccountNameTextView.setText(mAccountName);
|
||||
/*mKarmaTextView.setText(getString(R.string.karma_info, mKarma));
|
||||
mAccountNameTextView.setText(mAccountName);*/
|
||||
if (mMessageFullname != null) {
|
||||
ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
|
||||
@Override
|
||||
@ -643,7 +648,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
});
|
||||
}
|
||||
} else {
|
||||
mKarmaTextView.setText(R.string.press_here_to_login);
|
||||
/*mKarmaTextView.setText(R.string.press_here_to_login);
|
||||
mAccountNameTextView.setText(R.string.anonymous_account);
|
||||
accountLabelTextView.setVisibility(View.GONE);
|
||||
profileTextView.setVisibility(View.GONE);
|
||||
@ -656,10 +661,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
hiddenTextView.setVisibility(View.GONE);
|
||||
savedTextView.setVisibility(View.GONE);
|
||||
gildedTextView.setVisibility(View.GONE);
|
||||
divider.setVisibility(View.GONE);
|
||||
divider.setVisibility(View.GONE);*/
|
||||
}
|
||||
|
||||
if (mProfileImageUrl != null && !mProfileImageUrl.equals("")) {
|
||||
/*if (mProfileImageUrl != null && !mProfileImageUrl.equals("")) {
|
||||
glide.load(mProfileImageUrl)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0)))
|
||||
.error(glide.load(R.drawable.subreddit_default_icon)
|
||||
@ -673,9 +678,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
|
||||
if (mBannerImageUrl != null && !mBannerImageUrl.equals("")) {
|
||||
glide.load(mBannerImageUrl).into(mBannerImageView);
|
||||
}
|
||||
}*/
|
||||
|
||||
profileTextView.setOnClickListener(view -> {
|
||||
/*profileTextView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(this, ViewUserDetailActivity.class);
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName);
|
||||
startActivity(intent);
|
||||
@ -766,7 +771,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
drawer.closeDrawers();
|
||||
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
private void loadSubscriptions() {
|
||||
@ -804,7 +809,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
ParseAndSaveAccountInfo.parseAndSaveAccountInfo(response, mRedditDataRoomDatabase, new ParseAndSaveAccountInfo.ParseAndSaveAccountInfoListener() {
|
||||
@Override
|
||||
public void onParseMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) {
|
||||
mAccountNameTextView.setText(name);
|
||||
/*mAccountNameTextView.setText(name);
|
||||
if (profileImageUrl != null && !profileImageUrl.equals("")) {
|
||||
glide.load(profileImageUrl)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(128, 0)))
|
||||
@ -818,14 +823,14 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
}
|
||||
if (bannerImageUrl != null && !bannerImageUrl.equals("")) {
|
||||
glide.load(bannerImageUrl).into(mBannerImageView);
|
||||
}
|
||||
}*/
|
||||
|
||||
mAccountName = name;
|
||||
mProfileImageUrl = profileImageUrl;
|
||||
mBannerImageUrl = bannerImageUrl;
|
||||
mKarma = karma;
|
||||
|
||||
mKarmaTextView.setText(getString(R.string.karma_info, karma));
|
||||
//mKarmaTextView.setText(getString(R.string.karma_info, karma));
|
||||
|
||||
mFetchUserInfoSuccess = true;
|
||||
}
|
||||
|
@ -0,0 +1,302 @@
|
||||
package ml.docilealligator.infinityforreddit.Adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestManager;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import ml.docilealligator.infinityforreddit.Account.Account;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
|
||||
public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private static final int VIEW_TYPE_NAV_HEADER = 0;
|
||||
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_DIVIDER = 3;
|
||||
private static final int VIEW_TYPE_SUBSCRIBED_SUBREDDIT = 4;
|
||||
private static final int CURRENT_MENU_ITEMS = 15;
|
||||
|
||||
private Context context;
|
||||
private Resources resources;
|
||||
private RequestManager glide;
|
||||
private String accountName;
|
||||
private String userIconUrl;
|
||||
private String userBannerUrl;
|
||||
private int karma;
|
||||
private boolean isLoggedIn;
|
||||
private boolean isInMainPage = true;
|
||||
private ArrayList<SubscribedSubredditData> subscribedSubreddits;
|
||||
|
||||
public NavigationDrawerRecyclerViewAdapter(Context context, String accountName, String userIconUrl,
|
||||
String userBannerUrl, int karma) {
|
||||
this.context = context;
|
||||
resources = context.getResources();
|
||||
glide = Glide.with(context);
|
||||
this.accountName = accountName;
|
||||
this.userIconUrl = userIconUrl;
|
||||
this.userBannerUrl = userBannerUrl;
|
||||
this.karma = karma;
|
||||
isLoggedIn = accountName != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (isLoggedIn) {
|
||||
if (position >= 15) {
|
||||
return VIEW_TYPE_SUBSCRIBED_SUBREDDIT;
|
||||
} else if (position == 0) {
|
||||
return VIEW_TYPE_NAV_HEADER;
|
||||
} else if (position == 1 || position == 6) {
|
||||
return VIEW_TYPE_MENU_GROUP_TITLE;
|
||||
} else if (position == 12) {
|
||||
return VIEW_TYPE_DIVIDER;
|
||||
} else {
|
||||
return VIEW_TYPE_MENU_ITEM;
|
||||
}
|
||||
} else {
|
||||
if (position == 0) {
|
||||
return VIEW_TYPE_NAV_HEADER;
|
||||
} else {
|
||||
return VIEW_TYPE_MENU_ITEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
switch (viewType) {
|
||||
case VIEW_TYPE_NAV_HEADER:
|
||||
return new NavHeaderViewHolder(LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.nav_header_main, parent, false));
|
||||
case VIEW_TYPE_MENU_GROUP_TITLE:
|
||||
return new MenuGroupTitleViewHolder(LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.item_nav_drawer_menu_group_title, parent, false));
|
||||
case VIEW_TYPE_MENU_ITEM:
|
||||
return new MenuItemViewHolder(LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.item_nav_drawer_menu_item, parent, false));
|
||||
case VIEW_TYPE_DIVIDER:
|
||||
return new DividerViewHolder(LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.item_nav_drawer_divider, parent, false));
|
||||
default:
|
||||
return new SubscribedThingViewHolder(LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.item_nav_drawer_subscribed_thing, parent, false));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof NavHeaderViewHolder) {
|
||||
if (isLoggedIn) {
|
||||
((NavHeaderViewHolder) holder).karmaTextView.setText(context.getString(R.string.karma_info, karma));
|
||||
((NavHeaderViewHolder) holder).accountNameTextView.setText(accountName);
|
||||
if (userIconUrl != null && !userIconUrl.equals("")) {
|
||||
glide.load(userIconUrl)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0)))
|
||||
.error(glide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0))))
|
||||
.into(((NavHeaderViewHolder) holder).profileImageView);
|
||||
} else {
|
||||
glide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0)))
|
||||
.into(((NavHeaderViewHolder) holder).profileImageView);
|
||||
}
|
||||
|
||||
if (userBannerUrl != null && !userBannerUrl.equals("")) {
|
||||
glide.load(userBannerUrl).into(((NavHeaderViewHolder) holder).bannerImageView);
|
||||
}
|
||||
} else {
|
||||
((NavHeaderViewHolder) holder).karmaTextView.setText(R.string.press_here_to_login);
|
||||
((NavHeaderViewHolder) holder).accountNameTextView.setText(R.string.anonymous_account);
|
||||
}
|
||||
|
||||
if (isInMainPage) {
|
||||
((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_down_24px));
|
||||
} else {
|
||||
((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_up_24px));
|
||||
}
|
||||
|
||||
((NavHeaderViewHolder) holder).itemView.setOnClickListener(view -> {
|
||||
if (isInMainPage) {
|
||||
isInMainPage = false;
|
||||
((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_up_24px));
|
||||
} else {
|
||||
isInMainPage = true;
|
||||
((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_down_24px));
|
||||
}
|
||||
});
|
||||
} else if (holder instanceof MenuGroupTitleViewHolder) {
|
||||
if (position == 1) {
|
||||
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_account);
|
||||
} else if (position == 6) {
|
||||
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_post);
|
||||
}
|
||||
} else if (holder instanceof MenuItemViewHolder) {
|
||||
int stringId = 0;
|
||||
int drawableId = 0;
|
||||
|
||||
switch (position) {
|
||||
case 2:
|
||||
stringId = R.string.profile;
|
||||
drawableId = R.drawable.ic_account_circle_24dp;
|
||||
break;
|
||||
case 3:
|
||||
stringId = R.string.subscriptions;
|
||||
drawableId = R.drawable.ic_subscritptions_bottom_app_bar_24dp;
|
||||
break;
|
||||
case 4:
|
||||
stringId = R.string.multi_reddit;
|
||||
drawableId = R.drawable.ic_multi_reddit_24dp;
|
||||
break;
|
||||
case 5:
|
||||
stringId = R.string.inbox;
|
||||
drawableId = R.drawable.ic_inbox_24dp;
|
||||
break;
|
||||
case 7:
|
||||
stringId = R.string.upvoted;
|
||||
drawableId = R.drawable.ic_arrow_upward_black_24dp;
|
||||
break;
|
||||
case 8:
|
||||
stringId = R.string.downvoted;
|
||||
drawableId = R.drawable.ic_arrow_downward_black_24dp;
|
||||
break;
|
||||
case 9:
|
||||
stringId = R.string.hidden;
|
||||
drawableId = R.drawable.ic_outline_lock_24dp;
|
||||
break;
|
||||
case 10:
|
||||
stringId = R.string.saved;
|
||||
drawableId = R.drawable.ic_outline_bookmarks_24dp;
|
||||
break;
|
||||
case 11:
|
||||
stringId = R.string.gilded;
|
||||
drawableId = R.drawable.ic_star_border_24dp;
|
||||
break;
|
||||
case 13:
|
||||
if ((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
|
||||
stringId = R.string.dark_theme;
|
||||
drawableId = R.drawable.ic_dark_theme_24dp;
|
||||
} else {
|
||||
stringId = R.string.light_theme;
|
||||
drawableId = R.drawable.ic_light_theme_24dp;
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
stringId = R.string.settings;
|
||||
drawableId = R.drawable.ic_settings_24dp;
|
||||
break;
|
||||
}
|
||||
|
||||
((MenuItemViewHolder) holder).menuTextView.setText(stringId);
|
||||
((MenuItemViewHolder) holder).menuTextView.setCompoundDrawablesWithIntrinsicBounds(
|
||||
drawableId, 0, 0, 0);
|
||||
} else if (holder instanceof SubscribedThingViewHolder) {
|
||||
SubscribedSubredditData subreddit = subscribedSubreddits.get(position - CURRENT_MENU_ITEMS);
|
||||
((SubscribedThingViewHolder) holder).subredditNameTextView.setText(subreddit.getName());
|
||||
String iconUrl = subreddit.getIconUrl();
|
||||
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(((SubscribedThingViewHolder) holder).iconGifImageView);
|
||||
} else {
|
||||
glide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
.into(((SubscribedThingViewHolder) holder).iconGifImageView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (subscribedSubreddits != null) {
|
||||
return CURRENT_MENU_ITEMS + subscribedSubreddits.size();
|
||||
}
|
||||
|
||||
return CURRENT_MENU_ITEMS;
|
||||
}
|
||||
|
||||
public void setSubscribedSubreddits(List<SubscribedSubredditData> subscribedSubreddits) {
|
||||
this.subscribedSubreddits = (ArrayList<SubscribedSubredditData>) subscribedSubreddits;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void changeAccountsDataset(List<Account> accounts) {
|
||||
|
||||
}
|
||||
|
||||
class NavHeaderViewHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.name_text_view_nav_header_main)
|
||||
TextView accountNameTextView;
|
||||
@BindView(R.id.karma_text_view_nav_header_main)
|
||||
TextView karmaTextView;
|
||||
@BindView(R.id.profile_image_view_nav_header_main)
|
||||
GifImageView profileImageView;
|
||||
@BindView(R.id.banner_image_view_nav_header_main)
|
||||
ImageView bannerImageView;
|
||||
@BindView(R.id.account_switcher_image_view_nav_header_main)
|
||||
ImageView dropIconImageView;
|
||||
|
||||
public NavHeaderViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
}
|
||||
|
||||
class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView titleTextView;
|
||||
|
||||
MenuGroupTitleViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
titleTextView = (TextView) itemView;
|
||||
}
|
||||
}
|
||||
|
||||
class MenuItemViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView menuTextView;
|
||||
|
||||
MenuItemViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
menuTextView = (TextView) itemView;
|
||||
}
|
||||
}
|
||||
|
||||
class DividerViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
DividerViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
|
||||
class SubscribedThingViewHolder 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;
|
||||
|
||||
SubscribedThingViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,14 @@
|
||||
android:layout_gravity="start"
|
||||
android:background="?attr/backgroundColor">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/nav_drawer_recycler_view_main_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical"
|
||||
android:clipToPadding="false" />
|
||||
|
||||
<!--<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/nested_scroll_view_main_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@ -237,7 +244,7 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</androidx.core.widget.NestedScrollView>-->
|
||||
|
||||
</com.google.android.material.navigation.NavigationView>
|
||||
|
||||
|
5
app/src/main/res/layout/item_nav_drawer_divider.xml
Normal file
5
app/src/main/res/layout/item_nav_drawer_divider.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<View xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/dividerColor" />
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:text="@string/label_post"
|
||||
android:textSize="?attr/font_default" />
|
12
app/src/main/res/layout/item_nav_drawer_menu_item.xml
Normal file
12
app/src/main/res/layout/item_nav_drawer_menu_item.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:drawablePadding="32dp"
|
||||
android:focusable="true"
|
||||
android:gravity="center_vertical"
|
||||
android:padding="16dp"
|
||||
android:textColor="@color/primaryTextColor"
|
||||
android:textSize="?attr/font_default" />
|
27
app/src/main/res/layout/item_nav_drawer_subscribed_thing.xml
Normal file
27
app/src/main/res/layout/item_nav_drawer_subscribed_thing.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?attr/selectableItemBackground">
|
||||
|
||||
<pl.droidsonroids.gif.GifImageView
|
||||
android:id="@+id/thing_icon_gif_image_view_item_nav_drawer_subscribed_thing"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="32dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/thing_name_text_view_item_nav_drawer_subscribed_thing"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="@color/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:layout_gravity="center_vertical" />
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user