File tree Expand file tree Collapse file tree 10 files changed +79
-11
lines changed
free/java/com/yogeshpaliyal/deepr/review
main/java/com/yogeshpaliyal/deepr
proFreePlaystore/java/com/yogeshpaliyal/deepr/review Expand file tree Collapse file tree 10 files changed +79
-11
lines changed Original file line number Diff line number Diff line change @@ -156,10 +156,12 @@ dependencies {
156156 " proImplementation" (platform(libs.firebase.bom))
157157 " proImplementation" (libs.firebase.analytics)
158158 " proImplementation" (libs.firebase.crashlytics.ndk)
159+ " proImplementation" (libs.play.core)
159160
160161 " freePlaystoreImplementation" (platform(libs.firebase.bom))
161162 " freePlaystoreImplementation" (libs.firebase.analytics)
162163 " freePlaystoreImplementation" (libs.firebase.crashlytics.ndk)
164+ " freePlaystoreImplementation" (libs.play.core)
163165}
164166
165167kotlinter {
Original file line number Diff line number Diff line change 1+ package com.yogeshpaliyal.deepr.review
2+
3+ import android.app.Activity
4+ import android.content.ActivityNotFoundException
5+ import android.content.Intent
6+ import androidx.core.net.toUri
7+ import com.yogeshpaliyal.deepr.BuildConfig
8+
9+ class PlayStoreReviewManager : ReviewManager {
10+ override fun requestReview (activity : Activity ) {
11+ val appPackageName = BuildConfig .APPLICATION_ID
12+ try {
13+ activity.startActivity(
14+ Intent (
15+ Intent .ACTION_VIEW ,
16+ " https://play.google.com/store/apps/details?id=$appPackageName " .toUri(),
17+ ),
18+ )
19+ } catch (e: ActivityNotFoundException ) {
20+ // Handle case where Play Store is not available
21+ }
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package com.yogeshpaliyal.deepr.review
2+
3+ object ReviewManagerFactory {
4+ fun create (): ReviewManager = PlayStoreReviewManager ()
5+ }
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ import com.yogeshpaliyal.deepr.backup.ImportRepositoryImpl
1313import com.yogeshpaliyal.deepr.data.HtmlParser
1414import com.yogeshpaliyal.deepr.data.NetworkRepository
1515import com.yogeshpaliyal.deepr.preference.AppPreferenceDataStore
16+ import com.yogeshpaliyal.deepr.review.ReviewManager
17+ import com.yogeshpaliyal.deepr.review.ReviewManagerFactory
1618import com.yogeshpaliyal.deepr.server.LocalServerRepository
1719import com.yogeshpaliyal.deepr.server.LocalServerRepositoryImpl
1820import com.yogeshpaliyal.deepr.sync.SyncRepository
@@ -88,6 +90,10 @@ class DeeprApplication : Application() {
8890 viewModel {
8991 LocalServerViewModel (get())
9092 }
93+
94+ single<ReviewManager > {
95+ ReviewManagerFactory .create()
96+ }
9197 }
9298
9399 startKoin {
Original file line number Diff line number Diff line change 1+ package com.yogeshpaliyal.deepr.review
2+
3+ import android.app.Activity
4+
5+ interface ReviewManager {
6+ fun requestReview (activity : Activity )
7+ }
Original file line number Diff line number Diff line change 11package com.yogeshpaliyal.deepr.ui.screens
22
3- import android.content.ActivityNotFoundException
43import android.content.Intent
54import android.widget.Toast
65import androidx.activity.compose.rememberLauncherForActivityResult
@@ -510,16 +509,7 @@ fun SettingsScreen(
510509 description = " Rate us on the Play Store" ,
511510 shouldShowLoading = false ,
512511 onClick = {
513- val appPackageName = BuildConfig .APPLICATION_ID
514- try {
515- context.startActivity(
516- Intent (
517- Intent .ACTION_VIEW ,
518- " https://play.google.com/store/apps/details?id=$appPackageName " .toUri(),
519- ),
520- )
521- } catch (e: ActivityNotFoundException ) {
522- }
512+ viewModel.requestReview(context as MainActivity )
523513 },
524514 )
525515
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ class AccountViewModel(
7676) : ViewModel(),
7777 KoinComponent {
7878 private val preferenceDataStore: AppPreferenceDataStore = get()
79+ private val reviewManager: com.yogeshpaliyal.deepr.review.ReviewManager = get()
7980 private val searchQuery = MutableStateFlow (" " )
8081
8182 // State for tags
@@ -555,4 +556,8 @@ class AccountViewModel(
555556 }
556557 }
557558 }
559+
560+ fun requestReview (activity : android.app.Activity ) {
561+ reviewManager.requestReview(activity)
562+ }
558563}
Original file line number Diff line number Diff line change 1+ package com.yogeshpaliyal.deepr.review
2+
3+ import android.app.Activity
4+ import com.google.android.play.core.review.ReviewManagerFactory
5+
6+ class InAppReviewManager : ReviewManager {
7+ override fun requestReview (activity : Activity ) {
8+ val reviewManager = ReviewManagerFactory .create(activity)
9+ val request = reviewManager.requestReviewFlow()
10+
11+ request.addOnCompleteListener { task ->
12+ if (task.isSuccessful) {
13+ // We got the ReviewInfo object
14+ val reviewInfo = task.result
15+ val flow = reviewManager.launchReviewFlow(activity, reviewInfo)
16+ flow.addOnCompleteListener {
17+ // The flow has finished. The API does not indicate whether the user
18+ // reviewed or not, or even whether the review dialog was shown.
19+ }
20+ }
21+ }
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package com.yogeshpaliyal.deepr.review
2+
3+ object ReviewManagerFactory {
4+ fun create (): ReviewManager = InAppReviewManager ()
5+ }
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ haze = "1.6.10"
3131kotlinter = " 5.2.0"
3232googleServices = " 4.4.3"
3333firebaseCrashlytics = " 3.0.6"
34+ playCore = " 1.10.3"
3435
3536[libraries ]
3637android-driver = { module = " app.cash.sqldelight:android-driver" , version.ref = " androidDriver" }
@@ -82,6 +83,7 @@ ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx
8283coil-compose = { module = " io.coil-kt.coil3:coil-compose" , version.ref = " coilCompose" }
8384coil-network-ktor3 = { module = " io.coil-kt.coil3:coil-network-ktor3" , version.ref = " coilCompose" }
8485firebase-crashlytics-ndk = { module = " com.google.firebase:firebase-crashlytics-ndk" }
86+ play-core = { module = " com.google.android.play:core" , version.ref = " playCore" }
8587androidx-work-runtime-ktx = { module = " androidx.work:work-runtime-ktx" , version.ref = " workManager" }
8688haze = { module = " dev.chrisbanes.haze:haze" , version.ref = " haze" }
8789haze-materials = { module = " dev.chrisbanes.haze:haze-materials" , version.ref = " haze" }
You can’t perform that action at this time.
0 commit comments