Adding menu with rename action in session overview screen

This commit is contained in:
Maxime NATUREL 2022-09-19 14:28:37 +02:00
parent 3de96a3a0c
commit 82fabf4a85
5 changed files with 47 additions and 1 deletions

View file

@ -3295,6 +3295,7 @@
<string name="device_manager_session_details_session_id">Session ID</string>
<string name="device_manager_session_details_session_last_activity">Last activity</string>
<string name="device_manager_session_details_device_ip_address">IP address</string>
<string name="device_manager_session_rename">Rename session</string>
<!-- Note to translators: %s will be replaces with selected space name -->
<string name="home_empty_space_no_rooms_title">%s\nis looking a little empty.</string>

View file

@ -91,6 +91,7 @@ import im.vector.app.features.settings.devices.DevicesViewModel
import im.vector.app.features.settings.devices.v2.details.SessionDetailsViewModel
import im.vector.app.features.settings.devices.v2.othersessions.OtherSessionsViewModel
import im.vector.app.features.settings.devices.v2.overview.SessionOverviewViewModel
import im.vector.app.features.settings.devices.v2.rename.RenameSessionViewModel
import im.vector.app.features.settings.devtools.AccountDataViewModel
import im.vector.app.features.settings.devtools.GossipingEventsPaperTrailViewModel
import im.vector.app.features.settings.devtools.KeyRequestListViewModel
@ -653,4 +654,9 @@ interface MavericksViewModelModule {
@IntoMap
@MavericksViewModelKey(SessionDetailsViewModel::class)
fun sessionDetailsViewModelFactory(factory: SessionDetailsViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
@Binds
@IntoMap
@MavericksViewModelKey(RenameSessionViewModel::class)
fun renameSessionViewModelFactory(factory: RenameSessionViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
}

View file

@ -18,6 +18,7 @@ package im.vector.app.features.settings.devices.v2.overview
import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
@ -31,6 +32,7 @@ import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.date.VectorDateFormatter
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.platform.VectorMenuProvider
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.DrawableProvider
import im.vector.app.databinding.FragmentSessionOverviewBinding
@ -43,7 +45,8 @@ import javax.inject.Inject
*/
@AndroidEntryPoint
class SessionOverviewFragment :
VectorBaseFragment<FragmentSessionOverviewBinding>() {
VectorBaseFragment<FragmentSessionOverviewBinding>(),
VectorMenuProvider {
@Inject lateinit var viewNavigator: SessionOverviewViewNavigator
@ -103,6 +106,22 @@ class SessionOverviewFragment :
views.sessionOverviewInfo.onLearnMoreClickListener = null
}
override fun getMenuRes() = R.menu.menu_session_overview
override fun handleMenuItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.sessionOverviewRename -> {
goToRenameSession()
true
}
else -> false
}
}
private fun goToRenameSession() = withState(viewModel) { state ->
viewNavigator.goToRenameSession(requireContext(), state.deviceId)
}
override fun invalidate() = withState(viewModel) { state ->
updateToolbar(state.isCurrentSession)
updateEntryDetails(state.deviceId)

View file

@ -20,9 +20,11 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentSessionRenameBinding
import javax.inject.Inject
@ -45,6 +47,13 @@ class RenameSessionFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
observeViewEvents()
initToolbar()
}
private fun initToolbar() {
(activity as? AppCompatActivity)
?.supportActionBar
?.setTitle(R.string.device_manager_session_rename)
}
private fun observeViewEvents() {

View file

@ -0,0 +1,11 @@
<?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"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="AlwaysShowAction">
<item
android:id="@+id/sessionOverviewRename"
android:title="@string/device_manager_session_rename"
app:showAsAction="withText|never" />
</menu>