review-manager feedback updates

This commit is contained in:
Hafiz 2023-09-08 13:11:22 -04:00 committed by Phillip Thelen
parent d8ecc40834
commit 6b950ee4a9
8 changed files with 44 additions and 16 deletions

View file

@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.helpers
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.edit
import com.google.android.play.core.review.ReviewManagerFactory
class ReviewManager(private val context: Context) {
@ -24,13 +25,17 @@ class ReviewManager(private val context: Context) {
if (!shouldQueueReview) {
// First review request has been made, wait for following request (if any)
// to request again in the spirit of asking during a logical break.
sharedPref.edit().putBoolean(SHOULD_QUEUE_REVIEW, true).apply()
return false
sharedPref.edit {
putBoolean(SHOULD_QUEUE_REVIEW, true)
}
}
if (initialCheckins == -1) {
// Store the current checkins as the initial value
sharedPref.edit().putInt(INITIAL_CHECKINS_KEY, currentCheckins).apply()
sharedPref.edit {
putInt(INITIAL_CHECKINS_KEY, currentCheckins)
}
return true
}
@ -70,12 +75,16 @@ class ReviewManager(private val context: Context) {
}
// Save the current checkins after a successful review request
sharedPref.edit().putInt(LAST_REVIEW_CHECKIN_KEY, currentCheckins).apply()
sharedPref.edit {
putInt(LAST_REVIEW_CHECKIN_KEY, currentCheckins)
}
}
private fun incrementReviewRequestCount() {
val currentCount = sharedPref.getInt(REVIEW_REQUEST_COUNT_KEY, 0)
sharedPref.edit().putInt(REVIEW_REQUEST_COUNT_KEY, currentCount + 1).apply()
sharedPref.edit {
putInt(REVIEW_REQUEST_COUNT_KEY, currentCount + 1)
}
}
}

View file

@ -8,6 +8,7 @@ import com.habitrpg.android.habitica.BuildConfig
import com.habitrpg.android.habitica.data.ApiClient
import com.habitrpg.android.habitica.data.ContentRepository
import com.habitrpg.android.habitica.helpers.AppConfigManager
import com.habitrpg.android.habitica.helpers.ReviewManager
import com.habitrpg.android.habitica.helpers.SoundFileLoader
import com.habitrpg.android.habitica.helpers.notifications.PushNotificationManager
import com.habitrpg.common.habitica.helpers.KeyHelper
@ -100,4 +101,9 @@ class AppModule {
fun providesRemoteConfigManager(contentRepository: ContentRepository?): AppConfigManager {
return AppConfigManager(contentRepository)
}
@Provides
fun providesReviewManager(@ApplicationContext context: Context): ReviewManager {
return ReviewManager(context)
}
}

View file

@ -51,7 +51,9 @@ class ArmoireActivity : BaseActivity() {
@Inject
lateinit var userViewModel: MainUserViewModel
private lateinit var reviewManager: ReviewManager
@Inject
lateinit var reviewManager: ReviewManager
override fun getLayoutResId(): Int = R.layout.activity_armoire
@ -153,9 +155,8 @@ class ArmoireActivity : BaseActivity() {
if (args.type == "gear") {
userViewModel.user.observeOnce(this) { user ->
val totalCheckIns = user?.loginIncentives
if (totalCheckIns != null) {
reviewManager.requestReview(this@ArmoireActivity, totalCheckIns)
user?.loginIncentives?.let { totalCheckins ->
reviewManager.requestReview(this@ArmoireActivity, totalCheckins)
}
}
}

View file

@ -36,7 +36,9 @@ class ClassSelectionActivity : BaseActivity() {
@Inject
lateinit var userViewModel: MainUserViewModel
private lateinit var reviewManager: ReviewManager
@Inject
lateinit var reviewManager: ReviewManager
private lateinit var binding: ActivityClassSelectionBinding
private var currentClass: String? = null
@ -303,8 +305,9 @@ class ClassSelectionActivity : BaseActivity() {
private fun checkForReviewPromptAfterClassSelection() {
userViewModel.user.observeOnce(this) { user ->
val totalCheckIns = user?.loginIncentives ?: return@observeOnce
reviewManager.requestReview(this, totalCheckIns)
user?.loginIncentives?.let { totalCheckins ->
reviewManager.requestReview(this, totalCheckins)
}
}
}
}

View file

@ -79,6 +79,9 @@ class FullProfileActivity : BaseActivity() {
@Inject
lateinit var sharedPrefs: SharedPreferences
@Inject
lateinit var reviewManager: ReviewManager
private var userID = ""
private var username: String? = null
private var userDisplayName: String? = null
@ -90,7 +93,7 @@ class FullProfileActivity : BaseActivity() {
private val attributeRows = ArrayList<TableRow>()
private val dateFormatter = SimpleDateFormat.getDateInstance()
private lateinit var binding: ActivityFullProfileBinding
private lateinit var reviewManager: ReviewManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

View file

@ -135,7 +135,9 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
@Inject
internal lateinit var appConfigManager: AppConfigManager
private lateinit var reviewManager: ReviewManager
@Inject
lateinit var reviewManager: ReviewManager
lateinit var binding: ActivityMainBinding

View file

@ -36,7 +36,9 @@ class EquipmentDetailFragment :
override var binding: FragmentRefreshRecyclerviewBinding? = null
@Inject
lateinit var userViewModel: MainUserViewModel
private lateinit var reviewManager: ReviewManager
@Inject
lateinit var reviewManager: ReviewManager
override fun createBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRefreshRecyclerviewBinding {
return FragmentRefreshRecyclerviewBinding.inflate(inflater, container, false)

View file

@ -52,7 +52,9 @@ class PetDetailRecyclerFragment :
private var animalGroup: String? = null
private var animalColor: String? = null
internal var layoutManager: androidx.recyclerview.widget.GridLayoutManager? = null
private lateinit var reviewManager: ReviewManager
@Inject
lateinit var reviewManager: ReviewManager
override var binding: FragmentRefreshRecyclerviewBinding? = null