From 91ae3f9610cb97407bc23c2742fd4a991b681524 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 4 Jul 2021 09:20:36 +0800 Subject: [PATCH] Add an option in MarkdownBottomBarRecyclerViewAdapter to upload images. --- .../activities/CommentActivity.java | 14 ++++++++++-- .../activities/EditCommentActivity.java | 22 ++++++++++++++----- .../activities/EditPostActivity.java | 14 ++++++++++-- .../activities/PostTextActivity.java | 14 ++++++++++-- .../MarkdownBottomBarRecyclerViewAdapter.java | 16 ++++++++++++-- 5 files changed, 66 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java index 30811e2f..8bfd09dc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -236,8 +236,18 @@ public class CommentActivity extends BaseActivity { setSupportActionBar(toolbar); - MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter(mCustomThemeWrapper, item -> { - MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener(this, commentEditText, item); + MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter( + mCustomThemeWrapper, new MarkdownBottomBarRecyclerViewAdapter.ItemClickListener() { + @Override + public void onClick(int item) { + MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener( + CommentActivity.this, commentEditText, item); + } + + @Override + public void onUploadImage() { + + } }); markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManager(this, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java index 07c0c2af..8cd3d646 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java @@ -32,12 +32,12 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -109,8 +109,18 @@ public class EditCommentActivity extends BaseActivity { mCommentContent = getIntent().getStringExtra(EXTRA_CONTENT); contentEditText.setText(mCommentContent); - MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter(mCustomThemeWrapper, item -> { - MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener(this, contentEditText, item); + MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter( + mCustomThemeWrapper, new MarkdownBottomBarRecyclerViewAdapter.ItemClickListener() { + @Override + public void onClick(int item) { + MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener( + EditCommentActivity.this, contentEditText, item); + } + + @Override + public void onUploadImage() { + + } }); markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManager(this, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java index 5c8ea02f..f6573507 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java @@ -117,8 +117,18 @@ public class EditPostActivity extends BaseActivity { mPostContent = getIntent().getStringExtra(EXTRA_CONTENT); contentEditText.setText(mPostContent); - MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter(mCustomThemeWrapper, item -> { - MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener(this, contentEditText, item); + MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter( + mCustomThemeWrapper, new MarkdownBottomBarRecyclerViewAdapter.ItemClickListener() { + @Override + public void onClick(int item) { + MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener( + EditPostActivity.this, contentEditText, item); + } + + @Override + public void onUploadImage() { + + } }); markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManager(this, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java index 7d93fef7..1d256f00 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java @@ -310,8 +310,18 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr } }); - MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter(mCustomThemeWrapper, item -> { - MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener(this, contentEditText, item); + MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter( + mCustomThemeWrapper, new MarkdownBottomBarRecyclerViewAdapter.ItemClickListener() { + @Override + public void onClick(int item) { + MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener( + PostTextActivity.this, contentEditText, item); + } + + @Override + public void onUploadImage() { + + } }); markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManager(this, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java index b7057106..fec4d3c2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java @@ -29,14 +29,16 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter itemClickListener.onClick(getAdapterPosition())); + itemView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position == UPLOAD_IMAGE) { + itemClickListener.onUploadImage(); + } else { + itemClickListener.onClick(position); + } + }); imageView.setColorFilter(customThemeWrapper.getPrimaryIconColor(), android.graphics.PorterDuff.Mode.SRC_IN); }