change documentation + gradle deps

This commit is contained in:
Rinat Nurmukhametov 2022-03-17 12:02:27 +03:00
parent ccb3f1c4e1
commit 3681f5c92d
5 changed files with 42 additions and 8 deletions

View File

@ -5,7 +5,7 @@ dependencies {
implementation "androidx.core:core"
implementation "androidx.annotation:annotation"
implementation "com.google.android.gms:play-services-base"
implementation "com.huawei.hms:safetydetect"
implementation "com.huawei.hms:base"
constraints {
implementation("androidx.core:core") {
@ -26,9 +26,9 @@ dependencies {
}
}
implementation("com.huawei.hms:safetydetect") {
implementation("com.huawei.hms:base") {
version {
require '4.0.3.300'
require '6.3.0.303'
}
}
}

View File

@ -5,6 +5,10 @@ import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import com.huawei.hms.api.HuaweiApiAvailability
/**
* A class with utils for interacting with Google, Huawei, etc. services
*/
class ServicesUtils {
fun getCurrentService(context: Context): MobileService = when {

View File

@ -1,6 +1,32 @@
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_"
)
```

View File

@ -5,12 +5,15 @@ import ru.touchin.client_services.MobileService
import ru.touchin.client_services.ServicesUtils
/**
* onNewTokenReceived - callback на успешную проверку каптчи
* processThrowable - callback на ошибку проверки каптчи
* A class for displaying a dialog with a captcha
* 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(
onNewTokenReceived: (String) -> Unit,
private val onNewTokenReceived: (String) -> Unit,
private val processThrowable: (Throwable) -> Unit
) {

View File

@ -10,6 +10,7 @@ class HuaweiCaptchaClient(
override fun showCaptcha(activity: Activity, captchaKey: String) {
val huaweiSafetyDetectClient = SafetyDetect.getClient(activity)
huaweiSafetyDetectClient.initUserDetect()
.addOnSuccessListener {
huaweiSafetyDetectClient.userDetection(captchaKey)