use of net.osmand.plus.views.controls.ReorderItemTouchHelperCallback in project Osmand by osmandapp.
the class EditProfilesFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
OsmandApplication app = requireMyApplication();
if (savedInstanceState != null && savedInstanceState.containsKey(APP_MODES_ORDER_KEY) && savedInstanceState.containsKey(DELETED_APP_MODES_KEY)) {
appModesOrders = (HashMap<String, Integer>) savedInstanceState.getSerializable(APP_MODES_ORDER_KEY);
deletedModesKeys = savedInstanceState.getStringArrayList(DELETED_APP_MODES_KEY);
} else {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
appModesOrders.put(mode.getStringKey(), mode.getOrder());
}
}
nightMode = !app.getSettings().isLightContent();
View mainView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.edit_arrangement_list_fragment, container, false);
AppBarLayout appbar = mainView.findViewById(R.id.appbar);
View toolbar = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.global_preference_toolbar, container, false);
appbar.addView(toolbar);
ImageButton closeButton = mainView.findViewById(R.id.close_button);
closeButton.setImageResource(R.drawable.ic_action_remove_dark);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentActivity fragmentActivity = getActivity();
if (fragmentActivity != null) {
fragmentActivity.onBackPressed();
}
}
});
TextView toolbarTitle = mainView.findViewById(R.id.toolbar_title);
toolbarTitle.setText(R.string.edit_profiles);
RecyclerView recyclerView = mainView.findViewById(R.id.profiles_list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
adapter = new EditProfilesAdapter(app);
updateItems();
final ItemTouchHelper touchHelper = new ItemTouchHelper(new ReorderItemTouchHelperCallback(adapter));
touchHelper.attachToRecyclerView(recyclerView);
adapter.setAdapterListener(new ProfilesAdapterListener() {
private int fromPosition;
private int toPosition;
@Override
public void onDragStarted(RecyclerView.ViewHolder holder) {
fromPosition = holder.getAdapterPosition();
touchHelper.startDrag(holder);
}
@Override
public void onDragOrSwipeEnded(RecyclerView.ViewHolder holder) {
toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
adapter.notifyDataSetChanged();
}
}
@Override
public void onButtonClicked(int pos) {
Object item = adapter.getItem(pos);
if (item instanceof EditProfileDataObject) {
EditProfileDataObject profileDataObject = (EditProfileDataObject) item;
profileDataObject.toggleDeleted();
if (profileDataObject.deleted) {
deletedModesKeys.add(profileDataObject.getStringKey());
} else {
deletedModesKeys.remove(profileDataObject.getStringKey());
}
updateItems();
}
}
});
recyclerView.setAdapter(adapter);
View cancelButton = mainView.findViewById(R.id.dismiss_button);
UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentActivity fragmentActivity = getActivity();
if (fragmentActivity != null) {
fragmentActivity.onBackPressed();
}
}
});
mainView.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE);
View applyButton = mainView.findViewById(R.id.right_bottom_button);
UiUtilities.setupDialogButton(nightMode, applyButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_apply);
applyButton.setVisibility(View.VISIBLE);
applyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
if (!deletedModesKeys.isEmpty()) {
List<ApplicationMode> deletedModes = new ArrayList<>();
for (String modeKey : deletedModesKeys) {
ApplicationMode mode = ApplicationMode.valueOfStringKey(modeKey, null);
if (mode != null) {
deletedModes.add(mode);
}
}
ApplicationMode.deleteCustomModes(deletedModes, app);
}
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
String modeKey = mode.getStringKey();
Integer order = appModesOrders.get(modeKey);
if (order == null) {
order = mode.getOrder();
}
mode.setOrder(order);
}
ApplicationMode.reorderAppModes();
mapActivity.onBackPressed();
}
}
});
if (Build.VERSION.SDK_INT >= 21) {
AndroidUtils.addStatusBarPadding21v(app, mainView);
}
return mainView;
}
use of net.osmand.plus.views.controls.ReorderItemTouchHelperCallback in project Osmand by osmandapp.
the class RearrangePoiFiltersFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final OsmandApplication app = requireMyApplication();
final boolean nightMode = isNightMode(app, usedOnMap);
View mainView = UiUtilities.getInflater(app, nightMode).inflate(R.layout.edit_arrangement_list_fragment, container, false);
createToolbar(mainView, nightMode);
RecyclerView recyclerView = mainView.findViewById(R.id.profiles_list);
recyclerView.setLayoutManager(new LinearLayoutManager(app));
adapter = new EditPoiFiltersAdapter(app, nightMode);
initFiltersOrders(app, false);
final ItemTouchHelper touchHelper = new ItemTouchHelper(new ReorderItemTouchHelperCallback(adapter));
touchHelper.attachToRecyclerView(recyclerView);
orderModified = app.getSettings().POI_FILTERS_ORDER.get() != null;
activationModified = app.getSettings().INACTIVE_POI_FILTERS.get() != null;
adapter.setListener(new PoiAdapterListener() {
private int fromPosition;
private int toPosition;
@Override
public void onDragStarted(RecyclerView.ViewHolder holder) {
fromPosition = holder.getAdapterPosition();
touchHelper.startDrag(holder);
}
@Override
public void onDragOrSwipeEnded(RecyclerView.ViewHolder holder) {
toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
adapter.notifyDataSetChanged();
}
}
@Override
public void onButtonClicked(int pos) {
ListItem item = items.get(pos);
if (item.value instanceof PoiUIFilterDataObject) {
isChanged = true;
activationModified = true;
PoiUIFilterDataObject poiInfo = (PoiUIFilterDataObject) item.value;
poiInfo.toggleActive();
if (!poiInfo.isActive) {
availableFiltersKeys.add(poiInfo.filterId);
} else {
availableFiltersKeys.remove(poiInfo.filterId);
}
updateItems();
}
}
@Override
public void onDeleteClicked(final int position) {
final ListItem item = items.get(position);
if (item.value instanceof PoiUIFilterDataObject) {
PoiUIFilterDataObject poiInfo = (PoiUIFilterDataObject) item.value;
final PoiUIFilter filter = app.getPoiFilters().getFilterById(poiInfo.filterId);
if (filter != null && app.getPoiFilters().removePoiFilter(filter)) {
filter.setDeleted(true);
filterDeleted = true;
}
items.remove(item);
adapter.notifyDataSetChanged();
Snackbar snackbar = Snackbar.make(requireView(), getString(R.string.item_deleted, poiInfo.name), Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
items.add(position, item);
adapter.notifyDataSetChanged();
if (filter != null) {
filter.setDeleted(false);
app.getPoiFilters().createPoiFilter(filter, false);
}
}
});
ViewCompat.setElevation(snackbar.getView(), 0f);
snackbar.setAnchorView(buttonsContainer);
snackbar.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_FADE);
UiUtilities.setupSnackbar(snackbar, nightMode);
snackbar.show();
}
}
});
recyclerView.setAdapter(adapter);
View cancelButton = mainView.findViewById(R.id.dismiss_button);
UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
mainView.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE);
View applyButton = mainView.findViewById(R.id.right_bottom_button);
UiUtilities.setupDialogButton(nightMode, applyButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_apply);
applyButton.setVisibility(View.VISIBLE);
applyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ApplicationMode selectedAppMode = getSelectedAppMode();
if (isChanged) {
if (activationModified) {
app.getPoiFilters().saveInactiveFilters(selectedAppMode, availableFiltersKeys);
} else if (wasReset) {
app.getPoiFilters().saveInactiveFilters(selectedAppMode, null);
}
if (orderModified) {
List<PoiUIFilter> dataToSave = new ArrayList<>();
for (PoiUIFilter filter : getSortedPoiUiFilters(selectedAppMode, app)) {
String filterId = filter.getFilterId();
Integer order = poiFiltersOrders.get(filterId);
if (order == null) {
order = filter.getOrder();
}
boolean isActive = !availableFiltersKeys.contains(filterId);
filter.setActive(isActive);
filter.setOrder(order);
if (isActive) {
dataToSave.add(filter);
}
}
Collections.sort(dataToSave);
List<String> filterIds = new ArrayList<>();
for (PoiUIFilter filter : dataToSave) {
filterIds.add(filter.getFilterId());
}
app.getPoiFilters().saveFiltersOrder(selectedAppMode, filterIds);
} else if (wasReset) {
app.getPoiFilters().saveFiltersOrder(selectedAppMode, null);
}
}
if (resultCallback != null) {
resultCallback.onApplyPoiFiltersState(selectedAppMode, isChanged);
}
dismiss();
}
});
buttonsContainer = mainView.findViewById(R.id.buttons_container);
return mainView;
}
use of net.osmand.plus.views.controls.ReorderItemTouchHelperCallback in project Osmand by osmandapp.
the class QuickActionListFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
OsmandApplication app = requireMyApplication();
nightMode = !app.getSettings().isLightContent();
View view = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.quick_action_list, container, false);
rv = (RecyclerView) view.findViewById(R.id.recycler_view);
fab = (FloatingActionButton) view.findViewById(R.id.fabButton);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showAddQuickActionDialog();
}
});
if (Build.VERSION.SDK_INT >= 21) {
AndroidUtils.addStatusBarPadding21v(getContext(), view);
}
bottomPanel = view.findViewById(R.id.bottom_panel);
View btnSelectAll = bottomPanel.findViewById(R.id.select_all);
View btnDelete = bottomPanel.findViewById(R.id.delete);
btnSelectAll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
actionsToDelete.clear();
for (QuickAction action : adapter.getQuickActions()) {
actionsToDelete.add(action.id);
}
updateListItems();
updateToolbarTitle();
}
});
btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showConfirmDeleteActionsBottomSheet(getMapActivity());
}
});
UiUtilities.setupDialogButton(nightMode, btnDelete, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_delete);
quickActionRegistry = requireMyApplication().getQuickActionRegistry();
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
navigationIcon = toolbar.findViewById(R.id.close_button);
deleteIconContainer = toolbar.findViewById(R.id.action_button);
toolbarSwitchContainer = toolbar.findViewById(R.id.toolbar_switch_container);
setUpToolbar();
adapter = new QuickActionAdapter(new OnStartDragListener() {
@Override
public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
touchHelper.startDrag(viewHolder);
}
});
rv.setAdapter(adapter);
rv.setLayoutManager(new LinearLayoutManager(getContext()));
ItemTouchHelper.Callback touchHelperCallback = new ReorderItemTouchHelperCallback(adapter);
touchHelper = new ItemTouchHelper(touchHelperCallback);
touchHelper.attachToRecyclerView(rv);
rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
if (screenType == SCREEN_TYPE_REORDER) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
fab.hide();
} else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
fab.show();
}
}
}
});
updateListItems();
updateVisibility();
return view;
}
use of net.osmand.plus.views.controls.ReorderItemTouchHelperCallback in project Osmand by osmandapp.
the class SwitchableAction method drawUI.
@Override
public void drawUI(@NonNull ViewGroup parent, @NonNull final MapActivity mapActivity) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.quick_action_switchable_action, parent, false);
final SwitchCompat showDialog = view.findViewById(R.id.saveButton);
if (!getParams().isEmpty()) {
showDialog.setChecked(Boolean.valueOf(getParams().get(KEY_DIALOG)));
}
view.findViewById(R.id.saveButtonContainer).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean selected = showDialog.isChecked();
showDialog.setChecked(!selected);
}
});
RecyclerView list = view.findViewById(R.id.list);
adapter = new Adapter(mapActivity, new QuickActionListFragment.OnStartDragListener() {
@Override
public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
touchHelper.startDrag(viewHolder);
}
});
ReorderItemTouchHelperCallback touchHelperCallback = new ReorderItemTouchHelperCallback(adapter);
touchHelper = new ItemTouchHelper(touchHelperCallback);
touchHelper.attachToRecyclerView(list);
if (!getParams().isEmpty()) {
adapter.addItems(loadListFromParams());
}
list.setAdapter(adapter);
TextView dscrTitle = view.findViewById(R.id.textDscrTitle);
TextView dscrHint = view.findViewById(R.id.textDscrHint);
Button addBtn = view.findViewById(R.id.btnAdd);
dscrTitle.setText(parent.getContext().getString(getDiscrTitle()) + ":");
dscrHint.setText(getDiscrHint());
addBtn.setText(getAddBtnText());
addBtn.setOnClickListener(getOnAddBtnClickListener(mapActivity, adapter));
parent.addView(view);
}
use of net.osmand.plus.views.controls.ReorderItemTouchHelperCallback in project Osmand by osmandapp.
the class PointsCard method updateContent.
@Override
protected void updateContent() {
MeasurementEditingContext editingCtx = fragment.getEditingCtx();
adapter = new MeasurementToolAdapter(mapActivity, editingCtx.getPoints());
RecyclerView pointsRv = view.findViewById(R.id.measure_points_recycler_view);
ItemTouchHelper touchHelper = new ItemTouchHelper(new ReorderItemTouchHelperCallback(adapter));
touchHelper.attachToRecyclerView(pointsRv);
adapter.setAdapterListener(fragment.createMeasurementAdapterListener(touchHelper));
pointsRv.setLayoutManager(new LinearLayoutManager(app));
pointsRv.setAdapter(adapter);
}
Aggregations