Skip to content
Snippets Groups Projects
Commit 5c81a122 authored by Taras's avatar Taras
Browse files

Merge branch 'release/v1.0.29' into main

parents d0210d2d e14adac7
No related branches found
No related tags found
No related merge requests found
package org.futo.circles.update
import android.app.Activity
interface AppUpdateProvider {
fun getManager(): AppUpdateManager?
......
......@@ -81,6 +81,11 @@ dependencies {
//Subscriptions
gplayImplementation 'com.android.billingclient:billing-ktx:6.2.0'
//PasswordManager
def credentials_version = '1.3.0-alpha02'
gplayImplementation "androidx.credentials:credentials:$credentials_version"
gplayImplementation "androidx.credentials:credentials-play-services-auth:$credentials_version"
//QR
implementation 'com.github.yuriy-budiyev:code-scanner:2.3.2'
......
package org.futo.circles.auth.di
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.futo.circles.auth.credentials.CredentialsManager
import org.futo.circles.auth.credentials.CredentialsProvider
@Module
@InstallIn(SingletonComponent::class)
object CredentialsModule {
@Provides
fun provideCredentialsProvider(): CredentialsProvider {
return object : CredentialsProvider {
override fun getManager(): CredentialsManager? = null
}
}
}
\ No newline at end of file
package org.futo.circles.auth.credentials
import android.content.Context
import androidx.credentials.CreatePasswordRequest
import androidx.credentials.CredentialManager
import androidx.credentials.GetCredentialRequest
import androidx.credentials.GetPasswordOption
import androidx.credentials.PasswordCredential
class GoogleCredentialsManager : CredentialsManager {
override suspend fun getPasswordCredentials(activityContext: Context, userId: String): String? {
val credentialManager = CredentialManager.create(activityContext)
val request = GetCredentialRequest(
listOf(GetPasswordOption(allowedUserIds = setOf(userId)))
)
val result = credentialManager.getCredential(
context = activityContext,
request = request
).credential
return (result as? PasswordCredential)?.password
}
override suspend fun savePasswordCredentials(
activityContext: Context,
userId: String,
password: String
) {
val createPasswordRequest = CreatePasswordRequest(
id = userId,
password = password
)
CredentialManager.create(activityContext).createCredential(
activityContext,
createPasswordRequest
)
}
}
\ No newline at end of file
package org.futo.circles.auth.di
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.futo.circles.auth.credentials.CredentialsManager
import org.futo.circles.auth.credentials.CredentialsProvider
import org.futo.circles.auth.credentials.GoogleCredentialsManager
@Module
@InstallIn(SingletonComponent::class)
object CredentialsModule {
@Provides
fun provideCredentialsProvider(): CredentialsProvider {
return object : CredentialsProvider {
override fun getManager(): CredentialsManager = GoogleCredentialsManager()
}
}
}
\ No newline at end of file
package org.futo.circles.auth.credentials
import android.content.Context
interface CredentialsManager {
suspend fun getPasswordCredentials(activityContext: Context, userId: String): String?
suspend fun savePasswordCredentials(activityContext: Context, userId: String, password: String)
}
\ No newline at end of file
package org.futo.circles.auth.credentials
interface CredentialsProvider {
fun getManager(): CredentialsManager?
}
\ No newline at end of file
package org.futo.circles.auth.feature.uia.stages.password
import android.content.Context
import androidx.credentials.CreatePasswordRequest
import androidx.credentials.CredentialManager
import androidx.credentials.GetCredentialRequest
import androidx.credentials.GetPasswordOption
import androidx.credentials.PasswordCredential
import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import org.futo.circles.auth.credentials.CredentialsProvider
import org.futo.circles.auth.feature.uia.UIADataSourceProvider
import org.futo.circles.core.base.SingleEventLiveData
import org.futo.circles.core.extensions.Response
......@@ -17,7 +13,8 @@ import javax.inject.Inject
@HiltViewModel
class PasswordViewModel @Inject constructor(
private val passwordDataSource: PasswordDataSource
private val passwordDataSource: PasswordDataSource,
private val credentialsProvider: CredentialsProvider
) : ViewModel() {
private var isPasswordWarningConfirmed: Boolean = false
......@@ -31,22 +28,13 @@ class PasswordViewModel @Inject constructor(
fun getCredentials(activityContext: Context) {
launchBg {
tryOrNull {
val credentialManager = CredentialManager.create(activityContext)
val userId = UIADataSourceProvider.getDataSourceOrThrow().getUserId()
val request = GetCredentialRequest(
listOf(GetPasswordOption(allowedUserIds = setOf(userId)))
)
val result = credentialManager.getCredential(
context = activityContext,
request = request
).credential
if (result is PasswordCredential) {
val password = result.password
passwordSelectedEventLiveData.postValue(password)
handlePasswordRequest(password, false, activityContext)
}
credentialsProvider.getManager()
?.getPasswordCredentials(activityContext, userId)
?.let { password ->
passwordSelectedEventLiveData.postValue(password)
handlePasswordRequest(password, false, activityContext)
}
}
}
}
......@@ -63,15 +51,9 @@ class PasswordViewModel @Inject constructor(
private suspend fun registerPassword(activityContext: Context, password: String) {
tryOrNull {
val uiaDataSource = UIADataSourceProvider.getDataSourceOrThrow()
val createPasswordRequest = CreatePasswordRequest(
id = uiaDataSource.getUserId(),
password = password
)
CredentialManager.create(activityContext).createCredential(
activityContext,
createPasswordRequest
)
val userId = UIADataSourceProvider.getDataSourceOrThrow().getUserId()
credentialsProvider.getManager()
?.savePasswordCredentials(activityContext, userId, password)
}
}
......
......@@ -112,9 +112,6 @@ dependencies {
api "io.noties.markwon:ext-tasklist:$markwon_version"
api 'io.element.android:wysiwyg:2.36.0'
//PasswordManager
api "androidx.credentials:credentials:1.3.0-alpha02"
//ExoPlayer
def exoplayer_version = '1.3.0'
api "androidx.media3:media3-exoplayer:$exoplayer_version"
......
  • Taras @taras.smakula

    mentioned in commit 81fcc64e

    ·

    mentioned in commit 81fcc64e

    Toggle commit list
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment