From 42c7b316f37b17178518cbf9649a788fcdf0895c Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 13 Jun 2019 12:16:04 +0800 Subject: Add CommentActivity for sending comments (not implemented yet). Minor UI tweaks. --- .idea/assetWizardSettings.xml | 4 +- .idea/caches/build_file_checksums.ser | Bin 533 -> 533 bytes .idea/caches/gradle_models.ser | Bin 254950 -> 257017 bytes app/build.gradle | 3 +- app/src/main/AndroidManifest.xml | 15 ++- .../infinityforreddit/CommentActivity.java | 127 +++++++++++++++++++++ .../infinityforreddit/CommentData.java | 57 ++++++++- .../CommentMultiLevelRecyclerViewAdapter.java | 35 +++--- .../infinityforreddit/MainActivity.java | 7 +- .../infinityforreddit/ViewPostDetailActivity.java | 33 ++++-- .../res/drawable/ic_insert_comment_white_24dp.xml | 5 + app/src/main/res/drawable/ic_send_white_24dp.xml | 5 + app/src/main/res/layout/activity_comment.xml | 56 +++++++++ .../main/res/layout/activity_view_post_detail.xml | 18 ++- app/src/main/res/menu/comment_activity.xml | 10 ++ .../main/res/menu/view_post_detail_activity.xml | 10 +- app/src/main/res/values/strings.xml | 5 + 17 files changed, 346 insertions(+), 44 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java create mode 100644 app/src/main/res/drawable/ic_insert_comment_white_24dp.xml create mode 100644 app/src/main/res/drawable/ic_send_white_24dp.xml create mode 100644 app/src/main/res/layout/activity_comment.xml create mode 100644 app/src/main/res/menu/comment_activity.xml diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml index a57d325d..9bb2c988 100644 --- a/.idea/assetWizardSettings.xml +++ b/.idea/assetWizardSettings.xml @@ -23,7 +23,7 @@ @@ -34,7 +34,7 @@ diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 10211a73..c666d71b 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser index df82cf06..03ebde54 100644 Binary files a/.idea/caches/gradle_models.ser and b/.idea/caches/gradle_models.ser differ diff --git a/app/build.gradle b/app/build.gradle index ebe6c169..e6c35e6f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,7 +33,7 @@ repositories { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'androidx.appcompat:appcompat:1.1.0-alpha05' + implementation 'androidx.appcompat:appcompat:1.1.0-beta01' implementation 'com.google.android.material:material:1.1.0-alpha07' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.legacy:legacy-support-v4:1.0.0' @@ -75,4 +75,5 @@ dependencies { implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16' implementation 'com.github.Ferfalk:SimpleSearchView:0.1.3' implementation 'org.greenrobot:eventbus:3.1.1' + implementation 'com.github.chinalwb:are:0.1.5' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e1c3adf1..a0d209a4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,17 +19,23 @@ android:supportsRtl="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true"> - + - + android:parentActivityName=".MainActivity" + android:theme="@style/AppTheme.NoActionBar" /> + @@ -47,7 +53,8 @@ android:theme="@style/AppTheme.ActionBar.Transparent" /> + android:parentActivityName=".MainActivity" + android:theme="@style/AppTheme.NoActionBar"/> CREATOR = new Creator() { + @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); diff --git a/app/src/main/res/drawable/ic_insert_comment_white_24dp.xml b/app/src/main/res/drawable/ic_insert_comment_white_24dp.xml new file mode 100644 index 00000000..8ab8d733 --- /dev/null +++ b/app/src/main/res/drawable/ic_insert_comment_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_send_white_24dp.xml b/app/src/main/res/drawable/ic_send_white_24dp.xml new file mode 100644 index 00000000..33efc5c9 --- /dev/null +++ b/app/src/main/res/drawable/ic_send_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_comment.xml b/app/src/main/res/layout/activity_comment.xml new file mode 100644 index 00000000..3beff433 --- /dev/null +++ b/app/src/main/res/layout/activity_comment.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_view_post_detail.xml b/app/src/main/res/layout/activity_view_post_detail.xml index f70949ce..1810f995 100644 --- a/app/src/main/res/layout/activity_view_post_detail.xml +++ b/app/src/main/res/layout/activity_view_post_detail.xml @@ -7,10 +7,25 @@ android:layout_height="match_parent" tools:context=".ViewPostDetailActivity"> + + + + + + + android:layout_height="wrap_content" + app:layout_behavior="@string/appbar_scrolling_view_behavior"> - \ No newline at end of file diff --git a/app/src/main/res/menu/comment_activity.xml b/app/src/main/res/menu/comment_activity.xml new file mode 100644 index 00000000..640f6a43 --- /dev/null +++ b/app/src/main/res/menu/comment_activity.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/view_post_detail_activity.xml b/app/src/main/res/menu/view_post_detail_activity.xml index c0f667f9..f5b327d8 100644 --- a/app/src/main/res/menu/view_post_detail_activity.xml +++ b/app/src/main/res/menu/view_post_detail_activity.xml @@ -1,10 +1,16 @@ + + + app:showAsAction="never" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5dd09c72..7a3985eb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,6 +2,7 @@ Infinity Login Search + Add Comment Open navigation drawer Close navigation drawer @@ -9,9 +10,11 @@ Settings Download Refresh + Add a comment Search Start Lazy Mode Stop Lazy Mode + Send Error loading image. Tap to retry. Error loading posts.\nTap to retry. @@ -68,4 +71,6 @@ Lazy Mode starts in %1$.1fs Lazy Mode stopped + Your interesting thoughts here + -- cgit v1.2.3