From 4a25beab571e96d6cef5680ec9b395dd27ac960c Mon Sep 17 00:00:00 2001 From: ashb155 Date: Fri, 21 Aug 2026 22:57:39 +0530 Subject: [PATCH 1/4] rating model implementation --- .../java/be/scri/helpers/ui/RatingHelper.kt | 62 +++++++++++++++++-- .../ui/common/components/AboutPageItemComp.kt | 24 +++++-- .../ui/common/components/ItemCardContainer.kt | 1 + .../be/scri/ui/screens/about/AboutUtil.kt | 1 + 4 files changed, 78 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/be/scri/helpers/ui/RatingHelper.kt b/app/src/main/java/be/scri/helpers/ui/RatingHelper.kt index 878239292..cad009a82 100644 --- a/app/src/main/java/be/scri/helpers/ui/RatingHelper.kt +++ b/app/src/main/java/be/scri/helpers/ui/RatingHelper.kt @@ -1,10 +1,12 @@ // SPDX-License-Identifier: GPL-3.0-or-later package be.scri.helpers.ui +import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.net.Uri +import android.os.Build import android.util.Log import android.widget.Toast import androidx.activity.ComponentActivity @@ -20,6 +22,8 @@ import com.google.android.play.core.review.ReviewManagerFactory object RatingHelper { private const val INSTALLER_PLAY_STORE = "com.android.vending" private const val INSTALLER_FDROID = "org.fdroid.fdroid" + private const val INSTALLER_AMAZON = "com.amazon.venezia" + private const val INSTALLER_SAMSUNG = "com.sec.android.app.samsungapps" /** * Gets the package name of the app that installed this app. @@ -31,7 +35,12 @@ object RatingHelper { */ private fun getInstallSource(context: Context): String? = try { - context.packageManager.getInstallerPackageName(context.packageName) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + context.packageManager.getInstallSourceInfo(context.packageName).installingPackageName + } else { + @Suppress("DEPRECATION") + context.packageManager.getInstallerPackageName(context.packageName) + } } catch (e: PackageManager.NameNotFoundException) { Log.e("RatingHelper", "Failed to get install source", e) null @@ -47,11 +56,27 @@ object RatingHelper { * @param context The application context. * @param activity The current activity, required for launching the in-app review flow. */ + /** + * Gets the store description text (e.g. "Rate us on Google Play Store"). + * + * @param context App context. + * @return String for the description. + */ + fun getStoreDesc(context: Context): String? = + when (getInstallSource(context)) { + INSTALLER_PLAY_STORE -> "Rate us on Google Play Store" + INSTALLER_FDROID -> "Rate us on F-Droid" + INSTALLER_AMAZON -> "Rate us on Amazon Appstore" + INSTALLER_SAMSUNG -> "Rate us on Galaxy Store" + else -> "Rate us on your app store" + } + fun rateScribe( context: Context, activity: ComponentActivity, ) { - when (getInstallSource(context)) { + val installer = getInstallSource(context) + when (installer) { INSTALLER_PLAY_STORE -> { val reviewManager = ReviewManagerFactory.create(context) val request = reviewManager.requestReviewFlow() @@ -73,14 +98,43 @@ object RatingHelper { val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) try { context.startActivity(intent) - } catch (e: PackageManager.NameNotFoundException) { + } catch (e: ActivityNotFoundException) { Toast.makeText(context, "No browser found to open F-Droid page", Toast.LENGTH_SHORT).show() Log.e("RatingHelper", "Unable to open F-Droid link", e) } } + INSTALLER_AMAZON -> { + val url = "https://www.amazon.com/gp/mas/dl/android?p=${context.packageName}" + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + try { + context.startActivity(intent) + } catch (e: ActivityNotFoundException) { + Toast.makeText(context, "No browser found to open Amazon page", Toast.LENGTH_SHORT).show() + Log.e("RatingHelper", "Unable to open Amazon link", e) + } + } + + INSTALLER_SAMSUNG -> { + val url = "https://galaxystore.samsung.com/detail/${context.packageName}" + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + try { + context.startActivity(intent) + } catch (e: ActivityNotFoundException) { + Toast.makeText(context, "No browser found to open Galaxy Store page", Toast.LENGTH_SHORT).show() + Log.e("RatingHelper", "Unable to open Galaxy Store link", e) + } + } + else -> { - Toast.makeText(context, "Unknown installation source", Toast.LENGTH_SHORT).show() + val url = "https://play.google.com/store/apps/details?id=${context.packageName}" + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + try { + context.startActivity(intent) + } catch (e: ActivityNotFoundException) { + Toast.makeText(context, "No browser found to open Play Store page", Toast.LENGTH_SHORT).show() + Log.e("RatingHelper", "Unable to open Play Store link", e) + } } } } diff --git a/app/src/main/java/be/scri/ui/common/components/AboutPageItemComp.kt b/app/src/main/java/be/scri/ui/common/components/AboutPageItemComp.kt index 4bc29fc63..8385a007d 100644 --- a/app/src/main/java/be/scri/ui/common/components/AboutPageItemComp.kt +++ b/app/src/main/java/be/scri/ui/common/components/AboutPageItemComp.kt @@ -36,6 +36,7 @@ fun AboutPageItemComp( trailingIcon: Int, onClick: () -> Unit, modifier: Modifier = Modifier, + descText: String? = null, altText: String? = null, ) { val semanticsModifier = @@ -72,12 +73,23 @@ fun AboutPageItemComp( contentDescription = "Leading Icon", ) Spacer(modifier = Modifier.width(8.dp)) - Text( - text = title, - modifier = Modifier.weight(1f).padding(start = 4.dp), - color = MaterialTheme.colorScheme.onSurface, - style = MaterialTheme.typography.bodyMedium, - ) + androidx.compose.foundation.layout.Column( + modifier = Modifier.weight(1f).padding(start = 4.dp) + ) { + Text( + text = title, + color = MaterialTheme.colorScheme.onSurface, + style = MaterialTheme.typography.bodyMedium, + ) + if (descText != null) { + Text( + text = descText, + color = Color.Gray, + style = MaterialTheme.typography.bodySmall, + modifier = Modifier.padding(top = 4.dp), + ) + } + } Icon( painter = painterResource(trailingIcon), modifier = diff --git a/app/src/main/java/be/scri/ui/common/components/ItemCardContainer.kt b/app/src/main/java/be/scri/ui/common/components/ItemCardContainer.kt index d92e4ab45..bfc948bb2 100644 --- a/app/src/main/java/be/scri/ui/common/components/ItemCardContainer.kt +++ b/app/src/main/java/be/scri/ui/common/components/ItemCardContainer.kt @@ -64,6 +64,7 @@ fun ItemsCardContainer( is ScribeItem.ExternalLinkItem -> { AboutPageItemComp( title = stringResource(item.title), + descText = item.descText, altText = item.altText?.let { stringResource(it) }, leadingIcon = item.leadingIcon, trailingIcon = item.trailingIcon, diff --git a/app/src/main/java/be/scri/ui/screens/about/AboutUtil.kt b/app/src/main/java/be/scri/ui/screens/about/AboutUtil.kt index 6eb6e342b..5af849240 100644 --- a/app/src/main/java/be/scri/ui/screens/about/AboutUtil.kt +++ b/app/src/main/java/be/scri/ui/screens/about/AboutUtil.kt @@ -143,6 +143,7 @@ fun feedbackAndSupportList( } else { R.string.i18n_app_about_feedback_rate_scribe }, + descText = RatingHelper.getStoreDesc(context), trailingIcon = R.drawable.external_link, url = null, onClick = { onRateScribeClick() }, From 262055f1b451fa7b796339330aac55ce4157b850 Mon Sep 17 00:00:00 2001 From: ashb155 Date: Fri, 21 Aug 2026 22:57:48 +0530 Subject: [PATCH 2/4] rating model implementation 1 --- app/src/main/java/be/scri/ui/models/ScribeItem.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/be/scri/ui/models/ScribeItem.kt b/app/src/main/java/be/scri/ui/models/ScribeItem.kt index c52eaee9c..1a56f28b3 100644 --- a/app/src/main/java/be/scri/ui/models/ScribeItem.kt +++ b/app/src/main/java/be/scri/ui/models/ScribeItem.kt @@ -64,6 +64,7 @@ sealed class ScribeItem( data class ExternalLinkItem( override val title: Int, override val desc: Int? = null, + val descText: String? = null, override val altText: Int? = null, @DrawableRes val leadingIcon: Int, @DrawableRes val trailingIcon: Int, From a106f4754e9b329a34eca25a83d47b00e7679460 Mon Sep 17 00:00:00 2001 From: ashb155 Date: Fri, 21 Aug 2026 23:11:29 +0530 Subject: [PATCH 3/4] formatting fixes --- .../java/be/scri/helpers/ui/RatingHelper.kt | 20 +++++++++---------- .../ui/common/components/AboutPageItemComp.kt | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/be/scri/helpers/ui/RatingHelper.kt b/app/src/main/java/be/scri/helpers/ui/RatingHelper.kt index cad009a82..81a573dfa 100644 --- a/app/src/main/java/be/scri/helpers/ui/RatingHelper.kt +++ b/app/src/main/java/be/scri/helpers/ui/RatingHelper.kt @@ -46,16 +46,6 @@ object RatingHelper { null } - /** - * Initiates the app rating process based on the installation source. - * - * If the app was installed from the Google Play Store, it attempts to launch the in-app review flow. - * If the app was installed from F-Droid, it opens the app's F-Droid page in a browser. - * For any other installation source, it displays a toast message indicating an unknown source. - * - * @param context The application context. - * @param activity The current activity, required for launching the in-app review flow. - */ /** * Gets the store description text (e.g. "Rate us on Google Play Store"). * @@ -71,6 +61,16 @@ object RatingHelper { else -> "Rate us on your app store" } + /** + * Initiates the app rating process based on the installation source. + * + * If the app was installed from the Google Play Store, it attempts to launch the in-app review flow. + * If the app was installed from F-Droid, it opens the app's F-Droid page in a browser. + * For any other installation source, it displays a toast message indicating an unknown source. + * + * @param context The application context. + * @param activity The current activity, required for launching the in-app review flow. + */ fun rateScribe( context: Context, activity: ComponentActivity, diff --git a/app/src/main/java/be/scri/ui/common/components/AboutPageItemComp.kt b/app/src/main/java/be/scri/ui/common/components/AboutPageItemComp.kt index 8385a007d..fa0aab14a 100644 --- a/app/src/main/java/be/scri/ui/common/components/AboutPageItemComp.kt +++ b/app/src/main/java/be/scri/ui/common/components/AboutPageItemComp.kt @@ -74,7 +74,7 @@ fun AboutPageItemComp( ) Spacer(modifier = Modifier.width(8.dp)) androidx.compose.foundation.layout.Column( - modifier = Modifier.weight(1f).padding(start = 4.dp) + modifier = Modifier.weight(1f).padding(start = 4.dp), ) { Text( text = title, From f132f103d571cc0780d4b339c43976e2a92eb1c8 Mon Sep 17 00:00:00 2001 From: ashb155 Date: Fri, 21 Aug 2026 23:32:33 +0530 Subject: [PATCH 4/4] description update --- app/src/main/java/be/scri/helpers/ui/RatingHelper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/be/scri/helpers/ui/RatingHelper.kt b/app/src/main/java/be/scri/helpers/ui/RatingHelper.kt index 81a573dfa..0f372b140 100644 --- a/app/src/main/java/be/scri/helpers/ui/RatingHelper.kt +++ b/app/src/main/java/be/scri/helpers/ui/RatingHelper.kt @@ -58,7 +58,7 @@ object RatingHelper { INSTALLER_FDROID -> "Rate us on F-Droid" INSTALLER_AMAZON -> "Rate us on Amazon Appstore" INSTALLER_SAMSUNG -> "Rate us on Galaxy Store" - else -> "Rate us on your app store" + else -> "Rate us on Google Play Store" } /**