improve review prompt logic

This commit is contained in:
Phillip Thelen 2025-01-13 16:47:49 +01:00
parent 1fc471cb7a
commit fd69cf9d04
5 changed files with 59 additions and 24 deletions

View file

@ -663,7 +663,6 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
this.title = newTitle
}
}
checkForReviewPrompt(user)
}
}
@ -866,8 +865,4 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
binding.content.toolbarTitle.setPadding(0)
}
}
private fun checkForReviewPrompt(user: User) {
reviewManager.requestReview(this, user.loginIncentives)
}
}

View file

@ -2,11 +2,13 @@ package com.habitrpg.android.habitica.ui.fragments.inventory.items
import android.app.Activity
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.edit
import androidx.core.os.bundleOf
import androidx.lifecycle.lifecycleScope
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
@ -20,6 +22,7 @@ import com.habitrpg.android.habitica.extensions.addCloseButton
import com.habitrpg.android.habitica.helpers.Analytics
import com.habitrpg.android.habitica.helpers.EventCategory
import com.habitrpg.android.habitica.helpers.HitType
import com.habitrpg.android.habitica.helpers.ReviewManager
import com.habitrpg.android.habitica.interactors.HatchPetUseCase
import com.habitrpg.android.habitica.models.inventory.Egg
import com.habitrpg.android.habitica.models.inventory.Food
@ -72,6 +75,11 @@ class ItemRecyclerFragment :
@Inject
lateinit var userViewModel: MainUserViewModel
@Inject
lateinit var sharedPreferences: SharedPreferences
@Inject
lateinit var reviewManager: ReviewManager
var user: User? = null
var adapter: ItemRecyclerAdapter? = null
var itemType: String? = null
@ -273,6 +281,24 @@ class ItemRecyclerFragment :
it,
),
)
if (isAdded) {
var hatchCount = sharedPreferences.getInt("pets_hatched", 0)
hatchCount += 1
sharedPreferences.edit {
putInt("pets_hatched", hatchCount)
}
if (hatchCount >= 2) {
userViewModel.user.observeOnce(viewLifecycleOwner) { user ->
val parentActivity = activity as? MainActivity
val totalCheckIns = user?.loginIncentives
if (totalCheckIns != null && parentActivity != null) {
reviewManager.requestReview(parentActivity, totalCheckIns)
}
}
}
}
}
}
}

View file

@ -1,9 +1,11 @@
package com.habitrpg.android.habitica.ui.fragments.inventory.stable
import android.content.SharedPreferences
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.edit
import androidx.lifecycle.lifecycleScope
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.habitrpg.android.habitica.R
@ -49,14 +51,17 @@ class PetDetailRecyclerFragment :
@Inject
lateinit var userViewModel: MainUserViewModel
@Inject
lateinit var sharedPreferences: SharedPreferences
@Inject
lateinit var reviewManager: ReviewManager
val adapter: PetDetailRecyclerAdapter = PetDetailRecyclerAdapter()
private var animalType: String? = null
private var animalGroup: String? = null
private var animalColor: String? = null
internal var layoutManager: androidx.recyclerview.widget.GridLayoutManager? = null
@Inject
lateinit var reviewManager: ReviewManager
override var binding: FragmentRefreshRecyclerviewBinding? = null
@ -135,16 +140,6 @@ class PetDetailRecyclerFragment :
lifecycleScope.launchCatching {
val items = inventoryRepository.equip("pet", it)
adapter.currentPet = items?.currentPet
if (isAdded) {
userViewModel.user.observeOnce(viewLifecycleOwner) { user ->
val parentActivity = mainActivity
val totalCheckIns = user?.loginIncentives
if (totalCheckIns != null && parentActivity != null) {
reviewManager.requestReview(parentActivity, totalCheckIns)
}
}
}
}
}
userViewModel.user.observe(viewLifecycleOwner) { adapter.currentPet = it?.currentPet }
@ -247,13 +242,31 @@ class PetDetailRecyclerFragment :
): FeedResponse? {
if (food != null) {
val context = mainActivity ?: context ?: return null
return feedPetUseCase.callInteractor(
val response = feedPetUseCase.callInteractor(
FeedPetUseCase.RequestValues(
pet,
food,
context,
),
)
if (isAdded) {
var petFeedings = sharedPreferences.getInt("times_fed", 0)
petFeedings += 1
sharedPreferences.edit {
putInt("times_fed", petFeedings)
}
if (petFeedings >= 2) {
userViewModel.user.observeOnce(viewLifecycleOwner) { user ->
val parentActivity = mainActivity
val totalCheckIns = user?.loginIncentives
if (totalCheckIns != null && parentActivity != null) {
reviewManager.requestReview(parentActivity, totalCheckIns)
}
}
}
}
return response
}
return suspendCoroutine { cont ->
val fragment = ItemDialogFragment()

View file

@ -1,5 +1,6 @@
New in 4.5:
- Support for new subscription benefits
- Subscribers will now receive a Mystic Hourglass every month
- The amount of Gems subscribers can purchase in the Market will now go up +2 each month they have benefits until reaching a max of 50
- The amount of Gems subscribers can purchase in the Market will no longer reset if your benefits lapse. Subscribing again will unlock the Gem cap you left off with, even if subscribing at a lower tier.
New in 4.6.0
- Improvements to reminder scheduling to help them appear on time
- Reminders should no longer appear if a task isn't due that day
- Your avatar now shows at the top of the screen when choosing equipment, letting you see how you look as you try gear on!
- We made it easier to choose what to do with tasks from broken Challenges so they don't get stuck on your task list
- You'll now be able to leave your Party if you're participating in an active Quest

View file

@ -1,2 +1,2 @@
NAME=4.6.0
CODE=9311
CODE=9321