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