From 45366f4e0e26d222b8fc2eac3c31194f724ce6bf Mon Sep 17 00:00:00 2001 From: M M Arif Date: Sun, 27 Mar 2022 23:37:25 +0500 Subject: [PATCH] Add Signal style space at the bottom which also fix the overlap issue by comment button --- .../activities/IssueDetailActivity.java | 34 +++------------- .../gitnex/helpers/DividerItemDecorator.java | 40 +++++++++++++++++++ .../main/res/drawable/shape_list_divider.xml | 4 +- .../main/res/layout/activity_issue_detail.xml | 3 +- 4 files changed, 49 insertions(+), 32 deletions(-) create mode 100644 app/src/main/java/org/mian/gitnex/helpers/DividerItemDecorator.java diff --git a/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java b/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java index 874e9667..d63dd8c9 100644 --- a/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java @@ -6,7 +6,6 @@ import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -24,13 +23,13 @@ import android.widget.ScrollView; import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; import androidx.core.text.HtmlCompat; import androidx.core.widget.ImageViewCompat; -import androidx.core.widget.NestedScrollView; import androidx.lifecycle.ViewModelProvider; -import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import com.amulyakhare.textdrawable.TextDrawable; import com.google.gson.JsonElement; import com.vdurmont.emoji.EmojiParser; @@ -59,6 +58,7 @@ import org.mian.gitnex.helpers.AlertDialogs; import org.mian.gitnex.helpers.AppUtil; import org.mian.gitnex.helpers.ClickListener; import org.mian.gitnex.helpers.ColorInverter; +import org.mian.gitnex.helpers.DividerItemDecorator; import org.mian.gitnex.helpers.LabelWidthCalculator; import org.mian.gitnex.helpers.Markdown; import org.mian.gitnex.helpers.RoundedTransformation; @@ -82,7 +82,7 @@ import retrofit2.Callback; import retrofit2.Response; /** - * Author M M Arif + * @author M M Arif */ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapter.LabelsListAdapterListener, AssigneesListAdapter.AssigneesListAdapterListener, BottomSheetListener { @@ -154,7 +154,7 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt viewBinding.recyclerView.setNestedScrollingEnabled(false); viewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(ctx)); - DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(viewBinding.recyclerView.getContext(), DividerItemDecoration.VERTICAL); + RecyclerView.ItemDecoration dividerItemDecoration = new DividerItemDecorator(ContextCompat.getDrawable(this, R.drawable.shape_list_divider)); viewBinding.recyclerView.addItemDecoration(dividerItemDecoration); viewBinding.addNewComment.setOnClickListener(v -> { @@ -162,7 +162,6 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt BottomSheetReplyFragment bottomSheetReplyFragment = BottomSheetReplyFragment.newInstance(new Bundle(), issue); bottomSheetReplyFragment.setOnInteractedListener(this::onResume); bottomSheetReplyFragment.show(getSupportFragmentManager(), "replyBottomSheet"); - }); labelsAdapter = new LabelsListAdapter(labelsList, IssueDetailActivity.this, currentLabelsIds); @@ -170,29 +169,6 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt LabelsActions.getCurrentIssueLabels(ctx, repoOwner, repoName, issueIndex, currentLabelsIds); AssigneesActions.getCurrentIssueAssignees(ctx, repoOwner, repoName, issueIndex, currentAssignees); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - - viewBinding.scrollViewComments.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> { - - if((scrollY - oldScrollY) > 0 && viewBinding.addNewComment.isShown()) { - viewBinding.addNewComment.setVisibility(View.GONE); - } - else if((scrollY - oldScrollY) < 0) { - viewBinding.addNewComment.setVisibility(View.VISIBLE); - } - - if(!viewBinding.scrollViewComments.canScrollVertically(1)) { // bottom - viewBinding.addNewComment.setVisibility(View.GONE); - } - - if(!viewBinding.scrollViewComments.canScrollVertically(-1)) { // top - viewBinding.addNewComment.setVisibility(View.VISIBLE); - } - - }); - - } - viewBinding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> { viewBinding.pullToRefresh.setRefreshing(false); diff --git a/app/src/main/java/org/mian/gitnex/helpers/DividerItemDecorator.java b/app/src/main/java/org/mian/gitnex/helpers/DividerItemDecorator.java new file mode 100644 index 00000000..11758712 --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/helpers/DividerItemDecorator.java @@ -0,0 +1,40 @@ +package org.mian.gitnex.helpers; + +import android.graphics.Canvas; +import android.graphics.drawable.Drawable; +import android.view.View; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +/** + * @author M M Arif + */ + +public class DividerItemDecorator extends RecyclerView.ItemDecoration { + + private final Drawable rvDivider; + + public DividerItemDecorator(Drawable divider) { + rvDivider = divider; + } + + @Override + public void onDrawOver(@NonNull Canvas canvas, RecyclerView parent, @NonNull RecyclerView.State state) { + + int dividerLeft = parent.getPaddingLeft(); + int dividerRight = parent.getWidth() - parent.getPaddingRight(); + + int childCount = parent.getChildCount(); + for (int i = 0; i <= childCount - 2; i++) { + View child = parent.getChildAt(i); + + RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); + + int dividerTop = child.getBottom() + params.bottomMargin; + int dividerBottom = dividerTop + rvDivider.getIntrinsicHeight(); + + rvDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom); + rvDivider.draw(canvas); + } + } +} diff --git a/app/src/main/res/drawable/shape_list_divider.xml b/app/src/main/res/drawable/shape_list_divider.xml index ff307019..5269b123 100644 --- a/app/src/main/res/drawable/shape_list_divider.xml +++ b/app/src/main/res/drawable/shape_list_divider.xml @@ -1,5 +1,5 @@ - - + + diff --git a/app/src/main/res/layout/activity_issue_detail.xml b/app/src/main/res/layout/activity_issue_detail.xml index c82cbc6c..638d7c7d 100644 --- a/app/src/main/res/layout/activity_issue_detail.xml +++ b/app/src/main/res/layout/activity_issue_detail.xml @@ -62,7 +62,6 @@ android:textColor="@color/colorWhite" android:backgroundTint="?attr/fabColor" android:layout_gravity="bottom|end" - app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior" app:iconTint="@color/colorWhite" app:icon="@drawable/ic_reply" /> @@ -256,6 +255,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/primaryBackgroundColor" + android:paddingBottom="72dp" + android:clipToPadding="false" android:scrollbars="vertical" />