From 7a429f902dc0e9519382032cca2da97816877b0d Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 5 Apr 2020 16:21:47 +0800 Subject: Long press a multireddit in the list to show some options. Fix some UI issues. --- .../Activity/CustomThemeListingActivity.java | 10 ++ .../Activity/LinkResolverActivity.java | 124 +++++++++++---------- .../Activity/MultiRedditListingActivity.java | 34 ++++++ .../Activity/SelectedSubredditsActivity.java | 11 ++ .../Activity/ViewMultiRedditDetailActivity.java | 37 +++--- .../CustomThemeListingRecyclerViewAdapter.java | 12 +- .../Adapter/FollowedUsersRecyclerViewAdapter.java | 2 +- .../MultiRedditListingRecyclerViewAdapter.java | 46 +++++--- .../Adapter/PostRecyclerViewAdapter.java | 2 +- .../SubredditListingRecyclerViewAdapter.java | 2 +- .../SubscribedSubredditsRecyclerViewAdapter.java | 2 +- .../Adapter/UserListingRecyclerViewAdapter.java | 2 +- .../CustomTheme/CustomThemeWrapper.java | 22 ++-- .../Event/RefreshMultiRedditsEvent.java | 4 + .../MultiRedditOptionsBottomSheetFragment.java | 70 ++++++++++++ 15 files changed, 269 insertions(+), 111 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Event/RefreshMultiRedditsEvent.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditOptionsBottomSheetFragment.java (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java index 678dee79..0a8acf90 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java @@ -103,6 +103,16 @@ public class CustomThemeListingActivity extends BaseActivity implements CustomThemeWrapper.getPredefinedThemes(this)); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(this)); + recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + if (dy > 0) { + fab.hide(); + } else if (dy < 0) { + fab.show(); + } + } + }); customThemeViewModel = new ViewModelProvider(this, new CustomThemeViewModel.Factory(redditDataRoomDatabase)) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index 18799121..92ef6064 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -71,72 +71,76 @@ public class LinkResolverActivity extends AppCompatActivity { String messageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME); String newAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); - if (path.matches(POST_PATTERN)) { - List segments = uri.getPathSegments(); - int commentsIndex = segments.lastIndexOf("comments"); - if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { - Intent intent = new Intent(this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); - intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + String authority = uri.getAuthority(); + if (authority != null && (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app"))) { + if (path.matches(POST_PATTERN)) { + List segments = uri.getPathSegments(); + int commentsIndex = segments.lastIndexOf("comments"); + if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { + Intent intent = new Intent(this, ViewPostDetailActivity.class); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else { + deepLinkError(uri); + } + } else if (path.matches(COMMENT_PATTERN)) { + List segments = uri.getPathSegments(); + int commentsIndex = segments.lastIndexOf("comments"); + if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { + Intent intent = new Intent(this, ViewPostDetailActivity.class); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, segments.get(segments.size() - 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else { + deepLinkError(uri); + } + } else if (path.matches(SUBREDDIT_PATTERN)) { + String subredditName = path.substring(3); + if (subredditName.equals("popular") || subredditName.equals("all")) { + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_POST_TYPE, subredditName); + intent.putExtra(MainActivity.EXTRA_MESSSAGE_FULLNAME, messageFullname); + intent.putExtra(MainActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else { + Intent intent = new Intent(this, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3)); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } + } else if (path.matches(USER_PATTERN_1)) { + Intent intent = new Intent(this, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(6)); + intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); startActivity(intent); - } else { - deepLinkError(uri); - } - } else if (path.matches(COMMENT_PATTERN)) { - List segments = uri.getPathSegments(); - int commentsIndex = segments.lastIndexOf("comments"); - if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { + } else if (path.matches(USER_PATTERN_2)) { + Intent intent = new Intent(this, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(3)); + intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else if (path.matches(SIDEBAR_PATTERN)) { + Intent intent = new Intent(this, ViewSidebarActivity.class); + intent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, path.substring(3, path.length() - 14)); + startActivity(intent); + } else if (path.matches(MULTIREDDIT_PATTERN)) { + Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class); + intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_PATH, path); + startActivity(intent); + } else if (path.matches(REDD_IT_POST_PATTERN)) { Intent intent = new Intent(this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); - intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, segments.get(segments.size() - 1)); - intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1)); startActivity(intent); } else { deepLinkError(uri); } - } else if (path.matches(SUBREDDIT_PATTERN)) { - String subredditName = path.substring(3); - if (subredditName.equals("popular") || subredditName.equals("all")) { - Intent intent = new Intent(this, MainActivity.class); - intent.putExtra(MainActivity.EXTRA_POST_TYPE, subredditName); - intent.putExtra(MainActivity.EXTRA_MESSSAGE_FULLNAME, messageFullname); - intent.putExtra(MainActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } else { - Intent intent = new Intent(this, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3)); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } - } else if (path.matches(USER_PATTERN_1)) { - Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(6)); - intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } else if (path.matches(USER_PATTERN_2)) { - Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(3)); - intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } else if (path.matches(SIDEBAR_PATTERN)) { - Intent intent = new Intent(this, ViewSidebarActivity.class); - intent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, path.substring(3, path.length() - 14)); - startActivity(intent); - } else if (path.matches(MULTIREDDIT_PATTERN)) { - Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class); - intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_PATH, path); - startActivity(intent); - } else if (path.matches(REDD_IT_POST_PATTERN)) { - Intent intent = new Intent(this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1)); - startActivity(intent); - } - else { + } else { deepLinkError(uri); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java index 9e0164b6..b1d2890d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java @@ -24,8 +24,11 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import org.greenrobot.eventbus.Subscribe; + import java.util.ArrayList; import javax.inject.Inject; @@ -37,7 +40,9 @@ import ml.docilealligator.infinityforreddit.Adapter.MultiRedditListingRecyclerVi import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertMultiRedditAsyncTask; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Event.RefreshMultiRedditsEvent; import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.MultiReddit.DeleteMultiReddit; import ml.docilealligator.infinityforreddit.MultiReddit.FetchMyMultiReddits; import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit; import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditViewModel; @@ -260,4 +265,33 @@ public class MultiRedditListingActivity extends BaseActivity { mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); applyFABTheme(fab); } + + public void deleteMultiReddit(MultiReddit multiReddit) { + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.delete) + .setMessage(R.string.delete_multi_reddit_dialog_message) + .setPositiveButton(R.string.delete, (dialogInterface, i) + -> DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, + mAccessToken, mAccountName, multiReddit.getPath(), new DeleteMultiReddit.DeleteMultiRedditListener() { + @Override + public void success() { + Toast.makeText(MultiRedditListingActivity.this, + R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show(); + loadMultiReddits(); + } + + @Override + public void failed() { + Toast.makeText(MultiRedditListingActivity.this, + R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show(); + } + })) + .setNegativeButton(R.string.cancel, null) + .show(); + } + + @Subscribe + public void onRefreshMultiRedditsEvent(RefreshMultiRedditsEvent event) { + loadMultiReddits(); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java index 1f1c0f8f..4e612476 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java @@ -75,6 +75,17 @@ public class SelectedSubredditsActivity extends BaseActivity { adapter = new SelectedSubredditsRecyclerViewAdapter(mCustomThemeWrapper, subreddits); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(adapter); + recyclerView.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(); + } + } + }); fab.setOnClickListener(view -> { Intent intent = new Intent(this, SubredditMultiselectionActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java index 168d7276..f1ee3a02 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java @@ -19,6 +19,8 @@ import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import org.greenrobot.eventbus.EventBus; + import javax.inject.Inject; import javax.inject.Named; @@ -26,6 +28,7 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Event.RefreshMultiRedditsEvent; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment; @@ -33,7 +36,6 @@ import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.MultiReddit.DeleteMultiReddit; -import ml.docilealligator.infinityforreddit.MultiReddit.EditMultiReddit; import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit; import ml.docilealligator.infinityforreddit.Post.PostDataSource; import ml.docilealligator.infinityforreddit.R; @@ -259,23 +261,22 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT .setTitle(R.string.delete) .setMessage(R.string.delete_multi_reddit_dialog_message) .setPositiveButton(R.string.delete, (dialogInterface, i) - -> { - DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, - mAccessToken, mAccountName, multiPath, new DeleteMultiReddit.DeleteMultiRedditListener() { - @Override - public void success() { - Toast.makeText(ViewMultiRedditDetailActivity.this, - R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show(); - finish(); - } - - @Override - public void failed() { - Toast.makeText(ViewMultiRedditDetailActivity.this, - R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show(); - } - }); - }) + -> DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, + mAccessToken, mAccountName, multiPath, new DeleteMultiReddit.DeleteMultiRedditListener() { + @Override + public void success() { + Toast.makeText(ViewMultiRedditDetailActivity.this, + R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show(); + EventBus.getDefault().post(new RefreshMultiRedditsEvent()); + finish(); + } + + @Override + public void failed() { + Toast.makeText(ViewMultiRedditDetailActivity.this, + R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show(); + } + })) .setNegativeButton(R.string.cancel, null) .show(); return true; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java index ca3fb72d..b3cbb38c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java @@ -101,6 +101,10 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< customThemeOptionsBottomSheetFragment.setArguments(bundle); customThemeOptionsBottomSheetFragment.show(activity.getSupportFragmentManager(), customThemeOptionsBottomSheetFragment.getTag()); }); + ((UserCustomThemeViewHolder) holder).itemView.setOnLongClickListener(view -> { + ((UserCustomThemeViewHolder) holder).itemView.performClick(); + return true; + }); } else if (holder instanceof PreDefinedThemeDividerViewHolder) { ((TextView) ((PreDefinedThemeDividerViewHolder) holder).itemView).setText(R.string.predefined_themes); } else if (holder instanceof UserThemeDividerViewHolder) { @@ -127,7 +131,7 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< @BindView(R.id.add_image_view_item_predefined_custom_theme) ImageView createThemeImageView; - public PredefinedCustomThemeViewHolder(@NonNull View itemView) { + PredefinedCustomThemeViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); } @@ -144,7 +148,7 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< @BindView(R.id.share_image_view_item_user_custom_theme) ImageView shareImageView; - public UserCustomThemeViewHolder(@NonNull View itemView) { + UserCustomThemeViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); } @@ -152,14 +156,14 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< class PreDefinedThemeDividerViewHolder extends RecyclerView.ViewHolder { - public PreDefinedThemeDividerViewHolder(@NonNull View itemView) { + PreDefinedThemeDividerViewHolder(@NonNull View itemView) { super(itemView); } } class UserThemeDividerViewHolder extends RecyclerView.ViewHolder { - public UserThemeDividerViewHolder(@NonNull View itemView) { + UserThemeDividerViewHolder(@NonNull View itemView) { super(itemView); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java index 23f73a7c..dd5c8be1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java @@ -54,7 +54,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter= 0 && mMultiReddits.size() > position) { mMultiReddits.get(position).setFavorite(true); @@ -161,7 +163,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< @Override public void failed() { - Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); int position = holder.getAdapterPosition() - offset; if(position >= 0 && mMultiReddits.size() > position) { mMultiReddits.get(position).setFavorite(false); @@ -173,9 +175,14 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< } }); holder.itemView.setOnClickListener(view -> { - Intent intent = new Intent(mContext, ViewMultiRedditDetailActivity.class); + Intent intent = new Intent(mActivity, ViewMultiRedditDetailActivity.class); intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_DATA, multiReddit); - mContext.startActivity(intent); + mActivity.startActivity(intent); + }); + + holder.itemView.setOnLongClickListener(view -> { + showOptionsBottomSheetFragment(multiReddit); + return true; }); if (iconUrl != null && !iconUrl.equals("")) { @@ -218,7 +225,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< @Override public void failed() { - Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); int position = holder.getAdapterPosition() - 1; if(position >= 0 && mFavoriteMultiReddits.size() > position) { mFavoriteMultiReddits.get(position).setFavorite(true); @@ -244,7 +251,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< @Override public void failed() { - Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); int position = holder.getAdapterPosition() - 1; if(position >= 0 && mFavoriteMultiReddits.size() > position) { mFavoriteMultiReddits.get(position).setFavorite(false); @@ -256,9 +263,14 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< } }); holder.itemView.setOnClickListener(view -> { - Intent intent = new Intent(mContext, ViewMultiRedditDetailActivity.class); + Intent intent = new Intent(mActivity, ViewMultiRedditDetailActivity.class); intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_DATA, multiReddit); - mContext.startActivity(intent); + mActivity.startActivity(intent); + }); + + holder.itemView.setOnLongClickListener(view -> { + showOptionsBottomSheetFragment(multiReddit); + return true; }); if (iconUrl != null && !iconUrl.equals("")) { @@ -298,6 +310,14 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< } } + private void showOptionsBottomSheetFragment(MultiReddit multiReddit) { + MultiRedditOptionsBottomSheetFragment fragment = new MultiRedditOptionsBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putParcelable(MultiRedditOptionsBottomSheetFragment.EXTRA_MULTI_REDDIT, multiReddit); + fragment.setArguments(bundle); + fragment.show(mActivity.getSupportFragmentManager(), fragment.getTag()); + } + public void setMultiReddits(List multiReddits) { mMultiReddits = multiReddits; notifyDataSetChanged(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index e3b935b5..e6203992 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -198,7 +198,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + Intent editIntent = new Intent(multiRedditListingActivity, EditMultiRedditActivity.class); + editIntent.putExtra(EditMultiRedditActivity.EXTRA_MULTI_REDDIT, multiReddit); + startActivity(editIntent); + dismiss(); + }); + + deleteMultiRedditTextView.setOnClickListener(view -> { + multiRedditListingActivity.deleteMultiReddit(multiReddit); + dismiss(); + }); + + return rootView; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + multiRedditListingActivity = (MultiRedditListingActivity) context; + } +} -- cgit v1.2.3