From 32c2758b3bea20416e99bf32967846f4752ab360 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Fri, 2 Feb 2024 17:05:16 +0300 Subject: [PATCH 1/3] Create an extension function to log exceptions for in-app review --- .../android/ui/utils/InAppReviewsUtils.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/utils/InAppReviewsUtils.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/utils/InAppReviewsUtils.kt b/WordPress/src/main/java/org/wordpress/android/ui/utils/InAppReviewsUtils.kt new file mode 100644 index 000000000000..fcb5260ca36e --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/utils/InAppReviewsUtils.kt @@ -0,0 +1,15 @@ +package org.wordpress.android.ui.utils + +import com.google.android.gms.tasks.Task +import com.google.android.play.core.review.ReviewException +import com.google.android.play.core.review.ReviewInfo +import com.google.android.play.core.review.model.ReviewErrorCode +import org.wordpress.android.util.AppLog + +fun Task.logException() { + val errorMessage = "Error fetching ReviewInfo object from Review API to start in-app review process" + (exception as? ReviewException)?.let { + @ReviewErrorCode val reviewErrorCode = it.errorCode + AppLog.e(AppLog.T.UTILS, errorMessage, reviewErrorCode) + } ?: AppLog.e(AppLog.T.UTILS, "$errorMessage: ${exception?.message}") +} From fb752ccc0447bdefc54caa7f608b684fff7b0e23 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Fri, 2 Feb 2024 17:07:13 +0300 Subject: [PATCH 2/3] Use the extension function to log exceptions for in-app review --- .../org/wordpress/android/ui/main/WPMainActivity.java | 10 ++-------- .../wordpress/android/ui/posts/PostsListActivity.kt | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index dc03af478cf0..63036ecc879a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -29,11 +29,9 @@ import com.google.android.gms.common.GoogleApiAvailability; import com.google.android.gms.tasks.Task; import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.google.android.play.core.review.ReviewException; import com.google.android.play.core.review.ReviewInfo; import com.google.android.play.core.review.ReviewManager; import com.google.android.play.core.review.ReviewManagerFactory; -import com.google.android.play.core.review.model.ReviewErrorCode; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -139,6 +137,7 @@ import org.wordpress.android.ui.uploads.UploadActionUseCase; import org.wordpress.android.ui.uploads.UploadUtils; import org.wordpress.android.ui.uploads.UploadUtilsWrapper; +import org.wordpress.android.ui.utils.InAppReviewsUtilsKt; import org.wordpress.android.ui.utils.JetpackAppMigrationFlowUtils; import org.wordpress.android.ui.whatsnew.FeatureAnnouncementDialogFragment; import org.wordpress.android.util.AniUtils; @@ -854,12 +853,7 @@ private void launchInAppReviews() { Task flow = manager.launchReviewFlow(this, reviewInfo); flow.addOnFailureListener(e -> AppLog.e(T.MAIN, "Error launching google review API flow.", e)); } else { - @ReviewErrorCode int reviewErrorCode = ((ReviewException) task.getException()).getErrorCode(); - AppLog.e( - T.MAIN, - "Error fetching ReviewInfo object from Review API to start in-app review process", - reviewErrorCode - ); + InAppReviewsUtilsKt.logException(task); } }); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt index 007fa44e5b05..14948e096230 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt @@ -21,9 +21,7 @@ import androidx.appcompat.widget.Toolbar import androidx.lifecycle.ViewModelProvider import androidx.viewpager.widget.ViewPager.OnPageChangeListener import com.google.android.material.snackbar.Snackbar -import com.google.android.play.core.review.ReviewException import com.google.android.play.core.review.ReviewManagerFactory -import com.google.android.play.core.review.model.ReviewErrorCode import org.wordpress.android.R import org.wordpress.android.WordPress import org.wordpress.android.databinding.PostListActivityBinding @@ -61,6 +59,7 @@ import org.wordpress.android.ui.stories.StoriesMediaPickerResultHandler import org.wordpress.android.ui.uploads.UploadActionUseCase import org.wordpress.android.ui.uploads.UploadUtilsWrapper import org.wordpress.android.ui.utils.UiHelpers +import org.wordpress.android.ui.utils.logException import org.wordpress.android.util.AppLog import org.wordpress.android.util.SnackbarItem import org.wordpress.android.util.SnackbarSequencer @@ -360,12 +359,7 @@ class PostsListActivity : LocaleAwareActivity(), AppLog.e(AppLog.T.POSTS, "Error launching google review API flow.", e) } } else { - @ReviewErrorCode val reviewErrorCode = (task.exception as ReviewException).errorCode - AppLog.e( - AppLog.T.POSTS, - "Error fetching ReviewInfo object from Review API to start in-app review process", - reviewErrorCode - ) + task.logException() } } } From 7cbbb26d3a833f40c2db6ef8d8d5b20ac4122134 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Fri, 2 Feb 2024 19:30:37 +0300 Subject: [PATCH 3/3] Move `InAppReviewsUtils` to .util.extensions package --- .../java/org/wordpress/android/ui/main/WPMainActivity.java | 4 ++-- .../java/org/wordpress/android/ui/posts/PostsListActivity.kt | 2 +- .../extensions/InAppReviewExtensions.kt} | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename WordPress/src/main/java/org/wordpress/android/{ui/utils/InAppReviewsUtils.kt => util/extensions/InAppReviewExtensions.kt} (93%) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index 63036ecc879a..20b4f805f340 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -137,7 +137,6 @@ import org.wordpress.android.ui.uploads.UploadActionUseCase; import org.wordpress.android.ui.uploads.UploadUtils; import org.wordpress.android.ui.uploads.UploadUtilsWrapper; -import org.wordpress.android.ui.utils.InAppReviewsUtilsKt; import org.wordpress.android.ui.utils.JetpackAppMigrationFlowUtils; import org.wordpress.android.ui.whatsnew.FeatureAnnouncementDialogFragment; import org.wordpress.android.util.AniUtils; @@ -183,6 +182,7 @@ import static org.wordpress.android.login.LoginAnalyticsListener.CreatedAccountSource.EMAIL; import static org.wordpress.android.push.NotificationsProcessingService.ARG_NOTIFICATION_TYPE; import static org.wordpress.android.ui.JetpackConnectionSource.NOTIFICATIONS; +import static org.wordpress.android.util.extensions.InAppReviewExtensionsKt.logException; import dagger.hilt.android.AndroidEntryPoint; @@ -853,7 +853,7 @@ private void launchInAppReviews() { Task flow = manager.launchReviewFlow(this, reviewInfo); flow.addOnFailureListener(e -> AppLog.e(T.MAIN, "Error launching google review API flow.", e)); } else { - InAppReviewsUtilsKt.logException(task); + logException(task); } }); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt index 14948e096230..de058ca0ed9b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt @@ -59,12 +59,12 @@ import org.wordpress.android.ui.stories.StoriesMediaPickerResultHandler import org.wordpress.android.ui.uploads.UploadActionUseCase import org.wordpress.android.ui.uploads.UploadUtilsWrapper import org.wordpress.android.ui.utils.UiHelpers -import org.wordpress.android.ui.utils.logException import org.wordpress.android.util.AppLog import org.wordpress.android.util.SnackbarItem import org.wordpress.android.util.SnackbarSequencer import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.extensions.getSerializableExtraCompat +import org.wordpress.android.util.extensions.logException import org.wordpress.android.util.extensions.redirectContextClickToLongPressListener import org.wordpress.android.util.extensions.setLiftOnScrollTargetViewIdAndRequestLayout import org.wordpress.android.viewmodel.observeEvent diff --git a/WordPress/src/main/java/org/wordpress/android/ui/utils/InAppReviewsUtils.kt b/WordPress/src/main/java/org/wordpress/android/util/extensions/InAppReviewExtensions.kt similarity index 93% rename from WordPress/src/main/java/org/wordpress/android/ui/utils/InAppReviewsUtils.kt rename to WordPress/src/main/java/org/wordpress/android/util/extensions/InAppReviewExtensions.kt index fcb5260ca36e..5585efcdaeda 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/utils/InAppReviewsUtils.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/extensions/InAppReviewExtensions.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.utils +package org.wordpress.android.util.extensions import com.google.android.gms.tasks.Task import com.google.android.play.core.review.ReviewException