diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-02-19 05:53:59 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-02-19 05:53:59 +0000 |
commit | 61cc6089faea9d66ee8e8149f0d10c8a17b1676a (patch) | |
tree | 76e8151d92cdb441ae8c874ef9bcb5d71815a4b1 /app/src/main/java/ml/docilealligator | |
parent | 248aca0fb9f64eb66ec6214f60f51be3de181899 (diff) | |
download | infinity-for-reddit-61cc6089faea9d66ee8e8149f0d10c8a17b1676a.tar infinity-for-reddit-61cc6089faea9d66ee8e8149f0d10c8a17b1676a.tar.gz infinity-for-reddit-61cc6089faea9d66ee8e8149f0d10c8a17b1676a.tar.bz2 infinity-for-reddit-61cc6089faea9d66ee8e8149f0d10c8a17b1676a.tar.lz infinity-for-reddit-61cc6089faea9d66ee8e8149f0d10c8a17b1676a.tar.xz infinity-for-reddit-61cc6089faea9d66ee8e8149f0d10c8a17b1676a.tar.zst infinity-for-reddit-61cc6089faea9d66ee8e8149f0d10c8a17b1676a.zip |
Implemented ItemClickListener for the nav drawer.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
2 files changed, 93 insertions, 5 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 4480124a..eba098b1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -22,6 +22,7 @@ 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; @@ -93,6 +94,9 @@ import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUse import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; 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 { @@ -497,7 +501,75 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb fab.setVisibility(View.VISIBLE); } - adapter = new NavigationDrawerRecyclerViewAdapter(this, mAccountName, mProfileImageUrl, mBannerImageUrl, mKarma); + adapter = new NavigationDrawerRecyclerViewAdapter(this, mAccountName, mProfileImageUrl, + mBannerImageUrl, mKarma, new NavigationDrawerRecyclerViewAdapter.ItemClickListener() { + @Override + public void onMenuClick(int stringId) { + Intent intent = null; + switch (stringId) { + case R.string.profile: + intent = new Intent(MainActivity.this, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName); + break; + case R.string.subscriptions: + intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); + break; + case R.string.multi_reddit: + intent = new Intent(MainActivity.this, MultiRedditListingActivity.class); + break; + case R.string.inbox: + intent = new Intent(MainActivity.this, ViewMessageActivity.class); + break; + case R.string.upvoted: + intent = new Intent(MainActivity.this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_UPVOTED); + break; + case R.string.downvoted: + intent = new Intent(MainActivity.this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_DOWNVOTED); + break; + case R.string.hidden: + intent = new Intent(MainActivity.this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_HIDDEN); + break; + case R.string.saved: + intent = new Intent(MainActivity.this, AccountSavedThingActivity.class); + break; + case R.string.gilded: + intent = new Intent(MainActivity.this, AccountPostsActivity.class); + intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_GILDED); + break; + case R.string.light_theme: + mSharedPreferences.edit().putString(SharedPreferencesUtils.THEME_KEY, "1").apply(); + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { + getTheme().applyStyle(R.style.Theme_Default_AmoledDark, true); + } else { + getTheme().applyStyle(R.style.Theme_Default_NormalDark, true); + } + break; + case R.string.dark_theme: + mSharedPreferences.edit().putString(SharedPreferencesUtils.THEME_KEY, "0").apply(); + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + getTheme().applyStyle(R.style.Theme_Default, true); + break; + case R.string.settings: + intent = new Intent(MainActivity.this, SettingsActivity.class); + + } + if (intent != null) { + startActivity(intent); + } + drawer.closeDrawers(); + } + + @Override + public void onSubscribedSubredditClick(String subredditName) { + Intent intent = new Intent(MainActivity.this, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName); + startActivity(intent); + } + }); navDrawerRecyclerView.setLayoutManager(new LinearLayoutManager(this)); navDrawerRecyclerView.setAdapter(adapter); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java index 63069e9e..2d6cd5bd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java @@ -28,6 +28,11 @@ import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.Subscrib import pl.droidsonroids.gif.GifImageView; public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + public interface ItemClickListener { + void onMenuClick(int stringId); + void onSubscribedSubredditClick(String subredditName); + } + 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; @@ -42,12 +47,14 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re private String userIconUrl; private String userBannerUrl; private int karma; + private ItemClickListener itemClickListener; private boolean isLoggedIn; private boolean isInMainPage = true; private ArrayList<SubscribedSubredditData> subscribedSubreddits; + private ArrayList<Account> accounts; public NavigationDrawerRecyclerViewAdapter(Context context, String accountName, String userIconUrl, - String userBannerUrl, int karma) { + String userBannerUrl, int karma, ItemClickListener itemClickListener) { this.context = context; resources = context.getResources(); glide = Glide.with(context); @@ -56,6 +63,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re this.userBannerUrl = userBannerUrl; this.karma = karma; isLoggedIn = accountName != null; + this.itemClickListener = itemClickListener; } @Override @@ -209,10 +217,13 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re ((MenuItemViewHolder) holder).menuTextView.setText(stringId); ((MenuItemViewHolder) holder).menuTextView.setCompoundDrawablesWithIntrinsicBounds( drawableId, 0, 0, 0); + int finalStringId = stringId; + ((MenuItemViewHolder) holder).itemView.setOnClickListener(view -> itemClickListener.onMenuClick(finalStringId)); } else if (holder instanceof SubscribedThingViewHolder) { SubscribedSubredditData subreddit = subscribedSubreddits.get(position - CURRENT_MENU_ITEMS); - ((SubscribedThingViewHolder) holder).subredditNameTextView.setText(subreddit.getName()); + String subredditName = subreddit.getName(); String iconUrl = subreddit.getIconUrl(); + ((SubscribedThingViewHolder) holder).subredditNameTextView.setText(subredditName); if (iconUrl != null && !iconUrl.equals("")) { glide.load(iconUrl) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) @@ -224,6 +235,10 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .into(((SubscribedThingViewHolder) holder).iconGifImageView); } + + ((SubscribedThingViewHolder) holder).itemView.setOnClickListener(view -> { + itemClickListener.onSubscribedSubredditClick(subredditName); + }); } } @@ -242,7 +257,8 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re } public void changeAccountsDataset(List<Account> accounts) { - + this.accounts = (ArrayList<Account>) accounts; + notifyDataSetChanged(); } class NavHeaderViewHolder extends RecyclerView.ViewHolder { @@ -257,7 +273,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re @BindView(R.id.account_switcher_image_view_nav_header_main) ImageView dropIconImageView; - public NavHeaderViewHolder(@NonNull View itemView) { + NavHeaderViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); } |