From 33e78422bc8997273203dc6841ff49835702aa0a Mon Sep 17 00:00:00 2001 From: Sneh Date: Fri, 13 Dec 2024 14:03:23 +0530 Subject: [PATCH] Add share app and rate app functionalities with custom message and app link --- .../ui/flow/settings/SettingsScreen.kt | 36 +++++++++++++++++++ .../res/drawable/ic_setting_rate_icon.xml | 11 ++++++ .../res/drawable/ic_setting_share_icon.xml | 10 ++++++ app/src/main/res/values/strings.xml | 3 ++ 4 files changed, 60 insertions(+) create mode 100644 app/src/main/res/drawable/ic_setting_rate_icon.xml create mode 100644 app/src/main/res/drawable/ic_setting_share_icon.xml diff --git a/app/src/main/java/com/canopas/yourspace/ui/flow/settings/SettingsScreen.kt b/app/src/main/java/com/canopas/yourspace/ui/flow/settings/SettingsScreen.kt index 4625fb61..33a59461 100644 --- a/app/src/main/java/com/canopas/yourspace/ui/flow/settings/SettingsScreen.kt +++ b/app/src/main/java/com/canopas/yourspace/ui/flow/settings/SettingsScreen.kt @@ -1,6 +1,7 @@ package com.canopas.yourspace.ui.flow.settings import android.app.Activity +import android.content.Context import android.content.Intent import android.net.Uri import androidx.compose.foundation.Image @@ -186,6 +187,18 @@ private fun OtherSettingsContent(viewModel: SettingsViewModel) { } ) + SettingsItem( + label = stringResource(id = R.string.setting_share_app), + icon = R.drawable.ic_setting_share_icon, + onClick = { shareApp(context) } + ) + + SettingsItem( + label = stringResource(id = R.string.setting_rate_app), + icon = R.drawable.ic_setting_rate_icon, + onClick = { rateApp(context) } + ) + SettingsItem( label = stringResource(id = R.string.setting_btn_sign_out), icon = R.drawable.ic_setting_sign_out_icon, @@ -202,6 +215,29 @@ private fun openUrl(context: Activity, url: String) { context.startActivity(intent) } +fun shareApp(context: Context) { + val appUrl = "https://play.google.com/store/apps/details?id=${context.packageName}" + val shareMessage = context.getString(R.string.app_share_message, appUrl) + + val shareIntent = Intent().apply { + action = Intent.ACTION_SEND + putExtra(Intent.EXTRA_TEXT, shareMessage) + type = "text/plain" + } + context.startActivity( + Intent.createChooser( + shareIntent, + context.getString(R.string.setting_share_app) + ) + ) +} + +fun rateApp(context: Context) { + val appUrl = "https://play.google.com/store/apps/details?id=${context.packageName}" + val rateIntent = Intent(Intent.ACTION_VIEW, Uri.parse(appUrl)) + context.startActivity(rateIntent) +} + @Composable private fun SpaceSettingsContent( spaces: List, diff --git a/app/src/main/res/drawable/ic_setting_rate_icon.xml b/app/src/main/res/drawable/ic_setting_rate_icon.xml new file mode 100644 index 00000000..0e39bc9f --- /dev/null +++ b/app/src/main/res/drawable/ic_setting_rate_icon.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/ic_setting_share_icon.xml b/app/src/main/res/drawable/ic_setting_share_icon.xml new file mode 100644 index 00000000..74744a1e --- /dev/null +++ b/app/src/main/res/drawable/ic_setting_share_icon.xml @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 539f8f8d..7253c78e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -173,6 +173,9 @@ Privacy Policy About Us App version: %s + Share app + Rate us + Check out GroupTrack - the best app to stay connected with your loved ones! Download now: %1$s Edit profile Save