diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-06-13 04:16:04 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-06-13 04:16:04 +0000 |
commit | 42c7b316f37b17178518cbf9649a788fcdf0895c (patch) | |
tree | 907e829a37a3534691f968179a7d8d43af91329d /app/src/main/java | |
parent | ef8daed5714cd02f57774c86aab6bd0ca454fcb7 (diff) | |
download | infinity-for-reddit-42c7b316f37b17178518cbf9649a788fcdf0895c.tar infinity-for-reddit-42c7b316f37b17178518cbf9649a788fcdf0895c.tar.gz infinity-for-reddit-42c7b316f37b17178518cbf9649a788fcdf0895c.tar.bz2 infinity-for-reddit-42c7b316f37b17178518cbf9649a788fcdf0895c.tar.lz infinity-for-reddit-42c7b316f37b17178518cbf9649a788fcdf0895c.tar.xz infinity-for-reddit-42c7b316f37b17178518cbf9649a788fcdf0895c.tar.zst infinity-for-reddit-42c7b316f37b17178518cbf9649a788fcdf0895c.zip |
Add CommentActivity for sending comments (not implemented yet). Minor UI tweaks.
Diffstat (limited to '')
5 files changed, 226 insertions, 33 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java new file mode 100644 index 00000000..0e885b80 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java @@ -0,0 +1,127 @@ +package ml.docilealligator.infinityforreddit; + +import android.content.Intent; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.chinalwb.are.AREditText; +import com.chinalwb.are.styles.toolbar.IARE_Toolbar; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_AlignmentCenter; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_AlignmentLeft; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_AlignmentRight; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_At; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Bold; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Hr; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Image; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Italic; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Link; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_ListBullet; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_ListNumber; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Quote; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Strikethrough; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Subscript; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Superscript; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Underline; +import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Video; +import com.chinalwb.are.styles.toolitems.IARE_ToolItem; + +import butterknife.BindView; +import butterknife.ButterKnife; + +public class CommentActivity extends AppCompatActivity { + + static final String COMMENT_PARENT_TEXT = "CPT"; + static final String EXTRA_COMMENT_DATA = "ECD"; + static final int WRITE_COMMENT_REQUEST_CODE = 1; + + @BindView(R.id.toolbar_comment_activity) Toolbar toolbar; + @BindView(R.id.comment_parent_text_view_comment_activity) TextView commentParentTextView; + @BindView(R.id.arEditText) AREditText commentEditor; + @BindView(R.id.areToolbar) IARE_Toolbar editorToolbar; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_comment); + + ButterKnife.bind(this); + + setSupportActionBar(toolbar); + + commentParentTextView.setText(getIntent().getExtras().getString(COMMENT_PARENT_TEXT)); + + commentEditor.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + + initToolbar(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.comment_activity, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + case R.id.action_send_comment_activity: + CommentData commentData = null; + Intent returnIntent = new Intent(); + returnIntent.putExtra(EXTRA_COMMENT_DATA, commentData); + setResult(RESULT_OK, returnIntent); + } + return super.onOptionsItemSelected(item); + } + + private void initToolbar() { + IARE_ToolItem bold = new ARE_ToolItem_Bold(); + IARE_ToolItem italic = new ARE_ToolItem_Italic(); + IARE_ToolItem underline = new ARE_ToolItem_Underline(); + IARE_ToolItem strikethrough = new ARE_ToolItem_Strikethrough(); + IARE_ToolItem quote = new ARE_ToolItem_Quote(); + IARE_ToolItem listNumber = new ARE_ToolItem_ListNumber(); + IARE_ToolItem listBullet = new ARE_ToolItem_ListBullet(); + IARE_ToolItem hr = new ARE_ToolItem_Hr(); + IARE_ToolItem link = new ARE_ToolItem_Link(); + IARE_ToolItem subscript = new ARE_ToolItem_Subscript(); + IARE_ToolItem superscript = new ARE_ToolItem_Superscript(); + IARE_ToolItem left = new ARE_ToolItem_AlignmentLeft(); + IARE_ToolItem center = new ARE_ToolItem_AlignmentCenter(); + IARE_ToolItem right = new ARE_ToolItem_AlignmentRight(); + IARE_ToolItem image = new ARE_ToolItem_Image(); + IARE_ToolItem video = new ARE_ToolItem_Video(); + IARE_ToolItem at = new ARE_ToolItem_At(); + editorToolbar.addToolbarItem(bold); + editorToolbar.addToolbarItem(italic); + editorToolbar.addToolbarItem(underline); + editorToolbar.addToolbarItem(strikethrough); + editorToolbar.addToolbarItem(quote); + editorToolbar.addToolbarItem(listNumber); + editorToolbar.addToolbarItem(listBullet); + editorToolbar.addToolbarItem(hr); + editorToolbar.addToolbarItem(link); + editorToolbar.addToolbarItem(subscript); + editorToolbar.addToolbarItem(superscript); + editorToolbar.addToolbarItem(left); + editorToolbar.addToolbarItem(center); + editorToolbar.addToolbarItem(right); + editorToolbar.addToolbarItem(image); + editorToolbar.addToolbarItem(video); + editorToolbar.addToolbarItem(at); + + commentEditor.setToolbar(editorToolbar); + + /*setHtml(); + + initToolbarArrow();*/ + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java index ec8befee..57e95bae 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java @@ -1,8 +1,11 @@ package ml.docilealligator.infinityforreddit; +import android.os.Parcel; +import android.os.Parcelable; + import com.multilevelview.models.RecyclerViewItem; -class CommentData extends RecyclerViewItem { +class CommentData extends RecyclerViewItem implements Parcelable { private String id; private String fullName; private String author; @@ -35,6 +38,36 @@ class CommentData extends RecyclerViewItem { this.scoreHidden = scoreHidden; } + protected CommentData(Parcel in) { + super(0); + id = in.readString(); + fullName = in.readString(); + author = in.readString(); + commentTime = in.readString(); + commentContent = in.readString(); + score = in.readInt(); + voteType = in.readInt(); + isSubmitter = in.readByte() != 0; + permalink = in.readString(); + depth = in.readInt(); + collapsed = in.readByte() != 0; + hasReply = in.readByte() != 0; + scoreHidden = in.readByte() != 0; + super.setLevel(depth); + } + + public static final Creator<CommentData> CREATOR = new Creator<CommentData>() { + @Override + public CommentData createFromParcel(Parcel in) { + return new CommentData(in); + } + + @Override + public CommentData[] newArray(int size) { + return new CommentData[size]; + } + }; + public String getId() { return id; } @@ -98,4 +131,26 @@ class CommentData extends RecyclerViewItem { public void setVoteType(int voteType) { this.voteType = voteType; } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(id); + parcel.writeString(fullName); + parcel.writeString(author); + parcel.writeString(commentTime); + parcel.writeString(commentContent); + parcel.writeInt(score); + parcel.writeInt(voteType); + parcel.writeByte((byte) (isSubmitter ? 1 : 0)); + parcel.writeString(permalink); + parcel.writeInt(depth); + parcel.writeByte((byte) (collapsed ? 1 : 0)); + parcel.writeByte((byte) (hasReply ? 1 : 0)); + parcel.writeByte((byte) (scoreHidden ? 1 : 0)); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java index 6191b334..10a89be2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java @@ -258,6 +258,11 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter { notifyItemRangeInserted(sizeBefore, mCommentData.size() - sizeBefore); } + void addComment(CommentData comment) { + mCommentData.add(0, comment); + notifyItemInserted(0); + } + private void setExpandButton(ImageView expandButton, boolean isExpanded) { // set the icon based on the current state expandButton.setVisibility(View.VISIBLE); @@ -265,26 +270,16 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter { } class CommentViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.author_text_view_item_post_comment) - TextView authorTextView; - @BindView(R.id.comment_time_text_view_item_post_comment) - TextView commentTimeTextView; - @BindView(R.id.comment_markdown_view_item_post_comment) - MarkwonView commentMarkdownView; - @BindView(R.id.plus_button_item_post_comment) - ImageView upvoteButton; - @BindView(R.id.score_text_view_item_post_comment) - TextView scoreTextView; - @BindView(R.id.minus_button_item_post_comment) - ImageView downvoteButton; - @BindView(R.id.expand_button_item_post_comment) - ImageView expandButton; - @BindView(R.id.load_more_comments_progress_bar) - ProgressBar loadMoreCommentsProgressBar; - @BindView(R.id.reply_button_item_post_comment) - ImageView replyButton; - @BindView(R.id.vertical_block_item_post_comment) - View verticalBlock; + @BindView(R.id.author_text_view_item_post_comment) TextView authorTextView; + @BindView(R.id.comment_time_text_view_item_post_comment) TextView commentTimeTextView; + @BindView(R.id.comment_markdown_view_item_post_comment) MarkwonView commentMarkdownView; + @BindView(R.id.plus_button_item_post_comment) ImageView upvoteButton; + @BindView(R.id.score_text_view_item_post_comment) TextView scoreTextView; + @BindView(R.id.minus_button_item_post_comment) ImageView downvoteButton; + @BindView(R.id.expand_button_item_post_comment) ImageView expandButton; + @BindView(R.id.load_more_comments_progress_bar) ProgressBar loadMoreCommentsProgressBar; + @BindView(R.id.reply_button_item_post_comment) ImageView replyButton; + @BindView(R.id.vertical_block_item_post_comment) View verticalBlock; CommentViewHolder(View itemView) { super(itemView); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java index 0192acea..57f44cc3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java @@ -382,10 +382,13 @@ public class MainActivity extends AppCompatActivity { if (mFragment instanceof FragmentCommunicator) { switch (item.getItemId()) { case R.id.action_refresh_main_activity: - ((FragmentCommunicator) mFragment).refresh(); + /*((FragmentCommunicator) mFragment).refresh(); mFetchUserInfoSuccess = false; mInsertSuccess = false; - loadUserData(); + loadUserData();*/ + Intent intent = new Intent(this, CommentActivity.class); + intent.putExtra(CommentActivity.EXTRA_COMMENT_DATA, "asdfasdfas"); + startActivity(intent); return true; case R.id.action_lazy_mode_main_activity: MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_main_activity); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 2196b783..ea8e8b4c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -5,7 +5,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.ColorFilter; import android.graphics.PorterDuff; -import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; @@ -19,9 +18,10 @@ import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.browser.customtabs.CustomTabsIntent; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; @@ -64,6 +64,9 @@ import retrofit2.Retrofit; import ru.noties.markwon.SpannableConfiguration; import ru.noties.markwon.view.MarkwonView; +import static ml.docilealligator.infinityforreddit.CommentActivity.EXTRA_COMMENT_DATA; +import static ml.docilealligator.infinityforreddit.CommentActivity.WRITE_COMMENT_REQUEST_CODE; + public class ViewPostDetailActivity extends AppCompatActivity { static final String EXTRA_TITLE = "ET"; @@ -91,6 +94,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { private LoadSubredditIconAsyncTask mLoadSubredditIconAsyncTask; @BindView(R.id.coordinator_layout_view_post_detail) CoordinatorLayout mCoordinatorLayout; + @BindView(R.id.toolbar_view_post_detail_activity) Toolbar toolbar; @BindView(R.id.nested_scroll_view_view_post_detail_activity) NestedScrollView mNestedScrollView; @BindView(R.id.subreddit_icon_name_linear_layout_view_post_detail) LinearLayout mSubredditIconNameLinearLayout; @BindView(R.id.subreddit_icon_circle_image_view_view_post_detail) AspectRatioGifImageView mSubredditIconGifImageView; @@ -105,22 +109,18 @@ public class ViewPostDetailActivity extends AppCompatActivity { @BindView(R.id.nsfw_text_view_view_post_detail) Chip mNSFWChip; @BindView(R.id.link_text_view_view_post_detail) TextView linkTextView; @BindView(R.id.image_view_wrapper_view_post_detail) RelativeLayout mRelativeLayout; - @BindView(R.id.load_wrapper_view_post_detail) RelativeLayout mLoadWrapper; @BindView(R.id.progress_bar_view_post_detail) ProgressBar mLoadImageProgressBar; @BindView(R.id.load_image_error_text_view_view_post_detail) TextView mLoadImageErrorTextView; @BindView(R.id.image_view_view_post_detail) AspectRatioImageView mImageView; @BindView(R.id.image_view_no_preview_link_view_post_detail) ImageView mNoPreviewLinkImageView; - @BindView(R.id.plus_button_view_post_detail) ImageView mUpvoteButton; @BindView(R.id.score_text_view_view_post_detail) TextView mScoreTextView; @BindView(R.id.minus_button_view_post_detail) ImageView mDownvoteButton; @BindView(R.id.share_button_view_post_detail) ImageView mShareButton; - @BindView(R.id.comment_progress_bar_view_post_detail) CircleProgressBar mCommentProgressbar; @BindView(R.id.comment_card_view_view_post_detail) MaterialCardView mCommentCardView; @BindView(R.id.recycler_view_view_post_detail) MultiLevelRecyclerView mRecyclerView; - @BindView(R.id.no_comment_wrapper_linear_layout_view_post_detail) LinearLayout mNoCommentWrapperLinearLayout; @BindView(R.id.no_comment_image_view_view_post_detail) ImageView mNoCommentImageView; @@ -144,9 +144,8 @@ public class ViewPostDetailActivity extends AppCompatActivity { ((Infinity) getApplication()).getmAppComponent().inject(this); - ActionBar actionBar = getSupportActionBar(); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); + toolbar.setTitle(""); + setSupportActionBar(toolbar); mGlide = Glide.with(this); mLocale = getResources().getConfiguration().locale; @@ -684,6 +683,11 @@ public class ViewPostDetailActivity extends AppCompatActivity { case R.id.action_refresh_view_post_detail_activity: refresh(); return true; + case R.id.action_comment_view_post_detail_activity: + Intent intent = new Intent(this, CommentActivity.class); + intent.putExtra(CommentActivity.COMMENT_PARENT_TEXT, mPost.getTitle()); + startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE); + return true; case android.R.id.home: onBackPressed(); return true; @@ -692,7 +696,16 @@ public class ViewPostDetailActivity extends AppCompatActivity { } @Override - protected void onSaveInstanceState(Bundle outState) { + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if(resultCode == RESULT_OK && requestCode == WRITE_COMMENT_REQUEST_CODE) { + CommentData comment = data.getExtras().getParcelable(EXTRA_COMMENT_DATA); + mAdapter.addComment(comment); + } + } + + @Override + protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(ORIENTATION_STATE, orientation); outState.putParcelable(POST_STATE, mPost); |