Add an option in MarkdownBottomBarRecyclerViewAdapter to upload images.

This commit is contained in:
Alex Ning 2021-07-04 09:20:36 +08:00
parent f33dfd288a
commit 91ae3f9610
5 changed files with 66 additions and 14 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -29,14 +29,16 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
public static final int SPOILER = 7;
public static final int QUOTE = 8;
public static final int CODE_BLOCK = 9;
public static final int UPLOAD_IMAGE = 10;
private static final int ITEM_COUNT = 10;
private static final int ITEM_COUNT = 11;
private CustomThemeWrapper customThemeWrapper;
private ItemClickListener itemClickListener;
public interface ItemClickListener {
void onClick(int item);
void onUploadImage();
}
public MarkdownBottomBarRecyclerViewAdapter(CustomThemeWrapper customThemeWrapper,
@ -85,6 +87,9 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
case CODE_BLOCK:
((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_code_24dp);
break;
case UPLOAD_IMAGE:
((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_image_24dp);
break;
}
}
}
@ -289,7 +294,14 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
public MarkdownBottomBarItemViewHolder(@NonNull View itemView) {
super(itemView);
imageView = (ImageView) itemView;
itemView.setOnClickListener(view -> 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);
}