mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-13 17:51:57 +00:00
Improve leaving guilds and parties. Fixes #906
This commit is contained in:
parent
dd7ff58e8b
commit
0769ddc7e9
12 changed files with 55 additions and 41 deletions
|
|
@ -500,7 +500,7 @@
|
|||
<string name="welcome_back">Welcome Back</string>
|
||||
<string name="yesterdaililes_prompt">Check off any Dailies you did yesterday:</string>
|
||||
<string name="start_day">Start My Day</string>
|
||||
<string name="leave_party_confirmation">Are you sure you want to leave the Party?</string>
|
||||
<string name="leave_party_confirmation">Do you want to leave the party and keep or leave the challenges?</string>
|
||||
<string name="pending">Pending</string>
|
||||
<string name="accepted">Accepted</string>
|
||||
<string name="declined">Declined</string>
|
||||
|
|
@ -771,6 +771,7 @@
|
|||
<string name="report_violation">Report Violation</string>
|
||||
<string name="trillion_abbrev">t</string>
|
||||
<string name="leave_guild">Leave Guild</string>
|
||||
<string name="leave_guild_confirmation">Do you want to leave the guild and keep or leave the challenges?</string>
|
||||
<string name="left_guild">You left the guild</string>
|
||||
<string name="joined_guild">You joined the guild</string>
|
||||
<string name="cost">Cost</string>
|
||||
|
|
@ -833,4 +834,6 @@
|
|||
<string name="joinedChallengeDescription">You put themselves to the test by joining a Challenge!</string>
|
||||
<string name="inviteFriendTitle">Invited a Friend</string>
|
||||
<string name="inviteFriendDescription">You invited a friend (or friends) who joined you on your adventure!</string>
|
||||
<string name="keep_challenges">Keep Challenges</string>
|
||||
<string name="leave_challenges">Leave Challenges</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ interface ApiService {
|
|||
fun joinGroup(@Path("gid") groupId: String): Flowable<HabitResponse<Group>>
|
||||
|
||||
@POST("groups/{gid}/leave")
|
||||
fun leaveGroup(@Path("gid") groupId: String): Flowable<HabitResponse<Void>>
|
||||
fun leaveGroup(@Path("gid") groupId: String, @Query("keepChallenges") keepChallenges: String): Flowable<HabitResponse<Void>>
|
||||
|
||||
@POST("groups/{gid}/chat")
|
||||
fun postGroupChat(@Path("gid") groupId: String, @Body message: Map<String, String>): Flowable<HabitResponse<PostChatMessageResult>>
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ interface ApiClient {
|
|||
|
||||
fun joinGroup(groupId: String): Flowable<Group>
|
||||
|
||||
fun leaveGroup(groupId: String): Flowable<Void>
|
||||
fun leaveGroup(groupId: String, keepChallenges: String): Flowable<Void>
|
||||
|
||||
fun postGroupChat(groupId: String, message: Map<String, String>): Flowable<PostChatMessageResult>
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ interface SocialRepository : BaseRepository {
|
|||
fun retrieveGroup(id: String): Flowable<Group>
|
||||
fun getGroup(id: String?): Flowable<Group>
|
||||
|
||||
fun leaveGroup(id: String?): Flowable<Group>
|
||||
fun leaveGroup(id: String?, keepChallenges: Boolean): Flowable<Group>
|
||||
|
||||
fun joinGroup(id: String?): Flowable<Group>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.habitrpg.android.habitica.data.implementation
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.amplitude.api.Amplitude
|
||||
import com.google.gson.JsonSyntaxException
|
||||
import com.habitrpg.android.habitica.BuildConfig
|
||||
|
|
@ -124,7 +123,6 @@ class ApiClientImpl//private OnHabitsAPIResult mResultListener;
|
|||
val request = builder.method(original.method(), original.body())
|
||||
.build()
|
||||
lastAPICallURL = original.url().toString()
|
||||
Log.d("NETWORK", lastAPICallURL)
|
||||
chain.proceed(request)
|
||||
}
|
||||
.readTimeout(2400, TimeUnit.SECONDS)
|
||||
|
|
@ -493,8 +491,8 @@ class ApiClientImpl//private OnHabitsAPIResult mResultListener;
|
|||
return apiService.joinGroup(groupId).compose(configureApiCallObserver())
|
||||
}
|
||||
|
||||
override fun leaveGroup(groupId: String): Flowable<Void> {
|
||||
return apiService.leaveGroup(groupId).compose(configureApiCallObserver())
|
||||
override fun leaveGroup(groupId: String, keepChallenges: String): Flowable<Void> {
|
||||
return apiService.leaveGroup(groupId, keepChallenges).compose(configureApiCallObserver())
|
||||
}
|
||||
|
||||
override fun postGroupChat(groupId: String, message: Map<String, String>): Flowable<PostChatMessageResult> {
|
||||
|
|
|
|||
|
|
@ -139,11 +139,11 @@ class SocialRepositoryImpl(localRepository: SocialLocalRepository, apiClient: Ap
|
|||
return localRepository.getGroup(id)
|
||||
}
|
||||
|
||||
override fun leaveGroup(id: String?): Flowable<Group> {
|
||||
override fun leaveGroup(id: String?, keepChallenges: Boolean): Flowable<Group> {
|
||||
if (id == null) {
|
||||
return Flowable.empty()
|
||||
}
|
||||
return apiClient.leaveGroup(id)
|
||||
return apiClient.leaveGroup(id, if (keepChallenges) "remain-in-challenges" else "leave-challenges")
|
||||
.doOnNext { localRepository.updateMembership(userID, id, false) }
|
||||
.flatMapMaybe { localRepository.getGroup(id).firstElement() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class PublicGuildsRecyclerViewAdapter(data: OrderedRealmCollection<Group>?, auto
|
|||
val guild = v.tag as? Group ?: return@setOnClickListener
|
||||
val isMember = this.memberGuildIDs.contains(guild.id)
|
||||
if (isMember) {
|
||||
this@PublicGuildsRecyclerViewAdapter.socialRepository?.leaveGroup(guild.id)
|
||||
this@PublicGuildsRecyclerViewAdapter.socialRepository?.leaveGroup(guild.id, true)
|
||||
?.subscribe(Consumer {
|
||||
if (data != null) {
|
||||
val indexOfGroup = data?.indexOf(guild)
|
||||
|
|
|
|||
|
|
@ -19,11 +19,10 @@ import com.habitrpg.android.habitica.helpers.AppConfigManager
|
|||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||
import com.habitrpg.android.habitica.models.members.Member
|
||||
import com.habitrpg.android.habitica.models.social.Group
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import com.habitrpg.android.habitica.ui.AvatarView
|
||||
import com.habitrpg.android.habitica.ui.activities.GroupFormActivity
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity
|
||||
import com.habitrpg.android.habitica.ui.activities.GroupInviteActivity
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarkdownParser
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
|
|
@ -32,6 +31,7 @@ import com.habitrpg.android.habitica.ui.viewmodels.GroupViewModel
|
|||
import com.habitrpg.android.habitica.ui.views.HabiticaIcons
|
||||
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
|
||||
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||
import com.habitrpg.android.habitica.ui.views.social.UsernameLabel
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
|
@ -77,12 +77,7 @@ class GuildDetailFragment : BaseFragment() {
|
|||
guildDescriptionView.movementMethod = LinkMovementMethod.getInstance()
|
||||
guildBankIconView.setImageBitmap(HabiticaIconsHelper.imageOfGem())
|
||||
leaveGuildButton.setOnClickListener {
|
||||
viewModel?.leaveGroup {
|
||||
val activity = activity as? MainActivity
|
||||
if (activity != null) {
|
||||
HabiticaSnackbar.showSnackbar(activity.snackbarContainer, getString(R.string.left_guild), HabiticaSnackbar.SnackbarDisplayType.NORMAL)
|
||||
}
|
||||
}
|
||||
leaveGuild()
|
||||
}
|
||||
joinGuildButton.setOnClickListener {
|
||||
viewModel?.joinGroup {
|
||||
|
|
@ -159,6 +154,29 @@ class GuildDetailFragment : BaseFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
internal fun leaveGuild() {
|
||||
val context = context
|
||||
if (context != null) {
|
||||
val alert = HabiticaAlertDialog(context)
|
||||
alert.setMessage(R.string.leave_guild_confirmation)
|
||||
alert.addButton(R.string.keep_challenges, true) { _, _ ->
|
||||
viewModel?.leaveGroup(true) { showLeaveSnackbar() }
|
||||
}
|
||||
alert.addButton(R.string.leave_challenges, true) { _, _ ->
|
||||
viewModel?.leaveGroup(false) { showLeaveSnackbar() }
|
||||
}
|
||||
alert.addButton(R.string.no, false)
|
||||
alert.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showLeaveSnackbar() {
|
||||
val activity = activity as? MainActivity
|
||||
if (activity != null) {
|
||||
HabiticaSnackbar.showSnackbar(activity.snackbarContainer, getString(R.string.left_guild), HabiticaSnackbar.SnackbarDisplayType.NORMAL)
|
||||
}
|
||||
}
|
||||
|
||||
override fun injectFragment(component: UserComponent) {
|
||||
component.inject(this)
|
||||
}
|
||||
|
|
@ -173,7 +191,7 @@ class GuildDetailFragment : BaseFragment() {
|
|||
}
|
||||
|
||||
companion object {
|
||||
fun newInstance(viewModel: GroupViewModel?, user: User?): GuildDetailFragment {
|
||||
fun newInstance(viewModel: GroupViewModel?): GuildDetailFragment {
|
||||
val args = Bundle()
|
||||
|
||||
val fragment = GuildDetailFragment()
|
||||
|
|
|
|||
|
|
@ -108,13 +108,17 @@ class GuildFragment : BaseMainFragment() {
|
|||
return true
|
||||
}
|
||||
R.id.menu_guild_leave -> {
|
||||
viewModel.leaveGroup { fragmentManager?.popBackStack() }
|
||||
guildInformationFragment?.leaveGuild()
|
||||
return true
|
||||
}
|
||||
R.id.menu_guild_edit -> {
|
||||
this.displayEditForm()
|
||||
return true
|
||||
}
|
||||
R.id.action_reload -> {
|
||||
viewModel.retrieveGroup { }
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
|
@ -130,7 +134,7 @@ class GuildFragment : BaseMainFragment() {
|
|||
|
||||
when (position) {
|
||||
0 -> {
|
||||
guildInformationFragment = GuildDetailFragment.newInstance(viewModel, user)
|
||||
guildInformationFragment = GuildDetailFragment.newInstance(viewModel)
|
||||
fragment = guildInformationFragment
|
||||
}
|
||||
1 -> {
|
||||
|
|
|
|||
|
|
@ -279,13 +279,16 @@ class PartyDetailFragment : BaseFragment() {
|
|||
fragmentManager?.let { fragment.show(it, "questDialog") }
|
||||
}
|
||||
|
||||
private fun leaveParty() {
|
||||
internal fun leaveParty() {
|
||||
val context = context
|
||||
if (context != null) {
|
||||
val alert = HabiticaAlertDialog(context)
|
||||
alert.setMessage(R.string.leave_party_confirmation)
|
||||
alert.addButton(R.string.yes, true) { _, _ ->
|
||||
viewModel?.leaveGroup { }
|
||||
alert.addButton(R.string.keep_challenges, true) { _, _ ->
|
||||
viewModel?.leaveGroup(true) { }
|
||||
}
|
||||
alert.addButton(R.string.leave_challenges, true) { _, _ ->
|
||||
viewModel?.leaveGroup(false) { }
|
||||
}
|
||||
alert.addButton(R.string.no, false)
|
||||
alert.show()
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import com.habitrpg.android.habitica.ui.helpers.bindView
|
|||
import com.habitrpg.android.habitica.ui.helpers.resetViews
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.GroupViewType
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.PartyViewModel
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||
import io.reactivex.functions.Consumer
|
||||
import java.util.*
|
||||
|
||||
|
|
@ -153,18 +152,7 @@ class PartyFragment : BaseMainFragment() {
|
|||
return true
|
||||
}
|
||||
R.id.menu_guild_leave -> {
|
||||
context?.let {
|
||||
val alert = HabiticaAlertDialog(it)
|
||||
alert.setTitle(context?.getString(R.string.leave_party))
|
||||
alert.setMessage(context?.getString(R.string.leave_party_confirmation))
|
||||
alert.addButton(R.string.yes, true) { _, _ ->
|
||||
viewModel.leaveGroup {
|
||||
fragmentManager?.popBackStack()
|
||||
}
|
||||
}
|
||||
alert.addButton(R.string.no, false)
|
||||
alert.show()
|
||||
}
|
||||
(firstFragment as? PartyDetailFragment)?.leaveParty()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,9 +160,9 @@ open class GroupViewModel : BaseViewModel() {
|
|||
}
|
||||
}
|
||||
|
||||
fun leaveGroup(function: (() -> Unit)? = null) {
|
||||
disposable.add(socialRepository.leaveGroup(this.group.value?.id ?: "")
|
||||
.flatMap { userRepository.retrieveUser(false, true) }
|
||||
fun leaveGroup(keepChallenges: Boolean = true, function: (() -> Unit)? = null) {
|
||||
disposable.add(socialRepository.leaveGroup(this.group.value?.id ?: "", keepChallenges)
|
||||
.flatMap { userRepository.retrieveUser(withTasks = false, forced = true) }
|
||||
.subscribe(Consumer {
|
||||
function?.invoke()
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
|
|
|
|||
Loading…
Reference in a new issue