mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 20:29:02 +00:00
Merge pull request #1714 from Hafizzle/Fixes#1475
Fixes#1475 - "Unclear that you need to be part of a party to start a quest"
This commit is contained in:
commit
79b08159d6
4 changed files with 66 additions and 6 deletions
|
|
@ -134,6 +134,7 @@
|
|||
<string name="reward_dialog_buy">Buy</string>
|
||||
<string name="reward_dialog_dismiss">Dismiss</string>
|
||||
<string name="party">Party</string>
|
||||
<string name="usernames_party">%s\'s Party</string>
|
||||
<string name="chat">Chat</string>
|
||||
<string name="members">Members</string>
|
||||
<string name="habits">Habits</string>
|
||||
|
|
@ -243,6 +244,8 @@
|
|||
<string name="equipped">Equipped</string>
|
||||
<string name="quest_cancel_message">Are you sure you want to cancel this Quest? Canceling the Quest will cancel all accepted and pending invitations. The Quest will be returned to the owner’s inventory.</string>
|
||||
<string name="quest_begin_message">Are you sure? Only %1$d of your %2$d party members have joined this quest! Quests start automatically when all players have joined or rejected the invitation.</string>
|
||||
<string name="quest_party_required_title">You have to be in a Party before starting a Quest</string>
|
||||
<string name="quest_party_required_description">Once in a Party, you can take on Quests by yourself or invite friends to Quest with them too!</string>
|
||||
<string name="ago_1month">1 month ago</string>
|
||||
<string name="ago_months">%d months ago</string>
|
||||
<string name="ago_1week">1w ago</string>
|
||||
|
|
@ -280,6 +283,7 @@
|
|||
<string name="hatch_with_potion">Hatch with potion</string>
|
||||
<string name="hatch_egg">Hatch with egg</string>
|
||||
<string name="invite_party">Invite party</string>
|
||||
<string name="create_new_party">Create new party</string>
|
||||
<string name="dialog_feeding">Feed %s with:</string>
|
||||
<string name="use_animal">Use</string>
|
||||
<string name="feed">Feed</string>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.ui.adapter.inventory
|
|||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.DialogFragment
|
||||
|
|
@ -12,6 +13,7 @@ import com.habitrpg.android.habitica.extensions.layoutInflater
|
|||
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.adapter.BaseRecyclerViewAdapter
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||
import com.habitrpg.android.habitica.ui.menu.BottomSheetMenu
|
||||
|
|
@ -23,7 +25,7 @@ import io.reactivex.rxjava3.subjects.PublishSubject
|
|||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class ItemRecyclerAdapter(val context: Context) : BaseRecyclerViewAdapter<OwnedItem, ItemRecyclerAdapter.ItemViewHolder>() {
|
||||
class ItemRecyclerAdapter(val context: Context, val user: User?) : BaseRecyclerViewAdapter<OwnedItem, ItemRecyclerAdapter.ItemViewHolder>() {
|
||||
|
||||
var isHatching: Boolean = false
|
||||
var isFeeding: Boolean = false
|
||||
|
|
@ -44,9 +46,9 @@ class ItemRecyclerAdapter(val context: Context) : BaseRecyclerViewAdapter<OwnedI
|
|||
private val startHatchingSubject = PublishSubject.create<Item>()
|
||||
private val hatchPetSubject = PublishSubject.create<Pair<HatchingPotion, Egg>>()
|
||||
private val feedPetSubject = PublishSubject.create<Food>()
|
||||
private val createNewPartySubject = PublishSubject.create<Boolean>()
|
||||
private val useSpecialSubject = PublishSubject.create<SpecialItem>()
|
||||
|
||||
|
||||
fun getSellItemFlowable(): Flowable<OwnedItem> {
|
||||
return sellItemEvents.toFlowable(BackpressureStrategy.DROP)
|
||||
}
|
||||
|
|
@ -61,6 +63,7 @@ class ItemRecyclerAdapter(val context: Context) : BaseRecyclerViewAdapter<OwnedI
|
|||
val startHatchingEvents: Flowable<Item> = startHatchingSubject.toFlowable(BackpressureStrategy.DROP)
|
||||
val hatchPetEvents: Flowable<Pair<HatchingPotion, Egg>> = hatchPetSubject.toFlowable(BackpressureStrategy.DROP)
|
||||
val feedPetEvents: Flowable<Food> = feedPetSubject.toFlowable(BackpressureStrategy.DROP)
|
||||
val startNewPartyEvents: Flowable<Boolean> = createNewPartySubject.toFlowable(BackpressureStrategy.DROP)
|
||||
val useSpecialEvents: Flowable<SpecialItem> = useSpecialSubject.toFlowable(BackpressureStrategy.DROP)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
|
||||
|
|
@ -159,7 +162,11 @@ class ItemRecyclerAdapter(val context: Context) : BaseRecyclerViewAdapter<OwnedI
|
|||
menu.addMenuItem(BottomSheetMenuItem(resources.getString(R.string.hatch_egg)))
|
||||
} else if (item is QuestContent) {
|
||||
menu.addMenuItem(BottomSheetMenuItem(resources.getString(R.string.details)))
|
||||
menu.addMenuItem(BottomSheetMenuItem(resources.getString(R.string.invite_party)))
|
||||
if (user?.hasParty == true){
|
||||
menu.addMenuItem(BottomSheetMenuItem(resources.getString(R.string.invite_party)))
|
||||
} else {
|
||||
menu.addMenuItem(BottomSheetMenuItem(resources.getString(R.string.create_new_party)))
|
||||
}
|
||||
} else if (item is SpecialItem) {
|
||||
val specialItem = item as SpecialItem
|
||||
if (specialItem.isMysteryItem && ownedItem?.numberOwned ?: 0 > 0) {
|
||||
|
|
@ -184,7 +191,12 @@ class ItemRecyclerAdapter(val context: Context) : BaseRecyclerViewAdapter<OwnedI
|
|||
dialog.quest = selectedItem
|
||||
dialog.show()
|
||||
} else {
|
||||
questInvitationEvents.onNext(selectedItem)
|
||||
if (user?.hasParty == true) {
|
||||
questInvitationEvents.onNext(selectedItem)
|
||||
} else {
|
||||
createNewPartySubject.onNext(true)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
is SpecialItem ->
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class ItemDialogFragment : BaseDialogFragment<FragmentItemsBinding>(), SwipeRefr
|
|||
adapter = binding?.recyclerView?.adapter as? ItemRecyclerAdapter
|
||||
if (adapter == null) {
|
||||
context?.let {
|
||||
adapter = ItemRecyclerAdapter(context)
|
||||
adapter = ItemRecyclerAdapter(context, user)
|
||||
adapter?.isHatching = this.isHatching
|
||||
adapter?.isFeeding = this.isFeeding
|
||||
adapter?.fragment = this
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.habitrpg.android.habitica.R
|
||||
|
|
@ -32,6 +33,7 @@ import com.habitrpg.android.habitica.ui.fragments.BaseFragment
|
|||
import com.habitrpg.android.habitica.ui.helpers.EmptyItem
|
||||
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
||||
import com.habitrpg.android.habitica.ui.helpers.loadImage
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.MainUserViewModel
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.OpenedMysteryitemDialog
|
||||
|
|
@ -99,7 +101,7 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
|
|||
adapter = binding?.recyclerView?.adapter as? ItemRecyclerAdapter
|
||||
if (adapter == null) {
|
||||
context?.let {
|
||||
adapter = ItemRecyclerAdapter(context)
|
||||
adapter = ItemRecyclerAdapter(context, user)
|
||||
}
|
||||
binding?.recyclerView?.adapter = adapter
|
||||
adapter?.useSpecialEvents?.subscribeWithErrorHandler { onSpecialItemSelected(it) }?.let { compositeSubscription.add(it) }
|
||||
|
|
@ -144,6 +146,7 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
|
|||
)
|
||||
compositeSubscription.add(adapter.startHatchingEvents.subscribeWithErrorHandler { showHatchingDialog(it) })
|
||||
compositeSubscription.add(adapter.hatchPetEvents.subscribeWithErrorHandler { hatchPet(it.first, it.second) })
|
||||
compositeSubscription.addAll(adapter.startNewPartyEvents.subscribeWithErrorHandler { createNewParty(it) })
|
||||
}
|
||||
}
|
||||
activity?.let {
|
||||
|
|
@ -205,6 +208,47 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
|
|||
}
|
||||
}
|
||||
|
||||
private fun createNewParty(isCreateNewParty: Boolean) {
|
||||
val alert = context?.let { HabiticaAlertDialog(it) }
|
||||
alert?.setTitle(R.string.quest_party_required_title)
|
||||
alert?.setMessage(R.string.quest_party_required_description)
|
||||
alert?.addButton(R.string.create_new_party, true, false) { _, _ ->
|
||||
socialRepository.createGroup(
|
||||
getString(R.string.usernames_party, user?.profile?.name),
|
||||
"",
|
||||
user?.id,
|
||||
"party",
|
||||
"",
|
||||
false
|
||||
)
|
||||
.flatMap {
|
||||
userRepository.retrieveUser(false, true)
|
||||
.filter { it.hasParty }
|
||||
.flatMap { socialRepository.retrieveGroup("party") }
|
||||
.flatMap { group1 ->
|
||||
socialRepository.retrieveGroupMembers(
|
||||
group1.id,
|
||||
true
|
||||
)
|
||||
}
|
||||
}
|
||||
.subscribe(
|
||||
{
|
||||
MainNavigationController.navigate(
|
||||
R.id.partyFragment,
|
||||
bundleOf(Pair("partyID", user?.party?.id))
|
||||
)
|
||||
},
|
||||
RxErrorHandler.handleEmptyError()
|
||||
)
|
||||
|
||||
}
|
||||
alert?.addButton(R.string.close, false) { _, _ ->
|
||||
alert.dismiss()
|
||||
}
|
||||
alert?.show()
|
||||
}
|
||||
|
||||
private fun loadItems() {
|
||||
val itemClass: Class<out Item> = when (itemType) {
|
||||
"eggs" -> Egg::class.java
|
||||
|
|
|
|||
Loading…
Reference in a new issue