ADd the set labels sheet back in

This commit is contained in:
Jackson Harper
2023-05-10 14:44:36 +08:00
parent 431866da8b
commit de3db625f7
4 changed files with 60 additions and 19 deletions

View File

@ -68,11 +68,15 @@ fun WebReader(
view: WebView?,
request: WebResourceRequest?
): Boolean {
Log.d("reader","SHOULD OVERRIDE REQUEST: ${request?.url} hasGesture: ${request?.hasGesture()} isForMainFrame: ${request?.isForMainFrame()}")
if ((request?.isForMainFrame == true) && (request?.hasGesture() == true)) {
return false
var handled: Boolean? = null
request?.let {
if ((request?.isForMainFrame == true) && (request?.hasGesture() == true) && viewModel != null) {
viewModel?.showOpenLinkSheet(request.url)
handled = true
}
}
return super.shouldOverrideUrlLoading(view, request)
return handled ?: super.shouldOverrideUrlLoading(view, request)
}
}

View File

@ -174,6 +174,39 @@ fun WebReaderLoadingContainer(slug: String? = null, requestID: String? = null,
}
} ?: Color(0xFF000000)
when (bottomSheetState) {
BottomSheetState.PREFERENCES -> {
coroutineScope.launch {
modalBottomSheetState.animateTo(ModalBottomSheetValue.HalfExpanded)
}
}
BottomSheetState.NOTEBOOK -> {
coroutineScope.launch {
modalBottomSheetState.animateTo(ModalBottomSheetValue.Expanded)
}
}
BottomSheetState.HIGHLIGHTNOTE -> {
coroutineScope.launch {
modalBottomSheetState.animateTo(ModalBottomSheetValue.Expanded)
}
}
BottomSheetState.LABELS -> {
coroutineScope.launch {
modalBottomSheetState.animateTo(ModalBottomSheetValue.HalfExpanded)
}
}
BottomSheetState.NONE -> {
coroutineScope.launch {
modalBottomSheetState.hide()
}
}
else -> {
coroutineScope.launch {
modalBottomSheetState.hide()
}
}
}
ModalBottomSheetLayout(
modifier = Modifier
.statusBarsPadding(),

View File

@ -1,5 +1,6 @@
package app.omnivore.omnivore.ui.reader
import android.net.Uri
import android.util.Log
import androidx.compose.foundation.ScrollState
import androidx.compose.material.ModalBottomSheetValue
@ -24,6 +25,7 @@ import com.google.gson.Gson
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.distinctUntilChanged
import java.net.URI
import java.util.*
import javax.inject.Inject
@ -62,7 +64,6 @@ class WebReaderViewModel @Inject constructor(
val shouldPopViewLiveData = MutableLiveData(false)
val hasFetchError = MutableLiveData(false)
val currentToolbarHeightLiveData = MutableLiveData(0.0f)
val showLabelsSelectionSheetLiveData = MutableLiveData(false)
val savedItemLabelsLiveData = dataService.db.savedItemLabelDao().getSavedItemLabelsLiveData()
val bottomSheetStateLiveData = MutableLiveData<BottomSheetState>(BottomSheetState.NONE)
@ -96,6 +97,10 @@ class WebReaderViewModel @Inject constructor(
bottomSheetStateLiveData.postValue(BottomSheetState.NONE)
}
fun showOpenLinkSheet(uri: Uri) {
bottomSheetStateLiveData.postValue(BottomSheetState.LABELS)
}
fun onScrollChange(delta: Float) {
val newHeight = (currentToolbarHeightLiveData.value ?: 0.0f) + delta
currentToolbarHeightLiveData.value = newHeight.coerceIn(0f, maxToolbarHeightPx)
@ -195,7 +200,6 @@ class WebReaderViewModel @Inject constructor(
}
}
SavedItemAction.EditLabels -> {
showLabelsSelectionSheetLiveData.value = true
bottomSheetStateLiveData.postValue(BottomSheetState.LABELS)
}
}

View File

@ -24,19 +24,19 @@ fun SavedItemContextMenu(
expanded = isExpanded,
onDismissRequest = onDismiss
) {
// DropdownMenuItem(
// text = { Text("Edit Labels") },
// onClick = {
// actionHandler(SavedItemAction.EditLabels)
// onDismiss()
// },
// leadingIcon = {
// Icon(
// painter = painterResource(id = R.drawable.tag),
// contentDescription = null
// )
// }
// )
DropdownMenuItem(
text = { Text("Edit Labels") },
onClick = {
actionHandler(SavedItemAction.EditLabels)
onDismiss()
},
leadingIcon = {
Icon(
painter = painterResource(id = R.drawable.tag),
contentDescription = null
)
}
)
DropdownMenuItem(
text = { Text(if (isArchived) "Unarchive" else "Archive") },
onClick = {