Skip to content

Commit

Permalink
feat(md-3351): row count android (#105)
Browse files Browse the repository at this point in the history
* feat: row count & position indicator

* fix: less updates

* feat: cleanup

* fix: count

* fix: prevent line wrapping & cleanup
  • Loading branch information
gruskal committed Nov 2, 2022
1 parent 7a99fa3 commit 8b347a3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.graphics.Color;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
Expand All @@ -17,7 +18,8 @@ public class CustomRecyclerView extends RecyclerView {
final DataProvider dataProvider;
final TableView tableView;
final DragBox dragBox;
public boolean firstColumnOnly = false;
RowCountView rowCountView;
public boolean firstColumnOnly;
public boolean active = false;
public CustomRecyclerView scrollCoupledView = null;

Expand Down Expand Up @@ -53,11 +55,26 @@ public void setViewToScrollCouple(CustomRecyclerView viewToScroll) {
scrollCoupledView = viewToScroll;
}

public void setRowCountView(RowCountView view) {
this.rowCountView = view;
}

@Override
public void requestLayout() {
super.requestLayout();
post(measureAndLayout);
return;
if(rowCountView == null) {
return;
}
post(() -> {
if(linearLayout == null || dataProvider == null) {
return;
}
int windowMin = linearLayout.findFirstVisibleItemPosition() + 1;
int windowMax = linearLayout.findLastVisibleItemPosition() + 1;
int total = dataProvider.dataSize.qcy;
rowCountView.update(windowMin, windowMax, total);
});
}

class OnScrollListener extends RecyclerView.OnScrollListener {
Expand Down Expand Up @@ -87,11 +104,7 @@ public void onScrolled(@NonNull RecyclerView rv, int dx, int dy) {
public void onScrollStateChanged(int state) {
super.onScrollStateChanged(state);

active = true;
if(state == SCROLL_STATE_IDLE) {
active = false;
}

active = state != SCROLL_STATE_IDLE;
}

private final Runnable measureAndLayout = () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ protected void onDraw(Canvas canvas) {
int height = getHeight() - top;
if(firstColumnHeader != null && this.column == 0) {
if(this.pressed) {
canvas.drawLine(width, top, width, height, linePaint);
canvas.drawLine(width, top, width, height - TableTheme.headerHeight, linePaint);
} else {
return;
}
}
canvas.drawLine(width, top, width, height, linePaint);
canvas.drawLine(width, top, width, height - TableTheme.headerHeight, linePaint);
}

public void setFirstColumnHeader(HeaderCell cell) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.qliktrialreactnativestraighttable;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.text.Layout;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

@SuppressLint("ViewConstructor")
public class RowCountView extends RelativeLayout {
final int margin = (int)PixelUtils.dpToPx(8);
RelativeLayout container;
TextView textView;

public RowCountView(Context context, TableView tableView) {
super(context);
int height = tableView.getMeasuredHeight();

textView = new TextView(context);
textView.setSingleLine();
RelativeLayout.LayoutParams textLayout = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
textLayout.rightMargin = margin;
textLayout.topMargin = margin;
textView.setLayoutParams(textLayout);

container = new RelativeLayout(context);
container.setGravity(Gravity.RIGHT);
FrameLayout.LayoutParams frameLayout = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, TableTheme.headerHeight);
container.setLayoutParams(frameLayout);
container.setZ(4);
container.setY(height - TableTheme.headerHeight);
container.setBackgroundColor(Color.WHITE);

container.addView(textView);
addView(container);
}

public void update(int windowMin, int windowMax, int total) {
String text = windowMin + " - " + windowMax + " of " + total; // TODO: Translate
textView.setText(text);
textView.postInvalidate();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.graphics.Color;
import android.text.Layout;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.FrameLayout;
Expand All @@ -17,6 +16,7 @@ public class TableViewFactory {
public CustomHorizontalScrollView scrollView;
public RootLayout rootLayout;
public HeaderView headerView;
public RowCountView rowCountView;
public CustomRecyclerView firstColumnRecyclerView;
public CustomRecyclerView coupledRecyclerView;
public List<GrabberView> grabbers = null;
Expand Down Expand Up @@ -80,12 +80,14 @@ protected void createRecyclerViews() {
coupledRecyclerView = new CustomRecyclerView(context, false, dataProvider, tableView, linearLayout, dragBox, firstColumnDragBox);
FrameLayout.LayoutParams recyclerViewLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
recyclerViewLayoutParams.topMargin = TableTheme.headerHeight;
recyclerViewLayoutParams.bottomMargin = TableTheme.headerHeight;
rootLayout.addView(coupledRecyclerView, recyclerViewLayoutParams);

LinearLayoutManager firstColumnLinearLayout = new LinearLayoutManager(context);
firstColumnRecyclerView = new CustomRecyclerView(context, true, dataProvider, tableView, firstColumnLinearLayout, dragBox, firstColumnDragBox);
FrameLayout.LayoutParams firstColumnViewLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
firstColumnViewLayoutParams.topMargin = TableTheme.headerHeight;
firstColumnViewLayoutParams.bottomMargin = TableTheme.headerHeight;
if(tableView.isFirstColumnFrozen) {
firstColumnHeaderCell = HeaderViewFactory.buildFixedColumnCell(rootLayout, dataColumns.get(0), tableView);
dataProvider.setFirstColumnFrozen(true);
Expand All @@ -100,6 +102,14 @@ protected void createRecyclerViews() {
tableView.addView(firstColumnDragBox);
}

createRowCount();
}

protected void createRowCount() {
rowCountView = new RowCountView(context, tableView);
coupledRecyclerView.setRowCountView(rowCountView);
tableView.addView(rowCountView);

createGrabbers();
}

Expand Down

0 comments on commit 8b347a3

Please sign in to comment.