diff --git a/OsmAnd/res/layout/bottom_sheet_item_additional_data.xml b/OsmAnd/res/layout/bottom_sheet_item_additional_data.xml
index 8a677926b4..0e4d9e7a3c 100644
--- a/OsmAnd/res/layout/bottom_sheet_item_additional_data.xml
+++ b/OsmAnd/res/layout/bottom_sheet_item_additional_data.xml
@@ -1,31 +1,20 @@
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingBottom="20dp">
-
-
-
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/item_header_export_expand_list.xml b/OsmAnd/res/layout/item_header_export_expand_list.xml
new file mode 100644
index 0000000000..062c20398c
--- /dev/null
+++ b/OsmAnd/res/layout/item_header_export_expand_list.xml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/profile_data_list_item_child.xml b/OsmAnd/res/layout/profile_data_list_item_child.xml
index f6471514ed..e0a04a1892 100644
--- a/OsmAnd/res/layout/profile_data_list_item_child.xml
+++ b/OsmAnd/res/layout/profile_data_list_item_child.xml
@@ -55,6 +55,7 @@
modes, OsmandApplication app) {
@@ -789,25 +793,25 @@ public class ApplicationMode {
}
}
- static class ApplicationModeBean {
+ public static class ApplicationModeBean {
@Expose
- String stringKey;
+ public String stringKey;
@Expose
- String userProfileName;
+ public String userProfileName;
@Expose
- String parent;
+ public String parent;
@Expose
- String iconName = "map_world_globe_dark";
+ public String iconName = "map_world_globe_dark";
@Expose
- ProfileIconColors iconColor = ProfileIconColors.DEFAULT;
+ public ProfileIconColors iconColor = ProfileIconColors.DEFAULT;
@Expose
- String routingProfile = null;
+ public String routingProfile = null;
@Expose
- RouteService routeService = RouteService.OSMAND;
+ public RouteService routeService = RouteService.OSMAND;
@Expose
- LocationIcon locIcon = null;
+ public LocationIcon locIcon = null;
@Expose
- NavigationIcon navIcon = null;
+ public NavigationIcon navIcon = null;
@Expose
int order = -1;
}
diff --git a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java
index 1a677c10f4..3f4fee3c87 100644
--- a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java
+++ b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java
@@ -111,10 +111,9 @@ public class SQLiteTileSource implements ITileSource {
db = ctx.getSQLiteAPI().getOrCreateDatabase(
ctx.getAppPath(TILES_INDEX_DIR).getAbsolutePath() + "/" + name + SQLITE_EXT, true);
- db.execSQL("CREATE TABLE IF NOT EXIST tiles (x int, y int, z int, s int, image blob, time long, PRIMARY KEY (x,y,z,s))");
+ db.execSQL("CREATE TABLE tiles (x int, y int, z int, s int, image blob, time long, PRIMARY KEY (x,y,z,s))");
db.execSQL("CREATE INDEX IND on tiles (x,y,z,s)");
- db.execSQL("CREATE TABLE IF NOT EXIST info(tilenumbering,minzoom,maxzoom)");
- db.execSQL("CREATE TABLE IF NOT EXIST android_metadata (locale TEXT)");
+ db.execSQL("CREATE TABLE info(tilenumbering,minzoom,maxzoom)");
db.execSQL("INSERT INTO info (tilenumbering,minzoom,maxzoom) VALUES ('simple','" + minZoom + "','" + maxZoom + "');");
addInfoColumn(URL, urlTemplate);
diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java
index e709b73c65..4f4ddd6d3a 100644
--- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java
+++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java
@@ -436,24 +436,39 @@ public class SettingsHelper {
private ApplicationModeBuilder builder;
private ApplicationModeBean modeBean;
private Set appModeBeanPrefsIds;
+ private OsmandApplication app;
-
- public ProfileSettingsItem(@NonNull OsmandSettings settings, @NonNull ApplicationMode appMode) {
- super(SettingsItemType.PROFILE, settings);
+ public ProfileSettingsItem(@NonNull OsmandApplication app, @NonNull ApplicationMode appMode) {
+ super(SettingsItemType.PROFILE, app.getSettings());
this.appMode = appMode;
- appModeBeanPrefsIds = new HashSet<>(Arrays.asList(settings.appModeBeanPrefsIds));
+ this.app = app;
+ appModeBeanPrefsIds = new HashSet<>(Arrays.asList(app.getSettings().appModeBeanPrefsIds));
}
- public ProfileSettingsItem(@NonNull OsmandSettings settings, @NonNull JSONObject json) throws JSONException {
- super(SettingsItemType.PROFILE, settings, json);
- readFromJson(settings.getContext(), json);
- appModeBeanPrefsIds = new HashSet<>(Arrays.asList(settings.appModeBeanPrefsIds));
+ public ProfileSettingsItem(@NonNull OsmandApplication app, @NonNull ApplicationModeBean modeBean) {
+ super(SettingsItemType.PROFILE, app.getSettings());
+ this.app = app;
+ this.modeBean = modeBean;
+ builder = ApplicationMode.fromModeBean(app, modeBean);
+ appMode = builder.getApplicationMode();
+ appModeBeanPrefsIds = new HashSet<>(Arrays.asList(app.getSettings().appModeBeanPrefsIds));
+ }
+
+ public ProfileSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
+ super(SettingsItemType.PROFILE, app.getSettings(), json);
+ this.app = app;
+ readFromJson(app.getSettings().getContext(), json);
+ appModeBeanPrefsIds = new HashSet<>(Arrays.asList(app.getSettings().appModeBeanPrefsIds));
}
public ApplicationMode getAppMode() {
return appMode;
}
+ public ApplicationModeBean getModeBean() {
+ return modeBean;
+ }
+
@NonNull
@Override
public String getName() {
@@ -491,12 +506,6 @@ public class SettingsHelper {
@Override
public boolean exists() {
- List profiles = ApplicationMode.allPossibleValues();
- for (ApplicationMode profile : profiles) {
- if (appMode.toHumanString().equals(profile.toHumanString())) {
- return true;
- }
- }
return builder != null && ApplicationMode.valueOfStringKey(getName(), null) != null;
}
@@ -504,9 +513,12 @@ public class SettingsHelper {
public void apply() {
if (appMode.isCustomProfile()) {
if (!shouldReplace) {
- appMode.setUserProfileName(COPY_PREFIX + appMode.getUserProfileName());
+ modeBean.stringKey = COPY_PREFIX + modeBean.stringKey;
+ modeBean.userProfileName = COPY_PREFIX + modeBean.userProfileName;
+ builder = ApplicationMode.fromModeBean(app, modeBean);
}
appMode = ApplicationMode.saveProfile(builder, getSettings().getContext());
+ ApplicationMode.changeProfileAvailability(appMode, true, app);
}
}
@@ -716,6 +728,16 @@ public class SettingsHelper {
return file.exists();
}
+ private File renameFile(File file) {
+ String path = file.getAbsolutePath();
+ String copyName = path.replaceAll(file.getName(), COPY_PREFIX + file.getName());
+ File copyFile = new File(copyName);
+ if (file.exists()) {
+ renameFile(copyFile);
+ }
+ return copyFile;
+ }
+
@NonNull
@Override
SettingsItemReader getReader() {
@@ -723,13 +745,14 @@ public class SettingsHelper {
@Override
public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException {
OutputStream output;
- if (shouldReplace) {
+ if (shouldReplace || !file.exists()) {
output = new FileOutputStream(file);
} else {
- String path = file.getAbsolutePath();
- String copyName = path.replaceAll(file.getName(), COPY_PREFIX + file.getName());
- File copyFile = new File(copyName);
- output = new FileOutputStream(copyFile);
+// String path = file.getAbsolutePath();
+// String copyName = path.replaceAll(file.getName(), COPY_PREFIX + file.getName());
+// File copyFile = new File(copyName);
+// output = new FileOutputStream(copyFile);
+ output = new FileOutputStream(renameFile(file));
}
byte[] buffer = new byte[BUFFER];
int count;
@@ -955,7 +978,8 @@ public class SettingsHelper {
if (!poiUIFilters.isEmpty() || !duplicates.isEmpty()) {
for (PoiUIFilter duplicate : duplicates) {
if (!shouldReplace) {
- duplicate.setName(COPY_PREFIX + duplicate.getName());
+ renamePoiFilter(duplicate);
+// duplicate.setName(COPY_PREFIX + duplicate.getName());
}
poiUIFilters.add(duplicate);
}
@@ -966,6 +990,23 @@ public class SettingsHelper {
}
}
+ private void renamePoiFilter(PoiUIFilter poiUIFilter) {
+ poiUIFilter.setName(COPY_PREFIX + poiUIFilter.getName());
+ if (duplicateExists(poiUIFilter)) {
+ renamePoiFilter(poiUIFilter);
+ }
+ }
+
+ private boolean duplicateExists(PoiUIFilter poiUIFilter) {
+ List userPoiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
+ for (PoiUIFilter filter : userPoiList) {
+ if (filter.getName().equals(poiUIFilter.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public List getDuplicates() {
List duplicates = new ArrayList<>();
List userPoiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
@@ -1114,19 +1155,28 @@ public class SettingsHelper {
if (!mapSources.isEmpty() || !duplicates.isEmpty()) {
if (shouldReplace) {
for (ITileSource tileSource : duplicates) {
- File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName());
- if (f != null && f.exists()) {
- if (f.delete()) {
- mapSources.add(tileSource);
+ if (tileSource instanceof SQLiteTileSource) {
+ File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName() + IndexConstants.SQLITE_EXT);
+ if (f != null && f.exists()) {
+ if (f.delete()) {
+ mapSources.add(tileSource);
+ }
+ }
+ } else if (tileSource instanceof TileSourceManager.TileSourceTemplate) {
+ File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName());
+ if (f != null && f.exists() && f.isDirectory()) {
+ if (f.delete()) {
+ mapSources.add(tileSource);
+ }
}
}
}
} else {
for (ITileSource tileSource : duplicates) {
- tileSource.setName(COPY_PREFIX + tileSource.getName());
+ renameTileSource(tileSource);
+ mapSources.add(tileSource);
}
}
- mapSources.addAll(duplicates);
for (ITileSource template : mapSources) {
if (template instanceof TileSourceManager.TileSourceTemplate) {
getSettings().installTileSource((TileSourceManager.TileSourceTemplate) template);
@@ -1137,6 +1187,23 @@ public class SettingsHelper {
}
}
+ private void renameTileSource(ITileSource tileSource) {
+ tileSource.setName(COPY_PREFIX + tileSource.getName());
+ if (duplicateExists(tileSource)) {
+ renameTileSource(tileSource);
+ }
+ }
+
+ private boolean duplicateExists(ITileSource tileSource) {
+ LinkedHashMap tileSourceEntries = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true));
+ for (Map.Entry entry : tileSourceEntries.entrySet()) {
+ if (entry.getValue().equals(tileSource.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public List getDuplicates() {
List duplicates = new ArrayList<>();
final LinkedHashMap tileSourceEntries = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true));
@@ -1326,7 +1393,7 @@ public class SettingsHelper {
item = new GlobalSettingsItem(settings);
break;
case PROFILE:
- item = new ProfileSettingsItem(settings, json);
+ item = new ProfileSettingsItem(app, json);
break;
case PLUGIN:
break;
diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java
index 21fecfb2b4..06712dc32b 100644
--- a/OsmAnd/src/net/osmand/plus/UiUtilities.java
+++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java
@@ -22,6 +22,7 @@ import android.support.v7.view.ContextThemeWrapper;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.ImageView;
@@ -487,4 +488,12 @@ public class UiUtilities {
public static Context getThemedContext(Context context, boolean nightMode, int lightStyle, int darkStyle) {
return new ContextThemeWrapper(context, nightMode ? darkStyle : lightStyle);
}
+
+ public static void setMargins(View v, int l, int t, int r, int b) {
+ if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
+ ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
+ p.setMargins(l, t, r, b);
+ v.requestLayout();
+ }
+ }
}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java
index c520d9ca75..68a5958d50 100644
--- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java
@@ -192,7 +192,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
final View contentView = useScrollableItemsContainer() ? mainView.findViewById(R.id.scroll_view) : itemsContainer;
if (contentView.getHeight() > contentHeight) {
- if (useScrollableItemsContainer()) {
+ if (useScrollableItemsContainer() || useExpandableList()) {
contentView.getLayoutParams().height = contentHeight;
} else {
contentView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
@@ -231,6 +231,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
return true;
}
+ protected boolean useExpandableList() {
+ return false;
+ }
+
protected boolean hideButtonsContainer() {
return false;
}
diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java
index 0808f1e540..aa190ab5f7 100644
--- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java
@@ -399,9 +399,8 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
} else if (EXPORT_PROFILE.equals(prefId)) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
- ExportImportProfileBottomSheet.showInstance(
+ ExportProfileBottomSheet.showInstance(
fragmentManager,
- ExportImportProfileBottomSheet.State.EXPORT,
this,
getSelectedAppMode());
}
diff --git a/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java
index f28f3e08e5..e75beefc78 100644
--- a/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java
@@ -11,14 +11,17 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
+import net.osmand.AndroidUtils;
import net.osmand.map.ITileSource;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
+import net.osmand.plus.SettingsHelper;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.AdditionalDataWrapper;
+import net.osmand.plus.profiles.ProfileIconColors;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.render.RenderingIcons;
@@ -42,11 +45,19 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
this.importState = importState;
this.dataToOperate = new ArrayList<>();
this.profileColor = app.getSettings().getApplicationMode().getIconColorInfo().getColor(nightMode);
- if (!importState) {
- for (AdditionalDataWrapper dataWrapper : dataList) {
- dataToOperate.addAll(dataWrapper.getItems());
- }
- }
+// if (!importState) {
+// for (AdditionalDataWrapper dataWrapper : dataList) {
+// dataToOperate.addAll(dataWrapper.getItems());
+// }
+// }
+ }
+
+ ExportImportSettingsAdapter(OsmandApplication app, boolean nightMode) {
+ this.app = app;
+ this.nightMode = nightMode;
+ this.dataList = new ArrayList<>();
+ this.dataToOperate = new ArrayList<>();
+ this.profileColor = app.getSettings().getApplicationMode().getIconColorInfo().getColor(nightMode);
}
@Override
@@ -136,9 +147,11 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
switch (type) {
case PROFILE:
- title.setText(((ApplicationMode) currentItem).toHumanString());
- subText.setText(((ApplicationMode) currentItem).getDescription());
- icon.setImageDrawable(app.getUIUtilities().getIcon(((ApplicationMode) currentItem).getIconRes(), profileColor));
+ title.setText(((ApplicationMode.ApplicationModeBean) currentItem).userProfileName);
+ subText.setText(((ApplicationMode.ApplicationModeBean) currentItem).routingProfile);
+ int profileIconRes = AndroidUtils.getDrawableId(app, ((ApplicationMode.ApplicationModeBean) currentItem).iconName);
+ ProfileIconColors iconColor = ((ApplicationMode.ApplicationModeBean) currentItem).iconColor;
+ icon.setImageDrawable(app.getUIUtilities().getIcon(profileIconRes, iconColor.getColor(nightMode)));
subText.setVisibility(View.VISIBLE);
icon.setVisibility(View.VISIBLE);
break;
@@ -247,6 +260,11 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
notifyDataSetChanged();
}
+ public void clearSettingsList() {
+ this.dataList.clear();
+ notifyDataSetChanged();
+ }
+
public void selectAll(boolean selectAll) {
dataToOperate.clear();
if (selectAll) {
diff --git a/OsmAnd/src/net/osmand/plus/settings/ExportImportProfileBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java
similarity index 66%
rename from OsmAnd/src/net/osmand/plus/settings/ExportImportProfileBottomSheet.java
rename to OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java
index 9c429040ef..2966884c90 100644
--- a/OsmAnd/src/net/osmand/plus/settings/ExportImportProfileBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java
@@ -15,6 +15,7 @@ import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ExpandableListView;
+import android.widget.LinearLayout.LayoutParams;
import android.widget.Toast;
import net.osmand.AndroidUtils;
@@ -30,7 +31,6 @@ import net.osmand.plus.SettingsHelper;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
-import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.poi.PoiUIFilter;
@@ -48,38 +48,17 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
-
- private static final Log LOG = PlatformUtil.getLog(ExportImportProfileBottomSheet.class);
-
- public static final String TAG = ExportImportProfileBottomSheet.class.getSimpleName();
-
- private static final String STATE_KEY = "EXPORT_IMPORT_DIALOG_STATE_KEY";
+public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
+ private static final Log LOG = PlatformUtil.getLog(ExportProfileBottomSheet.class);
+ public static final String TAG = ExportProfileBottomSheet.class.getSimpleName();
private static final String INCLUDE_ADDITIONAL_DATA_KEY = "INCLUDE_ADDITIONAL_DATA_KEY";
-
private boolean includeAdditionalData = false;
-
- private boolean containsAdditionalData = false;
-
private OsmandApplication app;
-
private ApplicationMode profile;
-
- private State state;
-
private List dataList = new ArrayList<>();
-
- private List settingsItems;
-
- private ExpandableListView listView;
-
private ExportImportSettingsAdapter adapter;
- private SettingsHelper.ProfileSettingsItem profileSettingsItem;
-
- private File file;
-
@Override
public void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null) {
@@ -87,24 +66,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
}
super.onCreate(savedInstanceState);
app = requiredMyApplication();
- Bundle bundle = getArguments();
- if (bundle != null) {
- this.state = (State) getArguments().getSerializable(STATE_KEY);
- }
- if (state == State.IMPORT) {
- if (settingsItems == null) {
- settingsItems = app.getSettingsHelper().getSettingsItems();
- }
- if (file == null) {
- file = app.getSettingsHelper().getSettingsFile();
- }
- containsAdditionalData = checkAdditionalDataContains();
- } else {
- dataList = getAdditionalData();
-// for (AdditionalDataWrapper dataWrapper : dataList) {
-// dataToOperate.addAll(dataWrapper.getItems());
-// }
- }
+ dataList = getAdditionalData();
}
@Override
@@ -121,7 +83,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
}
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
- profile = state == State.IMPORT ? getAppModeFromSettingsItems() : getAppMode();
+ profile = getAppMode();
int profileColor = profile.getIconColorInfo().getColor(nightMode);
int colorNoAlpha = ContextCompat.getColor(context, profileColor);
@@ -129,9 +91,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
Drawable backgroundIcon = UiUtilities.getColoredSelectableDrawable(context, colorNoAlpha, 0.3f);
Drawable[] layers = {new ColorDrawable(UiUtilities.getColorWithAlpha(colorNoAlpha, 0.10f)), backgroundIcon};
- items.add(new TitleItem(state == State.EXPORT ?
- getString(R.string.export_profile)
- : getString(R.string.import_profile)));
+ items.add(new TitleItem(getString(R.string.export_profile)));
BaseBottomSheetItem profileItem = new BottomSheetItemWithCompoundButton.Builder()
.setChecked(true)
@@ -145,40 +105,42 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
.create();
items.add(profileItem);
- if (state == State.IMPORT && containsAdditionalData || state == State.EXPORT && !dataList.isEmpty()) {
- BaseBottomSheetItem descriptionItem = new BottomSheetItemWithDescription.Builder()
- .setDescription(state == State.EXPORT ?
- getString(R.string.export_profile_dialog_description)
- : getString(R.string.import_profile_dialog_description))
- .setLayoutId(R.layout.bottom_sheet_item_pref_info)
- .create();
- items.add(descriptionItem);
-
+ if (!dataList.isEmpty()) {
final View additionalDataView = inflater.inflate(R.layout.bottom_sheet_item_additional_data, null);
- listView = additionalDataView.findViewById(R.id.list);
- SwitchCompat switchItem = additionalDataView.findViewById(R.id.switchItem);
+ ExpandableListView listView = additionalDataView.findViewById(R.id.list);
+ adapter = new ExportImportSettingsAdapter(app, nightMode);
+ View listHeader = inflater.inflate(R.layout.item_header_export_expand_list, null);
+ final View topSwitchDivider = listHeader.findViewById(R.id.topSwitchDivider);
+ final View bottomSwitchDivider = listHeader.findViewById(R.id.bottomSwitchDivider);
+ final SwitchCompat switchItem = listHeader.findViewById(R.id.switchItem);
switchItem.setTextColor(getResources().getColor(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
switchItem.setChecked(includeAdditionalData);
switchItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
includeAdditionalData = !includeAdditionalData;
- listView.setVisibility(includeAdditionalData ?
- View.VISIBLE : View.GONE);
-// if (includeAdditionalData && state == State.IMPORT) {
-// updateDataToOperateFromSettingsItems();
-// }
+ topSwitchDivider.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE);
+ bottomSwitchDivider.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE);
+ if (includeAdditionalData) {
+ adapter.updateSettingsList(getAdditionalData());
+ adapter.selectAll(true);
+ } else {
+ adapter.selectAll(false);
+ adapter.clearSettingsList();
+ }
+ updateSwitch(switchItem);
setupHeightAndBackground(getView());
}
});
- listView.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE);
- adapter = new ExportImportSettingsAdapter(app, dataList, nightMode, false);
listView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int i) {
setupHeightAndBackground(getView());
}
});
+
+ updateSwitch(switchItem);
+ listView.addHeaderView(listHeader);
listView.setAdapter(adapter);
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
.setCustomView(additionalDataView)
@@ -187,19 +149,25 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
}
}
+ private void updateSwitch(View view) {
+ if (includeAdditionalData) {
+ UiUtilities.setMargins(view, 0, 0, 0, 0);
+ view.setPadding(AndroidUtils.dpToPx(app, 32), 0, AndroidUtils.dpToPx(app, 32), 0);
+ } else {
+ UiUtilities.setMargins(view, AndroidUtils.dpToPx(app, 16), 0, AndroidUtils.dpToPx(app, 16), 0);
+ view.setPadding(AndroidUtils.dpToPx(app, 16), 0, AndroidUtils.dpToPx(app, 16), 0);
+ }
+ }
+
@Override
protected int getRightBottomButtonTextId() {
- return state == State.EXPORT ? R.string.shared_string_export : R.string.shared_string_import;
+ return R.string.shared_string_export;
}
@Override
protected void onRightBottomButtonClick() {
super.onRightBottomButtonClick();
- if (state == State.EXPORT) {
- prepareFile();
- } else {
- importSettings();
- }
+ prepareFile();
}
@Override
@@ -212,14 +180,9 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
return false;
}
- private ApplicationMode getAppModeFromSettingsItems() {
- for (SettingsHelper.SettingsItem item : settingsItems) {
- if (item.getType().equals(SettingsHelper.SettingsItemType.PROFILE)) {
- profileSettingsItem = ((SettingsHelper.ProfileSettingsItem) item);
- return ((SettingsHelper.ProfileSettingsItem) item).getAppMode();
- }
- }
- return getAppMode();
+ @Override
+ protected boolean useExpandableList() {
+ return true;
}
private List getAdditionalData() {
@@ -287,7 +250,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
private List prepareSettingsItemsForExport() {
List settingsItems = new ArrayList<>();
- settingsItems.add(new SettingsHelper.ProfileSettingsItem(app.getSettings(), profile));
+ settingsItems.add(new SettingsHelper.ProfileSettingsItem(app, profile));
if (includeAdditionalData) {
settingsItems.addAll(prepareAdditionalSettingsItems());
}
@@ -323,39 +286,6 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
return settingsItems;
}
- private Boolean checkAdditionalDataContains() {
- boolean containsData = false;
- for (SettingsHelper.SettingsItem item : settingsItems) {
- containsData = item.getType().equals(SettingsHelper.SettingsItemType.QUICK_ACTION)
- || item.getType().equals(SettingsHelper.SettingsItemType.POI_UI_FILTERS)
- || item.getType().equals(SettingsHelper.SettingsItemType.MAP_SOURCES)
- || item.getType().equals(SettingsHelper.SettingsItemType.FILE);
- if (containsData) {
- break;
- }
- }
- return containsData;
- }
-
- private void importSettings() {
- List list = new ArrayList<>();
- list.add(profileSettingsItem);
- if (includeAdditionalData) {
- list.addAll(prepareAdditionalSettingsItems());
- }
- app.getSettingsHelper().importSettings(file, list, "", 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();
- }
-
private void prepareFile() {
if (app != null) {
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
@@ -393,14 +323,10 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
}
public static boolean showInstance(@NonNull FragmentManager fragmentManager,
- State state,
Fragment target,
@NonNull ApplicationMode appMode) {
try {
- Bundle bundle = new Bundle();
- bundle.putSerializable(STATE_KEY, state);
- ExportImportProfileBottomSheet fragment = new ExportImportProfileBottomSheet();
- fragment.setArguments(bundle);
+ ExportProfileBottomSheet fragment = new ExportProfileBottomSheet();
fragment.setAppMode(appMode);
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG);
@@ -409,39 +335,4 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
return false;
}
}
-
- public static boolean showInstance(@NonNull FragmentManager fragmentManager,
- State state,
- File file,
- List items) {
- try {
- Bundle bundle = new Bundle();
- bundle.putSerializable(STATE_KEY, state);
- ExportImportProfileBottomSheet fragment = new ExportImportProfileBottomSheet();
- fragment.setArguments(bundle);
- fragment.setSettingsItems(items);
- fragment.setFile(file);
- fragment.show(fragmentManager, TAG);
- return true;
- } catch (RuntimeException e) {
- return false;
- }
- }
-
- public void setSettingsItems(List settingsItems) {
- this.settingsItems = settingsItems;
- }
-
- public File getFile() {
- return file;
- }
-
- public void setFile(File file) {
- this.file = file;
- }
-
- public enum State {
- EXPORT,
- IMPORT
- }
}
diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java
index 8fe5428767..2486a45b89 100644
--- a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java
@@ -169,6 +169,10 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
}
}
});
+// if (getFragmentManager() != null) {
+// ImportSettingsFragment fragment = (ImportSettingsFragment) getFragmentManager().findFragmentByTag(ImportSettingsFragment.TAG);
+// fragment.dismiss();
+// }
dismiss();
}
diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java
index 26e52fd610..1bbc817cf6 100644
--- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java
@@ -1 +1 @@
-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