diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextView.java index 30cbce1a..97ac70f4 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextView.java @@ -132,7 +132,11 @@ private void setupUrl() { String qText = value.get("qText"); urlLabel = qText != null ? qText : ""; } else { - urlLabel = column.representation.urlPosition.equals("dimension") ? (column.representation.linkUrl != null ? column.representation.linkUrl : "") : (cell.qText != null ? cell.qText : ""); + if(column.representation.urlPosition != null) { + urlLabel = column.representation.urlPosition.equals("dimension") ? (column.representation.linkUrl != null ? column.representation.linkUrl : "") : (cell.qText != null ? cell.qText : ""); + } else { + urlLabel = cell.qText == null ? "" : cell.qText; + } } String urlText = cell.qText; int attrIndex = column.stylingInfo.indexOf("url"); diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/DataCell.java b/android/src/main/java/com/qliktrialreactnativestraighttable/DataCell.java index da8e54ed..27c5aaa1 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/DataCell.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/DataCell.java @@ -27,7 +27,7 @@ public class DataCell { boolean isDim = false; int rawRowIdx; int rawColIdx; - boolean isNumber; + boolean isNumber = false; qMiniChart miniChart; Indicator indicator; int cellForegroundColor; @@ -45,8 +45,10 @@ public DataCell(ReadableMap source, DataColumn column) { columnIndex = column.columnIndex; rawRowIdx = source.getInt("rawRowIdx"); rawColIdx = source.getInt("rawColIdx"); - ReadableType qNumType = source.getType("qNum"); - isNumber = qNumType == ReadableType.Number; + if(source.hasKey("qNum")) { + ReadableType qNumType = source.getType("qNum"); + isNumber = qNumType == ReadableType.Number; + } if (source.hasKey("isDim")) { isDim = source.getBoolean("isDim"); } @@ -101,8 +103,12 @@ public JSONObject toEvent() throws JSONException { cell.put("rawRowIdx", rawRowIdx); cell.put("rawColIdx", rawColIdx); cell.put("isNumber", isNumber); - cell.put("miniChart", miniChart); - cell.put("indicator", indicator); + if(miniChart != null) { + cell.put("qMiniChart", miniChart.toEvent()); + } + if(indicator != null) { + cell.put("indicator", indicator.toEvent()); + } return cell; } diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/DataColumn.java b/android/src/main/java/com/qliktrialreactnativestraighttable/DataColumn.java index afb7b6b9..05cfc177 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/DataColumn.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/DataColumn.java @@ -32,7 +32,9 @@ public class DataColumn { public DataColumn(ReadableMap source, int index) { ReadableMap representationMap = source.getMap("representation"); representation = new Representation(representationMap); - stylingInfo = source.getArray("stylingInfo").toArrayList(); + if(source.hasKey("stylingInfo")) { + stylingInfo = source.getArray("stylingInfo").toArrayList(); + } align = source.getString("align"); isDim = source.getBoolean("isDim"); label = source.getString("label"); diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/EventUtils.java b/android/src/main/java/com/qliktrialreactnativestraighttable/EventUtils.java index e2fcab70..f8cbea43 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/EventUtils.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/EventUtils.java @@ -38,7 +38,6 @@ public static void sendOnHeaderTapped(View contextView, DataColumn column) { WritableMap event = Arguments.createMap(); try { String columnJSONString = column.toEvent().toString(); - Log.d("foo", columnJSONString); event.putString("column", columnJSONString); EventUtils.sendEventToJSFromView(contextView, "onHeaderPressed", event); } catch (JSONException e) { diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/Indicator.java b/android/src/main/java/com/qliktrialreactnativestraighttable/Indicator.java index 97a15abb..6a4852df 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/Indicator.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/Indicator.java @@ -4,6 +4,9 @@ import com.facebook.react.bridge.ReadableMap; +import org.json.JSONException; +import org.json.JSONObject; + public class Indicator { boolean applySegmentColors = false; int color = Color.BLACK; @@ -28,6 +31,15 @@ private void parseColor(ReadableMap data) { getIcon(data); } + public JSONObject toEvent() throws JSONException { + JSONObject json = new JSONObject(); + json.put("applySegmentColors", applySegmentColors); + json.put("showTextValues", showTextValues); + json.put("position", position); + json.put("index", index); + return json; + } + private void getIcon(ReadableMap data) { if (data.hasKey("icon")) { hasIcon = true; diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartInfo.java b/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartInfo.java index 13490b0b..ed1814cb 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartInfo.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartInfo.java @@ -4,6 +4,9 @@ import com.facebook.react.bridge.ReadableMap; +import org.json.JSONException; +import org.json.JSONObject; + public class MiniChartInfo { public String type; public Boolean showDots; @@ -17,6 +20,13 @@ public YAxis(ReadableMap data) { position = data.hasKey("position") ? data.getString("position") : ""; scale = data.hasKey("scale") ? data.getString("scale") : ""; } + + public JSONObject toEvent() throws JSONException { + JSONObject json = new JSONObject(); + json.put("position", position); + json.put("scale", scale); + return json; + } } class MiniChartColor { @@ -32,6 +42,14 @@ public MiniChartColor(ReadableMap data) { valid = true; } } + + public JSONObject toEvent() throws JSONException { + JSONObject json = new JSONObject(); + json.put("index", index); + json.put("color", colorValue); + json.put("valid", valid); + return json; + } } class ChartColors { @@ -59,6 +77,19 @@ public void resetChartColors(ReadableMap data) { positive = getMiniChartColor("positive", data); main = getMiniChartColor("main", data); } + + public JSONObject toEvent() throws JSONException { + JSONObject json = new JSONObject(); + json.put("first", first.toEvent()); + json.put("last", last.toEvent()); + json.put("min", min.toEvent()); + json.put("max", max.toEvent()); + json.put("negative", negative.toEvent()); + json.put("positive", positive.toEvent()); + json.put("main", main.toEvent()); + + return json; + } } MiniChartInfo(ReadableMap data) { @@ -67,4 +98,13 @@ public void resetChartColors(ReadableMap data) { yAxis = data.hasKey("yAxis") ? new YAxis(data.getMap("yAxis")) : null; colors = data.hasKey("colors") ? new ChartColors(data.getMap("colors")) : null; } + + public JSONObject toEvent() throws JSONException { + JSONObject json = new JSONObject(); + json.put("type", type); + json.put("showDots", showDots); + json.put("yAxis", yAxis.toEvent()); + json.put("colors", colors.toEvent()); + return json; + } } diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartView.java index af4171c6..8e26e180 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartView.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartView.java @@ -20,6 +20,7 @@ public class MiniChartView extends View implements Content { Rect bounds = new Rect(); Paint paint = new Paint(); DataCell dataCell = null; + DataColumn dataColumn = null; MiniChartRenderer miniChartRenderer = null; public MiniChartView(Context context) { @@ -28,6 +29,8 @@ public MiniChartView(Context context) { } public void setData(DataCell cell, DataColumn column) { + this.dataCell = cell; + this.dataColumn = column; if(miniChartRenderer == null) { if (cell.miniChart != null && column.representation != null) { if (column.representation.miniChart != null) { diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartViewManager.java b/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartViewManager.java new file mode 100644 index 00000000..cdb10d02 --- /dev/null +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartViewManager.java @@ -0,0 +1,67 @@ +package com.qliktrialreactnativestraighttable; + +import android.annotation.SuppressLint; +import android.os.Build; +import android.util.Log; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; + +import com.facebook.react.bridge.ReadableArray; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.common.MapBuilder; +import com.facebook.react.uimanager.SimpleViewManager; +import com.facebook.react.uimanager.ThemedReactContext; +import com.facebook.react.uimanager.annotations.ReactProp; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class MiniChartViewManager extends SimpleViewManager { + public static final String REACT_CLASS = "MiniChartView"; + public ReadableMap column = null; + public ReadableMap cell = null; + @Override + @NonNull + public String getName() { + return REACT_CLASS; + } + + @SuppressLint("NewApi") + @Override + @NonNull + public View createViewInstance(ThemedReactContext reactContext) { + MiniChartView miniChartView = new MiniChartView(reactContext); + return miniChartView; + } + + @ReactProp(name = "colData") + public void setCol(View view, ReadableMap col) { + MiniChartView miniChartView = (MiniChartView) view; + column = col; + + if (cell != null) { + setupMiniChart(miniChartView); + } + } + + @ReactProp(name = "rowData") + public void setCell(View view, ReadableMap cell) { + MiniChartView miniChartView = (MiniChartView) view; + this.cell = cell; + + if (column != null) { + setupMiniChart(miniChartView); + } + } + + public void setupMiniChart(MiniChartView miniChartView) { + DataColumn dataColumn = new DataColumn(column, 0); + DataCell dataCell = new DataCell(cell, dataColumn); + + miniChartView.setData(dataCell, dataColumn); + } +} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTablePackage.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTablePackage.java index fe12fa5c..a12e26ad 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTablePackage.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTablePackage.java @@ -17,6 +17,6 @@ public List createNativeModules(ReactApplicationContext reactConte @Override public List createViewManagers(ReactApplicationContext reactContext) { - return Arrays.asList(new ReactNativeStraightTableViewManager()); + return Arrays.asList(new ReactNativeStraightTableViewManager(), new MiniChartViewManager()); } } diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/Representation.java b/android/src/main/java/com/qliktrialreactnativestraighttable/Representation.java index 76c195e4..0bb4bac6 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/Representation.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/Representation.java @@ -1,5 +1,7 @@ package com.qliktrialreactnativestraighttable; +import android.util.Log; + import com.facebook.react.bridge.ReadableMap; import org.json.JSONException; @@ -44,7 +46,9 @@ public JSONObject toEvent() throws JSONException { column.put("urlPosition", urlPosition); column.put("globalMax", globalMax); column.put("globalMin", globalMin); - column.put("miniChart", miniChart); + if(miniChart != null) { + column.put("miniChart", miniChart.toEvent()); + } return column; } diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/RowViewHolder.java b/android/src/main/java/com/qliktrialreactnativestraighttable/RowViewHolder.java index 4be84751..6a945648 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/RowViewHolder.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/RowViewHolder.java @@ -72,7 +72,7 @@ public void setData(DataRow dataRow, int rowHeight, CellContentStyle cellContent } else if(column.representation.type.equals("miniChart")) { LinearLayout.LayoutParams cellViewLayoutParams = new LinearLayout.LayoutParams(column.width, ViewGroup.LayoutParams.MATCH_PARENT); cellView.setLayoutParams(cellViewLayoutParams); - + cellView.setData(cell, dataRow, column); cellView.convertCellContentType("miniChart", column); MiniChartView miniChartView = (MiniChartView) cellView.content; miniChartView.setData(cell, column); diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/qMatrix.java b/android/src/main/java/com/qliktrialreactnativestraighttable/qMatrix.java index 8bd8fe02..4fa09811 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/qMatrix.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/qMatrix.java @@ -4,6 +4,10 @@ import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableType; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + import java.util.ArrayList; import java.util.List; @@ -13,7 +17,7 @@ public class qMatrix { class qMatrixColumn { public double qElemNumber; public double qNum = 0.0; - public String qText; + public String qText = null; public qMatrixColumn(ReadableMap data) { qElemNumber = data.hasKey("qElemNumber") ? data.getDouble("qElemNumber") : 0.0; if(data.hasKey("qNum")) { @@ -24,6 +28,16 @@ public qMatrixColumn(ReadableMap data) { } qText = data.hasKey("qText") ? data.getString("qText") : ""; } + + JSONObject toEvent() throws JSONException { + JSONObject object = new JSONObject(); + object.put("qElemenNumber", qElemNumber); + object.put("qNum", qNum); + if(qText != null){ + object.put("qText", qText); + } + return object; + } } class qMatrixRow { @@ -33,6 +47,13 @@ public qMatrixRow(ReadableArray dataArray) { columns.add(new qMatrixColumn(dataArray.getMap(i))); } } + JSONArray toEvent() throws JSONException { + JSONArray jsonArray = new JSONArray(); + for(qMatrixColumn column : columns) { + jsonArray.put(column.toEvent()); + } + return jsonArray; + } } public qMatrix(ReadableArray dataArray) { @@ -42,4 +63,12 @@ public qMatrix(ReadableArray dataArray) { } } + JSONArray toEvent() throws JSONException{ + JSONArray jsonArray = new JSONArray(); + for(qMatrixRow row : rows) { + jsonArray.put(row.toEvent()); + } + return jsonArray; + } + } diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/qMiniChart.java b/android/src/main/java/com/qliktrialreactnativestraighttable/qMiniChart.java index 65134b05..b4588e73 100644 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/qMiniChart.java +++ b/android/src/main/java/com/qliktrialreactnativestraighttable/qMiniChart.java @@ -3,6 +3,9 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; +import org.json.JSONException; +import org.json.JSONObject; + public class qMiniChart { public double qMin; public double qMax; @@ -15,4 +18,16 @@ public qMiniChart(ReadableMap data) { matrix = new qMatrix(dataArray); } } + + public JSONObject toEvent() throws JSONException { + + JSONObject json = new JSONObject(); + json.put("qMin", qMin); + json.put("qMax", qMax); + if(matrix != null) { + String foo = matrix.toEvent().toString(); + json.put("qMatrix", matrix.toEvent()); + } + return json; + } }