Add ability for users to create party from quest items

This commit is contained in:
Hafiz 2022-02-18 09:43:17 -05:00
parent c6305d9121
commit bcd2c2e2aa
4 changed files with 63 additions and 5 deletions

View file

@ -242,6 +242,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 owners 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>
@ -789,6 +791,7 @@
<string name="create">Create</string>
<string name="only_leader_create_challenge">Only leader can create Challenges</string>
<string name="create_party">Create Party</string>
<string name="create_a_party">Create a Party</string>
<string name="add_local_authentication">Add Local Authentication</string>
<string name="task_title">Task Title</string>

View file

@ -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,6 +46,7 @@ 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<Bundle>()
fun getSellItemFlowable(): Flowable<OwnedItem> {
return sellItemEvents.toFlowable(BackpressureStrategy.DROP)
@ -59,6 +62,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<Bundle> = createNewPartySubject.toFlowable(BackpressureStrategy.DROP)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
return ItemViewHolder(ItemItemBinding.inflate(context.layoutInflater, parent, false))
@ -173,7 +177,18 @@ class ItemRecyclerAdapter(val context: Context) : BaseRecyclerViewAdapter<OwnedI
dialog.quest = selectedItem
dialog.show()
} else {
questInvitationEvents.onNext(selectedItem)
if (user?.hasParty == true) {
questInvitationEvents.onNext(selectedItem)
} else {
val bundle = Bundle()
bundle.putString("groupType", "party")
bundle.putString("leader", user?.id)//Check null values
bundle.putString("name", user?.username)
bundle.putString("description", "")
bundle.putBoolean("leaderOnlyChallenges", false)
createNewPartySubject.onNext(bundle)
}
}
}
is SpecialItem -> openMysteryItemEvents.onNext(selectedItem)

View file

@ -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

View file

@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.UserComponent
@ -16,7 +17,6 @@ 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.OwnedPet
import com.habitrpg.android.habitica.models.user.User
@ -27,6 +27,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.dialogs.OpenedMysteryitemDialog
import javax.inject.Inject
@ -87,7 +88,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
@ -132,6 +133,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 {
@ -193,6 +195,44 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
}
}
private fun createNewParty(bundle: Bundle) {
val alert = context?.let { HabiticaAlertDialog(it) }//Context results?
alert?.setTitle(R.string.quest_party_required_title)
alert?.setMessage(R.string.quest_party_required_description)
alert?.addButton(R.string.create_a_party, true, false) { _, _ ->
socialRepository.createGroup(
bundle.getString("name"),
bundle.getString("description"),
bundle.getString("leader"),
"party",
bundle.getString("privacy"),
bundle.getBoolean("leaderCreateChallenge")
)
.flatMap {
userRepository.retrieveUser(false)
}
.subscribe(
{
if (isAdded) {
parentFragmentManager.popBackStack()//Needed?
}
MainNavigationController.navigate(//Same nav?
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