Skip to content

Commit

Permalink
[feat] in app review
Browse files Browse the repository at this point in the history
  • Loading branch information
rustamsafarovrs committed Jun 25, 2024
1 parent 4784e5e commit d3f11a7
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,6 @@ dependencies {
implementation(libs.firebase.messaging.ktx)
implementation(libs.firebase.analytics.ktx)
implementation(libs.firebase.crashlytics.ktx)

implementation(libs.google.play.review.ktx)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Preferences(context: Context) {
const val PREFS_REGION_ID = "region_id"
const val PREFS_USER_ID = "user_id"
const val PREFS_FIREBASE_TOKEN = "firebase_token"
const val PREFS_REVIEW_SHOWN = "review_shown"
}

fun saveRegionId(id: Long) {
Expand All @@ -41,4 +42,12 @@ class Preferences(context: Context) {
fun getFirebaseToken(): String {
return prefs.getString(PREFS_FIREBASE_TOKEN, null) ?: ""
}

fun saveReviewShown() {
editor.putBoolean(PREFS_REVIEW_SHOWN, true).commit()
}

fun isReviewShown(): Boolean {
return prefs.getBoolean(PREFS_REVIEW_SHOWN, false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,12 @@ class UserRepository
fun getFirebaseToken(): String {
return preferences.getFirebaseToken()
}

fun isReviewShown(): Boolean {
return preferences.isReviewShown()
}

fun saveReviewShown() {
preferences.saveReviewShown()
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/tj/rsdevteam/inmuslim/ui/home/HomeScreens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -32,6 +34,8 @@ import tj.rsdevteam.inmuslim.ui.common.ProgressIndicator
import tj.rsdevteam.inmuslim.ui.theme.InmuslimShapes
import tj.rsdevteam.inmuslim.ui.theme.InmuslimTheme
import tj.rsdevteam.inmuslim.ui.theme.InmuslimTypography
import tj.rsdevteam.inmuslim.utils.findActivity
import tj.rsdevteam.inmuslim.utils.launchInAppReview

/**
* Created by Rustam Safarov on 8/13/23.
Expand Down Expand Up @@ -60,6 +64,14 @@ fun HomeScreen(
viewModel: HomeViewModel = hiltViewModel(),
navigateToSettings: () -> Unit
) {
val context = LocalContext.current

LaunchedEffect(key1 = Unit) {
if (!viewModel.isReviewShown) {
context.findActivity().launchInAppReview { viewModel.reviewShowed() }
}
}

Scaffold(
topBar = {
TopAppBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class HomeViewModel
private set
var timing = mutableStateOf<Timing?>(null)
private set
val isReviewShown: Boolean
get() = userRepository.isReviewShown()
// endregion

init {
Expand Down Expand Up @@ -91,4 +93,8 @@ class HomeViewModel
registerUser()
}
}

fun reviewShowed() {
userRepository.saveReviewShown()
}
}
20 changes: 20 additions & 0 deletions app/src/main/java/tj/rsdevteam/inmuslim/utils/AndroidExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tj.rsdevteam.inmuslim.utils

import android.app.Activity
import com.google.android.play.core.review.ReviewManagerFactory

/**
* Created by Rustam Safarov on 6/25/24.
* github.com/rustamsafarovrs
*/

fun Activity.launchInAppReview(
onComplete: (() -> Unit)? = null,
) {
val reviewManager = ReviewManagerFactory.create(this)
reviewManager.requestReviewFlow().addOnCompleteListener { task ->
if (task.isSuccessful) {
reviewManager.launchReviewFlow(this, task.result).addOnCompleteListener { onComplete?.invoke() }
}
}
}
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ retrofit = "2.11.0"
retrofitAdapters = "1.0.11"
moshi = "1.15.1"
firebaseBom = "33.1.1"
googlePlayReview = "2.0.1"

junit = "4.13.2"
junitAndroid = "1.1.5"
Expand Down Expand Up @@ -72,6 +73,8 @@ firebase-analytics-ktx = { group = "com.google.firebase", name = "firebase-analy
firebase-crashlytics-ktx = { group = "com.google.firebase", name = "firebase-crashlytics-ktx" }
firebase-messaging-ktx = { group = "com.google.firebase", name = "firebase-messaging-ktx" }

google-play-review-ktx = { module = "com.google.android.play:review-ktx", version.ref = "googlePlayReview" }

[bundles]

[plugins]
Expand Down

0 comments on commit d3f11a7

Please sign in to comment.