From 515b3f0f4ae0fc030d08ca3c98c8a1d3ca7458ee Mon Sep 17 00:00:00 2001 From: Volodymyr Buberenko Date: Mon, 28 Jun 2021 18:15:19 +0300 Subject: [PATCH] Update 3.5.0 (#637) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update all dependencies and configs, update code for Detekt * Prepare for next release (#494) * Prepare for next release * Update workflows and readme to mirror latest changes * Update publishing action name (#495) * Fixed typo on DialogData (#501) * Update README.md (#505) fix the typo * Fix setting request body plain text in transaction (#538) * Fix setting request body plain text in transaction * Add test for plain text request body * Switch to CircularProgressIndicator * Switch to Activity Result API * Add immutable flag to pending intents (#593) * Update Github Actions workflows to match latest ones * Bump version * Resolve lint issues * Remove test using newer OkHttp API * Remove breaking change with BuildConfig removal * Bump kotlinVersion from 1.5.10 to 1.5.20 (#639) Bumps `kotlinVersion` from 1.5.10 to 1.5.20. Updates `kotlin-gradle-plugin` from 1.5.10 to 1.5.20 - [Release notes](https://github.com/JetBrains/kotlin/releases) - [Changelog](https://github.com/JetBrains/kotlin/blob/v1.5.20/ChangeLog.md) - [Commits](https://github.com/JetBrains/kotlin/compare/v1.5.10...v1.5.20) Updates `kotlin-stdlib` from 1.5.10 to 1.5.20 - [Release notes](https://github.com/JetBrains/kotlin/releases) - [Changelog](https://github.com/JetBrains/kotlin/blob/v1.5.20/ChangeLog.md) - [Commits](https://github.com/JetBrains/kotlin/compare/v1.5.10...v1.5.20) --- updated-dependencies: - dependency-name: org.jetbrains.kotlin:kotlin-gradle-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.jetbrains.kotlin:kotlin-stdlib dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Nicola Corti Co-authored-by: Okan AYDIN Co-authored-by: Michał Sikora Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/auto_rebase.yaml | 2 +- .../workflows/gradle-wrapper-validation.yml | 3 +- .github/workflows/pre-merge.yaml | 35 ++++++++++- .github/workflows/publish-release.yaml | 4 +- .github/workflows/publish-snapshot.yaml | 7 ++- README.md | 11 ++-- build.gradle | 49 ++++++++------- gradle.properties | 6 +- gradle/gradle-mvn-push.gradle | 6 +- gradle/kotlin-static-analysis.gradle | 3 +- gradle/wrapper/gradle-wrapper.properties | 2 +- library-no-op/build.gradle | 6 +- .../com/chuckerteam/chucker/api/Chucker.kt | 2 + .../chucker/api/ChuckerCollector.kt | 1 + .../chucker/api/ChuckerInterceptor.kt | 1 + .../chucker/api/RetentionManager.kt | 1 + library/build.gradle | 12 +++- .../com/chuckerteam/chucker/api/Chucker.kt | 1 + .../chucker/api/ChuckerInterceptor.kt | 2 +- .../chucker/api/RetentionManager.kt | 4 ++ .../chucker/internal/data/model/DialogData.kt | 2 +- .../internal/support/ClearDatabaseService.kt | 4 ++ .../chucker/internal/support/ContextExt.kt | 2 +- .../chucker/internal/support/FormatUtils.kt | 10 +-- .../chucker/internal/support/IOUtils.kt | 5 +- .../internal/support/NotificationHelper.kt | 10 ++- .../ui/throwable/ThrowableListFragment.kt | 2 +- .../ui/transaction/TransactionListFragment.kt | 4 +- .../transaction/TransactionPayloadFragment.kt | 63 +++++++------------ .../chucker_fragment_transaction_payload.xml | 11 ++-- .../chucker/TestTransactionFactory.kt | 2 +- .../chucker/api/ChuckerInterceptorTest.kt | 38 ++++++++--- .../data/entity/HttpTransactionTupleTest.kt | 1 + .../internal/support/FormattedUrlTest.kt | 1 + .../chucker/internal/support/IOUtilsTest.kt | 2 + sample/build.gradle | 19 +++++- sample/src/debug/AndroidManifest.xml | 4 +- 37 files changed, 215 insertions(+), 123 deletions(-) diff --git a/.github/workflows/auto_rebase.yaml b/.github/workflows/auto_rebase.yaml index 79b327fa7..4e5d90586 100644 --- a/.github/workflows/auto_rebase.yaml +++ b/.github/workflows/auto_rebase.yaml @@ -14,7 +14,7 @@ jobs: with: fetch-depth: 0 - name: Automatic Rebase - uses: cirrus-actions/rebase@1.3.1 + uses: cirrus-actions/rebase@1.5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # https://github.community/t5/GitHub-Actions/Workflow-is-failing-if-no-job-can-be-ran-due-to-condition/m-p/38186#M3250 diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index 9240f77fb..abfbcc82f 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -2,8 +2,7 @@ name: Validate Gradle Wrapper on: push: branches: - - develop - - main + - develop pull_request: branches: - '*' diff --git a/.github/workflows/pre-merge.yaml b/.github/workflows/pre-merge.yaml index b51ae6f84..240a6dfe9 100644 --- a/.github/workflows/pre-merge.yaml +++ b/.github/workflows/pre-merge.yaml @@ -2,8 +2,7 @@ name: Pre Merge Checks on: push: branches: - - develop - - main + - develop pull_request: branches: - '*' @@ -16,8 +15,15 @@ jobs: runs-on: [ubuntu-latest] steps: + - name: Cancel Previous Runs + if: github.event_name == 'pull_request' + uses: styfle/cancel-workflow-action@0.9.0 + with: + access_token: ${{ github.token }} + - name: Checkout Repo uses: actions/checkout@v2 + - name: Cache Gradle Folders uses: actions/cache@v2 with: @@ -41,6 +47,7 @@ jobs: steps: - name: Checkout Repo uses: actions/checkout@v2 + - name: Cache Gradle Folders uses: actions/cache@v2 with: @@ -56,12 +63,35 @@ jobs: - name: Stop Gradle run: ./gradlew --stop + lint: + runs-on: [ubuntu-latest] + + steps: + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Cache Gradle Folders + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches/ + ~/.gradle/wrapper/ + key: cache-gradle-${{ hashFiles('build.gradle') }} + restore-keys: cache-gradle- + + - name: Run lint + run: ./gradlew lint + + - name: Stop Gradle + run: ./gradlew --stop + ktlint: runs-on: [ubuntu-latest] steps: - name: Checkout Repo uses: actions/checkout@v2 + - name: Cache Gradle Folders uses: actions/cache@v2 with: @@ -83,6 +113,7 @@ jobs: steps: - name: Checkout Repo uses: actions/checkout@v2 + - name: Cache Gradle Folders uses: actions/cache@v2 with: diff --git a/.github/workflows/publish-release.yaml b/.github/workflows/publish-release.yaml index b30afa7fb..441c7418e 100644 --- a/.github/workflows/publish-release.yaml +++ b/.github/workflows/publish-release.yaml @@ -25,10 +25,10 @@ jobs: name: 'chucker-release-artifacts' path: '~/.m2/repository/' - - name: Publish to the Snapshot Repository + - name: Publish to the Staging Repository run: ./gradlew publishReleasePublicationToStagingRepository env: ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_KEY }} ORG_GRADLE_PROJECT_SIGNING_PWD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PWD }} ORG_GRADLE_PROJECT_NEXUS_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_NEXUS_USERNAME }} - ORG_GRADLE_PROJECT_NEXUS_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_NEXUS_PASSWORD }} \ No newline at end of file + ORG_GRADLE_PROJECT_NEXUS_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_NEXUS_PASSWORD }} diff --git a/.github/workflows/publish-snapshot.yaml b/.github/workflows/publish-snapshot.yaml index 31f3588bd..2f7ee359f 100644 --- a/.github/workflows/publish-snapshot.yaml +++ b/.github/workflows/publish-snapshot.yaml @@ -2,7 +2,7 @@ name: Publish Snapshot on: push: branches: - - develop + - develop jobs: publish: @@ -10,6 +10,11 @@ jobs: runs-on: [ubuntu-latest] steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.0 + with: + access_token: ${{ github.token }} + - name: Checkout Repo uses: actions/checkout@v2 diff --git a/README.md b/README.md index 1ff8c69bb..b16393990 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,8 @@ Please note that you should add both the `library` and the the `library-no-op` v ```groovy dependencies { - debugImplementation "com.github.chuckerteam.chucker:library:3.3.0" - releaseImplementation "com.github.chuckerteam.chucker:library-no-op:3.3.0" + debugImplementation "com.github.chuckerteam.chucker:library:3.4.0" + releaseImplementation "com.github.chuckerteam.chucker:library-no-op:3.4.0" } ``` @@ -100,7 +100,6 @@ val chuckerInterceptor = ChuckerInterceptor.Builder(context) // is closed before being read like in Retrofit with Void and Unit types. .alwaysReadResponseBody(true) .build() -) // Don't forget to plug the ChuckerInterceptor inside the OkHttpClient val client = OkHttpClient.Builder() @@ -150,8 +149,8 @@ repositories { maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } dependencies { - debugImplementation "com.github.chuckerteam.chucker:library:3.3.1-SNAPSHOT" - releaseImplementation "com.github.chuckerteam.chucker:library-no-op:3.3.1-SNAPSHOT" + debugImplementation "com.github.chuckerteam.chucker:library:3.4.1-SNAPSHOT" + releaseImplementation "com.github.chuckerteam.chucker:library-no-op:3.4.1-SNAPSHOT" } ``` @@ -170,7 +169,7 @@ dependencies { ⚠️ Please note that the latest snapshot might be **unstable**. Use it at your own risk ⚠️ -If you're looking for the **latest stable version**, you can always find it on the top of the `main` branch. +If you're looking for the **latest stable version**, you can always find it in `Releases` section. ## FAQ ❓ diff --git a/build.gradle b/build.gradle index 85d250a26..7f2e90884 100644 --- a/build.gradle +++ b/build.gradle @@ -1,43 +1,42 @@ buildscript { ext { - kotlinVersion = '1.4.10' - androidGradleVersion = '4.1.0' - coroutineVersion = '1.4.0' + kotlinVersion = '1.5.20' + androidGradleVersion = '4.2.1' + coroutineVersion = '1.4.3' // Google libraries - appCompatVersion = '1.2.0' + activityVersion = '1.2.3' + appCompatVersion = '1.3.0' constraintLayoutVersion = '2.0.4' - materialComponentsVersion = '1.2.1' - roomVersion = '2.2.5' - fragmentVersion = '1.2.5' - lifecycleVersion = '2.2.0' + materialComponentsVersion = '1.3.0' + roomVersion = '2.3.0' + fragmentVersion = '1.3.5' + lifecycleVersion = '2.3.1' androidXCoreVersion = '2.1.0' paletteKtxVersion = '1.0.0' // Networking - gsonVersion = '2.8.6' - okhttp3Version = '3.12.10' + gsonVersion = '2.8.7' + okhttpVersion = '3.12.10' retrofitVersion = '2.6.4' // Debug and quality control - detektVersion = '1.14.0' - dokkaVersion = '1.4.10.2' - ktLintVersion = '0.39.0' - ktLintGradleVersion = '9.4.0' - leakcanaryVersion = '2.5' + detektVersion = '1.17.1' + dokkaVersion = '1.4.32' + ktLintGradleVersion = '10.0.0' + leakcanaryVersion = '2.7' // Testing androidxTestCoreVersion = '1.3.0' - junitGradlePluignVersion = '1.6.2.0' - junitVersion = '5.7.0' - mockkVersion = '1.10.2' - robolectricVersion = '4.4' - truthVersion = '1.1' + junitGradlePluignVersion = '1.7.1.1' + junitVersion = '5.7.2' + mockkVersion = '1.11.0' + robolectricVersion = '4.5.1' + truthVersion = '1.1.3' vintageJunitVersion = '4.13' } repositories { - jcenter() google() gradlePluginPortal() } @@ -57,8 +56,14 @@ allprojects { group = GROUP repositories { - jcenter() google() + mavenCentral() + jcenter { + content { + includeModule("org.jetbrains.trove4j", "trove4j") + includeModule("org.jetbrains.kotlinx", "kotlinx-html-jvm") + } + } } tasks.withType(Test) { diff --git a/gradle.properties b/gradle.properties index 4b2eea5a9..8d568f2f2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,9 +18,9 @@ org.gradle.parallel=true android.useAndroidX=true -VERSION_NAME=3.4.0 -# 3*100*100 + 4*100 + 0 => 30400 -VERSION_CODE=30400 +VERSION_NAME=3.5.0 +# 3*100*100 + 5*100 + 0 => 30500 +VERSION_CODE=30500 GROUP=com.github.chuckerteam.chucker POM_REPO_NAME=Chucker diff --git a/gradle/gradle-mvn-push.gradle b/gradle/gradle-mvn-push.gradle index 810b7d3d1..85c29dfd6 100644 --- a/gradle/gradle-mvn-push.gradle +++ b/gradle/gradle-mvn-push.gradle @@ -15,7 +15,7 @@ dokkaJavadoc { skipEmptyPackages.set(true) perPackageOption { - prefix.set("com.chuckerteam.chucker.internal") + matchingRegex.set(".*\\.internal.*") suppress.set(true) } } @@ -95,6 +95,10 @@ afterEvaluate { name = 'Olivier Perez' email = 'olivier@olivierperez.fr' } + developer { + id = 'michalsikora90' + name = 'Michal Sikora' + } } } } diff --git a/gradle/kotlin-static-analysis.gradle b/gradle/kotlin-static-analysis.gradle index f75383206..ca8d071ce 100644 --- a/gradle/kotlin-static-analysis.gradle +++ b/gradle/kotlin-static-analysis.gradle @@ -2,7 +2,6 @@ apply plugin: 'io.gitlab.arturbosch.detekt' apply plugin: 'org.jlleitschuh.gradle.ktlint' ktlint { - version = rootProject.ext.ktLintVersion debug = false verbose = true android = false @@ -13,7 +12,7 @@ ktlint { include fileTree("scripts/") } filter { - exclude("**/generated/**") + exclude { element -> element.file.path.contains("generated/") } include("**/kotlin/**") } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 14e30f741..29e413457 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/library-no-op/build.gradle b/library-no-op/build.gradle index cd254b6fd..a78cebae2 100644 --- a/library-no-op/build.gradle +++ b/library-no-op/build.gradle @@ -18,11 +18,15 @@ android { lintOptions { warningsAsErrors true abortOnError true + // We don't want to impose RTL on consuming applications. + disable 'RtlEnabled' + // Don't fail build if some dependencies outdated + disable 'GradleDependency' } } dependencies { - api "com.squareup.okhttp3:okhttp:$okhttp3Version" + api "com.squareup.okhttp3:okhttp:$okhttpVersion" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" } diff --git a/library-no-op/src/main/java/com/chuckerteam/chucker/api/Chucker.kt b/library-no-op/src/main/java/com/chuckerteam/chucker/api/Chucker.kt index d33b68843..e7d2a90c7 100644 --- a/library-no-op/src/main/java/com/chuckerteam/chucker/api/Chucker.kt +++ b/library-no-op/src/main/java/com/chuckerteam/chucker/api/Chucker.kt @@ -6,10 +6,12 @@ import android.content.Intent /** * No-op implementation. */ +@Suppress("UnusedPrivateMember") public object Chucker { @Deprecated("This variable will be removed in 4.x release") public const val SCREEN_HTTP: Int = 1 + @Deprecated("This variable will be removed in 4.x release") public const val SCREEN_ERROR: Int = 2 diff --git a/library-no-op/src/main/java/com/chuckerteam/chucker/api/ChuckerCollector.kt b/library-no-op/src/main/java/com/chuckerteam/chucker/api/ChuckerCollector.kt index c8a8f8272..debbfc81f 100644 --- a/library-no-op/src/main/java/com/chuckerteam/chucker/api/ChuckerCollector.kt +++ b/library-no-op/src/main/java/com/chuckerteam/chucker/api/ChuckerCollector.kt @@ -5,6 +5,7 @@ import android.content.Context /** * No-op implementation. */ +@Suppress("UnusedPrivateMember") public class ChuckerCollector @JvmOverloads constructor( context: Context, public var showNotification: Boolean = true, diff --git a/library-no-op/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt b/library-no-op/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt index 95365372d..2a600f731 100644 --- a/library-no-op/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt +++ b/library-no-op/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt @@ -9,6 +9,7 @@ import kotlin.jvm.Throws /** * No-op implementation. */ +@Suppress("UnusedPrivateMember") public class ChuckerInterceptor @JvmOverloads constructor( context: Context, collector: Any? = null, diff --git a/library-no-op/src/main/java/com/chuckerteam/chucker/api/RetentionManager.kt b/library-no-op/src/main/java/com/chuckerteam/chucker/api/RetentionManager.kt index fa64a4288..4633125c2 100644 --- a/library-no-op/src/main/java/com/chuckerteam/chucker/api/RetentionManager.kt +++ b/library-no-op/src/main/java/com/chuckerteam/chucker/api/RetentionManager.kt @@ -5,6 +5,7 @@ import android.content.Context /** * No-op implementation. */ +@Suppress("UnusedPrivateMember") public class RetentionManager @JvmOverloads constructor( context: Context, retentionPeriod: Any? = null diff --git a/library/build.gradle b/library/build.gradle index 86de60d8c..5f6b0f6f1 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -28,6 +28,10 @@ android { lintOptions { warningsAsErrors true abortOnError true + // We don't want to impose RTL on consuming applications. + disable 'RtlEnabled' + // Don't fail build if some dependencies outdated + disable 'GradleDependency' } testOptions { @@ -49,6 +53,7 @@ dependencies { implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion" implementation "androidx.palette:palette-ktx:$paletteKtxVersion" + implementation "androidx.activity:activity-ktx:$activityVersion" implementation "androidx.fragment:fragment-ktx:$fragmentVersion" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion" @@ -56,11 +61,13 @@ dependencies { implementation "androidx.room:room-runtime:$roomVersion" kapt "androidx.room:room-compiler:$roomVersion" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutineVersion" implementation "com.google.code.gson:gson:$gsonVersion" - api "com.squareup.okhttp3:okhttp:$okhttp3Version" + + api platform("com.squareup.okhttp3:okhttp-bom:$okhttpVersion") + api "com.squareup.okhttp3:okhttp" + testImplementation "com.squareup.okhttp3:mockwebserver" testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion" @@ -68,7 +75,6 @@ dependencies { testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$vintageJunitVersion" testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion" testImplementation "io.mockk:mockk:$mockkVersion" - testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp3Version" testImplementation "androidx.test:core:$androidxTestCoreVersion" testImplementation "androidx.arch.core:core-testing:$androidXCoreVersion" testImplementation "com.google.truth:truth:$truthVersion" diff --git a/library/src/main/java/com/chuckerteam/chucker/api/Chucker.kt b/library/src/main/java/com/chuckerteam/chucker/api/Chucker.kt index 54369a30d..7e2b73faf 100644 --- a/library/src/main/java/com/chuckerteam/chucker/api/Chucker.kt +++ b/library/src/main/java/com/chuckerteam/chucker/api/Chucker.kt @@ -14,6 +14,7 @@ public object Chucker { @Deprecated("This variable will be removed in 4.x release") public const val SCREEN_HTTP: Int = 1 + @Deprecated("This variable will be removed in 4.x release") public const val SCREEN_ERROR: Int = 2 diff --git a/library/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt b/library/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt index b10fc1a22..6ba752af3 100755 --- a/library/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt +++ b/library/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt @@ -154,7 +154,7 @@ public class ChuckerInterceptor internal constructor( val content = io.readFromBuffer(buffer, charset, maxContentLength) transaction.requestBody = content } else { - transaction.isResponseBodyPlainText = false + transaction.isRequestBodyPlainText = false } } } diff --git a/library/src/main/java/com/chuckerteam/chucker/api/RetentionManager.kt b/library/src/main/java/com/chuckerteam/chucker/api/RetentionManager.kt index 6edc1a0f3..182d2320b 100644 --- a/library/src/main/java/com/chuckerteam/chucker/api/RetentionManager.kt +++ b/library/src/main/java/com/chuckerteam/chucker/api/RetentionManager.kt @@ -23,6 +23,7 @@ public class RetentionManager @JvmOverloads constructor( // The actual retention period in milliseconds (default to ONE_WEEK) private val period: Long = toMillis(retentionPeriod) + // How often the cleanup should happen private val cleanupFrequency: Long private val prefs: SharedPreferences = context.getSharedPreferences(PREFS_NAME, 0) @@ -86,10 +87,13 @@ public class RetentionManager @JvmOverloads constructor( public enum class Period { /** Retain data for the last hour. */ ONE_HOUR, + /** Retain data for the last day. */ ONE_DAY, + /** Retain data for the last week. */ ONE_WEEK, + /** Retain data forever. */ FOREVER } diff --git a/library/src/main/java/com/chuckerteam/chucker/internal/data/model/DialogData.kt b/library/src/main/java/com/chuckerteam/chucker/internal/data/model/DialogData.kt index 7a32de03b..11423905d 100644 --- a/library/src/main/java/com/chuckerteam/chucker/internal/data/model/DialogData.kt +++ b/library/src/main/java/com/chuckerteam/chucker/internal/data/model/DialogData.kt @@ -3,6 +3,6 @@ package com.chuckerteam.chucker.internal.data.model internal data class DialogData( val title: String, val message: String, - val postiveButtonText: String?, + val positiveButtonText: String?, val negativeButtonText: String? ) diff --git a/library/src/main/java/com/chuckerteam/chucker/internal/support/ClearDatabaseService.kt b/library/src/main/java/com/chuckerteam/chucker/internal/support/ClearDatabaseService.kt index b55fa5164..bc7bdea98 100644 --- a/library/src/main/java/com/chuckerteam/chucker/internal/support/ClearDatabaseService.kt +++ b/library/src/main/java/com/chuckerteam/chucker/internal/support/ClearDatabaseService.kt @@ -33,6 +33,10 @@ internal class ClearDatabaseService : IntentService(CLEAN_DATABASE_SERVICE_NAME) sealed class ClearAction : Serializable { object Transaction : ClearAction() object Error : ClearAction() + + companion object { + private const val serialVersionUID: Long = 987654321 + } } companion object { diff --git a/library/src/main/java/com/chuckerteam/chucker/internal/support/ContextExt.kt b/library/src/main/java/com/chuckerteam/chucker/internal/support/ContextExt.kt index fa28b1558..c81fafd36 100644 --- a/library/src/main/java/com/chuckerteam/chucker/internal/support/ContextExt.kt +++ b/library/src/main/java/com/chuckerteam/chucker/internal/support/ContextExt.kt @@ -12,7 +12,7 @@ internal fun Context.showDialog( MaterialAlertDialogBuilder(this) .setTitle(dialogData.title) .setMessage(dialogData.message) - .setPositiveButton(dialogData.postiveButtonText) { _, _ -> + .setPositiveButton(dialogData.positiveButtonText) { _, _ -> onPositiveClick?.invoke() } .setNegativeButton(dialogData.negativeButtonText) { _, _ -> diff --git a/library/src/main/java/com/chuckerteam/chucker/internal/support/FormatUtils.kt b/library/src/main/java/com/chuckerteam/chucker/internal/support/FormatUtils.kt index 7fad6457a..ef70ccf6d 100644 --- a/library/src/main/java/com/chuckerteam/chucker/internal/support/FormatUtils.kt +++ b/library/src/main/java/com/chuckerteam/chucker/internal/support/FormatUtils.kt @@ -84,11 +84,11 @@ internal object FormatUtils { transform(domSource, result) } writer.toString() - } catch (e: SAXParseException) { + } catch (_: SAXParseException) { xml - } catch (io: IOException) { + } catch (_: IOException) { xml - } catch (t: TransformerException) { + } catch (_: TransformerException) { xml } } @@ -104,9 +104,9 @@ internal object FormatUtils { val value = if (keyValue.size > 1) URLDecoder.decode(keyValue[1], "UTF-8") else "" "$key: $value" } - } catch (e: IllegalArgumentException) { + } catch (_: IllegalArgumentException) { form - } catch (e: UnsupportedEncodingException) { + } catch (_: UnsupportedEncodingException) { form } } diff --git a/library/src/main/java/com/chuckerteam/chucker/internal/support/IOUtils.kt b/library/src/main/java/com/chuckerteam/chucker/internal/support/IOUtils.kt index d31e4aa45..3f0bb41f3 100644 --- a/library/src/main/java/com/chuckerteam/chucker/internal/support/IOUtils.kt +++ b/library/src/main/java/com/chuckerteam/chucker/internal/support/IOUtils.kt @@ -19,6 +19,7 @@ internal class IOUtils(private val context: Context) { * Returns true if the body in question probably contains human readable text. Uses a small sample * of code points to detect unicode control characters commonly used in binary file signatures. */ + @Suppress("UnusedPrivateMember") fun isPlaintext(buffer: Buffer): Boolean { try { val prefix = Buffer() @@ -34,7 +35,7 @@ internal class IOUtils(private val context: Context) { } } return true - } catch (e: EOFException) { + } catch (_: EOFException) { return false // Truncated UTF-8 sequence. } } @@ -45,7 +46,7 @@ internal class IOUtils(private val context: Context) { var body = "" try { body = buffer.readString(maxBytes, charset) - } catch (e: EOFException) { + } catch (_: EOFException) { body += context.getString(R.string.chucker_body_unexpected_eof) } diff --git a/library/src/main/java/com/chuckerteam/chucker/internal/support/NotificationHelper.kt b/library/src/main/java/com/chuckerteam/chucker/internal/support/NotificationHelper.kt index 498f7b9f8..8c841b1b5 100644 --- a/library/src/main/java/com/chuckerteam/chucker/internal/support/NotificationHelper.kt +++ b/library/src/main/java/com/chuckerteam/chucker/internal/support/NotificationHelper.kt @@ -48,7 +48,7 @@ internal class NotificationHelper(val context: Context) { context, TRANSACTION_NOTIFICATION_ID, Chucker.getLaunchIntent(context), - PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_UPDATE_CURRENT or immutableFlag() ) } @@ -155,7 +155,7 @@ internal class NotificationHelper(val context: Context) { context, INTENT_REQUEST_CODE, deleteIntent, - PendingIntent.FLAG_ONE_SHOT + PendingIntent.FLAG_ONE_SHOT or immutableFlag() ) return NotificationCompat.Action(R.drawable.chucker_ic_delete_white, clearTitle, intent) } @@ -172,4 +172,10 @@ internal class NotificationHelper(val context: Context) { notificationManager.cancel(TRANSACTION_NOTIFICATION_ID) notificationManager.cancel(ERROR_NOTIFICATION_ID) } + + private fun immutableFlag() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PendingIntent.FLAG_IMMUTABLE + } else { + 0 + } } diff --git a/library/src/main/java/com/chuckerteam/chucker/internal/ui/throwable/ThrowableListFragment.kt b/library/src/main/java/com/chuckerteam/chucker/internal/ui/throwable/ThrowableListFragment.kt index c257eab60..9162f85a5 100644 --- a/library/src/main/java/com/chuckerteam/chucker/internal/ui/throwable/ThrowableListFragment.kt +++ b/library/src/main/java/com/chuckerteam/chucker/internal/ui/throwable/ThrowableListFragment.kt @@ -79,7 +79,7 @@ internal class ThrowableListFragment : Fragment(), ThrowableAdapter.ThrowableCli val confirmationDialogData = DialogData( title = getString(R.string.chucker_clear), message = getString(R.string.chucker_clear_throwable_confirmation), - postiveButtonText = getString(R.string.chucker_clear), + positiveButtonText = getString(R.string.chucker_clear), negativeButtonText = getString(R.string.chucker_cancel) ) requireContext().showDialog( diff --git a/library/src/main/java/com/chuckerteam/chucker/internal/ui/transaction/TransactionListFragment.kt b/library/src/main/java/com/chuckerteam/chucker/internal/ui/transaction/TransactionListFragment.kt index b9d6fa0ce..0d5b600b3 100644 --- a/library/src/main/java/com/chuckerteam/chucker/internal/ui/transaction/TransactionListFragment.kt +++ b/library/src/main/java/com/chuckerteam/chucker/internal/ui/transaction/TransactionListFragment.kt @@ -146,14 +146,14 @@ internal class TransactionListFragment : private fun getClearDialogData(): DialogData = DialogData( title = getString(R.string.chucker_clear), message = getString(R.string.chucker_clear_http_confirmation), - postiveButtonText = getString(R.string.chucker_clear), + positiveButtonText = getString(R.string.chucker_clear), negativeButtonText = getString(R.string.chucker_cancel) ) private fun getExportDialogData(): DialogData = DialogData( title = getString(R.string.chucker_export), message = getString(R.string.chucker_export_http_confirmation), - postiveButtonText = getString(R.string.chucker_export), + positiveButtonText = getString(R.string.chucker_export), negativeButtonText = getString(R.string.chucker_cancel) ) diff --git a/library/src/main/java/com/chuckerteam/chucker/internal/ui/transaction/TransactionPayloadFragment.kt b/library/src/main/java/com/chuckerteam/chucker/internal/ui/transaction/TransactionPayloadFragment.kt index aaeeb95c5..f5b3fb6c6 100644 --- a/library/src/main/java/com/chuckerteam/chucker/internal/ui/transaction/TransactionPayloadFragment.kt +++ b/library/src/main/java/com/chuckerteam/chucker/internal/ui/transaction/TransactionPayloadFragment.kt @@ -1,9 +1,7 @@ package com.chuckerteam.chucker.internal.ui.transaction import android.annotation.SuppressLint -import android.app.Activity import android.content.Context -import android.content.Intent import android.graphics.Color import android.net.Uri import android.os.Build @@ -15,7 +13,7 @@ import android.view.MenuInflater import android.view.View import android.view.ViewGroup import android.widget.Toast -import androidx.annotation.RequiresApi +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat import androidx.core.text.HtmlCompat @@ -35,8 +33,6 @@ import java.io.FileNotFoundException import java.io.FileOutputStream import java.io.IOException -private const val GET_FILE_FOR_SAVING_REQUEST_CODE: Int = 43 - internal class TransactionPayloadFragment : Fragment(), SearchView.OnQueryTextListener { @@ -46,6 +42,27 @@ internal class TransactionPayloadFragment : arguments?.getSerializable(ARG_TYPE) as PayloadType } + private val saveToFile = registerForActivityResult(ActivityResultContracts.CreateDocument()) { uri -> + val transaction = viewModel.transaction.value + if (uri != null && transaction != null) { + lifecycleScope.launch { + val result = saveToFile(payloadType, uri, transaction) + val toastMessageId = if (result) { + R.string.chucker_file_saved + } else { + R.string.chucker_file_not_saved + } + Toast.makeText(context, toastMessageId, Toast.LENGTH_SHORT).show() + } + } else { + Toast.makeText( + requireContext(), + R.string.chucker_save_failed_to_open_document, + Toast.LENGTH_SHORT + ).show() + } + } + private lateinit var payloadBinding: ChuckerFragmentTransactionPayloadBinding private val payloadAdapter = TransactionBodyAdapter() @@ -179,42 +196,8 @@ internal class TransactionPayloadFragment : foregroundSpanColor = ContextCompat.getColor(context, R.color.chucker_foreground_span_color) } - @RequiresApi(Build.VERSION_CODES.KITKAT) private fun createFileToSaveBody() { - val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply { - addCategory(Intent.CATEGORY_OPENABLE) - putExtra(Intent.EXTRA_TITLE, "$DEFAULT_FILE_PREFIX${System.currentTimeMillis()}") - type = "*/*" - } - if (intent.resolveActivity(requireActivity().packageManager) != null) { - startActivityForResult(intent, GET_FILE_FOR_SAVING_REQUEST_CODE) - } else { - Toast.makeText( - requireContext(), - R.string.chucker_save_failed_to_open_document, - Toast.LENGTH_SHORT - ).show() - } - } - - override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { - if (requestCode == GET_FILE_FOR_SAVING_REQUEST_CODE && resultCode == Activity.RESULT_OK) { - val uri = resultData?.data - val transaction = viewModel.transaction.value - if (uri != null && transaction != null) { - lifecycleScope.launch { - val result = saveToFile(payloadType, uri, transaction) - val toastMessageId = if (result) { - R.string.chucker_file_saved - } else { - R.string.chucker_file_not_saved - } - Toast.makeText(context, toastMessageId, Toast.LENGTH_SHORT).show() - } - } else { - Toast.makeText(context, R.string.chucker_file_not_saved, Toast.LENGTH_SHORT).show() - } - } + saveToFile.launch("$DEFAULT_FILE_PREFIX${System.currentTimeMillis()}") } override fun onQueryTextSubmit(query: String): Boolean = false diff --git a/library/src/main/res/layout/chucker_fragment_transaction_payload.xml b/library/src/main/res/layout/chucker_fragment_transaction_payload.xml index 12628b931..35abe09a8 100755 --- a/library/src/main/res/layout/chucker_fragment_transaction_payload.xml +++ b/library/src/main/res/layout/chucker_fragment_transaction_payload.xml @@ -7,9 +7,8 @@ android:animateLayoutChanges="true" tools:context="com.chuckerteam.chucker.internal.ui.transaction.TransactionPayloadFragment"> - + app:layout_constraintVertical_bias="1" + app:tint="@color/chucker_color_primary" /> + app:layout_constraintTop_toTopOf="parent" /> () every { mockBuffer.size() } returns 100L @@ -87,6 +88,7 @@ internal class IOUtilsTest { } @Test + @Suppress("MaxLineLength") fun readFromBuffer_unexpectedEOF() { val mockBuffer = mockk() every { mockBuffer.size() } returns 100L diff --git a/sample/build.gradle b/sample/build.gradle index 82f4d6213..312949d67 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -41,21 +41,34 @@ android { lintOptions { warningsAsErrors true abortOnError true + disable 'AcceptsUserCertificates' + // Don't fail build if some dependencies outdated + disable 'GradleDependency' } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions.jvmTarget = "1.8" } dependencies { debugImplementation project(':library') releaseImplementation project(':library-no-op') + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" + implementation "com.google.android.material:material:$materialComponentsVersion" implementation "androidx.appcompat:appcompat:$appCompatVersion" - implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3Version" + implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion" + + implementation "com.squareup.okhttp3:logging-interceptor:$okhttpVersion" implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion" - debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanaryVersion" - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" + debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanaryVersion" } apply from: rootProject.file('gradle/kotlin-static-analysis.gradle') \ No newline at end of file diff --git a/sample/src/debug/AndroidManifest.xml b/sample/src/debug/AndroidManifest.xml index 75b1f89aa..0f8158b85 100644 --- a/sample/src/debug/AndroidManifest.xml +++ b/sample/src/debug/AndroidManifest.xml @@ -1,9 +1,9 @@ - + tools:targetApi="n">