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: totals cell wrapping #173

Merged
merged 3 commits into from Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -217,9 +217,8 @@ public boolean isSelected(){
return selected;
}

@Override
public void setMaxLines(int maxLines) {
maxLines = textWrapper.setMaxLines(maxLines);
public void setMaxLines(int maxLines, DataColumn column) {
maxLines = textWrapper.setMaxLines(maxLines, column);
super.setMaxLines(maxLines);
}

Expand All @@ -230,6 +229,9 @@ public void testTextWrap(DataColumn dataColumn) {
}

public int getMeasuredLineCount() {
if(column != null && !column.isDim) {
return 1;
}
return textWrapper.getMeasuredLinedCount();
}

Expand Down
Expand Up @@ -120,8 +120,8 @@ public boolean onTouchEvent(@NonNull MotionEvent e) {
}

void setMaxLines(int maxLineCount) {
if(this.cell != null) {
this.cell.setMaxLines(maxLineCount);
if(this.cell != null && this.column != null) {
this.cell.setMaxLines(maxLineCount, this.column);
}
}
@SuppressLint("ViewConstructor")
Expand Down Expand Up @@ -149,9 +149,8 @@ public void testTextWrap() {
}
}

@Override
public void setMaxLines(int maxLines) {
maxLines = textWrapper.setMaxLines(maxLines);
public void setMaxLines(int maxLines, DataColumn column) {
maxLines = textWrapper.setMaxLines(maxLines, column);
super.setMaxLines(maxLines);
}

Expand Down
Expand Up @@ -54,7 +54,7 @@ public int getMaxLineCount() {

for(int i = 0; i < this.dataColumns.size(); i++) {
HeaderCell headerCell = (HeaderCell)this.getChildAt(i);
headerCell.cell.setMaxLines(lineCount);
headerCell.cell.setMaxLines(lineCount, dataColumns.get(i));
}
return lineCount;
}
Expand Down
Expand Up @@ -98,7 +98,7 @@ public void setData(DataRow dataRow, int rowHeight, CellContentStyle cellContent
setupHyperLink(textView);
}
if(column.isDim && cellContentStyle.wrap) {
textView.setMaxLines(rowHeight/cellContentStyle.lineHeight);
textView.setMaxLines(rowHeight/cellContentStyle.lineHeight, column);
} else {
textView.setMaxLines(1);
}
Expand Down Expand Up @@ -149,18 +149,9 @@ public boolean updateWidth(float deltaWidth, int column) {

DataColumn dataColumn = dataProvider.dataColumns.get(column);
checkTextWrap(dataColumn);
checkNeighbourTextWrap(column);

return true;
}

private void checkNeighbourTextWrap(int column) {
if (column + 1 < numColumns ) {
DataColumn dataColumn = dataProvider.dataColumns.get(column);
checkTextWrap(dataColumn);
}
}

private void checkTextWrap(DataColumn dataColumn) {
if(dataColumn.isDim && dataColumn.isText() ) {
CellView cellView = (CellView) row.getChildAt(dataColumn.columnIndex);
Expand Down Expand Up @@ -233,7 +224,7 @@ public void initializeHeight(int rowHeight, CellContentStyle cellContentStyle) {
if(column.columnIndex < row.getChildCount()) {
CellView cellView = (CellView) row.getChildAt(column.columnIndex);
ClickableTextView clickableTextView = (ClickableTextView) cellView.content;
clickableTextView.setMaxLines(lines);
clickableTextView.setMaxLines(lines, column);
clickableTextView.setGravity(column.textAlignment | Gravity.CENTER_VERTICAL);
clickableTextView.requestLayout();
}
Expand Down
Expand Up @@ -65,7 +65,7 @@ void measureLineCountNoUpdate() {
}

protected int calculateLineCount() {
int width = column.width - additionalPadding;
int width = Math.max(textView.getMeasuredWidth() - textView.getPaddingRight() - textView.getPaddingLeft(), 0);
measureTextPaint.setTypeface(textView.getTypeface());
StaticLayout.Builder builder = StaticLayout.Builder.obtain(textView.getText(), 0, textView.getText().length(), measureTextPaint, width);
builder.setIncludePad(true);
Expand All @@ -81,10 +81,16 @@ public int getMeasuredLinedCount() {
return lineCount;
}

public int setMaxLines(int maxLines) {
countWords(textView.getText().toString());
maxLines = wordCount > 1 ? maxLines : 1;
public int setMaxLines(int maxLines, DataColumn column) {
if(column.isDim) {
countWords(textView.getText().toString());
maxLines = wordCount > 1 ? maxLines : 1;
} else {
maxLines = 1;
wordCount = 1;
}
return maxLines;

}

public void countWords(String text) {
Expand Down
Expand Up @@ -48,7 +48,7 @@ public int getMaxLineCount() {

for(int i = 0; i < this.dataColumns.size(); i++) {
TotalsViewCell totalsCell = (TotalsViewCell)this.getChildAt(i);
totalsCell.setMaxLines(lineCount);
totalsCell.setMaxLines(lineCount, dataColumns.get(i));
}
return lineCount;
}
Expand Down
Expand Up @@ -36,13 +36,15 @@ public void testTextWrap() {
}
}

@Override
public void setMaxLines(int maxLines) {
maxLines = textWrapper.setMaxLines(maxLines);
public void setMaxLines(int maxLines, DataColumn column) {
maxLines = textWrapper.setMaxLines(maxLines, column);
super.setMaxLines(maxLines);
}

int getMeasuredLinedCount() {
if(column != null && !column.isDim) {
return 1;
}
return textWrapper.getMeasuredLinedCount();
}

Expand Down