Skip to content

Commit

Permalink
fix(md-3779): column sort indicators android (#122)
Browse files Browse the repository at this point in the history
* fix: sort indicators

* fix: first column sort

* fix: totals resize lost from rebase
  • Loading branch information
gruskal authored Nov 8, 2022
1 parent 478dac4 commit 79ed846
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class GrabberView extends LinearLayout {
DataProvider dataProvider = null;
AutoLinearLayout headerView = null;
AutoLinearLayout footerView = null;
AutoLinearLayout totalsView = null;
List<GrabberView> grabbers = null;
CustomRecyclerView recyclerView;
CustomRecyclerView firstColumnRecyclerView;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +16,8 @@

@SuppressLint("ViewConstructor")
public class HeaderCell extends LinearLayout {
String sortIndicatorState = "none";
Paint paint = new Paint();
DataColumn column;
TableView tableView;
HeaderText cell;
Expand Down Expand Up @@ -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() {
Expand All @@ -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();
}

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -147,8 +146,8 @@ public void setDataColumns(List<DataColumn> 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) {
Expand Down Expand Up @@ -233,7 +232,6 @@ void createRecyclerView() {
scrollView = tableViewFactory.scrollView;
screenGuideView = tableViewFactory.screenGuideView;
firstColumnView = tableViewFactory.firstColumnRecyclerView;
firstColumnHeaderCell = tableViewFactory.firstColumnHeaderCell;
}
}

Expand Down

0 comments on commit 79ed846

Please sign in to comment.