Fix #7235 add confirm changes dialog
This commit is contained in:
parent
c5c5ccd2ed
commit
26f205bbee
3 changed files with 115 additions and 26 deletions
|
@ -354,10 +354,14 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
|
|||
if (profileSettings) {
|
||||
modes.clear();
|
||||
findViewById(R.id.selector_shadow).setVisibility(View.VISIBLE);
|
||||
for (ApplicationMode a : ApplicationMode.values(app)) {
|
||||
if (a != ApplicationMode.DEFAULT) {
|
||||
modes.add(a);
|
||||
if (this instanceof SettingsNavigationActivity) {
|
||||
for (ApplicationMode a : ApplicationMode.values(app)) {
|
||||
if (a != ApplicationMode.DEFAULT) {
|
||||
modes.add(a);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
modes.addAll(ApplicationMode.values(app));
|
||||
}
|
||||
|
||||
getTypeButton().setVisibility(View.VISIBLE);
|
||||
|
@ -378,18 +382,16 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
|
|||
|
||||
final List<ProfileDataObject> activeModes = new ArrayList<>();
|
||||
for (ApplicationMode am : ApplicationMode.values(getMyApplication())) {
|
||||
boolean isSelected = false;
|
||||
if (am == selectedAppMode) {
|
||||
isSelected = true;
|
||||
}
|
||||
if (am != ApplicationMode.DEFAULT) {
|
||||
boolean isSelected = am == selectedAppMode;
|
||||
|
||||
if (am != ApplicationMode.DEFAULT || !(this instanceof SettingsNavigationActivity)) {
|
||||
activeModes.add(new ProfileDataObject(
|
||||
am.toHumanString(getMyApplication()),
|
||||
getAppModeDescription(am),
|
||||
am.getStringKey(),
|
||||
am.getIconRes(),
|
||||
isSelected,
|
||||
am.getIconColorInfo()
|
||||
am.toHumanString(getMyApplication()),
|
||||
getAppModeDescription(am),
|
||||
am.getStringKey(),
|
||||
am.getIconRes(),
|
||||
isSelected,
|
||||
am.getIconColorInfo()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -586,6 +588,10 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
|
|||
return true;
|
||||
}
|
||||
|
||||
protected Map<String, Map<String, ?>> getListPrefValues() {
|
||||
return listPrefValues;
|
||||
}
|
||||
|
||||
protected OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getApplication();
|
||||
}
|
||||
|
|
|
@ -1,24 +1,43 @@
|
|||
package net.osmand.plus.monitoring;
|
||||
|
||||
|
||||
import net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.activities.SettingsBaseActivity;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.activities.SettingsBaseActivity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static net.osmand.plus.OsmandSettings.DAILY_DIRECTORY;
|
||||
import static net.osmand.plus.OsmandSettings.MONTHLY_DIRECTORY;
|
||||
import static net.osmand.plus.OsmandSettings.REC_DIRECTORY;
|
||||
import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
|
||||
|
||||
|
||||
public class SettingsMonitoringActivity extends SettingsBaseActivity {
|
||||
|
@ -47,8 +66,15 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
|
|||
createLoggingSection(grp);
|
||||
createLiveSection(grp);
|
||||
createNotificationSection(grp);
|
||||
selectAppModeDialog().show();
|
||||
}
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent != null && intent.hasExtra(PROFILE_STRING_KEY)) {
|
||||
String modeName = intent.getStringExtra(PROFILE_STRING_KEY);
|
||||
selectedAppMode = ApplicationMode.valueOfStringKey(modeName, ApplicationMode.CAR);
|
||||
} else {
|
||||
selectAppModeDialog().show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void createLoggingSection(PreferenceScreen grp) {
|
||||
|
@ -198,7 +224,62 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String prefId = preference.getKey();
|
||||
if (preference instanceof ListPreference) {
|
||||
int ind = ((ListPreference) preference).findIndexOfValue((String) newValue);
|
||||
CharSequence entry = ((ListPreference) preference).getEntries()[ind];
|
||||
Map<String, ?> map = getListPrefValues().get(prefId);
|
||||
if (map != null) {
|
||||
newValue = map.get(entry);
|
||||
}
|
||||
}
|
||||
showConfirmDialog(prefId, newValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void showConfirmDialog(final String prefId, final Object newValue) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.change_default_settings);
|
||||
|
||||
String appModeName = selectedAppMode.toHumanString(this);
|
||||
String currentModeText = getString(R.string.apply_to_current_profile, appModeName);
|
||||
int start = currentModeText.indexOf(appModeName);
|
||||
|
||||
SpannableString[] strings = new SpannableString[2];
|
||||
strings[0] = new SpannableString(getString(R.string.apply_to_all_profiles));
|
||||
strings[1] = new SpannableString(currentModeText);
|
||||
strings[1].setSpan(new StyleSpan(Typeface.BOLD), start, start + appModeName.length(), 0);
|
||||
|
||||
final LayoutInflater themedInflater = UiUtilities.getInflater(this, !settings.isLightContent());
|
||||
final ArrayAdapter<SpannableString> singleChoiceAdapter = new ArrayAdapter<SpannableString>(this, R.layout.simple_list_menu_item, R.id.title, strings) {
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
|
||||
View v = convertView;
|
||||
if (v == null) {
|
||||
v = themedInflater.inflate(R.layout.simple_list_menu_item, parent, false);
|
||||
}
|
||||
TextView title = (TextView) v.findViewById(R.id.title);
|
||||
title.setText(getItem(position));
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
builder.setAdapter(singleChoiceAdapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == 0) {
|
||||
settings.setSharedGeneralPreference(prefId, newValue);
|
||||
} else {
|
||||
settings.setPreference(prefId, newValue);
|
||||
}
|
||||
updateAllSettings();
|
||||
}
|
||||
});
|
||||
|
||||
builder.setNegativeButton(R.string.discard_changes, null);
|
||||
builder.show();
|
||||
}
|
||||
}
|
|
@ -45,6 +45,7 @@ import static net.osmand.plus.profiles.EditProfileFragment.MAP_CONFIG;
|
|||
import static net.osmand.plus.profiles.EditProfileFragment.OPEN_CONFIG_ON_MAP;
|
||||
import static net.osmand.plus.profiles.EditProfileFragment.SCREEN_CONFIG;
|
||||
import static net.osmand.plus.profiles.EditProfileFragment.SELECTED_ITEM;
|
||||
import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
|
||||
|
||||
public class ConfigureProfileFragment extends BaseSettingsFragment {
|
||||
|
||||
|
@ -245,6 +246,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
final Class<? extends Activity> settingsActivity = plugin.getSettingsActivity();
|
||||
if (settingsActivity != null && !plugin.needsInstallation()) {
|
||||
intent = new Intent(getContext(), settingsActivity);
|
||||
intent.putExtra(PROFILE_STRING_KEY, getSelectedAppMode().getStringKey());
|
||||
} else {
|
||||
intent = new Intent(getContext(), PluginActivity.class);
|
||||
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId());
|
||||
|
|
Loading…
Reference in a new issue