Skip to content

Commit

Permalink
Add ActivityResultContract implementation for Login
Browse files Browse the repository at this point in the history
Fixes line#150
  • Loading branch information
vincent-paing committed Jan 31, 2024
1 parent 5ff4957 commit ea83431
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions dependencyVersion.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ext {

// API and runtime implementations
androidx : [
activity : "1.8.2",
annotation : "1.1.0",
appcompat : "1.1.0",
browser : "1.2.0",
Expand Down
1 change: 1 addition & 0 deletions line-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${ver.kotlin}"

implementation "androidx.activity:activity-ktx:${ver.androidx.activity}"
implementation "androidx.annotation:annotation:${ver.androidx.annotation}"
implementation "androidx.appcompat:appcompat:${ver.androidx.appcompat}"
implementation "androidx.browser:browser:${ver.androidx.browser}"
Expand Down
28 changes: 28 additions & 0 deletions line-sdk/src/main/java/com/linecorp/linesdk/auth/LineLogin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.linecorp.linesdk.auth

import android.content.Context
import android.content.Intent
import androidx.activity.result.contract.ActivityResultContract

class LineLogin : ActivityResultContract<LineLogin.Input, LineLoginResult>() {

data class Input(
val channelId: String,
val params: LineAuthenticationParams,
val isBrowserLoginOnly: Boolean = false
)

override fun createIntent(context: Context, input: Input): Intent {
val (channelId, params, isBrowserLoginOnly) = input
return if (isBrowserLoginOnly) {
LineLoginApi.getLoginIntentWithoutLineAppAuth(context, channelId, params)
} else {
LineLoginApi.getLoginIntent(context, channelId, params)
}
}

override fun parseResult(resultCode: Int, intent: Intent?): LineLoginResult {
return LineLoginApi.getLoginResultFromIntent(intent)
}

}

0 comments on commit ea83431

Please sign in to comment.