mirror of https://github.com/readrops/Readrops.git
Put three dots dropdown menu in a separate file
This commit is contained in:
parent
9c95e0d63c
commit
3109fed97e
|
@ -5,17 +5,11 @@ import androidx.compose.animation.core.LinearOutSlowInEasing
|
|||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
|
@ -30,6 +24,7 @@ import androidx.compose.ui.res.painterResource
|
|||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import com.readrops.app.R
|
||||
import com.readrops.app.util.components.ThreeDotsMenu
|
||||
import com.readrops.app.util.theme.MediumSpacer
|
||||
import com.readrops.app.util.theme.spacing
|
||||
import com.readrops.db.entities.Feed
|
||||
|
@ -46,7 +41,6 @@ fun FolderExpandableItem(
|
|||
onDeleteFolder: () -> Unit
|
||||
) {
|
||||
var isFolderExpanded by remember { mutableStateOf(false) }
|
||||
var isDropDownMenuExpanded by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(isExpanded) {
|
||||
isFolderExpanded = isExpanded
|
||||
|
@ -94,37 +88,18 @@ fun FolderExpandableItem(
|
|||
)
|
||||
}
|
||||
|
||||
Box {
|
||||
IconButton(
|
||||
onClick = { isDropDownMenuExpanded = isDropDownMenuExpanded.not() }
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.MoreVert,
|
||||
contentDescription = null,
|
||||
)
|
||||
ThreeDotsMenu(
|
||||
items = mapOf(
|
||||
1 to stringResource(id = R.string.update),
|
||||
2 to stringResource(id = R.string.delete)
|
||||
),
|
||||
onItemClick = { index ->
|
||||
when (index) {
|
||||
1 -> onUpdateFolder()
|
||||
else -> onDeleteFolder()
|
||||
}
|
||||
|
||||
DropdownMenu(
|
||||
expanded = isDropDownMenuExpanded,
|
||||
onDismissRequest = { isDropDownMenuExpanded = false },
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = "Update") },
|
||||
onClick = {
|
||||
isDropDownMenuExpanded = false
|
||||
onUpdateFolder()
|
||||
}
|
||||
)
|
||||
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.delete)) },
|
||||
onClick = {
|
||||
isDropDownMenuExpanded = false
|
||||
onDeleteFolder()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.readrops.app.notifications
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
|
@ -9,9 +8,6 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material.icons.Icons
|
||||
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.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
|
@ -37,6 +33,7 @@ import cafe.adriel.voyager.navigator.LocalNavigator
|
|||
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||
import com.readrops.app.R
|
||||
import com.readrops.app.util.components.AndroidScreen
|
||||
import com.readrops.app.util.components.ThreeDotsMenu
|
||||
import com.readrops.app.util.theme.MediumSpacer
|
||||
import com.readrops.app.util.theme.spacing
|
||||
import com.readrops.db.entities.account.Account
|
||||
|
@ -72,37 +69,18 @@ class NotificationsScreen(val account: Account) : AndroidScreen() {
|
|||
}
|
||||
},
|
||||
actions = {
|
||||
Box {
|
||||
IconButton(
|
||||
onClick = { isDropDownMenuExpanded = isDropDownMenuExpanded.not() }
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.MoreVert,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
|
||||
DropdownMenu(
|
||||
expanded = isDropDownMenuExpanded,
|
||||
onDismissRequest = { isDropDownMenuExpanded = false },
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = {
|
||||
Text(
|
||||
text = if (state.allFeedNotificationsEnabled) {
|
||||
ThreeDotsMenu(
|
||||
items = mapOf(
|
||||
1 to if (state.allFeedNotificationsEnabled) {
|
||||
stringResource(id = R.string.disable_all)
|
||||
} else {
|
||||
stringResource(id = R.string.enable_all)
|
||||
}
|
||||
)
|
||||
},
|
||||
onClick = {
|
||||
isDropDownMenuExpanded = false
|
||||
screenModel.setAllFeedsNotificationsState(enabled = !state.allFeedNotificationsEnabled)
|
||||
),
|
||||
onItemClick = {
|
||||
screenModel.setAllFeedsNotificationsState(!state.allFeedNotificationsEnabled)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
scrollBehavior = topAppBarScrollBehavior
|
||||
)
|
||||
|
@ -121,7 +99,6 @@ class NotificationsScreen(val account: Account) : AndroidScreen() {
|
|||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = MaterialTheme.spacing.mediumSpacing)
|
||||
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.enable_notifications)
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package com.readrops.app.util.components
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
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
|
||||
|
||||
@Composable
|
||||
fun ThreeDotsMenu(
|
||||
items: Map<Int, String>,
|
||||
onItemClick: (Int) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var isExpanded by remember { mutableStateOf(false) }
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
) {
|
||||
IconButton(
|
||||
onClick = { isExpanded = !isExpanded }
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.MoreVert,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
|
||||
DropdownMenu(
|
||||
expanded = isExpanded,
|
||||
onDismissRequest = { isExpanded = !isExpanded },
|
||||
) {
|
||||
for ((index, value) in items) {
|
||||
DropdownMenuItem(
|
||||
text = {
|
||||
Text(
|
||||
text = value
|
||||
)
|
||||
},
|
||||
onClick = {
|
||||
isExpanded = false
|
||||
onItemClick(index)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -171,4 +171,5 @@
|
|||
<string name="open_source_libraries">Bibliothèques Open source</string>
|
||||
<string name="make_donation">Faire une donation</string>
|
||||
<string name="other_accounts">Autres comptes</string>
|
||||
<string name="update">Mettre à jour</string>
|
||||
</resources>
|
|
@ -180,4 +180,5 @@
|
|||
<string name="app_changelog_url" translatable="false">https://github.com/readrops/Readrops/blob/develop/CHANGELOG.md</string>
|
||||
<string name="app_issues_url" translatable="false">https://github.com/readrops/Readrops/issues</string>
|
||||
<string name="other_accounts">Other accounts</string>
|
||||
<string name="update">Update</string>
|
||||
</resources>
|
Loading…
Reference in New Issue