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 13, 2024
1 parent 105ff34 commit 52e04d7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
18 changes: 12 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -289,19 +289,25 @@
<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">
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts"/>
</activity>

<activity

Check failure

Code scanning / Android Lint

Unspecified android:exported in manifest Error

As of Android 12, android:exported must be set; use true to make the activity available to other apps, and false otherwise.
android:name="com.gravatar.quickeditor.ui.GravatarQuickEditorActivity"

Check failure

Code scanning / Android Lint

Missing registered class Error

Class referenced in the manifest, com.gravatar.quickeditor.ui.GravatarQuickEditorActivity, was not found in the project or the libraries
tools:node="merge">

<intent-filter>
<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>

Check warning

Code scanning / Android Lint

Application has custom scheme intent filters with missing autoVerify attributes Warning

Custom scheme intent filters should explicitly set the autoVerify attribute to true

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts"/>
</activity>

<activity-alias
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.3.0"
fragment = "1.8.5"
glance = "1.0.0"
gravatar = "2.0.0"
gravatar = "425-2090953c8b2f8b2917a74d5bd2c91c8d3b75f125"
google-services = "4.4.2"
hilt = "2.52"
hilt-compiler = "1.2.0"
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 52e04d7

Please sign in to comment.