aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-09-17 16:21:50 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-09-17 16:21:50 +0000
commit2f27074478538206dc8cb1f762365535b9de20f0 (patch)
treef54c251e204c8f40938016b2f3328a92696ff23f /app/src/main/java
parent1fc2848813b521632d459e0a80cfc2e9d2c31451 (diff)
downloadinfinity-for-reddit-2f27074478538206dc8cb1f762365535b9de20f0.tar
infinity-for-reddit-2f27074478538206dc8cb1f762365535b9de20f0.tar.gz
infinity-for-reddit-2f27074478538206dc8cb1f762365535b9de20f0.tar.bz2
infinity-for-reddit-2f27074478538206dc8cb1f762365535b9de20f0.tar.lz
infinity-for-reddit-2f27074478538206dc8cb1f762365535b9de20f0.tar.xz
infinity-for-reddit-2f27074478538206dc8cb1f762365535b9de20f0.tar.zst
infinity-for-reddit-2f27074478538206dc8cb1f762365535b9de20f0.zip
Start implementing markdown toolbar.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MarkdownBottomBarRecyclerViewAdapter.java94
2 files changed, 109 insertions, 0 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java
index 1c171f16..2138e6b5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java
@@ -9,6 +9,7 @@ import android.os.Bundle;
import android.text.Spanned;
import android.text.style.SuperscriptSpan;
import android.text.util.Linkify;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -47,6 +48,7 @@ import io.noties.markwon.recycler.MarkwonAdapter;
import io.noties.markwon.recycler.table.TableEntry;
import io.noties.markwon.recycler.table.TableEntryPlugin;
import io.noties.markwon.simple.ext.SimpleExtPlugin;
+import ml.docilealligator.infinityforreddit.Adapter.MarkdownBottomBarRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Comment.Comment;
@@ -89,6 +91,8 @@ public class CommentActivity extends BaseActivity {
RecyclerView contentMarkdownRecyclerView;
@BindView(R.id.comment_edit_text_comment_activity)
EditText commentEditText;
+ @BindView(R.id.markdown_bottom_bar_recycler_view_comment_activity)
+ RecyclerView markdownBottomBarRecyclerView;
@Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@@ -259,6 +263,17 @@ public class CommentActivity extends BaseActivity {
setSupportActionBar(toolbar);
+ MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter(mCustomThemeWrapper, new MarkdownBottomBarRecyclerViewAdapter.ItemClickListener() {
+ @Override
+ public void onClick(int item) {
+ Log.i("asasdf", "s " + item);
+ }
+ });
+
+ markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManager(this,
+ LinearLayoutManager.HORIZONTAL, false));
+ markdownBottomBarRecyclerView.setAdapter(adapter);
+
commentEditText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MarkdownBottomBarRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MarkdownBottomBarRecyclerViewAdapter.java
new file mode 100644
index 00000000..11d06b14
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MarkdownBottomBarRecyclerViewAdapter.java
@@ -0,0 +1,94 @@
+package ml.docilealligator.infinityforreddit.Adapter;
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.R;
+
+public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+
+ public static final int BOLD = 0;
+ public static final int ITALIC = 1;
+ public static final int LINK = 2;
+ public static final int STRIKE_THROUGH = 3;
+ public static final int HEADER = 4;
+ public static final int ORDERED_LIST = 5;
+ public static final int UNORDERED_LIST = 6;
+ public static final int SPOILER = 7;
+
+ private static final int ITEM_COUNT = 8;
+
+ private CustomThemeWrapper customThemeWrapper;
+ private ItemClickListener itemClickListener;
+
+ public interface ItemClickListener {
+ void onClick(int item);
+ }
+
+ public MarkdownBottomBarRecyclerViewAdapter(CustomThemeWrapper customThemeWrapper,
+ ItemClickListener itemClickListener) {
+ this.customThemeWrapper = customThemeWrapper;
+ this.itemClickListener = itemClickListener;
+ }
+
+ @NonNull
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ return new MarkdownBottomBarItemViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_markdown_bottom_bar, parent, false));
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
+ if (holder instanceof MarkdownBottomBarItemViewHolder) {
+ switch (position) {
+ case BOLD:
+ ((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_bold_black_24dp);
+ break;
+ case ITALIC:
+ ((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_italic_black_24dp);
+ break;
+ case LINK:
+ ((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_link_round_black_24dp);
+ break;
+ case STRIKE_THROUGH:
+ ((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_strikethrough_black_24dp);
+ break;
+ case HEADER:
+ ((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_header_hashtag_black_24dp);
+ break;
+ case ORDERED_LIST:
+ ((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_ordered_list_black_24dp);
+ break;
+ case UNORDERED_LIST:
+ ((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_unordered_list_black_24dp);
+ break;
+ case SPOILER:
+ ((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_spoiler_black_24dp);
+ break;
+ }
+ }
+ }
+
+ @Override
+ public int getItemCount() {
+ return ITEM_COUNT;
+ }
+
+ class MarkdownBottomBarItemViewHolder extends RecyclerView.ViewHolder {
+ ImageView imageView;
+
+ public MarkdownBottomBarItemViewHolder(@NonNull View itemView) {
+ super(itemView);
+ imageView = (ImageView) itemView;
+ itemView.setOnClickListener(view -> itemClickListener.onClick(getAdapterPosition()));
+
+ imageView.setColorFilter(customThemeWrapper.getPrimaryIconColor(), android.graphics.PorterDuff.Mode.SRC_IN);
+ }
+ }
+}