avoid roads, refactor, corrections
This commit is contained in:
parent
a685cf4637
commit
321aa96846
13 changed files with 173 additions and 53 deletions
|
@ -46,8 +46,7 @@
|
|||
android:paddingBottom="@dimen/list_header_settings_top_margin"
|
||||
android:text="@string/select_data_to_import"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
android:textSize="@dimen/default_list_text_size" />
|
||||
|
||||
<include layout="@layout/card_bottom_divider" />
|
||||
|
||||
|
@ -62,7 +61,7 @@
|
|||
android:groupIndicator="@android:color/transparent"
|
||||
android:listSelector="@android:color/transparent" />
|
||||
|
||||
<include layout="@layout/card_top_divider" />
|
||||
<include layout="@layout/divider" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/buttons_container"
|
||||
|
|
|
@ -44,8 +44,7 @@
|
|||
android:paddingBottom="@dimen/list_header_settings_top_margin"
|
||||
android:text="@string/import_duplicates_description"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
android:textSize="@dimen/default_list_text_size" />
|
||||
|
||||
<include
|
||||
android:id="@+id/description_divider"
|
||||
|
@ -57,8 +56,7 @@
|
|||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<include
|
||||
layout="@layout/card_top_divider" />
|
||||
<include layout="@layout/divider" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/setting_list_item_small_height"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/bg_color"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="66dp">
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
|
@ -23,12 +23,16 @@
|
|||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="@dimen/content_padding_small"
|
||||
android:paddingBottom="@dimen/content_padding_small">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="OffRoad" />
|
||||
|
@ -37,6 +41,8 @@
|
|||
android:id="@+id/sub_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
tools:text="Navigation type: Car" />
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/setting_list_item_small_height"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
|
@ -15,8 +16,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="66dp">
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
|
@ -30,12 +30,16 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="@dimen/content_padding_small"
|
||||
android:paddingBottom="@dimen/content_padding_small">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/title_tv"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="Quick actions" />
|
||||
|
@ -44,6 +48,8 @@
|
|||
android:id="@+id/sub_title_tv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
android:visibility="gone"
|
||||
|
|
|
@ -353,5 +353,6 @@
|
|||
<dimen name="setting_profile_item_switch_margin">18dp</dimen>
|
||||
<dimen name="settings_divider_margin_start">72dp</dimen>
|
||||
<dimen name="setting_list_item_large_height">72dp</dimen>
|
||||
<dimen name="setting_list_item_small_height">42dp</dimen>
|
||||
|
||||
</resources>
|
|
@ -72,7 +72,7 @@
|
|||
<string name="sunset_at">Sunset at %1$s</string>
|
||||
<string name="sunrise_at">Sunrise at %1$s</string>
|
||||
<string name="shared_string_routing">Routing</string>
|
||||
<string name="shared_string_custom_rendering_style">Custom rendering style</string>
|
||||
<string name="shared_string_custom_rendering_style">Rendering styles</string>
|
||||
<string name="shared_string_include_data">Include additional data</string>
|
||||
<string name="import_profile_dialog_description">The imported profile contains additional data. Click Import to import only profile data or select additional data to import.</string>
|
||||
<string name="export_profile_dialog_description">You can select additional data to export along with the profile.</string>
|
||||
|
|
|
@ -805,7 +805,7 @@ public class SettingsHelper {
|
|||
@Override
|
||||
public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException {
|
||||
OutputStream output;
|
||||
if (shouldReplace || !file.exists()) {
|
||||
if (!file.exists() || file.exists() && shouldReplace) {
|
||||
output = new FileOutputStream(file);
|
||||
} else {
|
||||
output = new FileOutputStream(renameFile(file));
|
||||
|
@ -847,6 +847,7 @@ public class SettingsHelper {
|
|||
this.app = app;
|
||||
actionRegistry = app.getQuickActionRegistry();
|
||||
existingItems = actionRegistry.getQuickActions();
|
||||
duplicateItems = new ArrayList<>();
|
||||
}
|
||||
|
||||
QuickActionSettingsItem(@NonNull OsmandApplication app,
|
||||
|
@ -855,6 +856,7 @@ public class SettingsHelper {
|
|||
this.app = app;
|
||||
actionRegistry = app.getQuickActionRegistry();
|
||||
existingItems = actionRegistry.getQuickActions();
|
||||
duplicateItems = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -871,7 +873,6 @@ public class SettingsHelper {
|
|||
@NonNull
|
||||
@Override
|
||||
public List<QuickAction> excludeDuplicateItems() {
|
||||
duplicateItems = new ArrayList<>();
|
||||
for (QuickAction item : items) {
|
||||
if (isDuplicate(item)) {
|
||||
duplicateItems.add(item);
|
||||
|
@ -1026,12 +1027,14 @@ public class SettingsHelper {
|
|||
super(SettingsItemType.POI_UI_FILTERS, items);
|
||||
this.app = app;
|
||||
existingItems = app.getPoiFilters().getUserDefinedPoiFilters(false);
|
||||
duplicateItems = new ArrayList<>();
|
||||
}
|
||||
|
||||
PoiUiFilterSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
|
||||
super(SettingsItemType.POI_UI_FILTERS, json);
|
||||
this.app = app;
|
||||
existingItems = app.getPoiFilters().getUserDefinedPoiFilters(false);
|
||||
duplicateItems = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1061,7 +1064,6 @@ public class SettingsHelper {
|
|||
@NonNull
|
||||
@Override
|
||||
public List<PoiUIFilter> excludeDuplicateItems() {
|
||||
duplicateItems = new ArrayList<>();
|
||||
if (!items.isEmpty()) {
|
||||
for (PoiUIFilter item : items) {
|
||||
if (isDuplicate(item)) {
|
||||
|
@ -1212,6 +1214,7 @@ public class SettingsHelper {
|
|||
this.app = app;
|
||||
Collection values = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true)).values();
|
||||
existingItemsNames = new ArrayList(values);
|
||||
duplicateItems = new ArrayList<>();
|
||||
}
|
||||
|
||||
MapSourcesSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
|
||||
|
@ -1219,6 +1222,7 @@ public class SettingsHelper {
|
|||
this.app = app;
|
||||
Collection values = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true)).values();
|
||||
existingItemsNames = new ArrayList(values);
|
||||
duplicateItems = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1261,7 +1265,6 @@ public class SettingsHelper {
|
|||
@NonNull
|
||||
@Override
|
||||
public List<ITileSource> excludeDuplicateItems() {
|
||||
duplicateItems = new ArrayList<>();
|
||||
for (String name : existingItemsNames) {
|
||||
for (ITileSource tileSource : items) {
|
||||
if (name.equals(tileSource.getName())) {
|
||||
|
@ -1456,6 +1459,7 @@ public class SettingsHelper {
|
|||
settings = app.getSettings();
|
||||
specificRoads = app.getAvoidSpecificRoads();
|
||||
existingItems = new ArrayList<>(specificRoads.getImpassableRoads().values());
|
||||
duplicateItems = new ArrayList<>();
|
||||
}
|
||||
|
||||
AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
|
||||
|
@ -1464,6 +1468,7 @@ public class SettingsHelper {
|
|||
settings = app.getSettings();
|
||||
specificRoads = app.getAvoidSpecificRoads();
|
||||
existingItems = new ArrayList<>(specificRoads.getImpassableRoads().values());
|
||||
duplicateItems = new ArrayList<>();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -1486,27 +1491,28 @@ public class SettingsHelper {
|
|||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (AvoidRoadInfo duplicate : duplicateItems) {
|
||||
if (shouldReplace) {
|
||||
LatLon latLon = new LatLon(duplicate.latitude, duplicate.longitude);
|
||||
if (settings.removeImpassableRoad(latLon)) {
|
||||
settings.addImpassableRoad(duplicate);
|
||||
if (!items.isEmpty() || !duplicateItems.isEmpty()) {
|
||||
for (AvoidRoadInfo duplicate : duplicateItems) {
|
||||
if (shouldReplace) {
|
||||
LatLon latLon = new LatLon(duplicate.latitude, duplicate.longitude);
|
||||
if (settings.removeImpassableRoad(latLon)) {
|
||||
settings.addImpassableRoad(duplicate);
|
||||
}
|
||||
} else {
|
||||
settings.addImpassableRoad(renameItem(duplicate));
|
||||
}
|
||||
} else {
|
||||
settings.addImpassableRoad(duplicate);
|
||||
}
|
||||
for (AvoidRoadInfo avoidRoad : items) {
|
||||
settings.addImpassableRoad(avoidRoad);
|
||||
}
|
||||
specificRoads.loadImpassableRoads();
|
||||
specificRoads.initRouteObjects(true);
|
||||
}
|
||||
for (AvoidRoadInfo avoidRoad : items) {
|
||||
settings.addImpassableRoad(avoidRoad);
|
||||
}
|
||||
specificRoads.loadImpassableRoads();
|
||||
specificRoads.initRouteObjects(true);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public List<AvoidRoadInfo> excludeDuplicateItems() {
|
||||
duplicateItems = new ArrayList<>();
|
||||
for (AvoidRoadInfo item : items) {
|
||||
if (isDuplicate(item)) {
|
||||
duplicateItems.add(item);
|
||||
|
@ -1517,9 +1523,11 @@ public class SettingsHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isDuplicate(AvoidRoadInfo item) {
|
||||
public boolean isDuplicate(@NonNull AvoidRoadInfo item) {
|
||||
for (AvoidRoadInfo existingItem : existingItems) {
|
||||
if (item.latitude == existingItem.latitude && item.longitude == existingItem.longitude) {
|
||||
if (item.latitude == existingItem.latitude
|
||||
&& item.longitude == existingItem.longitude
|
||||
&& item.name.equals(existingItem.name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1537,9 +1545,13 @@ public class SettingsHelper {
|
|||
int number = 0;
|
||||
while (true) {
|
||||
number++;
|
||||
AvoidRoadInfo renamedItem = item;
|
||||
renamedItem.name = renamedItem.name + "_" + number;
|
||||
AvoidRoadInfo renamedItem = new AvoidRoadInfo();
|
||||
renamedItem.name = item.name + "_" + number;
|
||||
if (!isDuplicate(renamedItem)) {
|
||||
renamedItem.id = item.id;
|
||||
renamedItem.latitude = item.latitude;
|
||||
renamedItem.longitude = item.longitude;
|
||||
renamedItem.appModeKey = item.appModeKey;
|
||||
return renamedItem;
|
||||
}
|
||||
}
|
||||
|
@ -1581,7 +1593,11 @@ public class SettingsHelper {
|
|||
roadInfo.latitude = latitude;
|
||||
roadInfo.longitude = longitude;
|
||||
roadInfo.name = name;
|
||||
roadInfo.appModeKey = appModeKey;
|
||||
if (ApplicationMode.valueOfStringKey(appModeKey, null) != null) {
|
||||
roadInfo.appModeKey = appModeKey;
|
||||
} else {
|
||||
roadInfo.appModeKey = app.getRoutingHelper().getAppMode().getStringKey();
|
||||
}
|
||||
items.add(roadInfo);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
@ -1814,7 +1830,12 @@ public class SettingsHelper {
|
|||
if (item != null && collecting && item.shouldReadOnCollecting()
|
||||
|| item != null && !collecting && !item.shouldReadOnCollecting()) {
|
||||
try {
|
||||
item.getReader().readFromStream(ois);
|
||||
for (SettingsItem settingsItem : items) {
|
||||
if (item.getFileName().equals(settingsItem.getFileName())) {
|
||||
item.setShouldReplace(settingsItem.shouldReplace);
|
||||
item.getReader().readFromStream(ois);
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOG.error("Error reading item data: " + item.getName(), e);
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -782,7 +782,7 @@ public class ImportHelper {
|
|||
if (fragmentManager != null) {
|
||||
ImportSettingsFragment.showInstance(fragmentManager, items, file);
|
||||
}
|
||||
} else {
|
||||
} else if (empty) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_import_error, name, app.getString(R.string.shared_string_unexpected_error)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,9 +239,20 @@ public class RendererRegistry {
|
|||
}
|
||||
|
||||
public void initRenderers(IProgress progress) {
|
||||
updateExternalRenderers();
|
||||
String r = app.getSettings().RENDERER.get();
|
||||
if(r != null){
|
||||
RenderingRulesStorage obj = getRenderer(r);
|
||||
if(obj != null){
|
||||
setCurrentSelectedRender(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateExternalRenderers() {
|
||||
File file = app.getAppPath(IndexConstants.RENDERERS_DIR);
|
||||
file.mkdirs();
|
||||
Map<String, File> externalRenderers = new LinkedHashMap<String, File>();
|
||||
Map<String, File> externalRenderers = new LinkedHashMap<String, File>();
|
||||
if (file.exists() && file.canRead()) {
|
||||
File[] lf = file.listFiles();
|
||||
if (lf != null) {
|
||||
|
@ -256,13 +267,6 @@ public class RendererRegistry {
|
|||
}
|
||||
}
|
||||
this.externalRenderers = externalRenderers;
|
||||
String r = app.getSettings().RENDERER.get();
|
||||
if(r != null){
|
||||
RenderingRulesStorage obj = getRenderer(r);
|
||||
if(obj != null){
|
||||
setCurrentSelectedRender(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<String> getRendererNames(){
|
||||
|
|
|
@ -121,7 +121,7 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
itemHolder.subTitle.setVisibility(View.GONE);
|
||||
} else if (currentItem instanceof AvoidRoadInfo) {
|
||||
itemHolder.title.setText(((AvoidRoadInfo) currentItem).name);
|
||||
itemHolder.icon.setImageResource(R.drawable.map_pin_avoid_road);
|
||||
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_alert, nightMode));
|
||||
itemHolder.subTitle.setVisibility(View.GONE);
|
||||
itemHolder.icon.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
|||
case AVOID_ROADS:
|
||||
AvoidRoadInfo avoidRoadInfo = (AvoidRoadInfo) currentItem;
|
||||
title.setText(avoidRoadInfo.name);
|
||||
icon.setImageResource(R.drawable.map_pin_avoid_road);
|
||||
icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_alert, nightMode));
|
||||
icon.setVisibility(View.VISIBLE);
|
||||
subText.setVisibility(View.GONE);
|
||||
break;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.settings;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -12,6 +13,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.plus.AppInitializer;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -28,6 +30,8 @@ import java.io.File;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.settings.ImportSettingsFragment.getDuplicatesData;
|
||||
|
||||
|
||||
public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implements View.OnClickListener {
|
||||
|
||||
|
@ -46,7 +50,6 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
|
|||
fragment.setDuplicatesList(duplicatesList);
|
||||
fragment.setSettingsItems(settingsItems);
|
||||
fragment.setFile(file);
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.show(fm, TAG);
|
||||
}
|
||||
|
||||
|
@ -55,6 +58,20 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
|
|||
super.onCreate(savedInstanceState);
|
||||
app = getMyApplication();
|
||||
nightMode = !getSettings().isLightContent();
|
||||
if (settingsItems == null) {
|
||||
settingsItems = app.getSettingsHelper().getSettingsItems();
|
||||
if (settingsItems != null) {
|
||||
duplicatesList = getDuplicatesData(settingsItems);
|
||||
} else {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
if (file == null) {
|
||||
file = app.getSettingsHelper().getSettingsFile();
|
||||
if (file == null) {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -82,6 +99,21 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
|
|||
return root;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return new Dialog(requireActivity(), getTheme()) {
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (fm != null) {
|
||||
ImportSettingsFragment.showInstance(fm, null, file);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
@ -174,6 +206,12 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
|
|||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
if (succeed) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, file.getName()));
|
||||
app.getRendererRegistry().updateExternalRenderers();
|
||||
AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
|
||||
@Override
|
||||
public void onRoutingFilesLoaded() {
|
||||
}
|
||||
});
|
||||
} else if (empty) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error)));
|
||||
}
|
||||
|
@ -191,6 +229,10 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
|
|||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (fm != null) {
|
||||
ImportSettingsFragment.showInstance(fm, null, file);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package net.osmand.plus.settings;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -12,6 +16,7 @@ import android.widget.ExpandableListView;
|
|||
|
||||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.map.TileSourceManager;
|
||||
import net.osmand.plus.AppInitializer;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -43,7 +48,7 @@ public class ImportSettingsFragment extends BaseOsmAndDialogFragment
|
|||
private boolean allSelected;
|
||||
private boolean nightMode;
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fm, @NonNull List<SettingsItem> settingsItems, @NonNull File file) {
|
||||
public static void showInstance(@NonNull FragmentManager fm, List<SettingsItem> settingsItems, @NonNull File file) {
|
||||
ImportSettingsFragment fragment = new ImportSettingsFragment();
|
||||
fragment.setSettingsItems(settingsItems);
|
||||
fragment.setFile(file);
|
||||
|
@ -57,9 +62,15 @@ public class ImportSettingsFragment extends BaseOsmAndDialogFragment
|
|||
nightMode = !getSettings().isLightContent();
|
||||
if (settingsItems == null) {
|
||||
settingsItems = app.getSettingsHelper().getSettingsItems();
|
||||
if (settingsItems == null) {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
if (file == null) {
|
||||
file = app.getSettingsHelper().getSettingsFile();
|
||||
if (file == null) {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,6 +95,17 @@ public class ImportSettingsFragment extends BaseOsmAndDialogFragment
|
|||
expandableList.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return new Dialog(requireActivity(), getTheme()) {
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
showExitDialog();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
|
@ -113,6 +135,12 @@ public class ImportSettingsFragment extends BaseOsmAndDialogFragment
|
|||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
if (succeed) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, file.getName()));
|
||||
app.getRendererRegistry().updateExternalRenderers();
|
||||
AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
|
||||
@Override
|
||||
public void onRoutingFilesLoaded() {
|
||||
}
|
||||
});
|
||||
} else if (empty) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error)));
|
||||
}
|
||||
|
@ -125,7 +153,7 @@ public class ImportSettingsFragment extends BaseOsmAndDialogFragment
|
|||
}
|
||||
}
|
||||
|
||||
private List<Object> getDuplicatesData(List<SettingsItem> items) {
|
||||
public static List<Object> getDuplicatesData(List<SettingsItem> items) {
|
||||
List<Object> duplicateItems = new ArrayList<>();
|
||||
for (SettingsItem item : items) {
|
||||
if (item instanceof SettingsHelper.ProfileSettingsItem) {
|
||||
|
@ -275,15 +303,30 @@ public class ImportSettingsFragment extends BaseOsmAndDialogFragment
|
|||
return settingsToOperate;
|
||||
}
|
||||
|
||||
public void showExitDialog() {
|
||||
Context themedContext = UiUtilities.getThemedContext(getActivity(), nightMode);
|
||||
AlertDialog.Builder dismissDialog = new AlertDialog.Builder(themedContext);
|
||||
dismissDialog.setTitle(getString(R.string.shared_string_dismiss));
|
||||
dismissDialog.setMessage(getString(R.string.exit_without_saving));
|
||||
dismissDialog.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
dismissDialog.setPositiveButton(R.string.shared_string_exit, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
dismissDialog.show();
|
||||
}
|
||||
|
||||
private void setupToolbar(Toolbar toolbar) {
|
||||
toolbar.setNavigationIcon(getPaintedContentIcon(R.drawable.headline_close_button, nightMode
|
||||
toolbar.setNavigationIcon(getPaintedContentIcon(R.drawable.ic_action_close, 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();
|
||||
showExitDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue