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