Skip to content

Commit

Permalink
fix(md-3895): address comments (#168)
Browse files Browse the repository at this point in the history
* fix: text wrapping and padding

* fix: pr
  • Loading branch information
gruskal authored Dec 7, 2022
1 parent e7a74bb commit f0d5914
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ClickableTextView extends androidx.appcompat.widget.AppCompatTextVi
String linkUrl = null;
String linkLabel = null;
DataCell cell = null;
boolean isDataView = false;
boolean selected = false;
int defaultTextColor = Color.BLACK;
Animation fadeIn;
Expand All @@ -59,6 +60,13 @@ public class ClickableTextView extends androidx.appcompat.widget.AppCompatTextVi
textWrapper = new ClickableTextWrapper(tableView, this);
}

public void setIsDataView(boolean isDataView) {
this.isDataView = isDataView;
if(cell != null) {
cell.setIsDataView(isDataView);
}
}

@SuppressLint("ClickableViewAccessibility")
@Override
public boolean handleTouch(MotionEvent e) {
Expand Down Expand Up @@ -98,8 +106,8 @@ private Rect getMeasuredTextBounds() {
}

public void updateBackgroundColor(boolean shouldAnimate) {
int bgColor = cell.cellBackgroundColorValid ? cell.cellBackgroundColor : Color.TRANSPARENT;
int fgColor = cell.cellForegroundColorValid ? cell.cellForegroundColor : tableView.cellContentStyle.color;
int bgColor = cell.showBackground ? cell.cellBackgroundColor : Color.TRANSPARENT;
int fgColor = cell.showForeground ? cell.cellForegroundColor : tableView.cellContentStyle.color;
int color = selected ? TableTheme.selectedBackground : bgColor ;
int textColor = selected ? Color.WHITE : fgColor ;
cellView.setBackgroundColor(color);
Expand Down Expand Up @@ -154,15 +162,15 @@ public void setCellData(DataCell cell, DataRow row, DataColumn column) {
this.column = column;
this.cell = cell;

cell.setIsDataView(isDataView);
if(cell.indicator != null) {
buildSpannableText();
} else {
setText(cell.qText);
textWrapper.countWords(cell.qText);
}

setTextColor(cell.cellForegroundColorValid ? cell.cellForegroundColor : tableView.cellContentStyle.color);
setBackgroundColor(cell.cellBackgroundColorValid ? cell.cellBackgroundColor : Color.TRANSPARENT);
setTextColor(cell.showForeground ? cell.cellForegroundColor : tableView.cellContentStyle.color);
setBackgroundColor(cell.showBackground ? cell.cellBackgroundColor : Color.TRANSPARENT);

if(cell.type.equals("url")) {
setupUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ void measureLineCount() {
int lines = calculateLineCount();
if(lines != lineCount && lines <= wordCount) {
lineCount = lines;
tableView.updateRecyclerViewLineCount(column);
}
// Update rendered line height as it needs to decrease as well as increase with line count
tableView.updateRecyclerViewLineCount(column);
}
}
int getMeasureLinedCount(DataColumn column) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ public class CustomHorizontalScrollView extends HorizontalScrollView {
MockVerticalScrollView verticalScrollBar;

boolean disableIntercept = false;
public CustomHorizontalScrollView(Context context) {
public CustomHorizontalScrollView(Context context, TableView tableView) {
super(context);
setHorizontalScrollBarEnabled(false);
}

public int getOverScrollOffset() {
int scrollRange = computeHorizontalScrollRange();
int scrollX = computeHorizontalScrollOffset();
return scrollX + getMeasuredWidth() - scrollRange + (int) PixelUtils.dpToPx(25);
}

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
Expand All @@ -34,8 +40,7 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {
horizontalScrollBar.setContentWidth(scrollRange);
horizontalScrollBar.setScrollX(scrollX);

int overScroll = scrollX + horizontalScrollBar.getMeasuredWidth() - scrollRange + (int) PixelUtils.dpToPx(50);
verticalScrollBar.setTranslationX(-Math.max(0, overScroll));
verticalScrollBar.setOverScrollOffset(getOverScrollOffset());
}

public void setScrollbars(MockHorizontalScrollView horizontalScrollBar, MockVerticalScrollView verticalScrollBar){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class DataCell {
int cellBackgroundColor;
boolean cellForegroundColorValid = false;
boolean cellBackgroundColorValid = false;
boolean showForeground = false;
boolean showBackground = false;
qValues qAttrExpValues;
public DataCell(ReadableMap source, DataColumn column, ImageLoader imageLoader) {
type = column.representation.type;
Expand Down Expand Up @@ -110,6 +112,12 @@ private void updateCellColors(ReadableMap data) {
}
}


public void setIsDataView(boolean isDataView) {
showForeground = !isDataView && cellForegroundColorValid;
showBackground = !isDataView && cellBackgroundColorValid;
}

public JSONObject toEvent() throws JSONException {
JSONObject cell = new JSONObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class DataColumn {
public int dataColIdx = 0;
public boolean active = false;
public int textAlignment = Gravity.LEFT;
public int rowHeight = TableTheme.DefaultRowHeight;
public DataColumn(ReadableMap source, int index) {
ReadableMap representationMap = source.getMap("representation");
representation = new Representation(representationMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
float width = column.width;
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams((int)width, tableView.rowHeight);

if (column.representation.type.equals("image")) {
if (column.representation.type.equals("image") && !isDataView) {
CellView cellView = new CellView(parent.getContext(), "image", this.selectionsEngine, this.tableView, recyclerView.firstColumnOnly, column);
LinearLayout.LayoutParams cellLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);

rowView.addView(cellView, cellLayoutParams);

} else if(column.representation.type.equals("miniChart")) {
} else if(column.representation.type.equals("miniChart") && !isDataView) {
CellView cellView = new CellView(parent.getContext(), "miniChart", this.selectionsEngine, this.tableView, recyclerView.firstColumnOnly, column);

rowView.addView(cellView);
Expand Down Expand Up @@ -214,7 +214,9 @@ public void setRows(List<DataRow> data, boolean resetData) {
}
this.notifyDataSetChanged();
}
tableView.imageLoader.loadImages();
if(!isDataView) {
tableView.imageLoader.loadImages();
}
setLoading(false);
}
public void setDataColumns(List<DataColumn> cols) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,25 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
motionDx = (float) Math.round(motionDx);
if (dataProvider.updateWidth(motionDx, GrabberView.this.column)) {
// cast here to avoid drift

GrabberView.this.updateGrabbers(motionDx);
GrabberView.this.updateTotals();
GrabberView.this.updateHeader(motionDx);
GrabberView.this.updateFixedTotalsCell(motionDx);
GrabberView.this.updateFirstColumnHeader(motionDx);
GrabberView.this.tableView.tableViewFactory.updateScrollbarBounds();
lastX = motionEvent.getRawX();
if(isLastColumn && motionDx > 0) {
GrabberView.this.rootLayout.requestLayout();
GrabberView.this.recyclerView.requestLayout();
GrabberView.this.scrollView.updateLayout();
GrabberView.this.scrollView.scrollBy((int) motionDx, 0);
}
GrabberView.this.tableView.tableViewFactory.updateScrollbarBounds();
int overScroll = GrabberView.this.tableView.scrollView.getOverScrollOffset();
if (overScroll > 0) {
GrabberView.this.tableView.verticalScrollBar.setTranslationX(GrabberView.this.tableView.verticalScrollBar.getTranslationX() + motionDx);
} else {
GrabberView.this.tableView.verticalScrollBar.setTranslationX(0);
}
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public static HeaderCell buildFixedColumnCell(FrameLayout rootView, DataColumn c
}

public static TotalsViewCell buildFixedTotalsCell(TableView tableView, DataColumn column, TotalsCell totalsCell, boolean topPosition) {
int headerHeight = tableView.headerHeight;
int padding = (int) PixelUtils.dpToPx(16);
int padding = TableTheme.CellPadding;
TotalsViewCell text = new TotalsViewCell(tableView.getContext(), column, tableView);
text.setTypeface(text.getTypeface(), Typeface.BOLD);
text.setEllipsize(TextUtils.TruncateAt.END);
Expand Down Expand Up @@ -153,7 +152,7 @@ private void buildHeader(Context context) {

public static TotalsViewCell createTotalsCell(Context context, DataColumn column, TableView tableView) {
TotalsViewCell text = new TotalsViewCell(context, column, tableView);
int padding = (int) PixelUtils.dpToPx(16);
int padding = TableTheme.CellPadding;
text.setTypeface(text.getTypeface(), Typeface.BOLD);
text.setEllipsize(TextUtils.TruncateAt.END);
text.setTextSize(tableView.cellContentStyle.fontSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.widget.ScrollView;

public class MockVerticalScrollView extends ScrollView {
int overScrollOffset = 0;
View content;

public MockVerticalScrollView(Context context) {
Expand All @@ -21,6 +22,11 @@ public MockVerticalScrollView(Context context) {
addView(content);
}

public void setOverScrollOffset(int offset) {
overScrollOffset = offset;
setTranslationX(-Math.max(0, offset));
}

public void setContentHeight(int height){
content.setMinimumHeight(height);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void setData(DataRow dataRow, int rowHeight, CellContentStyle cellContent
} else {
cellView.convertCellContentType("text", column);
ClickableTextView textView = (ClickableTextView) cellView.content;
textView.setIsDataView(dataProvider.isDataView);
RelativeLayout.LayoutParams textViewLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
textView.setLayoutParams(textViewLayoutParams);
LinearLayout.LayoutParams cellViewLayoutParams = new LinearLayout.LayoutParams(column.width, ViewGroup.LayoutParams.MATCH_PARENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected void createMockScrollBar() {
}

protected void createScrollView() {
this.scrollView = new CustomHorizontalScrollView(context);
this.scrollView = new CustomHorizontalScrollView(context, tableView);
LinearLayout.LayoutParams scrollLayoutParams = new LinearLayout.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT, ScrollView.LayoutParams.MATCH_PARENT);
scrollLayoutParams.bottomMargin = TableTheme.DefaultRowHeight;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public void setColumn(DataColumn col) {

public void testTextWrap() {
if(tableView.headerContentStyle.wrap) {
textWrapper.testOnlyTextWrap();
textWrapper.countWords(getText().toString());
textWrapper.testTextWrap();
}
}

Expand Down

0 comments on commit f0d5914

Please sign in to comment.