Permalink message action + Fix crash on injection of navigator

This commit is contained in:
Valere 2019-06-06 12:26:38 +02:00
parent 053dc1d8dd
commit 04576ba7fd
10 changed files with 44 additions and 36 deletions

View file

@ -18,7 +18,6 @@ package im.vector.riotredesign.core.di
import android.content.Context
import android.content.Context.MODE_PRIVATE
import androidx.fragment.app.Fragment
import im.vector.matrix.android.api.Matrix
import im.vector.riotredesign.EmojiCompatFontProvider
import im.vector.riotredesign.core.error.ErrorFormatter
@ -87,8 +86,8 @@ class AppModule(private val context: Context) {
Matrix.getInstance().currentSession!!
}
factory { (fragment: Fragment) ->
DefaultNavigator(fragment) as Navigator
factory {
DefaultNavigator() as Navigator
}
single {

View file

@ -54,7 +54,7 @@ class HomeDrawerFragment : VectorBaseFragment() {
}
}
homeDrawerHeaderSettingsView.setOnClickListener {
navigator.openSettings()
navigator.openSettings(requireActivity())
}
// Debug menu

View file

@ -48,7 +48,7 @@ class HomeNavigator {
activity?.let {
//TODO enable eventId permalink. It doesn't work enough at the moment.
it.drawerLayout?.closeDrawer(GravityCompat.START)
navigator.openRoom(roomId)
navigator.openRoom(roomId, it)
}
}

View file

@ -53,6 +53,7 @@ import com.jaiselrahman.filepicker.model.MediaFile
import com.otaliastudios.autocomplete.Autocomplete
import com.otaliastudios.autocomplete.AutocompleteCallback
import com.otaliastudios.autocomplete.CharPolicy
import im.vector.matrix.android.api.permalinks.PermalinkFactory
import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.room.model.EditAggregatedSummary
@ -622,16 +623,16 @@ class RoomDetailFragment :
startActivityForResult(EmojiReactionPickerActivity.intent(requireContext(), eventId), REACTION_SELECT_REQUEST_CODE)
}
MessageMenuViewModel.ACTION_VIEW_REACTIONS -> {
val messageInformationData = actionData.data as? MessageInformationData ?: return
ViewReactionBottomSheet.newInstance(roomDetailArgs.roomId,messageInformationData)
val messageInformationData = actionData.data as? MessageInformationData
?: return
ViewReactionBottomSheet.newInstance(roomDetailArgs.roomId, messageInformationData)
.show(requireActivity().supportFragmentManager, "DISPLAY_REACTIONS")
}
MessageMenuViewModel.ACTION_COPY -> {
//I need info about the current selected message :/
copyToClipboard(requireContext(), actionData.data?.toString() ?: "", false)
val snack = Snackbar.make(view!!, requireContext().getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
snack.view.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.notification_accent_color))
snack.show()
val msg = requireContext().getString(R.string.copied_to_clipboard)
showSnackWithMessage(msg, Snackbar.LENGTH_SHORT)
}
MessageMenuViewModel.ACTION_DELETE -> {
val eventId = actionData.data?.toString() ?: return
@ -698,6 +699,13 @@ class RoomDetailFragment :
val eventId = actionData.data.toString()
roomDetailViewModel.process(RoomDetailActions.EnterReplyMode(eventId))
}
MessageMenuViewModel.ACTION_COPY_PERMALINK -> {
val eventId = actionData.data.toString()
val permalink = PermalinkFactory.createPermalink(roomDetailArgs.roomId, eventId)
copyToClipboard(requireContext(), permalink, false)
showSnackWithMessage(requireContext().getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
}
else -> {
Toast.makeText(context, "Action ${actionData.actionId} not implemented", Toast.LENGTH_LONG).show()
}

View file

@ -64,7 +64,7 @@ class MessageMenuViewModel(initialState: MessageMenuState) : VectorViewModel<Mes
)
)
}
val actions = ArrayList<SimpleAction>().apply {
if (event.sendState == SendState.SENDING) {
@ -123,7 +123,7 @@ class MessageMenuViewModel(initialState: MessageMenuState) : VectorViewModel<Mes
if (event.isEncrypted()) {
this.add(SimpleAction(VIEW_DECRYPTED_SOURCE, R.string.view_decrypted_source, R.drawable.ic_view_source, parcel.eventId))
}
this.add(SimpleAction(PERMALINK, R.string.permalink, R.drawable.ic_permalink, parcel.eventId))
this.add(SimpleAction(ACTION_COPY_PERMALINK, R.string.permalink, R.drawable.ic_permalink, parcel.eventId))
if (currentSession.sessionParams.credentials.userId != event.root.sender) {
//not sent by me
@ -225,7 +225,7 @@ class MessageMenuViewModel(initialState: MessageMenuState) : VectorViewModel<Mes
const val ACTION_DELETE = "delete"
const val VIEW_SOURCE = "VIEW_SOURCE"
const val VIEW_DECRYPTED_SOURCE = "VIEW_DECRYPTED_SOURCE"
const val PERMALINK = "PERMALINK"
const val ACTION_COPY_PERMALINK = "ACTION_COPY_PERMALINK"
const val ACTION_FLAG = "ACTION_FLAG"
const val ACTION_QUICK_REACT = "ACTION_QUICK_REACT"
const val ACTION_VIEW_REACTIONS = "ACTION_VIEW_REACTIONS"

View file

@ -72,7 +72,7 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback, O
setupRecyclerView()
roomListViewModel.subscribe { renderState(it) }
roomListViewModel.openRoomLiveData.observeEvent(this) {
navigator.openRoom(it)
navigator.openRoom(it, requireActivity())
}
createChatFabMenu.listener = this
@ -116,7 +116,7 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback, O
override fun openRoomDirectory() {
navigator.openRoomDirectory()
navigator.openRoomDirectory(requireActivity())
}
override fun createDirectChat() {

View file

@ -17,6 +17,7 @@
package im.vector.riotredesign.features.navigation
import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.fragment.app.Fragment
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
@ -27,29 +28,28 @@ import im.vector.riotredesign.features.roomdirectory.RoomDirectoryActivity
import im.vector.riotredesign.features.roomdirectory.roompreview.RoomPreviewActivity
import im.vector.riotredesign.features.settings.VectorSettingsActivity
class DefaultNavigator(private val fraqment: Fragment) : Navigator {
class DefaultNavigator : Navigator {
val activity: Activity = fraqment.requireActivity()
override fun openRoom(roomId: String) {
override fun openRoom(roomId: String, context: Context) {
val args = RoomDetailArgs(roomId)
val intent = RoomDetailActivity.newIntent(activity, args)
activity.startActivity(intent)
val intent = RoomDetailActivity.newIntent(context, args)
context.startActivity(intent)
}
override fun openRoomPreview(publicRoom: PublicRoom) {
val intent = RoomPreviewActivity.getIntent(activity, publicRoom)
activity.startActivity(intent)
override fun openRoomPreview(publicRoom: PublicRoom, context: Context) {
val intent = RoomPreviewActivity.getIntent(context, publicRoom)
context.startActivity(intent)
}
override fun openRoomDirectory() {
val intent = Intent(activity, RoomDirectoryActivity::class.java)
activity.startActivity(intent)
override fun openRoomDirectory(context: Context) {
val intent = Intent(context, RoomDirectoryActivity::class.java)
context.startActivity(intent)
}
override fun openSettings() {
val intent = VectorSettingsActivity.getIntent(activity, "TODO")
activity.startActivity(intent)
override fun openSettings(context: Context) {
val intent = VectorSettingsActivity.getIntent(context, "TODO")
context.startActivity(intent)
}
override fun openDebug() {

View file

@ -16,17 +16,18 @@
package im.vector.riotredesign.features.navigation
import android.content.Context
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
interface Navigator {
fun openRoom(roomId: String)
fun openRoom(roomId: String, context: Context)
fun openRoomPreview(publicRoom: PublicRoom)
fun openRoomPreview(publicRoom: PublicRoom, context: Context)
fun openRoomDirectory()
fun openRoomDirectory(context: Context)
fun openSettings()
fun openSettings(context: Context)
fun openDebug()

View file

@ -124,12 +124,12 @@ class PublicRoomsFragment : VectorBaseFragment(), PublicRoomsController.Callback
when (joinState) {
JoinState.JOINED -> {
navigator.openRoom(publicRoom.roomId)
navigator.openRoom(publicRoom.roomId, requireActivity())
}
JoinState.NOT_JOINED,
JoinState.JOINING_ERROR -> {
// ROOM PREVIEW
navigator.openRoomPreview(publicRoom)
navigator.openRoomPreview(publicRoom, requireActivity())
}
else -> {
Snackbar.make(publicRoomsCoordinator, getString(R.string.please_wait), Snackbar.LENGTH_SHORT)

View file

@ -108,7 +108,7 @@ class RoomPreviewNoPreviewFragment : VectorBaseFragment() {
// Quit this screen
requireActivity().finish()
// Open room
navigator.openRoom(roomPreviewData.roomId)
navigator.openRoom(roomPreviewData.roomId, requireActivity())
}
}
}