Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: test amity login without firebase login #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ dependencies {
implementation("com.google.firebase:firebase-firestore-ktx")

// Amity
implementation("com.github.AmityCo.Amity-Social-Cloud-SDK-Android:amity-sdk:5.33.5") {
exclude("androidx.paging")
}
implementation("com.github.AmityCo.Amity-Social-Cloud-SDK-Android:amity-sdk:5.33.5")


implementation("org.jetbrains.kotlinx:kotlinx-coroutines-rx2:1.6.4")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "c7ceb92e8dfb1c874cff20c505073dfb",
"entities": [
{
"tableName": "User",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` TEXT NOT NULL, `displayName` TEXT, `email` TEXT, `photoUrl` TEXT, PRIMARY KEY(`uid`))",
"fields": [
{
"fieldPath": "uid",
"columnName": "uid",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "displayName",
"columnName": "displayName",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "email",
"columnName": "email",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "photoUrl",
"columnName": "photoUrl",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"uid"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'c7ceb92e8dfb1c874cff20c505073dfb')"
]
}
}
16 changes: 2 additions & 14 deletions app/src/main/java/co/amity/archdemo/data/remote/AuthRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import co.amity.archdemo.data.local.models.ApiResponse
import co.amity.archdemo.data.local.models.User
import com.amity.socialcloud.sdk.AmityCoreClient
import com.amity.socialcloud.sdk.AmityCoreClient.login
import com.amity.socialcloud.sdk.core.authen.UserRegistration
import com.amity.socialcloud.sdk.core.session.AccessTokenRenewal
import com.amity.socialcloud.sdk.core.session.SessionHandler
import com.amity.socialcloud.sdk.core.session.model.SessionState
import com.ekoapp.core.utils.toSuspend
import com.google.android.gms.auth.api.identity.BeginSignInRequest
import com.google.android.gms.auth.api.identity.BeginSignInResult
import com.google.android.gms.auth.api.identity.SignInClient
import com.google.firebase.auth.AuthCredential
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.FirebaseFirestore
import io.reactivex.Completable
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
Expand All @@ -34,7 +31,6 @@ interface AuthRepository {
val isSignedIn: Flow<Boolean>
val amitySession: Flow<SessionState>
val amityTestSession: Flow<SessionState>
val amityLoginState: Flow<UserRegistration>
suspend fun signInWithGoogle(): OneTapResponse
suspend fun signUpWithGoogle(): OneTapResponse
suspend fun firebaseSignInWithGoogle(googleCredential: AuthCredential): SignInToFirebaseResponse
Expand Down Expand Up @@ -111,22 +107,14 @@ class AuthRepositoryImp @Inject constructor(

override val amitySession = flow {
emit(AmityCoreClient.currentSessionState)
AmityCoreClient.observeSessionState().asFlow().also { amityLogIn() }
AmityCoreClient.observeSessionState().asFlow()
}

override suspend fun amityLogIn() =
login(userId = currentUserId, sessionHandler = MySessionHandler())
.build()
.submit()
.toSuspend()

// TODO This is not if collected as state (but can't be combined). This is to be deleted when fixed
override val amityLoginState = AmityCoreClient
.login(currentUserId, sessionHandler = MySessionHandler())
.build()
.submit()
.toFlowable<UserRegistration>()
.asFlow()
.blockingAwait()

class MySessionHandler : SessionHandler {
override fun sessionWillRenewAccessToken(renewal: AccessTokenRenewal) {
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/co/amity/archdemo/ui/login/LoginScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
Expand Down Expand Up @@ -54,7 +60,10 @@ fun LoginScreen(
}

Column(modifier) {
Button(onClick = { scope.launch { viewModel.googleSignIn(launcher) } }) {
Button(onClick = {
scope.launch { viewModel.googleSignIn(launcher) }
}
) {
Text(text = stringResource(R.string.login_google_bt))
}
if (isProgressBarVisible) CircularProgressIndicator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import co.amity.archdemo.data.remote.AuthRepository
import com.google.android.gms.auth.api.identity.BeginSignInResult
import com.google.firebase.auth.AuthCredential
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand Down