2016-07-29 14:00:28 +02:00
|
|
|
/*
|
|
|
|
This file is part of the Diaspora for Android.
|
|
|
|
|
|
|
|
Diaspora for Android is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Diaspora for Android is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with the Diaspora for Android.
|
|
|
|
|
|
|
|
If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-06-09 22:21:49 +02:00
|
|
|
package com.github.dfa.diaspora_android.activity;
|
|
|
|
|
2016-06-18 21:45:23 +02:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.DialogInterface;
|
2016-06-16 21:18:42 +02:00
|
|
|
import android.content.Intent;
|
2016-06-09 22:21:49 +02:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.EditTextPreference;
|
|
|
|
import android.preference.ListPreference;
|
|
|
|
import android.preference.Preference;
|
|
|
|
import android.preference.PreferenceActivity;
|
2016-06-18 15:53:49 +02:00
|
|
|
import android.preference.PreferenceScreen;
|
2016-06-09 22:21:49 +02:00
|
|
|
|
2016-06-11 00:28:26 +02:00
|
|
|
import com.github.dfa.diaspora_android.App;
|
2016-06-09 22:21:49 +02:00
|
|
|
import com.github.dfa.diaspora_android.R;
|
2016-06-11 00:28:26 +02:00
|
|
|
import com.github.dfa.diaspora_android.data.AppSettings;
|
2016-06-09 22:21:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author vanitas
|
|
|
|
*/
|
|
|
|
public class SettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
2016-06-16 21:18:42 +02:00
|
|
|
|
2016-06-18 15:53:49 +02:00
|
|
|
private SharedPreferences sharedPreferences;
|
2016-06-16 21:18:42 +02:00
|
|
|
|
2016-06-09 22:21:49 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2016-06-16 22:55:06 +02:00
|
|
|
getPreferenceManager().setSharedPreferencesName("app");
|
2016-06-09 22:21:49 +02:00
|
|
|
addPreferencesFromResource(R.xml.preferences);
|
2016-06-18 15:53:49 +02:00
|
|
|
sharedPreferences = getPreferenceScreen().getSharedPreferences();
|
|
|
|
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
2016-06-16 22:55:06 +02:00
|
|
|
setPreferenceSummaries();
|
2016-06-18 15:53:49 +02:00
|
|
|
sharedPreferences.edit().putBoolean(AppSettings.PREF.PROXY_WAS_ENABLED,
|
|
|
|
sharedPreferences.getBoolean(AppSettings.PREF.PROXY_ENABLED, false)).apply();
|
2016-06-11 00:28:26 +02:00
|
|
|
}
|
|
|
|
|
2016-06-16 22:55:06 +02:00
|
|
|
private void setPreferenceSummaries() {
|
2016-06-16 23:36:52 +02:00
|
|
|
String[] editTextKeys = new String[]{AppSettings.PREF.PROXY_HOST, AppSettings.PREF.PROXY_PORT};
|
2016-06-16 22:55:06 +02:00
|
|
|
for(String key : editTextKeys) {
|
2016-06-11 00:28:26 +02:00
|
|
|
EditTextPreference p = (EditTextPreference) findPreference(key);
|
|
|
|
p.setSummary(p.getText());
|
|
|
|
}
|
2016-06-09 22:21:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
|
|
updatePreference(findPreference(key), key);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updatePreference(Preference preference, String key) {
|
|
|
|
if (preference == null) return;
|
|
|
|
if (preference instanceof EditTextPreference) {
|
|
|
|
EditTextPreference textPref = (EditTextPreference) preference;
|
|
|
|
textPref.setSummary(textPref.getText());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(preference instanceof ListPreference) {
|
|
|
|
ListPreference listPref = (ListPreference) preference;
|
|
|
|
listPref.setSummary(listPref.getEntry());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-06-18 15:53:49 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
2016-07-26 22:47:11 +02:00
|
|
|
Intent intent = new Intent(this, MainActivity.class);
|
2016-06-18 15:53:49 +02:00
|
|
|
String podDomain = ((App)getApplication()).getSettings().getPodDomain();
|
|
|
|
switch(preference.getKey()) {
|
|
|
|
case "pref_key_personal_settings":
|
2016-07-26 22:47:11 +02:00
|
|
|
intent.setAction(MainActivity.ACTION_OPEN_URL);
|
|
|
|
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/user/edit");
|
|
|
|
break;
|
2016-06-18 15:53:49 +02:00
|
|
|
case "pref_key_manage_tags":
|
2016-07-26 22:47:11 +02:00
|
|
|
intent.setAction(MainActivity.ACTION_OPEN_URL);
|
|
|
|
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/tag_followings/manage");
|
|
|
|
break;
|
2016-06-18 15:53:49 +02:00
|
|
|
case "pref_key_manage_contacts":
|
2016-07-26 22:47:11 +02:00
|
|
|
intent.setAction(MainActivity.ACTION_OPEN_URL);
|
|
|
|
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/contacts");
|
|
|
|
break;
|
2016-06-20 10:51:20 +02:00
|
|
|
case "pref_key_change_account":
|
2016-06-18 21:45:23 +02:00
|
|
|
new AlertDialog.Builder(SettingsActivity.this)
|
|
|
|
.setTitle(getString(R.string.confirmation))
|
2016-06-20 10:51:20 +02:00
|
|
|
.setMessage(getString(R.string.pref_warning_change_account))
|
2016-06-18 21:45:23 +02:00
|
|
|
.setNegativeButton(android.R.string.no, null)
|
|
|
|
.setPositiveButton(android.R.string.yes,
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
2016-07-26 22:47:11 +02:00
|
|
|
Intent intent = new Intent(SettingsActivity.this, MainActivity.class);
|
|
|
|
intent.setAction(MainActivity.ACTION_CHANGE_ACCOUNT);
|
|
|
|
startActivity(intent);
|
2016-06-18 21:45:23 +02:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
2016-07-26 22:47:11 +02:00
|
|
|
return true;
|
2016-07-26 22:52:26 +02:00
|
|
|
case "pref_key_clear_cache":
|
|
|
|
intent.setAction(MainActivity.ACTION_CLEAR_CACHE);
|
|
|
|
break;
|
2016-07-26 22:47:11 +02:00
|
|
|
default:
|
|
|
|
intent = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(intent != null) {
|
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
|
|
|
return true;
|
2016-06-18 15:53:49 +02:00
|
|
|
}
|
|
|
|
return super.onPreferenceTreeClick(screen, preference);
|
|
|
|
}
|
2016-07-29 14:00:28 +02:00
|
|
|
}
|