mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-18 07:11:58 +03:00
Migration to activity 1.5.0. Rework menu management
This commit is contained in:
parent
1297ccd45c
commit
aae6e20f9c
29 changed files with 320 additions and 270 deletions
|
@ -53,6 +53,7 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation libs.androidx.appCompat
|
implementation libs.androidx.appCompat
|
||||||
|
implementation libs.androidx.fragmentKtx
|
||||||
implementation libs.google.material
|
implementation libs.google.material
|
||||||
// Pref theme
|
// Pref theme
|
||||||
implementation libs.androidx.preferenceKtx
|
implementation libs.androidx.preferenceKtx
|
||||||
|
|
|
@ -18,8 +18,12 @@ package im.vector.lib.ui.styles.debug
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
|
import android.view.MenuItem
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.view.MenuProvider
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import im.vector.lib.ui.styles.R
|
import im.vector.lib.ui.styles.R
|
||||||
|
@ -31,6 +35,7 @@ abstract class DebugMaterialThemeActivity : AppCompatActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
setupMenu()
|
||||||
val views = ActivityDebugMaterialThemeBinding.inflate(layoutInflater)
|
val views = ActivityDebugMaterialThemeBinding.inflate(layoutInflater)
|
||||||
setContentView(views.root)
|
setContentView(views.root)
|
||||||
|
|
||||||
|
@ -72,6 +77,27 @@ abstract class DebugMaterialThemeActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupMenu() {
|
||||||
|
addMenuProvider(
|
||||||
|
object : MenuProvider {
|
||||||
|
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
||||||
|
menuInflater.inflate(R.menu.menu_debug, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
||||||
|
Toast.makeText(
|
||||||
|
this@DebugMaterialThemeActivity,
|
||||||
|
"Menu ${menuItem.title} clicked!",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
this,
|
||||||
|
Lifecycle.State.RESUMED
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun showTestDialog(theme: Int) {
|
private fun showTestDialog(theme: Int) {
|
||||||
MaterialAlertDialogBuilder(this, theme)
|
MaterialAlertDialogBuilder(this, theme)
|
||||||
.setTitle("Dialog title")
|
.setTitle("Dialog title")
|
||||||
|
@ -82,9 +108,4 @@ abstract class DebugMaterialThemeActivity : AppCompatActivity() {
|
||||||
.setNeutralButton("Neutral", null)
|
.setNeutralButton("Neutral", null)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
||||||
menuInflater.inflate(R.menu.menu_debug, menu)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,3 +180,8 @@ System\.currentTimeMillis\(\)===2
|
||||||
|
|
||||||
### Remove extra space between the name and the description
|
### Remove extra space between the name and the description
|
||||||
\* @\w+ \w+ +
|
\* @\w+ \w+ +
|
||||||
|
|
||||||
|
### Please use the MenuProvider interface now
|
||||||
|
onCreateOptionsMenu
|
||||||
|
onOptionsItemSelected
|
||||||
|
onPrepareOptionsMenu
|
||||||
|
|
|
@ -24,6 +24,7 @@ import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowInsetsController
|
import android.view.WindowInsetsController
|
||||||
|
@ -36,10 +37,12 @@ import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.view.MenuProvider
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentFactory
|
import androidx.fragment.app.FragmentFactory
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
|
@ -199,6 +202,7 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
|
||||||
supportFragmentManager.fragmentFactory = fragmentFactory
|
supportFragmentManager.fragmentFactory = fragmentFactory
|
||||||
viewModelFactory = activityEntryPoint.viewModelFactory()
|
viewModelFactory = activityEntryPoint.viewModelFactory()
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
setupMenu()
|
||||||
configurationViewModel = viewModelProvider.get(ConfigurationViewModel::class.java)
|
configurationViewModel = viewModelProvider.get(ConfigurationViewModel::class.java)
|
||||||
bugReporter = singletonEntryPoint.bugReporter()
|
bugReporter = singletonEntryPoint.bugReporter()
|
||||||
pinLocker = singletonEntryPoint.pinLocker()
|
pinLocker = singletonEntryPoint.pinLocker()
|
||||||
|
@ -249,6 +253,30 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupMenu() {
|
||||||
|
// Always add a MenuProvider to handle the back action from the Toolbar
|
||||||
|
addMenuProvider(
|
||||||
|
object : MenuProvider {
|
||||||
|
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
||||||
|
getMenuRes()
|
||||||
|
.takeIf { it != -1 }
|
||||||
|
?.let { menuInflater.inflate(it, menu) }
|
||||||
|
handlePostCreateMenu(menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPrepareMenu(menu: Menu) {
|
||||||
|
handlePrepareMenu(menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
||||||
|
return handleMenuItemSelected(menuItem)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
this,
|
||||||
|
Lifecycle.State.RESUMED
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method has to be called for the font size setting be supported correctly.
|
* This method has to be called for the font size setting be supported correctly.
|
||||||
*/
|
*/
|
||||||
|
@ -467,24 +495,24 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
|
||||||
* MENU MANAGEMENT
|
* MENU MANAGEMENT
|
||||||
* ========================================================================================== */
|
* ========================================================================================== */
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
@MenuRes
|
||||||
val menuRes = getMenuRes()
|
open fun getMenuRes() = -1
|
||||||
|
|
||||||
if (menuRes != -1) {
|
// No op by default
|
||||||
menuInflater.inflate(menuRes, menu)
|
open fun handlePostCreateMenu(menu: Menu) = Unit
|
||||||
return true
|
|
||||||
|
// No op by default
|
||||||
|
open fun handlePrepareMenu(menu: Menu) = Unit
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
open fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
|
return when (item.itemId) {
|
||||||
|
android.R.id.home -> {
|
||||||
|
onBackPressed(true)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onCreateOptionsMenu(menu)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
||||||
if (item.itemId == android.R.id.home) {
|
|
||||||
onBackPressed(true)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
|
@ -587,9 +615,6 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
|
||||||
@StringRes
|
@StringRes
|
||||||
open fun getTitleRes() = -1
|
open fun getTitleRes() = -1
|
||||||
|
|
||||||
@MenuRes
|
|
||||||
open fun getMenuRes() = -1
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a object containing other themes for this activity.
|
* Return a object containing other themes for this activity.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -22,12 +22,16 @@ import android.os.Parcelable
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.CallSuper
|
import androidx.annotation.CallSuper
|
||||||
import androidx.annotation.MainThread
|
import androidx.annotation.MainThread
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.core.view.MenuHost
|
||||||
|
import androidx.core.view.MenuProvider
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
|
@ -126,9 +130,7 @@ abstract class VectorBaseFragment<VB : ViewBinding> : Fragment(), MavericksView
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
if (getMenuRes() != -1) {
|
Timber.i("onCreate Fragment ${javaClass.simpleName}")
|
||||||
setHasOptionsMenu(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
final override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
@ -158,6 +160,30 @@ abstract class VectorBaseFragment<VB : ViewBinding> : Fragment(), MavericksView
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
Timber.i("onViewCreated Fragment ${javaClass.simpleName}")
|
Timber.i("onViewCreated Fragment ${javaClass.simpleName}")
|
||||||
|
setupMenu()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupMenu() {
|
||||||
|
val menuRes = getMenuRes().takeIf { it != -1 } ?: return
|
||||||
|
val menuHost: MenuHost = requireActivity()
|
||||||
|
menuHost.addMenuProvider(
|
||||||
|
object : MenuProvider {
|
||||||
|
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
||||||
|
menuInflater.inflate(menuRes, menu)
|
||||||
|
handlePostCreateMenu(menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPrepareMenu(menu: Menu) {
|
||||||
|
handlePrepareMenu(menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
||||||
|
return handleMenuItemSelected(menuItem)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
viewLifecycleOwner,
|
||||||
|
Lifecycle.State.RESUMED
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun showLoading(message: CharSequence?) {
|
open fun showLoading(message: CharSequence?) {
|
||||||
|
@ -272,12 +298,14 @@ abstract class VectorBaseFragment<VB : ViewBinding> : Fragment(), MavericksView
|
||||||
|
|
||||||
open fun getMenuRes() = -1
|
open fun getMenuRes() = -1
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
// No op by default
|
||||||
val menuRes = getMenuRes()
|
open fun handlePostCreateMenu(menu: Menu) = Unit
|
||||||
|
|
||||||
if (menuRes != -1) {
|
// No op by default
|
||||||
inflater.inflate(menuRes, menu)
|
open fun handlePrepareMenu(menu: Menu) = Unit
|
||||||
}
|
|
||||||
|
open fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
|
throw NotImplementedError("You must override this method to handle click on menu item")
|
||||||
}
|
}
|
||||||
|
|
||||||
// This should be provided by the framework
|
// This should be provided by the framework
|
||||||
|
|
|
@ -97,7 +97,7 @@ class AttachmentsPreviewFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.attachmentsPreviewRemoveAction -> {
|
R.id.attachmentsPreviewRemoveAction -> {
|
||||||
handleRemoveAction()
|
handleRemoveAction()
|
||||||
|
@ -107,20 +107,16 @@ class AttachmentsPreviewFragment @Inject constructor(
|
||||||
handleEditAction()
|
handleEditAction()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> {
|
else -> false
|
||||||
super.onOptionsItemSelected(item)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
withState(viewModel) { state ->
|
withState(viewModel) { state ->
|
||||||
val editMenuItem = menu.findItem(R.id.attachmentsPreviewEditAction)
|
val editMenuItem = menu.findItem(R.id.attachmentsPreviewEditAction)
|
||||||
val showEditMenuItem = state.attachments.getOrNull(state.currentAttachmentIndex)?.isEditable().orFalse()
|
val showEditMenuItem = state.attachments.getOrNull(state.currentAttachmentIndex)?.isEditable().orFalse()
|
||||||
editMenuItem.setVisible(showEditMenuItem)
|
editMenuItem.setVisible(showEditMenuItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onPrepareOptionsMenu(menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getMenuRes() = R.menu.vector_attachments_preview
|
override fun getMenuRes() = R.menu.vector_attachments_preview
|
||||||
|
|
|
@ -214,16 +214,19 @@ class VectorCallActivity : VectorBaseActivity<ActivityCallBinding>(), CallContro
|
||||||
renderState(it)
|
renderState(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
if (item.itemId == R.id.menu_call_open_chat) {
|
return when (item.itemId) {
|
||||||
returnToChat()
|
R.id.menu_call_open_chat -> {
|
||||||
return true
|
returnToChat()
|
||||||
} else if (item.itemId == android.R.id.home) {
|
true
|
||||||
// We check here as we want PiP in some cases
|
}
|
||||||
onBackPressed()
|
android.R.id.home -> {
|
||||||
return true
|
// We check here as we want PiP in some cases
|
||||||
|
onBackPressed()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> super.handleMenuItemSelected(item)
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|
|
@ -187,16 +187,6 @@ class KeysBackupSetupActivity : SimpleFragmentActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// I think this code is useful, but it violates the code quality rules
|
|
||||||
// override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
||||||
// if (item.itemId == android .R. id. home) {
|
|
||||||
// onBackPressed()
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return super.onOptionsItemSelected(item)
|
|
||||||
// }
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val KEYS_VERSION = "KEYS_VERSION"
|
const val KEYS_VERSION = "KEYS_VERSION"
|
||||||
const val MANUAL_EXPORT = "MANUAL_EXPORT"
|
const val MANUAL_EXPORT = "MANUAL_EXPORT"
|
||||||
|
|
|
@ -133,16 +133,18 @@ class RoomDevToolActivity : SimpleFragmentActivity(), FragmentManager.OnBackStac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
if (item.itemId == R.id.menuItemEdit) {
|
return when (item.itemId) {
|
||||||
viewModel.handle(RoomDevToolAction.MenuEdit)
|
R.id.menuItemEdit -> {
|
||||||
return true
|
viewModel.handle(RoomDevToolAction.MenuEdit)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
R.id.menuItemSend -> {
|
||||||
|
viewModel.handle(RoomDevToolAction.MenuItemSend)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> super.handleMenuItemSelected(item)
|
||||||
}
|
}
|
||||||
if (item.itemId == R.id.menuItemSend) {
|
|
||||||
viewModel.handle(RoomDevToolAction.MenuItemSend)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
|
@ -174,21 +176,22 @@ class RoomDevToolActivity : SimpleFragmentActivity(), FragmentManager.OnBackStac
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu): Boolean = withState(viewModel) { state ->
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
menu.forEach {
|
withState(viewModel) { state ->
|
||||||
val isVisible = when (it.itemId) {
|
menu.forEach {
|
||||||
R.id.menuItemEdit -> {
|
val isVisible = when (it.itemId) {
|
||||||
state.displayMode is RoomDevToolViewState.Mode.StateEventDetail
|
R.id.menuItemEdit -> {
|
||||||
|
state.displayMode is RoomDevToolViewState.Mode.StateEventDetail
|
||||||
|
}
|
||||||
|
R.id.menuItemSend -> {
|
||||||
|
state.displayMode is RoomDevToolViewState.Mode.EditEventContent ||
|
||||||
|
state.displayMode is RoomDevToolViewState.Mode.SendEventForm
|
||||||
|
}
|
||||||
|
else -> true
|
||||||
}
|
}
|
||||||
R.id.menuItemSend -> {
|
it.isVisible = isVisible
|
||||||
state.displayMode is RoomDevToolViewState.Mode.EditEventContent ||
|
|
||||||
state.displayMode is RoomDevToolViewState.Mode.SendEventForm
|
|
||||||
}
|
|
||||||
else -> true
|
|
||||||
}
|
}
|
||||||
it.isVisible = isVisible
|
|
||||||
}
|
}
|
||||||
return@withState true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -547,47 +547,45 @@ class HomeActivity :
|
||||||
|
|
||||||
override fun getMenuRes() = R.menu.home
|
override fun getMenuRes() = R.menu.home
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
menu.findItem(R.id.menu_home_init_sync_legacy).isVisible = vectorPreferences.developerMode()
|
menu.findItem(R.id.menu_home_init_sync_legacy).isVisible = vectorPreferences.developerMode()
|
||||||
menu.findItem(R.id.menu_home_init_sync_optimized).isVisible = vectorPreferences.developerMode()
|
menu.findItem(R.id.menu_home_init_sync_optimized).isVisible = vectorPreferences.developerMode()
|
||||||
return super.onPrepareOptionsMenu(menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.menu_home_suggestion -> {
|
R.id.menu_home_suggestion -> {
|
||||||
bugReporter.openBugReportScreen(this, ReportType.SUGGESTION)
|
bugReporter.openBugReportScreen(this, ReportType.SUGGESTION)
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
R.id.menu_home_report_bug -> {
|
R.id.menu_home_report_bug -> {
|
||||||
bugReporter.openBugReportScreen(this, ReportType.BUG_REPORT)
|
bugReporter.openBugReportScreen(this, ReportType.BUG_REPORT)
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
R.id.menu_home_init_sync_legacy -> {
|
R.id.menu_home_init_sync_legacy -> {
|
||||||
// Configure the SDK
|
// Configure the SDK
|
||||||
initialSyncStrategy = InitialSyncStrategy.Legacy
|
initialSyncStrategy = InitialSyncStrategy.Legacy
|
||||||
// And clear cache
|
// And clear cache
|
||||||
MainActivity.restartApp(this, MainActivityArgs(clearCache = true))
|
MainActivity.restartApp(this, MainActivityArgs(clearCache = true))
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
R.id.menu_home_init_sync_optimized -> {
|
R.id.menu_home_init_sync_optimized -> {
|
||||||
// Configure the SDK
|
// Configure the SDK
|
||||||
initialSyncStrategy = InitialSyncStrategy.Optimized()
|
initialSyncStrategy = InitialSyncStrategy.Optimized()
|
||||||
// And clear cache
|
// And clear cache
|
||||||
MainActivity.restartApp(this, MainActivityArgs(clearCache = true))
|
MainActivity.restartApp(this, MainActivityArgs(clearCache = true))
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
R.id.menu_home_filter -> {
|
R.id.menu_home_filter -> {
|
||||||
navigator.openRoomsFiltering(this)
|
navigator.openRoomsFiltering(this)
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
R.id.menu_home_setting -> {
|
R.id.menu_home_setting -> {
|
||||||
navigator.openSettings(this)
|
navigator.openSettings(this)
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
|
else -> super.handleMenuItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
|
|
|
@ -91,23 +91,21 @@ class HomeDetailFragment @Inject constructor(
|
||||||
|
|
||||||
override fun getMenuRes() = R.menu.room_list
|
override fun getMenuRes() = R.menu.room_list
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.menu_home_mark_all_as_read -> {
|
R.id.menu_home_mark_all_as_read -> {
|
||||||
viewModel.handle(HomeDetailAction.MarkAllRoomsRead)
|
viewModel.handle(HomeDetailAction.MarkAllRoomsRead)
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
withState(viewModel) { state ->
|
withState(viewModel) { state ->
|
||||||
val isRoomList = state.currentTab is HomeTab.RoomList
|
val isRoomList = state.currentTab is HomeTab.RoomList
|
||||||
menu.findItem(R.id.menu_home_mark_all_as_read).isVisible = isRoomList && hasUnreadRooms
|
menu.findItem(R.id.menu_home_mark_all_as_read).isVisible = isRoomList && hasUnreadRooms
|
||||||
}
|
}
|
||||||
super.onPrepareOptionsMenu(menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentHomeDetailBinding {
|
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentHomeDetailBinding {
|
||||||
|
|
|
@ -30,7 +30,6 @@ import android.view.HapticFeedbackConstants
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuInflater
|
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -1055,15 +1054,14 @@ class TimelineFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
override fun handlePostCreateMenu(menu: Menu) {
|
||||||
if (isThreadTimeLine()) {
|
if (isThreadTimeLine()) {
|
||||||
if (menu is MenuBuilder) menu.setOptionalIconsVisible(true)
|
if (menu is MenuBuilder) menu.setOptionalIconsVisible(true)
|
||||||
}
|
}
|
||||||
super.onCreateOptionsMenu(menu, inflater)
|
|
||||||
// We use a custom layout for this menu item, so we need to set a ClickListener
|
// We use a custom layout for this menu item, so we need to set a ClickListener
|
||||||
menu.findItem(R.id.open_matrix_apps)?.let { menuItem ->
|
menu.findItem(R.id.open_matrix_apps)?.let { menuItem ->
|
||||||
menuItem.actionView.debouncedClicks {
|
menuItem.actionView.debouncedClicks {
|
||||||
onOptionsItemSelected(menuItem)
|
handleMenuItemSelected(menuItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val joinConfItem = menu.findItem(R.id.join_conference)
|
val joinConfItem = menu.findItem(R.id.join_conference)
|
||||||
|
@ -1073,13 +1071,13 @@ class TimelineFragment @Inject constructor(
|
||||||
|
|
||||||
// Custom thread notification menu item
|
// Custom thread notification menu item
|
||||||
menu.findItem(R.id.menu_timeline_thread_list)?.let { menuItem ->
|
menu.findItem(R.id.menu_timeline_thread_list)?.let { menuItem ->
|
||||||
menuItem.actionView.setOnClickListener {
|
menuItem.actionView.debouncedClicks {
|
||||||
onOptionsItemSelected(menuItem)
|
handleMenuItemSelected(menuItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
menu.forEach {
|
menu.forEach {
|
||||||
it.isVisible = timelineViewModel.isMenuItemVisible(it.itemId)
|
it.isVisible = timelineViewModel.isMenuItemVisible(it.itemId)
|
||||||
}
|
}
|
||||||
|
@ -1121,7 +1119,7 @@ class TimelineFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.invite -> {
|
R.id.invite -> {
|
||||||
navigator.openInviteUsersToRoom(requireActivity(), timelineArgs.roomId)
|
navigator.openInviteUsersToRoom(requireActivity(), timelineArgs.roomId)
|
||||||
|
@ -1174,7 +1172,7 @@ class TimelineFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> super.onOptionsItemSelected(item)
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ package im.vector.app.features.home.room.threads.list.views
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuInflater
|
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -71,27 +70,26 @@ class ThreadListFragment @Inject constructor(
|
||||||
analyticsScreenName = MobileScreen.ScreenName.ThreadList
|
analyticsScreenName = MobileScreen.ScreenName.ThreadList
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
override fun handlePostCreateMenu(menu: Menu) {
|
||||||
super.onCreateOptionsMenu(menu, inflater)
|
// We use a custom layout for this menu item, so we need to set a ClickListener
|
||||||
|
|
||||||
menu.findItem(R.id.menu_thread_list_filter)?.let { menuItem ->
|
menu.findItem(R.id.menu_thread_list_filter)?.let { menuItem ->
|
||||||
menuItem.actionView.setOnClickListener {
|
menuItem.actionView.debouncedClicks {
|
||||||
onOptionsItemSelected(menuItem)
|
handleMenuItemSelected(menuItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.menu_thread_list_filter -> {
|
R.id.menu_thread_list_filter -> {
|
||||||
ThreadListBottomSheet().show(childFragmentManager, "Filtering")
|
ThreadListBottomSheet().show(childFragmentManager, "Filtering")
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> super.onOptionsItemSelected(item)
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
withState(threadListViewModel) { state ->
|
withState(threadListViewModel) { state ->
|
||||||
val filterIcon = menu.findItem(R.id.menu_thread_list_filter).actionView
|
val filterIcon = menu.findItem(R.id.menu_thread_list_filter).actionView
|
||||||
val filterBadge = filterIcon.findViewById<View>(R.id.threadListFilterBadge)
|
val filterBadge = filterIcon.findViewById<View>(R.id.threadListFilterBadge)
|
||||||
|
|
|
@ -99,14 +99,14 @@ class LocationPreviewFragment @Inject constructor(
|
||||||
|
|
||||||
override fun getMenuRes() = R.menu.menu_location_preview
|
override fun getMenuRes() = R.menu.menu_location_preview
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.share_external -> {
|
R.id.share_external -> {
|
||||||
onShareLocationExternal()
|
onShareLocationExternal()
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onShareLocationExternal() {
|
private fun onShareLocationExternal() {
|
||||||
|
|
|
@ -120,29 +120,27 @@ class BugReportActivity : VectorBaseActivity<ActivityBugReportBinding>() {
|
||||||
|
|
||||||
override fun getMenuRes() = R.menu.bug_report
|
override fun getMenuRes() = R.menu.bug_report
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
menu.findItem(R.id.ic_action_send_bug_report)?.let {
|
menu.findItem(R.id.ic_action_send_bug_report)?.let {
|
||||||
val isValid = !views.bugReportMaskView.isVisible
|
val isValid = !views.bugReportMaskView.isVisible
|
||||||
|
|
||||||
it.isEnabled = isValid
|
it.isEnabled = isValid
|
||||||
it.icon.alpha = if (isValid) 255 else 100
|
it.icon.alpha = if (isValid) 255 else 100
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onPrepareOptionsMenu(menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.ic_action_send_bug_report -> {
|
R.id.ic_action_send_bug_report -> {
|
||||||
if (views.bugReportEditText.text.toString().trim().length >= 10) {
|
if (views.bugReportEditText.text.toString().trim().length >= 10) {
|
||||||
sendBugReport()
|
sendBugReport()
|
||||||
} else {
|
} else {
|
||||||
views.bugReportTextInputLayout.error = getString(R.string.bug_report_error_too_short)
|
views.bugReportTextInputLayout.error = getString(R.string.bug_report_error_too_short)
|
||||||
}
|
}
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
|
else -> super.handleMenuItemSelected(item)
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -138,10 +138,7 @@ class EmojiReactionPickerActivity : VectorBaseActivity<ActivityEmojiReactionPick
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun handlePostCreateMenu(menu: Menu) {
|
||||||
val inflater: MenuInflater = menuInflater
|
|
||||||
inflater.inflate(getMenuRes(), menu)
|
|
||||||
|
|
||||||
val searchItem = menu.findItem(R.id.search)
|
val searchItem = menu.findItem(R.id.search)
|
||||||
(searchItem.actionView as? SearchView)?.let { searchView ->
|
(searchItem.actionView as? SearchView)?.let { searchView ->
|
||||||
searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
|
searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
|
||||||
|
@ -175,7 +172,6 @@ class EmojiReactionPickerActivity : VectorBaseActivity<ActivityEmojiReactionPick
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
}
|
}
|
||||||
searchItem.expandActionView()
|
searchItem.expandActionView()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO move to ThemeUtils when core module is created
|
// TODO move to ThemeUtils when core module is created
|
||||||
|
|
|
@ -105,14 +105,13 @@ class PublicRoomsFragment @Inject constructor(
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.menu_room_directory_change_protocol -> {
|
R.id.menu_room_directory_change_protocol -> {
|
||||||
sharedActionViewModel.post(RoomDirectorySharedAction.ChangeProtocol)
|
sharedActionViewModel.post(RoomDirectorySharedAction.ChangeProtocol)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else ->
|
else -> false
|
||||||
super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,14 +160,14 @@ class RoomMemberProfileFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.roomMemberProfileShareAction -> {
|
R.id.roomMemberProfileShareAction -> {
|
||||||
viewModel.handle(RoomMemberProfileAction.ShareRoomMemberProfile)
|
viewModel.handle(RoomMemberProfileAction.ShareRoomMemberProfile)
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleStartVerification(startVerification: RoomMemberProfileViewEvents.StartVerification) {
|
private fun handleStartVerification(startVerification: RoomMemberProfileViewEvents.StartVerification) {
|
||||||
|
|
|
@ -170,14 +170,14 @@ class RoomProfileFragment @Inject constructor(
|
||||||
headerViews.roomProfileAliasView.copyOnLongClick()
|
headerViews.roomProfileAliasView.copyOnLongClick()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.roomProfileShareAction -> {
|
R.id.roomProfileShareAction -> {
|
||||||
roomProfileViewModel.handle(RoomProfileAction.ShareRoomProfile)
|
roomProfileViewModel.handle(RoomProfileAction.ShareRoomProfile)
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleQuickActions(action: RoomListQuickActionsSharedAction) = when (action) {
|
private fun handleQuickActions(action: RoomListQuickActionsSharedAction) = when (action) {
|
||||||
|
|
|
@ -139,18 +139,20 @@ class RoomSettingsFragment @Inject constructor(
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
withState(viewModel) { state ->
|
withState(viewModel) { state ->
|
||||||
menu.findItem(R.id.roomSettingsSaveAction).isVisible = state.showSaveAction
|
menu.findItem(R.id.roomSettingsSaveAction).isVisible = state.showSaveAction
|
||||||
}
|
}
|
||||||
super.onPrepareOptionsMenu(menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
if (item.itemId == R.id.roomSettingsSaveAction) {
|
return when (item.itemId) {
|
||||||
viewModel.handle(RoomSettingsAction.Save)
|
R.id.roomSettingsSaveAction -> {
|
||||||
|
viewModel.handle(RoomSettingsAction.Save)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun invalidate() = withState(viewModel) { viewState ->
|
override fun invalidate() = withState(viewModel) { viewState ->
|
||||||
|
|
|
@ -26,8 +26,6 @@ import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||||
import androidx.viewpager2.widget.ViewPager2
|
|
||||||
import androidx.viewpager2.widget.ViewPager2.SCROLL_STATE_IDLE
|
|
||||||
import com.airbnb.mvrx.Loading
|
import com.airbnb.mvrx.Loading
|
||||||
import com.airbnb.mvrx.fragmentViewModel
|
import com.airbnb.mvrx.fragmentViewModel
|
||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
|
@ -61,19 +59,6 @@ class KeyRequestsFragment @Inject constructor(
|
||||||
|
|
||||||
override fun getMenuRes(): Int = R.menu.menu_audit
|
override fun getMenuRes(): Int = R.menu.menu_audit
|
||||||
|
|
||||||
private val pageAdapterListener = object : ViewPager2.OnPageChangeCallback() {
|
|
||||||
override fun onPageSelected(position: Int) {
|
|
||||||
invalidateOptionsMenu()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPageScrollStateChanged(state: Int) {
|
|
||||||
childFragmentManager.fragments.forEach {
|
|
||||||
it.setHasOptionsMenu(state == SCROLL_STATE_IDLE)
|
|
||||||
}
|
|
||||||
invalidateOptionsMenu()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun invalidate() = withState(viewModel) {
|
override fun invalidate() = withState(viewModel) {
|
||||||
when (it.exporting) {
|
when (it.exporting) {
|
||||||
is Loading -> views.exportWaitingView.isVisible = true
|
is Loading -> views.exportWaitingView.isVisible = true
|
||||||
|
@ -81,16 +66,10 @@ class KeyRequestsFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
|
||||||
invalidateOptionsMenu()
|
|
||||||
super.onDestroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
mPagerAdapter = KeyReqPagerAdapter(this)
|
mPagerAdapter = KeyReqPagerAdapter(this)
|
||||||
views.devToolKeyRequestPager.adapter = mPagerAdapter
|
views.devToolKeyRequestPager.adapter = mPagerAdapter
|
||||||
views.devToolKeyRequestPager.registerOnPageChangeCallback(pageAdapterListener)
|
|
||||||
|
|
||||||
TabLayoutMediator(views.devToolKeyRequestTabs, views.devToolKeyRequestPager) { tab, position ->
|
TabLayoutMediator(views.devToolKeyRequestTabs, views.devToolKeyRequestPager) { tab, position ->
|
||||||
when (position) {
|
when (position) {
|
||||||
|
@ -119,25 +98,26 @@ class KeyRequestsFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
views.devToolKeyRequestPager.unregisterOnPageChangeCallback(pageAdapterListener)
|
|
||||||
mPagerAdapter = null
|
mPagerAdapter = null
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
if (item.itemId == R.id.audit_export) {
|
return when (item.itemId) {
|
||||||
selectTxtFileToWrite(
|
R.id.audit_export -> {
|
||||||
activity = requireActivity(),
|
selectTxtFileToWrite(
|
||||||
activityResultLauncher = epxortAuditForActivityResult,
|
activity = requireActivity(),
|
||||||
defaultFileName = "audit-export_${clock.epochMillis()}.txt",
|
activityResultLauncher = exportAuditForActivityResult,
|
||||||
chooserHint = "Export Audit"
|
defaultFileName = "audit-export_${clock.epochMillis()}.txt",
|
||||||
)
|
chooserHint = "Export Audit"
|
||||||
return true
|
)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val epxortAuditForActivityResult = registerStartForActivityResult { activityResult ->
|
private val exportAuditForActivityResult = registerStartForActivityResult { activityResult ->
|
||||||
if (activityResult.resultCode == Activity.RESULT_OK) {
|
if (activityResult.resultCode == Activity.RESULT_OK) {
|
||||||
val uri = activityResult.data?.data
|
val uri = activityResult.data?.data
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
|
|
|
@ -46,14 +46,13 @@ class PushGatewaysFragment @Inject constructor(
|
||||||
|
|
||||||
override fun getMenuRes() = R.menu.menu_push_gateways
|
override fun getMenuRes() = R.menu.menu_push_gateways
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.refresh -> {
|
R.id.refresh -> {
|
||||||
viewModel.handle(PushGatewayAction.Refresh)
|
viewModel.handle(PushGatewayAction.Refresh)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else ->
|
else -> false
|
||||||
super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,40 +177,41 @@ class SpaceDirectoryFragment @Inject constructor(
|
||||||
views.addOrCreateChatRoomButton.isVisible = state.canAddRooms
|
views.addOrCreateChatRoomButton.isVisible = state.canAddRooms
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) = withState(viewModel) { state ->
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
menu.findItem(R.id.spaceAddRoom)?.isVisible = state.canAddRooms
|
withState(viewModel) { state ->
|
||||||
menu.findItem(R.id.spaceCreateRoom)?.isVisible = false // Not yet implemented
|
menu.findItem(R.id.spaceAddRoom)?.isVisible = state.canAddRooms
|
||||||
|
menu.findItem(R.id.spaceCreateRoom)?.isVisible = false // Not yet implemented
|
||||||
|
|
||||||
menu.findItem(R.id.spaceSearch)?.let { searchItem ->
|
menu.findItem(R.id.spaceSearch)?.let { searchItem ->
|
||||||
val searchView = searchItem.actionView as SearchView
|
val searchView = searchItem.actionView as SearchView
|
||||||
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onQueryTextChange(newText: String?): Boolean {
|
override fun onQueryTextChange(newText: String?): Boolean {
|
||||||
onFilterQueryChanged(newText)
|
onFilterQueryChanged(newText)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
super.onPrepareOptionsMenu(menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.spaceAddRoom -> {
|
R.id.spaceAddRoom -> {
|
||||||
withState(viewModel) { state ->
|
withState(viewModel) { state ->
|
||||||
addExistingRooms(state.spaceId)
|
addExistingRooms(state.spaceId)
|
||||||
}
|
}
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
R.id.spaceCreateRoom -> {
|
R.id.spaceCreateRoom -> {
|
||||||
// not implemented yet
|
// not implemented yet
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFilterQueryChanged(query: String?) {
|
override fun onFilterQueryChanged(query: String?) {
|
||||||
|
|
|
@ -89,7 +89,7 @@ class SpaceLeaveAdvancedFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
menu.findItem(R.id.menu_space_leave_search)?.let { searchItem ->
|
menu.findItem(R.id.menu_space_leave_search)?.let { searchItem ->
|
||||||
searchItem.bind(
|
searchItem.bind(
|
||||||
onExpanded = { viewModel.handle(SpaceLeaveAdvanceViewAction.SetFilteringEnabled(isEnabled = true)) },
|
onExpanded = { viewModel.handle(SpaceLeaveAdvanceViewAction.SetFilteringEnabled(isEnabled = true)) },
|
||||||
|
@ -97,7 +97,6 @@ class SpaceLeaveAdvancedFragment @Inject constructor(
|
||||||
onTextChanged = { viewModel.handle(SpaceLeaveAdvanceViewAction.UpdateFilter(it)) }
|
onTextChanged = { viewModel.handle(SpaceLeaveAdvanceViewAction.UpdateFilter(it)) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
super.onPrepareOptionsMenu(menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
|
|
|
@ -151,17 +151,18 @@ class SpaceAddRoomFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
super.onPrepareOptionsMenu(menu)
|
|
||||||
menu.findItem(R.id.spaceAddRoomSaveItem).isVisible = saveNeeded
|
menu.findItem(R.id.spaceAddRoomSaveItem).isVisible = saveNeeded
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
if (item.itemId == R.id.spaceAddRoomSaveItem) {
|
return when (item.itemId) {
|
||||||
viewModel.handle(SpaceAddRoomActions.Save)
|
R.id.spaceAddRoomSaveItem -> {
|
||||||
return true
|
viewModel.handle(SpaceAddRoomActions.Save)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
|
|
|
@ -111,18 +111,20 @@ class SpaceSettingsFragment @Inject constructor(
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
withState(viewModel) { state ->
|
withState(viewModel) { state ->
|
||||||
menu.findItem(R.id.roomSettingsSaveAction).isVisible = state.showSaveAction
|
menu.findItem(R.id.roomSettingsSaveAction).isVisible = state.showSaveAction
|
||||||
}
|
}
|
||||||
super.onPrepareOptionsMenu(menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
if (item.itemId == R.id.roomSettingsSaveAction) {
|
return when (item.itemId) {
|
||||||
viewModel.handle(RoomSettingsAction.Save)
|
R.id.roomSettingsSaveAction -> {
|
||||||
|
viewModel.handle(RoomSettingsAction.Save)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderRoomSummary(state: RoomSettingsViewState) {
|
private fun renderRoomSummary(state: RoomSettingsViewState) {
|
||||||
|
|
|
@ -113,19 +113,20 @@ class UserListFragment @Inject constructor(
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
withState(viewModel) {
|
withState(viewModel) {
|
||||||
val showMenuItem = it.pendingSelections.isNotEmpty()
|
val showMenuItem = it.pendingSelections.isNotEmpty()
|
||||||
menu.forEach { menuItem ->
|
menu.forEach { menuItem ->
|
||||||
menuItem.isVisible = showMenuItem
|
menuItem.isVisible = showMenuItem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.onPrepareOptionsMenu(menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = withState(viewModel) {
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
sharedActionViewModel.post(UserListSharedAction.OnMenuItemSelected(item.itemId, it.pendingSelections))
|
withState(viewModel) {
|
||||||
return@withState true
|
sharedActionViewModel.post(UserListSharedAction.OnMenuItemSelected(item.itemId, it.pendingSelections))
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupRecyclerView() {
|
private fun setupRecyclerView() {
|
||||||
|
|
|
@ -64,8 +64,6 @@ class WidgetActivity : VectorBaseActivity<ActivityWidgetBinding>() {
|
||||||
|
|
||||||
override fun getBinding() = ActivityWidgetBinding.inflate(layoutInflater)
|
override fun getBinding() = ActivityWidgetBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
override fun getMenuRes() = R.menu.menu_widget
|
|
||||||
|
|
||||||
override fun getTitleRes() = R.string.room_widget_activity_title
|
override fun getTitleRes() = R.string.room_widget_activity_title
|
||||||
|
|
||||||
override fun initUiAndData() {
|
override fun initUiAndData() {
|
||||||
|
|
|
@ -79,7 +79,6 @@ class WidgetFragment @Inject constructor(
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
setHasOptionsMenu(true)
|
|
||||||
views.widgetWebView.setupForWidget(this)
|
views.widgetWebView.setupForWidget(this)
|
||||||
if (fragmentArgs.kind.isAdmin()) {
|
if (fragmentArgs.kind.isAdmin()) {
|
||||||
viewModel.getPostAPIMediator().setWebView(views.widgetWebView)
|
viewModel.getPostAPIMediator().setWebView(views.widgetWebView)
|
||||||
|
@ -136,53 +135,64 @@ class WidgetFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu) = withState(viewModel) { state ->
|
override fun getMenuRes() = R.menu.menu_widget
|
||||||
val widget = state.asyncWidget()
|
|
||||||
menu.findItem(R.id.action_edit)?.isVisible = state.widgetKind != WidgetKind.INTEGRATION_MANAGER
|
override fun handlePrepareMenu(menu: Menu) {
|
||||||
if (widget == null) {
|
withState(viewModel) { state ->
|
||||||
menu.findItem(R.id.action_refresh)?.isVisible = false
|
val widget = state.asyncWidget()
|
||||||
menu.findItem(R.id.action_widget_open_ext)?.isVisible = false
|
menu.findItem(R.id.action_edit)?.isVisible = state.widgetKind != WidgetKind.INTEGRATION_MANAGER
|
||||||
menu.findItem(R.id.action_delete)?.isVisible = false
|
if (widget == null) {
|
||||||
menu.findItem(R.id.action_revoke)?.isVisible = false
|
menu.findItem(R.id.action_refresh)?.isVisible = false
|
||||||
} else {
|
menu.findItem(R.id.action_widget_open_ext)?.isVisible = false
|
||||||
menu.findItem(R.id.action_refresh)?.isVisible = true
|
menu.findItem(R.id.action_delete)?.isVisible = false
|
||||||
menu.findItem(R.id.action_widget_open_ext)?.isVisible = true
|
menu.findItem(R.id.action_revoke)?.isVisible = false
|
||||||
menu.findItem(R.id.action_delete)?.isVisible = state.canManageWidgets && widget.isAddedByMe
|
} else {
|
||||||
menu.findItem(R.id.action_revoke)?.isVisible = state.status == WidgetStatus.WIDGET_ALLOWED && !widget.isAddedByMe
|
menu.findItem(R.id.action_refresh)?.isVisible = true
|
||||||
|
menu.findItem(R.id.action_widget_open_ext)?.isVisible = true
|
||||||
|
menu.findItem(R.id.action_delete)?.isVisible = state.canManageWidgets && widget.isAddedByMe
|
||||||
|
menu.findItem(R.id.action_revoke)?.isVisible = state.status == WidgetStatus.WIDGET_ALLOWED && !widget.isAddedByMe
|
||||||
|
}
|
||||||
}
|
}
|
||||||
super.onPrepareOptionsMenu(menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = withState(viewModel) { state ->
|
override fun handleMenuItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
return withState(viewModel) { state ->
|
||||||
R.id.action_edit -> {
|
return@withState when (item.itemId) {
|
||||||
navigator.openIntegrationManager(
|
R.id.action_edit -> {
|
||||||
requireContext(),
|
navigator.openIntegrationManager(
|
||||||
integrationManagerActivityResultLauncher,
|
requireContext(),
|
||||||
state.roomId,
|
integrationManagerActivityResultLauncher,
|
||||||
state.widgetId,
|
state.roomId,
|
||||||
state.widgetKind.screenId
|
state.widgetId,
|
||||||
)
|
state.widgetKind.screenId
|
||||||
return@withState true
|
)
|
||||||
}
|
true
|
||||||
R.id.action_delete -> {
|
}
|
||||||
deleteWidget()
|
R.id.action_delete -> {
|
||||||
return@withState true
|
deleteWidget()
|
||||||
}
|
true
|
||||||
R.id.action_refresh -> if (state.formattedURL.complete) {
|
}
|
||||||
views.widgetWebView.reload()
|
R.id.action_refresh -> {
|
||||||
return@withState true
|
if (state.formattedURL.complete) {
|
||||||
}
|
views.widgetWebView.reload()
|
||||||
R.id.action_widget_open_ext -> if (state.formattedURL.complete) {
|
}
|
||||||
openUrlInExternalBrowser(requireContext(), state.formattedURL.invoke())
|
true
|
||||||
return@withState true
|
}
|
||||||
}
|
R.id.action_widget_open_ext -> {
|
||||||
R.id.action_revoke -> if (state.status == WidgetStatus.WIDGET_ALLOWED) {
|
if (state.formattedURL.complete) {
|
||||||
revokeWidget()
|
openUrlInExternalBrowser(requireContext(), state.formattedURL.invoke())
|
||||||
return@withState true
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
R.id.action_revoke -> {
|
||||||
|
if (state.status == WidgetStatus.WIDGET_ALLOWED) {
|
||||||
|
revokeWidget()
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return@withState super.onOptionsItemSelected(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed(toolbarButton: Boolean): Boolean = withState(viewModel) { state ->
|
override fun onBackPressed(toolbarButton: Boolean): Boolean = withState(viewModel) { state ->
|
||||||
|
|
Loading…
Reference in a new issue