Merge pull request #10402 from osmandapp/ResetToDefaultAfterApply
"Reset to default" changes settings only after click on "Apply" button
This commit is contained in:
commit
cc18fee1a4
3 changed files with 31 additions and 9 deletions
|
@ -102,7 +102,7 @@ public class ContextMenuItemsSettings implements Serializable {
|
||||||
return Collections.unmodifiableList(orderIds);
|
return Collections.unmodifiableList(orderIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContextMenuItemsSettings getDefaultInstanceForDrawer() {
|
public static ContextMenuItemsSettings getDrawerDefaultInstance() {
|
||||||
ArrayList<String> hiddenByDefault = new ArrayList<>();
|
ArrayList<String> hiddenByDefault = new ArrayList<>();
|
||||||
hiddenByDefault.add(DRAWER_DASHBOARD_ID);
|
hiddenByDefault.add(DRAWER_DASHBOARD_ID);
|
||||||
return new ContextMenuItemsSettings(hiddenByDefault, new ArrayList<String>());
|
return new ContextMenuItemsSettings(hiddenByDefault, new ArrayList<String>());
|
||||||
|
|
|
@ -2520,7 +2520,7 @@ public class OsmandSettings {
|
||||||
new ListStringPreference(this, "inactive_poi_filters", null, ",,").makeProfile().cache();
|
new ListStringPreference(this, "inactive_poi_filters", null, ",,").makeProfile().cache();
|
||||||
|
|
||||||
public final ContextMenuItemsPreference DRAWER_ITEMS =
|
public final ContextMenuItemsPreference DRAWER_ITEMS =
|
||||||
(ContextMenuItemsPreference) new ContextMenuItemsPreference(this, "drawer_items", DRAWER_ITEM_ID_SCHEME, ContextMenuItemsSettings.getDefaultInstanceForDrawer())
|
(ContextMenuItemsPreference) new ContextMenuItemsPreference(this, "drawer_items", DRAWER_ITEM_ID_SCHEME, ContextMenuItemsSettings.getDrawerDefaultInstance())
|
||||||
.makeProfile().cache();
|
.makeProfile().cache();
|
||||||
|
|
||||||
public final ContextMenuItemsPreference CONFIGURE_MAP_ITEMS =
|
public final ContextMenuItemsPreference CONFIGURE_MAP_ITEMS =
|
||||||
|
|
|
@ -164,17 +164,26 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSavedIds(ApplicationMode appMode) {
|
private void initSavedIds(ApplicationMode appMode) {
|
||||||
hiddenMenuItems = new ArrayList<>(getSettingForScreen(app, screenType).getModeValue(appMode).getHiddenIds());
|
initSavedIds(appMode, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initSavedIds(ApplicationMode appMode, boolean useDefaultValue) {
|
||||||
|
ContextMenuItemsSettings settings = getMenuItemsSettings(appMode, useDefaultValue);
|
||||||
|
hiddenMenuItems = new ArrayList<>(settings.getHiddenIds());
|
||||||
menuItemsOrder = new HashMap<>();
|
menuItemsOrder = new HashMap<>();
|
||||||
List<String> orderIds = getSettingForScreen(app, screenType).getModeValue(appMode).getOrderIds();
|
List<String> orderIds = settings.getOrderIds();
|
||||||
for (int i = 0; i < orderIds.size(); i++) {
|
for (int i = 0; i < orderIds.size(); i++) {
|
||||||
menuItemsOrder.put(orderIds.get(i), i);
|
menuItemsOrder.put(orderIds.get(i), i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initMainActionsIds(ApplicationMode appMode) {
|
private void initMainActionsIds(ApplicationMode appMode) {
|
||||||
|
initMainActionsIds(appMode, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initMainActionsIds(ApplicationMode appMode, boolean useDefaultValue) {
|
||||||
List<ContextMenuItem> defItems = getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems());
|
List<ContextMenuItem> defItems = getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems());
|
||||||
ContextMenuItemsSettings pref = getSettingForScreen(app, screenType).getModeValue(appMode);
|
ContextMenuItemsSettings pref = getMenuItemsSettings(appMode, useDefaultValue);
|
||||||
if (pref instanceof MainContextMenuItemsSettings) {
|
if (pref instanceof MainContextMenuItemsSettings) {
|
||||||
mainActionItems = new ArrayList<>(((MainContextMenuItemsSettings) pref).getMainIds());
|
mainActionItems = new ArrayList<>(((MainContextMenuItemsSettings) pref).getMainIds());
|
||||||
if (mainActionItems.isEmpty()) {
|
if (mainActionItems.isEmpty()) {
|
||||||
|
@ -276,7 +285,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
|
||||||
}
|
}
|
||||||
if (fm != null) {
|
if (fm != null) {
|
||||||
ChangeGeneralProfilesPrefBottomSheet.showInstance(fm,
|
ChangeGeneralProfilesPrefBottomSheet.showInstance(fm,
|
||||||
getSettingForScreen(app, screenType).getId(),
|
getSettingForScreen().getId(),
|
||||||
prefToSave,
|
prefToSave,
|
||||||
getTargetFragment(),
|
getTargetFragment(),
|
||||||
false,
|
false,
|
||||||
|
@ -501,13 +510,12 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
|
||||||
menuItemsOrder.clear();
|
menuItemsOrder.clear();
|
||||||
wasReset = true;
|
wasReset = true;
|
||||||
isChanged = true;
|
isChanged = true;
|
||||||
getSettingForScreen(app, screenType).resetModeToDefault(appMode);
|
|
||||||
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
|
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
|
||||||
mainActionItems.clear();
|
mainActionItems.clear();
|
||||||
}
|
}
|
||||||
instantiateContextMenuAdapter();
|
instantiateContextMenuAdapter();
|
||||||
initSavedIds(appMode);
|
initSavedIds(appMode, true);
|
||||||
initMainActionsIds(appMode);
|
initMainActionsIds(appMode, true);
|
||||||
rearrangeAdapter.updateItems(getAdapterItems());
|
rearrangeAdapter.updateItems(getAdapterItems());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -537,6 +545,20 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ContextMenuItemsSettings getMenuItemsSettings(ApplicationMode appMode,
|
||||||
|
boolean useDefaultValue) {
|
||||||
|
ContextMenuItemsPreference preference = getSettingForScreen();
|
||||||
|
if (useDefaultValue) {
|
||||||
|
return preference.getProfileDefaultValue(appMode);
|
||||||
|
} else {
|
||||||
|
return preference.getModeValue(appMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContextMenuItemsPreference getSettingForScreen() {
|
||||||
|
return getSettingForScreen(app, screenType);
|
||||||
|
}
|
||||||
|
|
||||||
public static ContextMenuItemsPreference getSettingForScreen(OsmandApplication app, ScreenType screenType) throws IllegalArgumentException {
|
public static ContextMenuItemsPreference getSettingForScreen(OsmandApplication app, ScreenType screenType) throws IllegalArgumentException {
|
||||||
switch (screenType) {
|
switch (screenType) {
|
||||||
case DRAWER:
|
case DRAWER:
|
||||||
|
|
Loading…
Reference in a new issue