-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6096 from k9mail/sign_in_with_google
Add "Sign in with Google" button
- Loading branch information
Showing
23 changed files
with
220 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/OAuthFlowActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.fsck.k9.activity.setup | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.View | ||
import android.widget.TextView | ||
import androidx.core.view.isVisible | ||
import com.fsck.k9.Account | ||
import com.fsck.k9.preferences.AccountManager | ||
import com.fsck.k9.ui.R | ||
import com.fsck.k9.ui.base.K9Activity | ||
import com.fsck.k9.ui.observe | ||
import org.koin.android.ext.android.inject | ||
import org.koin.androidx.viewmodel.ext.android.viewModel | ||
|
||
class OAuthFlowActivity : K9Activity() { | ||
private val authViewModel: AuthViewModel by viewModel() | ||
private val accountManager: AccountManager by inject() | ||
|
||
private lateinit var errorText: TextView | ||
|
||
public override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setLayout(R.layout.account_setup_oauth) | ||
setTitle(R.string.account_setup_basics_title) | ||
|
||
val accountUUid = intent.getStringExtra(EXTRA_ACCOUNT_UUID) ?: error("Missing account UUID") | ||
val account = accountManager.getAccount(accountUUid) ?: error("Account not found") | ||
|
||
errorText = findViewById(R.id.error_text) | ||
val signInButton: View = if (authViewModel.isUsingGoogle(account)) { | ||
findViewById(R.id.google_sign_in_button) | ||
} else { | ||
findViewById(R.id.oauth_sign_in_button) | ||
} | ||
|
||
signInButton.isVisible = true | ||
signInButton.setOnClickListener { startOAuthFlow(account) } | ||
|
||
authViewModel.init(activityResultRegistry, lifecycle) | ||
|
||
authViewModel.uiState.observe(this) { state -> | ||
handleUiUpdates(state) | ||
} | ||
} | ||
|
||
private fun handleUiUpdates(state: AuthFlowState) { | ||
when (state) { | ||
AuthFlowState.Idle -> { | ||
return | ||
} | ||
AuthFlowState.Success -> { | ||
setResult(RESULT_OK) | ||
finish() | ||
} | ||
AuthFlowState.Canceled -> { | ||
errorText.text = getString(R.string.account_setup_failed_dlg_oauth_flow_canceled) | ||
} | ||
is AuthFlowState.Failed -> { | ||
errorText.text = getString(R.string.account_setup_failed_dlg_oauth_flow_failed, state) | ||
} | ||
AuthFlowState.NotSupported -> { | ||
errorText.text = getString(R.string.account_setup_failed_dlg_oauth_not_supported) | ||
} | ||
AuthFlowState.BrowserNotFound -> { | ||
errorText.text = getString(R.string.account_setup_failed_dlg_browser_not_found) | ||
} | ||
} | ||
|
||
authViewModel.authResultConsumed() | ||
} | ||
|
||
private fun startOAuthFlow(account: Account) { | ||
errorText.text = "" | ||
|
||
authViewModel.login(account) | ||
} | ||
|
||
companion object { | ||
private const val EXTRA_ACCOUNT_UUID = "accountUuid" | ||
|
||
fun buildLaunchIntent(context: Context, accountUuid: String): Intent { | ||
return Intent(context, OAuthFlowActivity::class.java).apply { | ||
putExtra(EXTRA_ACCOUNT_UUID, accountUuid) | ||
} | ||
} | ||
} | ||
} |
Binary file added
BIN
+464 Bytes
app/ui/legacy/src/main/res/drawable-hdpi/btn_google_signin_dark_disabled.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.26 KB
app/ui/legacy/src/main/res/drawable-hdpi/btn_google_signin_dark_focus.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.2 KB
app/ui/legacy/src/main/res/drawable-hdpi/btn_google_signin_dark_normal.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.2 KB
app/ui/legacy/src/main/res/drawable-hdpi/btn_google_signin_dark_pressed.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+331 Bytes
app/ui/legacy/src/main/res/drawable-mdpi/btn_google_signin_dark_disabled.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+811 Bytes
app/ui/legacy/src/main/res/drawable-mdpi/btn_google_signin_dark_focus.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+758 Bytes
app/ui/legacy/src/main/res/drawable-mdpi/btn_google_signin_dark_normal.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+768 Bytes
app/ui/legacy/src/main/res/drawable-mdpi/btn_google_signin_dark_pressed.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+622 Bytes
app/ui/legacy/src/main/res/drawable-xhdpi/btn_google_signin_dark_disabled.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.58 KB
app/ui/legacy/src/main/res/drawable-xhdpi/btn_google_signin_dark_focus.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.53 KB
app/ui/legacy/src/main/res/drawable-xhdpi/btn_google_signin_dark_normal.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.54 KB
app/ui/legacy/src/main/res/drawable-xhdpi/btn_google_signin_dark_pressed.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+949 Bytes
app/ui/legacy/src/main/res/drawable-xxhdpi/btn_google_signin_dark_disabled.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.72 KB
app/ui/legacy/src/main/res/drawable-xxhdpi/btn_google_signin_dark_focus.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.48 KB
app/ui/legacy/src/main/res/drawable-xxhdpi/btn_google_signin_dark_normal.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.49 KB
app/ui/legacy/src/main/res/drawable-xxhdpi/btn_google_signin_dark_pressed.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions
7
app/ui/legacy/src/main/res/drawable/btn_google_signin_dark.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:state_enabled="false" android:drawable="@drawable/btn_google_signin_dark_disabled" /> | ||
<item android:state_pressed="true" android:drawable="@drawable/btn_google_signin_dark_pressed" /> | ||
<item android:state_focused="true" android:drawable="@drawable/btn_google_signin_dark_focus" /> | ||
<item android:drawable="@drawable/btn_google_signin_dark_normal" /> | ||
</selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context="com.fsck.k9.activity.setup.OAuthFlowActivity"> | ||
|
||
<include layout="@layout/toolbar" /> | ||
|
||
<ScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_weight="1" | ||
android:fadingEdge="none" | ||
android:padding="16dp" | ||
android:scrollbarStyle="outsideInset"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_vertical" | ||
android:gravity="center_horizontal" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="24dp" | ||
android:text="@string/account_setup_oauth_description" | ||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> | ||
|
||
<Button | ||
android:id="@+id/oauth_sign_in_button" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/account_setup_oauth_sign_in" | ||
android:visibility="gone" /> | ||
|
||
<Button | ||
android:id="@+id/google_sign_in_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:background="@drawable/btn_google_signin_dark" | ||
android:text="@string/account_setup_oauth_sign_in_with_google" | ||
android:textAllCaps="false" | ||
android:textColor="#ffffff" | ||
android:textSize="14sp" | ||
android:visibility="gone" | ||
tools:visibility="visible" /> | ||
|
||
<TextView | ||
android:id="@+id/error_text" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="24dp" | ||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" | ||
tools:text="@string/account_setup_failed_dlg_browser_not_found" /> | ||
|
||
</LinearLayout> | ||
|
||
</ScrollView> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters