Share action is added to room profile and room member profile

Fixes #858
This commit is contained in:
onurays 2020-02-21 15:30:01 +03:00
parent d6434654e2
commit f650e29ddd
12 changed files with 91 additions and 7 deletions

View File

@ -10,6 +10,7 @@ Features ✨:
Improvements 🙌:
- Migrate to binary QR code verification (#994)
- Share action is added to room profile and room member profile (#858)
Bugfix 🐛:
- Account creation: wrongly hints that an email can be used to create an account (#941)

View File

@ -23,4 +23,5 @@ sealed class RoomMemberProfileAction : VectorViewModelAction {
object RetryFetchingInfo : RoomMemberProfileAction()
object IgnoreUser : RoomMemberProfileAction()
object VerifyUser : RoomMemberProfileAction()
object ShareRoomMemberProfile : RoomMemberProfileAction()
}

View File

@ -19,6 +19,7 @@ package im.vector.riotx.features.roommemberprofile
import android.os.Bundle
import android.os.Parcelable
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
@ -28,6 +29,7 @@ import com.airbnb.mvrx.Success
import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.matrix.android.api.permalinks.PermalinkFactory
import im.vector.matrix.android.api.util.MatrixItem
import im.vector.riotx.R
import im.vector.riotx.core.animations.AppBarStateChangeListener
@ -38,6 +40,7 @@ import im.vector.riotx.core.extensions.exhaustive
import im.vector.riotx.core.extensions.setTextOrHide
import im.vector.riotx.core.platform.StateView
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.core.utils.startSharePlainTextIntent
import im.vector.riotx.features.crypto.verification.VerificationBottomSheet
import im.vector.riotx.features.home.AvatarRenderer
import im.vector.riotx.features.roommemberprofile.devices.DeviceListBottomSheet
@ -65,6 +68,8 @@ class RoomMemberProfileFragment @Inject constructor(
override fun getLayoutResId() = R.layout.fragment_matrix_profile
override fun getMenuRes() = R.menu.vector_room_member_profile
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupToolbar(matrixProfileToolbar)
@ -90,14 +95,25 @@ class RoomMemberProfileFragment @Inject constructor(
matrixProfileAppBarLayout.addOnOffsetChangedListener(appBarStateChangeListener)
viewModel.observeViewEvents {
when (it) {
is RoomMemberProfileViewEvents.Loading -> showLoading(it.message)
is RoomMemberProfileViewEvents.Failure -> showFailure(it.throwable)
is RoomMemberProfileViewEvents.OnIgnoreActionSuccess -> Unit
is RoomMemberProfileViewEvents.StartVerification -> handleStartVerification(it)
is RoomMemberProfileViewEvents.Loading -> showLoading(it.message)
is RoomMemberProfileViewEvents.Failure -> showFailure(it.throwable)
is RoomMemberProfileViewEvents.OnIgnoreActionSuccess -> Unit
is RoomMemberProfileViewEvents.StartVerification -> handleStartVerification(it)
is RoomMemberProfileViewEvents.ShareRoomMemberProfile -> handleShareRoomMemberProfile()
}.exhaustive
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.roomMemberProfileShareAction -> {
viewModel.handle(RoomMemberProfileAction.ShareRoomMemberProfile)
return true
}
}
return super.onOptionsItemSelected(item)
}
private fun handleStartVerification(startVerification: RoomMemberProfileViewEvents.StartVerification) {
if (startVerification.canCrossSign) {
VerificationBottomSheet
@ -208,4 +224,10 @@ class RoomMemberProfileFragment @Inject constructor(
override fun onMentionClicked() {
vectorBaseActivity.notImplemented("Mention")
}
private fun handleShareRoomMemberProfile() = withState(viewModel) {
PermalinkFactory.createPermalink(it.userId)?.let { permalink ->
startSharePlainTextIntent(fragment = this, chooserTitle = null, text = permalink)
}
}
}

View File

@ -31,4 +31,6 @@ sealed class RoomMemberProfileViewEvents : VectorViewEvents {
val userId: String,
val canCrossSign: Boolean
) : RoomMemberProfileViewEvents()
object ShareRoomMemberProfile : RoomMemberProfileViewEvents()
}

View File

@ -135,9 +135,10 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
override fun handle(action: RoomMemberProfileAction) {
when (action) {
is RoomMemberProfileAction.RetryFetchingInfo -> fetchProfileInfo()
is RoomMemberProfileAction.IgnoreUser -> handleIgnoreAction()
is RoomMemberProfileAction.VerifyUser -> prepareVerification()
is RoomMemberProfileAction.RetryFetchingInfo -> fetchProfileInfo()
is RoomMemberProfileAction.IgnoreUser -> handleIgnoreAction()
is RoomMemberProfileAction.VerifyUser -> prepareVerification()
is RoomMemberProfileAction.ShareRoomMemberProfile -> handleShareRoomMemberProfile()
}
}
@ -234,4 +235,8 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
session.ignoreUserIds(listOf(state.userId), ignoreActionCallback)
}
}
private fun handleShareRoomMemberProfile() {
_viewEvents.post(RoomMemberProfileViewEvents.ShareRoomMemberProfile)
}
}

View File

@ -23,4 +23,5 @@ import im.vector.riotx.core.platform.VectorViewModelAction
sealed class RoomProfileAction: VectorViewModelAction {
object LeaveRoom: RoomProfileAction()
data class ChangeRoomNotificationState(val notificationState: RoomNotificationState) : RoomProfileAction()
object ShareRoomProfile : RoomProfileAction()
}

View File

@ -19,12 +19,14 @@ package im.vector.riotx.features.roomprofile
import android.os.Bundle
import android.os.Parcelable
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import com.airbnb.mvrx.args
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.matrix.android.api.permalinks.PermalinkFactory
import im.vector.matrix.android.api.session.room.notification.RoomNotificationState
import im.vector.matrix.android.api.util.toMatrixItem
import im.vector.riotx.R
@ -35,6 +37,7 @@ import im.vector.riotx.core.extensions.configureWith
import im.vector.riotx.core.extensions.exhaustive
import im.vector.riotx.core.extensions.setTextOrHide
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.core.utils.startSharePlainTextIntent
import im.vector.riotx.features.crypto.util.toImageRes
import im.vector.riotx.features.home.AvatarRenderer
import im.vector.riotx.features.home.room.list.actions.RoomListActionsArgs
@ -67,6 +70,8 @@ class RoomProfileFragment @Inject constructor(
override fun getLayoutResId() = R.layout.fragment_matrix_profile
override fun getMenuRes() = R.menu.vector_room_profile
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
roomListQuickActionsSharedActionViewModel = activityViewModelProvider.get(RoomListQuickActionsSharedActionViewModel::class.java)
@ -89,6 +94,7 @@ class RoomProfileFragment @Inject constructor(
is RoomProfileViewEvents.Loading -> showLoading(it.message)
is RoomProfileViewEvents.Failure -> showFailure(it.throwable)
is RoomProfileViewEvents.OnLeaveRoomSuccess -> onLeaveRoom()
is RoomProfileViewEvents.ShareRoomProfile -> onShareRoomProfile()
}.exhaustive
}
roomListQuickActionsSharedActionViewModel
@ -97,6 +103,16 @@ class RoomProfileFragment @Inject constructor(
.disposeOnDestroyView()
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.roomProfileShareAction -> {
roomProfileViewModel.handle(RoomProfileAction.ShareRoomProfile)
return true
}
}
return super.onOptionsItemSelected(item)
}
private fun handleQuickActions(action: RoomListQuickActionsSharedAction) = when (action) {
is RoomListQuickActionsSharedAction.NotificationsAllNoisy -> {
roomProfileViewModel.handle(RoomProfileAction.ChangeRoomNotificationState(RoomNotificationState.ALL_MESSAGES_NOISY))
@ -187,4 +203,10 @@ class RoomProfileFragment @Inject constructor(
.setNegativeButton(R.string.cancel, null)
.show()
}
private fun onShareRoomProfile() {
PermalinkFactory.createPermalink(roomProfileArgs.roomId)?.let { permalink ->
startSharePlainTextIntent(fragment = this, chooserTitle = null, text = permalink)
}
}
}

View File

@ -26,4 +26,5 @@ sealed class RoomProfileViewEvents : VectorViewEvents {
data class Failure(val throwable: Throwable) : RoomProfileViewEvents()
object OnLeaveRoomSuccess : RoomProfileViewEvents()
object ShareRoomProfile : RoomProfileViewEvents()
}

View File

@ -66,6 +66,7 @@ class RoomProfileViewModel @AssistedInject constructor(@Assisted initialState: R
override fun handle(action: RoomProfileAction) = when (action) {
RoomProfileAction.LeaveRoom -> handleLeaveRoom()
is RoomProfileAction.ChangeRoomNotificationState -> handleChangeNotificationMode(action)
is RoomProfileAction.ShareRoomProfile -> handleShareRoomProfile()
}
private fun handleChangeNotificationMode(action: RoomProfileAction.ChangeRoomNotificationState) {
@ -88,4 +89,8 @@ class RoomProfileViewModel @AssistedInject constructor(@Assisted initialState: R
}
})
}
private fun handleShareRoomProfile() {
_viewEvents.post(RoomProfileViewEvents.ShareRoomProfile)
}
}

View File

@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
</vector>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/roomMemberProfileShareAction"
android:icon="@drawable/ic_material_share"
android:title="@string/share"
app:showAsAction="ifRoom" />
</menu>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/roomProfileShareAction"
android:icon="@drawable/ic_material_share"
android:title="@string/share"
app:iconTint="@color/riotx_accent"
app:showAsAction="ifRoom" />
</menu>