mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
show context menu on log press in android home cell
This commit is contained in:
parent
41a978e5fc
commit
201a736f0f
3 changed files with 66 additions and 9 deletions
|
|
@ -97,7 +97,8 @@ fun HomeViewContent(
|
|||
} else {
|
||||
navController.navigate("WebReader/${item.slug}")
|
||||
}
|
||||
}
|
||||
},
|
||||
actionHandler = { homeViewModel.handleLinkedItemAction(item.id, it) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package app.omnivore.omnivore.ui.home
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
|
|
@ -87,6 +88,17 @@ class HomeViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun handleLinkedItemAction(itemID: String, action: LinkedItemAction) {
|
||||
when (action) {
|
||||
LinkedItemAction.Delete -> {
|
||||
Log.d("maxx", "delete action for id: $itemID")
|
||||
}
|
||||
LinkedItemAction.Archive -> {
|
||||
Log.d("maxx", "archive action for id: $itemID")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchQuery(): String {
|
||||
var query = "in:inbox sort:saved"
|
||||
|
||||
|
|
@ -97,3 +109,8 @@ class HomeViewModel @Inject constructor(
|
|||
return query
|
||||
}
|
||||
}
|
||||
|
||||
enum class LinkedItemAction {
|
||||
Delete,
|
||||
Archive
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
package app.omnivore.omnivore.ui.home
|
||||
|
||||
import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Divider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material.icons.outlined.Edit
|
||||
import androidx.compose.material.icons.outlined.List
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
|
|
@ -18,8 +19,10 @@ import androidx.compose.ui.unit.sp
|
|||
import app.omnivore.omnivore.models.LinkedItem
|
||||
import coil.compose.rememberAsyncImagePainter
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun LinkedItemCard(item: LinkedItem, onClickHandler: () -> Unit) {
|
||||
fun LinkedItemCard(item: LinkedItem, onClickHandler: () -> Unit, actionHandler: (LinkedItemAction) -> Unit) {
|
||||
var isMenuExpanded by remember { mutableStateOf(false) }
|
||||
val publisherDisplayName = item.publisherDisplayName()
|
||||
|
||||
Column {
|
||||
|
|
@ -29,7 +32,11 @@ fun LinkedItemCard(item: LinkedItem, onClickHandler: () -> Unit) {
|
|||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(12.dp)
|
||||
.clickable(onClick = onClickHandler)
|
||||
.combinedClickable(
|
||||
onClick = onClickHandler,
|
||||
onLongClick = { isMenuExpanded = true }
|
||||
)
|
||||
.background(if (isMenuExpanded) Color.LightGray else Color.Transparent)
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
|
|
@ -75,5 +82,37 @@ fun LinkedItemCard(item: LinkedItem, onClickHandler: () -> Unit) {
|
|||
}
|
||||
|
||||
Divider(color = MaterialTheme.colorScheme.outlineVariant, thickness = 1.dp)
|
||||
|
||||
DropdownMenu(
|
||||
expanded = isMenuExpanded,
|
||||
onDismissRequest = { isMenuExpanded = false }
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text("Archive") },
|
||||
onClick = {
|
||||
actionHandler(LinkedItemAction.Archive)
|
||||
isMenuExpanded = false
|
||||
},
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
Icons.Outlined.List, // TODO: use more appropriate icon
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text("Remove Item") },
|
||||
onClick = {
|
||||
actionHandler(LinkedItemAction.Delete)
|
||||
isMenuExpanded = false
|
||||
},
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
Icons.Outlined.Delete,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue