Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(md-3919/3918/3920): totals fixes #175

Merged
merged 4 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

@SuppressLint("ViewConstructor")
public class CellView extends RelativeLayout implements SelectionsObserver {
String type = "";
Content content = null;
DataRow row;
DataColumn column;
Expand Down Expand Up @@ -91,6 +92,7 @@ private void createContent(String type, DataColumn dataColumn) {
this.setPadding(PADDING, 0, PADDING, 0);
break;
}
this.type = type;
}

private void addContentView(String type) {
Expand All @@ -103,6 +105,9 @@ private void addContentView(String type) {
}

public void convertCellContentType(String type, DataColumn dataColumn) {
if(this.type.equals(type)) {
return;
}
wrapper = null;
wrapperLayout = null;
column = dataColumn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ public void setLoading(boolean loading) {

public void setTotals(ReadableArray totals, String totalsLabel, String totalsPosition) {
if(this.isDataView) {
this.totalsCells = null;
this.totalsLabel = null;
this.totalsPosition = "noTotals";
return;
}

if(totals != null) {
this.totalsCells = HeaderViewFactory.getTotalsCellList(totals);
this.totalsLabel = totalsLabel;
}
this.totalsPosition = totalsPosition == null ? "noTotals" : totalsPosition;
}

public void setFirstColumnFrozen(boolean firstColumnFrozen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class HeaderViewFactory {
HeaderViewFactory headerViewFactory;
String totalsLabel;
boolean topPosition;
boolean bottomPosition;
HeaderView headerView = null;
TotalsView totalsView = null;
TableView tableView;
Expand All @@ -45,12 +46,13 @@ public List<DataColumn> getDataColumns() {
return dataColumns;
}

public HeaderViewFactory(List<DataColumn> dataColumns, List<TotalsCell> totalsCells, String totalsLabel, boolean topPosition, TableView tableView, HeaderContentStyle contentStyle, Context context) {
public HeaderViewFactory(List<DataColumn> dataColumns, List<TotalsCell> totalsCells, String totalsLabel, String totalsPosition, TableView tableView, HeaderContentStyle contentStyle, Context context) {
this.tableView = tableView;
this.dataColumns = dataColumns;
this.totalsCells = totalsCells;
this.totalsLabel = totalsLabel;
this.topPosition = topPosition;
this.topPosition = totalsPosition.equals("top");
this.bottomPosition = totalsPosition.equals("bottom");
this.headerContentStyle = contentStyle;
buildHeader(context);
if (totalsCells != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private List<DataColumn> processColumns(TableView tableView, ReadableMap cols) {
totalsPosition = totals.getString("position");
totalsLabel = totals.getString("label");
totalsRows = totals.getArray("rows");

tableView.setTotals(totalsRows, totalsPosition, totalsLabel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class SearchButton extends androidx.appcompat.widget.AppCompatImageButton
final DataColumn column;
final TableView tableView;
final int defaultColor = Color.TRANSPARENT;
final int pressedColor = Color.parseColor("#595959");
final int textColor = Color.parseColor("#404040");

public SearchButton(Context context, TableView tableView, DataColumn column) {
super(context);
Expand All @@ -26,38 +24,14 @@ public SearchButton(Context context, TableView tableView, DataColumn column) {
this.setBackgroundColor(defaultColor);
}

public void handleTouchDown(){
this.setBackgroundColor(pressedColor);

icon.setTint(Color.WHITE);
this.setImageDrawable(icon);
postInvalidate();
}


public void handleTouchUp(){
this.setBackgroundColor(defaultColor);

icon.setTint(textColor);
this.setImageDrawable(icon);
}

@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();

switch(action) {
case MotionEvent.ACTION_DOWN:
handleTouchDown();
break;
case MotionEvent.ACTION_CANCEL:
handleTouchUp();
break;
case MotionEvent.ACTION_UP:
EventUtils.sendOnSearchColumn(tableView, column);
postInvalidate();
break;
if (action == MotionEvent.ACTION_UP) {
EventUtils.sendOnSearchColumn(tableView, column);
postInvalidate();
}
return super.onTouchEvent(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,23 @@ public int getContentBottom() {
public void setTotals(ReadableArray totalsRows, String totalsPosition, String totalsLabel) {
this.totalsLabel = totalsLabel;
this.totalsRows = totalsRows;
this.totalsPosition = totalsPosition;
dataProvider.setTotals(totalsRows, totalsLabel, totalsPosition);

if(totalsPosition == null) {
this.totalsPosition = "noTotals";
} else {
switch(totalsPosition) {
case "bottom":
this.totalsPosition = totalsPosition;
break;
default:
case "noTotals":
case "top":
this.totalsPosition = "top";
break;
}
}

dataProvider.setTotals(totalsRows, totalsLabel, this.totalsPosition);
}

public void clearSelections() {
Expand Down Expand Up @@ -161,42 +176,7 @@ public void setDataColumns(List<DataColumn> cols) {

TotalsView totalsView = getTotalsView();
if(totalsView != null) {
totalsView.setDataColumns(cols);
// Create new totals when there are new columns
int totalCellCount = totalsView.getChildCount();
int numMissingCells = dataProvider.dataColumns.size() - totalCellCount;
int numCells = dataProvider.totalsCells.size();
int j = numCells - numMissingCells;
for(int i = totalCellCount; i < dataProvider.dataColumns.size(); i++) {
DataColumn column = dataProvider.dataColumns.get(i);
TotalsViewCell totalsViewCell = HeaderViewFactory.createTotalsCell(getContext(), column, this);
LinearLayout.LayoutParams totalsParams = new LinearLayout.LayoutParams(column.width, ViewGroup.LayoutParams.MATCH_PARENT);
if (!column.isDim && j < numCells) {
totalsViewCell.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
totalsViewCell.setText(dataProvider.totalsCells.get(j).qText);
j++;
}
totalsView.addView(totalsViewCell, totalsParams);
}
// Update totals in case of moved columns
j = 0;
for(int i = 0; i < totalsView.getChildCount(); i++) {
TotalsViewCell viewCell = (TotalsViewCell) totalsView.getChildAt(i);
viewCell.setText("");

if(i > dataProvider.dataColumns.size() - 1) {
totalsView.removeView(totalsView);
continue;
}

DataColumn column = dataProvider.dataColumns.get(i);
viewCell.setColumn(column);
if(!column.isDim && j < dataProvider.totalsCells.size()) {
String newText = dataProvider.totalsCells.get(j).qText;
viewCell.setText(newText != null && newText.length() > 0 ? newText : "");
j++;
}
}
totalsView.updateTotals(cols, dataProvider);
}

if(headerView != null) {
Expand Down Expand Up @@ -305,7 +285,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
}

void createRecyclerView() {
dataProvider.setTotals(totalsRows, totalsLabel, totalsPosition);
setTotals(totalsRows, totalsPosition, totalsLabel);
tableViewFactory.createAll();
recyclerView = tableViewFactory.coupledRecyclerView;
grabbers = tableViewFactory.grabbers;
Expand All @@ -315,9 +295,6 @@ void createRecyclerView() {
verticalScrollBar = tableViewFactory.verticalScrollBar;
screenGuideView = tableViewFactory.screenGuideView;
firstColumnView = tableViewFactory.firstColumnRecyclerView;
post(() -> {
tableViewFactory.updateScrollbarBounds();
});
}

void invalidateLayout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.util.List;

public class TableViewFactory {
public int extraTopMargin = 0;
public int extraBottomMargin = 0;
public HeaderViewFactory headerViewFactory = null;
public CustomHorizontalScrollView scrollView = null;
public MockVerticalScrollView verticalScrollBar = null;
Expand Down Expand Up @@ -91,6 +89,8 @@ public void createAll() {
@Override
public void run() {
updateGrabbers();
updateScrollbarBounds();
updateRecyclerViewMargins();
}
});
}
Expand All @@ -114,7 +114,7 @@ private void setMockScrollLayouts() {

FrameLayout.LayoutParams horizontalFrameLayout = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, (int) PixelUtils.dpToPx(5));
horizontalFrameLayout.gravity = Gravity.BOTTOM;
horizontalFrameLayout.bottomMargin = tableView.totalsHeight;
horizontalFrameLayout.bottomMargin = TableTheme.DefaultRowHeight;
horizontalFrameLayout.rightMargin = (int) PixelUtils.dpToPx(25);

horizontalScrollView.setLayoutParams(horizontalFrameLayout);
Expand Down Expand Up @@ -179,28 +179,21 @@ protected void createTotalsView() {

protected void createRecyclerViews() {
CustomLinearLayoutManger linearLayout = new CustomLinearLayoutManger(context);
linearLayout.recyclerView = coupledRecyclerView;

coupledRecyclerView = new CustomRecyclerView(context, false, dataProvider, tableView, linearLayout, dragBox, firstColumnDragBox);
FrameLayout.LayoutParams recyclerViewLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
CustomLinearLayoutManger firstColumnLinearLayout = new CustomLinearLayoutManger(context);
firstColumnRecyclerView = new CustomRecyclerView(context, true, dataProvider, tableView, firstColumnLinearLayout, dragBox, firstColumnDragBox);
coupledRecyclerView.setLayoutParams(recyclerViewLayoutParams);
coupledRecyclerView.setZ(0);
coupledRecyclerView.setElevation(0);

int headerHeight = tableView.headerHeight;
int marginTop = headerHeight + extraTopMargin;

linearLayout.recyclerView = coupledRecyclerView;
coupledRecyclerView.setAdapter(dataProvider);

recyclerViewLayoutParams.topMargin = marginTop;
coupledRecyclerView.setLayoutParams(recyclerViewLayoutParams);
rootLayout.addView(coupledRecyclerView, recyclerViewLayoutParams);

CustomLinearLayoutManger firstColumnLinearLayout = new CustomLinearLayoutManger(context);
firstColumnRecyclerView = new CustomRecyclerView(context, true, dataProvider, tableView, firstColumnLinearLayout, dragBox, firstColumnDragBox);
firstColumnLinearLayout.recyclerView = firstColumnRecyclerView;
firstColumnRecyclerView.setAdapter(dataProvider);
FrameLayout.LayoutParams firstColumnViewLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
firstColumnViewLayoutParams.topMargin = marginTop;
firstColumnViewLayoutParams.bottomMargin = TableTheme.DefaultRowHeight;
firstColumnRecyclerView.setLayoutParams(firstColumnViewLayoutParams);

if(tableView.isFirstColumnFrozen) {
Expand Down Expand Up @@ -298,15 +291,6 @@ protected void setupGrabbers() {
void invalidateLayout() {
if (this.coupledRecyclerView != null) {
int width = dataColumns.get(0).width;
int marginTop = tableView.headerHeight + extraTopMargin;

FrameLayout.LayoutParams recyclerViewLayoutParams = (FrameLayout.LayoutParams) coupledRecyclerView.getLayoutParams();
recyclerViewLayoutParams.topMargin = marginTop;
coupledRecyclerView.setLayoutParams(recyclerViewLayoutParams);

FrameLayout.LayoutParams firstColumnRecyclerViewLayoutParams = (FrameLayout.LayoutParams) firstColumnRecyclerView.getLayoutParams();
firstColumnRecyclerViewLayoutParams.topMargin = marginTop;
firstColumnRecyclerView.setLayoutParams(firstColumnRecyclerViewLayoutParams);

if (this.firstColumnHeaderCell != null) {
ViewGroup.LayoutParams params = firstColumnHeaderCell.getLayoutParams();
Expand All @@ -327,15 +311,11 @@ void invalidateLayout() {

this.headerView.updateLayout();
this.headerView.requestLayout();

updateScrollbarBounds();

this.dataProvider.invalidateLayout();
if (this.firstColumnRecyclerView != null) {
this.firstColumnRecyclerView.requestLayout();
}
this.coupledRecyclerView.requestLayout();

updateRecyclerViewMargins();

updateScrollbarBounds();
updateGrabbers();

this.rootLayout.requestLayout();
Expand All @@ -344,23 +324,28 @@ void invalidateLayout() {
}

private void createHeaderFactory() {
boolean topPosition = false;
if(this.totalsCells != null) {
switch(this.totalsPosition) {
case "bottom":
topPosition = false;
extraBottomMargin = tableView.totalsHeight;
break;
case "noTotals":
case "top":
default:
topPosition = true;
extraTopMargin = tableView.totalsHeight;
break;
}
this.headerViewFactory = new HeaderViewFactory(dataColumns, totalsCells, dataProvider.totalsLabel, tableView.totalsPosition, tableView, tableView.headerContentStyle, context);
}

private void updateRecyclerViewMargins() {
int extraTop = tableView.totalsPosition.equals("top") ? tableView.totalsHeight : 0;
int extraBottom = tableView.totalsPosition.equals("bottom") ? tableView.totalsHeight : 0;
int marginTop = tableView.headerHeight + extraTop;

FrameLayout.LayoutParams recyclerViewLayoutParams = (FrameLayout.LayoutParams) coupledRecyclerView.getLayoutParams();
recyclerViewLayoutParams.topMargin = marginTop;
recyclerViewLayoutParams.bottomMargin = extraBottom;

coupledRecyclerView.setLayoutParams(recyclerViewLayoutParams);

if (this.firstColumnRecyclerView != null) {
FrameLayout.LayoutParams firstColumnRecyclerViewLayoutParams = (FrameLayout.LayoutParams) firstColumnRecyclerView.getLayoutParams();
firstColumnRecyclerViewLayoutParams.topMargin = marginTop;
firstColumnRecyclerViewLayoutParams.bottomMargin = TableTheme.DefaultRowHeight + extraBottom;
firstColumnRecyclerView.setLayoutParams(firstColumnRecyclerViewLayoutParams);
this.firstColumnRecyclerView.requestLayout();
}
this.headerViewFactory = new HeaderViewFactory(dataColumns, totalsCells, dataProvider.totalsLabel, topPosition, tableView, tableView.headerContentStyle, context);
this.coupledRecyclerView.requestLayout();
}

public void updateGrabbers() {
Expand Down Expand Up @@ -399,7 +384,7 @@ public void updateHeaderViewLineCount() {

if(headerViewFactory.topPosition && totalsView != null) {
recyclerParams.topMargin += tableView.totalsHeight;
} else if(!headerViewFactory.topPosition && totalsView != null) {
} else if(headerViewFactory.bottomPosition && totalsView != null) {
recyclerParams.bottomMargin = tableView.totalsHeight;
}
coupledRecyclerView.setLayoutParams(recyclerParams);
Expand Down Expand Up @@ -430,9 +415,11 @@ public void updateFirstColumnsHeights() {
if(firstColumnRecyclerView != null && tableView != null) {
FrameLayout.LayoutParams dd = (FrameLayout.LayoutParams) firstColumnRecyclerView.getLayoutParams();
if(dd != null) {
dd.topMargin = tableView.headerHeight ;
dd.topMargin = tableView.headerHeight;
if(headerViewFactory.topPosition && totalsView != null) {
dd.topMargin += tableView.totalsHeight;
} else if(headerViewFactory.bottomPosition && totalsView != null) {
dd.bottomMargin = TableTheme.DefaultRowHeight + tableView.totalsHeight;
}
firstColumnRecyclerView.setLayoutParams(dd);
updateFirstColumnHeaderHeight();
Expand Down