mirror of
https://github.com/foobnix/LibreraReader.git
synced 2025-10-05 15:52:56 +02:00
refactoring
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,6 +13,7 @@
|
||||
/smartreflow/bin/
|
||||
/pro/bin/
|
||||
/app/bin/
|
||||
/bin
|
||||
/Builder/.vscode/
|
||||
/Builder/mupdf*
|
||||
/docs/Gemfile
|
||||
|
@@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'com.google.gms.google-services'
|
||||
}
|
||||
|
||||
def taskName = getGradle().getStartParameter().getTaskRequests().toString()
|
||||
|
@@ -363,12 +363,8 @@ public class SearchFragment2 extends UIFragment<FileMeta> {
|
||||
ComposeView composeView = (ComposeView) view.findViewById(R.id.compose_view);
|
||||
|
||||
GoogleSignInComposeHelper.createSimpleGoogleSignInButton(
|
||||
composeView,
|
||||
"Sign in with Google",
|
||||
() -> {
|
||||
// Handle sign-in click
|
||||
LOG.d("Google Sign-In button clicked");
|
||||
}
|
||||
composeView, getString(R.string.default_web_client_id)
|
||||
|
||||
);
|
||||
|
||||
secondTopPanel = view.findViewById(R.id.secondTopPanel);
|
||||
|
@@ -1,81 +0,0 @@
|
||||
package mobi.librera.appcompose.booksync
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import coil3.compose.AsyncImage
|
||||
import kotlinx.coroutines.launch
|
||||
import mobi.librera.lib.gdrive.GoogleSignInButton
|
||||
import org.koin.androidx.compose.koinViewModel
|
||||
|
||||
|
||||
@Composable
|
||||
fun GoogleSignInScreen(
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val context = LocalContext.current
|
||||
|
||||
|
||||
val viewModel: GoogleSingInViewModel = koinViewModel()
|
||||
val singInState by viewModel.singInState.collectAsState()
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.checkSingInState()
|
||||
}
|
||||
|
||||
when (val state = singInState) {
|
||||
is SingInState.NotSignIn -> {
|
||||
GoogleSignInButton(
|
||||
"Sing in with Google", onClick = {
|
||||
scope.launch {
|
||||
viewModel.signInWithGoogle(context)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
is SingInState.Success -> {
|
||||
Row(
|
||||
verticalAlignment = Alignment.Top,
|
||||
horizontalArrangement = Arrangement.Start
|
||||
) {
|
||||
AsyncImage(
|
||||
model = state.user.photoUrl,
|
||||
modifier = Modifier
|
||||
.size(40.dp)
|
||||
.clip(CircleShape),
|
||||
contentDescription = state.user.name
|
||||
)
|
||||
Column(Modifier.padding(start = 12.dp)) {
|
||||
Text(state.user.name)
|
||||
Text(state.user.email)
|
||||
}
|
||||
}
|
||||
GoogleSignInButton(
|
||||
"Sing out", onClick = {
|
||||
scope.launch {
|
||||
viewModel.signOut(context)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
is SingInState.Error -> {
|
||||
Text("Error: ${state.message}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -6,16 +6,11 @@ object GoogleSignInComposeHelper {
|
||||
|
||||
@JvmStatic
|
||||
fun createSimpleGoogleSignInButton(
|
||||
composeView: ComposeView,
|
||||
buttonText: String,
|
||||
onSignInClick: Runnable
|
||||
composeView: ComposeView, clientId: String
|
||||
) {
|
||||
composeView.setContent {
|
||||
GoogleSignInButton(
|
||||
text = buttonText,
|
||||
onClick = {
|
||||
onSignInClick.run()
|
||||
}
|
||||
GoogleSignInScreen(
|
||||
clientId
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@@ -49,7 +49,8 @@ fun GoogleSignInScreen(
|
||||
|
||||
is SingInState.Success -> {
|
||||
Row(
|
||||
verticalAlignment = Alignment.Top,
|
||||
modifier = Modifier.padding(4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Start
|
||||
) {
|
||||
AsyncImage(
|
||||
@@ -63,13 +64,15 @@ fun GoogleSignInScreen(
|
||||
Text(state.user.name)
|
||||
Text(state.user.email)
|
||||
}
|
||||
|
||||
GoogleSignInButton(
|
||||
"Sing out", onClick = {
|
||||
scope.launch {
|
||||
viewModel.signOut(context)
|
||||
}
|
||||
})
|
||||
}
|
||||
GoogleSignInButton(
|
||||
"Sing out", onClick = {
|
||||
scope.launch {
|
||||
viewModel.signOut(context)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
is SingInState.Error -> {
|
||||
|
@@ -21,10 +21,6 @@ import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
// TODO: These imports should be injected or passed as parameters to avoid circular dependency
|
||||
// import mobi.librera.appcompose.App
|
||||
// import mobi.librera.appcompose.R
|
||||
// import mobi.librera.appcompose.room.BookRepository
|
||||
|
||||
data class User(val name: String, val email: String, val photoUrl: Uri?)
|
||||
|
||||
|
Reference in New Issue
Block a user