mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add context menu to web reader (but keep it disabled for now)
This commit is contained in:
parent
6e1182d163
commit
e5fec25fd5
6 changed files with 111 additions and 39 deletions
|
|
@ -18,10 +18,10 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavHostController
|
||||
import app.omnivore.omnivore.Routes
|
||||
import app.omnivore.omnivore.models.LinkedItem
|
||||
import app.omnivore.omnivore.ui.linkedItemViews.LinkedItemCard
|
||||
import app.omnivore.omnivore.ui.reader.PDFReaderActivity
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
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
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
package app.omnivore.omnivore.ui.home
|
||||
package app.omnivore.omnivore.ui.linkedItemViews
|
||||
|
||||
import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material.icons.outlined.List
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
|
|
@ -16,6 +13,7 @@ import androidx.compose.ui.text.style.TextOverflow
|
|||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import app.omnivore.omnivore.models.LinkedItem
|
||||
import app.omnivore.omnivore.ui.home.LinkedItemAction
|
||||
import coil.compose.rememberAsyncImagePainter
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
|
|
@ -82,37 +80,11 @@ fun LinkedItemCard(item: LinkedItem, onClickHandler: () -> Unit, actionHandler:
|
|||
|
||||
Divider(color = MaterialTheme.colorScheme.outlineVariant, thickness = 1.dp)
|
||||
|
||||
DropdownMenu(
|
||||
expanded = isMenuExpanded,
|
||||
onDismissRequest = { isMenuExpanded = false }
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(if (item.isArchived) "Unarchive" else "Archive") },
|
||||
onClick = {
|
||||
val action = if (item.isArchived) LinkedItemAction.Unarchive else LinkedItemAction.Archive
|
||||
actionHandler(action)
|
||||
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
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
LinkedItemContextMenu(
|
||||
isExpanded = isMenuExpanded,
|
||||
isArchived = item.isArchived,
|
||||
onDismiss = { isMenuExpanded = false },
|
||||
actionHandler = actionHandler
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package app.omnivore.omnivore.ui.linkedItemViews
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material.icons.outlined.List
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import app.omnivore.omnivore.ui.home.LinkedItemAction
|
||||
|
||||
@Composable
|
||||
fun LinkedItemContextMenu(
|
||||
isExpanded: Boolean,
|
||||
isArchived: Boolean,
|
||||
onDismiss: () -> Unit,
|
||||
actionHandler: (LinkedItemAction) -> Unit
|
||||
) {
|
||||
DropdownMenu(
|
||||
expanded = isExpanded,
|
||||
onDismissRequest = onDismiss
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(if (isArchived) "Unarchive" else "Archive") },
|
||||
onClick = {
|
||||
val action = if (isArchived) LinkedItemAction.Unarchive else LinkedItemAction.Archive
|
||||
actionHandler(action)
|
||||
onDismiss()
|
||||
},
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
Icons.Outlined.List, // TODO: use more appropriate icon
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text("Remove Item") },
|
||||
onClick = {
|
||||
actionHandler(LinkedItemAction.Delete)
|
||||
onDismiss()
|
||||
},
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
Icons.Outlined.Delete,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.*
|
|||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.TopAppBar
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
|
|
@ -28,6 +29,7 @@ import androidx.compose.ui.unit.dp
|
|||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.core.content.ContextCompat.getSystemService
|
||||
import app.omnivore.omnivore.R
|
||||
import app.omnivore.omnivore.ui.linkedItemViews.LinkedItemContextMenu
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
|
@ -39,6 +41,7 @@ import kotlin.math.roundToInt
|
|||
|
||||
@Composable
|
||||
fun WebReaderLoadingContainer(slug: String, webReaderViewModel: WebReaderViewModel) {
|
||||
var isMenuExpanded by remember { mutableStateOf(false) }
|
||||
var showWebPreferencesDialog by remember { mutableStateOf(false ) }
|
||||
|
||||
val webReaderParams: WebReaderParams? by webReaderViewModel.webReaderParamsLiveData.observeAsState(null)
|
||||
|
|
@ -94,12 +97,25 @@ fun WebReaderLoadingContainer(slug: String, webReaderViewModel: WebReaderViewMod
|
|||
backgroundColor = MaterialTheme.colorScheme.surfaceVariant,
|
||||
title = {},
|
||||
actions = {
|
||||
// Disabling menu until we implement local persistence
|
||||
// IconButton(onClick = { isMenuExpanded = true }) {
|
||||
// Icon(
|
||||
// imageVector = Icons.Filled.Menu,
|
||||
// contentDescription = null
|
||||
// )
|
||||
// }
|
||||
IconButton(onClick = { showWebPreferencesDialog = true }) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.Settings,
|
||||
imageVector = Icons.Filled.Settings, // TODO: set a better icon
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
LinkedItemContextMenu(
|
||||
isExpanded = isMenuExpanded,
|
||||
isArchived = webReaderParams!!.item.isArchived,
|
||||
onDismiss = { isMenuExpanded = false },
|
||||
actionHandler = { webReaderViewModel.handleLinkedItemAction(webReaderParams!!.item.id, it) }
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,8 +10,11 @@ import app.omnivore.omnivore.DatastoreKeys
|
|||
import app.omnivore.omnivore.DatastoreRepository
|
||||
import app.omnivore.omnivore.models.LinkedItem
|
||||
import app.omnivore.omnivore.networking.*
|
||||
import app.omnivore.omnivore.ui.home.LinkedItemAction
|
||||
import com.google.gson.Gson
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.util.*
|
||||
|
|
@ -62,6 +65,36 @@ class WebReaderViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun handleLinkedItemAction(itemID: String, action: LinkedItemAction) {
|
||||
when (action) {
|
||||
LinkedItemAction.Delete -> {
|
||||
viewModelScope.launch {
|
||||
networker.deleteLinkedItem(itemID)
|
||||
popToHomeView(itemID)
|
||||
}
|
||||
}
|
||||
LinkedItemAction.Archive -> {
|
||||
viewModelScope.launch {
|
||||
networker.archiveLinkedItem(itemID)
|
||||
popToHomeView(itemID)
|
||||
}
|
||||
}
|
||||
LinkedItemAction.Unarchive -> {
|
||||
viewModelScope.launch {
|
||||
networker.unarchiveLinkedItem(itemID)
|
||||
popToHomeView(itemID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun popToHomeView(itemID: String) {
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
// TODO: pop to home
|
||||
Log.d("maxx", "should pop to home and remove item with ID: $itemID")
|
||||
}
|
||||
}
|
||||
|
||||
fun handleIncomingWebMessage(actionID: String, jsonString: String) {
|
||||
when (actionID) {
|
||||
"createHighlight" -> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue