commit
8063a97a43
16 changed files with 596 additions and 156 deletions
|
@ -42,6 +42,8 @@ public class IndexConstants {
|
|||
|
||||
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 final static String POI_TABLE = "poi"; //$NON-NLS-1$
|
||||
|
|
|
@ -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() {
|
||||
return routers;
|
||||
}
|
||||
|
|
|
@ -323,6 +323,39 @@
|
|||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.osf" />
|
||||
</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-->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
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="multimedia_notes_prefs_descr">Picture size, audio and video quality</string>
|
||||
<string name="osm_editing_prefs_descr">Login, password, offline editing</string>
|
||||
|
|
|
@ -46,12 +46,12 @@
|
|||
android:title="@string/new_profile"
|
||||
tools:icon="@drawable/ic_action_plus" />
|
||||
|
||||
<!--Preference
|
||||
<Preference
|
||||
android:key="import_profile"
|
||||
android:layout="@layout/preference_button"
|
||||
android:persistent="false"
|
||||
android:title="@string/profile_import"
|
||||
tools:icon="@drawable/ic_action_import" /-->
|
||||
android:title="@string/import_profile"
|
||||
tools:icon="@drawable/ic_action_import" />
|
||||
|
||||
<Preference
|
||||
android:key="reorder_profiles"
|
||||
|
|
|
@ -689,4 +689,36 @@ public class AndroidUtils {
|
|||
public static boolean isRTL() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,6 @@ import net.osmand.plus.voice.TTSCommandPlayerImpl;
|
|||
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
import net.osmand.router.RoutingConfiguration;
|
||||
import net.osmand.router.RoutingConfiguration.Builder;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.OpeningHoursParser;
|
||||
|
||||
|
@ -142,6 +141,10 @@ public class AppInitializer implements IProgress {
|
|||
void onFinish(AppInitializer init);
|
||||
}
|
||||
|
||||
public interface LoadRoutingFilesCallback {
|
||||
void onRoutingFilesLoaded();
|
||||
}
|
||||
|
||||
|
||||
public AppInitializer(OsmandApplication app) {
|
||||
this.app = app;
|
||||
|
@ -579,9 +582,19 @@ public class AppInitializer implements IProgress {
|
|||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private void getLazyRoutingConfig() {
|
||||
new AsyncTask<Void, Void, RoutingConfiguration.Builder>() {
|
||||
loadRoutingFiles(app, new LoadRoutingFilesCallback() {
|
||||
@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);
|
||||
RoutingConfiguration.Builder builder = RoutingConfiguration.getDefault();
|
||||
if (routingFolder.isDirectory()) {
|
||||
|
@ -602,10 +615,10 @@ public class AppInitializer implements IProgress {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Builder builder) {
|
||||
protected void onPostExecute(RoutingConfiguration.Builder builder) {
|
||||
super.onPostExecute(builder);
|
||||
app.updateRoutingConfig(builder);
|
||||
notifyEvent(InitEvents.ROUTING_CONFIG_INITIALIZED);
|
||||
callback.onRoutingFilesLoaded();
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public class SettingsHelper {
|
|||
private ImportAsyncTask importTask;
|
||||
|
||||
public interface SettingsImportListener {
|
||||
void onSettingsImportFinished(boolean succeed, boolean empty);
|
||||
void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items);
|
||||
}
|
||||
|
||||
public interface SettingsExportListener {
|
||||
|
@ -913,7 +913,7 @@ public class SettingsHelper {
|
|||
@Override
|
||||
protected void onPreExecute() {
|
||||
if (importing) {
|
||||
finishImport(listener, false, false);
|
||||
finishImport(listener, false, false, items);
|
||||
}
|
||||
importing = true;
|
||||
importSuspended = false;
|
||||
|
@ -948,7 +948,7 @@ public class SettingsHelper {
|
|||
if (processedItems.size() > 0) {
|
||||
new ImportItemsAsyncTask(file, listener, processedItems).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
finishImport(listener, false, true);
|
||||
finishImport(listener, false, true, items);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -1063,16 +1063,16 @@ public class SettingsHelper {
|
|||
|
||||
@Override
|
||||
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;
|
||||
importSuspended = false;
|
||||
importTask = null;
|
||||
if (listener != null) {
|
||||
listener.onSettingsImportFinished(success, empty);
|
||||
listener.onSettingsImportFinished(success, empty, items);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.view.View;
|
|||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
|
@ -39,6 +40,7 @@ import net.osmand.plus.OsmandPlugin;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.SettingsHelper;
|
||||
import net.osmand.plus.SettingsHelper.SettingsImportListener;
|
||||
import net.osmand.plus.activities.ActivityResultListener;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.TrackActivity;
|
||||
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.rastermaps.OsmandRasterMapsPlugin;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.router.RoutingConfiguration;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
|
@ -69,6 +73,10 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
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.GPX_TAB;
|
||||
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
|
||||
|
@ -86,6 +94,23 @@ public class ImportHelper {
|
|||
private final OsmandMapTileView mapView;
|
||||
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 {
|
||||
void onComplete(boolean success);
|
||||
}
|
||||
|
@ -156,14 +181,10 @@ public class ImportHelper {
|
|||
handleObfImport(intentUri, fileName);
|
||||
} else if (fileName != null && fileName.endsWith(IndexConstants.SQLITE_EXT)) {
|
||||
handleSqliteTileImport(intentUri, fileName);
|
||||
} else if (fileName != null && fileName.endsWith(IndexConstants.OSMAND_SETTINGS_FILE_EXT)) {
|
||||
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);
|
||||
} else {
|
||||
handleOsmAndSettingsImport(intentUri, fileName, null, -1);
|
||||
}
|
||||
} else if (fileName != null && fileName.endsWith(OSMAND_SETTINGS_FILE_EXT)) {
|
||||
handleOsmAndSettingsImport(intentUri, fileName, extras, null);
|
||||
} else if (fileName != null && fileName.endsWith(ROUTING_FILE_EXT)) {
|
||||
handleRoutingFileImport(intentUri, fileName, null);
|
||||
} else {
|
||||
handleFavouritesImport(intentUri, fileName, saveFile, useImportDir, false);
|
||||
}
|
||||
|
@ -585,8 +606,147 @@ public class ImportHelper {
|
|||
}.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")
|
||||
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>() {
|
||||
|
||||
ProgressDialog progress;
|
||||
|
@ -613,12 +773,15 @@ public class ImportHelper {
|
|||
if (error == null && file.exists()) {
|
||||
app.getSettingsHelper().importSettings(file, latestChanges, version, new SettingsImportListener() {
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, boolean empty) {
|
||||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
if (succeed) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, name));
|
||||
if (callback != null) {
|
||||
callback.processResult(items);
|
||||
}
|
||||
} else if (!empty) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_import_error, name, app.getString(R.string.shared_string_unexpected_error)));
|
||||
}
|
||||
|
|
|
@ -68,9 +68,9 @@ import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
|
|||
|
||||
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.PROFILE_KEY_ARG;
|
||||
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_ICON;
|
||||
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_USER_PROFILE;
|
||||
|
@ -312,7 +312,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
public void onClick(View v) {
|
||||
final SelectProfileBottomSheetDialogFragment iconSelectDialog = new SelectProfileBottomSheetDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(DIALOG_TYPE, TYPE_ICON);
|
||||
// bundle.putString(DIALOG_TYPE, TYPE_ICON);
|
||||
bundle.putString(SELECTED_ICON, profile.iconStringName);
|
||||
iconSelectDialog.setArguments(bundle);
|
||||
hideKeyboard();
|
||||
|
@ -470,10 +470,11 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
if (iconIdListener == null) {
|
||||
iconIdListener = new SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos, String stringRes) {
|
||||
public void onSelectedType(Bundle bundle) {
|
||||
int pos = -1;
|
||||
dataChanged = true;
|
||||
profile.iconId = pos;
|
||||
profile.iconStringName = stringRes;
|
||||
profile.iconStringName = null;
|
||||
profileIcon.setImageDrawable(app.getUIUtilities().getIcon(pos,
|
||||
profile.iconColor.getColor(nightMode)));
|
||||
|
||||
|
@ -487,11 +488,10 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
if (baseTypeListener == null) {
|
||||
baseTypeListener = new SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos, String stringRes) {
|
||||
String key = SettingsProfileFragment.getBaseProfiles(getMyApplication())
|
||||
.get(pos).getStringKey();
|
||||
setupBaseProfileView(key);
|
||||
profile.parent = ApplicationMode.valueOfStringKey(key, ApplicationMode.DEFAULT);
|
||||
public void onSelectedType(Bundle args) {
|
||||
String profileKey = args.getString(PROFILE_KEY_ARG);
|
||||
setupBaseProfileView(profileKey);
|
||||
profile.parent = ApplicationMode.valueOfStringKey(profileKey, ApplicationMode.DEFAULT);
|
||||
dataChanged = true;
|
||||
}
|
||||
};
|
||||
|
@ -503,7 +503,8 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
if (navTypeListener == null) {
|
||||
navTypeListener = new SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos, String stringRes) {
|
||||
public void onSelectedType(Bundle args) {
|
||||
int pos = -1;
|
||||
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<>();
|
||||
profilesObjects.add(new RoutingProfileDataObject(
|
||||
RoutingProfilesResources.STRAIGHT_LINE_MODE.name(),
|
||||
|
@ -812,7 +813,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
return profilesObjects;
|
||||
}
|
||||
|
||||
public enum RoutingProfilesResources {
|
||||
private 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),
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import android.os.Parcel;
|
||||
import net.osmand.plus.ApplicationMode.ProfileIconColors;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class RoutingProfileDataObject extends ProfileDataObject {
|
||||
|
@ -17,4 +19,43 @@ public class RoutingProfileDataObject extends ProfileDataObject {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
|
@ -9,13 +10,20 @@ import android.support.v4.app.FragmentActivity;
|
|||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
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.bottomsheetmenu.BaseBottomSheetItem;
|
||||
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.TitleItem;
|
||||
import net.osmand.plus.settings.MainSettingsFragment;
|
||||
|
@ -27,7 +35,8 @@ import org.apache.commons.logging.Log;
|
|||
import java.util.ArrayList;
|
||||
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 {
|
||||
|
||||
|
@ -38,18 +47,18 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
public final static String DIALOG_TYPE = "dialog_type";
|
||||
public final static String TYPE_BASE_APP_PROFILE = "base_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 PROFILE_KEY_ARG = "profile_key_arg";
|
||||
public final static String IS_PROFILE_IMPORTED_ARG = "is_profile_imported_arg";
|
||||
|
||||
String type;
|
||||
int bottomButtonText = R.string.shared_string_cancel;
|
||||
|
||||
private SelectProfileListener listener;
|
||||
|
||||
private final List<ProfileDataObject> profiles = new ArrayList<>();
|
||||
|
||||
private String selectedItemKey;
|
||||
private String selectedIconRes;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -60,11 +69,9 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
type = args.getString(DIALOG_TYPE);
|
||||
selectedItemKey = args.getString(SELECTED_KEY, null);
|
||||
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)) {
|
||||
profiles.addAll(SettingsProfileFragment.getBaseProfiles(app));
|
||||
} else if (type.equals(TYPE_ICON)) {
|
||||
selectedIconRes = args.getString(SELECTED_ICON, "");
|
||||
} else {
|
||||
LOG.error("Check intent data!");
|
||||
dismiss();
|
||||
|
@ -84,8 +91,11 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
});
|
||||
|
||||
if (type.equals(TYPE_NAV_PROFILE) || type.equals(TYPE_BASE_APP_PROFILE)) {
|
||||
if (items.get(items.size()-1).getView() != null) {
|
||||
items.get(items.size()-1).getView().findViewById(R.id.divider_bottom).setVisibility(View.INVISIBLE);
|
||||
for (BaseBottomSheetItem item : items) {
|
||||
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
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
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)) {
|
||||
items.add(new TitleItem(getString(R.string.select_base_profile_dialog_title)));
|
||||
items.add(new LongDescriptionItem(getString(R.string.select_base_profile_dialog_message)));
|
||||
|
@ -125,18 +142,56 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
if (listener == null) {
|
||||
getListener();
|
||||
}
|
||||
listener.onSelectedType(pos, "");
|
||||
Bundle args = new Bundle();
|
||||
args.putString(PROFILE_KEY_ARG, profile.getStringKey());
|
||||
listener.onSelectedType(args);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.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)){
|
||||
items.add(new TitleItem(getString(R.string.select_nav_profile_dialog_title)));
|
||||
items.add(new LongDescriptionItem(getString(R.string.select_nav_profile_dialog_message)));
|
||||
for (int i = 0; i < profiles.size(); i++) {
|
||||
final int pos = i;
|
||||
final ProfileDataObject profile = profiles.get(i);
|
||||
final boolean isSelected = profile.getStringKey().equals(selectedItemKey);
|
||||
final Drawable drawableIcon;
|
||||
|
@ -164,50 +219,47 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
if (listener == null) {
|
||||
getListener();
|
||||
}
|
||||
listener.onSelectedType(pos, "");
|
||||
Bundle args = new Bundle();
|
||||
args.putString(PROFILE_KEY_ARG, profile.getStringKey());
|
||||
listener.onSelectedType(args);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create());
|
||||
}
|
||||
} else if (type.equals(TYPE_ICON)) {
|
||||
items.add(new TitleItem(getString(R.string.select_icon_profile_dialog_title)));
|
||||
for (final ApplicationMode.ProfileIcons icon : ApplicationMode.ProfileIcons.values()) {
|
||||
Drawable drawableIcon;
|
||||
boolean isSelected = icon.getResStringId().equals(selectedIconRes);
|
||||
int iconRes = icon.getResId();
|
||||
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)
|
||||
items.add(new DividerItem(app));
|
||||
items.add(new LongDescriptionItem(app.getString(R.string.osmand_routing_promo)));
|
||||
items.add(new SimpleBottomSheetItem.Builder()
|
||||
.setTitle(app.getString(R.string.import_routing_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) {
|
||||
if(listener == null) {
|
||||
getListener();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity == null) {
|
||||
return;
|
||||
}
|
||||
listener.onSelectedType(icon.getResId(), icon.getResStringId());
|
||||
dismiss();
|
||||
mapActivity.getImportHelper().chooseFileToImport(ROUTING, new CallbackWithObject<String>() {
|
||||
@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();
|
||||
if (activity != null) {
|
||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
EditProfileFragment editProfileFragment = (EditProfileFragment) fragmentManager.findFragmentByTag(EditProfileFragment.TAG);
|
||||
SettingsProfileFragment settingsProfileFragment = (SettingsProfileFragment) fragmentManager.findFragmentByTag(SettingsProfileFragment.class.getName());
|
||||
NavigationFragment navigationFragment = (NavigationFragment) fragmentManager.findFragmentByTag(NavigationFragment.class.getName());
|
||||
ProfileAppearanceFragment profileAppearanceFragment = (ProfileAppearanceFragment) fragmentManager.findFragmentByTag(ProfileAppearanceFragment.TAG);
|
||||
MainSettingsFragment mainSettingsFragment = (MainSettingsFragment) fragmentManager.findFragmentByTag(MainSettingsFragment.TAG);
|
||||
|
||||
if (editProfileFragment != 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) {
|
||||
if (settingsProfileFragment != null) {
|
||||
listener = settingsProfileFragment.getBaseProfileListener();
|
||||
} else if (navigationFragment != null) {
|
||||
listener = navigationFragment.getNavProfileListener();
|
||||
|
@ -247,6 +285,15 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.PROFILE_KEY_ARG;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -147,19 +148,19 @@ public class SettingsProfileFragment extends BaseOsmAndFragment
|
|||
if (typeListener == null) {
|
||||
typeListener = new SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos, String stringRes) {
|
||||
public void onSelectedType(Bundle args) {
|
||||
FragmentActivity activity = getActivity();
|
||||
String profileKey = args.getString(PROFILE_KEY_ARG);
|
||||
if (activity != null) {
|
||||
if (activity instanceof SettingsProfileActivity) {
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
intent.putExtra(IS_NEW_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);
|
||||
} else {
|
||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
if (fragmentManager != null) {
|
||||
String profileKey = baseProfiles.get(pos).getStringKey();
|
||||
EditProfileFragment.showInstance(fragmentManager, true, true, profileKey);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,13 @@ import android.support.v7.preference.PreferenceViewHolder;
|
|||
import android.view.View;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.SettingsHelper.*;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.profiles.ProfileDataObject;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
|
||||
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener;
|
||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||
|
@ -26,9 +28,11 @@ import java.util.LinkedHashSet;
|
|||
import java.util.List;
|
||||
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.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.SettingsProfileFragment.getBaseProfiles;
|
||||
|
||||
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 SELECTED_PROFILE = "selected_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 List<ApplicationMode> allAppModes;
|
||||
|
@ -115,6 +119,25 @@ public class MainSettingsFragment extends BaseSettingsFragment {
|
|||
getActivity().getSupportFragmentManager().beginTransaction()
|
||||
.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);
|
||||
}
|
||||
|
@ -131,15 +154,17 @@ public class MainSettingsFragment extends BaseSettingsFragment {
|
|||
}
|
||||
|
||||
private void profileManagementPref() {
|
||||
int activeColorPrimaryResId = isNightMode() ? R.color.active_color_primary_dark
|
||||
: R.color.active_color_primary_light;
|
||||
|
||||
Preference createProfile = findPreference(CREATE_PROFILE);
|
||||
createProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_plus,
|
||||
isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
|
||||
// Preference importProfile = findPreference(IMPORT_PROFILE);
|
||||
// importProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_import,
|
||||
// isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
|
||||
createProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_plus, activeColorPrimaryResId));
|
||||
|
||||
Preference importProfile = findPreference(IMPORT_PROFILE);
|
||||
importProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_import, activeColorPrimaryResId));
|
||||
|
||||
Preference reorderProfiles = findPreference(REORDER_PROFILES);
|
||||
reorderProfiles.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_edit_dark,
|
||||
isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
|
||||
reorderProfiles.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_edit_dark, activeColorPrimaryResId));
|
||||
}
|
||||
|
||||
private void setupAppProfiles(PreferenceCategory preferenceCategory) {
|
||||
|
@ -181,14 +206,15 @@ public class MainSettingsFragment extends BaseSettingsFragment {
|
|||
if (selectProfileListener == null) {
|
||||
selectProfileListener = new SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos, String stringRes) {
|
||||
public void onSelectedType(Bundle args) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
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,
|
||||
profileDataObject.getStringKey());
|
||||
profileKey, imported);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,19 +7,23 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
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.RoutingProfilesResources;
|
||||
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
|
||||
import net.osmand.plus.routing.RouteProvider;
|
||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||
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.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.TYPE_NAV_PROFILE;
|
||||
|
||||
|
@ -29,13 +33,13 @@ public class NavigationFragment extends BaseSettingsFragment {
|
|||
public static final String NAVIGATION_TYPE = "navigation_type";
|
||||
|
||||
private SelectProfileBottomSheetDialogFragment.SelectProfileListener navTypeListener;
|
||||
private List<RoutingProfileDataObject> routingProfileDataObjects;
|
||||
private Map<String, RoutingProfileDataObject> routingProfileDataObjects;
|
||||
private Preference navigationType;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
routingProfileDataObjects = EditProfileFragment.getRoutingProfiles(app);
|
||||
routingProfileDataObjects = getRoutingProfiles(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,9 +59,14 @@ public class NavigationFragment extends BaseSettingsFragment {
|
|||
if (getSelectedAppMode().getRoutingProfile() != null) {
|
||||
GeneralRouter routingProfile = app.getRoutingConfig().getRouter(getSelectedAppMode().getRoutingProfile());
|
||||
if (routingProfile != null) {
|
||||
RoutingProfilesResources routingProfilesResources = RoutingProfilesResources.valueOf(routingProfile.getProfileName().toUpperCase());
|
||||
navigationType.setSummary(routingProfilesResources.getStringRes());
|
||||
navigationType.setIcon(getContentIcon(routingProfilesResources.getIconRes()));
|
||||
String profileNameUC = routingProfile.getProfileName().toUpperCase();
|
||||
if (RoutingProfilesResources.isRpValue(profileNameUC)) {
|
||||
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));
|
||||
|
@ -103,34 +112,35 @@ public class NavigationFragment extends BaseSettingsFragment {
|
|||
if (navTypeListener == null) {
|
||||
navTypeListener = new SelectProfileBottomSheetDialogFragment.SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos, String stringRes) {
|
||||
updateRoutingProfile(pos);
|
||||
public void onSelectedType(Bundle args) {
|
||||
if (args.getBoolean(IS_PROFILE_IMPORTED_ARG)) {
|
||||
routingProfileDataObjects = getRoutingProfiles(app);
|
||||
}
|
||||
updateRoutingProfile(args.getString(PROFILE_KEY_ARG));
|
||||
}
|
||||
};
|
||||
}
|
||||
return navTypeListener;
|
||||
}
|
||||
|
||||
void updateRoutingProfile(int pos) {
|
||||
for (int i = 0; i < routingProfileDataObjects.size(); i++) {
|
||||
if (i == pos) {
|
||||
routingProfileDataObjects.get(i).setSelected(true);
|
||||
} else {
|
||||
routingProfileDataObjects.get(i).setSelected(false);
|
||||
}
|
||||
void updateRoutingProfile(String profileKey) {
|
||||
RoutingProfileDataObject selectedRoutingProfileDataObject = routingProfileDataObjects.get(profileKey);
|
||||
if (profileKey == null || selectedRoutingProfileDataObject == null) {
|
||||
return;
|
||||
}
|
||||
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.setIcon(getContentIcon(selectedRoutingProfileDataObject.getIconRes()));
|
||||
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode.changeBaseMode(getSelectedAppMode());
|
||||
if (selectedRoutingProfileDataObject.getStringKey().equals(
|
||||
RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) {
|
||||
if (profileKey.equals(RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) {
|
||||
builder.setRouteService(RouteProvider.RouteService.STRAIGHT);
|
||||
} else if (selectedRoutingProfileDataObject.getStringKey().equals(
|
||||
RoutingProfilesResources.BROUTER_MODE.name())) {
|
||||
} else if (profileKey.equals(RoutingProfilesResources.BROUTER_MODE.name())) {
|
||||
builder.setRouteService(RouteProvider.RouteService.BROUTER);
|
||||
} else {
|
||||
builder.setRoutingProfile(selectedRoutingProfileDataObject.getStringKey());
|
||||
builder.setRoutingProfile(profileKey);
|
||||
}
|
||||
|
||||
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() {
|
||||
Preference vehicleParameters = findPreference("vehicle_parameters");
|
||||
int iconRes = getSelectedAppMode().getIconRes();
|
||||
|
|
|
@ -38,7 +38,6 @@ import net.osmand.plus.UiUtilities;
|
|||
import net.osmand.plus.UiUtilities.DialogButtonType;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
|
||||
import net.osmand.plus.profiles.SettingsProfileFragment;
|
||||
import net.osmand.plus.routing.RouteProvider;
|
||||
import net.osmand.plus.widgets.FlowLayout;
|
||||
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.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.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_NAVIGATION_ICON_KEY = "profile_navigation_icon_key";
|
||||
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 EditText baseProfileName;
|
||||
private ApplicationProfileObject profile;
|
||||
|
@ -89,6 +91,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
private OsmandTextFieldBoxes profileNameOtfb;
|
||||
private View saveButton;
|
||||
|
||||
private boolean isBaseProfileImported;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -97,12 +101,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
if (getArguments() != null) {
|
||||
Bundle arguments = getArguments();
|
||||
String keyBaseProfileForNew = arguments.getString(BASE_PROFILE_FOR_NEW, null);
|
||||
for (ApplicationMode mode : ApplicationMode.getDefaultValues()) {
|
||||
if (mode.getStringKey().equals(keyBaseProfileForNew)) {
|
||||
baseModeForNewProfile = mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
baseModeForNewProfile = ApplicationMode.valueOfStringKey(keyBaseProfileForNew, null);
|
||||
isBaseProfileImported = arguments.getBoolean(IS_BASE_PROFILE_IMPORTED);
|
||||
}
|
||||
if (baseModeForNewProfile != null) {
|
||||
profile.stringKey = baseModeForNewProfile.getStringKey() + "_" + System.currentTimeMillis();
|
||||
|
@ -214,9 +214,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (getActivity() != null) {
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
goBackWithoutSaving();
|
||||
}
|
||||
});
|
||||
saveButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -269,6 +267,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
if (changedProfile.parent != null) {
|
||||
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_NAVIGATION_ICON_KEY, changedProfile.navigationIcon);
|
||||
}
|
||||
|
@ -280,6 +279,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
changedProfile.color = (ApplicationMode.ProfileIconColors) savedInstanceState.getSerializable(PROFILE_COLOR_KEY);
|
||||
String parentStringKey = savedInstanceState.getString(PROFILE_PARENT_KEY);
|
||||
changedProfile.parent = ApplicationMode.valueOfStringKey(parentStringKey, null);
|
||||
isBaseProfileImported = savedInstanceState.getBoolean(IS_BASE_PROFILE_IMPORTED);
|
||||
changedProfile.locationIcon = (ApplicationMode.LocationIcon) savedInstanceState.getSerializable(PROFILE_LOCATION_ICON_KEY);
|
||||
changedProfile.navigationIcon = (ApplicationMode.NavigationIcon) savedInstanceState.getSerializable(PROFILE_NAVIGATION_ICON_KEY);
|
||||
}
|
||||
|
@ -610,18 +610,21 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
if (parentProfileListener == null) {
|
||||
parentProfileListener = new SelectProfileBottomSheetDialogFragment.SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos, String stringRes) {
|
||||
updateParentProfile(pos);
|
||||
public void onSelectedType(Bundle args) {
|
||||
String profileKey = args.getString(PROFILE_KEY_ARG);
|
||||
boolean imported = args.getBoolean(IS_PROFILE_IMPORTED_ARG);
|
||||
updateParentProfile(profileKey, imported);
|
||||
}
|
||||
};
|
||||
}
|
||||
return parentProfileListener;
|
||||
}
|
||||
|
||||
void updateParentProfile(int pos) {
|
||||
String key = SettingsProfileFragment.getBaseProfiles(getMyApplication()).get(pos).getStringKey();
|
||||
setupBaseProfileView(key);
|
||||
changedProfile.parent = ApplicationMode.valueOfStringKey(key, ApplicationMode.DEFAULT);
|
||||
void updateParentProfile(String profileKey, boolean isBaseProfileImported) {
|
||||
deleteImportedProfile();
|
||||
setupBaseProfileView(profileKey);
|
||||
changedProfile.parent = ApplicationMode.valueOfStringKey(profileKey, ApplicationMode.DEFAULT);
|
||||
this.isBaseProfileImported = isBaseProfileImported;
|
||||
}
|
||||
|
||||
private void setupBaseProfileView(String stringKey) {
|
||||
|
@ -679,7 +682,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
changedProfile = profile;
|
||||
mapActivity.onBackPressed();
|
||||
goBackWithoutSaving();
|
||||
}
|
||||
});
|
||||
dismissDialog.show();
|
||||
|
@ -698,12 +701,27 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
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 {
|
||||
Fragment fragment = Fragment.instantiate(activity, screenType.fragmentName);
|
||||
Bundle args = new Bundle();
|
||||
if (appMode != null) {
|
||||
args.putString(BASE_PROFILE_FOR_NEW, appMode);
|
||||
args.putBoolean(IS_BASE_PROFILE_IMPORTED, imported);
|
||||
}
|
||||
fragment.setArguments(args);
|
||||
activity.getSupportFragmentManager().beginTransaction()
|
||||
|
|
Loading…
Reference in a new issue