Merge pull request #8242 from osmandapp/ImportProfile

Import Profile
This commit is contained in:
max-klaus 2020-01-17 13:58:23 +03:00 committed by GitHub
commit 8063a97a43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 596 additions and 156 deletions

View file

@ -41,6 +41,8 @@ public class IndexConstants {
public static final String FONT_INDEX_EXT_ZIP = ".otf.zip"; //$NON-NLS-1$ public static final String FONT_INDEX_EXT_ZIP = ".otf.zip"; //$NON-NLS-1$
public static final String OSMAND_SETTINGS_FILE_EXT = ".osf"; public static final String OSMAND_SETTINGS_FILE_EXT = ".osf";
public static final String ROUTING_FILE_EXT = ".xml";
public static final String RENDERER_INDEX_EXT = ".render.xml"; //$NON-NLS-1$ public static final String RENDERER_INDEX_EXT = ".render.xml"; //$NON-NLS-1$

View file

@ -133,6 +133,17 @@ public class RoutingConfiguration {
} }
public String getRoutingProfileKeyByFileName(String fileName) {
if (fileName != null && routers != null) {
for (Map.Entry<String, GeneralRouter> router : routers.entrySet()) {
if (fileName.equals(router.getValue().getFilename())) {
return router.getKey();
}
}
}
return null;
}
public Map<String, GeneralRouter> getAllRouters() { public Map<String, GeneralRouter> getAllRouters() {
return routers; return routers;
} }

View file

@ -323,6 +323,39 @@
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.osf" /> <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.osf" />
</intent-filter> </intent-filter>
<intent-filter
android:label="@string/app_name"
android:priority="50">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.xml" />
<data android:pathPattern=".*\\..*\\.xml" />
<data android:pathPattern=".*\\..*\\..*\\.xml" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.xml" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.xml" />
</intent-filter>
<intent-filter
android:label="@string/app_name"
android:priority="50">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content"/>
<data android:scheme="file"/>
<data android:scheme="data"/>
<data android:host="*"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.xml" />
<data android:pathPattern=".*\\..*\\.xml" />
<data android:pathPattern=".*\\..*\\..*\\.xml" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.xml" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.xml" />
</intent-filter>
<!--trying to handle emails--> <!--trying to handle emails-->
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />

View file

@ -11,6 +11,11 @@
Thx - Hardy Thx - Hardy
--> -->
<string name="file_does_not_contain_routing_rules">\'%1$s\' file doesn\'t contain routing rules, please choose another file.</string>
<string name="not_support_file_type_with_ext">Not supported file type. You need to select a file with %1$s extension.</string>
<string name="import_from_file">Import from file</string>
<string name="import_routing_file">Import routing file</string>
<string name="import_profile">Import profile</string>
<string name="monitoring_prefs_descr">Navigation, logging accuracy</string> <string name="monitoring_prefs_descr">Navigation, logging accuracy</string>
<string name="multimedia_notes_prefs_descr">Picture size, audio and video quality</string> <string name="multimedia_notes_prefs_descr">Picture size, audio and video quality</string>
<string name="osm_editing_prefs_descr">Login, password, offline editing</string> <string name="osm_editing_prefs_descr">Login, password, offline editing</string>

View file

@ -46,12 +46,12 @@
android:title="@string/new_profile" android:title="@string/new_profile"
tools:icon="@drawable/ic_action_plus" /> tools:icon="@drawable/ic_action_plus" />
<!--Preference <Preference
android:key="import_profile" android:key="import_profile"
android:layout="@layout/preference_button" android:layout="@layout/preference_button"
android:persistent="false" android:persistent="false"
android:title="@string/profile_import" android:title="@string/import_profile"
tools:icon="@drawable/ic_action_import" /--> tools:icon="@drawable/ic_action_import" />
<Preference <Preference
android:key="reorder_profiles" android:key="reorder_profiles"

View file

@ -689,4 +689,36 @@ public class AndroidUtils {
public static boolean isRTL() { public static boolean isRTL() {
return TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL; return TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL;
} }
public static String createNewFileName(String oldName) {
int firstDotIndex = oldName.indexOf('.');
String nameWithoutExt = oldName.substring(0, firstDotIndex);
String ext = oldName.substring(firstDotIndex);
StringBuilder numberSection = new StringBuilder();
int i = nameWithoutExt.length() - 1;
boolean hasNameNumberSection = false;
do {
char c = nameWithoutExt.charAt(i);
if (Character.isDigit(c)) {
numberSection.insert(0, c);
} else if(Character.isSpaceChar(c) && numberSection.length() > 0) {
hasNameNumberSection = true;
break;
} else {
break;
}
i--;
} while (i >= 0);
int newNumberValue = Integer.parseInt(hasNameNumberSection ? numberSection.toString() : "0") + 1;
String newName;
if (newNumberValue == 1) {
newName = nameWithoutExt + " " + newNumberValue + ext;
} else {
newName = nameWithoutExt.substring(0, i) + " " + newNumberValue + ext;
}
return newName;
}
} }

View file

@ -58,7 +58,6 @@ import net.osmand.plus.voice.TTSCommandPlayerImpl;
import net.osmand.plus.wikivoyage.data.TravelDbHelper; import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
import net.osmand.router.RoutingConfiguration; import net.osmand.router.RoutingConfiguration;
import net.osmand.router.RoutingConfiguration.Builder;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.OpeningHoursParser; import net.osmand.util.OpeningHoursParser;
@ -141,6 +140,10 @@ public class AppInitializer implements IProgress {
void onFinish(AppInitializer init); void onFinish(AppInitializer init);
} }
public interface LoadRoutingFilesCallback {
void onRoutingFilesLoaded();
}
public AppInitializer(OsmandApplication app) { public AppInitializer(OsmandApplication app) {
@ -579,9 +582,19 @@ public class AppInitializer implements IProgress {
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
private void getLazyRoutingConfig() { private void getLazyRoutingConfig() {
new AsyncTask<Void, Void, RoutingConfiguration.Builder>() { loadRoutingFiles(app, new LoadRoutingFilesCallback() {
@Override @Override
protected Builder doInBackground(Void... voids) { public void onRoutingFilesLoaded() {
notifyEvent(InitEvents.ROUTING_CONFIG_INITIALIZED);
}
});
}
public static void loadRoutingFiles(final OsmandApplication app, final LoadRoutingFilesCallback callback) {
new AsyncTask<Void, Void, RoutingConfiguration.Builder>() {
@Override
protected RoutingConfiguration.Builder doInBackground(Void... voids) {
File routingFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR); File routingFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
RoutingConfiguration.Builder builder = RoutingConfiguration.getDefault(); RoutingConfiguration.Builder builder = RoutingConfiguration.getDefault();
if (routingFolder.isDirectory()) { if (routingFolder.isDirectory()) {
@ -602,10 +615,10 @@ public class AppInitializer implements IProgress {
} }
@Override @Override
protected void onPostExecute(Builder builder) { protected void onPostExecute(RoutingConfiguration.Builder builder) {
super.onPostExecute(builder); super.onPostExecute(builder);
app.updateRoutingConfig(builder); app.updateRoutingConfig(builder);
notifyEvent(InitEvents.ROUTING_CONFIG_INITIALIZED); callback.onRoutingFilesLoaded();
} }
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }

View file

@ -83,7 +83,7 @@ public class SettingsHelper {
private ImportAsyncTask importTask; private ImportAsyncTask importTask;
public interface SettingsImportListener { public interface SettingsImportListener {
void onSettingsImportFinished(boolean succeed, boolean empty); void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items);
} }
public interface SettingsExportListener { public interface SettingsExportListener {
@ -913,7 +913,7 @@ public class SettingsHelper {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
if (importing) { if (importing) {
finishImport(listener, false, false); finishImport(listener, false, false, items);
} }
importing = true; importing = true;
importSuspended = false; importSuspended = false;
@ -948,7 +948,7 @@ public class SettingsHelper {
if (processedItems.size() > 0) { if (processedItems.size() > 0) {
new ImportItemsAsyncTask(file, listener, processedItems).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new ImportItemsAsyncTask(file, listener, processedItems).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else { } else {
finishImport(listener, false, true); finishImport(listener, false, true, items);
} }
return; return;
} }
@ -1063,16 +1063,16 @@ public class SettingsHelper {
@Override @Override
protected void onPostExecute(Boolean success) { protected void onPostExecute(Boolean success) {
finishImport(listener, success, false); finishImport(listener, success, false, items);
} }
} }
private void finishImport(@Nullable SettingsImportListener listener, boolean success, boolean empty) { private void finishImport(@Nullable SettingsImportListener listener, boolean success, boolean empty, List<SettingsItem> items) {
importing = false; importing = false;
importSuspended = false; importSuspended = false;
importTask = null; importTask = null;
if (listener != null) { if (listener != null) {
listener.onSettingsImportFinished(success, empty); listener.onSettingsImportFinished(success, empty, items);
} }
} }

View file

@ -22,6 +22,7 @@ import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
@ -39,6 +40,7 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.SettingsHelper; import net.osmand.plus.SettingsHelper;
import net.osmand.plus.SettingsHelper.SettingsImportListener; import net.osmand.plus.SettingsHelper.SettingsImportListener;
import net.osmand.plus.activities.ActivityResultListener;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
@ -49,9 +51,11 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.router.RoutingConfiguration;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParserException;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
@ -69,6 +73,10 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import static android.app.Activity.RESULT_OK;
import static net.osmand.IndexConstants.OSMAND_SETTINGS_FILE_EXT;
import static net.osmand.IndexConstants.ROUTING_FILE_EXT;
import static net.osmand.plus.AppInitializer.loadRoutingFiles;
import static net.osmand.plus.myplaces.FavoritesActivity.FAV_TAB; import static net.osmand.plus.myplaces.FavoritesActivity.FAV_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB; import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
@ -86,6 +94,23 @@ public class ImportHelper {
private final OsmandMapTileView mapView; private final OsmandMapTileView mapView;
private OnGpxImportCompleteListener gpxImportCompleteListener; private OnGpxImportCompleteListener gpxImportCompleteListener;
public final static int IMPORT_FILE_REQUEST = 1006;
public enum ImportType {
SETTINGS(IndexConstants.OSMAND_SETTINGS_FILE_EXT),
ROUTING(ROUTING_FILE_EXT);
ImportType(String extension) {
this.extension = extension;
}
private String extension;
public String getExtension() {
return extension;
}
}
public interface OnGpxImportCompleteListener { public interface OnGpxImportCompleteListener {
void onComplete(boolean success); void onComplete(boolean success);
} }
@ -156,14 +181,10 @@ public class ImportHelper {
handleObfImport(intentUri, fileName); handleObfImport(intentUri, fileName);
} else if (fileName != null && fileName.endsWith(IndexConstants.SQLITE_EXT)) { } else if (fileName != null && fileName.endsWith(IndexConstants.SQLITE_EXT)) {
handleSqliteTileImport(intentUri, fileName); handleSqliteTileImport(intentUri, fileName);
} else if (fileName != null && fileName.endsWith(IndexConstants.OSMAND_SETTINGS_FILE_EXT)) { } else if (fileName != null && fileName.endsWith(OSMAND_SETTINGS_FILE_EXT)) {
if (extras != null && extras.containsKey(SettingsHelper.SETTINGS_VERSION_KEY) && extras.containsKey(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY)) { handleOsmAndSettingsImport(intentUri, fileName, extras, null);
int version = extras.getInt(SettingsHelper.SETTINGS_VERSION_KEY, -1); } else if (fileName != null && fileName.endsWith(ROUTING_FILE_EXT)) {
String latestChanges = extras.getString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY); handleRoutingFileImport(intentUri, fileName, null);
handleOsmAndSettingsImport(intentUri, fileName, latestChanges, version);
} else {
handleOsmAndSettingsImport(intentUri, fileName, null, -1);
}
} else { } else {
handleFavouritesImport(intentUri, fileName, saveFile, useImportDir, false); handleFavouritesImport(intentUri, fileName, saveFile, useImportDir, false);
} }
@ -585,8 +606,147 @@ public class ImportHelper {
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
public void chooseFileToImport(final ImportType importType, final CallbackWithObject callback) {
final MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return;
}
final OsmandApplication app = mapActivity.getMyApplication();
Intent intent = new Intent();
String action;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
action = Intent.ACTION_OPEN_DOCUMENT;
} else {
action = Intent.ACTION_GET_CONTENT;
}
intent.setAction(action);
intent.setType("*/*");
ActivityResultListener listener = new ActivityResultListener(IMPORT_FILE_REQUEST, new ActivityResultListener.OnActivityResultListener() {
@Override
public void onResult(int resultCode, Intent resultData) {
MapActivity mapActivity = getMapActivity();
if (resultCode == RESULT_OK) {
Uri data = resultData.getData();
if (mapActivity == null || data == null) {
return;
}
String scheme = data.getScheme();
String fileName = "";
if ("file".equals(scheme)) {
final String path = data.getPath();
if (path != null) {
fileName = new File(path).getName();
}
} else if ("content".equals(scheme)) {
fileName = getNameFromContentUri(app, data);
}
if (fileName.endsWith(importType.getExtension())) {
if (importType.equals(ImportType.SETTINGS)) {
handleOsmAndSettingsImport(data, fileName, resultData.getExtras(), callback);
} else if (importType.equals(ImportType.ROUTING)){
handleRoutingFileImport(data, fileName, callback);
}
} else {
app.showToastMessage(app.getString(R.string.not_support_file_type_with_ext,
importType.getExtension().replaceAll("\\.", "").toUpperCase()));
}
}
}
});
mapActivity.registerActivityResultListener(listener);
mapActivity.startActivityForResult(intent, IMPORT_FILE_REQUEST);
}
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
private void handleOsmAndSettingsImport(final Uri uri, final String name, final String latestChanges, final int version) { private void handleRoutingFileImport(final Uri uri, final String fileName, final CallbackWithObject<String> callback) {
final AsyncTask<Void, Void, String> routingImportTask = new AsyncTask<Void, Void, String>() {
String mFileName;
ProgressDialog progress;
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data));
mFileName = fileName;
}
@Override
protected String doInBackground(Void... voids) {
File routingDir = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
if (!routingDir.exists()) {
routingDir.mkdirs();
}
File dest = new File(routingDir, mFileName);
while (dest.exists()) {
mFileName = AndroidUtils.createNewFileName(mFileName);
dest = new File(routingDir, mFileName);
}
return copyFile(app, dest, uri, true);
}
@Override
protected void onPostExecute(String error) {
File routingDir = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
final File file = new File(routingDir, mFileName);
if (error == null && file.exists()) {
loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
@Override
public void onRoutingFilesLoaded() {
if (isActivityNotDestroyed(activity)) {
progress.dismiss();
}
String profileKey = app.getRoutingConfig().getRoutingProfileKeyByFileName(mFileName);
if (profileKey != null) {
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, mFileName));
if (callback != null) {
callback.processResult(profileKey);
}
} else {
app.showToastMessage(app.getString(R.string.file_does_not_contain_routing_rules, mFileName));
}
}
});
} else {
if (isActivityNotDestroyed(activity)) {
progress.dismiss();
}
app.showShortToastMessage(app.getString(R.string.file_import_error, mFileName, error));
}
}
};
if (app.isApplicationInitializing()) {
app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
@Override
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
}
@Override
public void onFinish(AppInitializer init) {
routingImportTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
} else {
routingImportTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
private void handleOsmAndSettingsImport(Uri intentUri, String fileName, Bundle extras,
CallbackWithObject<List<SettingsHelper.SettingsItem>> callback) {
if (extras != null && extras.containsKey(SettingsHelper.SETTINGS_VERSION_KEY) && extras.containsKey(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY)) {
int version = extras.getInt(SettingsHelper.SETTINGS_VERSION_KEY, -1);
String latestChanges = extras.getString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY);
handleOsmAndSettingsImport(intentUri, fileName, latestChanges, version, callback);
} else {
handleOsmAndSettingsImport(intentUri, fileName, null, -1, callback);
}
}
@SuppressLint("StaticFieldLeak")
private void handleOsmAndSettingsImport(final Uri uri, final String name, final String latestChanges, final int version,
final CallbackWithObject<List<SettingsHelper.SettingsItem>> callback) {
final AsyncTask<Void, Void, String> settingsImportTask = new AsyncTask<Void, Void, String>() { final AsyncTask<Void, Void, String> settingsImportTask = new AsyncTask<Void, Void, String>() {
ProgressDialog progress; ProgressDialog progress;
@ -613,12 +773,15 @@ public class ImportHelper {
if (error == null && file.exists()) { if (error == null && file.exists()) {
app.getSettingsHelper().importSettings(file, latestChanges, version, new SettingsImportListener() { app.getSettingsHelper().importSettings(file, latestChanges, version, new SettingsImportListener() {
@Override @Override
public void onSettingsImportFinished(boolean succeed, boolean empty) { public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
if (isActivityNotDestroyed(activity)) { if (isActivityNotDestroyed(activity)) {
progress.dismiss(); progress.dismiss();
} }
if (succeed) { if (succeed) {
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, name)); app.showShortToastMessage(app.getString(R.string.file_imported_successfully, name));
if (callback != null) {
callback.processResult(items);
}
} else if (!empty) { } 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

@ -68,9 +68,9 @@ import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.PROFILE_KEY_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_ICON;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE;
import static net.osmand.plus.profiles.SettingsProfileFragment.IS_NEW_PROFILE; import static net.osmand.plus.profiles.SettingsProfileFragment.IS_NEW_PROFILE;
import static net.osmand.plus.profiles.SettingsProfileFragment.IS_USER_PROFILE; import static net.osmand.plus.profiles.SettingsProfileFragment.IS_USER_PROFILE;
@ -312,7 +312,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
public void onClick(View v) { public void onClick(View v) {
final SelectProfileBottomSheetDialogFragment iconSelectDialog = new SelectProfileBottomSheetDialogFragment(); final SelectProfileBottomSheetDialogFragment iconSelectDialog = new SelectProfileBottomSheetDialogFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(DIALOG_TYPE, TYPE_ICON); // bundle.putString(DIALOG_TYPE, TYPE_ICON);
bundle.putString(SELECTED_ICON, profile.iconStringName); bundle.putString(SELECTED_ICON, profile.iconStringName);
iconSelectDialog.setArguments(bundle); iconSelectDialog.setArguments(bundle);
hideKeyboard(); hideKeyboard();
@ -470,10 +470,11 @@ public class EditProfileFragment extends BaseOsmAndFragment {
if (iconIdListener == null) { if (iconIdListener == null) {
iconIdListener = new SelectProfileListener() { iconIdListener = new SelectProfileListener() {
@Override @Override
public void onSelectedType(int pos, String stringRes) { public void onSelectedType(Bundle bundle) {
int pos = -1;
dataChanged = true; dataChanged = true;
profile.iconId = pos; profile.iconId = pos;
profile.iconStringName = stringRes; profile.iconStringName = null;
profileIcon.setImageDrawable(app.getUIUtilities().getIcon(pos, profileIcon.setImageDrawable(app.getUIUtilities().getIcon(pos,
profile.iconColor.getColor(nightMode))); profile.iconColor.getColor(nightMode)));
@ -487,11 +488,10 @@ public class EditProfileFragment extends BaseOsmAndFragment {
if (baseTypeListener == null) { if (baseTypeListener == null) {
baseTypeListener = new SelectProfileListener() { baseTypeListener = new SelectProfileListener() {
@Override @Override
public void onSelectedType(int pos, String stringRes) { public void onSelectedType(Bundle args) {
String key = SettingsProfileFragment.getBaseProfiles(getMyApplication()) String profileKey = args.getString(PROFILE_KEY_ARG);
.get(pos).getStringKey(); setupBaseProfileView(profileKey);
setupBaseProfileView(key); profile.parent = ApplicationMode.valueOfStringKey(profileKey, ApplicationMode.DEFAULT);
profile.parent = ApplicationMode.valueOfStringKey(key, ApplicationMode.DEFAULT);
dataChanged = true; dataChanged = true;
} }
}; };
@ -503,7 +503,8 @@ public class EditProfileFragment extends BaseOsmAndFragment {
if (navTypeListener == null) { if (navTypeListener == null) {
navTypeListener = new SelectProfileListener() { navTypeListener = new SelectProfileListener() {
@Override @Override
public void onSelectedType(int pos, String stringRes) { public void onSelectedType(Bundle args) {
int pos = -1;
updateRoutingProfile(pos); updateRoutingProfile(pos);
} }
}; };
@ -775,7 +776,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
} }
} }
public static List<RoutingProfileDataObject> getRoutingProfiles(OsmandApplication context) { private static List<RoutingProfileDataObject> getRoutingProfiles(OsmandApplication context) {
List<RoutingProfileDataObject> profilesObjects = new ArrayList<>(); List<RoutingProfileDataObject> profilesObjects = new ArrayList<>();
profilesObjects.add(new RoutingProfileDataObject( profilesObjects.add(new RoutingProfileDataObject(
RoutingProfilesResources.STRAIGHT_LINE_MODE.name(), RoutingProfilesResources.STRAIGHT_LINE_MODE.name(),
@ -812,7 +813,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
return profilesObjects; return profilesObjects;
} }
public enum RoutingProfilesResources { private enum RoutingProfilesResources {
STRAIGHT_LINE_MODE(R.string.routing_profile_straightline, R.drawable.ic_action_split_interval), STRAIGHT_LINE_MODE(R.string.routing_profile_straightline, R.drawable.ic_action_split_interval),
BROUTER_MODE(R.string.routing_profile_broutrer, R.drawable.ic_action_split_interval), BROUTER_MODE(R.string.routing_profile_broutrer, R.drawable.ic_action_split_interval),
CAR(R.string.rendering_value_car_name, R.drawable.ic_action_car_dark), CAR(R.string.rendering_value_car_name, R.drawable.ic_action_car_dark),

View file

@ -1,7 +1,9 @@
package net.osmand.plus.profiles; package net.osmand.plus.profiles;
import android.os.Parcel; import net.osmand.plus.R;
import net.osmand.plus.ApplicationMode.ProfileIconColors;
import java.util.ArrayList;
import java.util.List;
public class RoutingProfileDataObject extends ProfileDataObject { public class RoutingProfileDataObject extends ProfileDataObject {
@ -17,4 +19,43 @@ public class RoutingProfileDataObject extends ProfileDataObject {
return fileName; return fileName;
} }
public enum RoutingProfilesResources {
STRAIGHT_LINE_MODE(R.string.routing_profile_straightline, R.drawable.ic_action_split_interval),
BROUTER_MODE(R.string.routing_profile_broutrer, R.drawable.ic_action_split_interval),
CAR(R.string.rendering_value_car_name, R.drawable.ic_action_car_dark),
PEDESTRIAN(R.string.rendering_value_pedestrian_name, R.drawable.ic_action_pedestrian_dark),
BICYCLE(R.string.rendering_value_bicycle_name, R.drawable.ic_action_bicycle_dark),
SKI(R.string.routing_profile_ski, R.drawable.ic_action_skiing),
PUBLIC_TRANSPORT(R.string.app_mode_public_transport, R.drawable.ic_action_bus_dark),
BOAT(R.string.app_mode_boat, R.drawable.ic_action_sail_boat_dark),
GEOCODING(R.string.routing_profile_geocoding, R.drawable.ic_action_world_globe);
int stringRes;
int iconRes;
RoutingProfilesResources(int stringRes, int iconRes) {
this.stringRes = stringRes;
this.iconRes = iconRes;
}
public int getStringRes() {
return stringRes;
}
public int getIconRes() {
return iconRes;
}
private static final List<String> rpValues = new ArrayList<>();
static {
for (RoutingProfilesResources rpr : RoutingProfilesResources.values()) {
rpValues.add(rpr.name());
}
}
public static boolean isRpValue(String value) {
return rpValues.contains(value);
}
}
} }

View file

@ -1,5 +1,6 @@
package net.osmand.plus.profiles; package net.osmand.plus.profiles;
import android.app.Activity;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
@ -9,13 +10,20 @@ import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
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.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
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.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.MainSettingsFragment; import net.osmand.plus.settings.MainSettingsFragment;
@ -27,7 +35,8 @@ import org.apache.commons.logging.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static net.osmand.plus.profiles.EditProfileFragment.SELECTED_ICON; import static net.osmand.plus.helpers.ImportHelper.ImportType.ROUTING;
import static net.osmand.plus.helpers.ImportHelper.ImportType.SETTINGS;
public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -38,18 +47,18 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
public final static String DIALOG_TYPE = "dialog_type"; public final static String DIALOG_TYPE = "dialog_type";
public final static String TYPE_BASE_APP_PROFILE = "base_profiles"; public final static String TYPE_BASE_APP_PROFILE = "base_profiles";
public final static String TYPE_NAV_PROFILE = "routing_profiles"; public final static String TYPE_NAV_PROFILE = "routing_profiles";
public final static String TYPE_ICON = "icon_type";
public final static String SELECTED_KEY = "selected_base"; public final static String SELECTED_KEY = "selected_base";
public final static String PROFILE_KEY_ARG = "profile_key_arg";
public final static String IS_PROFILE_IMPORTED_ARG = "is_profile_imported_arg";
String type; String type;
int bottomButtonText = R.string.shared_string_cancel;
private SelectProfileListener listener; private SelectProfileListener listener;
private final List<ProfileDataObject> profiles = new ArrayList<>(); private final List<ProfileDataObject> profiles = new ArrayList<>();
private String selectedItemKey; private String selectedItemKey;
private String selectedIconRes;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -60,11 +69,9 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
type = args.getString(DIALOG_TYPE); type = args.getString(DIALOG_TYPE);
selectedItemKey = args.getString(SELECTED_KEY, null); selectedItemKey = args.getString(SELECTED_KEY, null);
if (type.equals(TYPE_NAV_PROFILE)) { if (type.equals(TYPE_NAV_PROFILE)) {
profiles.addAll(EditProfileFragment.getRoutingProfiles(app)); profiles.addAll(NavigationFragment.getRoutingProfiles(app).values());
} else if (type.equals(TYPE_BASE_APP_PROFILE)) { } else if (type.equals(TYPE_BASE_APP_PROFILE)) {
profiles.addAll(SettingsProfileFragment.getBaseProfiles(app)); profiles.addAll(SettingsProfileFragment.getBaseProfiles(app));
} else if (type.equals(TYPE_ICON)) {
selectedIconRes = args.getString(SELECTED_ICON, "");
} else { } else {
LOG.error("Check intent data!"); LOG.error("Check intent data!");
dismiss(); dismiss();
@ -84,8 +91,11 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
}); });
if (type.equals(TYPE_NAV_PROFILE) || type.equals(TYPE_BASE_APP_PROFILE)) { if (type.equals(TYPE_NAV_PROFILE) || type.equals(TYPE_BASE_APP_PROFILE)) {
if (items.get(items.size()-1).getView() != null) { for (BaseBottomSheetItem item : items) {
items.get(items.size()-1).getView().findViewById(R.id.divider_bottom).setVisibility(View.INVISIBLE); View bottomDivider = item.getView().findViewById(R.id.divider_bottom);
if (bottomDivider != null) {
bottomDivider.setVisibility(View.INVISIBLE);
}
} }
} }
} }
@ -93,6 +103,13 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
int iconDefaultColorResId = nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light;
OsmandApplication app = getMyApplication();
View bottomSpaceView = new View(app);
int space = (int) getResources().getDimension(R.dimen.empty_state_text_button_padding_top);
bottomSpaceView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, space));
if (type.equals(TYPE_BASE_APP_PROFILE)) { if (type.equals(TYPE_BASE_APP_PROFILE)) {
items.add(new TitleItem(getString(R.string.select_base_profile_dialog_title))); items.add(new TitleItem(getString(R.string.select_base_profile_dialog_title)));
items.add(new LongDescriptionItem(getString(R.string.select_base_profile_dialog_message))); items.add(new LongDescriptionItem(getString(R.string.select_base_profile_dialog_message)));
@ -125,18 +142,56 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
if (listener == null) { if (listener == null) {
getListener(); getListener();
} }
listener.onSelectedType(pos, ""); Bundle args = new Bundle();
args.putString(PROFILE_KEY_ARG, profile.getStringKey());
listener.onSelectedType(args);
dismiss(); dismiss();
} }
}) })
.create()); .create());
} }
items.add(new DividerItem(app));
items.add(new SimpleBottomSheetItem.Builder()
.setTitle(app.getString(R.string.import_from_file))
.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_folder, iconDefaultColorResId))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return;
}
mapActivity.getImportHelper().chooseFileToImport(SETTINGS, new CallbackWithObject<List<SettingsItem>>() {
@Override
public boolean processResult(List<SettingsItem> result) {
for (SettingsItem item : result) {
if (SettingsItemType.PROFILE.equals(item.getType())) {
if (listener == null) {
getListener();
}
Bundle args = new Bundle();
args.putString(PROFILE_KEY_ARG, item.getName());
args.putBoolean(IS_PROFILE_IMPORTED_ARG, true);
listener.onSelectedType(args);
dismiss();
break;
}
}
return false;
}
});
}
})
.create());
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(bottomSpaceView)
.create());
} else if (type.equals(TYPE_NAV_PROFILE)){ } else if (type.equals(TYPE_NAV_PROFILE)){
items.add(new TitleItem(getString(R.string.select_nav_profile_dialog_title))); items.add(new TitleItem(getString(R.string.select_nav_profile_dialog_title)));
items.add(new LongDescriptionItem(getString(R.string.select_nav_profile_dialog_message))); items.add(new LongDescriptionItem(getString(R.string.select_nav_profile_dialog_message)));
for (int i = 0; i < profiles.size(); i++) { for (int i = 0; i < profiles.size(); i++) {
final int pos = i;
final ProfileDataObject profile = profiles.get(i); final ProfileDataObject profile = profiles.get(i);
final boolean isSelected = profile.getStringKey().equals(selectedItemKey); final boolean isSelected = profile.getStringKey().equals(selectedItemKey);
final Drawable drawableIcon; final Drawable drawableIcon;
@ -164,50 +219,47 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
if (listener == null) { if (listener == null) {
getListener(); getListener();
} }
listener.onSelectedType(pos, ""); Bundle args = new Bundle();
args.putString(PROFILE_KEY_ARG, profile.getStringKey());
listener.onSelectedType(args);
dismiss(); dismiss();
} }
}) })
.create()); .create());
} }
} else if (type.equals(TYPE_ICON)) { items.add(new DividerItem(app));
items.add(new TitleItem(getString(R.string.select_icon_profile_dialog_title))); items.add(new LongDescriptionItem(app.getString(R.string.osmand_routing_promo)));
for (final ApplicationMode.ProfileIcons icon : ApplicationMode.ProfileIcons.values()) { items.add(new SimpleBottomSheetItem.Builder()
Drawable drawableIcon; .setTitle(app.getString(R.string.import_routing_file))
boolean isSelected = icon.getResStringId().equals(selectedIconRes); .setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_folder, iconDefaultColorResId))
int iconRes = icon.getResId(); .setLayoutId(R.layout.bottom_sheet_item_simple)
if (isSelected) {
drawableIcon = getMyApplication().getUIUtilities()
.getIcon(iconRes, nightMode
? R.color.active_color_primary_dark
: R.color.active_color_primary_light);
} else {
drawableIcon = getMyApplication().getUIUtilities()
.getIcon(iconRes, R.color.icon_color_default_light);
}
items.add(new BottomSheetItemWithCompoundButton.Builder()
.setCompoundButtonColorId(activeColorRes)
.setChecked(icon.getResStringId().equals(selectedIconRes))
.setButtonTintList(isSelected
? ColorStateList.valueOf(getResolvedColor(getActiveColorId()))
: null)
.setTitle(getMyApplication().getString(icon.getTitleId()))
.setIcon(drawableIcon)
.setLayoutId(R.layout.bottom_sheet_item_with_radio_btn)
.setOnClickListener(new OnClickListener() { .setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if(listener == null) { MapActivity mapActivity = getMapActivity();
getListener(); if (mapActivity == null) {
return;
} }
listener.onSelectedType(icon.getResId(), icon.getResStringId()); mapActivity.getImportHelper().chooseFileToImport(ROUTING, new CallbackWithObject<String>() {
dismiss(); @Override
public boolean processResult(String profileKey) {
if (listener == null) {
getListener();
}
Bundle args = new Bundle();
args.putString(PROFILE_KEY_ARG, profileKey);
args.putBoolean(IS_PROFILE_IMPORTED_ARG, true);
listener.onSelectedType(args);
dismiss();
return false;
}
});
} }
}) })
.create() .create());
); items.add(new BaseBottomSheetItem.Builder()
} .setCustomView(bottomSpaceView)
.create());
} }
} }
@ -215,26 +267,12 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
FragmentActivity activity = getActivity(); FragmentActivity activity = getActivity();
if (activity != null) { if (activity != null) {
FragmentManager fragmentManager = activity.getSupportFragmentManager(); FragmentManager fragmentManager = activity.getSupportFragmentManager();
EditProfileFragment editProfileFragment = (EditProfileFragment) fragmentManager.findFragmentByTag(EditProfileFragment.TAG);
SettingsProfileFragment settingsProfileFragment = (SettingsProfileFragment) fragmentManager.findFragmentByTag(SettingsProfileFragment.class.getName()); SettingsProfileFragment settingsProfileFragment = (SettingsProfileFragment) fragmentManager.findFragmentByTag(SettingsProfileFragment.class.getName());
NavigationFragment navigationFragment = (NavigationFragment) fragmentManager.findFragmentByTag(NavigationFragment.class.getName()); NavigationFragment navigationFragment = (NavigationFragment) fragmentManager.findFragmentByTag(NavigationFragment.class.getName());
ProfileAppearanceFragment profileAppearanceFragment = (ProfileAppearanceFragment) fragmentManager.findFragmentByTag(ProfileAppearanceFragment.TAG); ProfileAppearanceFragment profileAppearanceFragment = (ProfileAppearanceFragment) fragmentManager.findFragmentByTag(ProfileAppearanceFragment.TAG);
MainSettingsFragment mainSettingsFragment = (MainSettingsFragment) fragmentManager.findFragmentByTag(MainSettingsFragment.TAG); MainSettingsFragment mainSettingsFragment = (MainSettingsFragment) fragmentManager.findFragmentByTag(MainSettingsFragment.TAG);
if (editProfileFragment != null) { if (settingsProfileFragment != null) {
switch (type) {
case TYPE_BASE_APP_PROFILE:
listener = editProfileFragment.getBaseProfileListener();
break;
case TYPE_NAV_PROFILE:
listener = editProfileFragment.getNavProfileListener();
break;
case TYPE_ICON:
listener = editProfileFragment.getIconListener();
break;
}
} else if (settingsProfileFragment != null) {
listener = settingsProfileFragment.getBaseProfileListener(); listener = settingsProfileFragment.getBaseProfileListener();
} else if (navigationFragment != null) { } else if (navigationFragment != null) {
listener = navigationFragment.getNavProfileListener(); listener = navigationFragment.getNavProfileListener();
@ -247,6 +285,15 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
} }
public interface SelectProfileListener { public interface SelectProfileListener {
void onSelectedType(int pos, String stringRes); void onSelectedType(Bundle args);
}
@Nullable
private MapActivity getMapActivity() {
Activity activity = getActivity();
if (activity instanceof MapActivity) {
return (MapActivity) activity;
}
return null;
} }
} }

View file

@ -3,6 +3,7 @@ package net.osmand.plus.profiles;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.PROFILE_KEY_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
import android.content.Context; import android.content.Context;
@ -147,19 +148,19 @@ public class SettingsProfileFragment extends BaseOsmAndFragment
if (typeListener == null) { if (typeListener == null) {
typeListener = new SelectProfileListener() { typeListener = new SelectProfileListener() {
@Override @Override
public void onSelectedType(int pos, String stringRes) { public void onSelectedType(Bundle args) {
FragmentActivity activity = getActivity(); FragmentActivity activity = getActivity();
String profileKey = args.getString(PROFILE_KEY_ARG);
if (activity != null) { if (activity != null) {
if (activity instanceof SettingsProfileActivity) { if (activity instanceof SettingsProfileActivity) {
Intent intent = new Intent(getActivity(), EditProfileActivity.class); Intent intent = new Intent(getActivity(), EditProfileActivity.class);
intent.putExtra(IS_NEW_PROFILE, true); intent.putExtra(IS_NEW_PROFILE, true);
intent.putExtra(IS_USER_PROFILE, true); intent.putExtra(IS_USER_PROFILE, true);
intent.putExtra(PROFILE_STRING_KEY, baseProfiles.get(pos).getStringKey()); intent.putExtra(PROFILE_STRING_KEY, profileKey);
activity.startActivity(intent); activity.startActivity(intent);
} else { } else {
FragmentManager fragmentManager = activity.getSupportFragmentManager(); FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (fragmentManager != null) { if (fragmentManager != null) {
String profileKey = baseProfiles.get(pos).getStringKey();
EditProfileFragment.showInstance(fragmentManager, true, true, profileKey); EditProfileFragment.showInstance(fragmentManager, true, true, profileKey);
} }
} }

View file

@ -12,11 +12,13 @@ import android.support.v7.preference.PreferenceViewHolder;
import android.view.View; import android.view.View;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
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.profiles.ProfileDataObject; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
@ -26,9 +28,11 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import static net.osmand.plus.helpers.ImportHelper.ImportType.SETTINGS;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.IS_PROFILE_IMPORTED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.PROFILE_KEY_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
import static net.osmand.plus.profiles.SettingsProfileFragment.getBaseProfiles;
public class MainSettingsFragment extends BaseSettingsFragment { public class MainSettingsFragment extends BaseSettingsFragment {
@ -38,7 +42,7 @@ public class MainSettingsFragment extends BaseSettingsFragment {
private static final String APP_PROFILES = "app_profiles"; private static final String APP_PROFILES = "app_profiles";
private static final String SELECTED_PROFILE = "selected_profile"; private static final String SELECTED_PROFILE = "selected_profile";
private static final String CREATE_PROFILE = "create_profile"; private static final String CREATE_PROFILE = "create_profile";
// private static final String IMPORT_PROFILE = "import_profile"; private static final String IMPORT_PROFILE = "import_profile";
private static final String REORDER_PROFILES = "reorder_profiles"; private static final String REORDER_PROFILES = "reorder_profiles";
private List<ApplicationMode> allAppModes; private List<ApplicationMode> allAppModes;
@ -115,6 +119,25 @@ public class MainSettingsFragment extends BaseSettingsFragment {
getActivity().getSupportFragmentManager().beginTransaction() getActivity().getSupportFragmentManager().beginTransaction()
.add(dialog, "select_base_profile").commitAllowingStateLoss(); .add(dialog, "select_base_profile").commitAllowingStateLoss();
} }
} else if (IMPORT_PROFILE.equals(prefId)) {
final MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getImportHelper().chooseFileToImport(SETTINGS, new CallbackWithObject<List<SettingsItem>>() {
@Override
public boolean processResult(List<SettingsItem> result) {
for (SettingsItem item : result) {
if (SettingsItemType.PROFILE.equals(item.getType())) {
ConfigureProfileFragment.showInstance(mapActivity, SettingsScreenType.CONFIGURE_PROFILE,
ApplicationMode.valueOfStringKey(item.getName(), null));
break;
}
}
return false;
}
});
}
} }
return super.onPreferenceClick(preference); return super.onPreferenceClick(preference);
} }
@ -131,15 +154,17 @@ public class MainSettingsFragment extends BaseSettingsFragment {
} }
private void profileManagementPref() { private void profileManagementPref() {
int activeColorPrimaryResId = isNightMode() ? R.color.active_color_primary_dark
: R.color.active_color_primary_light;
Preference createProfile = findPreference(CREATE_PROFILE); Preference createProfile = findPreference(CREATE_PROFILE);
createProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_plus, createProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_plus, activeColorPrimaryResId));
isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
// Preference importProfile = findPreference(IMPORT_PROFILE); Preference importProfile = findPreference(IMPORT_PROFILE);
// importProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_import, importProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_import, activeColorPrimaryResId));
// isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
Preference reorderProfiles = findPreference(REORDER_PROFILES); Preference reorderProfiles = findPreference(REORDER_PROFILES);
reorderProfiles.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_edit_dark, reorderProfiles.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_edit_dark, activeColorPrimaryResId));
isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
} }
private void setupAppProfiles(PreferenceCategory preferenceCategory) { private void setupAppProfiles(PreferenceCategory preferenceCategory) {
@ -181,14 +206,15 @@ public class MainSettingsFragment extends BaseSettingsFragment {
if (selectProfileListener == null) { if (selectProfileListener == null) {
selectProfileListener = new SelectProfileListener() { selectProfileListener = new SelectProfileListener() {
@Override @Override
public void onSelectedType(int pos, String stringRes) { public void onSelectedType(Bundle args) {
FragmentActivity activity = getActivity(); FragmentActivity activity = getActivity();
if (activity != null) { if (activity != null) {
FragmentManager fragmentManager = activity.getSupportFragmentManager(); FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (fragmentManager != null) { if (fragmentManager != null) {
ProfileDataObject profileDataObject = getBaseProfiles(app).get(pos); String profileKey = args.getString(PROFILE_KEY_ARG);
boolean imported = args.getBoolean(IS_PROFILE_IMPORTED_ARG);
ProfileAppearanceFragment.showInstance(activity, SettingsScreenType.PROFILE_APPEARANCE, ProfileAppearanceFragment.showInstance(activity, SettingsScreenType.PROFILE_APPEARANCE,
profileDataObject.getStringKey()); profileKey, imported);
} }
} }
} }

View file

@ -7,19 +7,23 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.profiles.EditProfileFragment;
import net.osmand.plus.profiles.EditProfileFragment.RoutingProfilesResources;
import net.osmand.plus.profiles.RoutingProfileDataObject; import net.osmand.plus.profiles.RoutingProfileDataObject;
import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
import net.osmand.util.Algorithms;
import java.util.List; import java.util.HashMap;
import java.util.Map;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.IS_PROFILE_IMPORTED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.PROFILE_KEY_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE;
@ -29,13 +33,13 @@ public class NavigationFragment extends BaseSettingsFragment {
public static final String NAVIGATION_TYPE = "navigation_type"; public static final String NAVIGATION_TYPE = "navigation_type";
private SelectProfileBottomSheetDialogFragment.SelectProfileListener navTypeListener; private SelectProfileBottomSheetDialogFragment.SelectProfileListener navTypeListener;
private List<RoutingProfileDataObject> routingProfileDataObjects; private Map<String, RoutingProfileDataObject> routingProfileDataObjects;
private Preference navigationType; private Preference navigationType;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
routingProfileDataObjects = EditProfileFragment.getRoutingProfiles(app); routingProfileDataObjects = getRoutingProfiles(app);
} }
@Override @Override
@ -55,9 +59,14 @@ public class NavigationFragment extends BaseSettingsFragment {
if (getSelectedAppMode().getRoutingProfile() != null) { if (getSelectedAppMode().getRoutingProfile() != null) {
GeneralRouter routingProfile = app.getRoutingConfig().getRouter(getSelectedAppMode().getRoutingProfile()); GeneralRouter routingProfile = app.getRoutingConfig().getRouter(getSelectedAppMode().getRoutingProfile());
if (routingProfile != null) { if (routingProfile != null) {
RoutingProfilesResources routingProfilesResources = RoutingProfilesResources.valueOf(routingProfile.getProfileName().toUpperCase()); String profileNameUC = routingProfile.getProfileName().toUpperCase();
navigationType.setSummary(routingProfilesResources.getStringRes()); if (RoutingProfilesResources.isRpValue(profileNameUC)) {
navigationType.setIcon(getContentIcon(routingProfilesResources.getIconRes())); RoutingProfilesResources routingProfilesResources = RoutingProfilesResources.valueOf(profileNameUC);
navigationType.setSummary(routingProfilesResources.getStringRes());
navigationType.setIcon(getContentIcon(routingProfilesResources.getIconRes()));
} else {
navigationType.setIcon(getContentIcon(R.drawable.ic_action_gdirections_dark));
}
} }
} }
routeParameters.setIcon(getContentIcon(R.drawable.ic_action_route_distance)); routeParameters.setIcon(getContentIcon(R.drawable.ic_action_route_distance));
@ -103,34 +112,35 @@ public class NavigationFragment extends BaseSettingsFragment {
if (navTypeListener == null) { if (navTypeListener == null) {
navTypeListener = new SelectProfileBottomSheetDialogFragment.SelectProfileListener() { navTypeListener = new SelectProfileBottomSheetDialogFragment.SelectProfileListener() {
@Override @Override
public void onSelectedType(int pos, String stringRes) { public void onSelectedType(Bundle args) {
updateRoutingProfile(pos); if (args.getBoolean(IS_PROFILE_IMPORTED_ARG)) {
routingProfileDataObjects = getRoutingProfiles(app);
}
updateRoutingProfile(args.getString(PROFILE_KEY_ARG));
} }
}; };
} }
return navTypeListener; return navTypeListener;
} }
void updateRoutingProfile(int pos) { void updateRoutingProfile(String profileKey) {
for (int i = 0; i < routingProfileDataObjects.size(); i++) { RoutingProfileDataObject selectedRoutingProfileDataObject = routingProfileDataObjects.get(profileKey);
if (i == pos) { if (profileKey == null || selectedRoutingProfileDataObject == null) {
routingProfileDataObjects.get(i).setSelected(true); return;
} else { }
routingProfileDataObjects.get(i).setSelected(false); for (Map.Entry<String, RoutingProfileDataObject> rp : routingProfileDataObjects.entrySet()) {
} boolean selected = profileKey.equals(rp.getKey());
rp.getValue().setSelected(selected);
} }
RoutingProfileDataObject selectedRoutingProfileDataObject = routingProfileDataObjects.get(pos);
navigationType.setSummary(selectedRoutingProfileDataObject.getName()); navigationType.setSummary(selectedRoutingProfileDataObject.getName());
navigationType.setIcon(getContentIcon(selectedRoutingProfileDataObject.getIconRes())); navigationType.setIcon(getContentIcon(selectedRoutingProfileDataObject.getIconRes()));
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode.changeBaseMode(getSelectedAppMode()); ApplicationMode.ApplicationModeBuilder builder = ApplicationMode.changeBaseMode(getSelectedAppMode());
if (selectedRoutingProfileDataObject.getStringKey().equals( if (profileKey.equals(RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) {
RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) {
builder.setRouteService(RouteProvider.RouteService.STRAIGHT); builder.setRouteService(RouteProvider.RouteService.STRAIGHT);
} else if (selectedRoutingProfileDataObject.getStringKey().equals( } else if (profileKey.equals(RoutingProfilesResources.BROUTER_MODE.name())) {
RoutingProfilesResources.BROUTER_MODE.name())) {
builder.setRouteService(RouteProvider.RouteService.BROUTER); builder.setRouteService(RouteProvider.RouteService.BROUTER);
} else { } else {
builder.setRoutingProfile(selectedRoutingProfileDataObject.getStringKey()); builder.setRoutingProfile(profileKey);
} }
ApplicationMode mode = ApplicationMode.saveProfile(builder, app); ApplicationMode mode = ApplicationMode.saveProfile(builder, app);
@ -139,6 +149,43 @@ public class NavigationFragment extends BaseSettingsFragment {
} }
} }
public static Map<String, RoutingProfileDataObject> getRoutingProfiles(OsmandApplication context) {
Map<String, RoutingProfileDataObject> profilesObjects = new HashMap<>();
profilesObjects.put(RoutingProfilesResources.STRAIGHT_LINE_MODE.name(), new RoutingProfileDataObject(
RoutingProfilesResources.STRAIGHT_LINE_MODE.name(),
context.getString(RoutingProfilesResources.STRAIGHT_LINE_MODE.getStringRes()),
context.getString(R.string.special_routing_type),
RoutingProfilesResources.STRAIGHT_LINE_MODE.getIconRes(),
false, null));
if (context.getBRouterService() != null) {
profilesObjects.put(RoutingProfilesResources.BROUTER_MODE.name(), new RoutingProfileDataObject(
RoutingProfilesResources.BROUTER_MODE.name(),
context.getString(RoutingProfilesResources.BROUTER_MODE.getStringRes()),
context.getString(R.string.third_party_routing_type),
RoutingProfilesResources.BROUTER_MODE.getIconRes(),
false, null));
}
Map<String, GeneralRouter> inputProfiles = context.getRoutingConfig().getAllRouters();
for (Map.Entry<String, GeneralRouter> e : inputProfiles.entrySet()) {
if (!e.getKey().equals("geocoding")) {
int iconRes = R.drawable.ic_action_gdirections_dark;
String name = e.getValue().getProfileName();
String description = context.getString(R.string.osmand_default_routing);
if (!Algorithms.isEmpty(e.getValue().getFilename())) {
description = e.getValue().getFilename();
} else if (RoutingProfilesResources.isRpValue(name.toUpperCase())){
iconRes = RoutingProfilesResources.valueOf(name.toUpperCase()).getIconRes();
name = context
.getString(RoutingProfilesResources.valueOf(name.toUpperCase()).getStringRes());
}
profilesObjects.put(e.getKey(), new RoutingProfileDataObject(e.getKey(), name, description,
iconRes, false, e.getValue().getFilename()));
}
}
return profilesObjects;
}
private void setupVehicleParametersPref() { private void setupVehicleParametersPref() {
Preference vehicleParameters = findPreference("vehicle_parameters"); Preference vehicleParameters = findPreference("vehicle_parameters");
int iconRes = getSelectedAppMode().getIconRes(); int iconRes = getSelectedAppMode().getIconRes();

View file

@ -38,7 +38,6 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.UiUtilities.DialogButtonType;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
import net.osmand.plus.profiles.SettingsProfileFragment;
import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.widgets.FlowLayout; import net.osmand.plus.widgets.FlowLayout;
import net.osmand.plus.widgets.OsmandTextFieldBoxes; import net.osmand.plus.widgets.OsmandTextFieldBoxes;
@ -50,6 +49,8 @@ import java.util.ArrayList;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.IS_PROFILE_IMPORTED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.PROFILE_KEY_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
@ -77,6 +78,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
public static final String PROFILE_LOCATION_ICON_KEY = "profile_location_icon_key"; public static final String PROFILE_LOCATION_ICON_KEY = "profile_location_icon_key";
public static final String PROFILE_NAVIGATION_ICON_KEY = "profile_navigation_icon_key"; public static final String PROFILE_NAVIGATION_ICON_KEY = "profile_navigation_icon_key";
public static final String BASE_PROFILE_FOR_NEW = "base_profile_for_new"; public static final String BASE_PROFILE_FOR_NEW = "base_profile_for_new";
public static final String IS_BASE_PROFILE_IMPORTED = "is_base_profile_imported";
private SelectProfileBottomSheetDialogFragment.SelectProfileListener parentProfileListener; private SelectProfileBottomSheetDialogFragment.SelectProfileListener parentProfileListener;
private EditText baseProfileName; private EditText baseProfileName;
private ApplicationProfileObject profile; private ApplicationProfileObject profile;
@ -88,6 +90,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
private FlowLayout navIconItems; private FlowLayout navIconItems;
private OsmandTextFieldBoxes profileNameOtfb; private OsmandTextFieldBoxes profileNameOtfb;
private View saveButton; private View saveButton;
private boolean isBaseProfileImported;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -97,12 +101,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
if (getArguments() != null) { if (getArguments() != null) {
Bundle arguments = getArguments(); Bundle arguments = getArguments();
String keyBaseProfileForNew = arguments.getString(BASE_PROFILE_FOR_NEW, null); String keyBaseProfileForNew = arguments.getString(BASE_PROFILE_FOR_NEW, null);
for (ApplicationMode mode : ApplicationMode.getDefaultValues()) { baseModeForNewProfile = ApplicationMode.valueOfStringKey(keyBaseProfileForNew, null);
if (mode.getStringKey().equals(keyBaseProfileForNew)) { isBaseProfileImported = arguments.getBoolean(IS_BASE_PROFILE_IMPORTED);
baseModeForNewProfile = mode;
break;
}
}
} }
if (baseModeForNewProfile != null) { if (baseModeForNewProfile != null) {
profile.stringKey = baseModeForNewProfile.getStringKey() + "_" + System.currentTimeMillis(); profile.stringKey = baseModeForNewProfile.getStringKey() + "_" + System.currentTimeMillis();
@ -214,9 +214,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
cancelButton.setOnClickListener(new View.OnClickListener() { cancelButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (getActivity() != null) { goBackWithoutSaving();
getActivity().onBackPressed();
}
} }
}); });
saveButton.setOnClickListener(new View.OnClickListener() { saveButton.setOnClickListener(new View.OnClickListener() {
@ -269,6 +267,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
if (changedProfile.parent != null) { if (changedProfile.parent != null) {
outState.putString(PROFILE_PARENT_KEY, changedProfile.parent.getStringKey()); outState.putString(PROFILE_PARENT_KEY, changedProfile.parent.getStringKey());
} }
outState.putBoolean(IS_BASE_PROFILE_IMPORTED, isBaseProfileImported);
outState.putSerializable(PROFILE_LOCATION_ICON_KEY, changedProfile.locationIcon); outState.putSerializable(PROFILE_LOCATION_ICON_KEY, changedProfile.locationIcon);
outState.putSerializable(PROFILE_NAVIGATION_ICON_KEY, changedProfile.navigationIcon); outState.putSerializable(PROFILE_NAVIGATION_ICON_KEY, changedProfile.navigationIcon);
} }
@ -280,6 +279,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
changedProfile.color = (ApplicationMode.ProfileIconColors) savedInstanceState.getSerializable(PROFILE_COLOR_KEY); changedProfile.color = (ApplicationMode.ProfileIconColors) savedInstanceState.getSerializable(PROFILE_COLOR_KEY);
String parentStringKey = savedInstanceState.getString(PROFILE_PARENT_KEY); String parentStringKey = savedInstanceState.getString(PROFILE_PARENT_KEY);
changedProfile.parent = ApplicationMode.valueOfStringKey(parentStringKey, null); changedProfile.parent = ApplicationMode.valueOfStringKey(parentStringKey, null);
isBaseProfileImported = savedInstanceState.getBoolean(IS_BASE_PROFILE_IMPORTED);
changedProfile.locationIcon = (ApplicationMode.LocationIcon) savedInstanceState.getSerializable(PROFILE_LOCATION_ICON_KEY); changedProfile.locationIcon = (ApplicationMode.LocationIcon) savedInstanceState.getSerializable(PROFILE_LOCATION_ICON_KEY);
changedProfile.navigationIcon = (ApplicationMode.NavigationIcon) savedInstanceState.getSerializable(PROFILE_NAVIGATION_ICON_KEY); changedProfile.navigationIcon = (ApplicationMode.NavigationIcon) savedInstanceState.getSerializable(PROFILE_NAVIGATION_ICON_KEY);
} }
@ -610,18 +610,21 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
if (parentProfileListener == null) { if (parentProfileListener == null) {
parentProfileListener = new SelectProfileBottomSheetDialogFragment.SelectProfileListener() { parentProfileListener = new SelectProfileBottomSheetDialogFragment.SelectProfileListener() {
@Override @Override
public void onSelectedType(int pos, String stringRes) { public void onSelectedType(Bundle args) {
updateParentProfile(pos); String profileKey = args.getString(PROFILE_KEY_ARG);
boolean imported = args.getBoolean(IS_PROFILE_IMPORTED_ARG);
updateParentProfile(profileKey, imported);
} }
}; };
} }
return parentProfileListener; return parentProfileListener;
} }
void updateParentProfile(int pos) { void updateParentProfile(String profileKey, boolean isBaseProfileImported) {
String key = SettingsProfileFragment.getBaseProfiles(getMyApplication()).get(pos).getStringKey(); deleteImportedProfile();
setupBaseProfileView(key); setupBaseProfileView(profileKey);
changedProfile.parent = ApplicationMode.valueOfStringKey(key, ApplicationMode.DEFAULT); changedProfile.parent = ApplicationMode.valueOfStringKey(profileKey, ApplicationMode.DEFAULT);
this.isBaseProfileImported = isBaseProfileImported;
} }
private void setupBaseProfileView(String stringKey) { private void setupBaseProfileView(String stringKey) {
@ -679,7 +682,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
changedProfile = profile; changedProfile = profile;
mapActivity.onBackPressed(); goBackWithoutSaving();
} }
}); });
dismissDialog.show(); dismissDialog.show();
@ -698,12 +701,27 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
return warningDialog; return warningDialog;
} }
public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType, @Nullable String appMode) { private void goBackWithoutSaving() {
deleteImportedProfile();
if (getActivity() != null) {
getActivity().onBackPressed();
}
}
private void deleteImportedProfile() {
if (isBaseProfileImported) {
ApplicationMode.deleteCustomMode(ApplicationMode.valueOfStringKey(
changedProfile.parent.getStringKey(), ApplicationMode.DEFAULT), app);
}
}
public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType, @Nullable String appMode, boolean imported) {
try { try {
Fragment fragment = Fragment.instantiate(activity, screenType.fragmentName); Fragment fragment = Fragment.instantiate(activity, screenType.fragmentName);
Bundle args = new Bundle(); Bundle args = new Bundle();
if (appMode != null) { if (appMode != null) {
args.putString(BASE_PROFILE_FOR_NEW, appMode); args.putString(BASE_PROFILE_FOR_NEW, appMode);
args.putBoolean(IS_BASE_PROFILE_IMPORTED, imported);
} }
fragment.setArguments(args); fragment.setArguments(args);
activity.getSupportFragmentManager().beginTransaction() activity.getSupportFragmentManager().beginTransaction()