2016-01-23 17:44:40 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
|
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
* are made available under the terms of the GNU Public License v3.0
|
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
|
* http://www.gnu.org/licenses/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package at.bitfire.davdroid.ui;
|
|
|
|
|
|
|
|
|
|
import android.accounts.Account;
|
2016-03-19 10:22:30 +00:00
|
|
|
|
import android.content.DialogInterface;
|
2016-01-23 17:44:40 +00:00
|
|
|
|
import android.content.Intent;
|
2016-04-06 19:04:16 +00:00
|
|
|
|
import android.net.wifi.WifiConfiguration;
|
|
|
|
|
import android.net.wifi.WifiInfo;
|
|
|
|
|
import android.net.wifi.WifiManager;
|
2016-01-23 17:44:40 +00:00
|
|
|
|
import android.os.Bundle;
|
2016-03-19 10:22:30 +00:00
|
|
|
|
import android.provider.CalendarContract;
|
|
|
|
|
import android.provider.ContactsContract;
|
2016-01-23 17:44:40 +00:00
|
|
|
|
import android.support.v4.app.NavUtils;
|
2016-03-19 10:22:30 +00:00
|
|
|
|
import android.support.v7.app.AlertDialog;
|
2016-01-23 17:44:40 +00:00
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2016-03-19 10:22:30 +00:00
|
|
|
|
import android.support.v7.preference.EditTextPreference;
|
|
|
|
|
import android.support.v7.preference.ListPreference;
|
|
|
|
|
import android.support.v7.preference.Preference;
|
|
|
|
|
import android.support.v7.preference.PreferenceFragmentCompat;
|
|
|
|
|
import android.support.v7.preference.SwitchPreferenceCompat;
|
2016-04-06 19:04:16 +00:00
|
|
|
|
import android.text.TextUtils;
|
2016-01-23 17:44:40 +00:00
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
|
2016-04-06 19:04:16 +00:00
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
2016-03-25 14:18:31 +00:00
|
|
|
|
import java.util.logging.Level;
|
|
|
|
|
|
2016-03-19 10:22:30 +00:00
|
|
|
|
import at.bitfire.davdroid.AccountSettings;
|
2016-03-25 14:18:31 +00:00
|
|
|
|
import at.bitfire.davdroid.App;
|
|
|
|
|
import at.bitfire.davdroid.InvalidAccountException;
|
2016-01-23 17:44:40 +00:00
|
|
|
|
import at.bitfire.davdroid.R;
|
2016-03-19 10:22:30 +00:00
|
|
|
|
import at.bitfire.ical4android.TaskProvider;
|
2016-01-23 17:44:40 +00:00
|
|
|
|
|
|
|
|
|
public class AccountSettingsActivity extends AppCompatActivity {
|
|
|
|
|
public final static String EXTRA_ACCOUNT = "account";
|
|
|
|
|
|
|
|
|
|
private Account account;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
account = getIntent().getParcelableExtra(EXTRA_ACCOUNT);
|
|
|
|
|
setTitle(getString(R.string.settings_title, account.name));
|
|
|
|
|
|
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState == null)
|
|
|
|
|
getSupportFragmentManager().beginTransaction()
|
2016-03-24 16:43:35 +00:00
|
|
|
|
.replace(android.R.id.content, AccountSettingsFragment.instantiate(this, AccountSettingsFragment.class.getName(), getIntent().getExtras()))
|
2016-01-23 17:44:40 +00:00
|
|
|
|
.commit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
if (item.getItemId() == android.R.id.home) {
|
|
|
|
|
Intent intent = new Intent(this, AccountActivity.class);
|
2016-02-24 11:29:07 +00:00
|
|
|
|
intent.putExtra(AccountActivity.EXTRA_ACCOUNT, account);
|
2016-01-23 17:44:40 +00:00
|
|
|
|
NavUtils.navigateUpTo(this, intent);
|
|
|
|
|
return true;
|
|
|
|
|
} else
|
2016-02-24 11:29:07 +00:00
|
|
|
|
return false;
|
2016-01-23 17:44:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-19 10:22:30 +00:00
|
|
|
|
|
|
|
|
|
public static class AccountSettingsFragment extends PreferenceFragmentCompat {
|
|
|
|
|
Account account;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
account = getArguments().getParcelable(EXTRA_ACCOUNT);
|
|
|
|
|
refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreatePreferences(Bundle bundle, String s) {
|
|
|
|
|
addPreferencesFromResource(R.xml.settings_account);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void refresh() {
|
2016-03-25 14:18:31 +00:00
|
|
|
|
final AccountSettings settings;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
settings = new AccountSettings(getActivity(), account);
|
|
|
|
|
} catch(InvalidAccountException e) {
|
|
|
|
|
App.log.log(Level.INFO, "Account is invalid or doesn't exist (anymore)", e);
|
|
|
|
|
getActivity().finish();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-03-19 10:22:30 +00:00
|
|
|
|
|
|
|
|
|
// category: authentication
|
|
|
|
|
final EditTextPreference prefUserName = (EditTextPreference)findPreference("username");
|
|
|
|
|
prefUserName.setSummary(settings.username());
|
|
|
|
|
prefUserName.setText(settings.username());
|
|
|
|
|
prefUserName.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
|
settings.username((String) newValue);
|
|
|
|
|
refresh(); return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final EditTextPreference prefPassword = (EditTextPreference)findPreference("password");
|
|
|
|
|
prefPassword.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
|
settings.password((String) newValue);
|
|
|
|
|
refresh(); return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final SwitchPreferenceCompat prefPreemptive = (SwitchPreferenceCompat)findPreference("preemptive");
|
|
|
|
|
prefPreemptive.setChecked(settings.preemptiveAuth());
|
|
|
|
|
prefPreemptive.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
|
settings.preemptiveAuth((Boolean) newValue);
|
|
|
|
|
refresh(); return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// category: synchronization
|
|
|
|
|
final ListPreference prefSyncContacts = (ListPreference)findPreference("sync_interval_contacts");
|
|
|
|
|
final Long syncIntervalContacts = settings.getSyncInterval(ContactsContract.AUTHORITY);
|
|
|
|
|
if (syncIntervalContacts != null) {
|
|
|
|
|
prefSyncContacts.setValue(syncIntervalContacts.toString());
|
|
|
|
|
if (syncIntervalContacts == AccountSettings.SYNC_INTERVAL_MANUALLY)
|
|
|
|
|
prefSyncContacts.setSummary(R.string.settings_sync_summary_manually);
|
|
|
|
|
else
|
|
|
|
|
prefSyncContacts.setSummary(getString(R.string.settings_sync_summary_periodically, syncIntervalContacts / 60));
|
|
|
|
|
prefSyncContacts.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
|
settings.setSyncInterval(ContactsContract.AUTHORITY, Long.parseLong((String) newValue));
|
|
|
|
|
refresh(); return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
prefSyncContacts.setEnabled(false);
|
|
|
|
|
prefSyncContacts.setSummary(R.string.settings_sync_summary_not_available);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final ListPreference prefSyncCalendars = (ListPreference)findPreference("sync_interval_calendars");
|
|
|
|
|
final Long syncIntervalCalendars = settings.getSyncInterval(CalendarContract.AUTHORITY);
|
|
|
|
|
if (syncIntervalCalendars != null) {
|
|
|
|
|
prefSyncCalendars.setValue(syncIntervalCalendars.toString());
|
|
|
|
|
if (syncIntervalCalendars == AccountSettings.SYNC_INTERVAL_MANUALLY)
|
|
|
|
|
prefSyncCalendars.setSummary(R.string.settings_sync_summary_manually);
|
|
|
|
|
else
|
|
|
|
|
prefSyncCalendars.setSummary(getString(R.string.settings_sync_summary_periodically, syncIntervalCalendars / 60));
|
|
|
|
|
prefSyncCalendars.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
|
settings.setSyncInterval(CalendarContract.AUTHORITY, Long.parseLong((String) newValue));
|
|
|
|
|
refresh(); return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
prefSyncCalendars.setEnabled(false);
|
|
|
|
|
prefSyncCalendars.setSummary(R.string.settings_sync_summary_not_available);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final ListPreference prefSyncTasks = (ListPreference)findPreference("sync_interval_tasks");
|
|
|
|
|
final Long syncIntervalTasks = settings.getSyncInterval(TaskProvider.ProviderName.OpenTasks.authority);
|
|
|
|
|
if (syncIntervalTasks != null) {
|
|
|
|
|
prefSyncTasks.setValue(syncIntervalTasks.toString());
|
|
|
|
|
if (syncIntervalTasks == AccountSettings.SYNC_INTERVAL_MANUALLY)
|
|
|
|
|
prefSyncTasks.setSummary(R.string.settings_sync_summary_manually);
|
|
|
|
|
else
|
|
|
|
|
prefSyncTasks.setSummary(getString(R.string.settings_sync_summary_periodically, syncIntervalTasks / 60));
|
|
|
|
|
prefSyncTasks.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
|
settings.setSyncInterval(TaskProvider.ProviderName.OpenTasks.authority, Long.parseLong((String) newValue));
|
|
|
|
|
refresh(); return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
prefSyncTasks.setEnabled(false);
|
|
|
|
|
prefSyncTasks.setSummary(R.string.settings_sync_summary_not_available);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-06 19:04:16 +00:00
|
|
|
|
final SwitchPreferenceCompat prefWifiOnly = (SwitchPreferenceCompat)findPreference("sync_wifi_only");
|
|
|
|
|
prefWifiOnly.setChecked(settings.getSyncWifiOnly());
|
|
|
|
|
prefWifiOnly.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object wifiOnly) {
|
|
|
|
|
settings.setSyncWiFiOnly((Boolean)wifiOnly);
|
|
|
|
|
refresh();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final EditTextPreference prefWifiOnlySSID = (EditTextPreference)findPreference("sync_wifi_only_ssid");
|
|
|
|
|
final String onlySSID = settings.getSyncWifiOnlySSID();
|
|
|
|
|
prefWifiOnlySSID.setText(onlySSID);
|
|
|
|
|
if (onlySSID != null)
|
|
|
|
|
prefWifiOnlySSID.setSummary(getString(R.string.settings_sync_wifi_only_ssid_on, onlySSID));
|
|
|
|
|
else
|
|
|
|
|
prefWifiOnlySSID.setSummary(R.string.settings_sync_wifi_only_ssid_off);
|
|
|
|
|
prefWifiOnlySSID.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
|
String ssid = (String)newValue;
|
|
|
|
|
settings.setSyncWifiOnlySSID(!TextUtils.isEmpty(ssid) ? ssid : null);
|
|
|
|
|
refresh(); return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// category: CalDAV
|
2016-03-20 16:41:05 +00:00
|
|
|
|
final EditTextPreference prefTimeRangePastDays = (EditTextPreference)findPreference("caldav_time_range_past_days");
|
2016-03-19 10:22:30 +00:00
|
|
|
|
Integer pastDays = settings.getTimeRangePastDays();
|
|
|
|
|
if (pastDays != null) {
|
2016-03-20 16:41:05 +00:00
|
|
|
|
prefTimeRangePastDays.setText(pastDays.toString());
|
2016-03-19 10:22:30 +00:00
|
|
|
|
prefTimeRangePastDays.setSummary(getResources().getQuantityString(R.plurals.settings_sync_time_range_past_days, pastDays, pastDays));
|
|
|
|
|
} else {
|
2016-03-20 16:41:05 +00:00
|
|
|
|
prefTimeRangePastDays.setText(null);
|
2016-03-19 10:22:30 +00:00
|
|
|
|
prefTimeRangePastDays.setSummary(R.string.settings_sync_time_range_past_none);
|
|
|
|
|
}
|
|
|
|
|
prefTimeRangePastDays.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
|
int days;
|
|
|
|
|
try {
|
|
|
|
|
days = Integer.parseInt((String)newValue);
|
|
|
|
|
} catch(NumberFormatException ignored) {
|
|
|
|
|
days = -1;
|
|
|
|
|
}
|
|
|
|
|
settings.setTimeRangePastDays(days < 0 ? null : days);
|
|
|
|
|
refresh(); return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-31 18:07:36 +00:00
|
|
|
|
final SwitchPreferenceCompat prefManageColors = (SwitchPreferenceCompat)findPreference("manage_calendar_colors");
|
|
|
|
|
prefManageColors.setChecked(settings.getManageCalendarColors());
|
|
|
|
|
prefManageColors.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
|
settings.setManageCalendarColors((Boolean)newValue);
|
2016-04-06 19:04:16 +00:00
|
|
|
|
refresh();
|
|
|
|
|
return false;
|
2016-03-31 18:07:36 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-19 10:22:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2016-01-23 17:44:40 +00:00
|
|
|
|
}
|