fix equipping things

This commit is contained in:
Phillip Thelen 2022-02-07 21:16:52 +01:00 committed by Phillip Thelen
parent 79b08159d6
commit 43c2b465f2
19 changed files with 54 additions and 41 deletions

View file

@ -15,7 +15,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.android.tools.build:gradle:7.1.0'
classpath 'net.sourceforge.pmd:pmd-java:5.5.3'
}
}
@ -155,9 +155,9 @@ android {
vectorDrawables.useSupportLibrary = true
buildConfigField "String", "STORE", "\"google\""
buildConfigField "String", "TESTING_LEVEL", "\"production\""
resConfigs "en", "bg", "de", "en-rGB", "es", "fr", "hr-rHR", "in", "it", "iw", "ja", "ko", "lt", "nl", "pl", "pt-rBR", "pt-rPT", "ru", "tr", "zh", "zh-rTW"
resConfigs 'en', 'bg', 'de', 'en-rGB', 'es', 'fr', 'hr-rHR', 'in', 'it', 'iw', 'ja', 'ko', 'lt', 'nl', 'pl', 'pt-rBR', 'pt-rPT', 'ru', 'tr', 'zh', 'zh-rTW'
versionCode 3223
versionCode 3227
versionName "3.5"
targetSdkVersion 32
@ -169,9 +169,6 @@ android {
viewBinding true
}
lintOptions {
abortOnError false
}
signingConfigs {
release
@ -271,10 +268,6 @@ android {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
lintOptions {
disable 'MissingTranslation','InvalidPackage'
enable 'LogConditional','IconExpectedSize','MissingRegistered','TypographyQuotes'
}
bundle {
language {
@ -285,6 +278,11 @@ android {
enableSplit = false
}
}
lint {
abortOnError false
disable 'MissingTranslation', 'InvalidPackage'
enable 'LogConditional', 'IconExpectedSize', 'MissingRegistered', 'TypographyQuotes'
}
}
android.testOptions {

View file

@ -106,6 +106,7 @@ import com.habitrpg.android.habitica.ui.viewmodels.MainActivityViewModel;
import com.habitrpg.android.habitica.ui.viewmodels.MainUserViewModel;
import com.habitrpg.android.habitica.ui.viewmodels.NotificationsViewModel;
import com.habitrpg.android.habitica.ui.viewmodels.inventory.equipment.EquipmentOverviewViewModel;
import com.habitrpg.android.habitica.ui.views.dialogs.PetSuggestHatchDialog;
import com.habitrpg.android.habitica.ui.views.insufficientCurrency.InsufficientGemsDialog;
import com.habitrpg.android.habitica.ui.views.shops.PurchaseDialog;
import com.habitrpg.android.habitica.ui.views.social.ChatBarView;
@ -355,4 +356,6 @@ public interface UserComponent {
void inject(@NotNull GuidelinesActivity guidelinesActivity);
void inject(@NotNull MainUserViewModel mainUserViewModel);
void inject(@NotNull PetSuggestHatchDialog petSuggestHatchDialog);
}

View file

@ -49,8 +49,8 @@ interface InventoryRepository : BaseRepository {
fun sellItem(type: String, key: String): Flowable<User>
fun sellItem(item: OwnedItem): Flowable<User>
fun equipGear(user: User?, equipment: String, asCostume: Boolean): Flowable<Items>
fun equip(user: User?, type: String, key: String): Flowable<Items>
fun equipGear(equipment: String, asCostume: Boolean): Flowable<Items>
fun equip(type: String, key: String): Flowable<Items>
fun feedPet(pet: Pet, food: Food): Flowable<FeedResponse>

View file

@ -146,13 +146,15 @@ class InventoryRepositoryImpl(localRepository: InventoryLocalRepository, apiClie
}
}
override fun equipGear(user: User?, equipment: String, asCostume: Boolean): Flowable<Items> {
return equip(user, if (asCostume) "costume" else "equipped", equipment)
override fun equipGear(equipment: String, asCostume: Boolean): Flowable<Items> {
return equip(if (asCostume) "costume" else "equipped", equipment)
}
override fun equip(user: User?, type: String, key: String): Flowable<Items> {
if (user != null) {
localRepository.modify(user) { liveUser ->
override fun equip(type: String, key: String): Flowable<Items> {
val liveUser = localRepository.getLiveUser(userID)
if (liveUser != null) {
localRepository.modify(liveUser) { liveUser ->
if (type == "mount") {
liveUser.items?.currentMount = key
} else if (type == "pet") {
@ -177,10 +179,8 @@ class InventoryRepositoryImpl(localRepository: InventoryLocalRepository, apiClie
}
return apiClient.equipItem(type, key)
.doOnNext { items ->
if (user == null) {
return@doOnNext
}
localRepository.modify(user) { liveUser ->
if (liveUser == null) return@doOnNext
localRepository.modify(liveUser) { liveUser ->
val newEquipped = items.gear?.equipped
val oldEquipped = liveUser.items?.gear?.equipped
val newCostume = items.gear?.costume

View file

@ -386,12 +386,10 @@ class UserRepositoryImpl(localRepository: UserLocalRepository, apiClient: ApiCli
override fun retrieveTeamPlan(teamID: String): Flowable<Group> {
return Flowable.zip(
apiClient.getGroup(teamID), apiClient.getTeamPlanTasks(teamID),
{ team, tasks ->
team.tasks = tasks
team
}
)
apiClient.getGroup(teamID), apiClient.getTeamPlanTasks(teamID)) { team, tasks ->
team.tasks = tasks
team
}
.doOnNext { localRepository.save(it) }
.doOnNext { team ->
val id = team.id

View file

@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.data.local
import com.habitrpg.android.habitica.models.BaseMainObject
import com.habitrpg.android.habitica.models.BaseObject
import com.habitrpg.android.habitica.models.user.User
import io.realm.Realm
interface BaseLocalRepository {
@ -24,4 +25,6 @@ interface BaseLocalRepository {
fun <T : BaseObject> save(`object`: T)
fun <T : BaseObject> saveSyncronous(`object`: T)
fun <T : BaseMainObject> delete(obj: T)
fun getLiveUser(id: String): User?
}

View file

@ -85,6 +85,10 @@ abstract class RealmBaseLocalRepository internal constructor(override var realm:
}
}
override fun getLiveUser(id: String): User? {
return realm.where(User::class.java).equalTo("id", id).findFirst()
}
override fun <T : BaseObject> getLiveObject(obj: T): T? {
if (isClosed) return null
if (obj !is RealmObject || !obj.isManaged) return obj

View file

@ -32,7 +32,7 @@ constructor(private val inventoryRepository: InventoryRepository, postExecutionT
dialog.setTitle(requestValues.context.getString(R.string.hatched_pet_title, potionName, eggName))
dialog.setAdditionalContentView(petWrapper)
dialog.addButton(R.string.equip, true) { _, _ ->
inventoryRepository.equip(null, "pet", requestValues.egg.key + "-" + requestValues.potion.key)
inventoryRepository.equip("pet", requestValues.egg.key + "-" + requestValues.potion.key)
.subscribe({}, RxErrorHandler.handleEmptyError())
}
dialog.addButton(R.string.share, false) { hatchingDialog, _ ->

View file

@ -66,7 +66,7 @@ abstract class BaseActivity : AppCompatActivity() {
return (getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater).inflate(getLayoutResId(), null)
}
protected var compositeSubscription = CompositeDisposable()
var compositeSubscription = CompositeDisposable()
private val habiticaApplication: HabiticaApplication
get() = application as HabiticaApplication

View file

@ -379,6 +379,13 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction, Snack
if (user.flags?.welcomed == false) {
viewModel.updateUser("flags.welcomed", true)
}
val title = binding.toolbarTitle.text
if (title.isBlank()) {
viewModel.getToolbarTitle(0, null, null) { newTitle ->
this.title = newTitle
}
}
}
}

View file

@ -54,7 +54,7 @@ class AvatarEquipmentFragment :
adapter.getSelectCustomizationEvents()
.flatMap { equipment ->
val key = (if (equipment.key?.isNotBlank() != true) activeEquipment else equipment.key) ?: ""
inventoryRepository.equip(userViewModel.user.value, if (userViewModel.user.value?.preferences?.costume == true) "costume" else "equipped", key)
inventoryRepository.equip(if (userViewModel.user.value?.preferences?.costume == true) "costume" else "equipped", key)
}
.subscribe({ }, RxErrorHandler.handleEmptyError())
)

View file

@ -44,7 +44,7 @@ class EquipmentDetailFragment :
savedInstanceState: Bundle?
): View? {
compositeSubscription.add(
this.adapter.equipEvents.flatMapMaybe { key -> inventoryRepository.equipGear(null, key, isCostume ?: false).firstElement() }
this.adapter.equipEvents.flatMapMaybe { key -> inventoryRepository.equipGear(key, isCostume ?: false).firstElement() }
.subscribe({ }, RxErrorHandler.handleEmptyError())
)
return super.onCreateView(inflater, container, savedInstanceState)

View file

@ -150,7 +150,7 @@ class ItemDialogFragment : BaseDialogFragment<FragmentItemsBinding>(), SwipeRefr
dialog.binding.titleView.text = it.text
dialog.binding.descriptionView.text = it.notes
dialog.addButton(R.string.equip, true) { _, _ ->
inventoryRepository.equip(user, "equipped", it.key ?: "").subscribe({}, RxErrorHandler.handleEmptyError())
inventoryRepository.equip("equipped", it.key ?: "").subscribe({}, RxErrorHandler.handleEmptyError())
}
dialog.addCloseButton()
dialog.enqueue()
@ -204,7 +204,7 @@ class ItemDialogFragment : BaseDialogFragment<FragmentItemsBinding>(), SwipeRefr
private fun feedPet(food: Food) {
val pet = feedingPet ?: return
(activity as? BaseActivity)?.let {
compositeSubscription.add(feedPetUseCase.observable(
it.compositeSubscription.add(feedPetUseCase.observable(
FeedPetUseCase.RequestValues(
pet, food,
it

View file

@ -136,7 +136,7 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
dialog.binding.titleView.text = it.text
dialog.binding.descriptionView.text = it.notes
dialog.addButton(R.string.equip, true) { _, _ ->
inventoryRepository.equip(userViewModel.user.value, "equipped", it.key ?: "").subscribe({}, RxErrorHandler.handleEmptyError())
inventoryRepository.equip("equipped", it.key ?: "").subscribe({}, RxErrorHandler.handleEmptyError())
}
dialog.addCloseButton()
dialog.enqueue()

View file

@ -89,7 +89,7 @@ class MountDetailRecyclerFragment :
binding?.recyclerView?.itemAnimator = SafeDefaultItemAnimator()
this.loadItems()
adapter?.getEquipFlowable()?.flatMap { key -> inventoryRepository.equip(null, "mount", key) }
adapter?.getEquipFlowable()?.flatMap { key -> inventoryRepository.equip("mount", key) }
?.subscribe(
{
adapter?.currentMount = it.currentMount

View file

@ -112,7 +112,7 @@ class PetDetailRecyclerFragment :
compositeSubscription.add(
adapter.getEquipFlowable()
.flatMap { key -> inventoryRepository.equip(null, "pet", key) }
.flatMap { key -> inventoryRepository.equip("pet", key) }
.subscribe(
{
adapter.currentPet = it.currentPet

View file

@ -120,7 +120,7 @@ class StableRecyclerFragment :
adapter?.let {
compositeSubscription.add(
it.getEquipFlowable()
.flatMap { key -> inventoryRepository.equip(null, if (itemType == "pets") "pet" else "mount", key) }
.flatMap { key -> inventoryRepository.equip(if (itemType == "pets") "pet" else "mount", key) }
.subscribe({ }, RxErrorHandler.handleEmptyError())
)
}

View file

@ -57,7 +57,7 @@ class AvatarSetupFragment : BaseFragment<FragmentSetupAvatarBinding>() {
this.adapter = CustomizationSetupAdapter()
this.adapter?.userSize = this.user?.preferences?.size ?: "slim"
adapter?.updateUserEvents?.flatMap { userRepository.updateUser(it) }?.subscribeWithErrorHandler {}?.let { compositeSubscription.add(it) }
adapter?.equipGearEvents?.flatMap { inventoryRepository.equip(user, "equipped", it) }?.subscribeWithErrorHandler {}?.let { compositeSubscription.add(it) }
adapter?.equipGearEvents?.flatMap { inventoryRepository.equip("equipped", it) }?.subscribeWithErrorHandler {}?.let { compositeSubscription.add(it) }
this.adapter?.user = this.user
val layoutManager = LinearLayoutManager(activity)

View file

@ -8,15 +8,15 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.android.tools.build:gradle:7.1.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
classpath "io.realm:realm-gradle-plugin:10.8.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.19.0"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
classpath 'com.google.firebase:perf-plugin:1.4.0'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.5.0-alpha01"
classpath 'com.google.firebase:perf-plugin:1.4.1'
}
}