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-3895): address comments #168

Merged
merged 2 commits into from Dec 7, 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
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
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
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
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
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
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
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
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
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
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
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
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