Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ratings popup #187

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId = "com.emergetools.hackernews"
minSdk = 30
targetSdk = 34
versionCode = 10
versionName = "1.0.1"
versionCode = 12
versionName = "1.0.1-internal"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -136,6 +136,9 @@ dependencies {
implementation(libs.kotlinx.serialization.json)
implementation(libs.jsoup)

implementation(libs.play.review)
implementation(libs.play.review.ktx)

implementation(libs.androidx.room)
implementation(libs.androidx.room.ktx)
ksp(libs.androidx.room.compiler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.emergetools.hackernews.features.settings

import android.app.Activity
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand All @@ -23,7 +24,13 @@ import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -40,13 +47,42 @@ import com.emergetools.hackernews.ui.theme.HackerNewsTheme
import com.emergetools.hackernews.ui.theme.HackerOrange
import com.emergetools.hackernews.ui.theme.HackerRed
import com.emergetools.snapshots.annotations.EmergeAppStoreSnapshot
import com.google.android.play.core.review.ReviewInfo
import com.google.android.play.core.review.ReviewManager
import com.google.android.play.core.review.ReviewManagerFactory
import io.sentry.Sentry

@Composable
fun rememberReviewInfo(manager: ReviewManager): ReviewInfo? {
var reviewInfo: ReviewInfo? by remember { mutableStateOf(null) }
val request = manager.requestReviewFlow()
request.addOnCompleteListener { task ->
if (task.isSuccessful) {
reviewInfo = task.result
}
}
return reviewInfo
}

@Composable
fun SettingsScreen(
state: SettingsState,
actions: (SettingsAction) -> Unit,
navigation: (SettingsNavigation) -> Unit,
) {
val context = LocalContext.current
val activity = context as Activity
val reviewManager = remember { ReviewManagerFactory.create(context) }
val reviewInfo = rememberReviewInfo(reviewManager)
LaunchedEffect(reviewInfo) {
reviewInfo?.let { info ->
val flow = reviewManager.launchReviewFlow(activity, info)
flow.addOnCompleteListener {
Sentry.captureMessage("Showed Review Modal")
}
}
}

Column(
modifier = Modifier
.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ fun StoriesScreen(

val listState = rememberLazyListState()
val pullRefreshState = rememberPullToRefreshState()

val shouldLoadMore by remember {
derivedStateOf {
listState.atEndOfList()
Expand Down
4 changes: 4 additions & 0 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ room = "2.6.1"
jsoup = "1.18.1"
extendedspans = "1.4.0"
composeBom = "2024.09.03"
playReview = "2.0.1"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand Down Expand Up @@ -55,6 +56,9 @@ retrofit-kotlinx-serialization = { group = "com.squareup.retrofit2", name = "con
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" }
jsoup = { group = "org.jsoup", name = "jsoup", version.ref = "jsoup" }

play-review = { group = "com.google.android.play", name = "review", version.ref = "playReview" }
play-review-ktx = { group = "com.google.android.play", name = "review-ktx", version.ref = "playReview" }

emerge-snapshots = { group = "com.emergetools.snapshots", name = "snapshots", version.ref = "emergeSnapshots" }
emerge-snapshots-annotations = { group = "com.emergetools.snapshots", name = "snapshots-annotations", version.ref = "emergeSnapshots" }
emerge-reaper = { group = "com.emergetools.reaper", name = "reaper", version.ref = "emergeReaper" }
Expand Down