From 79ed8467400e851d7f3de02e5e4ccf3e0952d33f Mon Sep 17 00:00:00 2001 From: Luc Gruska Date: Tue, 8 Nov 2022 16:28:02 -0500 Subject: [PATCH] fix(md-3779): column sort indicators android (#122) * fix: sort indicators * fix: first column sort * fix: totals resize lost from rebase --- .../GrabberView.java | 11 +--- .../HeaderCell.java | 60 +++++++++++-------- .../SearchButton.java | 2 +- .../TableView.java | 6 +- 4 files changed, 40 insertions(+), 39 deletions(-) diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/GrabberView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/GrabberView.java index d3a7e993..81410262 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/GrabberView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/GrabberView.java @@ -23,7 +23,6 @@ public class GrabberView extends LinearLayout { DataProvider dataProvider = null; AutoLinearLayout headerView = null; AutoLinearLayout footerView = null; - AutoLinearLayout totalsView = null; List grabbers = null; CustomRecyclerView recyclerView; CustomRecyclerView firstColumnRecyclerView; @@ -65,7 +64,7 @@ public boolean onTouch(View view, MotionEvent motionEvent) { GrabberView.this.updateHeader(motionDx); GrabberView.this.updateFixedTotalsCell(motionDx); GrabberView.this.updateFirstColumnHeader(motionDx); - GrabberView.this.updateTotals(motionDx); + tableView.tableViewFactory.totalsView.updateLayout(); lastX = motionEvent.getRawX(); if(isLastColumn && motionDx > 0) { GrabberView.this.rootLayout.requestLayout(); @@ -198,14 +197,6 @@ public void updateFixedTotalsCell(float dxMotion) { } } - public void updateTotals(float dxMotion) { - if(totalsView != null) { - View view = totalsView.getChildAt(column); - resizeView(view, dxMotion); - updateNeighbour(totalsView, dxMotion); - } - } - public void updateFirstColumnHeader(float dxMotion) { if(firstColumnHeader != null && column == 0) { resizeView(firstColumnHeader, dxMotion); diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderCell.java b/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderCell.java index 536c003c..4ff63bfb 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderCell.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderCell.java @@ -2,7 +2,9 @@ import android.annotation.SuppressLint; import android.content.Context; +import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.Paint; import android.view.Gravity; import android.view.MotionEvent; import android.view.View; @@ -14,6 +16,8 @@ @SuppressLint("ViewConstructor") public class HeaderCell extends LinearLayout { + String sortIndicatorState = "none"; + Paint paint = new Paint(); DataColumn column; TableView tableView; HeaderText cell; @@ -42,8 +46,36 @@ public HeaderCell(Context context, DataColumn column, TableView tableView) { } public void setColumn(DataColumn column) { - this.cell.setColumn(column); + sortIndicatorState = "none"; + this.column = column; setBackgroundColor(TableTheme.headerBackgroundColor); + cell.setBackgroundColor(Color.TRANSPARENT); + if (column.active) { + if (column.sortDirection == null || column.sortDirection.compareToIgnoreCase("desc") == 0) { + sortIndicatorState = "top"; + } else { + sortIndicatorState = "bottom"; + } + } + postInvalidate(); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + paint.setStrokeWidth(PixelUtils.dpToPx(6)); + paint.setColor(Color.BLACK); + switch(sortIndicatorState) { + case "top": + canvas.drawLine(0, getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight(), paint); + break; + case "bottom": + canvas.drawLine(0, 0, getMeasuredWidth(), 0, paint); + break; + default: + case "none": + break; + } } public void handleSingleTap() { @@ -58,7 +90,8 @@ public void handleDown() { if (column.sortDirection == null && column.active) { return; } - this.setBackgroundColor(Color.LTGRAY); + setBackgroundColor(Color.LTGRAY); + cell.setBackgroundColor(Color.TRANSPARENT); this.invalidate(); } @@ -92,35 +125,14 @@ public class HeaderText extends androidx.appcompat.widget.AppCompatTextView { public HeaderText(Context context, DataColumn column, TableView tableView) { super(context); this.column = column; - this.setCompoundDrawablePadding((int) PixelUtils.dpToPx(4)); this.tableView = tableView; this.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); textWrapper = new TextWrapper(column, tableView, this); if(column.isDim) { textWrapper.additionalPadding = (int)PixelUtils.dpToPx(16) * 5; } + this.setBackgroundColor(Color.TRANSPARENT); this.setGravity(Gravity.CENTER_VERTICAL); - - updateArrow(); - } - - public void setColumn(DataColumn column) { - this.column = column; - textWrapper.column = column; - setBackgroundColor(TableTheme.headerBackgroundColor); - updateArrow(); - } - - private void updateArrow() { - if (column.active) { - if (column.sortDirection == null || column.sortDirection.compareToIgnoreCase("desc") == 0) { - setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_baseline_arrow_drop_up_24, 0, 0, 0); - } else { - setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_baseline_arrow_drop_down_24, 0, 0, 0); - } - } else { - setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - } } public void testTextWrap() { diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/SearchButton.java b/android/src/main/java/com/qliktrialreactnativestraighttable/SearchButton.java index 6224ea5a..5d3045f8 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/SearchButton.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/SearchButton.java @@ -52,7 +52,7 @@ public boolean onTouchEvent(MotionEvent event) { handleTouchDown(); break; case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_HOVER_EXIT: + case MotionEvent.ACTION_CANCEL: handleTouchUp(); break; } diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java index a2ff03d3..6ae3c51f 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/TableView.java @@ -34,7 +34,6 @@ public class TableView extends FrameLayout { AutoLinearLayout footerView = null; CustomRecyclerView recyclerView = null; CustomRecyclerView firstColumnView = null; - HeaderCell firstColumnHeaderCell = null; ScreenGuideView screenGuideView = null; SelectionsEngine selectionsEngine = new SelectionsEngine(); ReadableMap translations; @@ -147,8 +146,8 @@ public void setDataColumns(List cols) { headerView.update(cols); } - if(firstColumnHeaderCell != null && cols.size() > 0) { - firstColumnHeaderCell.setColumn(cols.get(0)); + if(tableViewFactory.firstColumnHeaderCell != null && cols.size() > 0) { + tableViewFactory.firstColumnHeaderCell.setColumn(cols.get(0)); } if(grabbers != null) { @@ -233,7 +232,6 @@ void createRecyclerView() { scrollView = tableViewFactory.scrollView; screenGuideView = tableViewFactory.screenGuideView; firstColumnView = tableViewFactory.firstColumnRecyclerView; - firstColumnHeaderCell = tableViewFactory.firstColumnHeaderCell; } }