2015-08-05 19:48:41 +02:00
|
|
|
package ch.dissem.apps.abit;
|
|
|
|
|
2015-12-21 15:31:48 +01:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
2015-08-05 19:48:41 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceFragment;
|
2015-12-21 15:31:48 +01:00
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
|
|
|
import ch.dissem.apps.abit.synchronization.SyncAdapter;
|
|
|
|
|
|
|
|
import static ch.dissem.apps.abit.util.Constants.PREFERENCE_SERVER_POW;
|
|
|
|
import static ch.dissem.apps.abit.util.Constants.PREFERENCE_TRUSTED_NODE;
|
2015-08-05 19:48:41 +02:00
|
|
|
|
|
|
|
/**
|
2015-12-21 15:31:48 +01:00
|
|
|
* @author Christian Basler
|
2015-08-05 19:48:41 +02:00
|
|
|
*/
|
2015-12-21 15:31:48 +01:00
|
|
|
public class SettingsFragment
|
|
|
|
extends PreferenceFragment
|
|
|
|
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
2015-08-05 19:48:41 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
// Load the preferences from an XML resource
|
|
|
|
addPreferencesFromResource(R.xml.preferences);
|
|
|
|
}
|
2015-12-21 15:31:48 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(Context ctx) {
|
|
|
|
super.onAttach(ctx);
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(ctx)
|
|
|
|
.registerOnSharedPreferenceChangeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
|
|
switch (key) {
|
|
|
|
case PREFERENCE_TRUSTED_NODE:
|
|
|
|
String node = sharedPreferences.getString(PREFERENCE_TRUSTED_NODE, null);
|
|
|
|
if (node != null) {
|
|
|
|
SyncAdapter.startSync(getActivity());
|
|
|
|
} else {
|
|
|
|
SyncAdapter.stopSync(getActivity());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PREFERENCE_SERVER_POW:
|
|
|
|
if (sharedPreferences.getBoolean(PREFERENCE_SERVER_POW, false)) {
|
|
|
|
SyncAdapter.startPowSync(getActivity());
|
|
|
|
} else {
|
|
|
|
SyncAdapter.stopPowSync(getActivity());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-05 19:48:41 +02:00
|
|
|
}
|