Merge pull request #9332 from osmandapp/rearrange_categories_refactor
Rearrange categories refactor
This commit is contained in:
commit
61f6b93d18
1 changed files with 52 additions and 42 deletions
|
@ -30,6 +30,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.snackbar.BaseTransientBottomBar;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
|
@ -106,7 +107,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
|
|||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
final OsmandApplication app = requireMyApplication();
|
||||
|
||||
boolean nightMode = isNightMode(app, usedOnMap);
|
||||
final boolean nightMode = isNightMode(app, usedOnMap);
|
||||
|
||||
View mainView = UiUtilities.getInflater(app, nightMode).inflate(R.layout.edit_arrangement_list_fragment, container, false);
|
||||
createToolbar(mainView, nightMode);
|
||||
|
@ -158,6 +159,39 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
|
|||
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);
|
||||
|
||||
|
@ -577,19 +611,23 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
|
|||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onBindViewHolder(final @NonNull RecyclerView.ViewHolder holder, final int position) {
|
||||
final ListItem item = items.get(position);
|
||||
final boolean nightMode = isNightMode(app, usedOnMap);
|
||||
public void onBindViewHolder(final @NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
ListItem item = items.get(position);
|
||||
boolean nightMode = isNightMode(app, usedOnMap);
|
||||
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
|
||||
if (holder instanceof PoiViewHolder) {
|
||||
PoiViewHolder h = (PoiViewHolder) holder;
|
||||
final PoiUIFilterDataObject poiInfo = (PoiUIFilterDataObject) item.value;
|
||||
PoiUIFilterDataObject poiInfo = (PoiUIFilterDataObject) item.value;
|
||||
int osmandOrangeColorResId = nightMode ? R.color.osmand_orange_dark : R.color.osmand_orange;
|
||||
boolean isActive = poiInfo.isActive;
|
||||
h.title.setText(poiInfo.name);
|
||||
int padding = (int) getResources().getDimension(R.dimen.content_padding);
|
||||
int paddingSmall = (int) getResources().getDimension(R.dimen.content_padding_small);
|
||||
h.title.setPadding(isActive ? 0 : padding, paddingSmall, paddingSmall, padding);
|
||||
boolean userFilter = poiInfo.filterId.startsWith(USER_PREFIX);
|
||||
int iconRes = QuickSearchListItem.getCustomFilterIconRes(poiHelper.getFilterById(poiInfo.filterId));
|
||||
h.icon.setImageDrawable(uiUtilities.getIcon(userFilter ? iconRes : poiInfo.iconRes, osmandOrangeColorResId));
|
||||
h.moveIcon.setVisibility(poiInfo.isActive ? View.VISIBLE : View.GONE);
|
||||
h.moveIcon.setVisibility(isActive ? View.VISIBLE : View.GONE);
|
||||
h.actionIcon.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -599,7 +637,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
|
|||
}
|
||||
}
|
||||
});
|
||||
if (poiInfo.isActive) {
|
||||
if (isActive) {
|
||||
h.actionIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_remove, R.color.color_osm_edit_delete));
|
||||
h.moveIcon.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
|
@ -618,40 +656,10 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
|
|||
h.actionDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
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);
|
||||
notifyDataSetChanged();
|
||||
int pos = holder.getAdapterPosition();
|
||||
if (listener != null && pos != RecyclerView.NO_POSITION) {
|
||||
listener.onDeleteClicked(pos);
|
||||
}
|
||||
})
|
||||
.addCallback(new Snackbar.Callback() {
|
||||
@Override
|
||||
public void onShown(Snackbar sb) {
|
||||
super.onShown(sb);
|
||||
items.remove(item);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissed(Snackbar transientBottomBar, int event) {
|
||||
super.onDismissed(transientBottomBar, event);
|
||||
if (DISMISS_EVENT_ACTION != event) {
|
||||
PoiUIFilter filter = poiHelper.getFilterById(poiInfo.filterId);
|
||||
if (filter != null && poiHelper.removePoiFilter(filter)) {
|
||||
availableFiltersKeys.remove(poiInfo.filterId);
|
||||
filter.setDeleted(true);
|
||||
filterDeleted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
ViewCompat.setElevation(snackbar.getView(), 0f);
|
||||
snackbar.setAnchorView(buttonsContainer);
|
||||
UiUtilities.setupSnackbar(snackbar, nightMode);
|
||||
snackbar.show();
|
||||
}
|
||||
});
|
||||
} else if (holder instanceof SpaceViewHolder) {
|
||||
|
@ -864,7 +872,9 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
|
|||
|
||||
void onDragOrSwipeEnded(RecyclerView.ViewHolder holder);
|
||||
|
||||
void onButtonClicked(int view);
|
||||
void onButtonClicked(int position);
|
||||
|
||||
void onDeleteClicked(int position);
|
||||
}
|
||||
|
||||
public interface OnApplyPoiFiltersState {
|
||||
|
|
Loading…
Reference in a new issue