diff --git a/build.gradle b/build.gradle index 495c503..f49197b 100644 --- a/build.gradle +++ b/build.gradle @@ -1 +1,18 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.0.0' + classpath files('libs/gradle-witness.jar') + } +} + +allprojects { + repositories { + mavenCentral() + + maven { url 'https://raw.github.com/whispersystems/maven/master/stripe-btc/releases' } + maven { url 'https://raw.github.com/whispersystems/maven/master/gson/releases/' } + } +} diff --git a/flock/build.gradle b/flock/build.gradle index c5ad61a..dade6b4 100644 --- a/flock/build.gradle +++ b/flock/build.gradle @@ -1,30 +1,22 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' - classpath files('libs/gradle-witness.jar') - } -} - apply plugin: 'com.android.application' apply plugin: 'witness' -repositories { - mavenCentral() - - maven { url 'https://raw.github.com/whispersystems/maven/master/stripe-btc/releases' } - maven { url 'https://raw.github.com/whispersystems/maven/master/gson/releases/' } -} - android { + compileSdkVersion 21 buildToolsVersion '21.1.2' defaultConfig { + applicationId "org.anhonesteffort.flock" + versionCode 25 + versionName "0.9.3" minSdkVersion 16 - targetSdkVersion 19 + targetSdkVersion 21 + } + + productFlavors { + play { } + nonplay { } } packagingOptions { @@ -42,13 +34,14 @@ android { } } +repositories { + mavenLocal() +} + dependencies { - compile group: 'com.google.guava', name: 'guava', version: '16.0' - compile group: 'com.android.support', name: 'support-v4', version: '19.0.1' + compile group: 'com.android.support', name: 'support-v4', version: '21.0.3' compile group: 'org.apache.jackrabbit', name: 'jackrabbit-webdav', version: '2.3.7' compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1' - compile group: 'javax.servlet', name: 'servlet-api', version: '2.5' - compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.5' compile group: 'com.googlecode.ez-vcard', name: 'ez-vcard', version: '0.9.0' compile group: 'org.mnode.ical4j', name: 'ical4j', version: '1.0.5.2' compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.3.0' @@ -62,22 +55,26 @@ dependencies { androidTestCompile group: 'com.squareup', name: 'fest-android', version: '1.0.8' androidTestCompile group: 'com.google.dexmaker', name: 'dexmaker', version: '1.1' androidTestCompile group: 'com.google.dexmaker', name: 'dexmaker-mockito', version: '1.1' + + nonplayCompile (group: 'org.whispersystems.supplychain', name:'libsupplychain', version:'1.0') { + exclude group: 'com.android.support', module: 'support-v4' + } } dependencyVerification { verify = [ - 'com.google.guava:guava:fa917f4f3f6a76375134ba89a40d3a1ce807945a91bbdbe39c31f76e03030868', - 'com.android.support:support-v4:a4268abd6370c3fd3f94d2a7f9e6e755f5ddd62450cf8bbc62ba789e1274d585', + 'com.android.support:support-v4:703572d3015a088cc5604b7e38885af3d307c829d0c5ceaf8654ff41c71cd160', 'org.apache.jackrabbit:jackrabbit-webdav:9a11e030921bc21de7d6dcf168571a3d2671f72c351498a0daefaf79e0edc888', 'commons-httpclient:commons-httpclient:dbd4953d013e10e7c1cc3701a3e6ccd8c950c892f08d804fabfac21705930443', - 'javax.servlet:servlet-api:c658ea360a70faeeadb66fb3c90a702e4142a0ab7768f9ae9828678e0d9ad4dc', - 'org.slf4j:slf4j-simple:6d06eedca4768119b2c6ac5adf97e7b5ad57a03d6578d69e734fa083c957dc06', 'com.googlecode.ez-vcard:ez-vcard:2e09cc227f8f269be5fbdc17b999b9514e239281754a0b4d4c221e29ba2d0876', 'org.mnode.ical4j:ical4j:dedb09e8975f0703b3ae5ad60205fedda7512f91d837070be99732001a08b138', 'com.fasterxml.jackson.core:jackson-databind:9b789c2de23ff5a1ae1fc8193ea79e34f16d74c64c51491fbe76ca277349e694', 'com.google.code.gson:gson:c0328cd07ca9e363a5acd00c1cf4afe8cf554bd6d373834981ba05cebec687fb', 'com.stripe:stripe-java-btc:daaabd181eb6bc4868d739e023226d344a56bf6020a7ad057dc0c26fc7d223da', 'com.google.zxing:core:f00b32f7a1b0edc914a8f74301e8dc34f189afc4698e9c8cc54e5d46772734a5', + 'org.whispersystems:libpastelog:3ccf00fe1597eb8ca1e5de99b17fc225387a1b80b5bbc00ec1bc4d4f3ea9cdde', + 'com.android.support:support-annotations:fdee2354787ef66b268e75958de3f7f6c4f8f325510a6dac9f49c929f83a63de', + 'org.slf4j:slf4j-api:367b909030f714ee1176ab096b681e06348f03385e98d1bce0ed801b5452357e', 'org.slf4j:jcl-over-slf4j:261e66d2b5d95ce1bc9923ab5e614f58b2568787b2b55f74dbb861b60ff798e0', 'org.jsoup:jsoup:37e3b44fb9476a677a956fb684090b9b4a1e4d38bcfc30b499dbc83f109422c0', 'org.freemarker:freemarker:c26923394f3f1cf0427f515ee3bb6be66d1a7f4261e6d6f0504fdec63ab85da8', @@ -86,9 +83,7 @@ dependencyVerification { 'commons-lang:commons-lang:50f11b09f877c294d56f24463f47d28f929cf5044f648661c0f0cfbae9a2f49c', 'backport-util-concurrent:backport-util-concurrent:f5759b7fcdfc83a525a036deedcbd32e5b536b625ebc282426f16ca137eb5902', 'com.fasterxml.jackson.core:jackson-annotations:0c8c3811322cc84c09a93f34436fe784a1259dd5376a90aec5a73493456f757d', - 'org.slf4j:slf4j-api:fe30825245d2336c859dc38d60c0fc5f3668dbf29cd586828d2b5667ec355b91', - 'com.fasterxml.jackson.core:jackson-core:61f84f93e3f901134d7498b50119ee01074f10d59560e45ccd3e1d48cfec493b', - 'org.whispersystems:libpastelog:3ccf00fe1597eb8ca1e5de99b17fc225387a1b80b5bbc00ec1bc4d4f3ea9cdde' + 'com.fasterxml.jackson.core:jackson-core:61f84f93e3f901134d7498b50119ee01074f10d59560e45ccd3e1d48cfec493b' ] } diff --git a/flock/src/androidTest/java/org/anhonesteffort/flock/test/auth/DavAccountTest.java b/flock/src/androidTest/java/org/anhonesteffort/flock/test/auth/DavAccountTest.java index 268f5a1..e5fc28a 100644 --- a/flock/src/androidTest/java/org/anhonesteffort/flock/test/auth/DavAccountTest.java +++ b/flock/src/androidTest/java/org/anhonesteffort/flock/test/auth/DavAccountTest.java @@ -19,7 +19,7 @@ import android.test.AndroidTestCase; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; diff --git a/flock/src/androidTest/java/org/anhonesteffort/flock/test/crypto/KeyHelperTest.java b/flock/src/androidTest/java/org/anhonesteffort/flock/test/crypto/KeyHelperTest.java index b841a37..2228f34 100644 --- a/flock/src/androidTest/java/org/anhonesteffort/flock/test/crypto/KeyHelperTest.java +++ b/flock/src/androidTest/java/org/anhonesteffort/flock/test/crypto/KeyHelperTest.java @@ -20,7 +20,7 @@ import android.content.Context; import android.test.AndroidTestCase; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.crypto.KeyHelper; import org.anhonesteffort.flock.crypto.KeyStore; diff --git a/flock/src/main/AndroidManifest.xml b/flock/src/main/AndroidManifest.xml index 9efa1bd..1d43a6c 100644 --- a/flock/src/main/AndroidManifest.xml +++ b/flock/src/main/AndroidManifest.xml @@ -1,12 +1,6 @@ - - + package="org.anhonesteffort.flock" > diff --git a/flock/src/main/java/org/anhonesteffort/flock/AbstractDavCollectionArrayAdapter.java b/flock/src/main/java/org/anhonesteffort/flock/AbstractDavCollectionArrayAdapter.java index a84f7d5..8c84a3f 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/AbstractDavCollectionArrayAdapter.java +++ b/flock/src/main/java/org/anhonesteffort/flock/AbstractDavCollectionArrayAdapter.java @@ -28,7 +28,7 @@ import android.widget.CompoundButton; import android.widget.TextView; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.crypto.InvalidMacException; import org.anhonesteffort.flock.sync.HidingDavCollection; import org.anhonesteffort.flock.sync.LocalComponentStore; diff --git a/flock/src/main/java/org/anhonesteffort/flock/AbstractMyCollectionsFragment.java b/flock/src/main/java/org/anhonesteffort/flock/AbstractMyCollectionsFragment.java index a87e72d..3183860 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/AbstractMyCollectionsFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/AbstractMyCollectionsFragment.java @@ -35,7 +35,7 @@ import android.widget.ListView; import android.widget.TextView; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import java.util.LinkedList; import java.util.List; diff --git a/flock/src/main/java/org/anhonesteffort/flock/AccountAndKeyRequiredActivity.java b/flock/src/main/java/org/anhonesteffort/flock/AccountAndKeyRequiredActivity.java index e3e7628..0ec8233 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/AccountAndKeyRequiredActivity.java +++ b/flock/src/main/java/org/anhonesteffort/flock/AccountAndKeyRequiredActivity.java @@ -25,7 +25,7 @@ import android.util.Log; import android.widget.Toast; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.crypto.KeyHelper; import org.anhonesteffort.flock.crypto.MasterCipher; diff --git a/flock/src/main/java/org/anhonesteffort/flock/AccountContactDetailsListAdapter.java b/flock/src/main/java/org/anhonesteffort/flock/AccountContactDetailsListAdapter.java index 8573913..49df46e 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/AccountContactDetailsListAdapter.java +++ b/flock/src/main/java/org/anhonesteffort/flock/AccountContactDetailsListAdapter.java @@ -29,7 +29,7 @@ import android.widget.CompoundButton; import android.widget.TextView; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import java.util.List; diff --git a/flock/src/main/java/org/anhonesteffort/flock/ChangeEncryptionPasswordActivity.java b/flock/src/main/java/org/anhonesteffort/flock/ChangeEncryptionPasswordActivity.java index a62b4c0..1e284d9 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/ChangeEncryptionPasswordActivity.java +++ b/flock/src/main/java/org/anhonesteffort/flock/ChangeEncryptionPasswordActivity.java @@ -34,7 +34,7 @@ import android.widget.TextView; import android.widget.Toast; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.crypto.KeyStore; import org.anhonesteffort.flock.sync.key.KeySyncScheduler; import org.anhonesteffort.flock.util.PasswordUtil; diff --git a/flock/src/main/java/org/anhonesteffort/flock/ChangeEncryptionPasswordService.java b/flock/src/main/java/org/anhonesteffort/flock/ChangeEncryptionPasswordService.java index a995906..00147a0 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/ChangeEncryptionPasswordService.java +++ b/flock/src/main/java/org/anhonesteffort/flock/ChangeEncryptionPasswordService.java @@ -15,8 +15,7 @@ import android.support.v4.app.NotificationCompat; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.crypto.KeyHelper; import org.anhonesteffort.flock.crypto.KeyStore; diff --git a/flock/src/main/java/org/anhonesteffort/flock/CorrectPasswordActivity.java b/flock/src/main/java/org/anhonesteffort/flock/CorrectPasswordActivity.java index 9a95c43..33efae2 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/CorrectPasswordActivity.java +++ b/flock/src/main/java/org/anhonesteffort/flock/CorrectPasswordActivity.java @@ -33,7 +33,7 @@ import android.widget.TextView; import android.widget.Toast; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.sync.addressbook.AddressbookSyncScheduler; import org.anhonesteffort.flock.sync.calendar.CalendarsSyncScheduler; diff --git a/flock/src/main/java/org/anhonesteffort/flock/CorrectPasswordService.java b/flock/src/main/java/org/anhonesteffort/flock/CorrectPasswordService.java index f11fc26..44c9ad1 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/CorrectPasswordService.java +++ b/flock/src/main/java/org/anhonesteffort/flock/CorrectPasswordService.java @@ -15,8 +15,7 @@ import android.support.v4.app.NotificationCompat; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.crypto.KeyHelper; import org.anhonesteffort.flock.crypto.KeyStore; diff --git a/flock/src/main/java/org/anhonesteffort/flock/DavAccountHelper.java b/flock/src/main/java/org/anhonesteffort/flock/DavAccountHelper.java index 6c12087..868f987 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/DavAccountHelper.java +++ b/flock/src/main/java/org/anhonesteffort/flock/DavAccountHelper.java @@ -24,7 +24,7 @@ import android.content.Context; import android.content.SharedPreferences; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.crypto.MasterCipher; import org.anhonesteffort.flock.sync.AndroidDavClient; @@ -33,10 +33,10 @@ import org.anhonesteffort.flock.sync.calendar.HidingCalDavStore; import org.anhonesteffort.flock.sync.key.DavKeyStore; import org.anhonesteffort.flock.webdav.PropertyParseException; +import org.anhonesteffort.flock.webdav.WebDavConstants; import org.anhonesteffort.flock.webdav.caldav.CalDavStore; import org.anhonesteffort.flock.webdav.carddav.CardDavStore; import org.apache.jackrabbit.webdav.DavException; -import org.apache.jackrabbit.webdav.DavServletResponse; import java.io.IOException; import java.net.MalformedURLException; @@ -244,7 +244,7 @@ public static boolean isAuthenticated(Context context, DavAccount account) if (e.getErrorCode() == OwsWebDav.STATUS_PAYMENT_REQUIRED) return true; - else if (e.getErrorCode() == DavServletResponse.SC_UNAUTHORIZED) + else if (e.getErrorCode() == WebDavConstants.SC_UNAUTHORIZED) return false; else throw e; diff --git a/flock/src/main/java/org/anhonesteffort/flock/DeleteAllContactsActivity.java b/flock/src/main/java/org/anhonesteffort/flock/DeleteAllContactsActivity.java index b5a34e5..e43ce33 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/DeleteAllContactsActivity.java +++ b/flock/src/main/java/org/anhonesteffort/flock/DeleteAllContactsActivity.java @@ -33,10 +33,8 @@ import android.widget.TextView; import android.widget.Toast; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.crypto.KeyStore; -import org.anhonesteffort.flock.sync.addressbook.AddressbookSyncScheduler; import org.anhonesteffort.flock.sync.addressbook.LocalAddressbookStore; import org.anhonesteffort.flock.sync.addressbook.LocalContactCollection; diff --git a/flock/src/main/java/org/anhonesteffort/flock/ErrorToaster.java b/flock/src/main/java/org/anhonesteffort/flock/ErrorToaster.java index a6889bc..d0298ee 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/ErrorToaster.java +++ b/flock/src/main/java/org/anhonesteffort/flock/ErrorToaster.java @@ -38,8 +38,8 @@ import org.anhonesteffort.flock.sync.OwsWebDav; import org.anhonesteffort.flock.webdav.InvalidComponentException; import org.anhonesteffort.flock.webdav.PropertyParseException; +import org.anhonesteffort.flock.webdav.WebDavConstants; import org.apache.jackrabbit.webdav.DavException; -import org.apache.jackrabbit.webdav.DavServletResponse; import java.io.IOException; import java.net.SocketException; @@ -110,7 +110,7 @@ else if (e instanceof RegistrationApiException) else if (e instanceof DavException) { DavException ex = (DavException) e; - if (ex.getErrorCode() == DavServletResponse.SC_UNAUTHORIZED) + if (ex.getErrorCode() == WebDavConstants.SC_UNAUTHORIZED) bundle.putInt(KEY_STATUS_CODE, CODE_UNAUTHORIZED); else if (ex.getErrorCode() == OwsWebDav.STATUS_PAYMENT_REQUIRED) bundle.putInt(KEY_STATUS_CODE, CODE_SUBSCRIPTION_EXPIRED); diff --git a/flock/src/main/java/org/anhonesteffort/flock/ImportAccountService.java b/flock/src/main/java/org/anhonesteffort/flock/ImportAccountService.java index 505721b..1febc0f 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/ImportAccountService.java +++ b/flock/src/main/java/org/anhonesteffort/flock/ImportAccountService.java @@ -5,14 +5,12 @@ import android.os.Bundle; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.AccountAuthenticator; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.crypto.InvalidMacException; import org.anhonesteffort.flock.crypto.KeyHelper; import org.anhonesteffort.flock.crypto.KeyStore; -import org.anhonesteffort.flock.sync.OwsWebDav; import org.anhonesteffort.flock.sync.key.DavKeyCollection; import org.anhonesteffort.flock.sync.key.DavKeyStore; import org.anhonesteffort.flock.sync.key.KeySyncScheduler; diff --git a/flock/src/main/java/org/anhonesteffort/flock/ImportCalendarsFragment.java b/flock/src/main/java/org/anhonesteffort/flock/ImportCalendarsFragment.java index e59c73d..32198bb 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/ImportCalendarsFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/ImportCalendarsFragment.java @@ -41,8 +41,8 @@ import android.widget.Toast; import com.chiralcode.colorpicker.ColorPicker; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.calendar.LocalCalendarStore; import org.anhonesteffort.flock.sync.calendar.LocalEventCollection; diff --git a/flock/src/main/java/org/anhonesteffort/flock/ImportOtherAccountFragment.java b/flock/src/main/java/org/anhonesteffort/flock/ImportOtherAccountFragment.java index d9646e3..260b1da 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/ImportOtherAccountFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/ImportOtherAccountFragment.java @@ -36,7 +36,7 @@ import android.widget.ProgressBar; import android.widget.TextView; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.util.PasswordUtil; import org.apache.commons.lang.StringUtils; diff --git a/flock/src/main/java/org/anhonesteffort/flock/ImportOwsAccountFragment.java b/flock/src/main/java/org/anhonesteffort/flock/ImportOwsAccountFragment.java index ea72f88..08bb5c4 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/ImportOwsAccountFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/ImportOwsAccountFragment.java @@ -33,7 +33,7 @@ import android.widget.TextView; import android.widget.Toast; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.apache.commons.lang.StringUtils; diff --git a/flock/src/main/java/org/anhonesteffort/flock/ImportOwsAccountService.java b/flock/src/main/java/org/anhonesteffort/flock/ImportOwsAccountService.java index a9df75a..4f98a80 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/ImportOwsAccountService.java +++ b/flock/src/main/java/org/anhonesteffort/flock/ImportOwsAccountService.java @@ -14,8 +14,7 @@ import android.support.v4.app.NotificationCompat; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.crypto.InvalidMacException; import org.anhonesteffort.flock.crypto.KeyHelper; diff --git a/flock/src/main/java/org/anhonesteffort/flock/IntroductionFragment.java b/flock/src/main/java/org/anhonesteffort/flock/IntroductionFragment.java index 1308207..03e1204 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/IntroductionFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/IntroductionFragment.java @@ -22,9 +22,12 @@ import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.text.Html; +import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; /** * Programmer: rhodey @@ -49,7 +52,9 @@ public View onCreateView(LayoutInflater inflater, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_intro, container, false); + initButtons(); + initDescription(view); return view; } @@ -64,4 +69,11 @@ public void onClick(View v) { }); } + + private void initDescription(View fragmentView) { + final TextView appDescription = (TextView) fragmentView.findViewById(R.id.flock_description); + + appDescription.setText(Html.fromHtml(getString(R.string.flock_syncs_your_contacts_and_calendars_between_multiple_devices))); + appDescription.setMovementMethod(LinkMovementMethod.getInstance()); + } } diff --git a/flock/src/main/java/org/anhonesteffort/flock/LocalCalendarListAdapter.java b/flock/src/main/java/org/anhonesteffort/flock/LocalCalendarListAdapter.java index 61c176b..c3fc905 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/LocalCalendarListAdapter.java +++ b/flock/src/main/java/org/anhonesteffort/flock/LocalCalendarListAdapter.java @@ -31,7 +31,7 @@ import android.widget.CompoundButton; import android.widget.TextView; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.calendar.LocalEventCollection; import java.util.List; diff --git a/flock/src/main/java/org/anhonesteffort/flock/ManageSubscriptionActivity.java b/flock/src/main/java/org/anhonesteffort/flock/ManageSubscriptionActivity.java index f46b8a0..7a63321 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/ManageSubscriptionActivity.java +++ b/flock/src/main/java/org/anhonesteffort/flock/ManageSubscriptionActivity.java @@ -35,8 +35,8 @@ import android.view.Window; import com.android.vending.billing.IInAppBillingService; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.registration.model.SubscriptionPlan; import org.anhonesteffort.flock.sync.account.AccountStore; diff --git a/flock/src/main/java/org/anhonesteffort/flock/MigrationHelperBroadcastReceiver.java b/flock/src/main/java/org/anhonesteffort/flock/MigrationHelperBroadcastReceiver.java index 88eed49..bec2078 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/MigrationHelperBroadcastReceiver.java +++ b/flock/src/main/java/org/anhonesteffort/flock/MigrationHelperBroadcastReceiver.java @@ -27,8 +27,7 @@ import android.preference.PreferenceManager; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.account.AccountSyncScheduler; import org.anhonesteffort.flock.sync.addressbook.AddressbookSyncScheduler; import org.anhonesteffort.flock.sync.addressbook.AddressbookSyncWorker; diff --git a/flock/src/main/java/org/anhonesteffort/flock/MigrationService.java b/flock/src/main/java/org/anhonesteffort/flock/MigrationService.java index debe2a0..860038c 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/MigrationService.java +++ b/flock/src/main/java/org/anhonesteffort/flock/MigrationService.java @@ -35,8 +35,7 @@ import android.support.v4.app.NotificationCompat; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.crypto.KeyHelper; import org.anhonesteffort.flock.crypto.KeyStore; @@ -56,6 +55,7 @@ import org.anhonesteffort.flock.sync.key.DavKeyStore; import org.anhonesteffort.flock.webdav.InvalidComponentException; import org.anhonesteffort.flock.webdav.PropertyParseException; +import org.anhonesteffort.flock.webdav.WebDavConstants; import org.anhonesteffort.flock.webdav.caldav.CalDavStore; import org.anhonesteffort.flock.webdav.carddav.CardDavStore; import org.apache.jackrabbit.webdav.DavException; @@ -426,7 +426,7 @@ private void handleCreateKeyCollection() { handleException(e); } catch (DavException e) { - if (e.getErrorCode() == DavServletResponse.SC_FORBIDDEN) { + if (e.getErrorCode() == WebDavConstants.SC_FORBIDDEN) { Log.w(TAG, "caught 403 when trying to create key collection, assuming already exists."); setState(STATE_REPLACED_KEY_COLLECTION); } @@ -569,7 +569,7 @@ else if (displayName.isPresent()) { handleException(e); } catch (DavException e) { - if (e.getErrorCode() != DavServletResponse.SC_FORBIDDEN) + if (e.getErrorCode() != WebDavConstants.SC_FORBIDDEN) handleException(e); } catch (GeneralSecurityException e) { @@ -612,7 +612,7 @@ private void handleReplaceRemoteAddressbooks() { } catch (DavException e) { - if (e.getErrorCode() != DavServletResponse.SC_FORBIDDEN) + if (e.getErrorCode() != WebDavConstants.SC_FORBIDDEN) handleException(e); } catch (GeneralSecurityException e) { diff --git a/flock/src/main/java/org/anhonesteffort/flock/MyAddressbooksFragment.java b/flock/src/main/java/org/anhonesteffort/flock/MyAddressbooksFragment.java index d136412..bd833c7 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/MyAddressbooksFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/MyAddressbooksFragment.java @@ -36,7 +36,7 @@ import android.widget.ListView; import android.widget.Toast; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.crypto.InvalidMacException; import org.anhonesteffort.flock.sync.addressbook.AddressbookSyncScheduler; import org.anhonesteffort.flock.sync.addressbook.HidingCardDavCollection; diff --git a/flock/src/main/java/org/anhonesteffort/flock/MyCalendarsFragment.java b/flock/src/main/java/org/anhonesteffort/flock/MyCalendarsFragment.java index ee815a9..25505d3 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/MyCalendarsFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/MyCalendarsFragment.java @@ -40,7 +40,7 @@ import android.widget.Toast; import com.chiralcode.colorpicker.ColorPicker; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.calendar.CalendarsSyncScheduler; import org.anhonesteffort.flock.sync.calendar.HidingCalDavCollection; import org.anhonesteffort.flock.sync.calendar.HidingCalDavStore; diff --git a/flock/src/main/java/org/anhonesteffort/flock/NotificationDrawer.java b/flock/src/main/java/org/anhonesteffort/flock/NotificationDrawer.java index 50aa156..432da46 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/NotificationDrawer.java +++ b/flock/src/main/java/org/anhonesteffort/flock/NotificationDrawer.java @@ -27,8 +27,7 @@ import android.support.v4.app.NotificationCompat; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.sync.addressbook.AddressbookSyncScheduler; import org.anhonesteffort.flock.sync.calendar.CalendarsSyncScheduler; diff --git a/flock/src/main/java/org/anhonesteffort/flock/PreferencesActivity.java b/flock/src/main/java/org/anhonesteffort/flock/PreferencesActivity.java index e1bacc3..45ccdf2 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/PreferencesActivity.java +++ b/flock/src/main/java/org/anhonesteffort/flock/PreferencesActivity.java @@ -33,8 +33,8 @@ import android.widget.Toast; import com.chiralcode.colorpicker.ColorPickerPreference; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.sync.account.AccountSyncScheduler; import org.anhonesteffort.flock.sync.addressbook.AddressbookSyncScheduler; diff --git a/flock/src/main/java/org/anhonesteffort/flock/RegisterAccountFragment.java b/flock/src/main/java/org/anhonesteffort/flock/RegisterAccountFragment.java index 85b8456..4a9b3a0 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/RegisterAccountFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/RegisterAccountFragment.java @@ -35,8 +35,7 @@ import android.widget.ProgressBar; import android.widget.TextView; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.util.PasswordUtil; import org.apache.commons.lang.StringUtils; diff --git a/flock/src/main/java/org/anhonesteffort/flock/RemoteCalendarListAdapter.java b/flock/src/main/java/org/anhonesteffort/flock/RemoteCalendarListAdapter.java index 3272770..08ea282 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/RemoteCalendarListAdapter.java +++ b/flock/src/main/java/org/anhonesteffort/flock/RemoteCalendarListAdapter.java @@ -24,7 +24,7 @@ import android.view.View; import android.widget.CompoundButton; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.crypto.InvalidMacException; import org.anhonesteffort.flock.sync.calendar.CalendarsSyncScheduler; import org.anhonesteffort.flock.sync.calendar.HidingCalDavCollection; diff --git a/flock/src/main/java/org/anhonesteffort/flock/SelectServiceProviderFragment.java b/flock/src/main/java/org/anhonesteffort/flock/SelectServiceProviderFragment.java index b6cec4f..4983fb5 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/SelectServiceProviderFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/SelectServiceProviderFragment.java @@ -136,11 +136,9 @@ public void onClick(View view) { if (!radioButtonOws.isChecked()) { radioButtonOws.setChecked(true); radioButtonOther.setChecked(false); - serviceDescription.setText( - Html.fromHtml( - getString(R.string.flock_sync_is_a_service_run_by_open_whisper_systems_available, costPerYearUsd) - ) - ); + String descriptionText = getString(R.string.flock_sync_is_a_service_run_by_open_whisper_systems_available, costPerYearUsd); + descriptionText += "

" + getString(R.string.privacy_and_terms_of_service); + serviceDescription.setText(Html.fromHtml(descriptionText)); serviceDescription.setMovementMethod(LinkMovementMethod.getInstance()); } } @@ -167,11 +165,9 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if (isChecked) { radioButtonOws.setChecked(true); radioButtonOther.setChecked(false); - serviceDescription.setText( - Html.fromHtml( - getString(R.string.flock_sync_is_a_service_run_by_open_whisper_systems_available, costPerYearUsd) - ) - ); + String descriptionText = getString(R.string.flock_sync_is_a_service_run_by_open_whisper_systems_available, costPerYearUsd); + descriptionText += "

" + getString(R.string.privacy_and_terms_of_service); + serviceDescription.setText(Html.fromHtml(descriptionText)); serviceDescription.setMovementMethod(LinkMovementMethod.getInstance()); } } @@ -196,11 +192,9 @@ private void initCostPerYear(View fragmentView) { final TextView serviceDescription = (TextView) fragmentView.findViewById(R.id.sync_service_description); final Double costPerYearUsd = (double) getResources().getInteger(R.integer.cost_per_year_usd); - serviceDescription.setText( - Html.fromHtml( - getString(R.string.flock_sync_is_a_service_run_by_open_whisper_systems_available, costPerYearUsd) - ) - ); + String descriptionText = getString(R.string.flock_sync_is_a_service_run_by_open_whisper_systems_available, costPerYearUsd); + descriptionText += "

" + getString(R.string.privacy_and_terms_of_service); + serviceDescription.setText(Html.fromHtml(descriptionText)); serviceDescription.setMovementMethod(LinkMovementMethod.getInstance()); } } diff --git a/flock/src/main/java/org/anhonesteffort/flock/SendBitcoinActivity.java b/flock/src/main/java/org/anhonesteffort/flock/SendBitcoinActivity.java index 74c7ea5..f5bb398 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/SendBitcoinActivity.java +++ b/flock/src/main/java/org/anhonesteffort/flock/SendBitcoinActivity.java @@ -41,7 +41,6 @@ import android.widget.TextView; import android.widget.Toast; -import com.google.common.base.Optional; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.MultiFormatWriter; @@ -51,6 +50,7 @@ import com.stripe.model.Receiver; import de.passsy.holocircularprogressbar.HoloCircularProgressBar; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.registration.OwsRegistration; import org.anhonesteffort.flock.registration.model.FlockAccount; diff --git a/flock/src/main/java/org/anhonesteffort/flock/ServerTestsFragment.java b/flock/src/main/java/org/anhonesteffort/flock/ServerTestsFragment.java index be26f49..8edbc15 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/ServerTestsFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/ServerTestsFragment.java @@ -33,7 +33,6 @@ import android.widget.TextView; import android.widget.Toast; -import com.google.common.base.Optional; import ezvcard.VCard; import ezvcard.VCardVersion; import ezvcard.property.StructuredName; @@ -45,11 +44,13 @@ import net.fortuna.ical4j.model.property.Description; import net.fortuna.ical4j.model.property.Version; import net.fortuna.ical4j.util.Calendars; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.sync.OwsWebDav; import org.anhonesteffort.flock.webdav.ComponentETagPair; import org.anhonesteffort.flock.webdav.InvalidComponentException; import org.anhonesteffort.flock.webdav.PropertyParseException; +import org.anhonesteffort.flock.webdav.WebDavConstants; import org.anhonesteffort.flock.webdav.caldav.CalDavCollection; import org.anhonesteffort.flock.webdav.caldav.CalDavStore; import org.anhonesteffort.flock.webdav.carddav.CardDavCollection; @@ -238,7 +239,7 @@ private void handleCardDavTestCurrentUserPrincipal(Bundle result, DavAccount tes } catch (DavException e) { Log.e(TAG, "carddav current user principal", e); - if (e.getErrorCode() == DavServletResponse.SC_UNAUTHORIZED) + if (e.getErrorCode() == WebDavConstants.SC_UNAUTHORIZED) result.putInt(ErrorToaster.KEY_STATUS_CODE, ErrorToaster.CODE_UNAUTHORIZED); else result.putInt(ErrorToaster.KEY_STATUS_CODE, CODE_ERROR_CARDDAV_CURRENT_USER_PRINCIPAL); @@ -264,7 +265,7 @@ private void handleCalDavTestCurrentUserPrincipal(Bundle result, DavAccount test } catch (DavException e) { Log.e(TAG, "calddav current user principal", e); - if (e.getErrorCode() == DavServletResponse.SC_UNAUTHORIZED) + if (e.getErrorCode() == WebDavConstants.SC_UNAUTHORIZED) result.putInt(ErrorToaster.KEY_STATUS_CODE, ErrorToaster.CODE_UNAUTHORIZED); else result.putInt(ErrorToaster.KEY_STATUS_CODE, CODE_ERROR_CALDAV_CURRENT_USER_PRINCIPAL); diff --git a/flock/src/main/java/org/anhonesteffort/flock/SetupActivity.java b/flock/src/main/java/org/anhonesteffort/flock/SetupActivity.java index 290b167..75c5a6e 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/SetupActivity.java +++ b/flock/src/main/java/org/anhonesteffort/flock/SetupActivity.java @@ -34,7 +34,7 @@ import android.widget.Toast; import com.example.android.wizardpager.wizard.ui.StepPagerStrip; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.key.KeySyncScheduler; /** diff --git a/flock/src/main/java/org/anhonesteffort/flock/StatusHeaderView.java b/flock/src/main/java/org/anhonesteffort/flock/StatusHeaderView.java index 18ebd7c..7d9f48c 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/StatusHeaderView.java +++ b/flock/src/main/java/org/anhonesteffort/flock/StatusHeaderView.java @@ -29,8 +29,7 @@ import android.widget.LinearLayout; import android.widget.TextView; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.crypto.InvalidCipherVersionException; import org.anhonesteffort.flock.crypto.KeyHelper; diff --git a/flock/src/main/java/org/anhonesteffort/flock/SubscriptionGoogleFragment.java b/flock/src/main/java/org/anhonesteffort/flock/SubscriptionGoogleFragment.java index 35f1970..c906075 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/SubscriptionGoogleFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/SubscriptionGoogleFragment.java @@ -382,7 +382,7 @@ private ArrayList getSkuDetails(ArrayList skuList, if (skuDetails.getInt("RESPONSE_CODE") == 0) return skuDetails.getStringArrayList("DETAILS_LIST"); else { - Log.e(TAG, "sku details response code is != 0"); + Log.e(TAG, "sku details response code is " + skuDetails.getInt("RESPONSE_CODE")); result.putInt(ErrorToaster.KEY_STATUS_CODE, ErrorToaster.CODE_GOOGLE_PLAY_ERROR); return new ArrayList(0); } @@ -527,6 +527,12 @@ protected Bundle doInBackground(Void... params) { .getPurchases(3, SubscriptionGoogleFragment.class.getPackage().getName(), PRODUCT_TYPE_SUBSCRIPTION, null); + if (ownedItems.getInt("RESPONSE_CODE") != 0) { + Log.e(TAG, "owned items response code is " + ownedItems.getInt("RESPONSE_CODE")); + result.putInt(ErrorToaster.KEY_STATUS_CODE, ErrorToaster.CODE_GOOGLE_PLAY_ERROR); + return result; + } + ArrayList purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST"); diff --git a/flock/src/main/java/org/anhonesteffort/flock/SubscriptionStripeFragment.java b/flock/src/main/java/org/anhonesteffort/flock/SubscriptionStripeFragment.java index e2b9d1a..b42518e 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/SubscriptionStripeFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/SubscriptionStripeFragment.java @@ -36,11 +36,11 @@ import android.widget.Toast; import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.base.Optional; import com.stripe.exception.CardException; import com.stripe.exception.StripeException; import com.stripe.model.Token; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.registration.OwsRegistration; import org.anhonesteffort.flock.registration.RegistrationApi; import org.anhonesteffort.flock.registration.RegistrationApiException; diff --git a/flock/src/main/java/org/anhonesteffort/flock/UnregisterAccountActivity.java b/flock/src/main/java/org/anhonesteffort/flock/UnregisterAccountActivity.java index 0443867..197f0cf 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/UnregisterAccountActivity.java +++ b/flock/src/main/java/org/anhonesteffort/flock/UnregisterAccountActivity.java @@ -34,7 +34,7 @@ import android.widget.TextView; import android.widget.Toast; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.AccountAuthenticator; import org.anhonesteffort.flock.crypto.KeyStore; import org.anhonesteffort.flock.registration.RegistrationApi; diff --git a/flock/src/main/java/org/anhonesteffort/flock/UnsubscribedFragment.java b/flock/src/main/java/org/anhonesteffort/flock/UnsubscribedFragment.java index 939b181..6c09464 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/UnsubscribedFragment.java +++ b/flock/src/main/java/org/anhonesteffort/flock/UnsubscribedFragment.java @@ -30,8 +30,7 @@ import android.view.ViewGroup; import android.widget.TextView; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.registration.RegistrationApiException; import org.anhonesteffort.flock.registration.model.SubscriptionPlan; import org.anhonesteffort.flock.sync.account.AccountStore; diff --git a/flock/src/main/java/org/anhonesteffort/flock/auth/DavAccount.java b/flock/src/main/java/org/anhonesteffort/flock/auth/DavAccount.java index ddd484c..d7f9c1e 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/auth/DavAccount.java +++ b/flock/src/main/java/org/anhonesteffort/flock/auth/DavAccount.java @@ -24,7 +24,7 @@ import android.content.SharedPreferences; import android.os.Bundle; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; /** diff --git a/flock/src/main/java/org/anhonesteffort/flock/crypto/KeyHelper.java b/flock/src/main/java/org/anhonesteffort/flock/crypto/KeyHelper.java index 89a54f3..3a47dfa 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/crypto/KeyHelper.java +++ b/flock/src/main/java/org/anhonesteffort/flock/crypto/KeyHelper.java @@ -22,7 +22,7 @@ import android.content.Context; import android.util.Log; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.util.Base64; import org.anhonesteffort.flock.util.Util; diff --git a/flock/src/main/java/org/anhonesteffort/flock/crypto/KeyStore.java b/flock/src/main/java/org/anhonesteffort/flock/crypto/KeyStore.java index bd7d3ac..ca9ec93 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/crypto/KeyStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/crypto/KeyStore.java @@ -23,7 +23,7 @@ import android.content.SharedPreferences; import android.util.Log; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.util.Base64; import java.io.IOException; diff --git a/flock/src/main/java/org/anhonesteffort/flock/registration/RegistrationApi.java b/flock/src/main/java/org/anhonesteffort/flock/registration/RegistrationApi.java index f13596c..9238d61 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/registration/RegistrationApi.java +++ b/flock/src/main/java/org/anhonesteffort/flock/registration/RegistrationApi.java @@ -22,8 +22,7 @@ import android.content.Context; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.registration.model.AugmentedFlockAccount; import org.anhonesteffort.flock.registration.model.FlockCardInformation; diff --git a/flock/src/main/java/org/anhonesteffort/flock/registration/model/FlockAccount.java b/flock/src/main/java/org/anhonesteffort/flock/registration/model/FlockAccount.java index ce9e0f5..de50b56 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/registration/model/FlockAccount.java +++ b/flock/src/main/java/org/anhonesteffort/flock/registration/model/FlockAccount.java @@ -28,7 +28,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.deser.std.DateDeserializers; import com.fasterxml.jackson.databind.ser.std.DateSerializer; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.util.Base64; import java.security.MessageDigest; diff --git a/flock/src/main/java/org/anhonesteffort/flock/registration/model/FlockCardInformation.java b/flock/src/main/java/org/anhonesteffort/flock/registration/model/FlockCardInformation.java index 8fecb4f..3c1ca78 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/registration/model/FlockCardInformation.java +++ b/flock/src/main/java/org/anhonesteffort/flock/registration/model/FlockCardInformation.java @@ -22,7 +22,7 @@ import android.os.Bundle; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; /** * Programmer: rhodey diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractDavSyncWorker.java b/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractDavSyncWorker.java index b445dd2..2c25ba0 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractDavSyncWorker.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractDavSyncWorker.java @@ -26,12 +26,12 @@ import android.util.Log; import android.util.Pair; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.crypto.InvalidMacException; import org.anhonesteffort.flock.webdav.ComponentETagPair; import org.anhonesteffort.flock.webdav.InvalidComponentException; import org.anhonesteffort.flock.webdav.PropertyParseException; +import org.anhonesteffort.flock.webdav.WebDavConstants; import org.anhonesteffort.flock.webdav.caldav.CalDavConstants; import org.apache.jackrabbit.webdav.DavException; import org.apache.jackrabbit.webdav.DavServletResponse; @@ -348,7 +348,7 @@ protected void pushLocallyCreatedComponents(SyncResult result) { SyncWorkerUtil.handleException(context, e, result); - if (e.getErrorCode() == DavServletResponse.SC_PRECONDITION_FAILED) + if (e.getErrorCode() == WebDavConstants.SC_PRECONDITION_FAILED) SyncWorkerUtil.handleServerRejectedLocalComponent(localCollection, componentId, context, result); else SyncWorkerUtil.handleServerErrorOnPushNewLocalComponent(localCollection, componentId, context, result); diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractLocalComponentCollection.java b/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractLocalComponentCollection.java index faa21ba..0268eff 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractLocalComponentCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractLocalComponentCollection.java @@ -31,7 +31,7 @@ import android.util.Log; import android.util.Pair; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import java.util.ArrayList; import java.util.HashMap; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractSyncAdapter.java b/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractSyncAdapter.java index 4e432d9..5f9ba67 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractSyncAdapter.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractSyncAdapter.java @@ -28,8 +28,7 @@ import android.os.RemoteException; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.DavAccountHelper; import org.anhonesteffort.flock.NotificationDrawer; import org.anhonesteffort.flock.auth.DavAccount; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractSyncScheduler.java b/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractSyncScheduler.java index a6468de..65843d9 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractSyncScheduler.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/AbstractSyncScheduler.java @@ -30,7 +30,7 @@ import android.preference.PreferenceManager; import android.util.Log; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.DavAccountHelper; import org.anhonesteffort.flock.PreferencesActivity; import org.anhonesteffort.flock.auth.DavAccount; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/HidingDavCollection.java b/flock/src/main/java/org/anhonesteffort/flock/sync/HidingDavCollection.java index d195ab2..f13b518 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/HidingDavCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/HidingDavCollection.java @@ -19,7 +19,7 @@ package org.anhonesteffort.flock.sync; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.crypto.InvalidMacException; import org.anhonesteffort.flock.webdav.ComponentETagPair; import org.anhonesteffort.flock.webdav.PropertyParseException; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/HidingDavCollectionMixin.java b/flock/src/main/java/org/anhonesteffort/flock/sync/HidingDavCollectionMixin.java index 31f4b7a..79ce3b7 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/HidingDavCollectionMixin.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/HidingDavCollectionMixin.java @@ -19,8 +19,7 @@ package org.anhonesteffort.flock.sync; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.crypto.HidingUtil; import org.anhonesteffort.flock.crypto.InvalidMacException; import org.anhonesteffort.flock.crypto.MasterCipher; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/HidingDavStore.java b/flock/src/main/java/org/anhonesteffort/flock/sync/HidingDavStore.java index 91a3b24..9f2c7ef 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/HidingDavStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/HidingDavStore.java @@ -19,7 +19,7 @@ package org.anhonesteffort.flock.sync; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.webdav.PropertyParseException; import org.apache.jackrabbit.webdav.DavException; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/InvalidLocalComponentException.java b/flock/src/main/java/org/anhonesteffort/flock/sync/InvalidLocalComponentException.java index 50f7402..9f29750 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/InvalidLocalComponentException.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/InvalidLocalComponentException.java @@ -19,8 +19,7 @@ package org.anhonesteffort.flock.sync; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.webdav.InvalidComponentException; import org.apache.jackrabbit.webdav.xml.Namespace; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/LocalComponentCollection.java b/flock/src/main/java/org/anhonesteffort/flock/sync/LocalComponentCollection.java index 553d3ca..4fcce1a 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/LocalComponentCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/LocalComponentCollection.java @@ -21,7 +21,7 @@ import android.os.RemoteException; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.webdav.ComponentETagPair; import org.anhonesteffort.flock.webdav.InvalidComponentException; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/LocalComponentStore.java b/flock/src/main/java/org/anhonesteffort/flock/sync/LocalComponentStore.java index 9ae0abb..06972d6 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/LocalComponentStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/LocalComponentStore.java @@ -21,7 +21,7 @@ import android.os.RemoteException; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import java.util.List; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/SyncWorkerUtil.java b/flock/src/main/java/org/anhonesteffort/flock/sync/SyncWorkerUtil.java index a56c694..280fc7c 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/SyncWorkerUtil.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/SyncWorkerUtil.java @@ -24,13 +24,14 @@ import android.util.Log; import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.crypto.InvalidMacException; import org.anhonesteffort.flock.registration.RegistrationApiParseException; import org.anhonesteffort.flock.registration.RegistrationApiException; import org.anhonesteffort.flock.webdav.InvalidComponentException; import org.anhonesteffort.flock.webdav.PropertyParseException; +import org.anhonesteffort.flock.webdav.WebDavConstants; import org.apache.jackrabbit.webdav.DavException; import org.apache.jackrabbit.webdav.DavServletResponse; import org.json.JSONException; @@ -58,11 +59,11 @@ public static void handleException(Context context, Exception e, SyncResult resu DavException ex = (DavException) e; Log.e(TAG, "error code: " + ex.getErrorCode() + ", status phrase: " + ex.getStatusPhrase(), e); - if (ex.getErrorCode() == DavServletResponse.SC_UNAUTHORIZED) + if (ex.getErrorCode() == WebDavConstants.SC_UNAUTHORIZED) result.stats.numAuthExceptions++; else if (ex.getErrorCode() == OwsWebDav.STATUS_PAYMENT_REQUIRED) result.stats.numSkippedEntries++; - else if (ex.getErrorCode() != DavServletResponse.SC_PRECONDITION_FAILED) + else if (ex.getErrorCode() != WebDavConstants.SC_PRECONDITION_FAILED) result.stats.numConflictDetectedExceptions++; } diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/account/AccountStore.java b/flock/src/main/java/org/anhonesteffort/flock/sync/account/AccountStore.java index d017d5d..a841af5 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/account/AccountStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/account/AccountStore.java @@ -23,8 +23,8 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.registration.model.AugmentedFlockAccount; import org.anhonesteffort.flock.registration.model.FlockCardInformation; import org.anhonesteffort.flock.registration.model.SubscriptionPlan; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/account/AccountSyncWorker.java b/flock/src/main/java/org/anhonesteffort/flock/sync/account/AccountSyncWorker.java index 86bb32d..c7c3f32 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/account/AccountSyncWorker.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/account/AccountSyncWorker.java @@ -26,8 +26,8 @@ import com.android.vending.billing.IInAppBillingService; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.SubscriptionGoogleFragment; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.registration.PaymentRequiredException; @@ -61,6 +61,8 @@ public class AccountSyncWorker implements SyncWorker { private final SyncResult result; private final RegistrationApi registration; + private boolean billingServiceHasErrors = false; + public AccountSyncWorker(Context context, DavAccount account, IInAppBillingService billingService, @@ -80,6 +82,7 @@ private List getPurchasedGoogleSubscriptions() { if (billingService == null) { Log.e(TAG, "billing service is null"); + billingServiceHasErrors = true; return subscriptions; } @@ -89,6 +92,12 @@ private List getPurchasedGoogleSubscriptions() { .getPurchases(3, SubscriptionGoogleFragment.class.getPackage().getName(), SubscriptionGoogleFragment.PRODUCT_TYPE_SUBSCRIPTION, null); + if (ownedItems.getInt("RESPONSE_CODE") != 0) { + Log.e(TAG, "owned items response code is " + ownedItems.getInt("RESPONSE_CODE")); + billingServiceHasErrors = true; + return subscriptions; + } + ArrayList purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST"); @@ -154,7 +163,7 @@ private void handleLocallyCanceledGoogleSubscriptions() { } } - if (!havePlanWithPlayServices && billingService != null) + if (!havePlanWithPlayServices && !billingServiceHasErrors) handleCancelSubscriptionWithServerIfNotRenewing(); } diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/AddressbookSyncService.java b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/AddressbookSyncService.java index c3f164b..f6bc4ad 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/AddressbookSyncService.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/AddressbookSyncService.java @@ -26,7 +26,7 @@ import android.os.RemoteException; import android.util.Log; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.DavAccountHelper; import org.anhonesteffort.flock.crypto.InvalidMacException; import org.anhonesteffort.flock.sync.AbstractSyncAdapter; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/AddressbookSyncWorker.java b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/AddressbookSyncWorker.java index 15ac49b..0cf26d2 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/AddressbookSyncWorker.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/AddressbookSyncWorker.java @@ -23,11 +23,10 @@ import android.content.Intent; import android.content.SyncResult; -import com.google.common.base.Optional; - import ezvcard.VCard; import ezvcard.property.Uid; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.DavAccountHelper; import org.anhonesteffort.flock.webdav.carddav.CardDavConstants; import org.anhonesteffort.flock.sync.AbstractDavSyncWorker; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/ContactFactory.java b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/ContactFactory.java index b2357c8..cf0a048 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/ContactFactory.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/ContactFactory.java @@ -25,7 +25,6 @@ import android.provider.ContactsContract; import android.util.Log; -import com.google.common.base.Optional; import ezvcard.VCard; import ezvcard.VCardVersion; import ezvcard.parameter.AddressType; @@ -49,6 +48,7 @@ import ezvcard.property.Uid; import ezvcard.property.Url; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.InvalidLocalComponentException; import org.anhonesteffort.flock.util.Base64; import org.anhonesteffort.flock.webdav.carddav.CardDavConstants; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/HidingCardDavCollection.java b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/HidingCardDavCollection.java index 59480f6..74f9dd6 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/HidingCardDavCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/HidingCardDavCollection.java @@ -19,7 +19,6 @@ package org.anhonesteffort.flock.sync.addressbook; -import com.google.common.base.Optional; import ezvcard.Ezvcard; import ezvcard.VCard; import ezvcard.parameter.ImageType; @@ -27,6 +26,7 @@ import ezvcard.property.RawProperty; import ezvcard.property.StructuredName; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.DecryptedMultiStatusResult; import org.anhonesteffort.flock.sync.InvalidLocalComponentException; import org.anhonesteffort.flock.sync.InvalidRemoteComponentException; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/HidingCardDavStore.java b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/HidingCardDavStore.java index 6bb817d..d6dbe88 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/HidingCardDavStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/HidingCardDavStore.java @@ -19,11 +19,10 @@ package org.anhonesteffort.flock.sync.addressbook; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.HidingDavCollectionMixin; +import org.anhonesteffort.flock.webdav.WebDavConstants; import org.anhonesteffort.flock.webdav.carddav.CardDavConstants; - import org.anhonesteffort.flock.crypto.MasterCipher; import org.anhonesteffort.flock.sync.HidingDavStore; import org.anhonesteffort.flock.crypto.HidingUtil; @@ -31,8 +30,8 @@ import org.anhonesteffort.flock.webdav.PropertyParseException; import org.anhonesteffort.flock.webdav.carddav.CardDavCollection; import org.anhonesteffort.flock.webdav.carddav.CardDavStore; + import org.apache.jackrabbit.webdav.DavException; -import org.apache.jackrabbit.webdav.DavServletResponse; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.MultiStatusResponse; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; @@ -107,7 +106,7 @@ public Optional getCollection(String path) throws DavEx } catch (DavException e) { - if (e.getErrorCode() == DavServletResponse.SC_NOT_FOUND) + if (e.getErrorCode() == WebDavConstants.SC_NOT_FOUND) return Optional.absent(); throw e; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/LocalAddressbookStore.java b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/LocalAddressbookStore.java index 29a475f..823c1a4 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/LocalAddressbookStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/LocalAddressbookStore.java @@ -24,7 +24,7 @@ import android.os.RemoteException; import android.util.Log; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.sync.LocalComponentStore; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/LocalContactCollection.java b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/LocalContactCollection.java index dccbfb3..8017a26 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/LocalContactCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/addressbook/LocalContactCollection.java @@ -37,11 +37,11 @@ import android.util.Log; import android.util.Pair; -import com.google.common.base.Optional; import ezvcard.VCard; import ezvcard.parameter.ImageType; import ezvcard.property.Photo; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.InvalidLocalComponentException; import org.anhonesteffort.flock.sync.InvalidRemoteComponentException; import org.anhonesteffort.flock.webdav.carddav.CardDavConstants; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/CalendarSyncWorker.java b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/CalendarSyncWorker.java index 09f62ab..7e46da1 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/CalendarSyncWorker.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/CalendarSyncWorker.java @@ -24,8 +24,7 @@ import android.content.SyncResult; import android.os.RemoteException; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.SyncWorkerUtil; import org.anhonesteffort.flock.webdav.caldav.CalDavConstants; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/CalendarsSyncService.java b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/CalendarsSyncService.java index 0cb4aa2..e5748cd 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/CalendarsSyncService.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/CalendarsSyncService.java @@ -28,14 +28,12 @@ import android.preference.PreferenceManager; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.crypto.InvalidMacException; import org.anhonesteffort.flock.sync.AbstractSyncAdapter; import org.anhonesteffort.flock.sync.SyncWorker; import org.anhonesteffort.flock.sync.key.DavKeyStore; import org.anhonesteffort.flock.webdav.caldav.CalDavConstants; - import org.anhonesteffort.flock.DavAccountHelper; import org.anhonesteffort.flock.PreferencesActivity; import org.anhonesteffort.flock.webdav.PropertyParseException; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/EventFactory.java b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/EventFactory.java index 24aab8b..b700602 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/EventFactory.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/EventFactory.java @@ -28,11 +28,11 @@ import android.text.format.DateUtils; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.InvalidLocalComponentException; import org.anhonesteffort.flock.sync.InvalidRemoteComponentException; import org.anhonesteffort.flock.webdav.caldav.CalDavConstants; +import org.anhonesteffort.flock.webdav.ComponentETagPair; import net.fortuna.ical4j.model.Calendar; import net.fortuna.ical4j.model.ComponentList; @@ -75,7 +75,6 @@ import net.fortuna.ical4j.model.property.XProperty; import net.fortuna.ical4j.util.Calendars; -import org.anhonesteffort.flock.webdav.ComponentETagPair; import org.apache.commons.lang.StringUtils; import java.io.IOException; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/HidingCalDavCollection.java b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/HidingCalDavCollection.java index 5236c6e..d27d39e 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/HidingCalDavCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/HidingCalDavCollection.java @@ -21,8 +21,7 @@ import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.DecryptedMultiStatusResult; import org.anhonesteffort.flock.sync.InvalidLocalComponentException; import org.anhonesteffort.flock.sync.InvalidRemoteComponentException; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/HidingCalDavStore.java b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/HidingCalDavStore.java index 4a795c2..3d96e6f 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/HidingCalDavStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/HidingCalDavStore.java @@ -19,11 +19,10 @@ package org.anhonesteffort.flock.sync.calendar; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.HidingDavCollectionMixin; +import org.anhonesteffort.flock.webdav.WebDavConstants; import org.anhonesteffort.flock.webdav.caldav.CalDavConstants; - import org.anhonesteffort.flock.crypto.MasterCipher; import org.anhonesteffort.flock.sync.HidingDavStore; import org.anhonesteffort.flock.crypto.HidingUtil; @@ -32,7 +31,6 @@ import org.anhonesteffort.flock.webdav.caldav.CalDavCollection; import org.anhonesteffort.flock.webdav.caldav.CalDavStore; import org.apache.jackrabbit.webdav.DavException; -import org.apache.jackrabbit.webdav.DavServletResponse; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.MultiStatusResponse; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; @@ -107,7 +105,7 @@ public Optional getCollection(String path) throws DavExc } catch (DavException e) { - if (e.getErrorCode() == DavServletResponse.SC_NOT_FOUND) + if (e.getErrorCode() == WebDavConstants.SC_NOT_FOUND) return Optional.absent(); throw e; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/LocalCalendarStore.java b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/LocalCalendarStore.java index 963027b..d23dd6a 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/LocalCalendarStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/LocalCalendarStore.java @@ -29,7 +29,7 @@ import android.provider.CalendarContract; import android.util.Log; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.sync.LocalComponentStore; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/LocalEventCollection.java b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/LocalEventCollection.java index 14254c9..72e2ba8 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/LocalEventCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/calendar/LocalEventCollection.java @@ -31,8 +31,7 @@ import android.provider.CalendarContract; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.InvalidRemoteComponentException; import org.anhonesteffort.flock.webdav.PropertyParseException; import org.anhonesteffort.flock.webdav.caldav.CalDavConstants; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/key/DavKeyCollection.java b/flock/src/main/java/org/anhonesteffort/flock/sync/key/DavKeyCollection.java index 0f36a39..128f296 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/key/DavKeyCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/key/DavKeyCollection.java @@ -5,8 +5,6 @@ import android.preference.PreferenceManager; import android.util.Log; -import com.google.common.base.Optional; - import net.fortuna.ical4j.model.Calendar; import net.fortuna.ical4j.model.Date; import net.fortuna.ical4j.model.component.VEvent; @@ -15,16 +13,17 @@ import net.fortuna.ical4j.model.property.Uid; import net.fortuna.ical4j.model.property.Version; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.sync.OwsWebDav; import org.anhonesteffort.flock.webdav.AbstractDavComponentCollection; import org.anhonesteffort.flock.webdav.InvalidComponentException; import org.anhonesteffort.flock.webdav.MultiStatusResult; import org.anhonesteffort.flock.webdav.PropertyParseException; +import org.anhonesteffort.flock.webdav.WebDavConstants; import org.anhonesteffort.flock.webdav.caldav.CalDavCollection; import org.anhonesteffort.flock.webdav.caldav.CalDavConstants; import org.anhonesteffort.flock.webdav.caldav.CalDavStore; import org.apache.jackrabbit.webdav.DavException; -import org.apache.jackrabbit.webdav.DavServletResponse; import org.apache.jackrabbit.webdav.MultiStatusResponse; import org.apache.jackrabbit.webdav.property.DavPropertyName; import org.apache.jackrabbit.webdav.property.DavPropertyNameSet; @@ -179,7 +178,7 @@ public boolean setMigrationStarted(Context context) setWeStartedMigration(context, true); } catch (DavException e) { - if (e.getErrorCode() == DavServletResponse.SC_PRECONDITION_FAILED) + if (e.getErrorCode() == WebDavConstants.SC_PRECONDITION_FAILED) return false; throw e; @@ -215,7 +214,7 @@ public void setMigrationComplete(Context context) setWeStartedMigration(context, false); } catch (DavException e) { - if (e.getErrorCode() != DavServletResponse.SC_PRECONDITION_FAILED) + if (e.getErrorCode() != WebDavConstants.SC_PRECONDITION_FAILED) throw e; } } diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/key/DavKeyStore.java b/flock/src/main/java/org/anhonesteffort/flock/sync/key/DavKeyStore.java index 79f6b15..66c645e 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/key/DavKeyStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/key/DavKeyStore.java @@ -3,17 +3,16 @@ import android.content.Context; import android.util.Log; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.DavAccountHelper; import org.anhonesteffort.flock.auth.DavAccount; import org.anhonesteffort.flock.webdav.DavClient; import org.anhonesteffort.flock.webdav.PropertyParseException; +import org.anhonesteffort.flock.webdav.WebDavConstants; import org.anhonesteffort.flock.webdav.caldav.CalDavCollection; import org.anhonesteffort.flock.webdav.caldav.CalDavConstants; import org.anhonesteffort.flock.webdav.caldav.CalDavStore; import org.apache.jackrabbit.webdav.DavException; -import org.apache.jackrabbit.webdav.DavServletResponse; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.MultiStatusResponse; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; @@ -89,7 +88,7 @@ public Optional getCollection() ); } catch (DavException e) { - if (e.getErrorCode() == DavServletResponse.SC_NOT_FOUND) + if (e.getErrorCode() == WebDavConstants.SC_NOT_FOUND) return Optional.absent(); throw e; diff --git a/flock/src/main/java/org/anhonesteffort/flock/sync/key/KeySyncWorker.java b/flock/src/main/java/org/anhonesteffort/flock/sync/key/KeySyncWorker.java index ce825f0..d9eb6f5 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/sync/key/KeySyncWorker.java +++ b/flock/src/main/java/org/anhonesteffort/flock/sync/key/KeySyncWorker.java @@ -24,7 +24,7 @@ import android.content.SyncResult; import android.util.Log; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.DavAccountHelper; import org.anhonesteffort.flock.MigrationHelperBroadcastReceiver; import org.anhonesteffort.flock.MigrationService; diff --git a/flock/src/main/java/org/anhonesteffort/flock/util/guava/Absent.java b/flock/src/main/java/org/anhonesteffort/flock/util/guava/Absent.java new file mode 100644 index 0000000..98d134b --- /dev/null +++ b/flock/src/main/java/org/anhonesteffort/flock/util/guava/Absent.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2015 Open Whisper Systems + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +package org.anhonesteffort.flock.util.guava; + +import static org.anhonesteffort.flock.util.guava.Preconditions.checkNotNull; + +import java.util.Collections; +import java.util.Set; + +/** + * Implementation of an {@link Optional} not containing a reference. + */ + +final class Absent extends Optional { + static final Absent INSTANCE = new Absent(); + + @Override public boolean isPresent() { + return false; + } + + @Override public Object get() { + throw new IllegalStateException("value is absent"); + } + + @Override public Object or(Object defaultValue) { + return checkNotNull(defaultValue, "use orNull() instead of or(null)"); + } + + @SuppressWarnings("unchecked") // safe covariant cast + @Override public Optional or(Optional secondChoice) { + return (Optional) checkNotNull(secondChoice); + } + + @Override public Object or(Supplier supplier) { + return checkNotNull(supplier.get(), + "use orNull() instead of a Supplier that returns null"); + } + + @Override public Object orNull() { + return null; + } + + @Override public Set asSet() { + return Collections.emptySet(); + } + + @Override + public Optional transform(Function function) { + checkNotNull(function); + return Optional.absent(); + } + + @Override public boolean equals(Object object) { + return object == this; + } + + @Override public int hashCode() { + return 0x598df91c; + } + + @Override public String toString() { + return "Optional.absent()"; + } + + private Object readResolve() { + return INSTANCE; + } + + private static final long serialVersionUID = 0; +} diff --git a/flock/src/main/java/org/anhonesteffort/flock/util/guava/Function.java b/flock/src/main/java/org/anhonesteffort/flock/util/guava/Function.java new file mode 100644 index 0000000..e13bef1 --- /dev/null +++ b/flock/src/main/java/org/anhonesteffort/flock/util/guava/Function.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2015 Open Whisper Systems + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +package org.anhonesteffort.flock.util.guava; + +/** + * Determines an output value based on an input value. + * + *

See the Guava User Guide article on the use of {@code + * Function}. + * + * @author Kevin Bourrillion + * @since 2.0 (imported from Google Collections Library) + */ + +public interface Function { + /** + * Returns the result of applying this function to {@code input}. This method is generally + * expected, but not absolutely required, to have the following properties: + * + *

    + *
  • Its execution does not cause any observable side effects. + *
  • The computation is consistent with equals; that is, {@link Objects#equal + * Objects.equal}{@code (a, b)} implies that {@code Objects.equal(function.apply(a), + * function.apply(b))}. + *
+ * + * @throws NullPointerException if {@code input} is null and this function does not accept null + * arguments + */ + T apply(F input); + + /** + * Indicates whether another object is equal to this function. + * + *

Most implementations will have no reason to override the behavior of {@link Object#equals}. + * However, an implementation may also choose to return {@code true} whenever {@code object} is a + * {@link org.anhonesteffort.flock.util.guava.Function} that it considers interchangeable with this one. "Interchangeable" + * typically means that {@code Objects.equal(this.apply(f), that.apply(f))} is true for all + * {@code f} of type {@code F}. Note that a {@code false} result from this method does not imply + * that the functions are known not to be interchangeable. + */ + @Override + boolean equals(Object object); +} diff --git a/flock/src/main/java/org/anhonesteffort/flock/util/guava/Optional.java b/flock/src/main/java/org/anhonesteffort/flock/util/guava/Optional.java new file mode 100644 index 0000000..f0557d1 --- /dev/null +++ b/flock/src/main/java/org/anhonesteffort/flock/util/guava/Optional.java @@ -0,0 +1,231 @@ +/* + * Copyright (C) 2015 Open Whisper Systems + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +package org.anhonesteffort.flock.util.guava; + +import static org.anhonesteffort.flock.util.guava.Preconditions.checkNotNull; + +import java.io.Serializable; +import java.util.Set; + +/** + * An immutable object that may contain a non-null reference to another object. Each + * instance of this type either contains a non-null reference, or contains nothing (in + * which case we say that the reference is "absent"); it is never said to "contain {@code + * null}". + * + *

A non-null {@code Optional} reference can be used as a replacement for a nullable + * {@code T} reference. It allows you to represent "a {@code T} that must be present" and + * a "a {@code T} that might be absent" as two distinct types in your program, which can + * aid clarity. + * + *

Some uses of this class include + * + *

    + *
  • As a method return type, as an alternative to returning {@code null} to indicate + * that no value was available + *
  • To distinguish between "unknown" (for example, not present in a map) and "known to + * have no value" (present in the map, with value {@code Optional.absent()}) + *
  • To wrap nullable references for storage in a collection that does not support + * {@code null} (though there are + * + * several other approaches to this that should be considered first) + *
+ * + *

A common alternative to using this class is to find or create a suitable + * null object for the + * type in question. + * + *

This class is not intended as a direct analogue of any existing "option" or "maybe" + * construct from other programming environments, though it may bear some similarities. + * + *

See the Guava User Guide article on + * using {@code Optional}. + * + * @param the type of instance that can be contained. {@code Optional} is naturally + * covariant on this type, so it is safe to cast an {@code Optional} to {@code + * Optional} for any supertype {@code S} of {@code T}. + * @author Kurt Alfred Kluever + * @author Kevin Bourrillion + * @since 10.0 + */ +public abstract class Optional implements Serializable { + /** + * Returns an {@code Optional} instance with no contained reference. + */ + @SuppressWarnings("unchecked") + public static Optional absent() { + return (Optional) Absent.INSTANCE; + } + + /** + * Returns an {@code Optional} instance containing the given non-null reference. + */ + public static Optional of(T reference) { + return new Present(checkNotNull(reference)); + } + + /** + * If {@code nullableReference} is non-null, returns an {@code Optional} instance containing that + * reference; otherwise returns {@link org.anhonesteffort.flock.util.guava.Optional#absent}. + */ + public static Optional fromNullable(T nullableReference) { + return (nullableReference == null) + ? Optional.absent() + : new Present(nullableReference); + } + + Optional() {} + + /** + * Returns {@code true} if this holder contains a (non-null) instance. + */ + public abstract boolean isPresent(); + + /** + * Returns the contained instance, which must be present. If the instance might be + * absent, use {@link #or(Object)} or {@link #orNull} instead. + * + * @throws IllegalStateException if the instance is absent ({@link #isPresent} returns + * {@code false}) + */ + public abstract T get(); + + /** + * Returns the contained instance if it is present; {@code defaultValue} otherwise. If + * no default value should be required because the instance is known to be present, use + * {@link #get()} instead. For a default value of {@code null}, use {@link #orNull}. + * + *

Note about generics: The signature {@code public T or(T defaultValue)} is overly + * restrictive. However, the ideal signature, {@code public S or(S)}, is not legal + * Java. As a result, some sensible operations involving subtypes are compile errors: + *

   {@code
+   *
+   *   Optional optionalInt = getSomeOptionalInt();
+   *   Number value = optionalInt.or(0.5); // error
+   *
+   *   FluentIterable numbers = getSomeNumbers();
+   *   Optional first = numbers.first();
+   *   Number value = first.or(0.5); // error}
+ * + * As a workaround, it is always safe to cast an {@code Optional} to {@code + * Optional}. Casting either of the above example {@code Optional} instances to {@code + * Optional} (where {@code Number} is the desired output type) solves the problem: + *
   {@code
+   *
+   *   Optional optionalInt = (Optional) getSomeOptionalInt();
+   *   Number value = optionalInt.or(0.5); // fine
+   *
+   *   FluentIterable numbers = getSomeNumbers();
+   *   Optional first = (Optional) numbers.first();
+   *   Number value = first.or(0.5); // fine}
+ */ + public abstract T or(T defaultValue); + + /** + * Returns this {@code Optional} if it has a value present; {@code secondChoice} + * otherwise. + */ + public abstract Optional or(Optional secondChoice); + + /** + * Returns the contained instance if it is present; {@code supplier.get()} otherwise. If the + * supplier returns {@code null}, a {@link NullPointerException} is thrown. + * + * @throws NullPointerException if the supplier returns {@code null} + */ + public abstract T or(Supplier supplier); + + /** + * Returns the contained instance if it is present; {@code null} otherwise. If the + * instance is known to be present, use {@link #get()} instead. + */ + public abstract T orNull(); + + /** + * Returns an immutable singleton {@link java.util.Set} whose only element is the contained instance + * if it is present; an empty immutable {@link java.util.Set} otherwise. + * + * @since 11.0 + */ + public abstract Set asSet(); + + /** + * If the instance is present, it is transformed with the given {@link Function}; otherwise, + * {@link org.anhonesteffort.flock.util.guava.Optional#absent} is returned. If the function returns {@code null}, a + * {@link NullPointerException} is thrown. + * + * @throws NullPointerException if the function returns {@code null} + * + * @since 12.0 + */ + + public abstract Optional transform(Function function); + + /** + * Returns {@code true} if {@code object} is an {@code Optional} instance, and either + * the contained references are {@linkplain Object#equals equal} to each other or both + * are absent. Note that {@code Optional} instances of differing parameterized types can + * be equal. + */ + @Override public abstract boolean equals(Object object); + + /** + * Returns a hash code for this instance. + */ + @Override public abstract int hashCode(); + + /** + * Returns a string representation for this instance. The form of this string + * representation is unspecified. + */ + @Override public abstract String toString(); + + /** + * Returns the value of each present instance from the supplied {@code optionals}, in order, + * skipping over occurrences of {@link org.anhonesteffort.flock.util.guava.Optional#absent}. Iterators are unmodifiable and are + * evaluated lazily. + * + * @since 11.0 (generics widened in 13.0) + */ + +// public static Iterable presentInstances( +// final Iterable> optionals) { +// checkNotNull(optionals); +// return new Iterable() { +// @Override public Iterator iterator() { +// return new AbstractIterator() { +// private final Iterator> iterator = +// checkNotNull(optionals.iterator()); +// +// @Override protected T computeNext() { +// while (iterator.hasNext()) { +// Optional optional = iterator.next(); +// if (optional.isPresent()) { +// return optional.get(); +// } +// } +// return endOfData(); +// } +// }; +// }; +// }; +// } + + private static final long serialVersionUID = 0; +} diff --git a/flock/src/main/java/org/anhonesteffort/flock/util/guava/Preconditions.java b/flock/src/main/java/org/anhonesteffort/flock/util/guava/Preconditions.java new file mode 100644 index 0000000..2be71f2 --- /dev/null +++ b/flock/src/main/java/org/anhonesteffort/flock/util/guava/Preconditions.java @@ -0,0 +1,443 @@ +/* + * Copyright (C) 2015 Open Whisper Systems + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +package org.anhonesteffort.flock.util.guava; + +/** + * Simple static methods to be called at the start of your own methods to verify + * correct arguments and state. This allows constructs such as + *
+ *     if (count <= 0) {
+ *       throw new IllegalArgumentException("must be positive: " + count);
+ *     }
+ * + * to be replaced with the more compact + *
+ *     checkArgument(count > 0, "must be positive: %s", count);
+ * + * Note that the sense of the expression is inverted; with {@code Preconditions} + * you declare what you expect to be true, just as you do with an + * + * {@code assert} or a JUnit {@code assertTrue} call. + * + *

Warning: only the {@code "%s"} specifier is recognized as a + * placeholder in these messages, not the full range of {@link + * String#format(String, Object[])} specifiers. + * + *

Take care not to confuse precondition checking with other similar types + * of checks! Precondition exceptions -- including those provided here, but also + * {@link IndexOutOfBoundsException}, {@link java.util.NoSuchElementException}, {@link + * UnsupportedOperationException} and others -- are used to signal that the + * calling method has made an error. This tells the caller that it should + * not have invoked the method when it did, with the arguments it did, or + * perhaps ever. Postcondition or other invariant failures should not throw + * these types of exceptions. + * + *

See the Guava User Guide on + * using {@code Preconditions}. + * + * @author Kevin Bourrillion + * @since 2.0 (imported from Google Collections Library) + */ + +public final class Preconditions { + private Preconditions() {} + + /** + * Ensures the truth of an expression involving one or more parameters to the + * calling method. + * + * @param expression a boolean expression + * @throws IllegalArgumentException if {@code expression} is false + */ + public static void checkArgument(boolean expression) { + if (!expression) { + throw new IllegalArgumentException(); + } + } + + /** + * Ensures the truth of an expression involving one or more parameters to the + * calling method. + * + * @param expression a boolean expression + * @param errorMessage the exception message to use if the check fails; will + * be converted to a string using {@link String#valueOf(Object)} + * @throws IllegalArgumentException if {@code expression} is false + */ + public static void checkArgument( + boolean expression, Object errorMessage) { + if (!expression) { + throw new IllegalArgumentException(String.valueOf(errorMessage)); + } + } + + /** + * Ensures the truth of an expression involving one or more parameters to the + * calling method. + * + * @param expression a boolean expression + * @param errorMessageTemplate a template for the exception message should the + * check fail. The message is formed by replacing each {@code %s} + * placeholder in the template with an argument. These are matched by + * position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. + * Unmatched arguments will be appended to the formatted message in square + * braces. Unmatched placeholders will be left as-is. + * @param errorMessageArgs the arguments to be substituted into the message + * template. Arguments are converted to strings using + * {@link String#valueOf(Object)}. + * @throws IllegalArgumentException if {@code expression} is false + * @throws NullPointerException if the check fails and either {@code + * errorMessageTemplate} or {@code errorMessageArgs} is null (don't let + * this happen) + */ + public static void checkArgument(boolean expression, + String errorMessageTemplate, + Object... errorMessageArgs) { + if (!expression) { + throw new IllegalArgumentException( + format(errorMessageTemplate, errorMessageArgs)); + } + } + + /** + * Ensures the truth of an expression involving the state of the calling + * instance, but not involving any parameters to the calling method. + * + * @param expression a boolean expression + * @throws IllegalStateException if {@code expression} is false + */ + public static void checkState(boolean expression) { + if (!expression) { + throw new IllegalStateException(); + } + } + + /** + * Ensures the truth of an expression involving the state of the calling + * instance, but not involving any parameters to the calling method. + * + * @param expression a boolean expression + * @param errorMessage the exception message to use if the check fails; will + * be converted to a string using {@link String#valueOf(Object)} + * @throws IllegalStateException if {@code expression} is false + */ + public static void checkState( + boolean expression, Object errorMessage) { + if (!expression) { + throw new IllegalStateException(String.valueOf(errorMessage)); + } + } + + /** + * Ensures the truth of an expression involving the state of the calling + * instance, but not involving any parameters to the calling method. + * + * @param expression a boolean expression + * @param errorMessageTemplate a template for the exception message should the + * check fail. The message is formed by replacing each {@code %s} + * placeholder in the template with an argument. These are matched by + * position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. + * Unmatched arguments will be appended to the formatted message in square + * braces. Unmatched placeholders will be left as-is. + * @param errorMessageArgs the arguments to be substituted into the message + * template. Arguments are converted to strings using + * {@link String#valueOf(Object)}. + * @throws IllegalStateException if {@code expression} is false + * @throws NullPointerException if the check fails and either {@code + * errorMessageTemplate} or {@code errorMessageArgs} is null (don't let + * this happen) + */ + public static void checkState(boolean expression, + String errorMessageTemplate, + Object... errorMessageArgs) { + if (!expression) { + throw new IllegalStateException( + format(errorMessageTemplate, errorMessageArgs)); + } + } + + /** + * Ensures that an object reference passed as a parameter to the calling + * method is not null. + * + * @param reference an object reference + * @return the non-null reference that was validated + * @throws NullPointerException if {@code reference} is null + */ + public static T checkNotNull(T reference) { + if (reference == null) { + throw new NullPointerException(); + } + return reference; + } + + /** + * Ensures that an object reference passed as a parameter to the calling + * method is not null. + * + * @param reference an object reference + * @param errorMessage the exception message to use if the check fails; will + * be converted to a string using {@link String#valueOf(Object)} + * @return the non-null reference that was validated + * @throws NullPointerException if {@code reference} is null + */ + public static T checkNotNull(T reference, Object errorMessage) { + if (reference == null) { + throw new NullPointerException(String.valueOf(errorMessage)); + } + return reference; + } + + /** + * Ensures that an object reference passed as a parameter to the calling + * method is not null. + * + * @param reference an object reference + * @param errorMessageTemplate a template for the exception message should the + * check fail. The message is formed by replacing each {@code %s} + * placeholder in the template with an argument. These are matched by + * position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. + * Unmatched arguments will be appended to the formatted message in square + * braces. Unmatched placeholders will be left as-is. + * @param errorMessageArgs the arguments to be substituted into the message + * template. Arguments are converted to strings using + * {@link String#valueOf(Object)}. + * @return the non-null reference that was validated + * @throws NullPointerException if {@code reference} is null + */ + public static T checkNotNull(T reference, + String errorMessageTemplate, + Object... errorMessageArgs) { + if (reference == null) { + // If either of these parameters is null, the right thing happens anyway + throw new NullPointerException( + format(errorMessageTemplate, errorMessageArgs)); + } + return reference; + } + + /* + * All recent hotspots (as of 2009) *really* like to have the natural code + * + * if (guardExpression) { + * throw new BadException(messageExpression); + * } + * + * refactored so that messageExpression is moved to a separate + * String-returning method. + * + * if (guardExpression) { + * throw new BadException(badMsg(...)); + * } + * + * The alternative natural refactorings into void or Exception-returning + * methods are much slower. This is a big deal - we're talking factors of + * 2-8 in microbenchmarks, not just 10-20%. (This is a hotspot optimizer + * bug, which should be fixed, but that's a separate, big project). + * + * The coding pattern above is heavily used in java.util, e.g. in ArrayList. + * There is a RangeCheckMicroBenchmark in the JDK that was used to test this. + * + * But the methods in this class want to throw different exceptions, + * depending on the args, so it appears that this pattern is not directly + * applicable. But we can use the ridiculous, devious trick of throwing an + * exception in the middle of the construction of another exception. + * Hotspot is fine with that. + */ + + /** + * Ensures that {@code index} specifies a valid element in an array, + * list or string of size {@code size}. An element index may range from zero, + * inclusive, to {@code size}, exclusive. + * + * @param index a user-supplied index identifying an element of an array, list + * or string + * @param size the size of that array, list or string + * @return the value of {@code index} + * @throws IndexOutOfBoundsException if {@code index} is negative or is not + * less than {@code size} + * @throws IllegalArgumentException if {@code size} is negative + */ + public static int checkElementIndex(int index, int size) { + return checkElementIndex(index, size, "index"); + } + + /** + * Ensures that {@code index} specifies a valid element in an array, + * list or string of size {@code size}. An element index may range from zero, + * inclusive, to {@code size}, exclusive. + * + * @param index a user-supplied index identifying an element of an array, list + * or string + * @param size the size of that array, list or string + * @param desc the text to use to describe this index in an error message + * @return the value of {@code index} + * @throws IndexOutOfBoundsException if {@code index} is negative or is not + * less than {@code size} + * @throws IllegalArgumentException if {@code size} is negative + */ + public static int checkElementIndex( + int index, int size, String desc) { + // Carefully optimized for execution by hotspot (explanatory comment above) + if (index < 0 || index >= size) { + throw new IndexOutOfBoundsException(badElementIndex(index, size, desc)); + } + return index; + } + + private static String badElementIndex(int index, int size, String desc) { + if (index < 0) { + return format("%s (%s) must not be negative", desc, index); + } else if (size < 0) { + throw new IllegalArgumentException("negative size: " + size); + } else { // index >= size + return format("%s (%s) must be less than size (%s)", desc, index, size); + } + } + + /** + * Ensures that {@code index} specifies a valid position in an array, + * list or string of size {@code size}. A position index may range from zero + * to {@code size}, inclusive. + * + * @param index a user-supplied index identifying a position in an array, list + * or string + * @param size the size of that array, list or string + * @return the value of {@code index} + * @throws IndexOutOfBoundsException if {@code index} is negative or is + * greater than {@code size} + * @throws IllegalArgumentException if {@code size} is negative + */ + public static int checkPositionIndex(int index, int size) { + return checkPositionIndex(index, size, "index"); + } + + /** + * Ensures that {@code index} specifies a valid position in an array, + * list or string of size {@code size}. A position index may range from zero + * to {@code size}, inclusive. + * + * @param index a user-supplied index identifying a position in an array, list + * or string + * @param size the size of that array, list or string + * @param desc the text to use to describe this index in an error message + * @return the value of {@code index} + * @throws IndexOutOfBoundsException if {@code index} is negative or is + * greater than {@code size} + * @throws IllegalArgumentException if {@code size} is negative + */ + public static int checkPositionIndex( + int index, int size, String desc) { + // Carefully optimized for execution by hotspot (explanatory comment above) + if (index < 0 || index > size) { + throw new IndexOutOfBoundsException(badPositionIndex(index, size, desc)); + } + return index; + } + + private static String badPositionIndex(int index, int size, String desc) { + if (index < 0) { + return format("%s (%s) must not be negative", desc, index); + } else if (size < 0) { + throw new IllegalArgumentException("negative size: " + size); + } else { // index > size + return format("%s (%s) must not be greater than size (%s)", + desc, index, size); + } + } + + /** + * Ensures that {@code start} and {@code end} specify a valid positions + * in an array, list or string of size {@code size}, and are in order. A + * position index may range from zero to {@code size}, inclusive. + * + * @param start a user-supplied index identifying a starting position in an + * array, list or string + * @param end a user-supplied index identifying a ending position in an array, + * list or string + * @param size the size of that array, list or string + * @throws IndexOutOfBoundsException if either index is negative or is + * greater than {@code size}, or if {@code end} is less than {@code start} + * @throws IllegalArgumentException if {@code size} is negative + */ + public static void checkPositionIndexes(int start, int end, int size) { + // Carefully optimized for execution by hotspot (explanatory comment above) + if (start < 0 || end < start || end > size) { + throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size)); + } + } + + private static String badPositionIndexes(int start, int end, int size) { + if (start < 0 || start > size) { + return badPositionIndex(start, size, "start index"); + } + if (end < 0 || end > size) { + return badPositionIndex(end, size, "end index"); + } + // end < start + return format("end index (%s) must not be less than start index (%s)", + end, start); + } + + /** + * Substitutes each {@code %s} in {@code template} with an argument. These + * are matched by position - the first {@code %s} gets {@code args[0]}, etc. + * If there are more arguments than placeholders, the unmatched arguments will + * be appended to the end of the formatted message in square braces. + * + * @param template a non-null string containing 0 or more {@code %s} + * placeholders. + * @param args the arguments to be substituted into the message + * template. Arguments are converted to strings using + * {@link String#valueOf(Object)}. Arguments can be null. + */ + static String format(String template, + Object... args) { + template = String.valueOf(template); // null -> "null" + + // start substituting the arguments into the '%s' placeholders + StringBuilder builder = new StringBuilder( + template.length() + 16 * args.length); + int templateStart = 0; + int i = 0; + while (i < args.length) { + int placeholderStart = template.indexOf("%s", templateStart); + if (placeholderStart == -1) { + break; + } + builder.append(template.substring(templateStart, placeholderStart)); + builder.append(args[i++]); + templateStart = placeholderStart + 2; + } + builder.append(template.substring(templateStart)); + + // if we run out of placeholders, append the extra args in square braces + if (i < args.length) { + builder.append(" ["); + builder.append(args[i++]); + while (i < args.length) { + builder.append(", "); + builder.append(args[i++]); + } + builder.append(']'); + } + + return builder.toString(); + } +} diff --git a/flock/src/main/java/org/anhonesteffort/flock/util/guava/Present.java b/flock/src/main/java/org/anhonesteffort/flock/util/guava/Present.java new file mode 100644 index 0000000..deba58f --- /dev/null +++ b/flock/src/main/java/org/anhonesteffort/flock/util/guava/Present.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2015 Open Whisper Systems + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +package org.anhonesteffort.flock.util.guava; + +import static org.anhonesteffort.flock.util.guava.Preconditions.checkNotNull; + +import java.util.Collections; +import java.util.Set; + +/** + * Implementation of an {@link Optional} containing a reference. + */ + +final class Present extends Optional { + private final T reference; + + Present(T reference) { + this.reference = reference; + } + + @Override public boolean isPresent() { + return true; + } + + @Override public T get() { + return reference; + } + + @Override public T or(T defaultValue) { + checkNotNull(defaultValue, "use orNull() instead of or(null)"); + return reference; + } + + @Override public Optional or(Optional secondChoice) { + checkNotNull(secondChoice); + return this; + } + + @Override public T or(Supplier supplier) { + checkNotNull(supplier); + return reference; + } + + @Override public T orNull() { + return reference; + } + + @Override public Set asSet() { + return Collections.singleton(reference); + } + + @Override public Optional transform(Function function) { + return new Present(checkNotNull(function.apply(reference), + "Transformation function cannot return null.")); + } + + @Override public boolean equals(Object object) { + if (object instanceof Present) { + Present other = (Present) object; + return reference.equals(other.reference); + } + return false; + } + + @Override public int hashCode() { + return 0x598df91c + reference.hashCode(); + } + + @Override public String toString() { + return "Optional.of(" + reference + ")"; + } + + private static final long serialVersionUID = 0; +} diff --git a/flock/src/main/java/org/anhonesteffort/flock/util/guava/Supplier.java b/flock/src/main/java/org/anhonesteffort/flock/util/guava/Supplier.java new file mode 100644 index 0000000..f684d29 --- /dev/null +++ b/flock/src/main/java/org/anhonesteffort/flock/util/guava/Supplier.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2015 Open Whisper Systems + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +package org.anhonesteffort.flock.util.guava; + +/** + * A class that can supply objects of a single type. Semantically, this could + * be a factory, generator, builder, closure, or something else entirely. No + * guarantees are implied by this interface. + * + * @author Harry Heymann + * @since 2.0 (imported from Google Collections Library) + */ +public interface Supplier { + /** + * Retrieves an instance of the appropriate type. The returned object may or + * may not be a new instance, depending on the implementation. + * + * @return an instance of the appropriate type + */ + T get(); +} diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/AbstractDavComponentCollection.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/AbstractDavComponentCollection.java index 2b5c832..922d780 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/AbstractDavComponentCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/AbstractDavComponentCollection.java @@ -19,8 +19,7 @@ package org.anhonesteffort.flock.webdav; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.webdav.caldav.CalDavConstants; import org.apache.jackrabbit.webdav.DavConstants; import org.apache.jackrabbit.webdav.DavException; @@ -283,7 +282,7 @@ public void fetchProperties(DavPropertyNameSet fetchProps) throws DavException, MultiStatus multiStatus = propFindMethod.getResponseBodyAsMultiStatus(); MultiStatusResponse[] responses = multiStatus.getResponses(); - DavPropertySet foundProperties = responses[0].getProperties(DavServletResponse.SC_OK); + DavPropertySet foundProperties = responses[0].getProperties(WebDavConstants.SC_OK); if (foundProperties != null) properties = foundProperties; } @@ -339,7 +338,7 @@ public HashMap getComponentETags() throws DavException, IOExcept MultiStatusResponse[] responses = multiStatus.getResponses(); for (MultiStatusResponse msResponse : responses) { - DavPropertySet foundProperties = msResponse.getProperties(DavServletResponse.SC_OK); + DavPropertySet foundProperties = msResponse.getProperties(WebDavConstants.SC_OK); Optional componentUid = getUidFromComponentPath(msResponse.getHref()); if (componentUid.isPresent() && foundProperties.get(DavPropertyName.PROPERTY_GETETAG) != null) { @@ -386,7 +385,7 @@ public MultiStatusResult getComponents(List uids) if (reportMethod.getStatusCode() == DavServletResponse.SC_MULTI_STATUS) return getComponentsFromMultiStatus(reportMethod.getResponseBodyAsMultiStatus().getResponses()); - else if (reportMethod.getStatusCode() == DavServletResponse.SC_NOT_FOUND) + else if (reportMethod.getStatusCode() == WebDavConstants.SC_NOT_FOUND) return new MultiStatusResult(new LinkedList>(), new LinkedList()); else throw new DavException(reportMethod.getStatusCode(), reportMethod.getStatusText()); @@ -449,7 +448,7 @@ public void removeComponent(String path) throws DavException, IOException { try { client.execute(deleteMethod); - if (!deleteMethod.succeeded() && deleteMethod.getStatusCode() != DavServletResponse.SC_OK) + if (!deleteMethod.succeeded() && deleteMethod.getStatusCode() != WebDavConstants.SC_OK) throw new DavException(deleteMethod.getStatusCode(), deleteMethod.getStatusText()); } finally { diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/AbstractDavComponentStore.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/AbstractDavComponentStore.java index 70e7573..7eed6bf 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/AbstractDavComponentStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/AbstractDavComponentStore.java @@ -19,11 +19,9 @@ package org.anhonesteffort.flock.webdav; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.apache.commons.httpclient.Header; import org.apache.jackrabbit.webdav.DavException; -import org.apache.jackrabbit.webdav.DavServletResponse; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.MultiStatusResponse; import org.apache.jackrabbit.webdav.Status; @@ -109,11 +107,11 @@ public List getDavOptions() throws DavException, IOException { protected Optional getCurrentUserPrincipalFromMultiStatus(MultiStatus multiStatus) { for (MultiStatusResponse msResponse : multiStatus.getResponses()) { - DavPropertySet foundProperties = msResponse.getProperties(DavServletResponse.SC_OK); + DavPropertySet foundProperties = msResponse.getProperties(WebDavConstants.SC_OK); DavProperty homeSetProperty = foundProperties.get(WebDavConstants.PROPERTY_NAME_CURRENT_USER_PRINCIPAL); for (Status status : msResponse.getStatus()) { - if (status.getStatusCode() == DavServletResponse.SC_OK) { + if (status.getStatusCode() == WebDavConstants.SC_OK) { if (homeSetProperty != null && homeSetProperty.getValue() instanceof ArrayList) { for (Object child : (ArrayList) homeSetProperty.getValue()) { @@ -181,11 +179,11 @@ public Optional getCurrentUserPrincipal() throws DavException, IOExcepti } catch (DavException e) { - if (e.getErrorCode() == DavServletResponse.SC_MOVED_PERMANENTLY || - e.getErrorCode() == DavServletResponse.SC_MOVED_TEMPORARILY || - e.getErrorCode() == DavServletResponse.SC_SEE_OTHER || - e.getErrorCode() == DavServletResponse.SC_USE_PROXY || - e.getErrorCode() == DavServletResponse.SC_TEMPORARY_REDIRECT) + if (e.getErrorCode() == WebDavConstants.SC_MOVED_PERMANENTLY || + e.getErrorCode() == WebDavConstants.SC_MOVED_TEMPORARILY || + e.getErrorCode() == WebDavConstants.SC_SEE_OTHER || + e.getErrorCode() == WebDavConstants.SC_USE_PROXY || + e.getErrorCode() == WebDavConstants.SC_TEMPORARY_REDIRECT) { Header locationHeader = propFindMethod.getResponseHeader("location"); // TODO: find constant for this... if (locationHeader.getValue() != null) { @@ -211,7 +209,7 @@ public void removeCollection(String path) throws DavException, IOException { getClient().execute(deleteMethod); - if (!deleteMethod.succeeded() && deleteMethod.getStatusCode() != DavServletResponse.SC_OK) + if (!deleteMethod.succeeded() && deleteMethod.getStatusCode() != WebDavConstants.SC_OK) throw new DavException(deleteMethod.getStatusCode(), deleteMethod.getStatusText()); } finally { diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/ComponentETagPair.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/ComponentETagPair.java index 3a0a689..2c2b905 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/ComponentETagPair.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/ComponentETagPair.java @@ -19,7 +19,7 @@ package org.anhonesteffort.flock.webdav; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; /** * Programmer: rhodey diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/DavComponentCollection.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/DavComponentCollection.java index 7182f20..814e362 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/DavComponentCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/DavComponentCollection.java @@ -19,7 +19,7 @@ package org.anhonesteffort.flock.webdav; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.apache.jackrabbit.webdav.DavException; import org.apache.jackrabbit.webdav.property.DavPropertyName; import org.apache.jackrabbit.webdav.property.DavPropertyNameSet; diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/DavComponentStore.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/DavComponentStore.java index b31014f..5765b99 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/DavComponentStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/DavComponentStore.java @@ -19,7 +19,7 @@ package org.anhonesteffort.flock.webdav; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.apache.jackrabbit.webdav.DavException; import java.io.IOException; diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/InvalidComponentException.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/InvalidComponentException.java index dab5b2a..f2cb826 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/InvalidComponentException.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/InvalidComponentException.java @@ -19,7 +19,7 @@ package org.anhonesteffort.flock.webdav; -import com.google.common.base.Optional; +import org.anhonesteffort.flock.util.guava.Optional; import org.apache.jackrabbit.webdav.xml.Namespace; /** diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/WebDavConstants.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/WebDavConstants.java index 1135d15..872268a 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/WebDavConstants.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/WebDavConstants.java @@ -27,6 +27,21 @@ */ public class WebDavConstants { + public static final int SC_OK = 200; + public static final int SC_NO_CONTENT = 204; + + public static final int SC_MOVED_PERMANENTLY = 301; + public static final int SC_MOVED_TEMPORARILY = 302; + public static final int SC_SEE_OTHER = 303; + public static final int SC_USE_PROXY = 305; + public static final int SC_TEMPORARY_REDIRECT = 307; + + public static final int SC_UNAUTHORIZED = 401; + public static final int SC_FORBIDDEN = 403; + public static final int SC_NOT_FOUND = 404; + public static final int SC_PRECONDITION_FAILED = 412; + public static final int SC_REQUEST_ENTITY_TOO_LARGE = 413; + public static final String PROPERTY_RESOURCE_ID = "resource-id"; public static final String PROPERTY_CURRENT_USER_PRINCIPAL = "current-user-principal"; public static final String PROPERTY_SUPPORTED_REPORT_SET = "supported-report-set"; diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/CalDavCollection.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/CalDavCollection.java index 68f2671..0351864 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/CalDavCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/CalDavCollection.java @@ -19,8 +19,6 @@ package org.anhonesteffort.flock.webdav.caldav; -import com.google.common.base.Optional; - import net.fortuna.ical4j.data.CalendarBuilder; import net.fortuna.ical4j.data.CalendarOutputter; import net.fortuna.ical4j.data.ParserException; @@ -30,11 +28,13 @@ import net.fortuna.ical4j.model.ValidationException; import net.fortuna.ical4j.model.property.ProdId; import net.fortuna.ical4j.util.Calendars; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.webdav.AbstractDavComponentCollection; import org.anhonesteffort.flock.webdav.ComponentETagPair; import org.anhonesteffort.flock.webdav.InvalidComponentException; import org.anhonesteffort.flock.webdav.MultiStatusResult; import org.anhonesteffort.flock.webdav.PropertyParseException; +import org.anhonesteffort.flock.webdav.WebDavConstants; import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; import org.apache.jackrabbit.webdav.DavException; import org.apache.jackrabbit.webdav.DavServletResponse; @@ -252,7 +252,7 @@ protected MultiStatusResult getComponentsFromMultiStatus(MultiStatusRe for (MultiStatusResponse response : msResponses) { Calendar calendar = null; String eTag = null; - DavPropertySet propertySet = response.getProperties(DavServletResponse.SC_OK); + DavPropertySet propertySet = response.getProperties(WebDavConstants.SC_OK); if (propertySet.get(CalDavConstants.PROPERTY_NAME_CALENDAR_DATA) != null) { String calendarData = (String) propertySet.get(CalDavConstants.PROPERTY_NAME_CALENDAR_DATA).getValue(); @@ -375,15 +375,15 @@ protected void putComponentToServer(Calendar calendar, Optional ifMatchE client.execute(putMethod); int status = putMethod.getStatusCode(); - if (status == DavServletResponse.SC_REQUEST_ENTITY_TOO_LARGE || - status == DavServletResponse.SC_FORBIDDEN) + if (status == WebDavConstants.SC_REQUEST_ENTITY_TOO_LARGE || + status == WebDavConstants.SC_FORBIDDEN) { throw new InvalidComponentException("Put method returned bad status " + status, CalDavConstants.CALDAV_NAMESPACE, getPath(), calendarUid); } - if (status < DavServletResponse.SC_OK || - status > DavServletResponse.SC_NO_CONTENT) + if (status < WebDavConstants.SC_OK || + status > WebDavConstants.SC_NO_CONTENT) { throw new DavException(status, putMethod.getStatusText()); } diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/CalDavConstants.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/CalDavConstants.java index 3a87f2c..a71db7a 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/CalDavConstants.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/CalDavConstants.java @@ -21,9 +21,6 @@ import org.apache.jackrabbit.webdav.property.DavPropertyName; import org.apache.jackrabbit.webdav.xml.Namespace; -import java.util.HashSet; -import java.util.Set; - /** * Programmer: rhodey */ diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/CalDavStore.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/CalDavStore.java index 3ed29f2..02f6e87 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/CalDavStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/CalDavStore.java @@ -19,10 +19,9 @@ package org.anhonesteffort.flock.webdav.caldav; -import com.google.common.base.Optional; - import org.anhonesteffort.flock.webdav.WebDavConstants; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.webdav.AbstractDavComponentStore; import org.anhonesteffort.flock.webdav.DavClient; import org.anhonesteffort.flock.webdav.DavComponentStore; @@ -109,11 +108,11 @@ public Optional getCalendarHomeSet() MultiStatusResponse[] msResponses = multiStatus.getResponses(); for (MultiStatusResponse msResponse : msResponses) { - DavPropertySet foundProperties = msResponse.getProperties(DavServletResponse.SC_OK); + DavPropertySet foundProperties = msResponse.getProperties(WebDavConstants.SC_OK); DavProperty homeSetProperty = foundProperties.get(CalDavConstants.PROPERTY_NAME_CALENDAR_HOME_SET); for (Status status : msResponse.getStatus()) { - if (status.getStatusCode() == DavServletResponse.SC_OK) { + if (status.getStatusCode() == WebDavConstants.SC_OK) { if (homeSetProperty != null && homeSetProperty.getValue() instanceof ArrayList) { for (Object child : (ArrayList) homeSetProperty.getValue()) { @@ -199,11 +198,11 @@ public static List getCollectionsFromMultiStatusResponses(CalD List collections = new LinkedList(); for (MultiStatusResponse msResponse : msResponses) { - DavPropertySet foundProperties = msResponse.getProperties(DavServletResponse.SC_OK); + DavPropertySet foundProperties = msResponse.getProperties(WebDavConstants.SC_OK); String collectionUri = msResponse.getHref(); for (Status status : msResponse.getStatus()) { - if (status.getStatusCode() == DavServletResponse.SC_OK) { + if (status.getStatusCode() == WebDavConstants.SC_OK) { boolean isCalendarCollection = false; DavPropertySet collectionProperties = new DavPropertySet(); @@ -263,7 +262,7 @@ public Optional getCollection(String path) throws DavException } catch (DavException e) { - if (e.getErrorCode() == DavServletResponse.SC_NOT_FOUND) + if (e.getErrorCode() == WebDavConstants.SC_NOT_FOUND) return Optional.absent(); throw e; diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/DavCalendarCollection.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/DavCalendarCollection.java index 15698cc..f6f9600 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/DavCalendarCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/caldav/DavCalendarCollection.java @@ -19,9 +19,9 @@ package org.anhonesteffort.flock.webdav.caldav; -import com.google.common.base.Optional; - import net.fortuna.ical4j.model.Calendar; + +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.webdav.DavComponentCollection; import org.anhonesteffort.flock.webdav.PropertyParseException; import org.apache.jackrabbit.webdav.DavException; diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/carddav/CardDavCollection.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/carddav/CardDavCollection.java index 3fccb9b..7072274 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/carddav/CardDavCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/carddav/CardDavCollection.java @@ -19,19 +19,19 @@ package org.anhonesteffort.flock.webdav.carddav; -import com.google.common.base.Optional; import ezvcard.Ezvcard; import ezvcard.VCard; import ezvcard.property.ProductId; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.webdav.AbstractDavComponentCollection; import org.anhonesteffort.flock.webdav.ComponentETagPair; import org.anhonesteffort.flock.webdav.InvalidComponentException; import org.anhonesteffort.flock.webdav.MultiStatusResult; import org.anhonesteffort.flock.webdav.PropertyParseException; +import org.anhonesteffort.flock.webdav.WebDavConstants; import org.apache.commons.httpclient.methods.ByteArrayRequestEntity; import org.apache.jackrabbit.webdav.DavException; -import org.apache.jackrabbit.webdav.DavServletResponse; import org.apache.jackrabbit.webdav.MultiStatusResponse; import org.apache.jackrabbit.webdav.client.methods.PutMethod; import org.apache.jackrabbit.webdav.property.DavPropertyName; @@ -128,7 +128,7 @@ protected MultiStatusResult getComponentsFromMultiStatus(MultiStatusRespo for (MultiStatusResponse response : msResponses) { VCard vCard = null; String eTag = null; - DavPropertySet propertySet = response.getProperties(DavServletResponse.SC_OK); + DavPropertySet propertySet = response.getProperties(WebDavConstants.SC_OK); if (propertySet.get(CardDavConstants.PROPERTY_NAME_ADDRESS_DATA) != null) { String addressData = (String) propertySet.get(CardDavConstants.PROPERTY_NAME_ADDRESS_DATA).getValue(); @@ -186,15 +186,15 @@ protected void putComponentToServer(VCard vCard, Optional ifMatchETag) client.execute(putMethod); int status = putMethod.getStatusCode(); - if (status == DavServletResponse.SC_REQUEST_ENTITY_TOO_LARGE || - status == DavServletResponse.SC_FORBIDDEN) + if (status == WebDavConstants.SC_REQUEST_ENTITY_TOO_LARGE || + status == WebDavConstants.SC_FORBIDDEN) { throw new InvalidComponentException("Put method returned bad status " + status, CardDavConstants.CARDDAV_NAMESPACE, getPath(), vCardUid); } - if (putMethod.getStatusCode() < DavServletResponse.SC_OK || - putMethod.getStatusCode() > DavServletResponse.SC_NO_CONTENT) + if (putMethod.getStatusCode() < WebDavConstants.SC_OK || + putMethod.getStatusCode() > WebDavConstants.SC_NO_CONTENT) { throw new DavException(putMethod.getStatusCode(), putMethod.getStatusText()); } diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/carddav/CardDavStore.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/carddav/CardDavStore.java index 767d88b..864c758 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/carddav/CardDavStore.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/carddav/CardDavStore.java @@ -19,23 +19,18 @@ package org.anhonesteffort.flock.webdav.carddav; -import com.google.common.base.Optional; - +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.webdav.WebDavConstants; - import org.anhonesteffort.flock.webdav.AbstractDavComponentStore; import org.anhonesteffort.flock.webdav.DavClient; import org.anhonesteffort.flock.webdav.DavComponentStore; import org.anhonesteffort.flock.webdav.ExtendedMkCol; import org.anhonesteffort.flock.webdav.PropertyParseException; -import org.apache.commons.httpclient.Header; import org.apache.jackrabbit.webdav.DavConstants; import org.apache.jackrabbit.webdav.DavException; -import org.apache.jackrabbit.webdav.DavServletResponse; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.MultiStatusResponse; import org.apache.jackrabbit.webdav.Status; -import org.apache.jackrabbit.webdav.client.methods.DeleteMethod; import org.apache.jackrabbit.webdav.client.methods.MkColMethod; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; import org.apache.jackrabbit.webdav.property.DavProperty; @@ -110,11 +105,11 @@ public Optional getAddressbookHomeSet() MultiStatusResponse[] msResponses = multiStatus.getResponses(); for (MultiStatusResponse msResponse : msResponses) { - DavPropertySet foundProperties = msResponse.getProperties(DavServletResponse.SC_OK); + DavPropertySet foundProperties = msResponse.getProperties(WebDavConstants.SC_OK); DavProperty homeSetProperty = foundProperties.get(CardDavConstants.PROPERTY_NAME_ADDRESSBOOK_HOME_SET); for (Status status : msResponse.getStatus()) { - if (status.getStatusCode() == DavServletResponse.SC_OK) { + if (status.getStatusCode() == WebDavConstants.SC_OK) { if (homeSetProperty != null && homeSetProperty.getValue() instanceof ArrayList) { for (Object child : (ArrayList) homeSetProperty.getValue()) { @@ -199,11 +194,11 @@ public static List getCollectionsFromMultiStatusResponses(Car List collections = new LinkedList(); for (MultiStatusResponse msResponse : msResponses) { - DavPropertySet foundProperties = msResponse.getProperties(DavServletResponse.SC_OK); + DavPropertySet foundProperties = msResponse.getProperties(WebDavConstants.SC_OK); String collectionUri = msResponse.getHref(); for (Status status : msResponse.getStatus()) { - if (status.getStatusCode() == DavServletResponse.SC_OK) { + if (status.getStatusCode() == WebDavConstants.SC_OK) { boolean isAddressbookCollection = false; DavPropertySet collectionProperties = new DavPropertySet(); @@ -260,7 +255,7 @@ public Optional getCollection(String path) throws DavExceptio } catch (DavException e) { - if (e.getErrorCode() == DavServletResponse.SC_NOT_FOUND) + if (e.getErrorCode() == WebDavConstants.SC_NOT_FOUND) return Optional.absent(); throw e; diff --git a/flock/src/main/java/org/anhonesteffort/flock/webdav/carddav/DavContactCollection.java b/flock/src/main/java/org/anhonesteffort/flock/webdav/carddav/DavContactCollection.java index 9f4ca69..0adadeb 100644 --- a/flock/src/main/java/org/anhonesteffort/flock/webdav/carddav/DavContactCollection.java +++ b/flock/src/main/java/org/anhonesteffort/flock/webdav/carddav/DavContactCollection.java @@ -19,9 +19,9 @@ package org.anhonesteffort.flock.webdav.carddav; -import com.google.common.base.Optional; import ezvcard.VCard; +import org.anhonesteffort.flock.util.guava.Optional; import org.anhonesteffort.flock.webdav.DavComponentCollection; import org.anhonesteffort.flock.webdav.PropertyParseException; import org.apache.jackrabbit.webdav.DavException; diff --git a/flock/src/main/res/layout/fragment_intro.xml b/flock/src/main/res/layout/fragment_intro.xml index 069acf0..d497f55 100644 --- a/flock/src/main/res/layout/fragment_intro.xml +++ b/flock/src/main/res/layout/fragment_intro.xml @@ -38,7 +38,8 @@ android:fontFamily="sans-serif-light" android:text="@string/welcome_to_flock"/> - Wähle einen Dienst Flock Sync - - Flock Sync ist ein Dienst von Open Whisper Systems, der für $%.2f/Jahr zur - Verfügung steht. Der Dienst kann 30 Tage ohne Zahlungsinformationen getestet - werden. - -
- Datenschutzerklärung und AGB - ]]> -
+ Datenschutzerklärung und AGB]]> + Flock Sync ist ein Dienst von Open Whisper Systems, der für $%.2f/Jahr zur Verfügung steht. Der Dienst kann 30 Tage ohne Zahlungsinformationen getestet werden. Eigener Server Du kannst deinen eigenen WebDAV-kompatiblen Server als Synchronisierungsdienst verwenden. Vor der Nutzung mit Flock muss der Server eine Reihe von Tests bestehen. diff --git a/flock/src/main/res/values-ko_KR/strings.xml b/flock/src/main/res/values-ko_KR/strings.xml index 8c3ab4c..1717217 100644 --- a/flock/src/main/res/values-ko_KR/strings.xml +++ b/flock/src/main/res/values-ko_KR/strings.xml @@ -67,14 +67,7 @@ 동기화 서비스 선택 Flock 동기화 - -Flock 동기화는 Open Whisper Systems이 $%.2f/year에 운영하는 서비스입니다. -별다른 결제없이 30일 동안 무료로 평가해보세요 . - -
-Privacy and Terms of Service -]]>
+ Flock 동기화는 Open Whisper Systems이 $%.2f/year에 운영하는 서비스입니다. 별다른 결제없이 30일 동안 무료로 평가해보세요. 직접 호스팅하기 직접 WebDAV-compliant 서버를 설정하고 운영하신다면, 동기화서비스로 Flock을 사용하기 전에 서버는 몇 가지의 테스트를 거쳐야 합니다. diff --git a/flock/src/main/res/values/strings.xml b/flock/src/main/res/values/strings.xml index d7bd7a9..9b771d9 100644 --- a/flock/src/main/res/values/strings.xml +++ b/flock/src/main/res/values/strings.xml @@ -85,15 +85,8 @@ Choose sync service Flock Sync - - Flock Sync is a service run by Open Whisper Systems available for $%.2f/year. - Evaluate at no charge for 30 days, no payment information required. - -
- Privacy and Terms of Service - ]]> -
+ Privacy and Terms of Service]]> + Flock Sync is a service run by Open Whisper Systems available for $%.2f/year. Evaluate at no charge for 30 days, no payment information required. Host my own You may chose to run and configure your own WebDAV-compliant server as a sync service. Before use with Flock the server must pass a series of tests. diff --git a/flock/src/nonplay/AndroidManifest.xml b/flock/src/nonplay/AndroidManifest.xml new file mode 100644 index 0000000..3f27f97 --- /dev/null +++ b/flock/src/nonplay/AndroidManifest.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + diff --git a/flock/src/nonplay/java/org/anhonesteffort/flock/ApplicationContext.java b/flock/src/nonplay/java/org/anhonesteffort/flock/ApplicationContext.java new file mode 100644 index 0000000..bfb4928 --- /dev/null +++ b/flock/src/nonplay/java/org/anhonesteffort/flock/ApplicationContext.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2015 Open Whisper Systems + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +package org.anhonesteffort.flock; + +import android.app.Application; +import android.util.Log; + +import org.whispersystems.libsupplychain.SupplyChain; +import org.whispersystems.libsupplychain.SupplyChainBuilder; + +import java.io.InputStream; +import java.security.KeyStore; + +/** + * rhodey + */ +public class ApplicationContext extends Application { + + @Override + public void onCreate() { + super.onCreate(); + + String installer = getPackageManager().getInstallerPackageName(getPackageName()); + if (installer != null && installer.equals("com.android.vending")) + return; + + Log.d(getClass().getName(), "app came from outside the play store (" + installer + "), starting SupplyChain."); + + final String packageName = getPackageName(); + final String hostName = "flock-supplychain.anhonesteffort.org"; + + try { + + final InputStream keyStoreInputStream = getAssets().open("flock.store"); + final KeyStore trustStore = KeyStore.getInstance("BKS"); + + trustStore.load(keyStoreInputStream, "owsflock".toCharArray()); + + SupplyChain supplyChain = + SupplyChainBuilder.newBuilder(this, packageName, hostName) + .withTrustStore(trustStore) + .withUpdateNotificationDrawable(R.drawable.flock_actionbar_icon) + .withUpdateNotificationColor(getResources().getColor(R.color.flocktheme_color)) + .withUpdateNotificationTitle(getString(R.string.update_available)) + .withUpdateNotificationText(getString(R.string.touch_to_install_update)) + .create(); + + supplyChain.start(); + + } catch (Exception e) { + Log.e(ApplicationContext.class.getName(), "why D:", e); + } + } + +} diff --git a/flock/src/nonplay/res/values-de/strings.xml b/flock/src/nonplay/res/values-de/strings.xml new file mode 100644 index 0000000..96372a4 --- /dev/null +++ b/flock/src/nonplay/res/values-de/strings.xml @@ -0,0 +1,25 @@ + + + + + + + Datenschutzerklärung und AGB]]> + Flock synchronisiert deine Kontakte und Kalender zwischen mehreren Geräten und schützt dabei deine Privatsphäre durch starke Verschlüsselung. Datenschutzerklärung und AGB]]> + + \ No newline at end of file diff --git a/flock/src/nonplay/res/values-ko_KR/strings.xml b/flock/src/nonplay/res/values-ko_KR/strings.xml new file mode 100644 index 0000000..98e2fa0 --- /dev/null +++ b/flock/src/nonplay/res/values-ko_KR/strings.xml @@ -0,0 +1,24 @@ + + + + + + + Flock은 사용자의 연락처와 달력을 일정을 암호화하여 개인정보를 보호함과 동시에, 다양한 기기에 동기화하여 사용할 수 있게 합니다. Privacy and Terms of Service]]> + + diff --git a/flock/src/nonplay/res/values/strings.xml b/flock/src/nonplay/res/values/strings.xml new file mode 100644 index 0000000..2b68d84 --- /dev/null +++ b/flock/src/nonplay/res/values/strings.xml @@ -0,0 +1,29 @@ + + + + + + + Privacy and Terms of Service]]> + Flock syncs your contacts and calendars between multiple devices while protecting your privacy with strong encryption. Privacy and Terms of Service]]> + + + Update available + Touch to install Flock update + + diff --git a/flock/libs/gradle-witness.jar b/libs/gradle-witness.jar similarity index 100% rename from flock/libs/gradle-witness.jar rename to libs/gradle-witness.jar