From f0d5914d321c6d1ebe1ab1df1f7429e701042bdb Mon Sep 17 00:00:00 2001 From: Luc Gruska Date: Wed, 7 Dec 2022 12:38:18 -0500 Subject: [PATCH] fix(md-3895): address comments (#168) * fix: text wrapping and padding * fix: pr --- .../ClickableTextView.java | 18 +++++++++++++----- .../ClickableTextWrapper.java | 3 ++- .../CustomHorizontalScrollView.java | 11 ++++++++--- .../DataCell.java | 8 ++++++++ .../DataColumn.java | 1 - .../DataProvider.java | 8 +++++--- .../GrabberView.java | 9 +++++++-- .../HeaderViewFactory.java | 5 ++--- .../MockVerticalScrollView.java | 6 ++++++ .../RowViewHolder.java | 1 + .../TableViewFactory.java | 2 +- .../TotalsViewCell.java | 3 ++- 12 files changed, 55 insertions(+), 20 deletions(-) diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextView.java index 4ebdbf81..e9db6b9f 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextView.java @@ -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; @@ -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) { @@ -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); @@ -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(); diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextWrapper.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextWrapper.java index b23e44f2..f8de8c71 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextWrapper.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextWrapper.java @@ -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) { diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/CustomHorizontalScrollView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/CustomHorizontalScrollView.java index dd87bee8..42c9a629 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/CustomHorizontalScrollView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/CustomHorizontalScrollView.java @@ -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); @@ -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){ diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/DataCell.java b/android/src/main/java/com/qliktrialreactnativestraighttable/DataCell.java index ad533452..168df614 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/DataCell.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/DataCell.java @@ -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; @@ -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(); diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/DataColumn.java b/android/src/main/java/com/qliktrialreactnativestraighttable/DataColumn.java index 9c17219f..4f0165b8 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/DataColumn.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/DataColumn.java @@ -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); diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/DataProvider.java b/android/src/main/java/com/qliktrialreactnativestraighttable/DataProvider.java index 12347ebf..256c0cb2 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/DataProvider.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/DataProvider.java @@ -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); @@ -214,7 +214,9 @@ public void setRows(List data, boolean resetData) { } this.notifyDataSetChanged(); } - tableView.imageLoader.loadImages(); + if(!isDataView) { + tableView.imageLoader.loadImages(); + } setLoading(false); } public void setDataColumns(List cols) { diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/GrabberView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/GrabberView.java index bdf1a3ac..bfbe078f 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/GrabberView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/GrabberView.java @@ -60,13 +60,11 @@ 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(); @@ -74,6 +72,13 @@ public boolean onTouch(View view, MotionEvent motionEvent) { 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; } diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java b/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java index dc1b711a..0f9e6289 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java @@ -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); @@ -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); diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/MockVerticalScrollView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/MockVerticalScrollView.java index 865bc5e3..9c3632f2 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/MockVerticalScrollView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/MockVerticalScrollView.java @@ -9,6 +9,7 @@ import android.widget.ScrollView; public class MockVerticalScrollView extends ScrollView { + int overScrollOffset = 0; View content; public MockVerticalScrollView(Context context) { @@ -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); } diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/RowViewHolder.java b/android/src/main/java/com/qliktrialreactnativestraighttable/RowViewHolder.java index 9eb4a3fb..c3985a96 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/RowViewHolder.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/RowViewHolder.java @@ -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); diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java index 03919e75..03578753 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/TableViewFactory.java @@ -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; diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsViewCell.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsViewCell.java index 70ed9927..343b7bb6 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsViewCell.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsViewCell.java @@ -31,7 +31,8 @@ public void setColumn(DataColumn col) { public void testTextWrap() { if(tableView.headerContentStyle.wrap) { - textWrapper.testOnlyTextWrap(); + textWrapper.countWords(getText().toString()); + textWrapper.testTextWrap(); } }