diff --git a/OsmAnd/src/net/osmand/plus/dialogs/RateUsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/dialogs/RateUsBottomSheetDialogFragment.java index c414004c74..67204cbbad 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/RateUsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/RateUsBottomSheetDialogFragment.java @@ -26,7 +26,6 @@ import androidx.fragment.app.FragmentManager; public class RateUsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public static final String TAG = "RateUsBottomSheetDialogFragment"; private static final Log LOG = PlatformUtil.getLog(SendAnalyticsBottomSheetDialogFragment.class); - private static final long SIXTY_DAYS = 60 * 24 * 60 * 60 * 1000L; private RateUsHelper rateUsHelper; diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ReviewHelper.java b/OsmAnd/src/net/osmand/plus/dialogs/ReviewHelper.java deleted file mode 100644 index 70a01cab2a..0000000000 --- a/OsmAnd/src/net/osmand/plus/dialogs/ReviewHelper.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.osmand.plus.dialogs; - -import android.os.Debug; -import android.util.Log; - -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.tasks.OnCompleteListener; -import com.google.android.play.core.tasks.Task; - -import net.osmand.plus.activities.MapActivity; - -import androidx.annotation.NonNull; - -public class ReviewHelper { - - public static void review(final MapActivity mapActivity) { - final ReviewManager manager = ReviewManagerFactory.create(mapActivity); - Task request = manager.requestReviewFlow(); - request.addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - if (task.isSuccessful()) { - showInAppReview(manager, mapActivity, task.getResult()); - } - } - }); - } - - private static void showInAppReview(ReviewManager manager, MapActivity mapActivity, ReviewInfo task) { - Task flow = manager.launchReviewFlow(mapActivity, task); - flow.addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - if (task.isSuccessful()) { - // TODO: Update - Log.v("M_ReviewHelper", "Shown"); - } - } - }); - } - -} diff --git a/OsmAnd/src/net/osmand/plus/helpers/RateUsHelper.java b/OsmAnd/src/net/osmand/plus/helpers/RateUsHelper.java index e61edbe5b5..29068ab46d 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/RateUsHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/RateUsHelper.java @@ -17,6 +17,8 @@ import net.osmand.plus.settings.backend.OsmandSettings; import org.apache.commons.logging.Log; +import java.lang.ref.WeakReference; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; @@ -91,14 +93,18 @@ public class RateUsHelper { } } - private static void showInAppRateDialog(final FragmentActivity activity) { + private static void showInAppRateDialog(FragmentActivity activity) { final ReviewManager reviewManager = ReviewManagerFactory.create(activity); + final WeakReference activityRef = new WeakReference<>(activity); Task requestReview = reviewManager.requestReviewFlow(); requestReview.addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { - showInAppRateDialogInternal(reviewManager, activity, task.getResult()); + FragmentActivity activity = activityRef.get(); + if (activity != null) { + showInAppRateDialogInternal(reviewManager, activity, task.getResult()); + } } else { log.error(task.getException()); } @@ -106,13 +112,17 @@ public class RateUsHelper { }); } - private static void showInAppRateDialogInternal(ReviewManager reviewManager, final FragmentActivity activity, ReviewInfo reviewInfo) { + private static void showInAppRateDialogInternal(ReviewManager reviewManager, FragmentActivity activity, ReviewInfo reviewInfo) { Task reviewFlow = reviewManager.launchReviewFlow(activity, reviewInfo); + final WeakReference activityRef = new WeakReference<>(activity); reviewFlow.addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { - storeRateResult(activity, RateUsState.IGNORED); + FragmentActivity activity = activityRef.get(); + if (activity != null) { + storeRateResult(activity, RateUsState.IGNORED); + } } else { log.error(task.getException()); }