Fix review
This commit is contained in:
parent
7e91b31461
commit
4030992ec2
4 changed files with 49 additions and 49 deletions
|
@ -45,6 +45,7 @@ import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||||
import net.osmand.plus.helpers.ColorDialogs;
|
import net.osmand.plus.helpers.ColorDialogs;
|
||||||
|
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
|
||||||
import net.osmand.plus.widgets.FlowLayout;
|
import net.osmand.plus.widgets.FlowLayout;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
@ -461,26 +462,21 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IconCategoriesAdapter iconCategoriesAdapter = new IconCategoriesAdapter(app);
|
HorizontalSelectionAdapter horizontalSelectionAdapter = new HorizontalSelectionAdapter(app, nightMode);
|
||||||
iconCategoriesAdapter.setItems(new ArrayList<>(iconCategories.keySet()));
|
horizontalSelectionAdapter.setItems(new ArrayList<>(iconCategories.keySet()));
|
||||||
iconCategoriesAdapter.setListenerCategory(new IconCategoriesAdapter.IconCategoriesAdapterListener() {
|
horizontalSelectionAdapter.setListener(new HorizontalSelectionAdapter.HorizontalSelectionAdapterListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(String item) {
|
public void onItemSelected(String item) {
|
||||||
selectedIconCategory = item;
|
selectedIconCategory = item;
|
||||||
createIconForCategory();
|
createIconForCategory();
|
||||||
updateIconSelector(selectedIcon, PointEditorFragmentNew.this.view);
|
updateIconSelector(selectedIcon, PointEditorFragmentNew.this.view);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSelectedItem() {
|
|
||||||
return selectedIconCategory;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
RecyclerView iconCategoriesRecyclerView = view.findViewById(R.id.group_name_recycler_view);
|
RecyclerView iconCategoriesRecyclerView = view.findViewById(R.id.group_name_recycler_view);
|
||||||
iconCategoriesRecyclerView.setAdapter(iconCategoriesAdapter);
|
iconCategoriesRecyclerView.setAdapter(horizontalSelectionAdapter);
|
||||||
iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false));
|
iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false));
|
||||||
iconCategoriesAdapter.notifyDataSetChanged();
|
horizontalSelectionAdapter.notifyDataSetChanged();
|
||||||
iconCategoriesRecyclerView.smoothScrollToPosition(iconCategoriesAdapter.getItemPosition(selectedIconCategory));
|
iconCategoriesRecyclerView.smoothScrollToPosition(horizontalSelectionAdapter.getItemPosition(selectedIconCategory));
|
||||||
for (String name : iconNameList) {
|
for (String name : iconNameList) {
|
||||||
selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(0, 0));
|
selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(0, 0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package net.osmand.plus.mapcontextmenu.editors;
|
package net.osmand.plus.mapcontextmenu.other;
|
||||||
|
|
||||||
import android.graphics.drawable.GradientDrawable;
|
import android.graphics.drawable.GradientDrawable;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
@ -15,22 +14,25 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.UiUtilities;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
|
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
|
||||||
|
|
||||||
|
|
||||||
public class IconCategoriesAdapter extends RecyclerView.Adapter<IconCategoriesAdapter.NameViewHolder> {
|
public class HorizontalSelectionAdapter extends RecyclerView.Adapter<HorizontalSelectionAdapter.ItemViewHolder> {
|
||||||
|
|
||||||
private List<String> items;
|
private List<String> items;
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private boolean nightMode;
|
private boolean nightMode;
|
||||||
private IconCategoriesAdapterListener listenerCategory;
|
private HorizontalSelectionAdapterListener listener;
|
||||||
|
|
||||||
public IconCategoriesAdapter(OsmandApplication app) {
|
private String selectedItem = "";
|
||||||
|
|
||||||
|
public HorizontalSelectionAdapter(OsmandApplication app, boolean nightMode) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
nightMode = app.getDaynightHelper().isNightModeForMapControls();
|
this.nightMode = nightMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItems(List<String> items) {
|
public void setItems(List<String> items) {
|
||||||
|
@ -39,18 +41,18 @@ public class IconCategoriesAdapter extends RecyclerView.Adapter<IconCategoriesAd
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public NameViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View view;
|
View view;
|
||||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.point_editor_icon_category_item, parent, false);
|
view = UiUtilities.getInflater(parent.getContext(), nightMode).inflate(R.layout.point_editor_icon_category_item, parent, false);
|
||||||
return new NameViewHolder(view);
|
return new ItemViewHolder(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull NameViewHolder holder, final int position) {
|
public void onBindViewHolder(@NonNull ItemViewHolder holder, final int position) {
|
||||||
final String category = items.get(holder.getAdapterPosition());
|
final String item = items.get(holder.getAdapterPosition());
|
||||||
TextView textView = holder.buttonText;
|
TextView textView = holder.buttonText;
|
||||||
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
|
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
|
||||||
if (category.equals(listenerCategory.getSelectedItem())) {
|
if (item.equals(selectedItem)) {
|
||||||
AndroidUtils.setBackground(holder.button, app.getUIUtilities().getPaintedIcon(R.drawable.bg_select_icon_group_button,
|
AndroidUtils.setBackground(holder.button, app.getUIUtilities().getPaintedIcon(R.drawable.bg_select_icon_group_button,
|
||||||
ContextCompat.getColor(app, activeColorResId)));
|
ContextCompat.getColor(app, activeColorResId)));
|
||||||
textView.setTextColor(ContextCompat.getColor(app, R.color.color_white));
|
textView.setTextColor(ContextCompat.getColor(app, R.color.color_white));
|
||||||
|
@ -64,12 +66,13 @@ public class IconCategoriesAdapter extends RecyclerView.Adapter<IconCategoriesAd
|
||||||
buttonBackground.setColor(ContextCompat.getColor(app, R.color.color_transparent));
|
buttonBackground.setColor(ContextCompat.getColor(app, R.color.color_transparent));
|
||||||
AndroidUtils.setBackground(holder.button, buttonBackground);
|
AndroidUtils.setBackground(holder.button, buttonBackground);
|
||||||
}
|
}
|
||||||
textView.setText(capitalizeFirstLetter(category));
|
textView.setText(capitalizeFirstLetter(item));
|
||||||
holder.button.setOnClickListener(new View.OnClickListener() {
|
holder.button.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (listenerCategory != null) {
|
selectedItem = item;
|
||||||
listenerCategory.onItemClick(category);
|
if (listener != null) {
|
||||||
|
listener.onItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -80,25 +83,29 @@ public class IconCategoriesAdapter extends RecyclerView.Adapter<IconCategoriesAd
|
||||||
return items.size();
|
return items.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int getItemPosition(String name) {
|
public int getItemPosition(String name) {
|
||||||
return items.indexOf(name);
|
return items.indexOf(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setListenerCategory(IconCategoriesAdapterListener listenerCategory) {
|
public void setSelectedItem(String selectedItem) {
|
||||||
this.listenerCategory = listenerCategory;
|
this.selectedItem = selectedItem;
|
||||||
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IconCategoriesAdapterListener {
|
public void setListener(HorizontalSelectionAdapterListener listener) {
|
||||||
void onItemClick(String item);
|
this.listener = listener;
|
||||||
|
|
||||||
String getSelectedItem();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class NameViewHolder extends RecyclerView.ViewHolder {
|
public interface HorizontalSelectionAdapterListener {
|
||||||
|
|
||||||
|
void onItemSelected(String item);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ItemViewHolder extends RecyclerView.ViewHolder {
|
||||||
final TextView buttonText;
|
final TextView buttonText;
|
||||||
final LinearLayout button;
|
final LinearLayout button;
|
||||||
|
|
||||||
NameViewHolder(@NonNull View itemView) {
|
ItemViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
buttonText = itemView.findViewById(R.id.button_text);
|
buttonText = itemView.findViewById(R.id.button_text);
|
||||||
button = itemView.findViewById(R.id.button_container);
|
button = itemView.findViewById(R.id.button_container);
|
|
@ -22,7 +22,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
import net.osmand.plus.mapcontextmenu.editors.IconCategoriesAdapter;
|
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.settings.fragments.ApplyQueryType;
|
import net.osmand.plus.settings.fragments.ApplyQueryType;
|
||||||
import net.osmand.plus.settings.fragments.OnConfirmPreferenceChange;
|
import net.osmand.plus.settings.fragments.OnConfirmPreferenceChange;
|
||||||
|
@ -124,12 +124,13 @@ public class VehicleParametersNumericBottomSheet extends BasePreferenceBottomShe
|
||||||
private BaseBottomSheetItem createComboView(OsmandApplication app, final SizePreference preference) {
|
private BaseBottomSheetItem createComboView(OsmandApplication app, final SizePreference preference) {
|
||||||
View mainView = UiUtilities.getMaterialInflater(app, nightMode)
|
View mainView = UiUtilities.getMaterialInflater(app, nightMode)
|
||||||
.inflate(R.layout.bottom_sheet_item_edit_with_recyclerview, null);
|
.inflate(R.layout.bottom_sheet_item_edit_with_recyclerview, null);
|
||||||
final IconCategoriesAdapter adapter = new IconCategoriesAdapter(app);
|
final HorizontalSelectionAdapter adapter = new HorizontalSelectionAdapter(app, nightMode);
|
||||||
final TextView metric = mainView.findViewById(R.id.metric);
|
final TextView metric = mainView.findViewById(R.id.metric);
|
||||||
metric.setText(app.getString(preference.getAssets().getMetricRes()));
|
metric.setText(app.getString(preference.getAssets().getMetricRes()));
|
||||||
final TextView text = mainView.findViewById(R.id.text_edit);
|
final TextView text = mainView.findViewById(R.id.text_edit);
|
||||||
currentValue = Float.parseFloat(preference.getValue());
|
currentValue = Float.parseFloat(preference.getValue());
|
||||||
selectedItem = preference.getEntryFromValue(preference.getValue());
|
selectedItem = preference.getEntryFromValue(preference.getValue());
|
||||||
|
|
||||||
String currentValueStr = currentValue == 0.0f ? "" : String.valueOf(currentValue + 0.01f);
|
String currentValueStr = currentValue == 0.0f ? "" : String.valueOf(currentValue + 0.01f);
|
||||||
text.setText(currentValueStr);
|
text.setText(currentValueStr);
|
||||||
text.addTextChangedListener(new TextWatcher() {
|
text.addTextChangedListener(new TextWatcher() {
|
||||||
|
@ -149,30 +150,25 @@ public class VehicleParametersNumericBottomSheet extends BasePreferenceBottomShe
|
||||||
currentValue = 0.0f;
|
currentValue = 0.0f;
|
||||||
}
|
}
|
||||||
selectedItem = preference.getEntryFromValue(String.valueOf(currentValue));
|
selectedItem = preference.getEntryFromValue(String.valueOf(currentValue));
|
||||||
adapter.notifyDataSetChanged();
|
adapter.setSelectedItem(selectedItem);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
adapter.setItems(Arrays.asList(preference.getEntries()));
|
adapter.setItems(Arrays.asList(preference.getEntries()));
|
||||||
adapter.setListenerCategory(new IconCategoriesAdapter.IconCategoriesAdapterListener() {
|
adapter.setListener(new HorizontalSelectionAdapter.HorizontalSelectionAdapterListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(String item) {
|
public void onItemSelected(String item) {
|
||||||
selectedItem = item;
|
selectedItem = item;
|
||||||
currentValue = preference.getValueFromEntries(selectedItem);
|
currentValue = preference.getValueFromEntries(selectedItem);
|
||||||
String currentValueStr = currentValue == 0.0f ? "" : String.valueOf(currentValue + 0.01f);
|
String currentValueStr = currentValue == 0.0f ? "" : String.valueOf(currentValue + 0.01f);
|
||||||
text.setText(currentValueStr);
|
text.setText(currentValueStr);
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSelectedItem() {
|
|
||||||
return selectedItem;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
RecyclerView recyclerView = mainView.findViewById(R.id.recycler_view);
|
RecyclerView recyclerView = mainView.findViewById(R.id.recycler_view);
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
adapter.notifyDataSetChanged();
|
adapter.setSelectedItem(selectedItem);
|
||||||
return new BaseBottomSheetItem.Builder()
|
return new BaseBottomSheetItem.Builder()
|
||||||
.setCustomView(mainView)
|
.setCustomView(mainView)
|
||||||
.create();
|
.create();
|
||||||
|
@ -189,7 +185,7 @@ public class VehicleParametersNumericBottomSheet extends BasePreferenceBottomShe
|
||||||
if (target instanceof OnConfirmPreferenceChange) {
|
if (target instanceof OnConfirmPreferenceChange) {
|
||||||
|
|
||||||
((OnConfirmPreferenceChange) target).onConfirmPreferenceChange(
|
((OnConfirmPreferenceChange) target).onConfirmPreferenceChange(
|
||||||
getPreference().getKey(), String.valueOf(currentValue), ApplyQueryType.BOTTOM_SHEET);
|
getPreference().getKey(), String.valueOf(currentValue), ApplyQueryType.SNACK_BAR);
|
||||||
}
|
}
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,8 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
|
||||||
if (preference instanceof SizePreference) {
|
if (preference instanceof SizePreference) {
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
if (fragmentManager != null) {
|
if (fragmentManager != null) {
|
||||||
VehicleParametersNumericBottomSheet.showInstance(getFragmentManager(), preference.getKey(), this, false, getSelectedAppMode());
|
VehicleParametersNumericBottomSheet.showInstance(fragmentManager, preference.getKey(),
|
||||||
|
this, false, getSelectedAppMode());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super.onDisplayPreferenceDialog(preference);
|
super.onDisplayPreferenceDialog(preference);
|
||||||
|
|
Loading…
Reference in a new issue