avoid roads, refactor, corrections

This commit is contained in:
veliymolfar 2020-02-21 18:03:28 +02:00
parent a685cf4637
commit 321aa96846
13 changed files with 173 additions and 53 deletions

View file

@ -46,8 +46,7 @@
android:paddingBottom="@dimen/list_header_settings_top_margin" android:paddingBottom="@dimen/list_header_settings_top_margin"
android:text="@string/select_data_to_import" android:text="@string/select_data_to_import"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size" />
osmand:typeface="@string/font_roboto_medium" />
<include layout="@layout/card_bottom_divider" /> <include layout="@layout/card_bottom_divider" />
@ -62,7 +61,7 @@
android:groupIndicator="@android:color/transparent" android:groupIndicator="@android:color/transparent"
android:listSelector="@android:color/transparent" /> android:listSelector="@android:color/transparent" />
<include layout="@layout/card_top_divider" /> <include layout="@layout/divider" />
<LinearLayout <LinearLayout
android:id="@+id/buttons_container" android:id="@+id/buttons_container"

View file

@ -44,8 +44,7 @@
android:paddingBottom="@dimen/list_header_settings_top_margin" android:paddingBottom="@dimen/list_header_settings_top_margin"
android:text="@string/import_duplicates_description" android:text="@string/import_duplicates_description"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size" />
osmand:typeface="@string/font_roboto_medium" />
<include <include
android:id="@+id/description_divider" android:id="@+id/description_divider"
@ -57,8 +56,7 @@
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" /> android:layout_weight="1" />
<include <include layout="@layout/divider" />
layout="@layout/card_top_divider" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -4,14 +4,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="@dimen/setting_list_item_small_height"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/bg_color" android:background="?attr/bg_color"
android:gravity="center_vertical" android:gravity="center_vertical">
android:minHeight="66dp">
<ImageView <ImageView
android:id="@+id/icon" android:id="@+id/icon"
@ -23,12 +23,16 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" 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 <net.osmand.plus.widgets.TextViewEx
android:id="@+id/title" android:id="@+id/title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
tools:text="OffRoad" /> tools:text="OffRoad" />
@ -37,6 +41,8 @@
android:id="@+id/sub_title" android:id="@+id/sub_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"
tools:text="Navigation type: Car" /> tools:text="Navigation type: Car" />

View file

@ -4,6 +4,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="@dimen/setting_list_item_small_height"
android:orientation="vertical"> android:orientation="vertical">
<FrameLayout <FrameLayout
@ -15,8 +16,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:gravity="center_vertical" android:gravity="center_vertical">
android:minHeight="66dp">
<ImageView <ImageView
android:id="@+id/icon" android:id="@+id/icon"
@ -30,12 +30,16 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_weight="1" 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 <net.osmand.plus.widgets.TextViewEx
android:id="@+id/title_tv" android:id="@+id/title_tv"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
tools:text="Quick actions" /> tools:text="Quick actions" />
@ -44,6 +48,8 @@
android:id="@+id/sub_title_tv" android:id="@+id/sub_title_tv"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"
android:visibility="gone" android:visibility="gone"

View file

@ -353,5 +353,6 @@
<dimen name="setting_profile_item_switch_margin">18dp</dimen> <dimen name="setting_profile_item_switch_margin">18dp</dimen>
<dimen name="settings_divider_margin_start">72dp</dimen> <dimen name="settings_divider_margin_start">72dp</dimen>
<dimen name="setting_list_item_large_height">72dp</dimen> <dimen name="setting_list_item_large_height">72dp</dimen>
<dimen name="setting_list_item_small_height">42dp</dimen>
</resources> </resources>

View file

@ -72,7 +72,7 @@
<string name="sunset_at">Sunset at %1$s</string> <string name="sunset_at">Sunset at %1$s</string>
<string name="sunrise_at">Sunrise at %1$s</string> <string name="sunrise_at">Sunrise at %1$s</string>
<string name="shared_string_routing">Routing</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="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="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> <string name="export_profile_dialog_description">You can select additional data to export along with the profile.</string>

View file

@ -805,7 +805,7 @@ public class SettingsHelper {
@Override @Override
public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException { public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException {
OutputStream output; OutputStream output;
if (shouldReplace || !file.exists()) { if (!file.exists() || file.exists() && shouldReplace) {
output = new FileOutputStream(file); output = new FileOutputStream(file);
} else { } else {
output = new FileOutputStream(renameFile(file)); output = new FileOutputStream(renameFile(file));
@ -847,6 +847,7 @@ public class SettingsHelper {
this.app = app; this.app = app;
actionRegistry = app.getQuickActionRegistry(); actionRegistry = app.getQuickActionRegistry();
existingItems = actionRegistry.getQuickActions(); existingItems = actionRegistry.getQuickActions();
duplicateItems = new ArrayList<>();
} }
QuickActionSettingsItem(@NonNull OsmandApplication app, QuickActionSettingsItem(@NonNull OsmandApplication app,
@ -855,6 +856,7 @@ public class SettingsHelper {
this.app = app; this.app = app;
actionRegistry = app.getQuickActionRegistry(); actionRegistry = app.getQuickActionRegistry();
existingItems = actionRegistry.getQuickActions(); existingItems = actionRegistry.getQuickActions();
duplicateItems = new ArrayList<>();
} }
@Override @Override
@ -871,7 +873,6 @@ public class SettingsHelper {
@NonNull @NonNull
@Override @Override
public List<QuickAction> excludeDuplicateItems() { public List<QuickAction> excludeDuplicateItems() {
duplicateItems = new ArrayList<>();
for (QuickAction item : items) { for (QuickAction item : items) {
if (isDuplicate(item)) { if (isDuplicate(item)) {
duplicateItems.add(item); duplicateItems.add(item);
@ -1026,12 +1027,14 @@ public class SettingsHelper {
super(SettingsItemType.POI_UI_FILTERS, items); super(SettingsItemType.POI_UI_FILTERS, items);
this.app = app; this.app = app;
existingItems = app.getPoiFilters().getUserDefinedPoiFilters(false); existingItems = app.getPoiFilters().getUserDefinedPoiFilters(false);
duplicateItems = new ArrayList<>();
} }
PoiUiFilterSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException { PoiUiFilterSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(SettingsItemType.POI_UI_FILTERS, json); super(SettingsItemType.POI_UI_FILTERS, json);
this.app = app; this.app = app;
existingItems = app.getPoiFilters().getUserDefinedPoiFilters(false); existingItems = app.getPoiFilters().getUserDefinedPoiFilters(false);
duplicateItems = new ArrayList<>();
} }
@Override @Override
@ -1061,7 +1064,6 @@ public class SettingsHelper {
@NonNull @NonNull
@Override @Override
public List<PoiUIFilter> excludeDuplicateItems() { public List<PoiUIFilter> excludeDuplicateItems() {
duplicateItems = new ArrayList<>();
if (!items.isEmpty()) { if (!items.isEmpty()) {
for (PoiUIFilter item : items) { for (PoiUIFilter item : items) {
if (isDuplicate(item)) { if (isDuplicate(item)) {
@ -1212,6 +1214,7 @@ public class SettingsHelper {
this.app = app; this.app = app;
Collection values = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true)).values(); Collection values = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true)).values();
existingItemsNames = new ArrayList(values); existingItemsNames = new ArrayList(values);
duplicateItems = new ArrayList<>();
} }
MapSourcesSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException { MapSourcesSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
@ -1219,6 +1222,7 @@ public class SettingsHelper {
this.app = app; this.app = app;
Collection values = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true)).values(); Collection values = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true)).values();
existingItemsNames = new ArrayList(values); existingItemsNames = new ArrayList(values);
duplicateItems = new ArrayList<>();
} }
@Override @Override
@ -1261,7 +1265,6 @@ public class SettingsHelper {
@NonNull @NonNull
@Override @Override
public List<ITileSource> excludeDuplicateItems() { public List<ITileSource> excludeDuplicateItems() {
duplicateItems = new ArrayList<>();
for (String name : existingItemsNames) { for (String name : existingItemsNames) {
for (ITileSource tileSource : items) { for (ITileSource tileSource : items) {
if (name.equals(tileSource.getName())) { if (name.equals(tileSource.getName())) {
@ -1456,6 +1459,7 @@ public class SettingsHelper {
settings = app.getSettings(); settings = app.getSettings();
specificRoads = app.getAvoidSpecificRoads(); specificRoads = app.getAvoidSpecificRoads();
existingItems = new ArrayList<>(specificRoads.getImpassableRoads().values()); existingItems = new ArrayList<>(specificRoads.getImpassableRoads().values());
duplicateItems = new ArrayList<>();
} }
AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException { AvoidRoadsSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
@ -1464,6 +1468,7 @@ public class SettingsHelper {
settings = app.getSettings(); settings = app.getSettings();
specificRoads = app.getAvoidSpecificRoads(); specificRoads = app.getAvoidSpecificRoads();
existingItems = new ArrayList<>(specificRoads.getImpassableRoads().values()); existingItems = new ArrayList<>(specificRoads.getImpassableRoads().values());
duplicateItems = new ArrayList<>();
} }
@NonNull @NonNull
@ -1486,6 +1491,7 @@ public class SettingsHelper {
@Override @Override
public void apply() { public void apply() {
if (!items.isEmpty() || !duplicateItems.isEmpty()) {
for (AvoidRoadInfo duplicate : duplicateItems) { for (AvoidRoadInfo duplicate : duplicateItems) {
if (shouldReplace) { if (shouldReplace) {
LatLon latLon = new LatLon(duplicate.latitude, duplicate.longitude); LatLon latLon = new LatLon(duplicate.latitude, duplicate.longitude);
@ -1493,7 +1499,7 @@ public class SettingsHelper {
settings.addImpassableRoad(duplicate); settings.addImpassableRoad(duplicate);
} }
} else { } else {
settings.addImpassableRoad(duplicate); settings.addImpassableRoad(renameItem(duplicate));
} }
} }
for (AvoidRoadInfo avoidRoad : items) { for (AvoidRoadInfo avoidRoad : items) {
@ -1502,11 +1508,11 @@ public class SettingsHelper {
specificRoads.loadImpassableRoads(); specificRoads.loadImpassableRoads();
specificRoads.initRouteObjects(true); specificRoads.initRouteObjects(true);
} }
}
@NonNull @NonNull
@Override @Override
public List<AvoidRoadInfo> excludeDuplicateItems() { public List<AvoidRoadInfo> excludeDuplicateItems() {
duplicateItems = new ArrayList<>();
for (AvoidRoadInfo item : items) { for (AvoidRoadInfo item : items) {
if (isDuplicate(item)) { if (isDuplicate(item)) {
duplicateItems.add(item); duplicateItems.add(item);
@ -1517,9 +1523,11 @@ public class SettingsHelper {
} }
@Override @Override
public boolean isDuplicate(AvoidRoadInfo item) { public boolean isDuplicate(@NonNull AvoidRoadInfo item) {
for (AvoidRoadInfo existingItem : existingItems) { 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; return true;
} }
} }
@ -1537,9 +1545,13 @@ public class SettingsHelper {
int number = 0; int number = 0;
while (true) { while (true) {
number++; number++;
AvoidRoadInfo renamedItem = item; AvoidRoadInfo renamedItem = new AvoidRoadInfo();
renamedItem.name = renamedItem.name + "_" + number; renamedItem.name = item.name + "_" + number;
if (!isDuplicate(renamedItem)) { if (!isDuplicate(renamedItem)) {
renamedItem.id = item.id;
renamedItem.latitude = item.latitude;
renamedItem.longitude = item.longitude;
renamedItem.appModeKey = item.appModeKey;
return renamedItem; return renamedItem;
} }
} }
@ -1581,7 +1593,11 @@ public class SettingsHelper {
roadInfo.latitude = latitude; roadInfo.latitude = latitude;
roadInfo.longitude = longitude; roadInfo.longitude = longitude;
roadInfo.name = name; roadInfo.name = name;
if (ApplicationMode.valueOfStringKey(appModeKey, null) != null) {
roadInfo.appModeKey = appModeKey; roadInfo.appModeKey = appModeKey;
} else {
roadInfo.appModeKey = app.getRoutingHelper().getAppMode().getStringKey();
}
items.add(roadInfo); items.add(roadInfo);
} }
} catch (JSONException e) { } catch (JSONException e) {
@ -1814,7 +1830,12 @@ public class SettingsHelper {
if (item != null && collecting && item.shouldReadOnCollecting() if (item != null && collecting && item.shouldReadOnCollecting()
|| item != null && !collecting && !item.shouldReadOnCollecting()) { || item != null && !collecting && !item.shouldReadOnCollecting()) {
try { try {
for (SettingsItem settingsItem : items) {
if (item.getFileName().equals(settingsItem.getFileName())) {
item.setShouldReplace(settingsItem.shouldReplace);
item.getReader().readFromStream(ois); item.getReader().readFromStream(ois);
}
}
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
LOG.error("Error reading item data: " + item.getName(), e); LOG.error("Error reading item data: " + item.getName(), e);
} catch (IOException e) { } catch (IOException e) {

View file

@ -782,7 +782,7 @@ public class ImportHelper {
if (fragmentManager != null) { if (fragmentManager != null) {
ImportSettingsFragment.showInstance(fragmentManager, items, file); 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))); app.showShortToastMessage(app.getString(R.string.file_import_error, name, app.getString(R.string.shared_string_unexpected_error)));
} }
} }

View file

@ -239,6 +239,17 @@ public class RendererRegistry {
} }
public void initRenderers(IProgress progress) { 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 file = app.getAppPath(IndexConstants.RENDERERS_DIR);
file.mkdirs(); file.mkdirs();
Map<String, File> externalRenderers = new LinkedHashMap<String, File>(); Map<String, File> externalRenderers = new LinkedHashMap<String, File>();
@ -256,13 +267,6 @@ public class RendererRegistry {
} }
} }
this.externalRenderers = externalRenderers; 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(){ public Collection<String> getRendererNames(){

View file

@ -121,7 +121,7 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
itemHolder.subTitle.setVisibility(View.GONE); itemHolder.subTitle.setVisibility(View.GONE);
} else if (currentItem instanceof AvoidRoadInfo) { } else if (currentItem instanceof AvoidRoadInfo) {
itemHolder.title.setText(((AvoidRoadInfo) currentItem).name); 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.subTitle.setVisibility(View.GONE);
itemHolder.icon.setVisibility(View.VISIBLE); itemHolder.icon.setVisibility(View.VISIBLE);
} }

View file

@ -217,7 +217,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
case AVOID_ROADS: case AVOID_ROADS:
AvoidRoadInfo avoidRoadInfo = (AvoidRoadInfo) currentItem; AvoidRoadInfo avoidRoadInfo = (AvoidRoadInfo) currentItem;
title.setText(avoidRoadInfo.name); 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); icon.setVisibility(View.VISIBLE);
subText.setVisibility(View.GONE); subText.setVisibility(View.GONE);
break; break;

View file

@ -1,5 +1,6 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -12,6 +13,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.plus.AppInitializer;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -28,6 +30,8 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static net.osmand.plus.settings.ImportSettingsFragment.getDuplicatesData;
public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implements View.OnClickListener { public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implements View.OnClickListener {
@ -46,7 +50,6 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
fragment.setDuplicatesList(duplicatesList); fragment.setDuplicatesList(duplicatesList);
fragment.setSettingsItems(settingsItems); fragment.setSettingsItems(settingsItems);
fragment.setFile(file); fragment.setFile(file);
fragment.setRetainInstance(true);
fragment.show(fm, TAG); fragment.show(fm, TAG);
} }
@ -55,6 +58,20 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
app = getMyApplication(); app = getMyApplication();
nightMode = !getSettings().isLightContent(); 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 @Nullable
@ -82,6 +99,21 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
return root; 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 @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, 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) { public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
if (succeed) { if (succeed) {
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, file.getName())); 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) { } else if (empty) {
app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error))); 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() { toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
FragmentManager fm = getFragmentManager();
if (fm != null) {
ImportSettingsFragment.showInstance(fm, null, file);
}
dismiss(); dismiss();
} }
}); });

View file

@ -1,9 +1,13 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -12,6 +16,7 @@ import android.widget.ExpandableListView;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager; import net.osmand.map.TileSourceManager;
import net.osmand.plus.AppInitializer;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -43,7 +48,7 @@ public class ImportSettingsFragment extends BaseOsmAndDialogFragment
private boolean allSelected; private boolean allSelected;
private boolean nightMode; 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(); ImportSettingsFragment fragment = new ImportSettingsFragment();
fragment.setSettingsItems(settingsItems); fragment.setSettingsItems(settingsItems);
fragment.setFile(file); fragment.setFile(file);
@ -57,9 +62,15 @@ public class ImportSettingsFragment extends BaseOsmAndDialogFragment
nightMode = !getSettings().isLightContent(); nightMode = !getSettings().isLightContent();
if (settingsItems == null) { if (settingsItems == null) {
settingsItems = app.getSettingsHelper().getSettingsItems(); settingsItems = app.getSettingsHelper().getSettingsItems();
if (settingsItems == null) {
dismiss();
}
} }
if (file == null) { if (file == null) {
file = app.getSettingsHelper().getSettingsFile(); file = app.getSettingsHelper().getSettingsFile();
if (file == null) {
dismiss();
}
} }
} }
@ -84,6 +95,17 @@ public class ImportSettingsFragment extends BaseOsmAndDialogFragment
expandableList.setAdapter(adapter); expandableList.setAdapter(adapter);
} }
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new Dialog(requireActivity(), getTheme()) {
@Override
public void onBackPressed() {
showExitDialog();
}
};
}
@Override @Override
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
@ -113,6 +135,12 @@ public class ImportSettingsFragment extends BaseOsmAndDialogFragment
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) { public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
if (succeed) { if (succeed) {
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, file.getName())); 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) { } else if (empty) {
app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error))); 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<>(); List<Object> duplicateItems = new ArrayList<>();
for (SettingsItem item : items) { for (SettingsItem item : items) {
if (item instanceof SettingsHelper.ProfileSettingsItem) { if (item instanceof SettingsHelper.ProfileSettingsItem) {
@ -275,15 +303,30 @@ public class ImportSettingsFragment extends BaseOsmAndDialogFragment
return settingsToOperate; 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) { 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_dark)
: getResources().getColor(R.color.active_buttons_and_links_text_light))); : getResources().getColor(R.color.active_buttons_and_links_text_light)));
toolbar.setNavigationContentDescription(R.string.shared_string_close); toolbar.setNavigationContentDescription(R.string.shared_string_close);
toolbar.setNavigationOnClickListener(new View.OnClickListener() { toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
dismiss(); showExitDialog();
} }
}); });
} }