add decoration

This commit is contained in:
Thomas 2020-11-27 11:38:36 +01:00
parent a02b8b79c1
commit 720c13fa2d
3 changed files with 19 additions and 118 deletions

View File

@ -40,7 +40,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.PopupMenu;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider;
@ -67,9 +66,6 @@ import es.dmoral.toasty.Toasty;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.MUTE;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPLY;
import static app.fedilab.fedilabtube.helper.CommentDecorationHelper.allDecoration;
import static app.fedilab.fedilabtube.helper.CommentDecorationHelper.hideDecoration;
import static app.fedilab.fedilabtube.helper.CommentDecorationHelper.topDecorationOnly;
public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -127,21 +123,19 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
return;
holder.binding.mainContainer.setTag(i);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams((int) Helper.convertDpToPixel(20, context), LinearLayout.LayoutParams.MATCH_PARENT);
holder.binding.decorationContainer.removeAllViews();
if (comment.isReply()) {
int ident = CommentDecorationHelper.getIndentation(comment.getInReplyToCommentId(), comments);
if (CommentDecorationHelper.hasReplies(comment.getId(), comments)) {
allDecoration(holder.binding);
} else {
topDecorationOnly(holder.binding);
for (int j = 0; j <= ident; j++) {
View view = new View(context);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(1, LinearLayout.LayoutParams.MATCH_PARENT);
params.setMargins((int) Helper.convertDpToPixel(5, context), 0, 0, 0);
view.setBackgroundResource(R.color.colorAccent);
view.setLayoutParams(params);
holder.binding.decorationContainer.addView(view, 0);
}
params.setMargins((int) Helper.convertDpToPixel(ident * 20, context), 0, 0, 0);
} else {
hideDecoration(holder.binding);
params.setMargins(0, 0, 0, 0);
}
holder.binding.decorationContainer.setLayoutParams(params);
holder.binding.moreActions.setOnClickListener(view -> {
PopupMenu popup = new PopupMenu(context, holder.binding.moreActions);
popup.getMenuInflater()

View File

@ -14,12 +14,9 @@ package app.fedilab.fedilabtube.helper;
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
* see <http://www.gnu.org/licenses>. */
import android.view.View;
import java.util.List;
import app.fedilab.fedilabtube.client.data.CommentData;
import app.fedilab.fedilabtube.databinding.DrawerCommentBinding;
public class CommentDecorationHelper {
@ -27,6 +24,7 @@ public class CommentDecorationHelper {
return numberOfIndentation(0, replyToCommentId, comments);
}
private static int numberOfIndentation(int currentIdentation, String replyToCommentId, List<CommentData.Comment> comments) {
String targetedComment = null;
@ -40,40 +38,8 @@ public class CommentDecorationHelper {
currentIdentation++;
return numberOfIndentation(currentIdentation, targetedComment, comments);
} else {
return Math.min(currentIdentation, 5);
return Math.min(currentIdentation, 15);
}
}
public static void topDecorationOnly(DrawerCommentBinding binding) {
binding.decorationTop.setVisibility(View.VISIBLE);
binding.decorationCurvedTop.setVisibility(View.VISIBLE);
binding.decorationCurvedBottom.setVisibility(View.GONE);
binding.decorationCurvedLine.setVisibility(View.VISIBLE);
binding.decorationBottom.setVisibility(View.GONE);
}
public static void allDecoration(DrawerCommentBinding binding) {
binding.decorationTop.setVisibility(View.VISIBLE);
binding.decorationCurvedTop.setVisibility(View.VISIBLE);
binding.decorationCurvedBottom.setVisibility(View.VISIBLE);
binding.decorationCurvedLine.setVisibility(View.VISIBLE);
binding.decorationBottom.setVisibility(View.VISIBLE);
}
public static void hideDecoration(DrawerCommentBinding binding) {
binding.decorationTop.setVisibility(View.GONE);
binding.decorationCurvedTop.setVisibility(View.GONE);
binding.decorationCurvedBottom.setVisibility(View.GONE);
binding.decorationCurvedLine.setVisibility(View.GONE);
binding.decorationBottom.setVisibility(View.GONE);
}
public static boolean hasReplies(String commentId, List<CommentData.Comment> comments) {
for (CommentData.Comment comment : comments) {
if (comment.getInReplyToCommentId() != null && commentId.compareTo(comment.getInReplyToCommentId()) == 0) {
return true;
}
}
return false;
}
}

View File

@ -25,79 +25,20 @@
android:showDividers="end"
android:focusable="true">
<androidx.constraintlayout.widget.ConstraintLayout
<LinearLayout
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:id="@+id/decoration_container"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<View
android:id="@+id/decoration_top"
android:layout_width="1dp"
android:layout_height="0dp"
android:background="?attr/colorAccent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/decoration_curved_top"
android:layout_width="11dp"
android:layout_height="10dp"
android:background="@drawable/rounded_decoration_top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/decoration_extension"
android:layout_width="20dp"
android:layout_height="1dp"
android:background="@color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@+id/decoration_curved_bottom"
app:layout_constraintStart_toEndOf="@+id/decoration_curved_top"
app:layout_constraintTop_toTopOf="@+id/decoration_curved_bottom" />
<View
android:id="@+id/decoration_curved_bottom"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginTop="17dp"
android:background="@drawable/rounded_decoration_bottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/decoration_curved_line"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="@+id/decoration_curved_top"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/decoration_curved_top" />
<View
android:id="@+id/decoration_bottom"
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_marginStart="8.5dp"
android:background="?attr/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/decoration_curved_bottom"
app:layout_constraintTop_toBottomOf="@+id/decoration_curved_bottom" />
</androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_height="wrap_content"
android:id="@+id/sub_comment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
app:layout_constraintStart_toEndOf="@+id/decoration_container"
app:layout_constraintTop_toTopOf="parent">
android:layout_marginStart="10dp">
<ImageView
android:id="@+id/comment_account_profile"