diff --git a/.travis.yml b/.travis.yml index 12dae44b..0a8c9598 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,9 @@ language: android jdk: - oraclejdk8 +git: + depth: false + env: matrix: - ANDROID_API=28 EMULATOR_API=24 @@ -54,8 +57,6 @@ cache: - $HOME/.android/build-cache before_install: - # Deep clone so we can get an accurate commit count for version code - - git fetch --unshallow # Unencrypt server account key for play publisher - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then openssl aes-256-cbc -K $encrypted_3476a8f5fa31_key -iv $encrypted_3476a8f5fa31_iv -in play-service-account-key.json.enc -out play-service-account-key.json diff --git a/Makefile b/Makefile index 83c7c712..92c82e13 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ deploy: check-env git checkout dev git checkout master git merge dev --no-edit - git tag -a $(TAG) + git tag $(TAG) git push && git push --tags git checkout dev @@ -12,7 +12,7 @@ redeploy: check-env git merge dev --no-edit git tag -d $(TAG) git push origin :refs/tags/$(TAG) - git tag -a $(TAG) + git tag $(TAG) git push && git push --tags git checkout dev diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 695ab17e..a93b0aaf 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -38,9 +38,9 @@ bugsnag { } play { - serviceAccountCredentials = file("../play-service-account-key.json") defaultToAppBundles = true track = "beta" + serviceAccountCredentials = file("../play-service-account-key.json") } // query git for the SHA, Tag and commit count. Use these to automate versioning. @@ -55,25 +55,19 @@ val gitCommitCount = 2007050 + Integer.parseInt( android { compileSdkVersion(28) - defaultConfig.apply { + defaultConfig { applicationId = "com.shalzz.attendance" minSdkVersion(16) targetSdkVersion(28) - multiDexEnabled = true versionCode = gitCommitCount versionName = gitTag - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - vectorDrawables.useSupportLibrary = true + multiDexEnabled = true // viewBinding.isEnabled = true + vectorDrawables.useSupportLibrary = true + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" resConfig("en") resValue("string", "app_version", versionName!!) - - // Needed because of this https://github.com/robolectric/robolectric/issues/{1399, 3826} - testOptions.unitTests.isIncludeAndroidResources = true - testOptions.unitTests.isReturnDefaultValues = true - javaCompileOptions { annotationProcessorOptions { arguments = mapOf( @@ -157,9 +151,17 @@ android { } } - //Needed because of this https://github.com/square/okio/issues/58 + // Needed because of this https://github.com/robolectric/robolectric/issues/{1399, 3826} + testOptions { + unitTests.isReturnDefaultValues = true + unitTests.isIncludeAndroidResources = true + } + lintOptions { - disable("InvalidPackage") + textReport = true + textOutput("stdout") + //Needed because of this https://github.com/square/okio/issues/58 +// disable("InvalidPackage") } //Needed because of this https://github.com/ReactiveX/RxJava/issues/4445 @@ -168,23 +170,27 @@ android { } } +kapt { + useBuildCache = true +} + dependencies { val DAGGER_VERSION = "2.24" val ESPRESSO_VERSION = "3.1.0" - val RETROFIT_VERSION = "2.5.0" - val MOSHI_VERSION = "1.9.0" + val RETROFIT_VERSION = "2.6.2" + val MOSHI_VERSION = "1.8.0" val ROOM_VERSION = "2.2.1" val NAV_VERSION = "1.0.0" // TODO: re-evaluate when RxJava is completely replaced with kotlin co-routines - implementation("com.android.support:multidex:1.0.3") + implementation("androidx.multidex:multidex:2.0.1") implementation(kotlin("stdlib-jdk7", KotlinCompilerVersion.VERSION)) - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0") - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0") - implementation("androidx.core:core-ktx:1.0.2") + implementation("androidx.core:core-ktx:1.1.0") implementation("android.arch.navigation:navigation-fragment-ktx:$NAV_VERSION") implementation("android.arch.navigation:navigation-ui-ktx:$NAV_VERSION") @@ -225,6 +231,7 @@ dependencies { implementation("com.squareup.moshi:moshi:$MOSHI_VERSION") implementation("com.squareup.moshi:moshi-adapters:$MOSHI_VERSION") kapt("com.squareup.moshi:moshi-kotlin-codegen:$MOSHI_VERSION") +// implementation("com.squareup.moshi:moshi-kotlin:1.9.1") implementation("com.malinskiy:materialicons:1.0.2") implementation("com.github.amlcurran.showcaseview:library:5.4.0") @@ -279,3 +286,6 @@ dependencies { resolutionStrategy.force("org.checkerframework:checker-compat-qual:2.5.3") } } + +// Add this at the bottom of your file to actually apply the plugin +apply(mapOf("plugin" to "com.google.gms.google-services")) \ No newline at end of file diff --git a/app/proguard/proguard-butterknife-7.pro b/app/proguard/proguard-butterknife-7.pro deleted file mode 100644 index a04d9bc1..00000000 --- a/app/proguard/proguard-butterknife-7.pro +++ /dev/null @@ -1,13 +0,0 @@ -# ButterKnife 7 - --keep class butterknife.** { *; } --dontwarn butterknife.internal.** --keep class **$$ViewBinder { *; } - --keepclasseswithmembernames class * { - @butterknife.* ; -} - --keepclasseswithmembernames class * { - @butterknife.* ; -} \ No newline at end of file diff --git a/app/proguard/proguard-moshi.pro b/app/proguard/proguard-moshi.pro index f99638fb..1488b0ce 100644 --- a/app/proguard/proguard-moshi.pro +++ b/app/proguard/proguard-moshi.pro @@ -13,6 +13,48 @@ ; } +# Retain generated target class's synthetic defaults constructor and keep DefaultConstructorMarker's +# name. We will look this up reflectively to invoke the type's constructor. +# +# We can't _just_ keep the defaults constructor because Proguard/R8's spec doesn't allow wildcard +# matching preceding parameters. +-keepnames class kotlin.jvm.internal.DefaultConstructorMarker +-keepclassmembers @com.squareup.moshi.JsonClass @kotlin.Metadata class * { + synthetic (...); +} + +# Retain generated JsonAdapters if annotated type is retained. +-if @com.squareup.moshi.JsonClass class * +-keep class <1>JsonAdapter { + (...); + ; +} +-if @com.squareup.moshi.JsonClass class **$* +-keep class <1>_<2>JsonAdapter { + (...); + ; +} +-if @com.squareup.moshi.JsonClass class **$*$* +-keep class <1>_<2>_<3>JsonAdapter { + (...); + ; +} +-if @com.squareup.moshi.JsonClass class **$*$*$* +-keep class <1>_<2>_<3>_<4>JsonAdapter { + (...); + ; +} +-if @com.squareup.moshi.JsonClass class **$*$*$*$* +-keep class <1>_<2>_<3>_<4>_<5>JsonAdapter { + (...); + ; +} +-if @com.squareup.moshi.JsonClass class **$*$*$*$*$* +-keep class <1>_<2>_<3>_<4>_<5>_<6>JsonAdapter { + (...); + ; +} + # The name of @JsonClass types is used to look up the generated adapter. -keepnames @com.squareup.moshi.JsonClass class * diff --git a/app/proguard/proguard-retrofit2.pro b/app/proguard/proguard-retrofit2.pro index af872842..66b2b096 100644 --- a/app/proguard/proguard-retrofit2.pro +++ b/app/proguard/proguard-retrofit2.pro @@ -21,8 +21,9 @@ # Top-level functions that can only be used by Kotlin. -dontwarn retrofit2.KotlinExtensions +-dontwarn retrofit2.KotlinExtensions$* # With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy # and replaces all potential values with null. Explicitly keeping the interfaces prevents this. -if interface * { @retrofit2.http.* ; } --keep,allowobfuscation interface <1> \ No newline at end of file +-keep,allowobfuscation interface <1> diff --git a/app/proguard/proguard-rules.pro b/app/proguard/proguard-rules.pro index ffb767c2..27a3d19f 100644 --- a/app/proguard/proguard-rules.pro +++ b/app/proguard/proguard-rules.pro @@ -10,6 +10,7 @@ # Application classes that will be serialized/deserialized over Gson -keep class com.shalzz.attendance.data.model.** { *; } +-keep class com.shalzz.attendance.data.model.entity.** { *; } -verbose diff --git a/app/src/main/java/com/shalzz/attendance/sync/Authenticator.kt b/app/src/main/java/com/shalzz/attendance/sync/Authenticator.kt index 2e77a543..db8fd9c1 100644 --- a/app/src/main/java/com/shalzz/attendance/sync/Authenticator.kt +++ b/app/src/main/java/com/shalzz/attendance/sync/Authenticator.kt @@ -47,7 +47,6 @@ class Authenticator(private val mDataManager: DataManager, val intent = Intent(mContext, AuthenticatorActivity::class.java) intent.putExtra(AuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType) intent.putExtra(AuthenticatorActivity.ARG_AUTH_TYPE, authTokenType) - intent.putExtra(AuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, true) intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response) val bundle = Bundle() @@ -140,14 +139,4 @@ class Authenticator(private val mDataManager: DataManager, result.putBoolean(KEY_BOOLEAN_RESULT, false) return result } - - private fun isAccountAvailable(account: Account, accountManager: AccountManager): Boolean { - val availableAccounts = accountManager.getAccountsByType(account.type) - for (availableAccount in availableAccounts) { - if (account.name == availableAccount.name && account.type == availableAccount.type) { - return true - } - } - return false - } } diff --git a/app/src/main/java/com/shalzz/attendance/ui/attendance/AttendancePresenter.kt b/app/src/main/java/com/shalzz/attendance/ui/attendance/AttendancePresenter.kt index e5002cfe..56044934 100644 --- a/app/src/main/java/com/shalzz/attendance/ui/attendance/AttendancePresenter.kt +++ b/app/src/main/java/com/shalzz/attendance/ui/attendance/AttendancePresenter.kt @@ -66,7 +66,6 @@ internal constructor(private val mDataManager: DataManager, @param:ApplicationCo override fun onNext(subject: Subject) {} override fun onError(error: Throwable) { - Timber.e(error) if (error !is RetrofitException) { Timber.e(error) } diff --git a/app/src/main/java/com/shalzz/attendance/ui/login/AuthenticatorActivity.kt b/app/src/main/java/com/shalzz/attendance/ui/login/AuthenticatorActivity.kt index 63ce00c0..25a63b83 100644 --- a/app/src/main/java/com/shalzz/attendance/ui/login/AuthenticatorActivity.kt +++ b/app/src/main/java/com/shalzz/attendance/ui/login/AuthenticatorActivity.kt @@ -74,16 +74,20 @@ class AuthenticatorActivity: AccountAuthenticatorActivity(), Timber.d( "> finishLogin") val accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME) + Timber.d("accountName: %s", accountName) val account = Account(accountName, intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE)) - if (getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false)) { + // In case the user tries to add the same account again. + if (!isAccountAvailable(account, mAccountManager)) { Timber.d("> finishLogin > addAccountExplicitly") val authtoken = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN) val authtokenType = mAuthTokenType // Creating the account on the device and setting the auth regId we got // (Not setting the auth regId will cause another call to the server to authenticate the user) - mAccountManager.addAccountExplicitly(account, null, null) + mAccountManager.addAccountExplicitly(account, + intent.getStringExtra(ARG_ACCOUNT_PASSWORD), + null) mAccountManager.setAuthToken(account, authtokenType, authtoken) // Set up sync @@ -96,10 +100,19 @@ class AuthenticatorActivity: AccountAuthenticatorActivity(), finish() } + private fun isAccountAvailable(account: Account, accountManager: AccountManager): Boolean { + val availableAccounts = accountManager.getAccountsByType(account.type) + for (availableAccount in availableAccounts) { + if (account.name == availableAccount.name && account.type == availableAccount.type) { + return true + } + } + return false + } + companion object { var ARG_ACCOUNT_TYPE: String = "ACCOUNT_TYPE" var ARG_ACCOUNT_PASSWORD: String = "ACCOUNT_PASSWORD" var ARG_AUTH_TYPE: String = "AUTH_TYPE" - var ARG_IS_ADDING_NEW_ACCOUNT: String = "IS_ADDING_ACCOUNT" } } \ No newline at end of file diff --git a/app/src/main/java/com/shalzz/attendance/ui/main/MainActivity.kt b/app/src/main/java/com/shalzz/attendance/ui/main/MainActivity.kt index debf3814..f69e0e14 100644 --- a/app/src/main/java/com/shalzz/attendance/ui/main/MainActivity.kt +++ b/app/src/main/java/com/shalzz/attendance/ui/main/MainActivity.kt @@ -148,6 +148,7 @@ class MainActivity : BaseActivity(), MainMvpView, BillingProvider { if (!mPreferencesHelper.loginStatus) { val ourIntent = Intent(this, AuthenticatorActivity::class.java) + ourIntent.putExtra(AuthenticatorActivity.ARG_AUTH_TYPE, MyAccountManager.AUTHTOKEN_TYPE_READ_ONLY) startActivityForResult(ourIntent, ACTIVITY_RESULT_CODE_AUTHENTICATION) } }