mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
show snackbar for broken equipment
This commit is contained in:
parent
1a77acdc54
commit
e44f44bdd6
7 changed files with 37 additions and 20 deletions
|
|
@ -1459,6 +1459,7 @@
|
|||
<string name="subscribe_incentive_button_faint">Subscribe to hold on with 1HP!</string>
|
||||
<string name="subscription_benefit_armoire_sub">Your subscription gives you an extra chance at the Armoire!</string>
|
||||
<string name="subscriber_benefit_success_faint">You got a second chance with 1HP!</string>
|
||||
<string name="revive_broken_equipment">Your %s broke</string>
|
||||
|
||||
|
||||
<plurals name="you_x_others">
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ interface ApiService {
|
|||
suspend fun sleep(): HabitResponse<Boolean>
|
||||
|
||||
@POST("user/revive")
|
||||
suspend fun revive(): HabitResponse<User>
|
||||
suspend fun revive(): HabitResponse<Items>
|
||||
|
||||
@POST("user/class/cast/{skill}")
|
||||
suspend fun useSkill(
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ interface ApiClient {
|
|||
suspend fun loginApple(authToken: String): UserAuthResponse?
|
||||
|
||||
suspend fun sleep(): Boolean?
|
||||
suspend fun revive(): User?
|
||||
suspend fun revive(): Items?
|
||||
|
||||
suspend fun useSkill(skillName: String, targetType: String, targetId: String): SkillResponse?
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.habitrpg.android.habitica.models.QuestAchievement
|
|||
import com.habitrpg.android.habitica.models.Skill
|
||||
import com.habitrpg.android.habitica.models.TeamPlan
|
||||
import com.habitrpg.android.habitica.models.inventory.Customization
|
||||
import com.habitrpg.android.habitica.models.inventory.Equipment
|
||||
import com.habitrpg.android.habitica.models.responses.SkillResponse
|
||||
import com.habitrpg.android.habitica.models.responses.UnlockResponse
|
||||
import com.habitrpg.android.habitica.models.social.Group
|
||||
|
|
@ -26,7 +27,7 @@ interface UserRepository : BaseRepository {
|
|||
|
||||
suspend fun retrieveUser(withTasks: Boolean = false, forced: Boolean = false, overrideExisting: Boolean = false): User?
|
||||
|
||||
suspend fun revive(): User?
|
||||
suspend fun revive(): Equipment?
|
||||
|
||||
suspend fun resetTutorial(): User?
|
||||
|
||||
|
|
|
|||
|
|
@ -502,7 +502,7 @@ class ApiClientImpl(
|
|||
|
||||
override suspend fun sleep(): Boolean? = process { apiService.sleep() }
|
||||
|
||||
override suspend fun revive(): User? = process { apiService.revive() }
|
||||
override suspend fun revive(): Items? = process { apiService.revive() }
|
||||
|
||||
override suspend fun useSkill(skillName: String, targetType: String, targetId: String): SkillResponse? {
|
||||
return process { apiService.useSkill(skillName, targetType, targetId) }
|
||||
|
|
|
|||
|
|
@ -9,11 +9,13 @@ import com.habitrpg.android.habitica.models.Achievement
|
|||
import com.habitrpg.android.habitica.models.QuestAchievement
|
||||
import com.habitrpg.android.habitica.models.TeamPlan
|
||||
import com.habitrpg.android.habitica.models.inventory.Customization
|
||||
import com.habitrpg.android.habitica.models.inventory.Equipment
|
||||
import com.habitrpg.android.habitica.models.responses.SkillResponse
|
||||
import com.habitrpg.android.habitica.models.responses.UnlockResponse
|
||||
import com.habitrpg.android.habitica.models.social.Group
|
||||
import com.habitrpg.android.habitica.models.social.GroupMembership
|
||||
import com.habitrpg.android.habitica.models.tasks.Task
|
||||
import com.habitrpg.android.habitica.models.user.OwnedItem
|
||||
import com.habitrpg.android.habitica.models.user.Stats
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import com.habitrpg.android.habitica.models.user.UserQuestStatus
|
||||
|
|
@ -98,16 +100,17 @@ class UserRepositoryImpl(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun revive(): User? {
|
||||
val revivedUser = apiClient.revive()
|
||||
override suspend fun revive(): Equipment? {
|
||||
val items = apiClient.revive()
|
||||
val currentUser = localRepository.getLiveUser(currentUserID)
|
||||
if (revivedUser != null && currentUser != null) {
|
||||
val brokenItem = currentUser.items?.gear?.owned?.firstOrNull { equipment ->
|
||||
revivedUser.items?.gear?.owned?.filter { it.key == equipment.key }?.size == 0
|
||||
var brokenItem: Equipment? = null
|
||||
if (items != null && currentUser != null) {
|
||||
brokenItem = items.gear?.owned?.filter { it.owned == false }?.firstOrNull { equipment ->
|
||||
currentUser.items?.gear?.owned?.firstOrNull { it.key == equipment.key && it.owned == true } != null
|
||||
}
|
||||
|
||||
}
|
||||
return retrieveUser(false, true)
|
||||
retrieveUser(false, true)
|
||||
return brokenItem
|
||||
}
|
||||
|
||||
override suspend fun resetTutorial(): User? {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import com.habitrpg.common.habitica.helpers.ExceptionHandler
|
|||
import com.habitrpg.common.habitica.helpers.launchCatching
|
||||
import com.plattysoft.leonids.ParticleSystem
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Calendar
|
||||
|
|
@ -143,9 +144,13 @@ class DeathActivity : BaseActivity(), SnackbarActivity {
|
|||
}
|
||||
lifecycleScope.launch(ExceptionHandler.coroutine()) {
|
||||
userRepository.updateUser("stats.hp", 1)
|
||||
HabiticaSnackbar.showSnackbar(
|
||||
this@DeathActivity.snackbarContainer(), getString(R.string.subscriber_benefit_success_faint), HabiticaSnackbar.SnackbarDisplayType.SUCCESS, isSubscriberBenefit = true)
|
||||
delay(2000)
|
||||
MainScope().launchCatching {
|
||||
delay(1000)
|
||||
(HabiticaBaseApplication.getInstance(this@DeathActivity)?.currentActivity?.get() as? SnackbarActivity)?.let {activity ->
|
||||
HabiticaSnackbar.showSnackbar(
|
||||
activity.snackbarContainer(), getString(R.string.subscriber_benefit_success_faint), HabiticaSnackbar.SnackbarDisplayType.SUCCESS, isSubscriberBenefit = true)
|
||||
}
|
||||
}
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
|
@ -153,13 +158,20 @@ class DeathActivity : BaseActivity(), SnackbarActivity {
|
|||
binding.restartButton.setOnClickListener {
|
||||
binding.restartButton.isEnabled = false
|
||||
lifecycleScope.launch(ExceptionHandler.coroutine()) {
|
||||
userRepository.revive()
|
||||
finish()
|
||||
delay(1000)
|
||||
(HabiticaBaseApplication.getInstance(this@DeathActivity)?.currentActivity as? SnackbarActivity)?.let {activity ->
|
||||
HabiticaSnackbar.showSnackbar(
|
||||
activity.snackbarContainer(), getString(R.string.subscriber_benefit_success_faint), HabiticaSnackbar.SnackbarDisplayType.SUCCESS, isSubscriberBenefit = true)
|
||||
val brokenItem = userRepository.revive()
|
||||
if (brokenItem != null) {
|
||||
MainScope().launchCatching {
|
||||
delay(500)
|
||||
(HabiticaBaseApplication.getInstance(this@DeathActivity)?.currentActivity?.get() as? SnackbarActivity)?.let { activity ->
|
||||
HabiticaSnackbar.showSnackbar(
|
||||
activity.snackbarContainer(),
|
||||
getString(R.string.revive_broken_equipment, brokenItem.text),
|
||||
HabiticaSnackbar.SnackbarDisplayType.BLACK
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
finish()
|
||||
}
|
||||
}
|
||||
startAnimating()
|
||||
|
|
|
|||
Loading…
Reference in a new issue