2016-01-19 20:50:58 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Christian Basler
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
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;
|
2016-01-14 16:41:10 +01:00
|
|
|
import android.content.Intent;
|
2015-12-21 15:31:48 +01:00
|
|
|
import android.content.SharedPreferences;
|
2015-08-05 19:48:41 +02:00
|
|
|
import android.os.Bundle;
|
2015-12-27 22:07:44 +01:00
|
|
|
import android.preference.Preference;
|
2015-08-05 19:48:41 +02:00
|
|
|
import android.preference.PreferenceFragment;
|
2015-12-21 15:31:48 +01:00
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
2015-12-27 22:07:44 +01:00
|
|
|
import com.mikepenz.aboutlibraries.Libs;
|
|
|
|
import com.mikepenz.aboutlibraries.LibsBuilder;
|
|
|
|
|
2015-12-21 15:31:48 +01:00
|
|
|
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-27 22:07:44 +01:00
|
|
|
|
|
|
|
Preference about = findPreference("about");
|
|
|
|
about.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
new LibsBuilder()
|
2016-01-01 15:35:16 +01:00
|
|
|
.withActivityTitle(getActivity().getString(R.string.about))
|
2015-12-27 22:07:44 +01:00
|
|
|
.withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
|
|
|
|
.withAboutIconShown(true)
|
|
|
|
.withAboutVersionShown(true)
|
|
|
|
.withAboutDescription(getString(R.string.about_app))
|
|
|
|
.start(getActivity());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2016-01-14 16:41:10 +01:00
|
|
|
|
|
|
|
Preference status = findPreference("status");
|
|
|
|
status.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
startActivity(new Intent(getActivity(), StatusActivity.class));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2015-08-05 19:48:41 +02:00
|
|
|
}
|
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
|
|
|
}
|