Skip to content

Commit 926eb61

Browse files
Update Gravatar to 2.0.0
1 parent da5752d commit 926eb61

File tree

9 files changed

+49
-24
lines changed

9 files changed

+49
-24
lines changed

WordPress/src/main/java/org/wordpress/android/ui/accounts/login/LoginHeaderViewHolder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ private int getAvatarSize(Context context) {
115115
}
116116
return new AvatarUrl(
117117
new Email(site.getEmail()),
118-
new AvatarQueryOptions(getAvatarSize(context), DefaultAvatarOption.Status404.INSTANCE, null, null)
119-
).url().toString();
118+
new AvatarQueryOptions.Builder()
119+
.setPreferredSize(getAvatarSize(context))
120+
.setDefaultAvatarOption(DefaultAvatarOption.Status404.INSTANCE)
121+
.build()
122+
).url(null).toString();
120123
}
121124
}

WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SignupEpilogueFragment.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import androidx.core.widget.NestedScrollView
3131
import androidx.lifecycle.lifecycleScope
3232
import com.google.android.material.dialog.MaterialAlertDialogBuilder
3333
import com.gravatar.services.AvatarService
34-
import com.gravatar.services.Result
34+
import com.gravatar.services.GravatarResult
3535
import com.gravatar.types.Email
3636
import com.yalantis.ucrop.UCrop
3737
import com.yalantis.ucrop.UCropActivity
@@ -725,12 +725,14 @@ class SignupEpilogueFragment : LoginBaseFormFragment<SignupEpilogueListener?>(),
725725
mAccountStore.accessToken?.let { accessToken ->
726726
startProgress(false)
727727
lifecycleScope.launch {
728-
val result = mAvatarService.upload(
729-
file, Email(mAccountStore.account.email),
730-
accessToken
728+
val result = mAvatarService.uploadCatching(
729+
file,
730+
accessToken,
731+
hash = Email(mAccountStore.account.email).hash(),
732+
selectAvatar = true
731733
)
732734
when (result) {
733-
is Result.Success -> {
735+
is GravatarResult.Success -> {
734736
endProgress()
735737
AnalyticsTracker.track(Stat.ME_GRAVATAR_UPLOADED)
736738
mPhotoUrl = WPAvatarUtils.rewriteAvatarUrl(
@@ -742,7 +744,7 @@ class SignupEpilogueFragment : LoginBaseFormFragment<SignupEpilogueListener?>(),
742744
mIsAvatarAdded = true
743745
}
744746

745-
is Result.Failure -> {
747+
is GravatarResult.Failure -> {
746748
endProgress()
747749
showErrorDialogWithCloseButton(getString(R.string.signup_epilogue_error_avatar))
748750
val properties: MutableMap<String, Any?> = HashMap()
@@ -834,16 +836,16 @@ class SignupEpilogueFragment : LoginBaseFormFragment<SignupEpilogueListener?>(),
834836
val uri = MediaUtils.downloadExternalMedia(context, Uri.parse(mUrl))
835837
val file = File(URI(uri.toString()))
836838
lifecycleScope.launch {
837-
when (val result = mAvatarService.upload(file, Email(mEmail), mToken)) {
838-
is Result.Success -> {
839+
when (val result = mAvatarService.uploadCatching(file, mToken, Email(mEmail).hash(), true)) {
840+
is GravatarResult.Success -> {
839841
AppLog.i(
840842
AppLog.T.NUX,
841843
"Google avatar download and Gravatar upload succeeded."
842844
)
843845
AnalyticsTracker.track(Stat.ME_GRAVATAR_UPLOADED)
844846
}
845847

846-
is Result.Failure -> {
848+
is GravatarResult.Failure -> {
847849
AppLog.i(
848850
AppLog.T.NUX,
849851
"Google avatar download and Gravatar upload failed."

WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ private void showCommentWhenNonNull(
820820
avatarUrl = WPAvatarUtils.rewriteAvatarUrl(comment.getAuthorProfileImageUrl(), avatarSz);
821821
} else if (comment.getAuthorEmail() != null) {
822822
avatarUrl = new AvatarUrl(new Email(comment.getAuthorEmail()),
823-
new AvatarQueryOptions(avatarSz, null, null, null)).url().toString();
823+
new AvatarQueryOptions.Builder().setPreferredSize(avatarSz).build()).url(null).toString();
824824
}
825825
mImageManager.loadIntoCircle(binding.imageAvatar, ImageType.AVATAR_WITH_BACKGROUND, avatarUrl);
826826

WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentViewHolder.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ class UnifiedCommentViewHolder(
8585
} else if (!TextUtils.isEmpty(comment.authorEmail)) {
8686
AvatarUrl(
8787
Email(comment.authorEmail),
88-
AvatarQueryOptions(preferredSize = resourceProvider.getDimensionPixelSize(R.dimen.avatar_sz_medium))
88+
AvatarQueryOptions {
89+
preferredSize = resourceProvider.getDimensionPixelSize(R.dimen.avatar_sz_medium)
90+
}
8991
).url().toString()
9092
} else {
9193
""

WordPress/src/main/java/org/wordpress/android/ui/main/MeFragment.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import androidx.lifecycle.lifecycleScope
2222
import com.google.android.material.dialog.MaterialAlertDialogBuilder
2323
import com.google.android.material.snackbar.Snackbar
2424
import com.gravatar.services.AvatarService
25-
import com.gravatar.services.Result
25+
import com.gravatar.services.GravatarResult
2626
import com.gravatar.types.Email
2727
import com.yalantis.ucrop.UCrop
2828
import com.yalantis.ucrop.UCrop.Options
@@ -684,15 +684,22 @@ class MeFragment : Fragment(R.layout.me_fragment), OnScrollToTopListener {
684684
}
685685
binding?.showGravatarProgressBar(true)
686686
lifecycleScope.launch {
687-
val result =
688-
avatarService.upload(file, Email(accountStore.account.email), accountStore.accessToken.orEmpty())
687+
val result = avatarService.uploadCatching(
688+
file = file,
689+
oauthToken = accountStore.accessToken.orEmpty(),
690+
hash = Email(accountStore.account.email).hash(),
691+
selectAvatar = true,
692+
)
689693
when (result) {
690-
is Result.Failure -> {
691-
AnalyticsTracker.track(ME_GRAVATAR_UPLOAD_EXCEPTION, mapOf("error_type" to result.error.name))
694+
is GravatarResult.Failure -> {
695+
AnalyticsTracker.track(
696+
ME_GRAVATAR_UPLOAD_EXCEPTION,
697+
mapOf("error_type" to result.error.javaClass.name)
698+
)
692699
EventBus.getDefault().post(GravatarUploadFinished(filePath, false))
693700
}
694701

695-
is Result.Success -> {
702+
is GravatarResult.Success -> {
696703
AnalyticsTracker.track(ME_GRAVATAR_UPLOADED)
697704
EventBus.getDefault().post(GravatarUploadFinished(filePath, true))
698705
}

WordPress/src/main/java/org/wordpress/android/util/WPAvatarUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public static String rewriteAvatarUrl(@NonNull final String imageUrl, int avatar
4646
} else {
4747
try {
4848
return new AvatarUrl(new URL(imageUrl),
49-
new AvatarQueryOptions(avatarSz, defaultImage, null, null)).url().toString();
49+
new AvatarQueryOptions.Builder()
50+
.setPreferredSize(avatarSz)
51+
.setDefaultAvatarOption(defaultImage)
52+
.build()
53+
).url(null).toString();
5054
} catch (MalformedURLException | IllegalArgumentException e) {
5155
return "";
5256
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ google-play-app-update = '2.1.0'
6363
google-play-review = '2.0.2'
6464
google-play-services-auth = '20.4.1'
6565
google-services = '4.4.2'
66-
gravatar = '1.0.0'
66+
gravatar = '2.0.0'
6767
greenrobot-eventbus = '3.3.1'
6868
gutenberg-kit = 'trunk-a58a46f3fbb892f311b562e3c122d7ef4ebbfe33'
6969
gutenberg-mobile = 'v1.121.0'

libs/login/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ext {
4040
// libs
4141
wordpressLintVersion = '2.1.0'
4242
wordpressUtilsVersion = '3.5.0'
43-
gravatarSdkVersion = '0.2.0'
43+
gravatarSdkVersion = '2.0.0'
4444

4545
// main
4646
androidxAppCompatVersion = '1.7.0'

libs/login/src/main/java/org/wordpress/android/login/util/AvatarHelper.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ object AvatarHelper {
2323
listener: AvatarRequestListener
2424
) {
2525
val avatarSize = fragment.resources.getDimensionPixelSize(R.dimen.avatar_sz_login)
26-
val avatarUrl = email?.let { AvatarUrl(Email(email),
27-
AvatarQueryOptions(preferredSize = avatarSize, defaultAvatarOption = Status404)).url().toString() }
26+
val avatarUrl = email?.let {
27+
AvatarUrl(
28+
email = Email(email),
29+
avatarQueryOptions = AvatarQueryOptions {
30+
preferredSize = avatarSize
31+
defaultAvatarOption = Status404
32+
}
33+
).url().toString()
34+
}
2835
loadAvatarFromUrl(fragment, avatarUrl, avatarView, listener)
2936
}
3037

0 commit comments

Comments
 (0)