Check if user has enough power level to change room avatar.
This commit is contained in:
parent
8787f5d920
commit
a03f69fb98
|
@ -77,7 +77,7 @@ class BigImageViewerActivity : VectorBaseActivity(), AvatarSelectorView.Callback
|
|||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
|
||||
menu.findItem(R.id.bigAvatarEditAction).isVisible = uri != null
|
||||
menu.findItem(R.id.bigAvatarEditAction).isVisible = shouldShowEditAction()
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,10 @@ class BigImageViewerActivity : VectorBaseActivity(), AvatarSelectorView.Callback
|
|||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun shouldShowEditAction(): Boolean {
|
||||
return uri != null && intent.getBooleanExtra(EXTRA_CAN_EDIT_IMAGE, false)
|
||||
}
|
||||
|
||||
private fun showAvatarSelector() {
|
||||
if (!::avatarSelector.isInitialized) {
|
||||
avatarSelector = AvatarSelectorView(this, layoutInflater, this)
|
||||
|
@ -180,12 +184,14 @@ class BigImageViewerActivity : VectorBaseActivity(), AvatarSelectorView.Callback
|
|||
companion object {
|
||||
private const val EXTRA_TITLE = "EXTRA_TITLE"
|
||||
private const val EXTRA_IMAGE_URL = "EXTRA_IMAGE_URL"
|
||||
private const val EXTRA_CAN_EDIT_IMAGE = "EXTRA_CAN_EDIT_IMAGE"
|
||||
const val REQUEST_CODE = 1000
|
||||
|
||||
fun newIntent(context: Context, title: String?, imageUrl: String): Intent {
|
||||
fun newIntent(context: Context, title: String?, imageUrl: String, canEditImage: Boolean = false): Intent {
|
||||
return Intent(context, BigImageViewerActivity::class.java).apply {
|
||||
putExtra(EXTRA_TITLE, title)
|
||||
putExtra(EXTRA_IMAGE_URL, imageUrl)
|
||||
putExtra(EXTRA_CAN_EDIT_IMAGE, canEditImage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,14 +241,13 @@ class RoomProfileFragment @Inject constructor(
|
|||
startSharePlainTextIntent(fragment = this, chooserTitle = null, text = permalink)
|
||||
}
|
||||
|
||||
private fun onAvatarClicked(view: View, matrixItem: MatrixItem.RoomItem) {
|
||||
if (matrixItem.avatarUrl.isNullOrEmpty()) {
|
||||
showAvatarSelector()
|
||||
} else {
|
||||
val intent = BigImageViewerActivity.newIntent(requireContext(), matrixItem.getBestName(), matrixItem.avatarUrl!!)
|
||||
private fun onAvatarClicked(view: View, matrixItem: MatrixItem.RoomItem) = withState(roomProfileViewModel) {
|
||||
if (matrixItem.avatarUrl?.isNotEmpty() == true) {
|
||||
val intent = BigImageViewerActivity.newIntent(requireContext(), matrixItem.getBestName(), matrixItem.avatarUrl!!, it.canChangeAvatar)
|
||||
val options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity!!, view, ViewCompat.getTransitionName(view) ?: "")
|
||||
|
||||
startActivityForResult(intent, BigImageViewerActivity.REQUEST_CODE, options.toBundle())
|
||||
} else if (it.canChangeAvatar) {
|
||||
showAvatarSelector()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,11 +25,13 @@ 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.android.api.session.room.powerlevels.PowerLevelsHelper
|
||||
import im.vector.matrix.rx.rx
|
||||
import im.vector.matrix.rx.unwrap
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.platform.VectorViewModel
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.features.powerlevel.PowerLevelsObservableFactory
|
||||
import java.util.UUID
|
||||
|
||||
class RoomProfileViewModel @AssistedInject constructor(@Assisted private val initialState: RoomProfileViewState,
|
||||
|
@ -63,6 +65,13 @@ class RoomProfileViewModel @AssistedInject constructor(@Assisted private val ini
|
|||
.execute {
|
||||
copy(roomSummary = it)
|
||||
}
|
||||
|
||||
val powerLevelsContentLive = PowerLevelsObservableFactory(room).createObservable()
|
||||
|
||||
powerLevelsContentLive.subscribe {
|
||||
val powerLevelsHelper = PowerLevelsHelper(it)
|
||||
setState { copy(canChangeAvatar = powerLevelsHelper.isUserAbleToChangeRoomAvatar(session.myUserId)) }
|
||||
}.disposeOnClear()
|
||||
}
|
||||
|
||||
override fun handle(action: RoomProfileAction) = when (action) {
|
||||
|
|
|
@ -24,7 +24,8 @@ import im.vector.matrix.android.api.session.room.model.RoomSummary
|
|||
|
||||
data class RoomProfileViewState(
|
||||
val roomId: String,
|
||||
val roomSummary: Async<RoomSummary> = Uninitialized
|
||||
val roomSummary: Async<RoomSummary> = Uninitialized,
|
||||
val canChangeAvatar: Boolean = false
|
||||
) : MvRxState {
|
||||
|
||||
constructor(args: RoomProfileArgs) : this(roomId = args.roomId)
|
||||
|
|
Loading…
Reference in New Issue