Merge pull request #9262 from osmandapp/rearrange_filters_redesign

rearrange filters redesign
This commit is contained in:
vshcherb 2020-06-19 13:05:31 +02:00 committed by GitHub
commit 31125065ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 99 additions and 23 deletions

View file

@ -16,17 +16,16 @@
tools:background="?android:attr/selectableItemBackground">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/action_icon"
android:id="@+id/move_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:minHeight="@dimen/bottom_sheet_list_item_height"
tools:src="@drawable/ic_action_remove"
tools:tint="@color/icon_color_default_light"
android:paddingStart="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding"
android:paddingStart="@dimen/content_padding" />
android:tint="?attr/secondary_icon_color"
osmand:srcCompat="@drawable/ic_action_item_move" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
@ -59,16 +58,30 @@
android:paddingStart="0dp" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/move_icon"
android:id="@+id/action_delete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:paddingEnd="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
tools:src="@drawable/ic_action_delete_item"
tools:tint="@color/icon_color_default_light" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/action_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
osmand:srcCompat="@drawable/ic_action_item_move"
android:tint="?attr/secondary_icon_color"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingStart="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding" />
android:paddingEnd="@dimen/content_padding"
tools:src="@drawable/ic_action_remove"
tools:tint="@color/icon_color_default_light" />
</LinearLayout>

View file

@ -11,6 +11,7 @@
Thx - Hardy
-->
<string name="item_deleted">%1$s deleted</string>
<string name="shared_string_bearing">Bearing</string>
<string name="quick_action_showhide_mapillary_descr">A toggle to show or hide the Mapillary layer on the map.</string>
<string name="quick_action_mapillary_show">Show Mapillary</string>

View file

@ -10,7 +10,6 @@ import net.osmand.PlatformUtil;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.api.SQLiteAPI;
@ -19,7 +18,6 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.plus.api.SQLiteAPI.SQLiteStatement;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.wikipedia.WikipediaPoiMenu;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import org.json.JSONArray;
@ -39,7 +37,6 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import static net.osmand.osm.MapPoiTypes.WIKI_PLACE;
import static net.osmand.plus.wikipedia.WikipediaPoiMenu.ENABLED_WIKI_POI_LANGUAGES_KEY;
import static net.osmand.plus.wikipedia.WikipediaPoiMenu.GLOBAL_WIKI_POI_ENABLED_KEY;
@ -178,7 +175,6 @@ public class PoiFiltersHelper {
helper.close();
}
private PoiUIFilter getFilterById(String filterId, PoiUIFilter... filters) {
for (PoiUIFilter pf : filters) {
if (pf != null && pf.getFilterId() != null && filterId != null && pf.getFilterId().equals(filterId)) {

View file

@ -2,6 +2,7 @@ package net.osmand.plus.poi;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
@ -13,6 +14,7 @@ import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
@ -27,6 +29,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.snackbar.Snackbar;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
@ -47,6 +50,7 @@ import java.util.HashMap;
import java.util.List;
import static net.osmand.plus.poi.PoiUIFilter.CUSTOM_FILTER_ID;
import static net.osmand.plus.poi.PoiUIFilter.USER_PREFIX;
import static net.osmand.plus.poi.RearrangePoiFiltersFragment.ItemType.DESCRIPTION;
import static net.osmand.plus.poi.RearrangePoiFiltersFragment.ItemType.POI;
import static net.osmand.plus.poi.RearrangePoiFiltersFragment.ItemType.SPACE;
@ -67,6 +71,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
private boolean wasReset = false;
private boolean isChanged = false;
private ApplicationMode appMode;
private LinearLayout buttonsContainer;
private HashMap<String, Integer> poiFiltersOrders = new HashMap<>();
private List<String> availableFiltersKeys = new ArrayList<>();
@ -199,7 +204,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
}
app.getPoiFilters().saveFiltersOrder(selectedAppMode, filterIds);
} else if (wasReset) {
app.getPoiFilters().saveFiltersOrder(selectedAppMode,null);
app.getPoiFilters().saveFiltersOrder(selectedAppMode, null);
}
}
if (resultCallback != null) {
@ -208,10 +213,19 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
dismiss();
}
});
buttonsContainer = mainView.findViewById(R.id.buttons_container);
return mainView;
}
@Override
public void onDismiss(@NonNull DialogInterface dialog) {
if (isChanged && !orderModified && !activationModified && resultCallback != null) {
resultCallback.onCustomFiltersDeleted();
}
super.onDismiss(dialog);
}
private void createToolbar(View mainView, boolean nightMode) {
AppBarLayout appbar = mainView.findViewById(R.id.appbar);
View toolbar = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.profile_preference_toolbar_with_icon, appbar, false);
@ -512,6 +526,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
private OsmandApplication app;
private UiUtilities uiUtilities;
private PoiFiltersHelper poiHelper;
private List<ListItem> items = new ArrayList<>();
private boolean nightMode;
@ -520,8 +535,9 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
public EditPoiFiltersAdapter(OsmandApplication app, boolean nightMode) {
setHasStableIds(true);
this.app = app;
this.uiUtilities = app.getUIUtilities();
this.nightMode = nightMode;
uiUtilities = app.getUIUtilities();
poiHelper = app.getPoiFilters();
}
@NonNull
@ -557,13 +573,13 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
@SuppressLint("ClickableViewAccessibility")
@Override
public void onBindViewHolder(final @NonNull RecyclerView.ViewHolder holder, int position) {
ListItem item = items.get(position);
boolean nightMode = isNightMode(app, usedOnMap);
public void onBindViewHolder(final @NonNull RecyclerView.ViewHolder holder, final int position) {
final ListItem item = items.get(position);
final 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;
PoiUIFilterDataObject poiInfo = (PoiUIFilterDataObject) item.value;
final PoiUIFilterDataObject poiInfo = (PoiUIFilterDataObject) item.value;
int osmandOrangeColorResId = nightMode ? R.color.osmand_orange_dark : R.color.osmand_orange;
h.title.setText(poiInfo.name);
h.icon.setImageDrawable(uiUtilities.getIcon(poiInfo.iconRes, osmandOrangeColorResId));
@ -591,6 +607,46 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
} else {
h.actionIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_add, R.color.color_osm_edit_create));
}
boolean userFilter = poiInfo.filterId.startsWith(USER_PREFIX);
h.actionDelete.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_delete_item, R.color.color_osm_edit_delete));
h.actionDelete.setVisibility(userFilter ? View.VISIBLE : View.GONE);
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();
}
})
.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)) {
filter.setDeleted(true);
isChanged = true;
}
}
}
});
snackbar.setAnchorView(buttonsContainer);
UiUtilities.setupSnackbar(snackbar, nightMode);
snackbar.show();
}
});
} else if (holder instanceof SpaceViewHolder) {
float space = (float) item.value;
((SpaceViewHolder) holder).setSpace((int) space);
@ -751,6 +807,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
private TextView description;
private ImageView icon;
private ImageView actionIcon;
private ImageView actionDelete;
private ImageView moveIcon;
private View itemsContainer;
@ -758,6 +815,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
super(itemView);
title = itemView.findViewById(R.id.title);
actionIcon = itemView.findViewById(R.id.action_icon);
actionDelete = itemView.findViewById(R.id.action_delete);
icon = itemView.findViewById(R.id.icon);
moveIcon = itemView.findViewById(R.id.move_icon);
itemsContainer = itemView.findViewById(R.id.selectable_list_item);
@ -804,5 +862,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment implements Selec
public interface OnApplyPoiFiltersState {
void onApplyPoiFiltersState(ApplicationMode mode, boolean stateChanged);
void onCustomFiltersDeleted();
}
}

View file

@ -1281,9 +1281,15 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
UiUtilities.setupSnackbarVerticalLayout(snackbar);
UiUtilities.setupSnackbar(snackbar, nightMode);
snackbar.show();
}
}
}
});
@Override
public void onCustomFiltersDeleted() {
searchHelper.refreshCustomPoiFilters();
reloadCategoriesInternal();
}
});
}
}));
if (categoriesSearchFragment != null) {