Skip to content

Commit

Permalink
fix: column resize behaviour to match ios (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
gruskal committed Nov 17, 2022
1 parent 8819225 commit d34c26d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
Expand Up @@ -283,14 +283,9 @@ public boolean updateWidth(float deltaWidth, int column) {
}
}

int next = column + 1;
if (next < dataColumns.size()) {
dataColumns.get(next).width -= (int)deltaWidth;
}

dataColumns.get(column).width += (int)deltaWidth;

columnWidths.updateWidths();

return true;
}

Expand Down
Expand Up @@ -37,6 +37,7 @@ public class GrabberView extends LinearLayout {
class TouchListener implements OnTouchListener {
float dX = 0;
float lastX = 0;

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
int action = motionEvent.getAction();
Expand All @@ -55,13 +56,13 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
return true;
}
case MotionEvent.ACTION_MOVE: {
float x = motionEvent.getRawX() + dX;
float motionDx = motionEvent.getRawX() - lastX;
motionDx = (float) Math.round(motionDx);
if (dataProvider.updateWidth(motionDx, GrabberView.this.column)) {
// cast here to avoid drift
GrabberView.this.setTranslationX((int)x);
GrabberView.this.updateTotals(motionDx);

GrabberView.this.updateGrabbers(motionDx);
GrabberView.this.updateTotals();
GrabberView.this.updateHeader(motionDx);
GrabberView.this.updateFixedTotalsCell(motionDx);
GrabberView.this.updateFirstColumnHeader(motionDx);
Expand Down Expand Up @@ -91,7 +92,6 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
if(screenGuideView != null) {
screenGuideView.fade(1, 0);
}

return true;
}
}
Expand Down Expand Up @@ -176,24 +176,21 @@ public void updateHeader(float dxMotion) {
HeaderCell headerCell = (HeaderCell)headerView.getChildAt(column);
resizeView(headerCell, dxMotion);
headerCell.cell.testTextWrap();
View neighbour = updateNeighbour(headerView, dxMotion);
if(neighbour != null) {
headerCell = (HeaderCell) neighbour;
headerCell.cell.testTextWrap();
}

public void updateGrabbers(float dxMotion) {
for(GrabberView grabber : tableView.grabbers) {
if(grabber.getX() >= GrabberView.this.getX()) {
grabber.setTranslationX((int) (grabber.getTranslationX() + dxMotion));
}
}
}

public void updateTotals(float dxMotion) {
public void updateTotals() {
TotalsView totalsView = tableView.getTotalsView();
if(totalsView != null) {
TotalsViewCell totalsViewCell = (TotalsViewCell) totalsView.getChildAt(column);
resizeView(totalsViewCell, dxMotion);
totalsViewCell.testTextWrap();
View neighbour = updateNeighbour(totalsView, dxMotion);
if(neighbour != null) {
totalsViewCell = (TotalsViewCell) neighbour;
totalsViewCell.testTextWrap();
}
totalsView.updateLayout();
totalsView.testTextWrap();
}
}

Expand All @@ -210,15 +207,6 @@ public void updateFirstColumnHeader(float dxMotion) {
}
}

public View updateNeighbour(LinearLayout container, float dxMotion) {
if(column + 1 < container.getChildCount()) {
View neighbour = container.getChildAt(column + 1);
resizeView(neighbour, -dxMotion);
return neighbour;
}
return null;
}

public void resizeView(View view, float dxMotion) {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.width += dxMotion;
Expand Down

0 comments on commit d34c26d

Please sign in to comment.