diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index f358785..07b0532 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -12,6 +12,7 @@
+
diff --git a/Google/src/main/java/io/github/devzwy/socialhelper/google/GoogleSocialHelperExt.kt b/Google/src/main/java/io/github/devzwy/socialhelper/google/GoogleSocialHelperExt.kt
index 7516404..81614f8 100644
--- a/Google/src/main/java/io/github/devzwy/socialhelper/google/GoogleSocialHelperExt.kt
+++ b/Google/src/main/java/io/github/devzwy/socialhelper/google/GoogleSocialHelperExt.kt
@@ -15,8 +15,8 @@ import io.github.devzwy.socialhelper.google.GoogleSocialConst.Companion.REQUEST_
import io.github.devzwy.socialhelper.utils.*
-lateinit var onGoogleReqAuthError: (String) -> Unit
-lateinit var onGoogleReqAuthSuccess: (GoogleSignInAccount) -> Unit
+private lateinit var onGoogleReqAuthError: (String) -> Unit
+private lateinit var onGoogleReqAuthSuccess: (GoogleSignInAccount) -> Unit
/**
* 在Google授权当前页面的Activity调用,调用处于[reqGoogleAuth]传入的activity保持一致 调用时请判断requestCode==[REQUEST_CODE_GOOGLE_AUTH]
diff --git a/Line/.gitignore b/Line/.gitignore
new file mode 100644
index 0000000..42afabf
--- /dev/null
+++ b/Line/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/Line/build.gradle b/Line/build.gradle
new file mode 100644
index 0000000..0784d98
--- /dev/null
+++ b/Line/build.gradle
@@ -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')
+}
\ No newline at end of file
diff --git a/Line/consumer-rules.pro b/Line/consumer-rules.pro
new file mode 100644
index 0000000..e69de29
diff --git a/Line/proguard-rules.pro b/Line/proguard-rules.pro
new file mode 100644
index 0000000..481bb43
--- /dev/null
+++ b/Line/proguard-rules.pro
@@ -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
\ No newline at end of file
diff --git a/Line/src/androidTest/java/io/github/devzwy/socialhelper/line/ExampleInstrumentedTest.kt b/Line/src/androidTest/java/io/github/devzwy/socialhelper/line/ExampleInstrumentedTest.kt
new file mode 100644
index 0000000..2994fb7
--- /dev/null
+++ b/Line/src/androidTest/java/io/github/devzwy/socialhelper/line/ExampleInstrumentedTest.kt
@@ -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)
+ }
+}
\ No newline at end of file
diff --git a/Line/src/main/AndroidManifest.xml b/Line/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..e7d621b
--- /dev/null
+++ b/Line/src/main/AndroidManifest.xml
@@ -0,0 +1,5 @@
+
+
+
\ No newline at end of file
diff --git a/Line/src/main/java/io/github/devzwy/socialhelper/line/LineSocialConst.kt b/Line/src/main/java/io/github/devzwy/socialhelper/line/LineSocialConst.kt
new file mode 100644
index 0000000..7ef3b95
--- /dev/null
+++ b/Line/src/main/java/io/github/devzwy/socialhelper/line/LineSocialConst.kt
@@ -0,0 +1,7 @@
+package io.github.devzwy.socialhelper.line
+
+class LineSocialConst {
+ companion object{
+ const val REQUEST_CODE_LINE_AUTH = 888
+ }
+}
\ No newline at end of file
diff --git a/Line/src/main/java/io/github/devzwy/socialhelper/line/LineSocialHelperExt.kt b/Line/src/main/java/io/github/devzwy/socialhelper/line/LineSocialHelperExt.kt
new file mode 100644
index 0000000..4662669
--- /dev/null
+++ b/Line/src/main/java/io/github/devzwy/socialhelper/line/LineSocialHelperExt.kt
@@ -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")
+ }
+}
\ No newline at end of file
diff --git a/Line/src/main/res/values/strings.xml b/Line/src/main/res/values/strings.xml
new file mode 100644
index 0000000..6f90114
--- /dev/null
+++ b/Line/src/main/res/values/strings.xml
@@ -0,0 +1,4 @@
+
+ 授权失败,请重试
+ 授权异常,%s
+
\ No newline at end of file
diff --git a/Line/src/test/java/io/github/devzwy/socialhelper/line/ExampleUnitTest.kt b/Line/src/test/java/io/github/devzwy/socialhelper/line/ExampleUnitTest.kt
new file mode 100644
index 0000000..1e1f57d
--- /dev/null
+++ b/Line/src/test/java/io/github/devzwy/socialhelper/line/ExampleUnitTest.kt
@@ -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)
+ }
+}
\ No newline at end of file
diff --git a/PlatformInfo.md b/PlatformInfo.md
index f7f61a9..f3c04d8 100644
--- a/PlatformInfo.md
+++ b/PlatformInfo.md
@@ -39,4 +39,32 @@ class ShareEntryActivity: AlipaySocialEntryActivity() {
## Google
- src目录同级防止在google平台生成的**google-services.json**
- ![google_platform](https://download.wdsf.top/dev/image/google_platform.png)
\ No newline at end of file
+ ![google_platform](https://download.wdsf.top/dev/image/google_platform.png)
+
+- 调用授权**Activity**的**onActivityResult**中增加如下代码
+```
+override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+ super.onActivityResult(requestCode, resultCode, data)
+ //加入这一行
+ if (requestCode == REQUEST_CODE_GOOGLE_AUTH) SocialHelper.onGoogleAuthResult(data)
+ }
+```
+
+## Line
+- 在**AndroidManifest.xml**下的**application标签加入如下代码**
+```
+
+```
+
+- 调用授权**Activity**的**onActivityResult**中增加如下代码
+```
+override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+ super.onActivityResult(requestCode, resultCode, data)
+ //加入这一行
+ if (requestCode == REQUEST_CODE_LINE_AUTH) SocialHelper.onLineAuthResult(data)
+ }
+```
\ No newline at end of file
diff --git a/README.md b/README.md
index 2fa1c7f..c78344f 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
- [x] 🎉 微信平台 **授权**、**获取用户资料**、**分享**[支持文本、图片、音乐、视频、网页、小程序]
- [x] 🎉 支付宝平台 **授权**、**分享**[支持文本、图片、网页]
- [x] 💃🏻 Google **授权**、**获取用户资料**
-- [ ] 🚑 Line
+- [x] 🚑 Line **授权**、**获取用户资料**
- [ ] 📝 ...
## demo效果图
@@ -35,24 +35,29 @@
```
//必选
- implementation("io.github.devzwy:socialhelper:1.0.6")
+ implementation("io.github.devzwy:socialhelper:1.0.7")
//微信平台 可选 需要时集成
implementation('com.tencent.mm.opensdk:wechat-sdk-android:6.8.0')
- implementation("io.github.devzwy:socialhelper.wechat:1.0.6"){
+ implementation("io.github.devzwy:socialhelper.wechat:1.0.7"){
transitive = false
}
//支付宝平台 可选 需要时集成
- implementation("io.github.devzwy:socialhelper.alipay:1.0.6"){
+ implementation("io.github.devzwy:socialhelper.alipay:1.0.7"){
transitive = false
}
//Google平台 可选 需要时集成
implementation("com.google.android.gms:play-services-auth:20.2.0")
- implementation("io.github.devzwy:socialhelper.google:1.0.6"){
+ implementation("io.github.devzwy:socialhelper.google:1.0.7"){
transitive = false
}
+
+ implementation("io.github.devzwy:socialhelper.line:1.0.7"){
+ transitive = false
+ }
+
```
#### 2.初始化
@@ -68,6 +73,7 @@ class MyApplication:Application() {
enableWeChatPlatform("微信AppId", "微信secretKey(可选)")
enableAlipayPlatform("支付宝AppId", "支付宝商户号", "支付宝应用私钥")
enableGooglePlatform("Google客户端Id clientId")
+ enableLinePlatform("Line AppId")
..
})
}
@@ -155,7 +161,7 @@ SocialHelper.reqGoogleAuth(this, {
})
```
-- 获取用户资料
+- 获取用户资料(授权返回数据读取)
```
this.mGoogleSignInAccount?.let {
//演示 从对象取出对应用户资料
@@ -172,3 +178,25 @@ SocialHelper.reqGoogleAuth(this, {
SocialHelper.signOut()
```
+#### Line
+- 获取授权
+```
+SocialHelper.reqLineAuth(this, {
+ appendLog(it)
+ }, {
+ //你要的东西应该在这个里面
+ this.mLineLoginResult = it
+ appendLog(it.toJsonStr())
+ btGetUserInfo.isEnabled = true
+ })
+```
+
+- 获取用户资料(授权返回数据读取)
+```
+this.mLineLoginResult?.lineProfile?.let {
+ //演示 从对象取出对应用户资料
+ appendLog("displayName:${it.displayName}")
+ appendLog("userId:${it.userId}")
+ appendLog("pictureUrl:${it.pictureUrl}")
+ }
+```
diff --git a/Sample/build.gradle b/Sample/build.gradle
index 6ac194f..0be1981 100644
--- a/Sample/build.gradle
+++ b/Sample/build.gradle
@@ -5,8 +5,6 @@ plugins {
android {
- //
-
compileSdk COMPILESDK
defaultConfig {
@@ -23,10 +21,10 @@ android {
signingConfigs {
release {
- storeFile file("E:\\StudioProjects\\keys\\hila_release.jks")
- storePassword 'hila1024'
- keyAlias = 'hilakey'
- keyPassword 'hila1024'
+ storeFile file("E:\\StudioProjects\\keys\\social_demo.jks")
+ storePassword 'abc123456'
+ keyAlias = 'socialhelper'
+ keyPassword 'abc123456'
v1SigningEnabled true
v2SigningEnabled true
@@ -69,19 +67,30 @@ dependencies {
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
implementation("com.github.Gavras:MultiLineRadioGroup:v1.0.0.6")
-//
- implementation("io.github.devzwy:socialhelper:1.0.6")
+ //基础依赖
+ implementation("io.github.devzwy:socialhelper:1.0.7")
+
+ //微信平台
implementation('com.tencent.mm.opensdk:wechat-sdk-android:6.8.0')
- implementation("io.github.devzwy:socialhelper.wechat:1.0.6"){
+ implementation("io.github.devzwy:socialhelper.wechat:1.0.7"){
transitive = false
}
- implementation("io.github.devzwy:socialhelper.alipay:1.0.6"){
+ //支付宝平台
+ implementation("io.github.devzwy:socialhelper.alipay:1.0.7"){
transitive = false
}
+
+ //google平台
implementation("com.google.android.gms:play-services-auth:20.2.0")
- implementation("io.github.devzwy:socialhelper.google:1.0.6"){
+ implementation("io.github.devzwy:socialhelper.google:1.0.7"){
+ transitive = false
+ }
+
+ //line平台
+ implementation("com.linecorp.linesdk:linesdk:5.8.0")
+ implementation("io.github.devzwy:socialhelper.line:1.0.7"){
transitive = false
}
//
@@ -89,6 +98,6 @@ dependencies {
// implementation project(path: ':WeChat')
// implementation project(path: ':AliPay')
// implementation project(path: ':Google')
-
+// implementation project(path: ':Line')
}
\ No newline at end of file
diff --git a/Sample/src/main/AndroidManifest.xml b/Sample/src/main/AndroidManifest.xml
index 0d92ef8..2d9aa0c 100644
--- a/Sample/src/main/AndroidManifest.xml
+++ b/Sample/src/main/AndroidManifest.xml
@@ -1,7 +1,6 @@
-
{
+ //Google
+ platform = 3
+
+ contentTypes = resources.getStringArray(R.array.radio_buttons_type_alipay)
+ radioGroupContentType.removeAllButtons()
+ contentTypes.forEach {
+ radioGroupContentType.addButtons(it)
+ }
+
+ radioGroupContentType.check(contentTypes[0])
+
+ radioGroupToType.visibility = View.GONE
+ tv2.visibility = View.GONE
+ tv1.visibility = View.GONE
+ btShare.visibility = View.GONE
+ radioGroupContentType.visibility = View.GONE
+ btGetUserInfo.visibility = View.VISIBLE
+ }
}
refreshUI()
diff --git a/Sample/src/main/res/layout/activity_main.xml b/Sample/src/main/res/layout/activity_main.xml
index fe82a8e..5ebeb22 100644
--- a/Sample/src/main/res/layout/activity_main.xml
+++ b/Sample/src/main/res/layout/activity_main.xml
@@ -24,7 +24,7 @@
微信
- 支付宝
- Google
+ - Line
-
- 文本
- 图片
diff --git a/SocialHelper/src/main/java/io/github/devzwy/socialhelper/SocialConfig.kt b/SocialHelper/src/main/java/io/github/devzwy/socialhelper/SocialConfig.kt
index 7147601..a9bd3ce 100644
--- a/SocialHelper/src/main/java/io/github/devzwy/socialhelper/SocialConfig.kt
+++ b/SocialHelper/src/main/java/io/github/devzwy/socialhelper/SocialConfig.kt
@@ -42,7 +42,13 @@ class SocialConfig private constructor(
/**
* google client ID like:312345678907-aa345c1jn1c3kstealsio4aaqe8m888e.apps.googleusercontent.com
*/
- val googleClientId: String
+ val googleClientId: String,
+
+
+ /**
+ * Line appId
+ */
+ val lineAppId: String
) {
@@ -90,6 +96,11 @@ class SocialConfig private constructor(
*/
private var googleClientId: String = ""
+ /**
+ * Line appId
+ */
+ private var lineAppId = ""
+
/**
* 开启日志 可选配置 默认关闭
*/
@@ -144,9 +155,19 @@ class SocialConfig private constructor(
*/
fun enableGooglePlatform(clientId: String) {
this.googleClientId = clientId.trim()
+ if (this.googleClientId.isEmpty()) throw SocialException("google平台参数配置错误,请重新配置![googleClientId不能为空]")
"Google平台配置完成,[googleClientId:${this.googleClientId}]".logD()
}
+ /**
+ * 开启Line平台
+ */
+ fun enableLinePlatform(lineAppId: String) {
+ this.lineAppId = lineAppId.trim()
+ if (this.lineAppId.isEmpty()) throw SocialException("Line平台参数配置错误,请重新配置![lineAppId不能为空]")
+ "Line平台配置完成,[lineAppId:${this.lineAppId}]".logD()
+ }
+
fun build(): SocialConfig {
return SocialConfig(
this.application,
@@ -156,7 +177,8 @@ class SocialConfig private constructor(
this.alipayAppId,
this.alipayPid,
this.alipayPrivateKey,
- this.googleClientId
+ this.googleClientId,
+ this.lineAppId
)
}
diff --git a/build.gradle b/build.gradle
index 7ddd563..ee750ae 100644
--- a/build.gradle
+++ b/build.gradle
@@ -12,6 +12,6 @@ ext {
MINSDK = 21
TARGETSDK = 32
VERSIONCODE=1
- VERSIONNAME = "1.0.6"
+ VERSIONNAME = "1.0.7"
GROUPID = "io.github.devzwy"
}
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index 64abd0a..3c17742 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -23,3 +23,4 @@ include ':SocialHelper'
include ':WeChat'
include ':AliPay'
include ':Google'
+include ':Line'
\ No newline at end of file