diff --git a/app/src/androidTest/java/at/bitfire/davdroid/HttpClientTest.java b/app/src/androidTest/java/at/bitfire/davdroid/HttpClientTest.java index d7d07eb4..b1138ac0 100644 --- a/app/src/androidTest/java/at/bitfire/davdroid/HttpClientTest.java +++ b/app/src/androidTest/java/at/bitfire/davdroid/HttpClientTest.java @@ -26,7 +26,7 @@ public class HttpClientTest extends InstrumentationTestCase { @Override public void setUp() throws IOException { - httpClient = HttpClient.create(getInstrumentation().getTargetContext().getApplicationContext()); + httpClient = HttpClient.create(getInstrumentation().getTargetContext().getApplicationContext(), null); server = new MockWebServer(); server.start(); diff --git a/app/src/androidTest/java/at/bitfire/davdroid/resource/DavResourceFinderTest.java b/app/src/androidTest/java/at/bitfire/davdroid/resource/DavResourceFinderTest.java index 30a0dfbc..752c3e06 100644 --- a/app/src/androidTest/java/at/bitfire/davdroid/resource/DavResourceFinderTest.java +++ b/app/src/androidTest/java/at/bitfire/davdroid/resource/DavResourceFinderTest.java @@ -3,12 +3,12 @@ package at.bitfire.davdroid.resource; import android.test.InstrumentationTestCase; import java.io.IOException; +import java.net.URI; import at.bitfire.dav4android.exception.DavException; import at.bitfire.dav4android.exception.HttpException; -import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.ui.setup.DavResourceFinder; -import at.bitfire.davdroid.ui.setup.LoginCredentialsFragment; +import at.bitfire.davdroid.ui.setup.LoginCredentials; import okhttp3.HttpUrl; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; @@ -30,7 +30,7 @@ public class DavResourceFinderTest extends InstrumentationTestCase { public void testGetCurrentUserPrincipal() throws IOException, HttpException, DavException { HttpUrl url = server.url("/dav"); - LoginCredentialsFragment.LoginCredentials credentials = new LoginCredentialsFragment.LoginCredentials(url.uri(), "admin", "12345", true); + LoginCredentials credentials = new LoginCredentials(url.uri(), "admin", "12345", true); DavResourceFinder finder = new DavResourceFinder(getInstrumentation().getTargetContext().getApplicationContext(), credentials); // positive test case @@ -51,8 +51,8 @@ public class DavResourceFinderTest extends InstrumentationTestCase { server.enqueue(new MockResponse() // OPTIONS response .setResponseCode(200) .setHeader("DAV", "addressbook")); - HttpUrl principal = finder.getCurrentUserPrincipal(url, DavResourceFinder.Service.CARDDAV); - assertEquals(url.resolve("/principals/myself"), principal); + URI principal = finder.getCurrentUserPrincipal(url, DavResourceFinder.Service.CARDDAV); + assertEquals(url.resolve("/principals/myself").uri(), principal); // negative test case: no current-user-principal server.enqueue(new MockResponse() diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index aed7d5b3..0564b78b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -43,6 +43,7 @@ enabledCiphers = preferredCiphers; enabledCiphers.addAll(new HashSet<>(Arrays.asList(socket.getEnabledCipherSuites()))); - Constants.log.debug("Enabling (only) those TLS ciphers: " + TextUtils.join(", ", enabledCiphers)); + Constants.log.info("Enabling (only) those TLS ciphers: " + TextUtils.join(", ", enabledCiphers)); SSLSocketFactoryCompat.cipherSuites = enabledCiphers.toArray(new String[enabledCiphers.size()]); } } @@ -112,15 +111,11 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory { } private void upgradeTLS(SSLSocket ssl) { - if (protocols != null) { - Constants.log.trace("Setting allowed TLS protocols: " + TextUtils.join(", ", protocols)); + if (protocols != null) ssl.setEnabledProtocols(protocols); - } - if (Build.VERSION.SDK_INT < 20 && cipherSuites != null) { - Constants.log.trace("Setting allowed TLS ciphers: " + TextUtils.join(", ", cipherSuites)); + if (cipherSuites != null) ssl.setEnabledCipherSuites(cipherSuites); - } } diff --git a/app/src/main/java/at/bitfire/davdroid/log/CustomLogger.java b/app/src/main/java/at/bitfire/davdroid/log/CustomLogger.java index 86c58897..c64e812e 100644 --- a/app/src/main/java/at/bitfire/davdroid/log/CustomLogger.java +++ b/app/src/main/java/at/bitfire/davdroid/log/CustomLogger.java @@ -34,7 +34,6 @@ public abstract class CustomLogger implements Logger { protected String name; protected PrintWriter writer; - protected boolean verbose; // CUSTOM LOGGING METHODS @@ -69,36 +68,32 @@ public abstract class CustomLogger implements Logger { @Override public boolean isTraceEnabled() { - return verbose; + return true; } @Override public void trace(String msg) { - if (verbose) - log(PREFIX_TRACE, msg); + log(PREFIX_TRACE, msg); } @Override public void trace(String format, Object arg) { - if (verbose) - log(PREFIX_TRACE, format, arg); + log(PREFIX_TRACE, format, arg); } @Override public void trace(String format, Object arg1, Object arg2) { - if (verbose) log(PREFIX_TRACE, format, arg1, arg2); + log(PREFIX_TRACE, format, arg1, arg2); } @Override public void trace(String format, Object... arguments) { - if (verbose) - log(PREFIX_TRACE, format, arguments); + log(PREFIX_TRACE, format, arguments); } @Override public void trace(String msg, Throwable t) { - if (verbose) - log(PREFIX_TRACE, msg, t); + log(PREFIX_TRACE, msg, t); } diff --git a/app/src/main/java/at/bitfire/davdroid/log/ExternalFileLogger.java b/app/src/main/java/at/bitfire/davdroid/log/ExternalFileLogger.java index fd99c787..469e91c1 100644 --- a/app/src/main/java/at/bitfire/davdroid/log/ExternalFileLogger.java +++ b/app/src/main/java/at/bitfire/davdroid/log/ExternalFileLogger.java @@ -19,9 +19,7 @@ import java.io.PrintWriter; public class ExternalFileLogger extends CustomLogger implements Closeable { - public ExternalFileLogger(Context context, String fileName, boolean verbose) throws IOException { - this.verbose = verbose; - + public ExternalFileLogger(Context context, String fileName) throws IOException { File dir = getDirectory(context); if (dir == null) throw new IOException("External media not available for log creation"); diff --git a/app/src/main/java/at/bitfire/davdroid/log/LogcatHandler.java b/app/src/main/java/at/bitfire/davdroid/log/LogcatHandler.java new file mode 100644 index 00000000..8d5bbb1c --- /dev/null +++ b/app/src/main/java/at/bitfire/davdroid/log/LogcatHandler.java @@ -0,0 +1,67 @@ +/* + * 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.log; + +import android.util.Log; + +import java.util.logging.Formatter; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; + +public class LogcatHandler extends Handler { + private static final String TAG = "davdroid"; + + public static final LogcatHandler INSTANCE = new LogcatHandler(); + + private LogcatHandler() { + super(); + setFormatter(AdbFormatter.INSTANCE); + setLevel(Level.ALL); + } + + @Override + public void publish(LogRecord record) { + String line = getFormatter().format(record); + int level = record.getLevel().intValue(); + + if (level >= Level.SEVERE.intValue()) + Log.e(TAG, line); + else if (level >= Level.WARNING.intValue()) + Log.w(TAG, line); + else if (level >= Level.CONFIG.intValue()) + Log.i(TAG, line); + else if (level >= Level.FINER.intValue()) + Log.d(TAG, line); + else + Log.v(TAG, line); + } + + @Override + public void flush() { + } + + @Override + public void close() { + } + + + private static class AdbFormatter extends Formatter { + public static AdbFormatter INSTANCE = new AdbFormatter(); + + private AdbFormatter() { + } + + @Override + public String format(LogRecord r) { + return String.format("[%s] %s", r.getSourceClassName(), r.getMessage()); + } + } + +} diff --git a/app/src/main/java/at/bitfire/davdroid/log/StringLogger.java b/app/src/main/java/at/bitfire/davdroid/log/StringLogger.java index 46ea3aca..21fd1820 100644 --- a/app/src/main/java/at/bitfire/davdroid/log/StringLogger.java +++ b/app/src/main/java/at/bitfire/davdroid/log/StringLogger.java @@ -14,16 +14,12 @@ import java.io.StringWriter; import lombok.Getter; public class StringLogger extends CustomLogger { - @Getter protected final String name; protected final StringWriter stringWriter = new StringWriter(); - - public StringLogger(String name, boolean verbose) { + public StringLogger(String name) { this.name = name; - this.verbose = verbose; - writer = new PrintWriter(stringWriter); } @@ -31,5 +27,4 @@ public class StringLogger extends CustomLogger { return stringWriter.toString(); } - } diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java index 3124b59d..b1d038b4 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java @@ -290,7 +290,7 @@ public class ContactsSyncManager extends SyncManager { return null; } - OkHttpClient resourceClient = HttpClient.create(context); + OkHttpClient resourceClient = HttpClient.create(context, null); // authenticate only against a certain host, and only upon request resourceClient = HttpClient.addAuthentication(resourceClient, baseUrl.host(), settings.username(), settings.password()); diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java index fa065daf..467c69f0 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java @@ -39,6 +39,7 @@ package at.bitfire.davdroid.syncadapter; import at.bitfire.dav4android.exception.UnauthorizedException; import at.bitfire.dav4android.property.GetCTag; import at.bitfire.dav4android.property.GetETag; + import at.bitfire.davdroid.AccountSettings; import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.HttpClient; import at.bitfire.davdroid.R; @@ -107,21 +108,11 @@ abstract public class SyncManager { this.authority = authority; this.syncResult = syncResult; - // get account settings and log to file (if requested) + // get account settings (for sync interval etc.) settings = new AccountSettings(context, account); - try { - if (settings.logToExternalFile()) - log = new ExternalFileLogger(context, "davdroid-SyncManager-" + account.name + "-" + authority + ".txt", settings.logVerbose()); - } catch(IOException e) { - Constants.log.error("Couldn't log to external file", e); - } - if (log == null) - log = Constants.log; // create HttpClient with given logger - httpClient = HttpClient.create(context); - httpClient = HttpClient.addLogger(httpClient, log); - httpClient = HttpClient.addAuthentication(httpClient, settings.username(), settings.password(), settings.preemptiveAuth()); + httpClient = HttpClient.create(context, account); // dismiss previous error notifications notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); diff --git a/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsFragment.java index cce97f5d..47db334b 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsFragment.java @@ -19,7 +19,7 @@ import android.support.v7.preference.PreferenceFragmentCompat; import android.support.v7.preference.SwitchPreferenceCompat; import at.bitfire.davdroid.R; -import at.bitfire.davdroid.syncadapter.AccountSettings; +import at.bitfire.davdroid.AccountSettings; import at.bitfire.ical4android.TaskProvider; public class AccountSettingsFragment extends PreferenceFragmentCompat { diff --git a/app/src/main/java/at/bitfire/davdroid/ui/AccountsActivity.java b/app/src/main/java/at/bitfire/davdroid/ui/AccountsActivity.java index bc885a99..1503bede 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/AccountsActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/AccountsActivity.java @@ -20,6 +20,7 @@ import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; +import at.bitfire.davdroid.App; import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.R; import at.bitfire.davdroid.ui.setup.LoginActivity; diff --git a/app/src/main/java/at/bitfire/davdroid/ui/CreateAddressBookActivity.java b/app/src/main/java/at/bitfire/davdroid/ui/CreateAddressBookActivity.java index 31bf372e..4015cbcd 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/CreateAddressBookActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/CreateAddressBookActivity.java @@ -50,7 +50,6 @@ import at.bitfire.davdroid.model.CollectionInfo; import at.bitfire.davdroid.model.Service; import at.bitfire.davdroid.model.HomeSet; import at.bitfire.davdroid.model.ServiceDB; -import at.bitfire.davdroid.syncadapter.AccountSettings; import lombok.Cleanup; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; @@ -195,8 +194,7 @@ public class CreateAddressBookActivity extends AppCompatActivity implements Load @Override public Exception loadInBackground() { - OkHttpClient client = HttpClient.create(getContext()); - client = HttpClient.addAuthentication(client, new AccountSettings(getContext(), account)); + OkHttpClient client = HttpClient.create(getContext(), account); StringWriter writer = new StringWriter(); try { diff --git a/app/src/main/java/at/bitfire/davdroid/ui/CreateCollectionFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/CreateCollectionFragment.java index 1365fb5c..079d9bf9 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/CreateCollectionFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/CreateCollectionFragment.java @@ -16,7 +16,6 @@ import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; -import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; @@ -39,7 +38,6 @@ import at.bitfire.davdroid.HttpClient; import at.bitfire.davdroid.R; import at.bitfire.davdroid.model.CollectionInfo; import at.bitfire.davdroid.model.ServiceDB; -import at.bitfire.davdroid.syncadapter.AccountSettings; import lombok.Cleanup; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; @@ -126,11 +124,6 @@ public class CreateCollectionFragment extends DialogFragment implements LoaderMa @Override public Exception loadInBackground() { - Constants.log.info("MKCOl !!!!"); - - OkHttpClient client = HttpClient.create(getContext()); - client = HttpClient.addAuthentication(client, new AccountSettings(getContext(), account)); - StringWriter writer = new StringWriter(); try { XmlSerializer serializer = XmlUtils.newSerializer(); @@ -212,6 +205,8 @@ public class CreateCollectionFragment extends DialogFragment implements LoaderMa } ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(getContext()); + + OkHttpClient client = HttpClient.create(getContext(), account); DavResource collection = new DavResource(null, client, HttpUrl.parse(info.url)); try { // create collection on remote server diff --git a/app/src/main/java/at/bitfire/davdroid/ui/DebugInfoActivity.java b/app/src/main/java/at/bitfire/davdroid/ui/DebugInfoActivity.java index 5d19e318..e2c83c73 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/DebugInfoActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/DebugInfoActivity.java @@ -24,6 +24,7 @@ import android.provider.CalendarContract; import android.provider.ContactsContract; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; @@ -40,7 +41,7 @@ import at.bitfire.dav4android.exception.HttpException; import at.bitfire.davdroid.BuildConfig; import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.R; -import at.bitfire.davdroid.syncadapter.AccountSettings; +import at.bitfire.davdroid.AccountSettings; public class DebugInfoActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks { public static final String @@ -173,8 +174,7 @@ public class DebugInfoActivity extends AppCompatActivity implements LoaderManage if (exception != null) { report.append("\nSTACK TRACE:\n"); - for (String stackTrace : ExceptionUtils.getRootCauseStackTrace(exception)) - report.append(stackTrace + "\n"); + report.append(Log.getStackTraceString(exception)); report.append("\n"); } diff --git a/app/src/main/java/at/bitfire/davdroid/ui/DeleteCollectionFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/DeleteCollectionFragment.java index 3b6eec27..82b340bd 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/DeleteCollectionFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/DeleteCollectionFragment.java @@ -32,7 +32,6 @@ import at.bitfire.davdroid.HttpClient; import at.bitfire.davdroid.R; import at.bitfire.davdroid.model.CollectionInfo; import at.bitfire.davdroid.model.ServiceDB; -import at.bitfire.davdroid.syncadapter.AccountSettings; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; @@ -109,8 +108,7 @@ public class DeleteCollectionFragment extends DialogFragment implements LoaderMa @Override public Exception loadInBackground() { - OkHttpClient httpClient = HttpClient.create(getContext()); - httpClient = HttpClient.addAuthentication(httpClient, new AccountSettings(getContext(), account)); + OkHttpClient httpClient = HttpClient.create(getContext(), account); DavResource collection = new DavResource(null, httpClient, HttpUrl.parse(collectionInfo.url)); try { diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.java index bcc48fc0..c9c51e09 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/AccountDetailsFragment.java @@ -35,7 +35,7 @@ import at.bitfire.davdroid.model.ServiceDB.Collections; import at.bitfire.davdroid.model.ServiceDB.HomeSets; import at.bitfire.davdroid.model.ServiceDB.OpenHelper; import at.bitfire.davdroid.model.ServiceDB.Services; -import at.bitfire.davdroid.syncadapter.AccountSettings; +import at.bitfire.davdroid.AccountSettings; import at.bitfire.ical4android.TaskProvider; import lombok.Cleanup; diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java index 7ac0bc8b..d6f4bfff 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java @@ -8,7 +8,7 @@ package at.bitfire.davdroid.ui.setup; import android.content.Context; -import android.text.TextUtils; +import android.support.annotation.NonNull; import org.slf4j.Logger; import org.xbill.DNS.Lookup; @@ -46,7 +46,6 @@ import at.bitfire.dav4android.property.SupportedCalendarComponentSet; import at.bitfire.davdroid.HttpClient; import at.bitfire.davdroid.log.StringLogger; import at.bitfire.davdroid.model.CollectionInfo; -import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.ToString; import okhttp3.HttpUrl; @@ -60,21 +59,21 @@ public class DavResourceFinder { final String name; Service(String name) { this.name = name;} @Override public String toString() { return name; } - }; + } protected final Context context; - protected final LoginCredentialsFragment.LoginCredentials credentials; + protected final LoginCredentials credentials; - protected final Logger log = new StringLogger("DavResourceFinder", true); + protected final Logger log = new StringLogger("DavResourceFinder"); protected OkHttpClient httpClient; - public DavResourceFinder(@NonNull Context context, @NonNull LoginCredentialsFragment.LoginCredentials credentials) { + public DavResourceFinder(@NonNull Context context, @NonNull LoginCredentials credentials) { this.context = context; this.credentials = credentials; - httpClient = HttpClient.create(context); - httpClient = HttpClient.addLogger(httpClient, log); + httpClient = HttpClient.create(context, null); httpClient = HttpClient.addAuthentication(httpClient, credentials.userName, credentials.password, credentials.authPreemptive); + //httpClient = HttpClient.addLogger(httpClient, log); } diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.java index 5c039b96..95b4c27e 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.java @@ -14,6 +14,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v4.app.LoaderManager; import android.support.v4.content.AsyncTaskLoader; @@ -31,9 +32,17 @@ import at.bitfire.davdroid.ui.DebugInfoActivity; import lombok.Cleanup; public class DetectConfigurationFragment extends DialogFragment implements LoaderManager.LoaderCallbacks { + protected static final String ARG_LOGIN_CREDENTIALS = "credentials"; - static final String ARG_LOGIN_CREDENTIALS = "credentials"; + public static DetectConfigurationFragment newInstance(LoginCredentials credentials) { + DetectConfigurationFragment frag = new DetectConfigurationFragment(); + Bundle args = new Bundle(1); + args.putParcelable(ARG_LOGIN_CREDENTIALS, credentials); + frag.setArguments(args); + return frag; + } + @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { ProgressDialog dialog = new ProgressDialog(getActivity()); @@ -55,7 +64,7 @@ public class DetectConfigurationFragment extends DialogFragment implements Loade @Override public Loader onCreateLoader(int id, Bundle args) { - return new ServerConfigurationLoader(getContext(), args); + return new ServerConfigurationLoader(getContext(), (LoginCredentials)args.getParcelable(ARG_LOGIN_CREDENTIALS)); } @Override @@ -117,12 +126,12 @@ public class DetectConfigurationFragment extends DialogFragment implements Loade static class ServerConfigurationLoader extends AsyncTaskLoader { final Context context; - final LoginCredentialsFragment.LoginCredentials credentials; + final LoginCredentials credentials; - public ServerConfigurationLoader(Context context, Bundle args) { + public ServerConfigurationLoader(Context context, LoginCredentials credentials) { super(context); this.context = context; - credentials = (LoginCredentialsFragment.LoginCredentials)args.getParcelable(ARG_LOGIN_CREDENTIALS); + this.credentials = credentials; } @Override diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginCredentials.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginCredentials.java new file mode 100644 index 00000000..d1edd32a --- /dev/null +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginCredentials.java @@ -0,0 +1,53 @@ +/* + * 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.setup; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.net.URI; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class LoginCredentials implements Parcelable { + public final URI uri; + public final String userName, password; + public final boolean authPreemptive; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeSerializable(uri); + dest.writeString(userName); + dest.writeString(password); + dest.writeValue(authPreemptive); + } + + public static final Creator CREATOR = new Creator() { + @Override + public LoginCredentials createFromParcel(Parcel source) { + LoginCredentials credentials = new LoginCredentials( + (URI)source.readSerializable(), + source.readString(), source.readString(), + (boolean)source.readValue(null) + ); + return credentials; + } + + @Override + public LoginCredentials[] newArray(int size) { + return new LoginCredentials[size]; + } + }; +} diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginCredentialsFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginCredentialsFragment.java index 609eb758..768bb4a4 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginCredentialsFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/LoginCredentialsFragment.java @@ -10,9 +10,6 @@ package at.bitfire.davdroid.ui.setup; import android.net.Uri; import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; -import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v7.widget.AppCompatCheckBox; import android.support.v7.widget.AppCompatRadioButton; @@ -30,7 +27,6 @@ import java.net.URISyntaxException; import at.bitfire.davdroid.R; import at.bitfire.davdroid.ui.widget.EditPassword; -import lombok.RequiredArgsConstructor; public class LoginCredentialsFragment extends Fragment implements CompoundButton.OnCheckedChangeListener { @@ -73,15 +69,8 @@ public class LoginCredentialsFragment extends Fragment implements CompoundButton @Override public void onClick(View v) { LoginCredentials credentials = validateLoginData(); - if (credentials != null) { - // login data OK, continue with DetectConfigurationFragment - Bundle args = new Bundle(1); - args.putParcelable(DetectConfigurationFragment.ARG_LOGIN_CREDENTIALS, credentials); - - DialogFragment dialog = new DetectConfigurationFragment(); - dialog.setArguments(args); - dialog.show(getFragmentManager(), DetectConfigurationFragment.class.getName()); - } + if (credentials != null) + DetectConfigurationFragment.newInstance(credentials).show(getFragmentManager(), null); } }); @@ -126,20 +115,17 @@ public class LoginCredentialsFragment extends Fragment implements CompoundButton URI uri = null; boolean valid = true; - String host = null, path = null; - int port = -1; - Uri baseUrl = Uri.parse(editBaseURL.getText().toString()); String scheme = baseUrl.getScheme(); if ("https".equalsIgnoreCase(scheme) || "http".equalsIgnoreCase(scheme)) { - host = IDN.toASCII(baseUrl.getHost()); + String host = IDN.toASCII(baseUrl.getHost()); if (host.isEmpty()) { editBaseURL.setError(getString(R.string.login_url_host_name_required)); valid = false; } - path = baseUrl.getEncodedPath(); - port = baseUrl.getPort(); + String path = baseUrl.getEncodedPath(); + int port = baseUrl.getPort(); try { uri = new URI(baseUrl.getScheme(), null, host, port, path, null, null); } catch (URISyntaxException e) { @@ -169,42 +155,4 @@ public class LoginCredentialsFragment extends Fragment implements CompoundButton return null; } - - @RequiredArgsConstructor - public static class LoginCredentials implements Parcelable { - public final URI uri; - public final String userName, password; - public final boolean authPreemptive; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeSerializable(uri); - dest.writeString(userName); - dest.writeString(password); - dest.writeInt(authPreemptive ? 1 : 0); - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public LoginCredentials createFromParcel(Parcel source) { - LoginCredentials credentials = new LoginCredentials( - (URI)source.readSerializable(), - source.readString(), source.readString(), - source.readInt() != 0 ? true : false - ); - return null; - } - - @Override - public LoginCredentials[] newArray(int size) { - return new LoginCredentials[0]; - } - }; - } - }