Use FlowLayout to host all the information of a post in item_post and item_post_detail.

This commit is contained in:
Alex Ning 2019-10-28 21:17:09 +08:00
parent 8d5bf2c646
commit 3a81ca17e8
7 changed files with 116 additions and 221 deletions

View File

@ -79,5 +79,5 @@ dependencies {
annotationProcessor 'com.evernote:android-state-processor:1.4.1'
implementation 'androidx.work:work-runtime:2.2.0'
implementation 'androidx.preference:preference:1.1.0'
implementation 'org.sufficientlysecure:html-textview:3.6'
implementation 'com.nex3z:flow-layout:1.3.0'
}

View File

@ -15,7 +15,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
@ -359,7 +358,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailViewHolder) holder).mPostTimeTextView.setText(mPost.getPostTime());
if (mPost.getGilded() > 0) {
((PostDetailViewHolder) holder).mGildedImageView.setVisibility(View.VISIBLE);
((PostDetailViewHolder) holder).mGildedNumberTextView.setVisibility(View.VISIBLE);
String gildedNumber = mActivity.getResources().getString(R.string.gilded_count, mPost.getGilded());
((PostDetailViewHolder) holder).mGildedNumberTextView.setText(gildedNumber);
@ -373,10 +371,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailViewHolder) holder).mLockedImageView.setVisibility(View.VISIBLE);
}
if (mPost.isSpoiler() || mPost.getFlair() != null) {
((PostDetailViewHolder) holder).spoilerFlairlinearLayout.setVisibility(View.VISIBLE);
}
if (mPost.isSpoiler()) {
((PostDetailViewHolder) holder).spoilerTextView.setVisibility(View.VISIBLE);
}
@ -1392,7 +1386,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailViewHolder) holder).mUpvoteButton.clearColorFilter();
((PostDetailViewHolder) holder).mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor));
((PostDetailViewHolder) holder).mDownvoteButton.clearColorFilter();
((PostDetailViewHolder) holder).spoilerFlairlinearLayout.setVisibility(View.GONE);
((PostDetailViewHolder) holder).flairTextView.setVisibility(View.GONE);
((PostDetailViewHolder) holder).spoilerTextView.setVisibility(View.GONE);
((PostDetailViewHolder) holder).mNSFWTextView.setVisibility(View.GONE);
@ -1448,8 +1441,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
TextView mContentMarkdownView;
@BindView(R.id.type_text_view_item_post_detail)
CustomTextView mTypeTextView;
@BindView(R.id.gilded_image_view_item_post_detail)
ImageView mGildedImageView;
@BindView(R.id.gilded_number_text_view_item_post_detail)
TextView mGildedNumberTextView;
@BindView(R.id.crosspost_image_view_item_post_detail)
@ -1460,8 +1451,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
ImageView mLockedImageView;
@BindView(R.id.nsfw_text_view_item_post_detail)
CustomTextView mNSFWTextView;
@BindView(R.id.spoiler_flair_linear_layout_item_post_detail)
LinearLayout spoilerFlairlinearLayout;
@BindView(R.id.spoiler_custom_text_view_item_post_detail)
CustomTextView spoilerTextView;
@BindView(R.id.flair_custom_text_view_item_post_detail)

View File

@ -311,7 +311,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
if (gilded > 0) {
((DataViewHolder) holder).gildedImageView.setVisibility(View.VISIBLE);
((DataViewHolder) holder).gildedNumberTextView.setVisibility(View.VISIBLE);
String gildedNumber = mContext.getResources().getString(R.string.gilded_count, gilded);
((DataViewHolder) holder).gildedNumberTextView.setText(gildedNumber);
@ -334,10 +333,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((DataViewHolder) holder).nsfwTextView.setVisibility(View.VISIBLE);
}
if (spoiler || flair != null) {
((DataViewHolder) holder).spoilerFlairLinearLayout.setVisibility(View.VISIBLE);
}
if (spoiler) {
((DataViewHolder) holder).spoilerTextView.setVisibility(View.VISIBLE);
}
@ -776,13 +771,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mGlide.clear(((DataViewHolder) holder).iconGifImageView);
((DataViewHolder) holder).stickiedPostImageView.setVisibility(View.GONE);
((DataViewHolder) holder).relativeLayout.setVisibility(View.GONE);
((DataViewHolder) holder).gildedImageView.setVisibility(View.GONE);
((DataViewHolder) holder).gildedNumberTextView.setVisibility(View.GONE);
((DataViewHolder) holder).crosspostImageView.setVisibility(View.GONE);
((DataViewHolder) holder).archivedImageView.setVisibility(View.GONE);
((DataViewHolder) holder).lockedImageView.setVisibility(View.GONE);
((DataViewHolder) holder).nsfwTextView.setVisibility(View.GONE);
((DataViewHolder) holder).spoilerFlairLinearLayout.setVisibility(View.GONE);
((DataViewHolder) holder).spoilerTextView.setVisibility(View.GONE);
((DataViewHolder) holder).flairTextView.setVisibility(View.GONE);
((DataViewHolder) holder).linkTextView.setVisibility(View.GONE);
@ -820,8 +813,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
TextView titleTextView;
@BindView(R.id.type_text_view_item_post)
CustomTextView typeTextView;
@BindView(R.id.gilded_image_view_item_post)
ImageView gildedImageView;
@BindView(R.id.gilded_number_text_view_item_post)
TextView gildedNumberTextView;
@BindView(R.id.archived_image_view_item_post)
@ -832,8 +823,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
ImageView crosspostImageView;
@BindView(R.id.nsfw_text_view_item_post)
CustomTextView nsfwTextView;
@BindView(R.id.spoiler_flair_linear_layout_item_post)
LinearLayout spoilerFlairLinearLayout;
@BindView(R.id.spoiler_custom_text_view_item_post)
CustomTextView spoilerTextView;
@BindView(R.id.flair_custom_text_view_item_post)

View File

@ -97,6 +97,9 @@ public class AcknowledgementFragment extends Fragment {
acknowledgements.add(new Acknowledgement("Android-State",
"A utility library for Android to save objects in a Bundle without any boilerplate",
Uri.parse("https://github.com/evernote/android-state")));
acknowledgements.add(new Acknowledgement("FlowLayout",
"A FlowLayout for Android, which allows child views flow to next row when there is no enough space.",
Uri.parse("https://github.com/nex3z/FlowLayout")));
AcknowledgementRecyclerViewAdapter adapter = new AcknowledgementRecyclerViewAdapter(activity, acknowledgements);
recyclerView.setLayoutManager(new LinearLayoutManager(activity));

View File

@ -1,5 +1,5 @@
<vector android:height="16dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="16dp" xmlns:android="http://schemas.android.com/apk/res/android">
<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF3636" android:pathData="M470.191,46.036L408.754,5.824c-16.42,-10.748 -38.501,-6.19 -49.334,10.141L248.83,175.589c-2.666,3.847 -2.86,8.89 -0.497,12.931l67.332,115.201c2.184,3.737 6.135,6.208 10.463,6.233c0.029,0 0.058,0 0.087,0c4.785,0 9.487,-2.287 12.388,-6.537L480.357,95.734l0.162,-0.242C491.306,79.01 486.673,56.824 470.191,46.036z"/>
<path android:fillColor="#FF712F" android:pathData="M338.563,286.469L152.591,16.703c-5.229,-7.892 -13.204,-13.301 -22.479,-15.238c-9.342,-1.95 -18.883,-0.147 -26.867,5.079L41.808,46.757C25.326,57.546 20.694,79.732 31.482,96.214l0.112,0.172l141.293,203.513c1.582,2.279 4.139,3.687 6.911,3.805l146.445,6.251c2.932,0 5.894,-0.859 8.49,-2.649C341.544,302.611 343.259,293.281 338.563,286.469z"/>
<path android:fillColor="#FFD561" android:pathData="M383.798,384.115c0,70.514 -57.37,127.885 -127.885,127.885s-127.885,-57.37 -127.885,-127.885c0,-70.524 57.37,-127.895 127.885,-127.895S383.798,313.59 383.798,384.115z"/>

View File

@ -94,10 +94,13 @@
android:textSize="?attr/content_font_default"
android:ellipsize="end" />
<androidx.constraintlayout.widget.ConstraintLayout
<com.nex3z.flowlayout.FlowLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
android:padding="16dp"
app:flChildSpacing="16dp"
app:flChildSpacingForLastRow="align"
app:flRowSpacing="8dp">
<com.libRG.CustomTextView
android:id="@+id/type_text_view_item_post"
@ -106,110 +109,17 @@
android:padding="4dp"
android:textSize="?attr/font_12"
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lib_setRoundedBGColor="@color/backgroundColorPrimaryDark"
app:lib_setRoundedBorderColor="@color/backgroundColorPrimaryDark"
app:lib_setRadius="3dp"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
<ImageView
android:id="@+id/gilded_image_view_item_post"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="16dp"
android:src="@drawable/gold"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/type_text_view_item_post"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/gilded_number_text_view_item_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:textColor="@color/gold"
android:textSize="?attr/font_default"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/gilded_image_view_item_post"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/archived_image_view_item_post"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_archive_outline"
android:tint="@color/archivedTint"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/gilded_number_text_view_item_post"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/locked_image_view_item_post"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_outline_lock"
android:tint="@color/lockedIconTint"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/archived_image_view_item_post"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0" />
<ImageView
android:id="@+id/crosspost_image_view_item_post"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="16dp"
android:src="@drawable/crosspost"
android:tint="@color/colorAccent"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/locked_image_view_item_post"
app:layout_constraintTop_toTopOf="parent" />
<com.libRG.CustomTextView
android:id="@+id/nsfw_text_view_item_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:text="@string/nsfw"
android:textSize="?attr/font_12"
android:textColor="@android:color/white"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/crosspost_image_view_item_post"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="1"
app:lib_setRoundedBGColor="@color/colorAccent"
app:lib_setRoundedBorderColor="@color/colorAccent"
app:lib_setRadius="3dp"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:id="@+id/spoiler_flair_linear_layout_item_post"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:visibility="gone">
<com.libRG.CustomTextView
android:id="@+id/spoiler_custom_text_view_item_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="16dp"
android:text="@string/spoiler"
android:textSize="?attr/font_12"
android:textColor="@android:color/white"
@ -221,12 +131,26 @@
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
<com.libRG.CustomTextView
android:id="@+id/nsfw_text_view_item_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:text="@string/nsfw"
android:textSize="?attr/font_12"
android:textColor="@android:color/white"
android:visibility="gone"
app:lib_setRoundedBGColor="@color/colorAccent"
app:lib_setRoundedBorderColor="@color/colorAccent"
app:lib_setRadius="3dp"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
<com.libRG.CustomTextView
android:id="@+id/flair_custom_text_view_item_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="16dp"
android:textSize="?attr/font_12"
android:textColor="@android:color/white"
android:padding="4dp"
@ -237,7 +161,41 @@
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
</LinearLayout>
<TextView
android:id="@+id/gilded_number_text_view_item_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/gold"
android:textSize="?attr/font_default"
android:drawableStart="@drawable/gold"
android:drawablePadding="4dp"
android:visibility="gone" />
<ImageView
android:id="@+id/archived_image_view_item_post"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_archive_outline"
android:tint="@color/archivedTint"
android:visibility="gone" />
<ImageView
android:id="@+id/locked_image_view_item_post"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_outline_lock"
android:tint="@color/lockedIconTint"
android:visibility="gone" />
<ImageView
android:id="@+id/crosspost_image_view_item_post"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/crosspost"
android:tint="@color/colorAccent"
android:visibility="gone" />
</com.nex3z.flowlayout.FlowLayout>
<TextView
android:id="@+id/link_text_view_item_post"

View File

@ -85,10 +85,13 @@
android:visibility="gone"
android:textSize="?attr/content_font_default" />
<androidx.constraintlayout.widget.ConstraintLayout
<com.nex3z.flowlayout.FlowLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
android:padding="16dp"
app:flChildSpacing="16dp"
app:flChildSpacingForLastRow="align"
app:flRowSpacing="8dp">
<com.libRG.CustomTextView
android:id="@+id/type_text_view_item_post_detail"
@ -97,112 +100,17 @@
android:padding="4dp"
android:textSize="?attr/font_12"
android:textColor="@android:color/white"
app:chipBackgroundColor="@color/backgroundColorPrimaryDark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lib_setRoundedBGColor="@color/backgroundColorPrimaryDark"
app:lib_setRoundedBorderColor="@color/backgroundColorPrimaryDark"
app:lib_setRadius="3dp"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
<ImageView
android:id="@+id/gilded_image_view_item_post_detail"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="16dp"
android:src="@drawable/gold"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/type_text_view_item_post_detail"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/gilded_number_text_view_item_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:textColor="@color/gold"
android:textSize="?attr/font_default"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/gilded_image_view_item_post_detail"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/archived_image_view_item_post_detail"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_archive_outline"
android:tint="@color/archivedTint"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/crosspost_image_view_item_post_detail"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/locked_image_view_item_post_detail"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_outline_lock"
android:tint="@color/lockedIconTint"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/nsfw_text_view_item_post_detail"
app:layout_constraintStart_toEndOf="@+id/archived_image_view_item_post_detail"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0" />
<ImageView
android:id="@+id/crosspost_image_view_item_post_detail"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="16dp"
android:src="@drawable/crosspost"
android:tint="@color/colorAccent"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/gilded_number_text_view_item_post_detail"
app:layout_constraintTop_toTopOf="parent" />
<com.libRG.CustomTextView
android:id="@+id/nsfw_text_view_item_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:text="@string/nsfw"
android:textSize="?attr/font_12"
android:textColor="@android:color/white"
android:visibility="gone"
app:chipBackgroundColor="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="1"
app:lib_setRoundedBGColor="@color/colorAccent"
app:lib_setRoundedBorderColor="@color/colorAccent"
app:lib_setRadius="3dp"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:id="@+id/spoiler_flair_linear_layout_item_post_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:visibility="gone">
<com.libRG.CustomTextView
android:id="@+id/spoiler_custom_text_view_item_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="16dp"
android:text="@string/spoiler"
android:textSize="?attr/font_12"
android:textColor="@android:color/white"
@ -214,12 +122,26 @@
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
<com.libRG.CustomTextView
android:id="@+id/nsfw_text_view_item_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:text="@string/nsfw"
android:textSize="?attr/font_12"
android:textColor="@android:color/white"
android:visibility="gone"
app:lib_setRoundedBGColor="@color/colorAccent"
app:lib_setRoundedBorderColor="@color/colorAccent"
app:lib_setRadius="3dp"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
<com.libRG.CustomTextView
android:id="@+id/flair_custom_text_view_item_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="16dp"
android:padding="4dp"
android:textSize="?attr/font_12"
android:textColor="@android:color/white"
@ -230,7 +152,41 @@
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
</LinearLayout>
<TextView
android:id="@+id/gilded_number_text_view_item_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/gold"
android:textSize="?attr/font_default"
android:drawableStart="@drawable/gold"
android:drawablePadding="4dp"
android:visibility="gone" />
<ImageView
android:id="@+id/archived_image_view_item_post_detail"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_archive_outline"
android:tint="@color/archivedTint"
android:visibility="gone" />
<ImageView
android:id="@+id/locked_image_view_item_post_detail"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_outline_lock"
android:tint="@color/lockedIconTint"
android:visibility="gone" />
<ImageView
android:id="@+id/crosspost_image_view_item_post_detail"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/crosspost"
android:tint="@color/colorAccent"
android:visibility="gone" />
</com.nex3z.flowlayout.FlowLayout>
<TextView
android:id="@+id/link_text_view_item_post_detail"