Merge pull request #1048 from vector-im/feature/profile_share_actions

Share action is added to room profile and room member profile
This commit is contained in:
Benoit Marty 2020-02-24 17:29:17 +01:00 committed by GitHub
commit 281620b88d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 117 additions and 9 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
@ -38,6 +39,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 +67,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 +94,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(it.permalink)
}.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 +223,8 @@ class RoomMemberProfileFragment @Inject constructor(
override fun onMentionClicked() {
vectorBaseActivity.notImplemented("Mention")
}
private fun handleShareRoomMemberProfile(permalink: String) {
startSharePlainTextIntent(fragment = this, chooserTitle = null, text = permalink)
}
}

View file

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

View file

@ -26,6 +26,7 @@ import com.airbnb.mvrx.ViewModelContext
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.permalinks.PermalinkFactory
import im.vector.matrix.android.api.query.QueryStringValue
import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.events.model.EventType
@ -135,9 +136,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 +236,10 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
session.ignoreUserIds(listOf(state.userId), ignoreActionCallback)
}
}
private fun handleShareRoomMemberProfile() {
PermalinkFactory.createPermalink(initialState.userId)?.let { permalink ->
_viewEvents.post(RoomMemberProfileViewEvents.ShareRoomMemberProfile(permalink))
}
}
}

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,6 +19,7 @@ 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
@ -35,6 +36,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 +69,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 +93,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(it.permalink)
}.exhaustive
}
roomListQuickActionsSharedActionViewModel
@ -97,6 +102,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 +202,8 @@ class RoomProfileFragment @Inject constructor(
.setNegativeButton(R.string.cancel, null)
.show()
}
private fun onShareRoomProfile(permalink: String) {
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()
data class ShareRoomProfile(val permalink: String) : RoomProfileViewEvents()
}

View file

@ -23,6 +23,7 @@ import com.airbnb.mvrx.ViewModelContext
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.permalinks.PermalinkFactory
import im.vector.matrix.android.api.session.Session
import im.vector.matrix.rx.rx
import im.vector.matrix.rx.unwrap
@ -30,7 +31,7 @@ import im.vector.riotx.R
import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.core.resources.StringProvider
class RoomProfileViewModel @AssistedInject constructor(@Assisted initialState: RoomProfileViewState,
class RoomProfileViewModel @AssistedInject constructor(@Assisted private val initialState: RoomProfileViewState,
private val stringProvider: StringProvider,
private val session: Session)
: VectorViewModel<RoomProfileViewState, RoomProfileAction, RoomProfileViewEvents>(initialState) {
@ -66,6 +67,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 +90,10 @@ class RoomProfileViewModel @AssistedInject constructor(@Assisted initialState: R
}
})
}
private fun handleShareRoomProfile() {
PermalinkFactory.createPermalink(initialState.roomId)?.let { permalink ->
_viewEvents.post(RoomProfileViewEvents.ShareRoomProfile(permalink))
}
}
}

View file

@ -0,0 +1,24 @@
<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="#00000000" android:fillType="evenOdd"
android:pathData="M18,8C19.6569,8 21,6.6568 21,5C21,3.3431 19.6569,2 18,2C16.3431,2 15,3.3431 15,5C15,6.6568 16.3431,8 18,8Z"
android:strokeColor="#03B381" android:strokeLineCap="round"
android:strokeLineJoin="round" android:strokeWidth="2"/>
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M6,15C7.6568,15 9,13.6569 9,12C9,10.3431 7.6568,9 6,9C4.3432,9 3,10.3431 3,12C3,13.6569 4.3432,15 6,15Z"
android:strokeColor="#03B381" android:strokeLineCap="round"
android:strokeLineJoin="round" android:strokeWidth="2"/>
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M18,22C19.6569,22 21,20.6569 21,19C21,17.3431 19.6569,16 18,16C16.3431,16 15,17.3431 15,19C15,20.6569 16.3431,22 18,22Z"
android:strokeColor="#03B381" android:strokeLineCap="round"
android:strokeLineJoin="round" android:strokeWidth="2"/>
<path android:fillColor="#00000000"
android:pathData="M8.59,13.51L15.42,17.49"
android:strokeColor="#03B381" android:strokeLineCap="round"
android:strokeLineJoin="round" android:strokeWidth="2"/>
<path android:fillColor="#00000000"
android:pathData="M15.41,6.51L8.59,10.49"
android:strokeColor="#03B381" android:strokeLineCap="round"
android:strokeLineJoin="round" android:strokeWidth="2"/>
</vector>

View file

@ -15,7 +15,7 @@
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/matrixProfileCollapsingToolbarLayout"
style="@style/VectorAppBarLayoutStyle"
android:theme="@style/Vector.Toolbar.Profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?riotx_background"

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/roomMemberProfileShareAction"
android:icon="@drawable/ic_material_share"
android:title="@string/share"
app:iconTint="?attr/colorAccent"
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="?attr/colorAccent"
app:showAsAction="ifRoom" />
</menu>

View file

@ -30,6 +30,10 @@
<item name="android:fontFamily">"sans-serif"</item>
</style>
<style name="Vector.Toolbar.Profile" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<item name="colorControlNormal">?attr/colorAccent</item>
</style>
<style name="VectorAppBarLayoutStyle" parent="Widget.Design.AppBarLayout">
<item name="android:background">?riotx_background</item>
</style>