mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 04:12:08 +01:00
Migrated SettingsActivity to using PreferenceFragment
This commit is contained in:
parent
48a7680930
commit
99349fc13a
1 changed files with 102 additions and 93 deletions
|
@ -27,8 +27,8 @@ import android.preference.EditTextPreference;
|
|||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
|
@ -36,14 +36,24 @@ import com.github.dfa.diaspora_android.R;
|
|||
/**
|
||||
* @author vanitas
|
||||
*/
|
||||
public class SettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private SharedPreferences sharedPreferences;
|
||||
private boolean activityRestartRequired = false;
|
||||
public class SettingsActivity extends PreferenceActivity {
|
||||
private boolean activityRestartRequired;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
|
||||
}
|
||||
|
||||
public void setActivityRestartRequired(boolean b) {
|
||||
this.activityRestartRequired = b;
|
||||
}
|
||||
|
||||
public static class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
public void onCreate(Bundle savedInstances) {
|
||||
super.onCreate(savedInstances);
|
||||
getPreferenceManager().setSharedPreferencesName("app");
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
sharedPreferences = getPreferenceScreen().getSharedPreferences();
|
||||
|
@ -65,10 +75,10 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
|||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
updatePreference(findPreference(key), key);
|
||||
updatePreference(findPreference(key));
|
||||
}
|
||||
|
||||
private void updatePreference(Preference preference, String key) {
|
||||
private void updatePreference(Preference preference) {
|
||||
if (preference == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -80,14 +90,13 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
|||
if (preference instanceof ListPreference) {
|
||||
ListPreference listPref = (ListPreference) preference;
|
||||
listPref.setSummary(listPref.getEntry());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
String podDomain = ((App) getApplication()).getSettings().getPodDomain();
|
||||
Intent intent = new Intent(getActivity(), MainActivity.class);
|
||||
String podDomain = ((App) getActivity().getApplication()).getSettings().getPodDomain();
|
||||
switch (preference.getTitleRes()) {
|
||||
case R.string.pref_title__personal_settings: {
|
||||
intent.setAction(MainActivity.ACTION_OPEN_URL);
|
||||
|
@ -105,17 +114,17 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
|||
break;
|
||||
}
|
||||
case R.string.pref_title__change_account: {
|
||||
new AlertDialog.Builder(SettingsActivity.this)
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(getString(R.string.confirmation))
|
||||
.setMessage(getString(R.string.pref_warning__change_account))
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.setPositiveButton(android.R.string.yes,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
Intent intent = new Intent(SettingsActivity.this, MainActivity.class);
|
||||
Intent intent = new Intent(getActivity(), MainActivity.class);
|
||||
intent.setAction(MainActivity.ACTION_CHANGE_ACCOUNT);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
getActivity().finish();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
|
@ -126,7 +135,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
|||
break;
|
||||
}
|
||||
case R.string.pref_title__intellihide_toolbars: {
|
||||
activityRestartRequired = true;
|
||||
((SettingsActivity) getActivity()).setActivityRestartRequired(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -135,23 +144,23 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
|||
break;
|
||||
}
|
||||
}
|
||||
if(preference.getKey() != null && preference.getKey().startsWith("pref_key__visibility_nav__")) {
|
||||
activityRestartRequired = true;
|
||||
if (preference.getKey() != null && preference.getKey().startsWith("pref_key__visibility_nav__")) {
|
||||
((SettingsActivity) getActivity()).setActivityRestartRequired(true);
|
||||
return true;
|
||||
}
|
||||
if (intent != null) {
|
||||
startActivity(intent);
|
||||
finish();
|
||||
getActivity().finish();
|
||||
return true;
|
||||
}
|
||||
return super.onPreferenceTreeClick(screen, preference);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
Log.d(App.TAG, "Settings onStop" + activityRestartRequired);
|
||||
super.onStop();
|
||||
if (activityRestartRequired){
|
||||
if (activityRestartRequired) {
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.setAction(MainActivity.ACTION_RELOAD_ACTIVITY);
|
||||
startActivity(intent);
|
||||
|
|
Loading…
Reference in a new issue