Finish POI Categories
This commit is contained in:
parent
bc0fdeaaaa
commit
a3ce80fbe0
9 changed files with 282 additions and 65 deletions
|
@ -8,11 +8,7 @@
|
|||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<include layout="@layout/global_preference_toolbar" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="marquee"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingLeft="0dp"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingTop="@dimen/content_padding_half"
|
||||
android:paddingBottom="@dimen/content_padding_half"
|
||||
|
@ -56,7 +56,7 @@
|
|||
osmand:typeface="@string/font_roboto_regular"
|
||||
tools:text="@string/poi_aerialway_transport"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingStart="@dimen/content_padding" />
|
||||
android:paddingStart="0dp" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/move_icon"
|
||||
|
|
77
OsmAnd/res/layout/profile_preference_toolbar_with_icon.xml
Normal file
77
OsmAnd/res/layout/profile_preference_toolbar_with_icon.xml
Normal file
|
@ -0,0 +1,77 @@
|
|||
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/actionModeBackground"
|
||||
android:minHeight="@dimen/toolbar_height"
|
||||
osmand:contentInsetLeft="0dp"
|
||||
osmand:contentInsetStart="0dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/close_button"
|
||||
style="@style/Widget.AppCompat.Toolbar.Button.Navigation"
|
||||
android:layout_width="@dimen/toolbar_height"
|
||||
android:layout_height="@dimen/toolbar_height"
|
||||
android:contentDescription="@string/access_shared_string_navigate_up"
|
||||
android:src="@drawable/ic_action_mode_back"
|
||||
android:tint="?attr/app_bar_primary_item_color"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="@dimen/content_padding_half"
|
||||
android:paddingBottom="@dimen/content_padding_half">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/toolbar_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:letterSpacing="@dimen/text_button_letter_spacing"
|
||||
android:maxLines="2"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:textColor="?attr/app_bar_primary_item_color"
|
||||
android:textSize="@dimen/dialog_header_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="@string/routing_settings_2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toolbar_subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:textColor="?attr/pstsInactiveTextColor"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:textAppearance="@style/TextAppearance.ContextMenuSubtitle"
|
||||
android:visibility="gone"
|
||||
tools:text="Some description" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include
|
||||
layout="@layout/profile_button_small"
|
||||
android:layout_width="@dimen/route_info_toolbar_button_size"
|
||||
android:layout_height="@dimen/route_info_toolbar_button_size"
|
||||
android:layout_marginLeft="@dimen/content_padding_half"
|
||||
android:layout_marginRight="@dimen/content_padding_half" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
|
@ -4,7 +4,6 @@ import android.content.Context;
|
|||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
|
@ -39,6 +38,7 @@ import androidx.core.graphics.drawable.DrawableCompat;
|
|||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.widget.TintableCompoundButton;
|
||||
|
||||
import com.google.android.material.snackbar.BaseTransientBottomBar;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.snackbar.SnackbarContentLayout;
|
||||
|
||||
|
@ -51,8 +51,6 @@ import net.osmand.plus.widgets.TextViewEx;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import gnu.trove.map.hash.TLongObjectHashMap;
|
||||
|
||||
public class UiUtilities {
|
||||
|
@ -414,6 +412,9 @@ public class UiUtilities {
|
|||
actionView.setGravity(Gravity.CENTER_VERTICAL | Gravity.END);
|
||||
container.setLayoutParams(params);
|
||||
}
|
||||
try {
|
||||
snackbar.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_FADE);
|
||||
} catch (Throwable e) { }
|
||||
}
|
||||
|
||||
public static void rotateImageByLayoutDirection(ImageView image, int layoutDirection) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import net.osmand.osm.AbstractPoiType;
|
|||
import net.osmand.osm.MapPoiTypes;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -316,14 +317,20 @@ public class PoiFiltersHelper {
|
|||
public Map<String, Integer> getPoiFilterOrders(boolean onlyActive) {
|
||||
Map<String, Integer> filterOrders = new HashMap<>();
|
||||
List<PoiUIFilter> sortedFilters = getSortedPoiFilters(onlyActive);
|
||||
int order = 0;
|
||||
for (PoiUIFilter filter : sortedFilters) {
|
||||
filterOrders.put(filter.getFilterId(), filter.getOrder());
|
||||
filterOrders.put(filter.getFilterId(), order++);
|
||||
}
|
||||
return filterOrders;
|
||||
}
|
||||
|
||||
public List<PoiUIFilter> getSortedPoiFilters(boolean onlyActive) {
|
||||
initPoiUIFiltersState();
|
||||
ApplicationMode selectedAppMode = application.getSettings().getApplicationMode();
|
||||
return getSortedPoiFilters(selectedAppMode, onlyActive);
|
||||
}
|
||||
|
||||
public List<PoiUIFilter> getSortedPoiFilters(@NonNull ApplicationMode appMode, boolean onlyActive) {
|
||||
initPoiUIFiltersState(appMode);
|
||||
List<PoiUIFilter> allFilters = new ArrayList<>();
|
||||
for (PoiUIFilter filter : getTopDefinedPoiFilters()) {
|
||||
if (!filter.isWikiFilter()) {
|
||||
|
@ -345,13 +352,13 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private void initPoiUIFiltersState() {
|
||||
private void initPoiUIFiltersState(@NonNull ApplicationMode appMode) {
|
||||
List<PoiUIFilter> allFilters = new ArrayList<>();
|
||||
allFilters.addAll(getTopDefinedPoiFilters());
|
||||
allFilters.addAll(getSearchPoiFilters());
|
||||
|
||||
refreshPoiFiltersActivation(allFilters);
|
||||
refreshPoiFiltersOrder(allFilters);
|
||||
refreshPoiFiltersActivation(appMode, allFilters);
|
||||
refreshPoiFiltersOrder(appMode, allFilters);
|
||||
|
||||
//set up the biggest order to custom filter
|
||||
PoiUIFilter customFilter = getCustomPOIFilter();
|
||||
|
@ -359,8 +366,9 @@ public class PoiFiltersHelper {
|
|||
customFilter.setOrder(allFilters.size());
|
||||
}
|
||||
|
||||
private void refreshPoiFiltersOrder(List<PoiUIFilter> filters) {
|
||||
Map<String, Integer> orders = getPoiFiltersOrder();
|
||||
private void refreshPoiFiltersOrder(@NonNull ApplicationMode appMode,
|
||||
List<PoiUIFilter> filters) {
|
||||
Map<String, Integer> orders = getPoiFiltersOrder(appMode);
|
||||
List<PoiUIFilter> existedFilters = new ArrayList<>();
|
||||
List<PoiUIFilter> newFilters = new ArrayList<>();
|
||||
if (orders != null) {
|
||||
|
@ -392,8 +400,9 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private void refreshPoiFiltersActivation(List<PoiUIFilter> filters) {
|
||||
List<String> inactiveFiltersIds = getInactivePoiFiltersIds();
|
||||
private void refreshPoiFiltersActivation(@NonNull ApplicationMode appMode,
|
||||
List<PoiUIFilter> filters) {
|
||||
List<String> inactiveFiltersIds = getInactivePoiFiltersIds(appMode);
|
||||
if (inactiveFiltersIds != null) {
|
||||
for (PoiUIFilter filter : filters) {
|
||||
filter.setActive(!inactiveFiltersIds.contains(filter.getFilterId()));
|
||||
|
@ -405,16 +414,16 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void saveFiltersOrder(List<String> filterIds) {
|
||||
application.getSettings().POI_FILTERS_ORDER.setStringsList(filterIds);
|
||||
public void saveFiltersOrder(ApplicationMode appMode, List<String> filterIds) {
|
||||
application.getSettings().POI_FILTERS_ORDER.setStringsListForProfile(appMode, filterIds);
|
||||
}
|
||||
|
||||
public void saveInactiveFilters(List<String> filterIds) {
|
||||
application.getSettings().INACTIVE_POI_FILTERS.setStringsList(filterIds);
|
||||
public void saveInactiveFilters(ApplicationMode appMode, List<String> filterIds) {
|
||||
application.getSettings().INACTIVE_POI_FILTERS.setStringsListForProfile(appMode, filterIds);
|
||||
}
|
||||
|
||||
public Map<String, Integer> getPoiFiltersOrder() {
|
||||
List<String> ids = application.getSettings().POI_FILTERS_ORDER.getStringsList();
|
||||
public Map<String, Integer> getPoiFiltersOrder(@NonNull ApplicationMode appMode) {
|
||||
List<String> ids = application.getSettings().POI_FILTERS_ORDER.getStringsListForProfile(appMode);
|
||||
if (ids == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -425,8 +434,8 @@ public class PoiFiltersHelper {
|
|||
return result;
|
||||
}
|
||||
|
||||
public List<String> getInactivePoiFiltersIds() {
|
||||
return application.getSettings().INACTIVE_POI_FILTERS.getStringsList();
|
||||
public List<String> getInactivePoiFiltersIds(@NonNull ApplicationMode appMode) {
|
||||
return application.getSettings().INACTIVE_POI_FILTERS.getStringsListForProfile(appMode);
|
||||
}
|
||||
|
||||
private PoiFilterDbHelper openDbHelperNoPois() {
|
||||
|
|
|
@ -3,6 +3,8 @@ package net.osmand.plus.poi;
|
|||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -19,16 +21,20 @@ import androidx.core.content.ContextCompat;
|
|||
import androidx.core.view.MotionEventCompat;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.profiles.SelectAppModesBottomSheetDialogFragment;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
|
||||
|
||||
|
@ -45,14 +51,14 @@ import static net.osmand.plus.poi.RearrangePoiFiltersFragment.ItemType.DESCRIPTI
|
|||
import static net.osmand.plus.poi.RearrangePoiFiltersFragment.ItemType.POI;
|
||||
import static net.osmand.plus.poi.RearrangePoiFiltersFragment.ItemType.SPACE;
|
||||
|
||||
public class RearrangePoiFiltersFragment extends DialogFragment {
|
||||
public class RearrangePoiFiltersFragment extends DialogFragment implements SelectAppModesBottomSheetDialogFragment.AppModeChangedListener {
|
||||
|
||||
public static final String TAG = "RearrangePoiFiltersFragment";
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(RearrangePoiFiltersFragment.class);
|
||||
|
||||
private boolean usedOnMap;
|
||||
private CallbackWithObject<Boolean> resultCallback;
|
||||
private OnApplyPoiFiltersState resultCallback;
|
||||
|
||||
private List<ListItem> items = new ArrayList<>();
|
||||
private EditPoiFiltersAdapter adapter;
|
||||
|
@ -60,6 +66,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment {
|
|||
private boolean activationModified;
|
||||
private boolean wasReset = false;
|
||||
private boolean isChanged = false;
|
||||
private ApplicationMode appMode;
|
||||
|
||||
private HashMap<String, Integer> poiFiltersOrders = new HashMap<>();
|
||||
private List<String> availableFiltersKeys = new ArrayList<>();
|
||||
|
@ -67,11 +74,20 @@ public class RearrangePoiFiltersFragment extends DialogFragment {
|
|||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
dismiss();
|
||||
}
|
||||
boolean nightMode = isNightMode(requireMyApplication(), usedOnMap);
|
||||
int themeId = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
setStyle(STYLE_NO_FRAME, themeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
updateProfileButton();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
@ -80,17 +96,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment {
|
|||
boolean nightMode = isNightMode(app, usedOnMap);
|
||||
|
||||
View mainView = UiUtilities.getInflater(app, nightMode).inflate(R.layout.edit_arrangement_list_fragment, container, false);
|
||||
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) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
TextView toolbarTitle = mainView.findViewById(R.id.toolbar_title);
|
||||
toolbarTitle.setText(R.string.rearrange_categories);
|
||||
createToolbar(mainView, nightMode);
|
||||
|
||||
RecyclerView recyclerView = mainView.findViewById(R.id.profiles_list);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(app));
|
||||
|
@ -161,13 +167,13 @@ public class RearrangePoiFiltersFragment extends DialogFragment {
|
|||
public void onClick(View v) {
|
||||
if (isChanged) {
|
||||
if (activationModified) {
|
||||
app.getPoiFilters().saveInactiveFilters(availableFiltersKeys);
|
||||
app.getPoiFilters().saveInactiveFilters(appMode, availableFiltersKeys);
|
||||
} else if (wasReset) {
|
||||
app.getPoiFilters().saveInactiveFilters(null);
|
||||
app.getPoiFilters().saveInactiveFilters(appMode, null);
|
||||
}
|
||||
if (orderModified) {
|
||||
List<PoiUIFilter> dataToSave = new ArrayList<>();
|
||||
for (PoiUIFilter filter : getSortedPoiUiFilters(app)) {
|
||||
for (PoiUIFilter filter : getSortedPoiUiFilters(appMode, app)) {
|
||||
String filterId = filter.getFilterId();
|
||||
Integer order = poiFiltersOrders.get(filterId);
|
||||
if (order == null) {
|
||||
|
@ -185,13 +191,13 @@ public class RearrangePoiFiltersFragment extends DialogFragment {
|
|||
for (PoiUIFilter filter : dataToSave) {
|
||||
filterIds.add(filter.getFilterId());
|
||||
}
|
||||
app.getPoiFilters().saveFiltersOrder(filterIds);
|
||||
app.getPoiFilters().saveFiltersOrder(appMode, filterIds);
|
||||
} else if (wasReset) {
|
||||
app.getPoiFilters().saveFiltersOrder(null);
|
||||
app.getPoiFilters().saveFiltersOrder(appMode,null);
|
||||
}
|
||||
}
|
||||
if (resultCallback != null) {
|
||||
resultCallback.processResult(isChanged);
|
||||
resultCallback.onApplyPoiFiltersState(getSelectedAppMode(), isChanged);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
@ -200,10 +206,83 @@ public class RearrangePoiFiltersFragment extends DialogFragment {
|
|||
return mainView;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
ImageButton closeButton = toolbar.findViewById(R.id.close_button);
|
||||
closeButton.setImageResource(R.drawable.ic_action_remove_dark);
|
||||
closeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
TextView toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
|
||||
toolbarTitle.setText(R.string.rearrange_categories);
|
||||
|
||||
View switchProfile = toolbar.findViewById(R.id.profile_button);
|
||||
if (switchProfile != null) {
|
||||
switchProfile.setContentDescription(getString(R.string.switch_profile));
|
||||
switchProfile.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
if (fragmentManager != null) {
|
||||
SelectAppModesBottomSheetDialogFragment.showInstance(fragmentManager,
|
||||
RearrangePoiFiltersFragment.this, false, getSelectedAppMode(), false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
appbar.addView(toolbar);
|
||||
}
|
||||
|
||||
protected void updateProfileButton() {
|
||||
View view = getView();
|
||||
if (view == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
OsmandApplication app = requireMyApplication();
|
||||
UiUtilities uiUtilities = app.getUIUtilities();
|
||||
ApplicationMode selectedAppMode = getSelectedAppMode();
|
||||
boolean nightMode = isNightMode(app, usedOnMap);
|
||||
|
||||
ImageView profileIcon = (ImageView) view.findViewById(R.id.profile_icon);
|
||||
if (profileIcon != null) {
|
||||
int iconRes = selectedAppMode.getIconRes();
|
||||
int iconColor = selectedAppMode.getIconColorInfo().getColor(nightMode);
|
||||
profileIcon.setImageDrawable(uiUtilities.getPaintedIcon(iconRes, iconColor));
|
||||
}
|
||||
|
||||
View profileButton = view.findViewById(R.id.profile_button);
|
||||
if (profileButton != null) {
|
||||
int iconColor = getSelectedAppMode().getIconColorInfo().getColor(nightMode);
|
||||
int bgColor = ContextCompat.getColor(app, nightMode ?
|
||||
R.color.active_buttons_and_links_text_dark : R.color.active_buttons_and_links_text_light);
|
||||
int selectedColor = UiUtilities.getColorWithAlpha(iconColor, 0.3f);
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
|
||||
int bgResId = R.drawable.circle_background_light;
|
||||
int selectableResId = R.drawable.ripple_circle;
|
||||
Drawable bgDrawable = uiUtilities.getPaintedIcon(bgResId, bgColor);
|
||||
Drawable selectable = uiUtilities.getPaintedIcon(selectableResId, selectedColor);
|
||||
Drawable[] layers = {bgDrawable, selectable};
|
||||
AndroidUtils.setBackground(profileButton, new LayerDrawable(layers));
|
||||
} else {
|
||||
int bgResId = R.drawable.circle_background_light;
|
||||
Drawable bgDrawable = uiUtilities.getPaintedIcon(bgResId, bgColor);
|
||||
AndroidUtils.setBackground(profileButton, bgDrawable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initFiltersOrders(OsmandApplication app, boolean arrangementByDefault) {
|
||||
poiFiltersOrders.clear();
|
||||
availableFiltersKeys.clear();
|
||||
List<PoiUIFilter> filters = getSortedPoiUiFilters(app);
|
||||
List<PoiUIFilter> filters = getSortedPoiUiFilters(appMode, app);
|
||||
if (arrangementByDefault) {
|
||||
Collections.sort(filters, new Comparator<PoiUIFilter>() {
|
||||
@Override
|
||||
|
@ -272,21 +351,31 @@ public class RearrangePoiFiltersFragment extends DialogFragment {
|
|||
adapter.setItems(items);
|
||||
}
|
||||
|
||||
public static void showInstance(@NonNull DialogFragment parentFragment, boolean usedOnMap, CallbackWithObject<Boolean> callback) {
|
||||
public static void showInstance(@NonNull ApplicationMode appMode, @NonNull DialogFragment parentFragment,
|
||||
boolean usedOnMap, OnApplyPoiFiltersState callback) {
|
||||
try {
|
||||
RearrangePoiFiltersFragment fragment = new RearrangePoiFiltersFragment();
|
||||
fragment.setUsedOnMap(usedOnMap);
|
||||
fragment.setResultCallback(callback);
|
||||
fragment.setSelectedAppMode(appMode);
|
||||
fragment.show(parentFragment.getChildFragmentManager(), RearrangePoiFiltersFragment.TAG);
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("showInstance", e);
|
||||
}
|
||||
}
|
||||
|
||||
public ApplicationMode getSelectedAppMode() {
|
||||
return appMode;
|
||||
}
|
||||
|
||||
public void setSelectedAppMode(ApplicationMode appMode) {
|
||||
this.appMode = appMode;
|
||||
}
|
||||
|
||||
public List<ListItem> getPoiFilters(boolean isActive) {
|
||||
OsmandApplication app = requireMyApplication();
|
||||
List<ListItem> result = new ArrayList<>();
|
||||
for (PoiUIFilter f : getSortedPoiUiFilters(app)) {
|
||||
for (PoiUIFilter f : getSortedPoiUiFilters(appMode, app)) {
|
||||
addFilterToList(result, f, isActive);
|
||||
}
|
||||
Collections.sort(result, new Comparator<ListItem>() {
|
||||
|
@ -322,8 +411,9 @@ public class RearrangePoiFiltersFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private static List<PoiUIFilter> getSortedPoiUiFilters(@NonNull OsmandApplication app) {
|
||||
List<PoiUIFilter> filters = app.getPoiFilters().getSortedPoiFilters(false);
|
||||
private static List<PoiUIFilter> getSortedPoiUiFilters(@NonNull ApplicationMode appMode,
|
||||
@NonNull OsmandApplication app) {
|
||||
List<PoiUIFilter> filters = app.getPoiFilters().getSortedPoiFilters(appMode, false);
|
||||
//remove custom filter
|
||||
for (int i = filters.size() - 1; i >= 0; i--) {
|
||||
PoiUIFilter filter = filters.get(i);
|
||||
|
@ -339,7 +429,7 @@ public class RearrangePoiFiltersFragment extends DialogFragment {
|
|||
this.usedOnMap = usedOnMap;
|
||||
}
|
||||
|
||||
public void setResultCallback(CallbackWithObject<Boolean> resultCallback) {
|
||||
public void setResultCallback(OnApplyPoiFiltersState resultCallback) {
|
||||
this.resultCallback = resultCallback;
|
||||
}
|
||||
|
||||
|
@ -356,6 +446,13 @@ public class RearrangePoiFiltersFragment extends DialogFragment {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppModeChanged(ApplicationMode appMode) {
|
||||
this.appMode = appMode;
|
||||
updateProfileButton();
|
||||
initFiltersOrders(requireMyApplication(), false);
|
||||
}
|
||||
|
||||
public class PoiUIFilterDataObject {
|
||||
String filterId;
|
||||
String name;
|
||||
|
@ -693,4 +790,8 @@ public class RearrangePoiFiltersFragment extends DialogFragment {
|
|||
|
||||
void onButtonClicked(int view);
|
||||
}
|
||||
|
||||
public interface OnApplyPoiFiltersState {
|
||||
void onApplyPoiFiltersState(ApplicationMode mode, boolean stateChanged);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ import androidx.recyclerview.widget.ItemTouchHelper;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -67,6 +69,11 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
|
|||
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() {
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.app.Dialog;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
@ -14,6 +15,7 @@ import android.text.SpannableString;
|
|||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -44,10 +46,10 @@ import androidx.fragment.app.FragmentPagerAdapter;
|
|||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
|
@ -66,6 +68,7 @@ import net.osmand.osm.PoiCategory;
|
|||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.plus.AppInitializer;
|
||||
import net.osmand.plus.AppInitializer.AppInitializeListener;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.LockableViewPager;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
|
@ -74,6 +77,7 @@ import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode;
|
||||
|
@ -1238,15 +1242,40 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
app.getString(R.string.rearrange_categories), new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
RearrangePoiFiltersFragment.showInstance(QuickSearchDialogFragment.this, false, new CallbackWithObject<Boolean>() {
|
||||
ApplicationMode appMode = app.getSettings().getApplicationMode();
|
||||
RearrangePoiFiltersFragment.showInstance(appMode, QuickSearchDialogFragment.this, false,
|
||||
new RearrangePoiFiltersFragment.OnApplyPoiFiltersState() {
|
||||
|
||||
@Override
|
||||
public boolean processResult(Boolean changed) {
|
||||
if (changed) {
|
||||
public void onApplyPoiFiltersState(final ApplicationMode appMode, boolean stateChanged) {
|
||||
if (stateChanged) {
|
||||
searchHelper.refreshFilterOrders();
|
||||
reloadCategoriesInternal();
|
||||
}
|
||||
return false;
|
||||
View containerView = getView();
|
||||
if (containerView != null) {
|
||||
//show "Apply to all profiles" SnackBar
|
||||
String modeName = appMode.toHumanString();
|
||||
String text = app.getString(R.string.changes_applied_to_profile, modeName);
|
||||
SpannableString message = UiUtilities.createSpannableString(text, modeName, new StyleSpan(Typeface.BOLD));
|
||||
Snackbar snackbar = Snackbar.make(containerView, message, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.apply_to_all_profiles, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
OsmandSettings settings = app.getSettings();
|
||||
String orders = settings.POI_FILTERS_ORDER.getModeValue(appMode);
|
||||
String inactive = settings.INACTIVE_POI_FILTERS.getModeValue(appMode);
|
||||
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
|
||||
settings.POI_FILTERS_ORDER.setModeValue(mode, orders);
|
||||
settings.INACTIVE_POI_FILTERS.setModeValue(mode, inactive);
|
||||
}
|
||||
searchHelper.refreshFilterOrders();
|
||||
reloadCategoriesInternal();
|
||||
}
|
||||
});
|
||||
UiUtilities.setupSnackbarVerticalLayout(snackbar);
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -940,9 +940,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
}
|
||||
});
|
||||
UiUtilities.setupSnackbarVerticalLayout(snackbar);
|
||||
try {
|
||||
snackbar.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_FADE);
|
||||
} catch (Throwable e) { }
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue