Merge pull request #1304 from HiroinaProtagonist/party-invite

Party invite
This commit is contained in:
Phillip Thelen 2020-06-11 14:21:28 +02:00 committed by GitHub
commit 1956df6f66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 151 additions and 30 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--Infrastructure for animated button-->
<!--item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/picture" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/picture_pressed" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/picture_pressed" /-->
<item android:drawable="@drawable/party_invite_accept" />
</selector>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--Infrastructure for animated button-->
<!--item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/picture" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/picture_pressed" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/picture_pressed" /-->
<item android:drawable="@drawable/party_invite_reject" />
</selector>

View file

@ -78,7 +78,7 @@
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"/>
<Button
android:id="@+id/craetePartyButton"
android:id="@+id/createPartyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/HabiticaButton.Gray.600"

View file

@ -1,32 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_view"
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/invited_to_party" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="end">
style="@style/CardView.Default"
android:id="@+id/party_invitation_wrapper">
<LinearLayout
android:orientation="horizontal"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/CardContent">
<Button
android:id="@+id/accept_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/quest_accept"
android:textColor="@color/btn_success"
style="?android:buttonBarButtonStyle" />
<com.habitrpg.android.habitica.ui.RoundedFrameLayout
android:layout_width="@dimen/party_invite_avatar"
android:layout_height="@dimen/party_invite_avatar"
android:clipChildren="true"
android:layout_marginEnd="@dimen/spacing_medium"
android:background="@drawable/rounded_avatar_bg">
<com.habitrpg.android.habitica.ui.AvatarView
android:id="@+id/groupleader_avatar_view"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
app:showBackground="true"
app:showMount="false"
app:showPet="false" />
</com.habitrpg.android.habitica.ui.RoundedFrameLayout>
<Button
android:id="@+id/reject_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/quest_reject"
android:textColor="@color/btn_danger"
style="?android:buttonBarButtonStyle" />
</LinearLayout>
<TextView
android:id="@+id/groupleader_text_view"
android:layout_width="@dimen/party_invite_text_width"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/party_invite_separator"
android:text="@string/invitation_title" />
<Space
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginEnd="@dimen/party_invite_separator"
android:layout_gravity="end|center_vertical|fill_horizontal">
<Button
android:id="@+id/accept_button"
android:layout_width="@dimen/party_invite_button"
android:layout_height="@dimen/party_invite_button"
android:layout_marginEnd="@dimen/party_accept_button_start_margin"
android:background="@drawable/party_invite_accept" />
<Button
android:id="@+id/reject_button"
android:layout_width="@dimen/party_invite_button"
android:layout_height="@dimen/party_invite_button"
android:layout_marginStart="@dimen/party_accept_button_start_margin"
android:background="@drawable/party_invite_reject" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>

View file

@ -13,6 +13,12 @@
<dimen name="section_top_padding">16dp</dimen>
<dimen name="card_margin">6dp</dimen>
<dimen name="party_invite_button">31dp</dimen>
<dimen name="party_accept_button_start_margin">5dp</dimen>
<dimen name="party_invite_avatar">46dp</dimen> <!--50?-->
<dimen name="party_invite_separator">4dp</dimen>
<dimen name="party_invite_text_width">140dp</dimen>
<dimen name="bar_size">15dp</dimen>
<dimen name="bar_padding">5dp</dimen>
<dimen name="bar_padding_small">2dp</dimen>

View file

@ -910,7 +910,7 @@
<string name="id_copied">Copied User ID to clipboard</string>
<string name="copy_username">Copy Username</string>
<string name="password_too_short">Your password has to be at least %d characters long</string>
<string name="invitation_title">%s invited you to %s</string>
<string name="invitation_title">%s invited you to join their group %s</string>
<string name="someone">Someone</string>
<string name="authentication_methods">Authentication Methods</string>
<string name="local">local</string>

View file

@ -65,6 +65,17 @@ class NoPartyFragmentFragment : BaseMainFragment() {
invitations_view.rejectCall = {
socialRepository.rejectGroupInvite(it).subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
invitationWrapper.visibility = View.GONE
}
invitations_view.setLeader = { leader ->
compositeSubscription.add(
socialRepository.getMember(leader)
.subscribe(Consumer {
invitations_view.avatarView.setAvatar(it)
invitations_view.textView.text = getString(R.string.invitation_title,it.displayName,invitations_view.groupName)
}, RxErrorHandler.handleEmptyError())
)
}
username_textview.setOnClickListener {
@ -77,7 +88,7 @@ class NoPartyFragmentFragment : BaseMainFragment() {
}
}
craetePartyButton.setOnClickListener {
createPartyButton.setOnClickListener {
val bundle = Bundle()
bundle.putString("groupType", "party")
bundle.putString("leader", user?.id)

View file

@ -24,6 +24,7 @@ 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.modules.AppModule
import com.habitrpg.android.habitica.ui.AvatarView
import com.habitrpg.android.habitica.ui.activities.FullProfileActivity
import com.habitrpg.android.habitica.ui.activities.MainActivity
import com.habitrpg.android.habitica.ui.fragments.BaseFragment
@ -44,7 +45,7 @@ import kotlinx.coroutines.launch
import net.pherth.android.emoji_library.EmojiEditText
import javax.inject.Inject
import javax.inject.Named
import kotlinx.android.synthetic.main.fragment_party_detail.invitations_view
class PartyDetailFragment : BaseFragment() {
@ -62,6 +63,8 @@ class PartyDetailFragment : BaseFragment() {
private val refreshLayout: androidx.swiperefreshlayout.widget.SwipeRefreshLayout? by bindView(R.id.refreshLayout)
private val partyInvitationWrapper: ViewGroup? by bindView(R.id.party_invitation_wrapper)
private val invitationsView: InvitationsView? by bindView(R.id.invitations_view)
private val inviteLeaderAvatarView: AvatarView? by bindView(R.id.groupleader_avatar_view)
private val inviteLeaderTextView: TextView? by bindView(R.id.groupleader_text_view)
private val titleView: TextView? by bindView(R.id.title_view)
private val descriptionView: TextView? by bindView(R.id.description_view)
private val newQuestButton: Button? by bindView(R.id.new_quest_button)
@ -105,6 +108,8 @@ class PartyDetailFragment : BaseFragment() {
questDetailButton?.setOnClickListener { questDetailButtonClicked() }
leaveButton?.setOnClickListener { leaveParty() }
invitationsView?.setLeader = null
invitationsView?.acceptCall = {
viewModel?.joinGroup(it) {
compositeSubscription.add(userRepository.retrieveUser(false)
@ -188,7 +193,30 @@ class PartyDetailFragment : BaseFragment() {
if ((user.invitations?.parties?.count() ?: 0) > 0) {
partyInvitationWrapper?.visibility = View.VISIBLE
user.invitations?.parties?.let { invitationsView?.setInvitations(it) }
user.invitations?.parties?.let {
for (invitation in it){
val leaderID = invitation.inviter
val groupName = invitation.name
leaderID.let {
compositeSubscription.add(
socialRepository.getMember(it)
.subscribe(Consumer {
inviteLeaderAvatarView?.setAvatar(it)
inviteLeaderTextView?.text = getString(R.string.invitation_title,it.displayName,groupName)
}, RxErrorHandler.handleEmptyError())
)
}
view?.findViewById<Button>(R.id.accept_button)?.setOnClickListener {
invitation.id?.let { it1 -> invitations_view.acceptCall?.invoke(it1) }
}
view?.findViewById<Button>(R.id.reject_button)?.setOnClickListener {
invitation.id?.let { it1 -> invitations_view.rejectCall?.invoke(it1) }
}
}
}
} else {
partyInvitationWrapper?.visibility = View.GONE
}
@ -335,11 +363,13 @@ class PartyDetailFragment : BaseFragment() {
alert.addButton(R.string.keep_challenges, true) { _, _ ->
viewModel?.leaveGroup(true) {
fragmentManager?.popBackStack()
MainNavigationController.navigate(R.id.noPartyFragment)
}
}
alert.addButton(R.string.leave_challenges, true) { _, _ ->
viewModel?.leaveGroup(false) {
fragmentManager?.popBackStack()
MainNavigationController.navigate(R.id.noPartyFragment)
}
}
alert.addButton(R.string.no, false)

View file

@ -8,6 +8,8 @@ import android.widget.TextView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.inflate
import com.habitrpg.android.habitica.models.invitations.GenericInvitation
import com.habitrpg.android.habitica.ui.AvatarView
import com.habitrpg.android.habitica.ui.helpers.bindView
class InvitationsView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
@ -15,6 +17,13 @@ class InvitationsView @JvmOverloads constructor(
var acceptCall: ((String) -> Unit)? = null
var rejectCall: ((String) -> Unit)? = null
var setLeader: ((String) -> Unit)? = null
val avatarView: AvatarView by bindView(R.id.groupleader_avatar_view)
val textView: TextView by bindView(R.id.groupleader_text_view)
var leaderID: String? = null
var groupName: String? = null
var leaderName: String? = null
val view = inflate(R.layout.view_invitation, true)
init {
orientation = VERTICAL
@ -23,9 +32,15 @@ class InvitationsView @JvmOverloads constructor(
fun setInvitations(invitations: List<GenericInvitation>) {
removeAllViews()
for (invitation in invitations) {
leaderID = invitation.inviter
groupName = invitation.name
val view = inflate(R.layout.view_invitation, true)
val textView = view.findViewById<TextView>(R.id.text_view)
textView.text = context.getString(R.string.invitation_title, context.getString(R.string.someone), invitation.name)
leaderID?.let {
setLeader?.invoke(it)
invalidate()
}
view.findViewById<Button>(R.id.accept_button).setOnClickListener {
invitation.id?.let { it1 -> acceptCall?.invoke(it1) }
}