Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.browser.auth.AuthTabIntent
import androidx.browser.customtabs.CustomTabsClient
import androidx.browser.customtabs.CustomTabsIntent

internal class AuthTabInternalClient (
internal class AuthTabInternalClient(
private val authTabIntentBuilder: AuthTabIntent.Builder = AuthTabIntent.Builder(),
private val customTabsIntentBuilder: CustomTabsIntent.Builder = CustomTabsIntent.Builder()
) {
Expand All @@ -30,7 +30,7 @@ internal class AuthTabInternalClient (
context: Context,
url: Uri,
returnUrlScheme: String?,
appLinkUri: Uri?,
@Suppress("UnusedParameter") appLinkUri: Uri?,
successAppLinkUri: Uri?,
launcher: ActivityResultLauncher<Intent>?,
launchType: LaunchType?,
Expand Down Expand Up @@ -68,4 +68,4 @@ internal class AuthTabInternalClient (
}
customTabsIntent.launchUrl(context, url)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.json.JSONObject
/**
* The result of a browser switch obtained from [BrowserSwitchClient.completeRequest]
*/
@Suppress("LibraryEntitiesShouldNotBePublic")
sealed class BrowserSwitchFinalResult {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.braintreepayments.api
/**
* The result of a browser switch obtained from [BrowserSwitchClient.start]
*/
@Suppress("LibraryEntitiesShouldNotBePublic")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ruleset doesn't make complete sense to me.
It is good to have most of the library entities to be internal or private, but there'll have to be some classes that need to be exposed. Is this the way that detekt expects us to deal with all public library classes? An explicit way for saying that we are allowing something?
I have a feeling that this isn't the best way to do things, but I don't expect any changes in this PR. Just saying stuff out loud.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a very fair point, and the one we should address when time permits. Tagging @tdchow in case we want to create a ticket for this work in the future. In the meantime, I will merge and close this PR to limit its scope.

sealed class BrowserSwitchStartResult {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package com.braintreepayments.api
* - [ACTIVITY_NEW_TASK]: sets the `Intent.FLAG_ACTIVITY_NEW_TASK` flag.
* - [ACTIVITY_CLEAR_TOP]: sets the `Intent.FLAG_ACTIVITY_CLEAR_TOP` flag.
*/
@Suppress("LibraryEntitiesShouldNotBePublic")
enum class LaunchType {
ACTIVITY_NEW_TASK,
ACTIVITY_CLEAR_TOP
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ import androidx.activity.result.ActivityResultLauncher
import androidx.browser.auth.AuthTabIntent
import androidx.browser.customtabs.CustomTabsClient
import androidx.browser.customtabs.CustomTabsIntent
import io.mockk.*
import org.junit.Assert.*
import io.mockk.clearAllMocks
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
@Suppress("LibraryEntitiesShouldNotBePublic")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might be able to add an exclusion for this rule to the detekt file for ignoring Test classes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tdchow I added the rules to exclude tests and demo from that rule. Let me know if you think it is sufficient.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

class AuthTabInternalClientUnitTest {

private lateinit var authTabBuilder: AuthTabIntent.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ class BrowserSwitchRequestUnitTest {
assertEquals("return-url-scheme", sut.returnUrlScheme)
assertEquals(Uri.parse("https://app-link-uri.com"), sut.appLinkUri)
}
}
}
36 changes: 36 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ buildscript {
classpath 'com.android.tools.build:gradle:8.9.1'
classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.9.10'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0'
classpath 'io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.6'
}
}

plugins {
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
id 'org.jetbrains.dokka' version '1.9.10'
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
id 'io.gitlab.arturbosch.detekt' version '1.23.6'
}

version = '3.4.1-SNAPSHOT'
Expand Down Expand Up @@ -79,6 +81,40 @@ dokkaHtmlMultiModule.configure {
outputDirectory.set(project.file("docs"))
}

dependencies {
detektPlugins 'io.gitlab.arturbosch.detekt:detekt-formatting:1.23.6'
detektPlugins 'io.gitlab.arturbosch.detekt:detekt-rules-libraries:1.23.6'
}

detekt {
toolVersion = "1.23.6"
config = files("detekt/detekt-config.yml")
input = files(
"browser-switch/src",
"demo/src"
)
autoCorrect = project.hasProperty('detektAutoCorrect')
reports {
html {
enabled = true
destination = file("build/reports/detekt_report.html")
}
}
}

subprojects {
apply plugin: 'io.gitlab.arturbosch.detekt'

detekt {
config = files("$rootDir/detekt/detekt-config.yml")
}

dependencies {
detektPlugins 'io.gitlab.arturbosch.detekt:detekt-formatting:1.23.6'
detektPlugins 'io.gitlab.arturbosch.detekt:detekt-rules-libraries:1.23.6'
}
}

task changeGradleReleaseVersion {
doLast {
def gradleFile = new File('build.gradle')
Expand Down
2 changes: 2 additions & 0 deletions ci
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ case $command_name in
;;
lint)
./gradlew clean lint
./gradlew detekt --auto-correct
;;
unit_tests)
./gradlew --stacktrace testRelease
Expand Down Expand Up @@ -85,6 +86,7 @@ case $command_name in
;;
android_lint)
./gradlew lint
./gradlew detekt
;;

esac
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.braintreepayments.api.browserswitch.demo

import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
Expand Down Expand Up @@ -39,6 +40,7 @@ class ComposeActivity : ComponentActivity() {
try {
browserSwitchClient.restorePendingRequest(pendingRequest)
} catch (e: BrowserSwitchException) {
Log.e("ComposeActivity", "Failed to restore pending request", e)
PendingRequestStore.clear(this)
}
}
Expand Down Expand Up @@ -115,7 +117,6 @@ fun BrowserSwitchResult(viewModel: BrowserSwitchViewModel) {
BrowserSwitchSuccess(result = it)
}
uiState.browserSwitchError?.let { BrowserSwitchError(exception = it) }

}

@Composable
Expand Down Expand Up @@ -158,4 +159,4 @@ fun BrowserSwitchError(exception: Exception) {
)
exception.message?.let { Text(text = it, color = Color.White) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.braintreepayments.api.browserswitch.demo.utils
import android.content.Context
import android.content.SharedPreferences

@Suppress("UtilityClassWithPublicConstructor")
class PendingRequestStore {

companion object {
Expand Down Expand Up @@ -37,4 +38,4 @@ class PendingRequestStore {
sharedPreferences.edit().remove(PENDING_REQUEST_KEY).apply()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ class BrowserSwitchViewModel : ViewModel() {
_uiState.update { it.copy(browserSwitchError = value) }
_uiState.update { it.copy(browserSwitchFinalResult = null) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.braintreepayments.api.browserswitch.demo.viewmodel

import com.braintreepayments.api.BrowserSwitchFinalResult

data class UiState (
data class UiState(
val browserSwitchFinalResult: BrowserSwitchFinalResult? = null,
val browserSwitchError: Exception? = null,
)
)
Loading