Skip to content

Commit

Permalink
Use GravatarQuickEditorActivity instead of the BottomSheet
Browse files Browse the repository at this point in the history
As it is not viable to modify the activity to use `singleTask`, we need to implement the recently added GravatarQuickEditorActivity to handle the OAuth authorization.
  • Loading branch information
hamorillo committed Nov 19, 2024
1 parent 83e5370 commit 3544c49
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 28 deletions.
10 changes: 0 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,6 @@
<data android:pathPrefix="/get/"/>
</intent-filter>

<!-- https://lists.pocketcasts.com/.well-known/assetlinks.json is needed for this to work -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"/>
<data android:host="pocketcasts.com"/>
<data android:pathPrefix="/gravatar-qe-redirect"/>
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts"/>
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ espresso = "3.6.1"
firebase = "33.6.0"
fragment = "1.8.5"
glance = "1.0.0"
gravatar = "2.0.0"
gravatar = "2.1.0"
google-services = "4.4.2"
hilt = "2.52"
hilt-compiler = "1.2.0"
Expand Down
19 changes: 18 additions & 1 deletion modules/features/profile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application>
<activity android:name=".cloud.AddFileActivity"
Expand Down Expand Up @@ -31,6 +32,22 @@
<activity
android:name="au.com.shiftyjelly.pocketcasts.account.AccountActivity"
android:windowSoftInputMode="adjustResize" />
<activity
android:name="com.gravatar.quickeditor.ui.GravatarQuickEditorActivity"
android:exported="true"
tools:node="merge">

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https"/>
<data android:host="pocketcasts.com"/>
<data android:pathPrefix="/gravatar-qe-redirect"/>
</intent-filter>
</activity>
<service
android:name=".accountmanager.PocketCastsAuthenticatorService"
android:enabled="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ import au.com.shiftyjelly.pocketcasts.utils.log.LogBuffer
import au.com.shiftyjelly.pocketcasts.views.dialog.ConfirmationDialog
import au.com.shiftyjelly.pocketcasts.views.fragments.BaseFragment
import au.com.shiftyjelly.pocketcasts.views.helper.NavigationIcon
import com.gravatar.quickeditor.GravatarQuickEditor
import com.gravatar.quickeditor.ui.GetQuickEditorResult
import com.gravatar.quickeditor.ui.GravatarQuickEditorActivity
import com.gravatar.quickeditor.ui.GravatarQuickEditorResult
import com.gravatar.quickeditor.ui.editor.AuthenticationMethod
import com.gravatar.quickeditor.ui.editor.AvatarPickerContentLayout
import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorParams
Expand Down Expand Up @@ -103,6 +105,19 @@ class AccountDetailsFragment : BaseFragment(), OnUserViewClickListener {
private val viewModel: AccountDetailsViewModel by viewModels()
private var binding: FragmentAccountDetailsBinding? = null

private val getQEResult = registerForActivityResult(GetQuickEditorResult()) { quickEditorResult ->
when (quickEditorResult) {
GravatarQuickEditorResult.AVATAR_SELECTED -> {
Gravatar.refreshGravatarTimestamp()
viewModel.signInState.observe(viewLifecycleOwner) { signInState ->
binding?.userView?.signedInState = signInState
}
}

else -> { /* Do nothing */ }
}
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = FragmentAccountDetailsBinding.inflate(inflater, container, false)
return binding?.root
Expand Down Expand Up @@ -132,23 +147,19 @@ class AccountDetailsFragment : BaseFragment(), OnUserViewClickListener {
binding.btnChangeAvatar?.setOnClickListener {
analyticsTracker.track(AnalyticsEvent.ACCOUNT_DETAILS_CHANGE_AVATAR)
if (FeatureFlag.isEnabled(Feature.GRAVATAR_NATIVE_QUICK_EDITOR)) {
GravatarQuickEditor.show(
activity = requireActivity(),
gravatarQuickEditorParams = GravatarQuickEditorParams {
email = Email(signInState.email)
avatarPickerContentLayout = AvatarPickerContentLayout.Horizontal
},
authenticationMethod = AuthenticationMethod.OAuth(
OAuthParams {
clientId = GRAVATAR_APP_ID
redirectUri = Gravatar.GRAVATAR_QE_REDIRECT_URL
getQEResult.launch(
GravatarQuickEditorActivity.GravatarEditorActivityArguments(
gravatarQuickEditorParams = GravatarQuickEditorParams {
email = Email(signInState.email)
avatarPickerContentLayout = AvatarPickerContentLayout.Horizontal
},
authenticationMethod = AuthenticationMethod.OAuth(
OAuthParams {
clientId = GRAVATAR_APP_ID
redirectUri = Gravatar.GRAVATAR_QE_REDIRECT_URL
},
),
),
onAvatarSelected = {
Gravatar.refreshGravatarTimestamp()
binding.userView.signedInState = signInState
},
onDismiss = {},
)
} else {
Gravatar.refreshGravatarTimestamp()
Expand Down

0 comments on commit 3544c49

Please sign in to comment.