Copy mode preferences initial commit
This commit is contained in:
parent
d970918a19
commit
da12c5dbd5
4 changed files with 60 additions and 1 deletions
|
@ -71,6 +71,13 @@
|
|||
android:layout="@layout/preference_category_with_descr"
|
||||
android:title="@string/shared_string_actions" />
|
||||
|
||||
<Preference
|
||||
android:key="copy_from_other_profile"
|
||||
android:layout="@layout/preference_button"
|
||||
android:persistent="false"
|
||||
android:title="@string/copy_from_other_profile"
|
||||
tools:icon="@drawable/ic_action_copy" />
|
||||
|
||||
<Preference
|
||||
android:key="export_profile"
|
||||
android:layout="@layout/preference_button"
|
||||
|
|
|
@ -301,6 +301,17 @@ public class OsmandSettings {
|
|||
}
|
||||
}
|
||||
|
||||
public void copyPreferencesFromProfile(ApplicationMode modeFrom, ApplicationMode modeTo) {
|
||||
for (OsmandPreference pref : registeredPreferences.values()) {
|
||||
if (pref instanceof CommonPreference) {
|
||||
CommonPreference commonPreference = (CommonPreference) pref;
|
||||
if (!commonPreference.global) {
|
||||
commonPreference.copyFromMode(modeFrom, modeTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setPreference(String key, Object value) {
|
||||
return setPreference(key, value, APPLICATION_MODE.get());
|
||||
}
|
||||
|
@ -723,6 +734,23 @@ public class OsmandSettings {
|
|||
return settingsAPI.contains(getProfilePreferences(mode), getId());
|
||||
}
|
||||
|
||||
public boolean copyFromMode(ApplicationMode modeFrom, ApplicationMode modeTo) {
|
||||
if (global) {
|
||||
return false;
|
||||
}
|
||||
|
||||
T copiedValue = getModeValue(modeFrom);
|
||||
Object profilePrefs = getProfilePreferences(modeTo);
|
||||
|
||||
boolean valueSaved = setValue(profilePrefs, copiedValue);
|
||||
if (valueSaved && cache && cachedPreference == profilePrefs) {
|
||||
cachedValue = copiedValue;
|
||||
}
|
||||
fireEvent(copiedValue);
|
||||
|
||||
return valueSaved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeToJson(JSONObject json, ApplicationMode appMode) throws JSONException {
|
||||
if (appMode != null) {
|
||||
|
|
|
@ -32,8 +32,8 @@ import android.widget.Toast;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.aidl.OsmandAidlApi;
|
||||
import net.osmand.aidl.ConnectedApp;
|
||||
import net.osmand.aidl.OsmandAidlApi;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
|
@ -45,6 +45,7 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.activities.PluginActivity;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
|
||||
import net.osmand.plus.profiles.SelectAppModesBottomSheetDialogFragment;
|
||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||
import net.osmand.plus.skimapsplugin.SkiMapsPlugin;
|
||||
|
||||
|
@ -69,6 +70,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
private static final String SETTINGS_ACTIONS = "settings_actions";
|
||||
private static final String CONFIGURE_MAP = "configure_map";
|
||||
private static final String CONFIGURE_SCREEN = "configure_screen";
|
||||
private static final String COPY_FROM_OTHER_PROFILE = "copy_from_other_profile";
|
||||
private static final String EXPORT_PROFILE = "export_profile";
|
||||
private static final String DELETE_PROFILE = "delete_profile";
|
||||
private static final String PROFILE_APPEARANCE = "profile_appearance";
|
||||
|
@ -208,6 +210,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
PreferenceCategory settingsActions = (PreferenceCategory) findPreference(SETTINGS_ACTIONS);
|
||||
settingsActions.setIconSpaceReserved(false);
|
||||
|
||||
setupCopyFromOtherProfilePref();
|
||||
setupExportProfilePref();
|
||||
setupDeleteProfilePref();
|
||||
}
|
||||
|
@ -261,6 +264,12 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private void setupCopyFromOtherProfilePref() {
|
||||
Preference copyProfilePrefs = findPreference(COPY_FROM_OTHER_PROFILE);
|
||||
copyProfilePrefs.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_copy,
|
||||
isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
|
||||
}
|
||||
|
||||
private void setupExportProfilePref() {
|
||||
Preference exportProfile = findPreference(EXPORT_PROFILE);
|
||||
exportProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_app_configuration,
|
||||
|
@ -349,6 +358,11 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppModeChanged(ApplicationMode appMode) {
|
||||
settings.copyPreferencesFromProfile(appMode, getSelectedAppMode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
String prefId = preference.getKey();
|
||||
|
@ -373,6 +387,12 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
} else if (COPY_FROM_OTHER_PROFILE.equals(prefId)) {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
if (fragmentManager != null) {
|
||||
SelectAppModesBottomSheetDialogFragment.showInstance(fragmentManager,
|
||||
ConfigureProfileFragment.this, false, getSelectedAppMode(), false);
|
||||
}
|
||||
} else if (EXPORT_PROFILE.equals(prefId)) {
|
||||
Context ctx = requireContext();
|
||||
final ApplicationMode profile = getSelectedAppMode();
|
||||
|
|
|
@ -469,6 +469,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
.setRouteService(changedProfile.routeService)
|
||||
.setRoutingProfile(changedProfile.routingProfile)
|
||||
.setColor(changedProfile.color);
|
||||
|
||||
if (ApplicationMode.valueOfStringKey(changedProfile.stringKey, null) == null) {
|
||||
settings.copyPreferencesFromProfile(changedProfile.parent, getSelectedAppMode());
|
||||
}
|
||||
ApplicationMode mode = ApplicationMode.saveProfile(builder, getMyApplication());
|
||||
if (!ApplicationMode.values(app).contains(mode)) {
|
||||
ApplicationMode.changeProfileAvailability(mode, true, getMyApplication());
|
||||
|
|
Loading…
Reference in a new issue