From 707245562e30ebef47270b23963ca0000b27d62d Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 30 May 2023 22:08:29 +0800 Subject: [PATCH] Work on PDF notes --- android/Omnivore/app/build.gradle | 4 +- .../omnivore/ui/notebook/NotebookView.kt | 3 +- .../omnivore/ui/reader/AnnotationEditView.kt | 179 ++++-------------- .../main/res/layout/pdf_reader_fragment.xml | 2 +- 4 files changed, 36 insertions(+), 152 deletions(-) diff --git a/android/Omnivore/app/build.gradle b/android/Omnivore/app/build.gradle index 4d05dc295..1e52cc6b1 100644 --- a/android/Omnivore/app/build.gradle +++ b/android/Omnivore/app/build.gradle @@ -17,8 +17,8 @@ android { applicationId "app.omnivore.omnivore" minSdk 26 targetSdk 33 - versionCode 80 - versionName "0.0.80" + versionCode 82 + versionName "0.0.82" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/notebook/NotebookView.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/notebook/NotebookView.kt index e2c0155a6..45a7f3aa4 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/notebook/NotebookView.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/notebook/NotebookView.kt @@ -184,7 +184,6 @@ fun EditNoteModal(initialValue: String?, onDismiss: (save: Boolean, text: String colors = TextFieldDefaults.textFieldColors( textColor = Color.White ) - ) } } @@ -381,7 +380,7 @@ fun BottomSheetUI(content: @Composable () -> Unit) { .wrapContentHeight() .fillMaxWidth() .clip(RoundedCornerShape(topEnd = 20.dp, topStart = 20.dp)) - .background(Color.White) + .background(Color.Transparent) .statusBarsPadding() ) { Scaffold( diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/AnnotationEditView.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/AnnotationEditView.kt index 7bcd2989b..97abd9781 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/AnnotationEditView.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/AnnotationEditView.kt @@ -1,41 +1,30 @@ package app.omnivore.omnivore.ui.reader -import android.content.ClipData +import android.R import android.content.DialogInterface import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.compose.foundation.background +import android.view.WindowManager import androidx.compose.foundation.layout.* -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack -import androidx.compose.material.icons.filled.MoreVert import androidx.compose.material3.* -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.focus.FocusRequester -import androidx.compose.ui.focus.focusRequester -import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy -import androidx.compose.ui.unit.dp import androidx.fragment.app.DialogFragment -import app.omnivore.omnivore.ui.notebook.ArticleNotes -import app.omnivore.omnivore.ui.notebook.HighlightsList -import app.omnivore.omnivore.ui.notebook.notebookMD +import app.omnivore.omnivore.ui.notebook.EditNoteModal import app.omnivore.omnivore.ui.theme.OmnivoreTheme +import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED +import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment -import kotlinx.coroutines.launch -class AnnotationEditFragment : BottomSheetDialogFragment() { + +class AnnotationEditFragment : DialogFragment() { private var onSave: (String) -> Unit = {} private var onCancel: () -> Unit = {} private var initialAnnotation: String = "" @@ -50,24 +39,38 @@ class AnnotationEditFragment : BottomSheetDialogFragment() { this.onCancel = onCancel } + @OptIn(ExperimentalMaterial3Api::class) override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { + return ComposeView(requireContext()).apply { - // Dispose of the Composition when the view's LifecycleOwner - // is destroyed - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) + + (dialog as? BottomSheetDialog)?.let { + it.behavior.skipCollapsed = true + it.behavior.state = STATE_EXPANDED + } + + dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) + + + + setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { - OmnivoreTheme { - AnnotationEditView( - initialAnnotation, - onSave, - onCancel, - // dismissAction = { dismiss() } - ) - } + val annotation = remember { mutableStateOf(initialAnnotation ?: "") } + + OmnivoreTheme { + EditNoteModal(initialValue = initialAnnotation, onDismiss = { save, text -> + if (save) { + onSave(text ?: "") + } else { + onCancel() + } + dismissNow() + }) + } } } } @@ -77,121 +80,3 @@ class AnnotationEditFragment : BottomSheetDialogFragment() { super.onDismiss(dialog) } } - -@OptIn(ExperimentalMaterial3Api::class) -@Composable -fun AnnotationEditView( - initialAnnotation: String, - onSave: (String) -> Unit, - onCancel: () -> Unit, -) { - val annotation = remember { mutableStateOf(initialAnnotation) } - val focusRequester = FocusRequester() - - Scaffold( - topBar = { - TopAppBar( - title = { Text("Notebook") }, - colors = TopAppBarDefaults.topAppBarColors( - containerColor = MaterialTheme.colorScheme.background - ), - navigationIcon = { - IconButton(onClick = { - onCancel() - }) { - Icon( - imageVector = Icons.Filled.ArrowBack, - modifier = Modifier, - contentDescription = "Back", - ) - } - }, - actions = { - TextButton( - onClick = { - onSave(annotation.value) - } - ) { - Text("Save") - } - } - ) - } - ) { paddingValues -> - Column( - modifier = Modifier - .padding(paddingValues) - .fillMaxSize() - ) { - TextField( - value = annotation.value, - onValueChange = { annotation.value = it }, - colors = TextFieldDefaults.textFieldColors( - textColor = Color.White, - containerColor = Color.Green, - ), - modifier = Modifier - .focusRequester(focusRequester) - .fillMaxSize() - ) - } - } -} -// -// Column( -// modifier = Modifier.padding(16.dp), -// horizontalAlignment = Alignment.CenterHorizontally, -// ) { -// Row { -// TextButton( -// onClick = { -// onCancel() -// dismissAction() -// } -// ) { -// Text("Cancel") -// } -// -// Spacer(modifier = Modifier.weight(1.0F)) -// -// Text(text = "Note") -// -// Spacer(modifier = Modifier.weight(1.0F)) -// -// TextButton( -// onClick = { -// onSave(annotation.value) -// dismissAction() -// } -// ) { -// Text("Save") -// } -// } -// -// Spacer(modifier = Modifier.height(8.dp)) -// -// -// -// Spacer(modifier = Modifier.height(16.dp)) - -// -// LaunchedEffect(Unit) { -// focusRequester.requestFocus() -// } - -// Row { -// Spacer(modifier = Modifier.weight(0.1F)) -// TextField( -// value = annotation.value, -// onValueChange = { annotation.value = it }, -// modifier = Modifier -// .width(IntrinsicSize.Max) -// .height(IntrinsicSize.Max) -// .weight(1.0F) -// ) -// Spacer(modifier = Modifier.weight(0.1F)) -// } -// } -// -// // } -//} diff --git a/android/Omnivore/app/src/main/res/layout/pdf_reader_fragment.xml b/android/Omnivore/app/src/main/res/layout/pdf_reader_fragment.xml index 401e22ae8..2cf240f6f 100644 --- a/android/Omnivore/app/src/main/res/layout/pdf_reader_fragment.xml +++ b/android/Omnivore/app/src/main/res/layout/pdf_reader_fragment.xml @@ -7,7 +7,7 @@ + android:layout_height="match_parent" />