import custom profiles, ui fixes
This commit is contained in:
parent
c7f2de7f22
commit
a19e6a3576
14 changed files with 276 additions and 234 deletions
|
@ -1,31 +1,20 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
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:paddingBottom="20dp">
|
android:paddingBottom="20dp">
|
||||||
|
|
||||||
<android.support.v7.widget.SwitchCompat
|
<ExpandableListView
|
||||||
android:id="@+id/switchItem"
|
android:id="@+id/list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginStart="@dimen/content_padding"
|
android:divider="@null"
|
||||||
android:layout_marginEnd="@dimen/content_padding"
|
android:headerDividersEnabled="false"
|
||||||
android:minHeight="48dp"
|
android:dividerHeight="0dp"
|
||||||
android:text="@string/shared_string_include_data"
|
android:drawSelectorOnTop="false"
|
||||||
android:textSize="@dimen/default_list_text_size"
|
android:groupIndicator="@android:color/transparent"
|
||||||
tools:text="@string/shared_string_include_data" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<ExpandableListView
|
|
||||||
android:id="@+id/list"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:divider="@null"
|
|
||||||
android:dividerHeight="0dp"
|
|
||||||
android:drawSelectorOnTop="false"
|
|
||||||
android:groupIndicator="@android:color/transparent"
|
|
||||||
android:visibility="gone"
|
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
56
OsmAnd/res/layout/item_header_export_expand_list.xml
Normal file
56
OsmAnd/res/layout/item_header_export_expand_list.xml
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:animateLayoutChanges="true"
|
||||||
|
android:background="?attr/activity_background_basic"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/description"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/bg_color"
|
||||||
|
android:letterSpacing="@dimen/text_button_letter_spacing"
|
||||||
|
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||||
|
android:paddingLeft="@dimen/content_padding"
|
||||||
|
android:paddingTop="@dimen/content_padding"
|
||||||
|
android:paddingRight="@dimen/content_padding"
|
||||||
|
android:paddingBottom="@dimen/content_padding"
|
||||||
|
android:text="@string/export_profile_dialog_description"
|
||||||
|
android:textColor="?android:textColorPrimary"
|
||||||
|
android:textSize="@dimen/default_list_text_size"
|
||||||
|
app:typeface="@string/font_roboto_regular" />
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/topSwitchDivider"
|
||||||
|
layout="@layout/card_bottom_divider"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/bg_color">
|
||||||
|
|
||||||
|
<android.support.v7.widget.SwitchCompat
|
||||||
|
android:id="@+id/switchItem"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:focusable="false"
|
||||||
|
android:focusableInTouchMode="false"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/activity_background_basic"
|
||||||
|
android:minHeight="48dp"
|
||||||
|
android:text="@string/shared_string_include_data"
|
||||||
|
android:textSize="@dimen/default_list_text_size"
|
||||||
|
tools:text="@string/shared_string_include_data" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/bottomSwitchDivider"
|
||||||
|
layout="@layout/divider"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -55,6 +55,7 @@
|
||||||
<android.support.v7.widget.AppCompatCheckBox
|
<android.support.v7.widget.AppCompatCheckBox
|
||||||
android:id="@+id/check_box"
|
android:id="@+id/check_box"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
android:focusableInTouchMode="false"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="@dimen/content_padding"
|
android:layout_marginStart="@dimen/content_padding"
|
||||||
android:layout_marginEnd="@dimen/content_padding"
|
android:layout_marginEnd="@dimen/content_padding"
|
||||||
|
|
|
@ -66,6 +66,7 @@
|
||||||
|
|
||||||
<android.support.v7.widget.AppCompatCheckBox
|
<android.support.v7.widget.AppCompatCheckBox
|
||||||
android:id="@+id/check_box"
|
android:id="@+id/check_box"
|
||||||
|
android:focusableInTouchMode="false"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="@dimen/content_padding"
|
android:layout_margin="@dimen/content_padding"
|
||||||
|
|
|
@ -601,6 +601,11 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toJson() {
|
public String toJson() {
|
||||||
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||||
|
return gson.toJson(toModeBean());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationModeBean toModeBean(){
|
||||||
ApplicationModeBean mb = new ApplicationModeBean();
|
ApplicationModeBean mb = new ApplicationModeBean();
|
||||||
mb.stringKey = stringKey;
|
mb.stringKey = stringKey;
|
||||||
mb.userProfileName = getUserProfileName();
|
mb.userProfileName = getUserProfileName();
|
||||||
|
@ -612,8 +617,7 @@ public class ApplicationMode {
|
||||||
mb.locIcon = getLocationIcon();
|
mb.locIcon = getLocationIcon();
|
||||||
mb.navIcon = getNavigationIcon();
|
mb.navIcon = getNavigationIcon();
|
||||||
mb.order = getOrder();
|
mb.order = getOrder();
|
||||||
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
return mb;
|
||||||
return gson.toJson(mb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteCustomModes(List<ApplicationMode> modes, OsmandApplication app) {
|
public static void deleteCustomModes(List<ApplicationMode> modes, OsmandApplication app) {
|
||||||
|
@ -789,25 +793,25 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ApplicationModeBean {
|
public static class ApplicationModeBean {
|
||||||
@Expose
|
@Expose
|
||||||
String stringKey;
|
public String stringKey;
|
||||||
@Expose
|
@Expose
|
||||||
String userProfileName;
|
public String userProfileName;
|
||||||
@Expose
|
@Expose
|
||||||
String parent;
|
public String parent;
|
||||||
@Expose
|
@Expose
|
||||||
String iconName = "map_world_globe_dark";
|
public String iconName = "map_world_globe_dark";
|
||||||
@Expose
|
@Expose
|
||||||
ProfileIconColors iconColor = ProfileIconColors.DEFAULT;
|
public ProfileIconColors iconColor = ProfileIconColors.DEFAULT;
|
||||||
@Expose
|
@Expose
|
||||||
String routingProfile = null;
|
public String routingProfile = null;
|
||||||
@Expose
|
@Expose
|
||||||
RouteService routeService = RouteService.OSMAND;
|
public RouteService routeService = RouteService.OSMAND;
|
||||||
@Expose
|
@Expose
|
||||||
LocationIcon locIcon = null;
|
public LocationIcon locIcon = null;
|
||||||
@Expose
|
@Expose
|
||||||
NavigationIcon navIcon = null;
|
public NavigationIcon navIcon = null;
|
||||||
@Expose
|
@Expose
|
||||||
int order = -1;
|
int order = -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,10 +111,9 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
db = ctx.getSQLiteAPI().getOrCreateDatabase(
|
db = ctx.getSQLiteAPI().getOrCreateDatabase(
|
||||||
ctx.getAppPath(TILES_INDEX_DIR).getAbsolutePath() + "/" + name + SQLITE_EXT, true);
|
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 INDEX IND on tiles (x,y,z,s)");
|
||||||
db.execSQL("CREATE TABLE IF NOT EXIST info(tilenumbering,minzoom,maxzoom)");
|
db.execSQL("CREATE TABLE info(tilenumbering,minzoom,maxzoom)");
|
||||||
db.execSQL("CREATE TABLE IF NOT EXIST android_metadata (locale TEXT)");
|
|
||||||
db.execSQL("INSERT INTO info (tilenumbering,minzoom,maxzoom) VALUES ('simple','" + minZoom + "','" + maxZoom + "');");
|
db.execSQL("INSERT INTO info (tilenumbering,minzoom,maxzoom) VALUES ('simple','" + minZoom + "','" + maxZoom + "');");
|
||||||
|
|
||||||
addInfoColumn(URL, urlTemplate);
|
addInfoColumn(URL, urlTemplate);
|
||||||
|
|
|
@ -436,24 +436,39 @@ public class SettingsHelper {
|
||||||
private ApplicationModeBuilder builder;
|
private ApplicationModeBuilder builder;
|
||||||
private ApplicationModeBean modeBean;
|
private ApplicationModeBean modeBean;
|
||||||
private Set<String> appModeBeanPrefsIds;
|
private Set<String> appModeBeanPrefsIds;
|
||||||
|
private OsmandApplication app;
|
||||||
|
|
||||||
|
public ProfileSettingsItem(@NonNull OsmandApplication app, @NonNull ApplicationMode appMode) {
|
||||||
public ProfileSettingsItem(@NonNull OsmandSettings settings, @NonNull ApplicationMode appMode) {
|
super(SettingsItemType.PROFILE, app.getSettings());
|
||||||
super(SettingsItemType.PROFILE, settings);
|
|
||||||
this.appMode = appMode;
|
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 {
|
public ProfileSettingsItem(@NonNull OsmandApplication app, @NonNull ApplicationModeBean modeBean) {
|
||||||
super(SettingsItemType.PROFILE, settings, json);
|
super(SettingsItemType.PROFILE, app.getSettings());
|
||||||
readFromJson(settings.getContext(), json);
|
this.app = app;
|
||||||
appModeBeanPrefsIds = new HashSet<>(Arrays.asList(settings.appModeBeanPrefsIds));
|
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() {
|
public ApplicationMode getAppMode() {
|
||||||
return appMode;
|
return appMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ApplicationModeBean getModeBean() {
|
||||||
|
return modeBean;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -491,12 +506,6 @@ public class SettingsHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean exists() {
|
public boolean exists() {
|
||||||
List<ApplicationMode> profiles = ApplicationMode.allPossibleValues();
|
|
||||||
for (ApplicationMode profile : profiles) {
|
|
||||||
if (appMode.toHumanString().equals(profile.toHumanString())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder != null && ApplicationMode.valueOfStringKey(getName(), null) != null;
|
return builder != null && ApplicationMode.valueOfStringKey(getName(), null) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,9 +513,12 @@ public class SettingsHelper {
|
||||||
public void apply() {
|
public void apply() {
|
||||||
if (appMode.isCustomProfile()) {
|
if (appMode.isCustomProfile()) {
|
||||||
if (!shouldReplace) {
|
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());
|
appMode = ApplicationMode.saveProfile(builder, getSettings().getContext());
|
||||||
|
ApplicationMode.changeProfileAvailability(appMode, true, app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -716,6 +728,16 @@ public class SettingsHelper {
|
||||||
return file.exists();
|
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
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
SettingsItemReader getReader() {
|
SettingsItemReader getReader() {
|
||||||
|
@ -723,13 +745,14 @@ 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) {
|
if (shouldReplace || !file.exists()) {
|
||||||
output = new FileOutputStream(file);
|
output = new FileOutputStream(file);
|
||||||
} else {
|
} else {
|
||||||
String path = file.getAbsolutePath();
|
// String path = file.getAbsolutePath();
|
||||||
String copyName = path.replaceAll(file.getName(), COPY_PREFIX + file.getName());
|
// String copyName = path.replaceAll(file.getName(), COPY_PREFIX + file.getName());
|
||||||
File copyFile = new File(copyName);
|
// File copyFile = new File(copyName);
|
||||||
output = new FileOutputStream(copyFile);
|
// output = new FileOutputStream(copyFile);
|
||||||
|
output = new FileOutputStream(renameFile(file));
|
||||||
}
|
}
|
||||||
byte[] buffer = new byte[BUFFER];
|
byte[] buffer = new byte[BUFFER];
|
||||||
int count;
|
int count;
|
||||||
|
@ -955,7 +978,8 @@ public class SettingsHelper {
|
||||||
if (!poiUIFilters.isEmpty() || !duplicates.isEmpty()) {
|
if (!poiUIFilters.isEmpty() || !duplicates.isEmpty()) {
|
||||||
for (PoiUIFilter duplicate : duplicates) {
|
for (PoiUIFilter duplicate : duplicates) {
|
||||||
if (!shouldReplace) {
|
if (!shouldReplace) {
|
||||||
duplicate.setName(COPY_PREFIX + duplicate.getName());
|
renamePoiFilter(duplicate);
|
||||||
|
// duplicate.setName(COPY_PREFIX + duplicate.getName());
|
||||||
}
|
}
|
||||||
poiUIFilters.add(duplicate);
|
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<PoiUIFilter> userPoiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
|
||||||
|
for (PoiUIFilter filter : userPoiList) {
|
||||||
|
if (filter.getName().equals(poiUIFilter.getName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public List<PoiUIFilter> getDuplicates() {
|
public List<PoiUIFilter> getDuplicates() {
|
||||||
List<PoiUIFilter> duplicates = new ArrayList<>();
|
List<PoiUIFilter> duplicates = new ArrayList<>();
|
||||||
List<PoiUIFilter> userPoiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
|
List<PoiUIFilter> userPoiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
|
||||||
|
@ -1114,19 +1155,28 @@ public class SettingsHelper {
|
||||||
if (!mapSources.isEmpty() || !duplicates.isEmpty()) {
|
if (!mapSources.isEmpty() || !duplicates.isEmpty()) {
|
||||||
if (shouldReplace) {
|
if (shouldReplace) {
|
||||||
for (ITileSource tileSource : duplicates) {
|
for (ITileSource tileSource : duplicates) {
|
||||||
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName());
|
if (tileSource instanceof SQLiteTileSource) {
|
||||||
if (f != null && f.exists()) {
|
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName() + IndexConstants.SQLITE_EXT);
|
||||||
if (f.delete()) {
|
if (f != null && f.exists()) {
|
||||||
mapSources.add(tileSource);
|
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 {
|
} else {
|
||||||
for (ITileSource tileSource : duplicates) {
|
for (ITileSource tileSource : duplicates) {
|
||||||
tileSource.setName(COPY_PREFIX + tileSource.getName());
|
renameTileSource(tileSource);
|
||||||
|
mapSources.add(tileSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mapSources.addAll(duplicates);
|
|
||||||
for (ITileSource template : mapSources) {
|
for (ITileSource template : mapSources) {
|
||||||
if (template instanceof TileSourceManager.TileSourceTemplate) {
|
if (template instanceof TileSourceManager.TileSourceTemplate) {
|
||||||
getSettings().installTileSource((TileSourceManager.TileSourceTemplate) template);
|
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<String, String> tileSourceEntries = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true));
|
||||||
|
for (Map.Entry<String, String> entry : tileSourceEntries.entrySet()) {
|
||||||
|
if (entry.getValue().equals(tileSource.getName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ITileSource> getDuplicates() {
|
public List<ITileSource> getDuplicates() {
|
||||||
List<ITileSource> duplicates = new ArrayList<>();
|
List<ITileSource> duplicates = new ArrayList<>();
|
||||||
final LinkedHashMap<String, String> tileSourceEntries = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true));
|
final LinkedHashMap<String, String> tileSourceEntries = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true));
|
||||||
|
@ -1326,7 +1393,7 @@ public class SettingsHelper {
|
||||||
item = new GlobalSettingsItem(settings);
|
item = new GlobalSettingsItem(settings);
|
||||||
break;
|
break;
|
||||||
case PROFILE:
|
case PROFILE:
|
||||||
item = new ProfileSettingsItem(settings, json);
|
item = new ProfileSettingsItem(app, json);
|
||||||
break;
|
break;
|
||||||
case PLUGIN:
|
case PLUGIN:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import android.support.v7.view.ContextThemeWrapper;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
@ -487,4 +488,12 @@ public class UiUtilities {
|
||||||
public static Context getThemedContext(Context context, boolean nightMode, int lightStyle, int darkStyle) {
|
public static Context getThemedContext(Context context, boolean nightMode, int lightStyle, int darkStyle) {
|
||||||
return new ContextThemeWrapper(context, nightMode ? darkStyle : lightStyle);
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -192,7 +192,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
||||||
|
|
||||||
final View contentView = useScrollableItemsContainer() ? mainView.findViewById(R.id.scroll_view) : itemsContainer;
|
final View contentView = useScrollableItemsContainer() ? mainView.findViewById(R.id.scroll_view) : itemsContainer;
|
||||||
if (contentView.getHeight() > contentHeight) {
|
if (contentView.getHeight() > contentHeight) {
|
||||||
if (useScrollableItemsContainer()) {
|
if (useScrollableItemsContainer() || useExpandableList()) {
|
||||||
contentView.getLayoutParams().height = contentHeight;
|
contentView.getLayoutParams().height = contentHeight;
|
||||||
} else {
|
} else {
|
||||||
contentView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
contentView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||||
|
@ -231,6 +231,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean useExpandableList() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean hideButtonsContainer() {
|
protected boolean hideButtonsContainer() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,9 +399,8 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
|
||||||
} else if (EXPORT_PROFILE.equals(prefId)) {
|
} else if (EXPORT_PROFILE.equals(prefId)) {
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
if (fragmentManager != null) {
|
if (fragmentManager != null) {
|
||||||
ExportImportProfileBottomSheet.showInstance(
|
ExportProfileBottomSheet.showInstance(
|
||||||
fragmentManager,
|
fragmentManager,
|
||||||
ExportImportProfileBottomSheet.State.EXPORT,
|
|
||||||
this,
|
this,
|
||||||
getSelectedAppMode());
|
getSelectedAppMode());
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,14 +11,17 @@ import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
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;
|
||||||
|
import net.osmand.plus.SettingsHelper;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||||
import net.osmand.plus.poi.PoiUIFilter;
|
import net.osmand.plus.poi.PoiUIFilter;
|
||||||
import net.osmand.plus.profiles.AdditionalDataWrapper;
|
import net.osmand.plus.profiles.AdditionalDataWrapper;
|
||||||
|
import net.osmand.plus.profiles.ProfileIconColors;
|
||||||
import net.osmand.plus.quickaction.QuickAction;
|
import net.osmand.plus.quickaction.QuickAction;
|
||||||
import net.osmand.plus.render.RenderingIcons;
|
import net.osmand.plus.render.RenderingIcons;
|
||||||
|
|
||||||
|
@ -42,11 +45,19 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
||||||
this.importState = importState;
|
this.importState = importState;
|
||||||
this.dataToOperate = new ArrayList<>();
|
this.dataToOperate = new ArrayList<>();
|
||||||
this.profileColor = app.getSettings().getApplicationMode().getIconColorInfo().getColor(nightMode);
|
this.profileColor = app.getSettings().getApplicationMode().getIconColorInfo().getColor(nightMode);
|
||||||
if (!importState) {
|
// if (!importState) {
|
||||||
for (AdditionalDataWrapper dataWrapper : dataList) {
|
// for (AdditionalDataWrapper dataWrapper : dataList) {
|
||||||
dataToOperate.addAll(dataWrapper.getItems());
|
// 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
|
@Override
|
||||||
|
@ -136,9 +147,11 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PROFILE:
|
case PROFILE:
|
||||||
title.setText(((ApplicationMode) currentItem).toHumanString());
|
title.setText(((ApplicationMode.ApplicationModeBean) currentItem).userProfileName);
|
||||||
subText.setText(((ApplicationMode) currentItem).getDescription());
|
subText.setText(((ApplicationMode.ApplicationModeBean) currentItem).routingProfile);
|
||||||
icon.setImageDrawable(app.getUIUtilities().getIcon(((ApplicationMode) currentItem).getIconRes(), profileColor));
|
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);
|
subText.setVisibility(View.VISIBLE);
|
||||||
icon.setVisibility(View.VISIBLE);
|
icon.setVisibility(View.VISIBLE);
|
||||||
break;
|
break;
|
||||||
|
@ -247,6 +260,11 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearSettingsList() {
|
||||||
|
this.dataList.clear();
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
public void selectAll(boolean selectAll) {
|
public void selectAll(boolean selectAll) {
|
||||||
dataToOperate.clear();
|
dataToOperate.clear();
|
||||||
if (selectAll) {
|
if (selectAll) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import android.support.v7.widget.SwitchCompat;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ExpandableListView;
|
import android.widget.ExpandableListView;
|
||||||
|
import android.widget.LinearLayout.LayoutParams;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
@ -30,7 +31,6 @@ import net.osmand.plus.SettingsHelper;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
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.SimpleBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
import net.osmand.plus.poi.PoiUIFilter;
|
import net.osmand.plus.poi.PoiUIFilter;
|
||||||
|
@ -48,38 +48,17 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
public class ExportProfileBottomSheet 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";
|
|
||||||
|
|
||||||
|
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 static final String INCLUDE_ADDITIONAL_DATA_KEY = "INCLUDE_ADDITIONAL_DATA_KEY";
|
||||||
|
|
||||||
private boolean includeAdditionalData = false;
|
private boolean includeAdditionalData = false;
|
||||||
|
|
||||||
private boolean containsAdditionalData = false;
|
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
|
||||||
private ApplicationMode profile;
|
private ApplicationMode profile;
|
||||||
|
|
||||||
private State state;
|
|
||||||
|
|
||||||
private List<AdditionalDataWrapper> dataList = new ArrayList<>();
|
private List<AdditionalDataWrapper> dataList = new ArrayList<>();
|
||||||
|
|
||||||
private List<SettingsHelper.SettingsItem> settingsItems;
|
|
||||||
|
|
||||||
private ExpandableListView listView;
|
|
||||||
|
|
||||||
private ExportImportSettingsAdapter adapter;
|
private ExportImportSettingsAdapter adapter;
|
||||||
|
|
||||||
private SettingsHelper.ProfileSettingsItem profileSettingsItem;
|
|
||||||
|
|
||||||
private File file;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
|
@ -87,24 +66,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
}
|
}
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
app = requiredMyApplication();
|
app = requiredMyApplication();
|
||||||
Bundle bundle = getArguments();
|
dataList = getAdditionalData();
|
||||||
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());
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -121,7 +83,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
}
|
}
|
||||||
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
|
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
|
||||||
|
|
||||||
profile = state == State.IMPORT ? getAppModeFromSettingsItems() : getAppMode();
|
profile = getAppMode();
|
||||||
|
|
||||||
int profileColor = profile.getIconColorInfo().getColor(nightMode);
|
int profileColor = profile.getIconColorInfo().getColor(nightMode);
|
||||||
int colorNoAlpha = ContextCompat.getColor(context, profileColor);
|
int colorNoAlpha = ContextCompat.getColor(context, profileColor);
|
||||||
|
@ -129,9 +91,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
Drawable backgroundIcon = UiUtilities.getColoredSelectableDrawable(context, colorNoAlpha, 0.3f);
|
Drawable backgroundIcon = UiUtilities.getColoredSelectableDrawable(context, colorNoAlpha, 0.3f);
|
||||||
Drawable[] layers = {new ColorDrawable(UiUtilities.getColorWithAlpha(colorNoAlpha, 0.10f)), backgroundIcon};
|
Drawable[] layers = {new ColorDrawable(UiUtilities.getColorWithAlpha(colorNoAlpha, 0.10f)), backgroundIcon};
|
||||||
|
|
||||||
items.add(new TitleItem(state == State.EXPORT ?
|
items.add(new TitleItem(getString(R.string.export_profile)));
|
||||||
getString(R.string.export_profile)
|
|
||||||
: getString(R.string.import_profile)));
|
|
||||||
|
|
||||||
BaseBottomSheetItem profileItem = new BottomSheetItemWithCompoundButton.Builder()
|
BaseBottomSheetItem profileItem = new BottomSheetItemWithCompoundButton.Builder()
|
||||||
.setChecked(true)
|
.setChecked(true)
|
||||||
|
@ -145,40 +105,42 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
.create();
|
.create();
|
||||||
items.add(profileItem);
|
items.add(profileItem);
|
||||||
|
|
||||||
if (state == State.IMPORT && containsAdditionalData || state == State.EXPORT && !dataList.isEmpty()) {
|
if (!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);
|
|
||||||
|
|
||||||
final View additionalDataView = inflater.inflate(R.layout.bottom_sheet_item_additional_data, null);
|
final View additionalDataView = inflater.inflate(R.layout.bottom_sheet_item_additional_data, null);
|
||||||
listView = additionalDataView.findViewById(R.id.list);
|
ExpandableListView listView = additionalDataView.findViewById(R.id.list);
|
||||||
SwitchCompat switchItem = additionalDataView.findViewById(R.id.switchItem);
|
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.setTextColor(getResources().getColor(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
|
||||||
switchItem.setChecked(includeAdditionalData);
|
switchItem.setChecked(includeAdditionalData);
|
||||||
switchItem.setOnClickListener(new View.OnClickListener() {
|
switchItem.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
includeAdditionalData = !includeAdditionalData;
|
includeAdditionalData = !includeAdditionalData;
|
||||||
listView.setVisibility(includeAdditionalData ?
|
topSwitchDivider.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE);
|
||||||
View.VISIBLE : View.GONE);
|
bottomSwitchDivider.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE);
|
||||||
// if (includeAdditionalData && state == State.IMPORT) {
|
if (includeAdditionalData) {
|
||||||
// updateDataToOperateFromSettingsItems();
|
adapter.updateSettingsList(getAdditionalData());
|
||||||
// }
|
adapter.selectAll(true);
|
||||||
|
} else {
|
||||||
|
adapter.selectAll(false);
|
||||||
|
adapter.clearSettingsList();
|
||||||
|
}
|
||||||
|
updateSwitch(switchItem);
|
||||||
setupHeightAndBackground(getView());
|
setupHeightAndBackground(getView());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
listView.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE);
|
|
||||||
adapter = new ExportImportSettingsAdapter(app, dataList, nightMode, false);
|
|
||||||
listView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
|
listView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onGroupExpand(int i) {
|
public void onGroupExpand(int i) {
|
||||||
setupHeightAndBackground(getView());
|
setupHeightAndBackground(getView());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
updateSwitch(switchItem);
|
||||||
|
listView.addHeaderView(listHeader);
|
||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
||||||
.setCustomView(additionalDataView)
|
.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
|
@Override
|
||||||
protected int getRightBottomButtonTextId() {
|
protected int getRightBottomButtonTextId() {
|
||||||
return state == State.EXPORT ? R.string.shared_string_export : R.string.shared_string_import;
|
return R.string.shared_string_export;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRightBottomButtonClick() {
|
protected void onRightBottomButtonClick() {
|
||||||
super.onRightBottomButtonClick();
|
super.onRightBottomButtonClick();
|
||||||
if (state == State.EXPORT) {
|
prepareFile();
|
||||||
prepareFile();
|
|
||||||
} else {
|
|
||||||
importSettings();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -212,14 +180,9 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApplicationMode getAppModeFromSettingsItems() {
|
@Override
|
||||||
for (SettingsHelper.SettingsItem item : settingsItems) {
|
protected boolean useExpandableList() {
|
||||||
if (item.getType().equals(SettingsHelper.SettingsItemType.PROFILE)) {
|
return true;
|
||||||
profileSettingsItem = ((SettingsHelper.ProfileSettingsItem) item);
|
|
||||||
return ((SettingsHelper.ProfileSettingsItem) item).getAppMode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getAppMode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<AdditionalDataWrapper> getAdditionalData() {
|
private List<AdditionalDataWrapper> getAdditionalData() {
|
||||||
|
@ -287,7 +250,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
|
|
||||||
private List<SettingsHelper.SettingsItem> prepareSettingsItemsForExport() {
|
private List<SettingsHelper.SettingsItem> prepareSettingsItemsForExport() {
|
||||||
List<SettingsHelper.SettingsItem> settingsItems = new ArrayList<>();
|
List<SettingsHelper.SettingsItem> settingsItems = new ArrayList<>();
|
||||||
settingsItems.add(new SettingsHelper.ProfileSettingsItem(app.getSettings(), profile));
|
settingsItems.add(new SettingsHelper.ProfileSettingsItem(app, profile));
|
||||||
if (includeAdditionalData) {
|
if (includeAdditionalData) {
|
||||||
settingsItems.addAll(prepareAdditionalSettingsItems());
|
settingsItems.addAll(prepareAdditionalSettingsItems());
|
||||||
}
|
}
|
||||||
|
@ -323,39 +286,6 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
return settingsItems;
|
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<SettingsHelper.SettingsItem> 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<SettingsHelper.SettingsItem> 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() {
|
private void prepareFile() {
|
||||||
if (app != null) {
|
if (app != null) {
|
||||||
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
|
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
|
||||||
|
@ -393,14 +323,10 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean showInstance(@NonNull FragmentManager fragmentManager,
|
public static boolean showInstance(@NonNull FragmentManager fragmentManager,
|
||||||
State state,
|
|
||||||
Fragment target,
|
Fragment target,
|
||||||
@NonNull ApplicationMode appMode) {
|
@NonNull ApplicationMode appMode) {
|
||||||
try {
|
try {
|
||||||
Bundle bundle = new Bundle();
|
ExportProfileBottomSheet fragment = new ExportProfileBottomSheet();
|
||||||
bundle.putSerializable(STATE_KEY, state);
|
|
||||||
ExportImportProfileBottomSheet fragment = new ExportImportProfileBottomSheet();
|
|
||||||
fragment.setArguments(bundle);
|
|
||||||
fragment.setAppMode(appMode);
|
fragment.setAppMode(appMode);
|
||||||
fragment.setTargetFragment(target, 0);
|
fragment.setTargetFragment(target, 0);
|
||||||
fragment.show(fragmentManager, TAG);
|
fragment.show(fragmentManager, TAG);
|
||||||
|
@ -409,39 +335,4 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean showInstance(@NonNull FragmentManager fragmentManager,
|
|
||||||
State state,
|
|
||||||
File file,
|
|
||||||
List<SettingsHelper.SettingsItem> 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<SettingsHelper.SettingsItem> settingsItems) {
|
|
||||||
this.settingsItems = settingsItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getFile() {
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFile(File file) {
|
|
||||||
this.file = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum State {
|
|
||||||
EXPORT,
|
|
||||||
IMPORT
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -169,6 +169,10 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// if (getFragmentManager() != null) {
|
||||||
|
// ImportSettingsFragment fragment = (ImportSettingsFragment) getFragmentManager().findFragmentByTag(ImportSettingsFragment.TAG);
|
||||||
|
// fragment.dismiss();
|
||||||
|
// }
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue