Start implementing markdown toolbar.

This commit is contained in:
Alex Ning 2020-09-18 00:21:50 +08:00
parent 1fc2848813
commit 2f27074478
12 changed files with 246 additions and 41 deletions

View File

@ -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) {

View File

@ -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);
}
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M15.6,10.79c0.97,-0.67 1.65,-1.77 1.65,-2.79 0,-2.26 -1.75,-4 -4,-4L8,4c-0.55,0 -1,0.45 -1,1v12c0,0.55 0.45,1 1,1h5.78c2.07,0 3.96,-1.69 3.97,-3.77 0.01,-1.53 -0.85,-2.84 -2.15,-3.44zM10,6.5h3c0.83,0 1.5,0.67 1.5,1.5s-0.67,1.5 -1.5,1.5h-3v-3zM13.5,15.5L10,15.5v-3h3.5c0.83,0 1.5,0.67 1.5,1.5s-0.67,1.5 -1.5,1.5z"
android:fillColor="#000000"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="M35.4182,18.3369c-0.2456,-0.3018 -0.6104,-0.4678 -1.0273,-0.4678H31.0766l0.9194,-4.4711c0.0864,-0.4199 -0.0063,-0.8359 -0.2549,-1.1406c-0.2461,-0.3008 -0.6108,-0.4668 -1.0278,-0.4668c-0.8237,0 -1.6011,0.6435 -1.77,1.4668l-0.2498,1.2147c-0.0082,0.0305 -0.0214,0.0594 -0.0277,0.0903l-0.6794,3.3066h-5.5789l0.9194,-4.4711c0.0864,-0.4199 -0.0063,-0.8359 -0.2549,-1.1406c-0.2461,-0.3008 -0.6108,-0.4668 -1.0278,-0.4668c-0.8237,0 -1.6011,0.6435 -1.77,1.4668l-0.2601,1.2647c-0.0032,0.0137 -0.0095,0.0266 -0.0124,0.0403l-0.6799,3.3066h-3.6087c-0.8237,0 -1.6016,0.6435 -1.7705,1.4658c-0.0864,0.4209 0.0068,0.8359 0.2554,1.1406c0.2461,0.3018 0.6108,0.4668 1.0273,0.4668h3.4649l-0.9841,4.7861h-3.6087c-0.8237,0 -1.6016,0.6435 -1.7705,1.4668c-0.0864,0.4189 0.0063,0.835 0.2544,1.1387c0.2461,0.3018 0.6113,0.4678 1.0283,0.4678h3.4649l-0.9244,4.4951c-0.0864,0.4199 0.0063,0.8359 0.2549,1.1406c0.2456,0.3008 0.6108,0.4668 1.0273,0.4668c0.8237,0 1.6016,-0.6435 1.7705,-1.4668l0.9533,-4.6357h5.5824l-0.9244,4.4951c-0.0864,0.4199 0.0063,0.8359 0.2549,1.1406c0.2461,0.3008 0.6108,0.4668 1.0278,0.4668c0.8237,0 1.6011,-0.6435 1.77,-1.4668l0.9533,-4.6357h3.4666c0.8237,0 1.6016,-0.6435 1.7705,-1.4658c0.0884,-0.4287 -0.001,-0.834 -0.2515,-1.1416c-0.2451,-0.3008 -0.6113,-0.4658 -1.0308,-0.4658h-3.3229l0.9837,-4.7861h3.4666c0.8237,0 1.6016,-0.6435 1.7705,-1.4668C35.7595,19.0566 35.6667,18.6406 35.4182,18.3369zM20.7882,25.7285l0.9837,-4.7861h5.5824l-0.9841,4.7861H20.7882z"
android:fillColor="#303030"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M10,5.5c0,0.83 0.67,1.5 1.5,1.5h0.71l-3.42,8H7.5c-0.83,0 -1.5,0.67 -1.5,1.5S6.67,18 7.5,18h5c0.83,0 1.5,-0.67 1.5,-1.5s-0.67,-1.5 -1.5,-1.5h-0.71l3.42,-8h1.29c0.83,0 1.5,-0.67 1.5,-1.5S17.33,4 16.5,4h-5c-0.83,0 -1.5,0.67 -1.5,1.5z"
android:fillColor="#000000"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M17,7h-3c-0.55,0 -1,0.45 -1,1s0.45,1 1,1h3c1.65,0 3,1.35 3,3s-1.35,3 -3,3h-3c-0.55,0 -1,0.45 -1,1s0.45,1 1,1h3c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5zM8,12c0,0.55 0.45,1 1,1h6c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L9,11c-0.55,0 -1,0.45 -1,1zM10,15L7,15c-1.65,0 -3,-1.35 -3,-3s1.35,-3 3,-3h3c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L7,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5h3c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1z"
android:fillColor="#000000"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M8,7h12c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L8,5c-0.55,0 -1,0.45 -1,1s0.45,1 1,1zM20,17L8,17c-0.55,0 -1,0.45 -1,1s0.45,1 1,1h12c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1zM20,11L8,11c-0.55,0 -1,0.45 -1,1s0.45,1 1,1h12c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1zM4.5,16h-2c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5L4,17v0.5h-0.5c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5L4,18.5v0.5L2.5,19c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5h2c0.28,0 0.5,-0.22 0.5,-0.5v-3c0,-0.28 -0.22,-0.5 -0.5,-0.5zM2.5,5L3,5v2.5c0,0.28 0.22,0.5 0.5,0.5s0.5,-0.22 0.5,-0.5v-3c0,-0.28 -0.22,-0.5 -0.5,-0.5h-1c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5zM4.5,10h-2c-0.28,0 -0.5,0.22 -0.5,0.5s0.22,0.5 0.5,0.5h1.3l-1.68,1.96c-0.08,0.09 -0.12,0.21 -0.12,0.32v0.22c0,0.28 0.22,0.5 0.5,0.5h2c0.28,0 0.5,-0.22 0.5,-0.5s-0.22,-0.5 -0.5,-0.5L3.2,13l1.68,-1.96c0.08,-0.09 0.12,-0.21 0.12,-0.32v-0.22c0,-0.28 -0.22,-0.5 -0.5,-0.5z"
android:fillColor="#000000"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M4.47,21h15.06c1.54,0 2.5,-1.67 1.73,-3L13.73,4.99c-0.77,-1.33 -2.69,-1.33 -3.46,0L2.74,18c-0.77,1.33 0.19,3 1.73,3zM12,14c-0.55,0 -1,-0.45 -1,-1v-2c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v2c0,0.55 -0.45,1 -1,1zM13,18h-2v-2h2v2z"
android:fillColor="#000000"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M14.59,7.52c0,-0.31 -0.05,-0.59 -0.15,-0.85 -0.09,-0.27 -0.24,-0.49 -0.44,-0.68 -0.2,-0.19 -0.45,-0.33 -0.75,-0.44 -0.3,-0.1 -0.66,-0.16 -1.06,-0.16 -0.39,0 -0.74,0.04 -1.03,0.13s-0.53,0.21 -0.72,0.36c-0.19,0.16 -0.34,0.34 -0.44,0.55 -0.1,0.21 -0.15,0.43 -0.15,0.66 0,0.48 0.25,0.88 0.74,1.21 0.38,0.25 0.77,0.48 1.41,0.7H7.39c-0.05,-0.08 -0.11,-0.17 -0.15,-0.25 -0.26,-0.48 -0.39,-1.03 -0.39,-1.67 0,-0.61 0.13,-1.16 0.4,-1.67 0.26,-0.5 0.63,-0.93 1.11,-1.29 0.48,-0.35 1.05,-0.63 1.7,-0.83 0.66,-0.19 1.39,-0.29 2.18,-0.29 0.81,0 1.54,0.11 2.21,0.34 0.66,0.22 1.23,0.54 1.69,0.94 0.47,0.4 0.83,0.88 1.08,1.43s0.38,1.15 0.38,1.81h-3.01M20,10H4c-0.55,0 -1,0.45 -1,1s0.45,1 1,1h8.62c0.18,0.07 0.4,0.14 0.55,0.2 0.37,0.17 0.66,0.34 0.87,0.51s0.35,0.36 0.43,0.57c0.07,0.2 0.11,0.43 0.11,0.69 0,0.23 -0.05,0.45 -0.14,0.66 -0.09,0.2 -0.23,0.38 -0.42,0.53 -0.19,0.15 -0.42,0.26 -0.71,0.35 -0.29,0.08 -0.63,0.13 -1.01,0.13 -0.43,0 -0.83,-0.04 -1.18,-0.13s-0.66,-0.23 -0.91,-0.42c-0.25,-0.19 -0.45,-0.44 -0.59,-0.75s-0.25,-0.76 -0.25,-1.21H6.4c0,0.55 0.08,1.13 0.24,1.58s0.37,0.85 0.65,1.21c0.28,0.35 0.6,0.66 0.98,0.92 0.37,0.26 0.78,0.48 1.22,0.65 0.44,0.17 0.9,0.3 1.38,0.39 0.48,0.08 0.96,0.13 1.44,0.13 0.8,0 1.53,-0.09 2.18,-0.28s1.21,-0.45 1.67,-0.79c0.46,-0.34 0.82,-0.77 1.07,-1.27s0.38,-1.07 0.38,-1.71c0,-0.6 -0.1,-1.14 -0.31,-1.61 -0.05,-0.11 -0.11,-0.23 -0.17,-0.33H20c0.55,0 1,-0.45 1,-1V11c0,-0.55 -0.45,-1 -1,-1z"
android:fillColor="#000000"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M4,10.5c-0.83,0 -1.5,0.67 -1.5,1.5s0.67,1.5 1.5,1.5 1.5,-0.67 1.5,-1.5 -0.67,-1.5 -1.5,-1.5zM4,4.5c-0.83,0 -1.5,0.67 -1.5,1.5S3.17,7.5 4,7.5 5.5,6.83 5.5,6 4.83,4.5 4,4.5zM4,16.5c-0.83,0 -1.5,0.68 -1.5,1.5s0.68,1.5 1.5,1.5 1.5,-0.68 1.5,-1.5 -0.67,-1.5 -1.5,-1.5zM8,19h12c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L8,17c-0.55,0 -1,0.45 -1,1s0.45,1 1,1zM8,13h12c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L8,11c-0.55,0 -1,0.45 -1,1s0.45,1 1,1zM7,6c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L8,5c-0.55,0 -1,0.45 -1,1z"
android:fillColor="#000000"/>
</vector>

View File

@ -23,11 +23,17 @@
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -75,4 +81,13 @@
</androidx.core.widget.NestedScrollView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/markdown_bottom_bar_recycler_view_comment_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
android:layout_gravity="bottom" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:background="?actionBarItemBackground"
android:clickable="true"
android:focusable="true" />