diff --git a/OsmAnd/res/layout/fragment_import.xml b/OsmAnd/res/layout/fragment_import.xml index 71810a5fd9..adb5757830 100644 --- a/OsmAnd/res/layout/fragment_import.xml +++ b/OsmAnd/res/layout/fragment_import.xml @@ -1,5 +1,5 @@ - @@ -40,7 +39,6 @@ android:id="@+id/description" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_below="@+id/toolbar_layout" android:background="?attr/bg_color" android:paddingStart="@dimen/content_padding" android:paddingTop="@dimen/list_header_settings_top_margin" @@ -55,15 +53,13 @@ android:id="@+id/description_divider" layout="@layout/card_bottom_divider" android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_below="@+id/description" /> + android:layout_height="wrap_content"/> - \ No newline at end of file + \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_import_duplicates.xml b/OsmAnd/res/layout/fragment_import_duplicates.xml index a60ea21119..16f45a773f 100644 --- a/OsmAnd/res/layout/fragment_import_duplicates.xml +++ b/OsmAnd/res/layout/fragment_import_duplicates.xml @@ -47,14 +47,17 @@ android:textSize="@dimen/default_list_text_size" osmand:typeface="@string/font_roboto_medium" /> - + + android:layout_weight="1" /> savedActions = factory.parseActiveActionsList(getSettings().QUICK_ACTION_LIST.get()); + for (QuickAction action : savedActions) { + if (action.getName(app).equals(quickAction.getName(app))) { + return true; + } + } + return false; + } + @Override public void apply() { if (!quickActions.isEmpty() || !duplicates.isEmpty()) { @@ -822,7 +844,7 @@ public class SettingsHelper { } } else { for (QuickAction action : duplicates) { - action.setName(COPY_PREFIX + action.getName(app)); + renameAction(action); } } newActions.addAll(duplicates); @@ -979,7 +1001,6 @@ public class SettingsHelper { for (PoiUIFilter duplicate : duplicates) { if (!shouldReplace) { renamePoiFilter(duplicate); -// duplicate.setName(COPY_PREFIX + duplicate.getName()); } poiUIFilters.add(duplicate); } @@ -992,6 +1013,7 @@ public class SettingsHelper { private void renamePoiFilter(PoiUIFilter poiUIFilter) { poiUIFilter.setName(COPY_PREFIX + poiUIFilter.getName()); + poiUIFilter.setFilterId(poiUIFilter.getFilterId() + COPY_SUFFIX); if (duplicateExists(poiUIFilter)) { renamePoiFilter(poiUIFilter); } diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index facbc5a6ed..6e024e290a 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -726,6 +726,10 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable return filterId; } + public void setFilterId(String filterId) { + this.filterId = filterId; + } + public Map getPoiAdditionals() { return poiAdditionals; } diff --git a/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java index 704863fa49..764b3d43f0 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java @@ -97,7 +97,7 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter settingsItems; private File file; private boolean allSelected; private boolean nightMode; public static void showInstance(@NonNull FragmentManager fm, @NonNull List settingsItems, @NonNull File file) { ImportSettingsFragment fragment = new ImportSettingsFragment(); fragment.setSettingsItems(settingsItems); fragment.setFile(file); // fragment.setTargetFragment(); // fragment.getTargetFragment() fragment.show(fm, TAG); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); app = getMyApplication(); nightMode = !getSettings().isLightContent(); if (settingsItems == null) { settingsItems = app.getSettingsHelper().getSettingsItems(); } if (file == null) { file = app.getSettingsHelper().getSettingsFile(); } } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { inflater = UiUtilities.getInflater(app, nightMode); View root = inflater.inflate(R.layout.fragment_import, container, false); setupToolbar((Toolbar) root.findViewById(R.id.toolbar)); TextViewEx continueBtn = root.findViewById(R.id.continue_button); selectBtn = root.findViewById(R.id.select_button); expandableList = root.findViewById(R.id.list); continueBtn.setOnClickListener(this); selectBtn.setOnClickListener(this); return root; } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); adapter = new ExportImportSettingsAdapter(getMyApplication(), getSettingsToOperate(), nightMode, true); expandableList.setAdapter(adapter); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.select_button: { allSelected = !allSelected; selectBtn.setText(allSelected ? R.string.shared_string_deselect_all : R.string.shared_string_select_all); adapter.selectAll(allSelected); break; } case R.id.continue_button: { if (adapter.getDataToOperate().isEmpty()) { app.showShortToastMessage(getString(R.string.shared_sting_nothing_selected)); } else { importItems(); } break; } } } private void importItems() { List settingsItems = getSettingsItemsFromData(adapter.getDataToOperate()); List duplicateItems = getDuplicatesData(settingsItems); if (duplicateItems.isEmpty()) { app.getSettingsHelper().importSettings(file, settingsItems, "", 1, new SettingsHelper.SettingsImportListener() { @Override public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { if (succeed) { app.showShortToastMessage(app.getString(R.string.file_imported_successfully, file.getName())); } else if (empty) { app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error))); } } }); dismiss(); } else { ImportDuplicatesFragment.showInstance(getChildFragmentManager(), duplicateItems, settingsItems, file); } } private List getDuplicatesData(List items) { List duplicateItems = new ArrayList<>(); for (SettingsItem item : items) { if (item instanceof SettingsHelper.ProfileSettingsItem) { if (item.exists()) { duplicateItems.add(((SettingsHelper.ProfileSettingsItem) item).getAppMode()); } } else if (item instanceof SettingsHelper.QuickActionSettingsItem) { List duplicates = ((SettingsHelper.QuickActionSettingsItem) item).getDuplicates(); if (!duplicates.isEmpty()) { duplicateItems.addAll(duplicates); } } else if (item instanceof SettingsHelper.PoiUiFilterSettingsItem) { List duplicates = ((SettingsHelper.PoiUiFilterSettingsItem) item).getDuplicates(); if (!duplicates.isEmpty()) { duplicateItems.addAll(duplicates); } } else if (item instanceof SettingsHelper.MapSourcesSettingsItem) { List duplicates = ((SettingsHelper.MapSourcesSettingsItem) item).getDuplicates(); if (!duplicates.isEmpty()) { duplicateItems.addAll(duplicates); } } else if (item instanceof SettingsHelper.FileSettingsItem) { if (item.exists()) { duplicateItems.add(((SettingsHelper.FileSettingsItem) item).getFile()); } } } return duplicateItems; } public void setSettingsItems(List settingsItems) { this.settingsItems = settingsItems; } private List getSettingsItemsFromData(List dataToOperate) { List settingsItems = new ArrayList<>(); List quickActions = new ArrayList<>(); List poiUIFilters = new ArrayList<>(); List tileSourceTemplates = new ArrayList<>(); for (Object object : dataToOperate) { if (object instanceof ApplicationMode.ApplicationModeBean) { settingsItems.add(new SettingsHelper.ProfileSettingsItem(app, (ApplicationMode.ApplicationModeBean) object)); } if (object instanceof QuickAction) { quickActions.add((QuickAction) object); } else if (object instanceof PoiUIFilter) { poiUIFilters.add((PoiUIFilter) object); } else if (object instanceof TileSourceManager.TileSourceTemplate || object instanceof SQLiteTileSource) { tileSourceTemplates.add((ITileSource) object); } else if (object instanceof File) { settingsItems.add(new SettingsHelper.FileSettingsItem(getMyApplication(), (File) object)); } } if (!quickActions.isEmpty()) { settingsItems.add(new SettingsHelper.QuickActionSettingsItem(getMyApplication(), quickActions)); } if (!poiUIFilters.isEmpty()) { settingsItems.add(new SettingsHelper.PoiUiFilterSettingsItem(getMyApplication(), poiUIFilters)); } if (!tileSourceTemplates.isEmpty()) { settingsItems.add(new SettingsHelper.MapSourcesSettingsItem(getMyApplication(), tileSourceTemplates)); } return settingsItems; } private List getSettingsToOperate() { List settingsToOperate = new ArrayList<>(); List profiles = new ArrayList<>(); List quickActions = new ArrayList<>(); List poiUIFilters = new ArrayList<>(); List tileSourceTemplates = new ArrayList<>(); List routingFilesList = new ArrayList<>(); List renderFilesList = new ArrayList<>(); for (SettingsHelper.SettingsItem item : settingsItems) { if (item.getType().equals(SettingsHelper.SettingsItemType.PROFILE)) { profiles.add(((SettingsHelper.ProfileSettingsItem) item).getModeBean()); } else if (item.getType().equals(SettingsHelper.SettingsItemType.QUICK_ACTION)) { quickActions.addAll(((SettingsHelper.QuickActionSettingsItem) item).getQuickActions()); } else if (item.getType().equals(SettingsHelper.SettingsItemType.POI_UI_FILTERS)) { poiUIFilters.addAll(((SettingsHelper.PoiUiFilterSettingsItem) item).getPoiUIFilters()); } else if (item.getType().equals(SettingsHelper.SettingsItemType.MAP_SOURCES)) { tileSourceTemplates.addAll(((SettingsHelper.MapSourcesSettingsItem) item).getMapSources()); } else if (item.getType().equals(SettingsHelper.SettingsItemType.FILE)) { if (item.getName().startsWith("/rendering/")) { renderFilesList.add(((SettingsHelper.FileSettingsItem) item).getFile()); } else if (item.getName().startsWith("/routing/")) { routingFilesList.add(((SettingsHelper.FileSettingsItem) item).getFile()); } } } if (!profiles.isEmpty()) { settingsToOperate.add(new AdditionalDataWrapper( AdditionalDataWrapper.Type.PROFILE, profiles)); } if (!quickActions.isEmpty()) { settingsToOperate.add(new AdditionalDataWrapper( AdditionalDataWrapper.Type.QUICK_ACTIONS, quickActions)); } if (!poiUIFilters.isEmpty()) { settingsToOperate.add(new AdditionalDataWrapper( AdditionalDataWrapper.Type.POI_TYPES, poiUIFilters)); } if (!tileSourceTemplates.isEmpty()) { settingsToOperate.add(new AdditionalDataWrapper( AdditionalDataWrapper.Type.MAP_SOURCES, tileSourceTemplates )); } if (!renderFilesList.isEmpty()) { settingsToOperate.add(new AdditionalDataWrapper( AdditionalDataWrapper.Type.CUSTOM_RENDER_STYLE, renderFilesList )); } if (!routingFilesList.isEmpty()) { settingsToOperate.add(new AdditionalDataWrapper( AdditionalDataWrapper.Type.CUSTOM_ROUTING, routingFilesList )); } return settingsToOperate; } private void setupToolbar(Toolbar toolbar) { toolbar.setNavigationIcon(getPaintedContentIcon(R.drawable.headline_close_button, nightMode ? getResources().getColor(R.color.active_buttons_and_links_text_dark) : getResources().getColor(R.color.active_buttons_and_links_text_light))); toolbar.setNavigationContentDescription(R.string.shared_string_close); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); } public void setFile(File file) { this.file = file; } } \ No newline at end of file +package net.osmand.plus.settings; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.FragmentManager; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ExpandableListView; import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.SettingsHelper; import net.osmand.plus.SettingsHelper.SettingsItem; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.BaseOsmAndDialogFragment; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.profiles.AdditionalDataWrapper; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.widgets.TextViewEx; import java.io.File; import java.util.ArrayList; import java.util.List; public class ImportSettingsFragment extends BaseOsmAndDialogFragment implements View.OnClickListener { public static final String TAG = ImportSettingsFragment.class.getSimpleName(); private OsmandApplication app; private ExportImportSettingsAdapter adapter; private ExpandableListView expandableList; private TextViewEx selectBtn; private List settingsItems; private File file; private boolean allSelected; private boolean nightMode; public static void showInstance(@NonNull FragmentManager fm, @NonNull List settingsItems, @NonNull File file) { ImportSettingsFragment fragment = new ImportSettingsFragment(); fragment.setSettingsItems(settingsItems); fragment.setFile(file); fragment.show(fm, TAG); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); app = getMyApplication(); nightMode = !getSettings().isLightContent(); if (settingsItems == null) { settingsItems = app.getSettingsHelper().getSettingsItems(); } if (file == null) { file = app.getSettingsHelper().getSettingsFile(); } } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { inflater = UiUtilities.getInflater(app, nightMode); View root = inflater.inflate(R.layout.fragment_import, container, false); setupToolbar((Toolbar) root.findViewById(R.id.toolbar)); TextViewEx continueBtn = root.findViewById(R.id.continue_button); selectBtn = root.findViewById(R.id.select_button); expandableList = root.findViewById(R.id.list); continueBtn.setOnClickListener(this); selectBtn.setOnClickListener(this); return root; } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); adapter = new ExportImportSettingsAdapter(getMyApplication(), getSettingsToOperate(), nightMode, true); expandableList.setAdapter(adapter); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.select_button: { allSelected = !allSelected; selectBtn.setText(allSelected ? R.string.shared_string_deselect_all : R.string.shared_string_select_all); adapter.selectAll(allSelected); break; } case R.id.continue_button: { if (adapter.getDataToOperate().isEmpty()) { app.showShortToastMessage(getString(R.string.shared_sting_nothing_selected)); } else { importItems(); } break; } } } private void importItems() { List settingsItems = getSettingsItemsFromData(adapter.getDataToOperate()); List duplicateItems = getDuplicatesData(settingsItems); if (duplicateItems.isEmpty()) { app.getSettingsHelper().importSettings(file, settingsItems, "", 1, new SettingsHelper.SettingsImportListener() { @Override public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { if (succeed) { app.showShortToastMessage(app.getString(R.string.file_imported_successfully, file.getName())); } else if (empty) { app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error))); } } }); dismiss(); } else { ImportDuplicatesFragment.showInstance(getFragmentManager(), duplicateItems, settingsItems, file); dismiss(); } } private List getDuplicatesData(List items) { List duplicateItems = new ArrayList<>(); for (SettingsItem item : items) { if (item instanceof SettingsHelper.ProfileSettingsItem) { if (item.exists()) { duplicateItems.add(((SettingsHelper.ProfileSettingsItem) item).getAppMode()); } } else if (item instanceof SettingsHelper.QuickActionSettingsItem) { List duplicates = ((SettingsHelper.QuickActionSettingsItem) item).getDuplicates(); if (!duplicates.isEmpty()) { duplicateItems.addAll(duplicates); } } else if (item instanceof SettingsHelper.PoiUiFilterSettingsItem) { List duplicates = ((SettingsHelper.PoiUiFilterSettingsItem) item).getDuplicates(); if (!duplicates.isEmpty()) { duplicateItems.addAll(duplicates); } } else if (item instanceof SettingsHelper.MapSourcesSettingsItem) { List duplicates = ((SettingsHelper.MapSourcesSettingsItem) item).getDuplicates(); if (!duplicates.isEmpty()) { duplicateItems.addAll(duplicates); } } else if (item instanceof SettingsHelper.FileSettingsItem) { if (item.exists()) { duplicateItems.add(((SettingsHelper.FileSettingsItem) item).getFile()); } } } return duplicateItems; } public void setSettingsItems(List settingsItems) { this.settingsItems = settingsItems; } private List getSettingsItemsFromData(List dataToOperate) { List settingsItems = new ArrayList<>(); List quickActions = new ArrayList<>(); List poiUIFilters = new ArrayList<>(); List tileSourceTemplates = new ArrayList<>(); for (Object object : dataToOperate) { if (object instanceof ApplicationMode.ApplicationModeBean) { settingsItems.add(new SettingsHelper.ProfileSettingsItem(app, (ApplicationMode.ApplicationModeBean) object)); } if (object instanceof QuickAction) { quickActions.add((QuickAction) object); } else if (object instanceof PoiUIFilter) { poiUIFilters.add((PoiUIFilter) object); } else if (object instanceof TileSourceManager.TileSourceTemplate || object instanceof SQLiteTileSource) { tileSourceTemplates.add((ITileSource) object); } else if (object instanceof File) { settingsItems.add(new SettingsHelper.FileSettingsItem(getMyApplication(), (File) object)); } } if (!quickActions.isEmpty()) { settingsItems.add(new SettingsHelper.QuickActionSettingsItem(getMyApplication(), quickActions)); } if (!poiUIFilters.isEmpty()) { settingsItems.add(new SettingsHelper.PoiUiFilterSettingsItem(getMyApplication(), poiUIFilters)); } if (!tileSourceTemplates.isEmpty()) { settingsItems.add(new SettingsHelper.MapSourcesSettingsItem(getMyApplication(), tileSourceTemplates)); } return settingsItems; } private List getSettingsToOperate() { List settingsToOperate = new ArrayList<>(); List profiles = new ArrayList<>(); List quickActions = new ArrayList<>(); List poiUIFilters = new ArrayList<>(); List tileSourceTemplates = new ArrayList<>(); List routingFilesList = new ArrayList<>(); List renderFilesList = new ArrayList<>(); for (SettingsHelper.SettingsItem item : settingsItems) { if (item.getType().equals(SettingsHelper.SettingsItemType.PROFILE)) { profiles.add(((SettingsHelper.ProfileSettingsItem) item).getModeBean()); } else if (item.getType().equals(SettingsHelper.SettingsItemType.QUICK_ACTION)) { quickActions.addAll(((SettingsHelper.QuickActionSettingsItem) item).getQuickActions()); } else if (item.getType().equals(SettingsHelper.SettingsItemType.POI_UI_FILTERS)) { poiUIFilters.addAll(((SettingsHelper.PoiUiFilterSettingsItem) item).getPoiUIFilters()); } else if (item.getType().equals(SettingsHelper.SettingsItemType.MAP_SOURCES)) { tileSourceTemplates.addAll(((SettingsHelper.MapSourcesSettingsItem) item).getMapSources()); } else if (item.getType().equals(SettingsHelper.SettingsItemType.FILE)) { if (item.getName().startsWith("/rendering/")) { renderFilesList.add(((SettingsHelper.FileSettingsItem) item).getFile()); } else if (item.getName().startsWith("/routing/")) { routingFilesList.add(((SettingsHelper.FileSettingsItem) item).getFile()); } } } if (!profiles.isEmpty()) { settingsToOperate.add(new AdditionalDataWrapper( AdditionalDataWrapper.Type.PROFILE, profiles)); } if (!quickActions.isEmpty()) { settingsToOperate.add(new AdditionalDataWrapper( AdditionalDataWrapper.Type.QUICK_ACTIONS, quickActions)); } if (!poiUIFilters.isEmpty()) { settingsToOperate.add(new AdditionalDataWrapper( AdditionalDataWrapper.Type.POI_TYPES, poiUIFilters)); } if (!tileSourceTemplates.isEmpty()) { settingsToOperate.add(new AdditionalDataWrapper( AdditionalDataWrapper.Type.MAP_SOURCES, tileSourceTemplates )); } if (!renderFilesList.isEmpty()) { settingsToOperate.add(new AdditionalDataWrapper( AdditionalDataWrapper.Type.CUSTOM_RENDER_STYLE, renderFilesList )); } if (!routingFilesList.isEmpty()) { settingsToOperate.add(new AdditionalDataWrapper( AdditionalDataWrapper.Type.CUSTOM_ROUTING, routingFilesList )); } return settingsToOperate; } private void setupToolbar(Toolbar toolbar) { toolbar.setNavigationIcon(getPaintedContentIcon(R.drawable.headline_close_button, nightMode ? getResources().getColor(R.color.active_buttons_and_links_text_dark) : getResources().getColor(R.color.active_buttons_and_links_text_light))); toolbar.setNavigationContentDescription(R.string.shared_string_close); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); } public void setFile(File file) { this.file = file; } } \ No newline at end of file