Skip to content

Commit

Permalink
feat(md-3746): search expand android (#110)
Browse files Browse the repository at this point in the history
* feat: search & expand

* feat: cleanup
  • Loading branch information
gruskal committed Nov 3, 2022
1 parent c0c065e commit 39810b7
Show file tree
Hide file tree
Showing 22 changed files with 410 additions and 133 deletions.
Expand Up @@ -21,6 +21,8 @@
@SuppressLint("ViewConstructor")
public class CellView extends LinearLayout implements SelectionsObserver {
Content content = null;
DataRow row;
DataColumn column;
final DragBoxEventHandler dragBoxEventHandler;
final SelectionsEngine selectionsEngine;
final TableView tableView;
Expand All @@ -31,35 +33,47 @@ public class CellView extends LinearLayout implements SelectionsObserver {
CellView(Context context, String type, SelectionsEngine selectionsEngine, TableView tableView, boolean firstColumn) {
super(context);
this.tableView = tableView;
if(type.equals("text")) {
ClickableTextView textView = new ClickableTextView(context, selectionsEngine, tableView, this);
textView.setPadding(padding, 0, padding, 0);
content = textView;
} else if(type.equals("image")) {
content = new ClickableImageView(context, selectionsEngine, tableView, this);
} else if(type.equals("miniChart")) {
content = new MiniChartView(context);
this.setPadding(padding, 0, padding, 0);
}

this.selectionsEngine = selectionsEngine;
this.firstColumn = firstColumn;
this.dragBoxEventHandler = tableView.dragBoxEventHandler;

dragBoxEventHandler.addDragBoxListener((boxBounds, column) -> handleDragBoxDrag(boxBounds, column));
switch (type) {
case "text":
ClickableTextView textView = new ClickableTextView(context, selectionsEngine, tableView, this);
textView.setPadding(padding, 0, padding, 0);
content = textView;
break;
case "image":
content = new ClickableImageView(context, selectionsEngine, tableView, this);
break;
case "miniChart":
content = new MiniChartView(context);
this.setPadding(padding, 0, padding, 0);
break;
}

dragBoxEventHandler.addDragBoxListener(this::handleDragBoxDrag);
gestureDetector = new GestureDetector(getContext(), new CellView.SingleTapListener());
content.setGestureDetector(gestureDetector);

MenuItem.OnMenuItemClickListener handleMenuItemClick = item -> {
switch (item.getItemId()) {
case 0: // Copy
copyCell();
break;
case 1: // Expand
default:
copyCell(context);
expandRow();
}
return true;
};
String copyString = tableView.getTranslation("menu", content.getCopyMenuString());
View.OnCreateContextMenuListener onCreateContextMenuListener = (contextMenu, view, contextMenuInfo) -> contextMenu.add(0, 0, 0, copyString).setOnMenuItemClickListener(handleMenuItemClick);
String expandString = tableView.getTranslation("menu", "expand");

View.OnCreateContextMenuListener onCreateContextMenuListener = (contextMenu, view, contextMenuInfo) -> {
contextMenu.add(0, 0, 0, copyString).setOnMenuItemClickListener(handleMenuItemClick);
contextMenu.add(0, 1, 1, expandString).setOnMenuItemClickListener(handleMenuItemClick);
};
View contentView = (View) content;
contentView.setOnCreateContextMenuListener(onCreateContextMenuListener);
this.addView(contentView);
Expand All @@ -80,13 +94,19 @@ public void handleDragBoxDrag(Rect dragBoxBounds, int columnId) {
}
}

private void copyCell(Context context){
private void expandRow() {
EventUtils.sendOnExpand(tableView, column, row);
}

private void copyCell(){
if(content != null) {
content.copyToClipBoard();
}
}

public void setData(DataCell cell) {
public void setData(DataCell cell, DataRow row, DataColumn column) {
this.row = row;
this.column = column;
content.setCell(cell);
if (cell.isDim) {
selectionsEngine.observe(this);
Expand Down Expand Up @@ -161,7 +181,7 @@ public boolean onSingleTapConfirmed(MotionEvent motionEvent) {

@Override
public void onLongPress(MotionEvent e) {
((View) content).showContextMenu();
((View) content).showContextMenu(e.getX(), e.getY());
}
}
}
Expand Up @@ -12,6 +12,7 @@
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

Expand Down
Expand Up @@ -23,6 +23,7 @@
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

@SuppressLint("ViewConstructor")
public class ClickableTextView extends androidx.appcompat.widget.AppCompatTextView implements Content {
Expand Down
Expand Up @@ -2,7 +2,9 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
Expand All @@ -24,6 +26,7 @@ public class CustomRecyclerView extends RecyclerView {
public boolean firstColumnOnly;
public boolean active = false;
public CustomRecyclerView scrollCoupledView = null;
Paint paint = new Paint();

public CustomRecyclerView(Context context, boolean onlyFirstColumn, DataProvider dp, TableView tv, LinearLayoutManager ll, DragBox db, DragBox firstColumnDb) {
super(context);
Expand Down Expand Up @@ -52,6 +55,14 @@ public CustomRecyclerView(Context context, boolean onlyFirstColumn, DataProvider
firstColumnDb.setScrollListener(this);
}

@Override
public void onDraw(Canvas c) {
super.onDraw(c);
paint.setStrokeWidth(PixelUtils.dpToPx(2));
paint.setColor(TableTheme.borderBackgroundColor);
c.drawLine(0, getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight(), paint);
}

public void setViewToScrollCouple(CustomRecyclerView viewToScroll) {
scrollCoupledView = viewToScroll;
}
Expand Down
Expand Up @@ -2,13 +2,14 @@

import android.graphics.Color;
import android.util.Log;
import android.view.Gravity;
import android.webkit.URLUtil;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableType;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

Expand Down Expand Up @@ -81,4 +82,23 @@ private void updateCellColors(ReadableMap data) {
}
}

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

cell.put("qText", qText);
cell.put("qNum", qNum);
cell.put("qElemNumber", qElemNumber);
cell.put("qState", qState);
cell.put("imageUrl", imageUrl);
cell.put("rowIdx", rowIdx);
cell.put("colIdx", colIdx);
cell.put("isDim", isDim);
cell.put("rawRowIdx", rawRowIdx);
cell.put("rawColIdx", rawColIdx);
cell.put("isNumber", isNumber);
cell.put("miniChart", miniChart);
cell.put("indicator", indicator);

return cell;
}
}
Expand Up @@ -64,7 +64,7 @@ private void setupTextAlign() {
}
}

public String toEvent() throws JSONException {
public JSONObject toEvent() throws JSONException {
JSONObject column = new JSONObject();
column.put("isDim", isDim);
column.put("width", width);
Expand All @@ -74,7 +74,9 @@ public String toEvent() throws JSONException {
column.put("sortDirection", sortDirection);
column.put("dataColIdx", dataColIdx);
column.put("active", active);
return column.toString();
column.put("representation", representation.toEvent());

return column;
}

public boolean isText() {
Expand Down
Expand Up @@ -3,6 +3,10 @@
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -21,4 +25,18 @@ public DataRow(ReadableMap source, List<DataColumn> columns) {
}
Collections.sort(cells, (a, b) -> a.rawColIdx - b.rawColIdx);
}

public String toEvent() throws JSONException {
JSONObject data = new JSONObject();
JSONArray cellJson = new JSONArray();
cells.forEach((DataCell cell) -> {
try {
cellJson.put(cell.toEvent());
} catch (JSONException e) {
e.printStackTrace();
}
});
data.put("cells", cellJson);
return data.toString();
}
}
Expand Up @@ -38,7 +38,7 @@ public DragBox(Context context, TableView tableView, DragBoxEventHandler dragBox
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(1, 1);
setX(-1);
setY(-1);
setZ(PixelUtils.dpToPx(3));
setZ(PixelUtils.dpToPx(1));
setLayoutParams(layoutParams);
}

Expand All @@ -53,6 +53,7 @@ public void show(Rect bounds, int column) {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(width, height);
setX(bounds.left);
setY(bounds.top);
setAlpha(1);
setLayoutParams(layoutParams);
int inset = width / 4;
drawRect = new Rect(0, 0, layoutParams.width, layoutParams.height);
Expand All @@ -72,6 +73,7 @@ public void hide() {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(1, 1);
setX(-1);
setY(-1);
setAlpha(0);
setLayoutParams(layoutParams);
}

Expand All @@ -82,7 +84,7 @@ protected void onDraw(Canvas canvas) {
}
super.onDraw(canvas);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.BLUE);
paint.setColor(Color.DKGRAY);
canvas.drawRect(drawBottomFill, paint);

paint.setStyle(Paint.Style.STROKE);
Expand Down
Expand Up @@ -11,7 +11,9 @@
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.RCTEventEmitter;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

Expand All @@ -35,12 +37,41 @@ public static void sendEventToJSFromView(View contextView, String eventName, Wri
public static void sendOnHeaderTapped(View contextView, DataColumn column) {
WritableMap event = Arguments.createMap();
try {
String columnJSONString = column.toEvent();
String columnJSONString = column.toEvent().toString();
Log.d("foo", columnJSONString);
event.putString("column", columnJSONString);
EventUtils.sendEventToJSFromView(contextView, "onHeaderPressed", event);
} catch (JSONException e) {
e.printStackTrace();
}
}

public static void sendOnExpand(View contextView, DataColumn column, DataRow row) {
WritableMap event = Arguments.createMap();
try {
JSONObject columnJSONObject = column.toEvent();
JSONArray columnJSONArray = new JSONArray();
columnJSONArray.put(columnJSONObject);

String rowJSONString = row.toEvent();
Log.d("bar", rowJSONString);
event.putString("row", rowJSONString);
event.putString("col", columnJSONArray.toString());
EventUtils.sendEventToJSFromView(contextView, "onExpandCell", event);
} catch (JSONException e) {
e.printStackTrace();
}
}

public static void sendOnSearchColumn(View contextView, DataColumn column) {
WritableMap event = Arguments.createMap();
try {
String columnJSONString = column.toEvent().toString();
Log.d("column", columnJSONString);
event.putString("column", columnJSONString);
EventUtils.sendEventToJSFromView(contextView, "onSearchColumn", event);
} catch (JSONException e) {
e.printStackTrace();
}
}
}

0 comments on commit 39810b7

Please sign in to comment.