mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-20 12:49:02 +00:00
Transformation items added to Item special tab
This commit is contained in:
parent
c6305d9121
commit
741b59b46b
6 changed files with 48 additions and 6 deletions
|
|
@ -35,6 +35,7 @@ interface UserRepository : BaseRepository {
|
|||
fun sleep(user: User): Flowable<User>
|
||||
|
||||
fun getSkills(user: User): Flowable<out List<Skill>>
|
||||
fun getTransformationItems(): Flowable<out List<Skill>>
|
||||
|
||||
fun getSpecialItems(user: User): Flowable<out List<Skill>>
|
||||
|
||||
|
|
|
|||
|
|
@ -124,6 +124,9 @@ class UserRepositoryImpl(localRepository: UserLocalRepository, apiClient: ApiCli
|
|||
override fun getSpecialItems(user: User): Flowable<out List<Skill>> =
|
||||
localRepository.getSpecialItems(user)
|
||||
|
||||
override fun getTransformationItems(): Flowable<out List<Skill>> =
|
||||
localRepository.getTransformationItems()
|
||||
|
||||
override fun useSkill(key: String, target: String?, taskId: String): Flowable<SkillResponse> {
|
||||
return zipWithLiveUser(apiClient.useSkill(key, target ?: "", taskId)) { response, user ->
|
||||
response.hpDiff = response.user?.stats?.hp ?: 0 - (user.stats?.hp ?: 0.0)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ interface UserLocalRepository : BaseLocalRepository {
|
|||
fun getSkills(user: User): Flowable<out List<Skill>>
|
||||
|
||||
fun getSpecialItems(user: User): Flowable<out List<Skill>>
|
||||
fun getTransformationItems(): Flowable<out List<Skill>>
|
||||
fun getAchievements(): Flowable<out List<Achievement>>
|
||||
fun getQuestAchievements(userID: String): Flowable<out List<QuestAchievement>>
|
||||
fun getUserQuestStatus(userID: String): Flowable<UserQuestStatus>
|
||||
|
|
|
|||
|
|
@ -171,4 +171,15 @@ class RealmUserLocalRepository(realm: Realm) : RealmBaseLocalRepository(realm),
|
|||
.filter { it.isLoaded }
|
||||
)
|
||||
}
|
||||
|
||||
override fun getTransformationItems(): Flowable<out List<Skill>> {
|
||||
val habitClass = "special"
|
||||
return RxJavaBridge.toV3Flowable(
|
||||
realm.where(Skill::class.java)
|
||||
.equalTo("habitClass", habitClass)
|
||||
.findAll()
|
||||
.asFlowable()
|
||||
.filter { it.isLoaded }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.databinding.ItemItemBinding
|
||||
import com.habitrpg.android.habitica.extensions.layoutInflater
|
||||
import com.habitrpg.android.habitica.models.Skill
|
||||
import com.habitrpg.android.habitica.models.inventory.*
|
||||
import com.habitrpg.android.habitica.models.user.OwnedItem
|
||||
import com.habitrpg.android.habitica.models.user.OwnedPet
|
||||
|
|
@ -110,10 +111,14 @@ class ItemRecyclerAdapter(val context: Context) : BaseRecyclerViewAdapter<OwnedI
|
|||
val imageName: String?
|
||||
if (item is QuestContent) {
|
||||
imageName = "inventory_quest_scroll_" + ownedItem.key
|
||||
} else if (item is SpecialItem) {
|
||||
val sdf = SimpleDateFormat("MM", Locale.getDefault())
|
||||
val month = sdf.format(Date())
|
||||
imageName = "inventory_present_$month"
|
||||
} else if (ownedItem.itemType == "special") {
|
||||
if (item is SpecialItem){
|
||||
val sdf = SimpleDateFormat("MM", Locale.getDefault())
|
||||
val month = sdf.format(Date())
|
||||
imageName = "inventory_present_$month"
|
||||
}else{
|
||||
imageName = "shop_" + ownedItem.key
|
||||
}
|
||||
} else {
|
||||
val type = when (ownedItem.itemType) {
|
||||
"eggs" -> "Egg"
|
||||
|
|
@ -203,4 +208,17 @@ class ItemRecyclerAdapter(val context: Context) : BaseRecyclerViewAdapter<OwnedI
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setSpecialItems(skillItems: List<Skill>, ownedItems: MutableList<OwnedItem>){
|
||||
val transformationItems: MutableList<OwnedItem> = mutableListOf()
|
||||
for (item in skillItems){
|
||||
val ownedTransformationItem = OwnedItem()
|
||||
ownedTransformationItem.key = item.key
|
||||
ownedTransformationItem.itemType = item.habitClass
|
||||
ownedTransformationItem.numberOwned = 5 //Test
|
||||
transformationItems.add(ownedTransformationItem)
|
||||
}
|
||||
data = ownedItems + transformationItems
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ import com.habitrpg.android.habitica.extensions.subscribeWithErrorHandler
|
|||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.interactors.HatchPetUseCase
|
||||
import com.habitrpg.android.habitica.interactors.NotifyUserUseCase
|
||||
import com.habitrpg.android.habitica.models.inventory.*
|
||||
import com.habitrpg.android.habitica.models.user.OwnedItem
|
||||
import com.habitrpg.android.habitica.models.user.OwnedPet
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import com.habitrpg.android.habitica.ui.activities.BaseActivity
|
||||
|
|
@ -43,6 +43,7 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
|
|||
|
||||
var adapter: ItemRecyclerAdapter? = null
|
||||
var itemType: String? = null
|
||||
var transformationItems: MutableList<OwnedItem> = mutableListOf()
|
||||
var itemTypeText: String? = null
|
||||
var user: User? = null
|
||||
internal var layoutManager: androidx.recyclerview.widget.LinearLayoutManager? = null
|
||||
|
|
@ -208,9 +209,16 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
|
|||
.map { it.distinctBy { it.key } }
|
||||
.doOnNext { items ->
|
||||
adapter?.data = items
|
||||
if (itemType == "special") {
|
||||
transformationItems = items.toMutableList()
|
||||
userRepository.getTransformationItems()
|
||||
.subscribe { skillItems -> adapter?.setSpecialItems(skillItems, transformationItems) }
|
||||
}
|
||||
}
|
||||
.map { items -> items.mapNotNull { it.key } }
|
||||
.flatMap { inventoryRepository.getItems(itemClass, it.toTypedArray()) }
|
||||
.flatMap {
|
||||
inventoryRepository.getItems(itemClass, it.toTypedArray())
|
||||
}
|
||||
.map {
|
||||
val itemMap = mutableMapOf<String, Item>()
|
||||
for (item in it) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue