change documentation + gradle deps
This commit is contained in:
parent
ccb3f1c4e1
commit
3681f5c92d
|
|
@ -5,7 +5,7 @@ dependencies {
|
||||||
implementation "androidx.core:core"
|
implementation "androidx.core:core"
|
||||||
implementation "androidx.annotation:annotation"
|
implementation "androidx.annotation:annotation"
|
||||||
implementation "com.google.android.gms:play-services-base"
|
implementation "com.google.android.gms:play-services-base"
|
||||||
implementation "com.huawei.hms:safetydetect"
|
implementation "com.huawei.hms:base"
|
||||||
|
|
||||||
constraints {
|
constraints {
|
||||||
implementation("androidx.core:core") {
|
implementation("androidx.core:core") {
|
||||||
|
|
@ -26,9 +26,9 @@ dependencies {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation("com.huawei.hms:safetydetect") {
|
implementation("com.huawei.hms:base") {
|
||||||
version {
|
version {
|
||||||
require '4.0.3.300'
|
require '6.3.0.303'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,10 @@ import com.google.android.gms.common.ConnectionResult
|
||||||
import com.google.android.gms.common.GoogleApiAvailability
|
import com.google.android.gms.common.GoogleApiAvailability
|
||||||
import com.huawei.hms.api.HuaweiApiAvailability
|
import com.huawei.hms.api.HuaweiApiAvailability
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class with utils for interacting with Google, Huawei, etc. services
|
||||||
|
*/
|
||||||
|
|
||||||
class ServicesUtils {
|
class ServicesUtils {
|
||||||
|
|
||||||
fun getCurrentService(context: Context): MobileService = when {
|
fun getCurrentService(context: Context): MobileService = when {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,32 @@
|
||||||
recaptcha
|
recaptcha
|
||||||
=====
|
=====
|
||||||
|
|
||||||
Модуль содержит класс `RecaptchaController` - служит для проверки используемого сервиса (Huawei или Google) и показа диалога с каптчёй
|
### Общее описание
|
||||||
|
|
||||||
Для использования модуля нужно добавить json файл с сервисами в корневую папку проекта
|
Модуль содержит класс `CaptchaManager` - служит для проверки используемого сервиса (Huawei или Google) и показа диалога с каптчёй
|
||||||
|
В конструктуре `CaptchaManager` принимает два callback`а:
|
||||||
|
`onNewTokenReceived` - успешная проверка, возвращает токен
|
||||||
|
`processThrowable` - ошибка, возвращает `Throwable`
|
||||||
|
|
||||||
|
### Требования
|
||||||
|
|
||||||
|
Для использования модуля нужно добавить json файл с сервисами в корневую папку проекта:
|
||||||
|
Для Google - google-services.json
|
||||||
|
Для Huawei - agconnect-services.json
|
||||||
|
|
||||||
|
### Пример
|
||||||
|
|
||||||
|
Во `Fragment`
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val manager = CaptchaManager(onNewTokenReceived = { token ->
|
||||||
|
viewModel.sendRequest(token)
|
||||||
|
}, processThrowable = { error ->
|
||||||
|
showError(error)
|
||||||
|
})
|
||||||
|
|
||||||
|
manager.showRecaptchaAlert(
|
||||||
|
activity = activity,
|
||||||
|
captchaKey = "6Lc2heYeAAAAAHqe3mp0ylUnvXSY4lYfbRCwsVz_"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,15 @@ import ru.touchin.client_services.MobileService
|
||||||
import ru.touchin.client_services.ServicesUtils
|
import ru.touchin.client_services.ServicesUtils
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onNewTokenReceived - callback на успешную проверку каптчи
|
* A class for displaying a dialog with a captcha
|
||||||
* processThrowable - callback на ошибку проверки каптчи
|
* with a check on the current service of the application
|
||||||
|
*
|
||||||
|
* @param onNewTokenReceived - callback for a successful captcha check, return token
|
||||||
|
* @param processThrowable - callback for a captcha check error, return throwable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class CaptchaManager(
|
class CaptchaManager(
|
||||||
onNewTokenReceived: (String) -> Unit,
|
private val onNewTokenReceived: (String) -> Unit,
|
||||||
private val processThrowable: (Throwable) -> Unit
|
private val processThrowable: (Throwable) -> Unit
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ class HuaweiCaptchaClient(
|
||||||
|
|
||||||
override fun showCaptcha(activity: Activity, captchaKey: String) {
|
override fun showCaptcha(activity: Activity, captchaKey: String) {
|
||||||
val huaweiSafetyDetectClient = SafetyDetect.getClient(activity)
|
val huaweiSafetyDetectClient = SafetyDetect.getClient(activity)
|
||||||
|
|
||||||
huaweiSafetyDetectClient.initUserDetect()
|
huaweiSafetyDetectClient.initUserDetect()
|
||||||
.addOnSuccessListener {
|
.addOnSuccessListener {
|
||||||
huaweiSafetyDetectClient.userDetection(captchaKey)
|
huaweiSafetyDetectClient.userDetection(captchaKey)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue