-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add In-App Review Functionality for playstore flavor (#4860)
Co-authored-by: lailajs <lailajs@umich.edu>
- Loading branch information
Showing
4 changed files
with
124 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...src/fdroid/java/openfoodfacts/github/scrachx/openfood/features/scan/MainActivityHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package openfoodfacts.github.scrachx.openfood.features.scan | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.net.Uri | ||
import androidx.browser.customtabs.CustomTabsIntent | ||
import androidx.core.net.toUri | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
import openfoodfacts.github.scrachx.openfood.R | ||
import openfoodfacts.github.scrachx.openfood.customtabs.CustomTabActivityHelper | ||
import openfoodfacts.github.scrachx.openfood.customtabs.WebViewFallback | ||
import openfoodfacts.github.scrachx.openfood.utils.PreferencesService | ||
import javax.inject.Inject | ||
|
||
|
||
class MainActivityHelper @Inject constructor( | ||
private val prefManager: PreferencesService, | ||
) { | ||
|
||
/** Dialog for rating the app on play store */ | ||
fun showReviewDialog(activity: Activity, customTabsIntent: CustomTabsIntent) { | ||
val rateDialog = MaterialAlertDialogBuilder(activity).setTitle(R.string.app_name) | ||
.setMessage(R.string.user_ask_rate_app) | ||
.setPositiveButton(R.string.rate_app) { dialog, _ -> | ||
//open app page in play store | ||
activity.startActivity(Intent( | ||
Intent.ACTION_VIEW, | ||
Uri.parse("market://details?id=${activity.packageName}"), | ||
)) | ||
dialog.dismiss() | ||
} | ||
.setNegativeButton(R.string.no_thx) { dialog, _ -> dialog.dismiss() } | ||
|
||
//dialog for giving feedback | ||
val feedbackDialog = MaterialAlertDialogBuilder(activity) | ||
.setTitle(R.string.app_name) | ||
.setMessage(R.string.user_ask_show_feedback_form) | ||
.setPositiveButton(android.R.string.ok) { dialog, _ -> | ||
//show feedback form | ||
CustomTabActivityHelper.openCustomTab( | ||
activity, | ||
customTabsIntent, | ||
activity.getString(R.string.feedback_form_url).toUri(), | ||
WebViewFallback(), | ||
) | ||
dialog.dismiss() | ||
}.setNegativeButton(R.string.txtNo) { dialog, _ -> dialog.dismiss() } | ||
|
||
|
||
MaterialAlertDialogBuilder(activity) | ||
.setTitle(R.string.app_name) | ||
.setMessage(R.string.user_enjoying_app) | ||
.setPositiveButton(R.string.txtYes) { dialog, _ -> | ||
prefManager.userAskedToRate = true | ||
rateDialog.show() | ||
dialog.dismiss() | ||
} | ||
.setNegativeButton(R.string.txtNo) { dialog, _ -> | ||
prefManager.userAskedToRate = true | ||
feedbackDialog.show() | ||
dialog.dismiss() | ||
}.show() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
.../playstore/java/openfoodfacts/github/scrachx/openfood/features/scan/MainActivityHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package openfoodfacts.github.scrachx.openfood.features.scan | ||
|
||
import android.app.Activity | ||
import androidx.browser.customtabs.CustomTabsIntent | ||
import com.google.android.play.core.review.ReviewManagerFactory | ||
import javax.inject.Inject | ||
|
||
class MainActivityHelper @Inject constructor() { | ||
/** Dialog for rating the app on play store */ | ||
fun showReviewDialog( | ||
activity: Activity, | ||
@Suppress("UNUSED_PARAMETER") customTabsIntent: CustomTabsIntent, | ||
) { | ||
//dialog for rating the app on play store | ||
val manager = ReviewManagerFactory.create(activity) | ||
val request = manager.requestReviewFlow() | ||
request.addOnCompleteListener { task -> | ||
if (task.isSuccessful) { | ||
val reviewInfo = task.result | ||
manager.launchReviewFlow(activity, reviewInfo) | ||
} | ||
} | ||
} | ||
} |