Fix plugins updates inside preference category
This commit is contained in:
parent
b1edd88daa
commit
f3e1195d98
2 changed files with 18 additions and 13 deletions
|
@ -26,6 +26,7 @@ import android.support.v7.preference.Preference;
|
|||
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceGroupAdapter;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
|
@ -299,19 +300,21 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
if (getSelectedAppMode() != null) {
|
||||
int resId = getPreferencesResId();
|
||||
if (resId != -1) {
|
||||
addPreferencesFromResource(getPreferencesResId());
|
||||
addPreferencesFromResource(resId);
|
||||
setupPreferences();
|
||||
registerPreferences();
|
||||
registerPreferences(getPreferenceScreen());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void registerPreferences() {
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
if (screen != null) {
|
||||
for (int i = 0; i < screen.getPreferenceCount(); i++) {
|
||||
Preference preference = screen.getPreference(i);
|
||||
private void registerPreferences(PreferenceGroup preferenceGroup) {
|
||||
if (preferenceGroup != null) {
|
||||
for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) {
|
||||
Preference preference = preferenceGroup.getPreference(i);
|
||||
registerPreference(preference);
|
||||
if (preference instanceof PreferenceGroup) {
|
||||
registerPreferences((PreferenceGroup) preference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
|
||||
public static final String TAG = "ConfigureProfileFragment";
|
||||
|
||||
private static final String PLUGIN_SETTINGS = "plugin_settings";
|
||||
|
||||
@Override
|
||||
protected int getPreferencesResId() {
|
||||
return R.xml.configure_profile;
|
||||
|
@ -111,7 +113,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
Preference pref = ((PreferenceGroupAdapter) getListView().getAdapter()).getItem(position);
|
||||
if (pref != null && pref.getParent() != null) {
|
||||
PreferenceGroup preferenceGroup = pref.getParent();
|
||||
return preferenceGroup.hasKey() && preferenceGroup.getKey().equals("plugin_settings");
|
||||
return preferenceGroup.hasKey() && preferenceGroup.getKey().equals(PLUGIN_SETTINGS);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -126,7 +128,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
setupNavigationSettingsPref();
|
||||
setupConfigureMapPref();
|
||||
|
||||
PreferenceCategory pluginSettings = (PreferenceCategory) findPreference("plugin_settings");
|
||||
PreferenceCategory pluginSettings = (PreferenceCategory) findPreference(PLUGIN_SETTINGS);
|
||||
pluginSettings.setIconSpaceReserved(false);
|
||||
|
||||
setupConnectedAppsPref(pluginSettings);
|
||||
|
@ -166,8 +168,8 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
SwitchPreference preference = new SwitchPreference(app);
|
||||
preference.setPersistent(false);
|
||||
preference.setKey(connectedApp.getPack());
|
||||
preference.setTitle(connectedApp.getName());
|
||||
preference.setIcon(connectedApp.getIcon());
|
||||
preference.setTitle(connectedApp.getName());
|
||||
preference.setChecked(connectedApp.isEnabled());
|
||||
preference.setLayoutResource(R.layout.preference_switch);
|
||||
|
||||
|
@ -186,10 +188,10 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
preference.setPersistent(false);
|
||||
preference.setKey(plugin.getId());
|
||||
preference.setTitle(plugin.getName());
|
||||
preference.setIcon(getPluginIcon(plugin));
|
||||
preference.setChecked(plugin.isActive());
|
||||
preference.setLayoutResource(R.layout.preference_dialog_and_switch);
|
||||
preference.setIcon(getPluginIcon(plugin));
|
||||
preference.setIntent(getPluginIntent(plugin));
|
||||
preference.setLayoutResource(R.layout.preference_dialog_and_switch);
|
||||
|
||||
preferenceCategory.addPreference(preference);
|
||||
}
|
||||
|
@ -221,7 +223,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
if (newValue instanceof Boolean) {
|
||||
if ((plugin.isActive() || !plugin.needsInstallation())) {
|
||||
if (OsmandPlugin.enablePlugin(getActivity(), app, plugin, (Boolean) newValue)) {
|
||||
updateAllSettings();
|
||||
preference.setIcon(getPluginIcon(plugin));
|
||||
return true;
|
||||
}
|
||||
} else if (plugin.needsInstallation() && preference.getIntent() != null) {
|
||||
|
|
Loading…
Reference in a new issue