Skip to content

Commit

Permalink
Replace QE in browser for the native one
Browse files Browse the repository at this point in the history
When the user taps over "Change Avatar" the Gravatar Native QE will be shown. If it needs authorization, the OAuth screen will be opened automatically.

^ Conflicts:
^	modules/services/utils/src/main/java/au/com/shiftyjelly/pocketcasts/utils/featureflag/Feature.kt
  • Loading branch information
hamorillo committed Oct 31, 2024
1 parent 6b59c30 commit aeea00c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,16 @@
<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
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ subprojects {
buildConfigField("String", "ENCRYPTION_KEY", "\"${project.property("encryptionKey")}\"")
buildConfigField("String", "APP_SECRET", "\"${project.property("appSecret")}\"")
buildConfigField("String", "META_APP_ID", "\"${project.property("metaAppId")}\"")
buildConfigField("String", "GRAVATAR_APP_ID", "\"${project.property("gravatarAppId")}\"")

testInstrumentationRunner = project.property("testInstrumentationRunner") as String
testApplicationId = "au.com.shiftyjelly.pocketcasts.test${project.name.replace("-", "_")}"
Expand Down
1 change: 1 addition & 0 deletions dependencies.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,6 @@ project.apply {
set("encryptionKey", secretProperties.getProperty("encryption_key", ""))
set("appSecret", secretProperties.getProperty("app_secret", ""))
set("metaAppId", secretProperties.getProperty("metaAppId", ""))
set("gravatarAppId", secretProperties.getProperty("gravatarAppId", ""))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import au.com.shiftyjelly.pocketcasts.compose.AppTheme
import au.com.shiftyjelly.pocketcasts.models.to.SignInState
import au.com.shiftyjelly.pocketcasts.models.to.SubscriptionStatus
import au.com.shiftyjelly.pocketcasts.preferences.Settings
import au.com.shiftyjelly.pocketcasts.profile.BuildConfig.GRAVATAR_APP_ID
import au.com.shiftyjelly.pocketcasts.profile.champion.PocketCastsChampionBottomSheetDialog
import au.com.shiftyjelly.pocketcasts.profile.databinding.FragmentAccountDetailsBinding
import au.com.shiftyjelly.pocketcasts.repositories.playback.PlaybackManager
Expand All @@ -46,10 +47,18 @@ import au.com.shiftyjelly.pocketcasts.settings.onboarding.OnboardingUpgradeSourc
import au.com.shiftyjelly.pocketcasts.ui.helper.FragmentHostListener
import au.com.shiftyjelly.pocketcasts.utils.Gravatar
import au.com.shiftyjelly.pocketcasts.utils.Util
import au.com.shiftyjelly.pocketcasts.utils.featureflag.Feature
import au.com.shiftyjelly.pocketcasts.utils.featureflag.FeatureFlag
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.editor.AuthenticationMethod
import com.gravatar.quickeditor.ui.editor.AvatarPickerContentLayout
import com.gravatar.quickeditor.ui.editor.GravatarQuickEditorParams
import com.gravatar.quickeditor.ui.oauth.OAuthParams
import com.gravatar.types.Email
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -122,8 +131,34 @@ class AccountDetailsFragment : BaseFragment(), OnUserViewClickListener {
if (signInState is SignInState.SignedIn) {
binding.btnChangeAvatar?.setOnClickListener {
analyticsTracker.track(AnalyticsEvent.ACCOUNT_DETAILS_CHANGE_AVATAR)
Gravatar.refreshGravatarTimestamp()
context?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Gravatar.getGravatarChangeAvatarUrl(signInState.email))))
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
},
),
onAvatarSelected = {
Gravatar.refreshGravatarTimestamp()
binding.userView.signedInState = signInState
},
onDismiss = {},
)
} else {
Gravatar.refreshGravatarTimestamp()
context?.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse(Gravatar.getGravatarChangeAvatarUrl(signInState.email)),
),
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import java.net.URLEncoder

object Gravatar {

const val GRAVATAR_QE_REDIRECT_URL = "https://pocketcasts.com/gravatar-qe-redirect"

fun getGravatarChangeAvatarUrl(email: String): String =
"https://gravatar.com/profile?is_quick_editor=true&email=${URLEncoder.encode(email, "UTF-8")}&scope=avatars&is_app_origin=true"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ enum class Feature(
hasFirebaseRemoteFlag = false,
hasDevToggle = true,
),
GRAVATAR_NATIVE_QUICK_EDITOR(
key = "gravatar_native_quick_editor",
title = "Gravatar native QE",
defaultValue = true,
tier = FeatureTier.Free,
hasFirebaseRemoteFlag = true,
hasDevToggle = true,
),
;

companion object {
Expand Down

0 comments on commit aeea00c

Please sign in to comment.