This repository has been archived by the owner on Mar 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yumi
committed
May 22, 2022
1 parent
7aa5f78
commit 86bc2ed
Showing
23 changed files
with
370 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
ext { | ||
PUBLISH_GROUP_ID = GROUPID //项目包名 | ||
PUBLISH_ARTIFACT_ID = 'socialhelper.line' //项目名 | ||
PUBLISH_VERSION = VERSIONNAME //版本号 | ||
} | ||
|
||
apply from: "../publish.gradle" | ||
|
||
android { | ||
compileSdk COMPILESDK | ||
|
||
defaultConfig { | ||
minSdk MINSDK | ||
targetSdk TARGETSDK | ||
versionCode VERSIONCODE | ||
versionName VERSIONNAME | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
dependencies { | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
|
||
implementation project(path: ':SocialHelper') | ||
api ('com.linecorp.linesdk:linesdk:5.8.0') | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
Line/src/androidTest/java/io/github/devzwy/socialhelper/line/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.github.devzwy.socialhelper.line | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("io.github.devzwy.socialhelper.line.test", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="io.github.devzwy.socialhelper.line"> | ||
</manifest> |
7 changes: 7 additions & 0 deletions
7
Line/src/main/java/io/github/devzwy/socialhelper/line/LineSocialConst.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.github.devzwy.socialhelper.line | ||
|
||
class LineSocialConst { | ||
companion object{ | ||
const val REQUEST_CODE_LINE_AUTH = 888 | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
Line/src/main/java/io/github/devzwy/socialhelper/line/LineSocialHelperExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.github.devzwy.socialhelper.line | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import com.linecorp.linesdk.LineApiResponseCode | ||
import com.linecorp.linesdk.api.LineApiClient | ||
import com.linecorp.linesdk.api.LineApiClientBuilder | ||
import com.linecorp.linesdk.auth.LineAuthenticationParams | ||
import com.linecorp.linesdk.auth.LineLoginApi | ||
import com.linecorp.linesdk.auth.LineLoginResult | ||
import io.github.devzwy.socialhelper.SocialHelper | ||
import io.github.devzwy.socialhelper.line.LineSocialConst.Companion.REQUEST_CODE_LINE_AUTH | ||
import io.github.devzwy.socialhelper.utils.logE | ||
import io.github.devzwy.socialhelper.utils.toJsonStr | ||
import java.util.* | ||
|
||
private lateinit var onLineReqAuthError: (String) -> Unit | ||
private lateinit var onLineReqAuthSuccess: (LineLoginResult) -> Unit | ||
|
||
/** | ||
* 在Line授权当前页面的Activity调用,调用处于[reqLineAuth]传入的activity保持一致 调用时请判断requestCode==[REQUEST_CODE_LINE_AUTH] | ||
*/ | ||
fun SocialHelper.onLineAuthResult(intent: Intent?) { | ||
runCatching { | ||
val result = LineLoginApi.getLoginResultFromIntent(intent) | ||
when (result.responseCode) { | ||
LineApiResponseCode.SUCCESS -> { | ||
onLineReqAuthSuccess(result) | ||
} | ||
LineApiResponseCode.CANCEL -> { | ||
//取消了操作 | ||
onLineReqAuthError(socialConfig.application.getString(com.linecorp.linesdk.R.string.common_cancel)) | ||
} | ||
else -> { | ||
onLineReqAuthError(result.errorData.message ?: result.toJsonStr()) | ||
} | ||
} | ||
|
||
}.onFailure { | ||
it.printStackTrace() | ||
onLineReqAuthError( | ||
socialConfig.application.getString( | ||
R.string.social_auth_fail_exception, | ||
it.message ?: "" | ||
) | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* 发起Line授权 授权成功会在传入Activity对应的onActivityResult中回调,请务必在该回调中调用[onLineAuthResult] | ||
* [activity] Line SDK内部需要 | ||
* [onError] 授权失败的回调 | ||
* [onSuccess] 授权成功的回调 成功时会回传LineLoginResult | ||
*/ | ||
fun SocialHelper.reqLineAuth( | ||
activity: Activity, | ||
onError: (String) -> Unit, | ||
onSuccess: (LineLoginResult) -> Unit | ||
) { | ||
onLineReqAuthError = onError | ||
onLineReqAuthSuccess = onSuccess | ||
|
||
kotlin.runCatching { | ||
activity.startActivityForResult( | ||
LineLoginApi.getLoginIntent( | ||
activity, | ||
socialConfig.lineAppId, | ||
LineAuthenticationParams.Builder() | ||
.scopes(Arrays.asList(com.linecorp.linesdk.Scope.PROFILE)) | ||
.build() | ||
), REQUEST_CODE_LINE_AUTH | ||
) | ||
}.onFailure { | ||
it.localizedMessage?.logE() | ||
onError(it.message ?: "Line service not found") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<resources> | ||
<string name="social_auth_fail">授权失败,请重试</string> | ||
<string name="social_auth_fail_exception">授权异常,%s</string> | ||
</resources> |
17 changes: 17 additions & 0 deletions
17
Line/src/test/java/io/github/devzwy/socialhelper/line/ExampleUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.github.devzwy.socialhelper.line | ||
|
||
import org.junit.Test | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
class ExampleUnitTest { | ||
@Test | ||
fun addition_isCorrect() { | ||
assertEquals(4, 2 + 2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.