Skip to content

Commit

Permalink
sign in method added
Browse files Browse the repository at this point in the history
  • Loading branch information
fcat97 committed Mar 27, 2023
1 parent ef61a7e commit 125d81a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.google.code.gson:gson:2.10.1'

// implementation project(':libDriveBackup')
implementation 'com.github.fcat97:driveBackupApi:1.0.4'
implementation project(':libDriveBackup')
// implementation 'com.github.fcat97:driveBackupApi:1.0.5'
}
12 changes: 12 additions & 0 deletions app/src/main/java/com/tos/drivebackup/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MainActivity : ComponentActivity() {
private lateinit var terminal: TextView
private lateinit var emailTextView: TextView
private lateinit var signOutButton: Button
private lateinit var signInButton: Button

private val googleDriveBackupManager = GoogleDriveBackupManager(
appID = BuildConfig.APPLICATION_ID,
Expand Down Expand Up @@ -69,6 +70,7 @@ class MainActivity : ComponentActivity() {
terminal = findViewById(R.id.terminal)
emailTextView = findViewById(R.id.emailTextView)
signOutButton = findViewById(R.id.signOutButton)
signInButton = findViewById(R.id.signInButton)

createDemoBackupButton.setOnClickListener { createDemoBackup() }
downloadDemoBackupButton.setOnClickListener { downloadDemoBackup() }
Expand All @@ -90,6 +92,7 @@ class MainActivity : ComponentActivity() {
fetchFiles()
}
}
signInButton.setOnClickListener { singIn() }
signOutButton.setOnClickListener { signOut() }
clearTerminalButton.setOnClickListener { terminalOutputLiveData.value = "" }

Expand Down Expand Up @@ -156,6 +159,15 @@ class MainActivity : ComponentActivity() {
)
}

private fun singIn() {
googleDriveBackupManager.signIn(
onFailed = null,
onSuccess = {
printToTerminal(it.toString())
}
)
}

private fun signOut() {
googleDriveBackupManager.signOut(
onFailed = {
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/main_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@
android:layout_gravity="center_horizontal"
tools:text="Example\nexample@gmail.com"/>

<com.google.android.material.button.MaterialButton
android:id="@+id/signInButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign Out"
android:layout_marginVertical="8dp"
style="@style/ThemeOverlay.Material3.Button.ElevatedButton"/>

<com.google.android.material.button.MaterialButton
android:id="@+id/signOutButton"
android:layout_width="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion libDriveBackup/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ afterEvaluate {
publications {
maven(MavenPublication) {
group = 'media.uqab.driveBackupApi'
version = '1.0.4'
version = '1.0.5'
artifactId = "driveBackupApi"
from components.release

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ class GoogleDriveBackupManager(
}
}

fun signIn(
onFailed: ((Exception) -> Unit)?,
onSuccess: (UserInfo) -> Unit
) = requestConsentAndProceed(onFailed) {
val info = GetSignedInEmail.getSignedInEmail(activity)
if (info != null) onSuccess(info)
else onFailed?.invoke(Exception(""))
}

/**
* Request for User Consent to grant access to his/her drive account.
*
Expand Down

0 comments on commit 125d81a

Please sign in to comment.