Skip to content

Commit

Permalink
review-manager feedback updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Hafizzle authored and phillipthelen committed Sep 11, 2023
1 parent d8ecc40 commit 6b950ee
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -100,4 +101,9 @@ class AppModule {
fun providesRemoteConfigManager(contentRepository: ContentRepository?): AppConfigManager {
return AppConfigManager(contentRepository)
}

@Provides
fun providesReviewManager(@ApplicationContext context: Context): ReviewManager {
return ReviewManager(context)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6b950ee

Please sign in to comment.