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

feat(md-3747): translations android #107

Merged
merged 2 commits into from
Nov 2, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public class CellView extends LinearLayout implements SelectionsObserver {
}
return true;
};
View.OnCreateContextMenuListener onCreateContextMenuListener = (contextMenu, view, contextMenuInfo) -> contextMenu.add(0, 0, 0, "Copy").setOnMenuItemClickListener(handleMenuItemClick);
String copyString = tableView.getTranslation("menu", "copy");
View.OnCreateContextMenuListener onCreateContextMenuListener = (contextMenu, view, contextMenuInfo) -> contextMenu.add(0, 0, 0, copyString).setOnMenuItemClickListener(handleMenuItemClick);
View contentView = (View) content;
contentView.setOnCreateContextMenuListener(onCreateContextMenuListener);
this.addView(contentView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ public void updateLayout() {
}

public void testTextWrap() {
for (int i = 0; i < this.dataColumns.size(); i++){
HeaderCell headerCell = (HeaderCell)this.getChildAt(i);
for (int i = 0; i < this.dataColumns.size(); i++) {
HeaderCell headerCell = (HeaderCell) this.getChildAt(i);
headerCell.testTextWrap();
}

}

public int getMaxLineCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ static String getString(ReadableMap data, String key) {
return data.hasKey(key) ? data.getString(key) : null;
}

static String getString(ReadableMap data, String key, String defaultValue) {
return data.hasKey(key) ? data.getString(key) : defaultValue;
}

static int getInt(ReadableMap data, String key, int defaultValue) {
return data.hasKey(key) ? data.getInt(key) : defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public void setTheme(View view, ReadableMap theme) {

}

@ReactProp(name = "translations")
public void setTranslations(View view, @Nullable ReadableMap translations) {
TableView tableView = (TableView) (view);
tableView.setTranslations(translations);
}

@ReactProp(name = "freezeFirstColumn")
public void setFreezeFirstColumn(View view, Boolean value) {
TableView tableView = (TableView) view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

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

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

textView = new TextView(context);
textView.setSingleLine();
Expand All @@ -42,7 +44,9 @@ public RowCountView(Context context, TableView tableView) {
}

public void update(int windowMin, int windowMax, int total) {
String text = windowMin + " - " + windowMax + " of " + total; // TODO: Translate
String ofString = tableView.getTranslation("misc", "of");

String text = windowMin + " - " + windowMax + " " + ofString + " " + total;
textView.setText(text);
textView.postInvalidate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.widget.FrameLayout;
import androidx.annotation.RequiresApi;

import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.views.text.ReactFontManager;

Expand All @@ -33,6 +34,7 @@ public class TableView extends FrameLayout {
HeaderCell firstColumnHeaderCell = null;
ScreenGuideView screenGuideView = null;
SelectionsEngine selectionsEngine = new SelectionsEngine();
ReadableMap translations;
final ColumnWidths columnWidths ;
DataProvider dataProvider;
boolean isFirstColumnFrozen = false;
Expand Down Expand Up @@ -85,6 +87,19 @@ public void setFirstColumnFrozen(boolean shouldFreeze) {
dataProvider.setFirstColumnFrozen(shouldFreeze);
}

public void setTranslations(ReadableMap translations) {
this.translations = translations;
}

public String getTranslation(String mapKey, String stringKey) {
String defaultString = mapKey + "." + stringKey;
ReadableMap map = translations.getMap(mapKey);
if(map == null) {
return defaultString;
}
return JsonUtils.getString(map, stringKey, defaultString);
}

public void setName(String value) {
this.name = value;
columnWidths.setName(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

import android.content.Context;
import android.graphics.Color;
import android.text.Layout;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ScrollView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -90,7 +97,7 @@ protected void createRecyclerViews() {
coupledRecyclerView.setAdapter(dataProvider);

FrameLayout.LayoutParams recyclerViewLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
recyclerViewLayoutParams.topMargin = tableView.headerHeight;
recyclerViewLayoutParams.topMargin = TableTheme.rowHeightFactor;
recyclerViewLayoutParams.bottomMargin = TableTheme.rowHeightFactor;
rootLayout.addView(coupledRecyclerView, recyclerViewLayoutParams);

Expand All @@ -99,9 +106,9 @@ protected void createRecyclerViews() {
firstColumnLinearLayout.recyclerView = firstColumnRecyclerView;
firstColumnRecyclerView.setAdapter(dataProvider);
FrameLayout.LayoutParams firstColumnViewLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
firstColumnViewLayoutParams.topMargin = tableView.headerHeight;
firstColumnViewLayoutParams.topMargin = TableTheme.rowHeightFactor;
firstColumnViewLayoutParams.bottomMargin = TableTheme.rowHeightFactor;
if(tableView.isFirstColumnFrozen) {
if (tableView.isFirstColumnFrozen) {
firstColumnHeaderCell = HeaderViewFactory.buildFixedColumnCell(rootLayout, dataColumns.get(0), tableView);
dataProvider.setFirstColumnFrozen(true);
coupledRecyclerView.setViewToScrollCouple(firstColumnRecyclerView);
Expand Down
3 changes: 3 additions & 0 deletions src/components/SimpleGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export type SimpleGridProps = {
copy: string;
expand: string;
};
misc: {
of: string;
}
};
};

Expand Down