mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-23 05:29:54 +01:00
migrate dropdown menu
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
84ce5df2d7
commit
6ed17603d6
@ -8,23 +8,36 @@
|
|||||||
package com.nextcloud.talk.diagnose
|
package com.nextcloud.talk.diagnose
|
||||||
|
|
||||||
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
|
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
|
import androidx.compose.material3.DropdownMenu
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.colorResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import com.nextcloud.talk.R
|
import com.nextcloud.talk.R
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun AppBar(title: String) {
|
fun AppBar(title: String, menuItems: List<Pair<String, () -> Unit>>?) {
|
||||||
val backDispatcher = LocalOnBackPressedDispatcherOwner.current?.onBackPressedDispatcher
|
val backDispatcher = LocalOnBackPressedDispatcherOwner.current?.onBackPressedDispatcher
|
||||||
|
|
||||||
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = { Text(text = title) },
|
title = { Text(text = title) },
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
@ -36,6 +49,29 @@ fun AppBar(title: String) {
|
|||||||
contentDescription = stringResource(R.string.back_button)
|
contentDescription = stringResource(R.string.back_button)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
Box {
|
||||||
|
IconButton(onClick = { expanded = true }) {
|
||||||
|
Icon(Icons.Default.MoreVert, contentDescription = "More Options")
|
||||||
|
}
|
||||||
|
|
||||||
|
DropdownMenu(
|
||||||
|
expanded = expanded,
|
||||||
|
onDismissRequest = { expanded = false },
|
||||||
|
Modifier.background(colorResource(id = R.color.bg_default))
|
||||||
|
) {
|
||||||
|
menuItems?.forEach { (label, action) ->
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(label) },
|
||||||
|
onClick = {
|
||||||
|
action()
|
||||||
|
expanded = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -43,5 +79,5 @@ fun AppBar(title: String) {
|
|||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
fun AppBarPreview() {
|
fun AppBarPreview() {
|
||||||
AppBar("title")
|
AppBar("title", null)
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,6 @@ import android.os.Build.MANUFACTURER
|
|||||||
import android.os.Build.MODEL
|
import android.os.Build.MODEL
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.SpannableStringBuilder
|
import android.text.SpannableStringBuilder
|
||||||
import android.view.Menu
|
|
||||||
import android.view.MenuItem
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
@ -83,13 +81,27 @@ class DiagnoseActivity : BaseActivity() {
|
|||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
val backgroundColor = colorResource(id = R.color.bg_default)
|
val backgroundColor = colorResource(id = R.color.bg_default)
|
||||||
|
|
||||||
|
val menuItems = mutableListOf(
|
||||||
|
stringResource(R.string.nc_common_copy) to { copyToClipboard(diagnoseData.toMarkdownString()) },
|
||||||
|
stringResource(R.string.share) to { shareToOtherApps(diagnoseData.toMarkdownString()) },
|
||||||
|
stringResource(R.string.send_email) to { composeEmail(diagnoseData.toMarkdownString()) }
|
||||||
|
)
|
||||||
|
|
||||||
|
if (BrandingUtils.isOriginalNextcloudClient(applicationContext)) {
|
||||||
|
menuItems.add(
|
||||||
|
stringResource(R.string.create_issue) to { createGithubIssue(diagnoseData.toMarkdownString()) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
MaterialTheme(
|
MaterialTheme(
|
||||||
colorScheme = colorScheme
|
colorScheme = colorScheme
|
||||||
) {
|
) {
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
AppBar(
|
AppBar(
|
||||||
title = stringResource(R.string.nc_settings_diagnose_title)
|
title = stringResource(R.string.nc_settings_diagnose_title),
|
||||||
|
menuItems
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
content = {
|
content = {
|
||||||
@ -122,50 +134,6 @@ class DiagnoseActivity : BaseActivity() {
|
|||||||
diagnoseDataState.value = diagnoseData.toList()
|
diagnoseDataState.value = diagnoseData.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
||||||
menuInflater.inflate(R.menu.menu_diagnose, menu)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
|
|
||||||
super.onPrepareOptionsMenu(menu)
|
|
||||||
menu.findItem(R.id.create_issue).isVisible = BrandingUtils.isOriginalNextcloudClient(applicationContext)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
||||||
return when (item.itemId) {
|
|
||||||
android.R.id.home -> {
|
|
||||||
onBackPressedDispatcher.onBackPressed()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
R.id.copy -> {
|
|
||||||
copyToClipboard(diagnoseData.toMarkdownString())
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
R.id.share -> {
|
|
||||||
shareToOtherApps(diagnoseData.toMarkdownString())
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
R.id.send_mail -> {
|
|
||||||
composeEmail(diagnoseData.toMarkdownString())
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
R.id.create_issue -> {
|
|
||||||
createGithubIssue(diagnoseData.toMarkdownString())
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
super.onOptionsItemSelected(item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun shareToOtherApps(message: String) {
|
private fun shareToOtherApps(message: String) {
|
||||||
val sendIntent: Intent = Intent().apply {
|
val sendIntent: Intent = Intent().apply {
|
||||||
action = Intent.ACTION_SEND
|
action = Intent.ACTION_SEND
|
||||||
@ -468,6 +436,7 @@ class DiagnoseActivity : BaseActivity() {
|
|||||||
markdownText.append("$MARKDOWN_HEADLINE ${it.headline}")
|
markdownText.append("$MARKDOWN_HEADLINE ${it.headline}")
|
||||||
markdownText.append("\n\n")
|
markdownText.append("\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
is DiagnoseElement.DiagnoseEntry -> {
|
is DiagnoseElement.DiagnoseEntry -> {
|
||||||
markdownText.append("$MARKDOWN_BOLD${it.key}$MARKDOWN_BOLD")
|
markdownText.append("$MARKDOWN_BOLD${it.key}$MARKDOWN_BOLD")
|
||||||
markdownText.append("\n\n")
|
markdownText.append("\n\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user