Adds Invites bottoms sheet
This commit is contained in:
parent
a158d9866d
commit
c72ba8d651
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2022 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.home
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import im.vector.app.R
|
||||
import im.vector.app.databinding.ListItemInviteBinding
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||
|
||||
class InvitesAdapter(
|
||||
private val avatarRenderer: AvatarRenderer,
|
||||
private val inviteUserTask: ((String) -> String?)?,
|
||||
) : RecyclerView.Adapter<InvitesAdapter.ViewHolder>() {
|
||||
|
||||
private val invites = mutableListOf<RoomSummary>()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = ListItemInviteBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(invites[position])
|
||||
}
|
||||
|
||||
override fun getItemCount() = invites.size
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun updateList(invites: List<RoomSummary>) {
|
||||
this.invites.clear()
|
||||
this.invites.addAll(invites)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
inner class ViewHolder(private val binding: ListItemInviteBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(invite: RoomSummary) {
|
||||
avatarRenderer.render(invite.toMatrixItem(), binding.avatar)
|
||||
binding.name.text = invite.name
|
||||
invite.inviterId?.let {
|
||||
val inviterName = inviteUserTask?.invoke(it)
|
||||
if (inviterName != null) {
|
||||
binding.invitedBy.text = binding.root.context.getString(R.string.invited_by, inviterName)
|
||||
} else {
|
||||
binding.invitedBy.text = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2022 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.home
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import im.vector.app.databinding.BottomSheetInvitesBinding
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
|
||||
class InvitesBottomSheet(
|
||||
private val invites: List<RoomSummary>,
|
||||
private val avatarRenderer: AvatarRenderer,
|
||||
private val inviteUserTask: ((String) -> String?)?
|
||||
) : BottomSheetDialogFragment() {
|
||||
|
||||
private lateinit var binding: BottomSheetInvitesBinding
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
binding = BottomSheetInvitesBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setupInvitesList()
|
||||
}
|
||||
|
||||
private fun setupInvitesList() {
|
||||
val adapter = InvitesAdapter(avatarRenderer, inviteUserTask)
|
||||
val layoutManager = LinearLayoutManager(context)
|
||||
binding.invitesList.adapter = adapter
|
||||
binding.invitesList.layoutManager = layoutManager
|
||||
adapter.updateList(invites)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "InvitesBottomSheet"
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.allViews
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
|
@ -58,6 +59,7 @@ class SpaceListModalFragment : VectorBaseFragment<FragmentSpaceListModalBinding>
|
|||
sharedActionViewModel = activityViewModelProvider.get(HomeSharedActionViewModel::class.java)
|
||||
setupRecyclerView()
|
||||
setupAddSpace()
|
||||
setupInvites()
|
||||
observeSpaceChange()
|
||||
}
|
||||
|
||||
|
@ -82,6 +84,17 @@ class SpaceListModalFragment : VectorBaseFragment<FragmentSpaceListModalBinding>
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupInvites() {
|
||||
binding.invitesGroup.referencedIds.map { binding.root.findViewById<View>(it) }.forEach {
|
||||
it.setOnClickListener {
|
||||
withState(viewModel) { state ->
|
||||
val invitesBottomSheet = InvitesBottomSheet(state.inviteSpaces.orEmpty(), avatarRenderer, state.inviteUserTask)
|
||||
invitesBottomSheet.show(requireActivity().supportFragmentManager, InvitesBottomSheet.TAG)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeSpaceChange() = sharedActionViewModel.space.observe(viewLifecycleOwner) {
|
||||
viewModel.setSpace(it)
|
||||
binding.headerText.isVisible = it == null
|
||||
|
|
|
@ -51,6 +51,7 @@ import org.matrix.android.sdk.api.session.Session
|
|||
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import org.matrix.android.sdk.api.session.getRoom
|
||||
import org.matrix.android.sdk.api.session.getUser
|
||||
import org.matrix.android.sdk.api.session.group.groupSummaryQueryParams
|
||||
import org.matrix.android.sdk.api.session.room.RoomSortOrder
|
||||
import org.matrix.android.sdk.api.session.room.accountdata.RoomAccountDataTypes
|
||||
|
@ -295,6 +296,9 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
|
|||
val rootSpaces = async.invoke().orEmpty().filter { it.flattenParentIds.isEmpty() }
|
||||
val displaySpaces = (currentSpaceChildren ?: rootSpaces).filter { it.inviterId == null }
|
||||
val inviteSpaces = (currentSpaceChildren ?: rootSpaces).filter { it.inviterId != null }
|
||||
val inviteUserTask: (String) -> String? = {
|
||||
session.getUser(it)?.displayName
|
||||
}
|
||||
val orders = displaySpaces.associate {
|
||||
it.roomId to session.getRoom(it.roomId)
|
||||
?.roomAccountDataService()
|
||||
|
@ -307,6 +311,7 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
|
|||
rootSpacesOrdered = displaySpaces.sortedWith(TopLevelSpaceComparator(orders)),
|
||||
inviteSpaces = inviteSpaces.sortedWith(TopLevelSpaceComparator(orders)),
|
||||
inviteCount = inviteSpaces.size,
|
||||
inviteUserTask = inviteUserTask,
|
||||
spaceOrderInfo = orders
|
||||
)
|
||||
}
|
||||
|
|
|
@ -36,5 +36,6 @@ data class SpaceListViewState(
|
|||
val legacyGroups: List<GroupSummary>? = null,
|
||||
val expandedStates: Map<String, Boolean> = emptyMap(),
|
||||
val inviteCount: Int = 0,
|
||||
val inviteUserTask: ((String) -> String?)? = null,
|
||||
val homeAggregateCount: RoomAggregateNotificationCount = RoomAggregateNotificationCount(0, 0)
|
||||
) : MavericksState
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="360dp"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/invites_header"
|
||||
style="@style/Widget.Vector.TextView.Title.Medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/space_invites"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/invites_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/invites_header"
|
||||
tools:listitem="@layout/list_item_invite"
|
||||
tools:itemCount="3"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="42dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:src="@sample/space_avatars"
|
||||
android:layout_marginStart="16dp" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/Widget.Vector.TextView.Body.Medium"
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintTop_toTopOf="@id/avatar"
|
||||
app:layout_constraintBottom_toTopOf="@id/invited_by"
|
||||
app:layout_constraintStart_toEndOf="@id/avatar"
|
||||
app:layout_constraintVertical_chainStyle="spread_inside"
|
||||
tools:text="Element Corp."/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/Widget.Vector.TextView.Body"
|
||||
android:id="@+id/invited_by"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textColor="?attr/vctr_content_secondary"
|
||||
app:layout_constraintTop_toBottomOf="@id/name"
|
||||
app:layout_constraintBottom_toBottomOf="@id/avatar"
|
||||
app:layout_constraintStart_toStartOf="@id/name"
|
||||
tools:text="Invited by John from Cornwall"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -3045,4 +3045,5 @@
|
|||
<string name="no_spaces_yet_message">Add spaces to group your chats</string>
|
||||
<string name="no_subspaces_yet">No subspaces yet</string>
|
||||
<string name="no_subspaces_yet_message">Add subspaces to group your chats</string>
|
||||
<string name="space_invites">Space Invites</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue