소스 검색

阅读Moudle

hubowen 2 년 전
부모
커밋
0f44444dc3

+ 1 - 1
app/build.gradle

@@ -8,7 +8,7 @@ android {
     buildToolsVersion rootProject.ext.buildToolsVersion
 
     defaultConfig {
-        applicationId "com.common.android.lib"
+        applicationId "com.convenient.android.lib"
         minSdkVersion rootProject.ext.minSdkVersion
         targetSdkVersion rootProject.ext.targetSdkVersion
         versionCode rootProject.ext.versionCode

+ 6 - 12
app/src/main/java/com/convenient/android/lib/MainActivity.kt

@@ -25,6 +25,7 @@ import com.convenient.android.common.extension.readyGo
 import com.convenient.android.lib.ui.sample.ad.AdMainActivity
 import com.convenient.android.lib.ui.sample.media.MediaSampleActivity
 import com.convenient.android.lib.ui.sample.read.ReaderActivity
+import com.convenient.android.lib.ui.sample.read.annotation.BottomItem
 import com.convenient.android.lib.ui.theme.SampleTheme
 
 class MainActivity : ComponentActivity() {
@@ -57,12 +58,11 @@ private fun MainPage() {
         }, colors = TopAppBarDefaults.smallTopAppBarColors(
             containerColor = MaterialTheme.colorScheme.primary.copy(alpha = .1F)
         ))
-        Scaffold(
-            bottomBar = {
-                BottomBarView(selectedPosition = bottomSelectedState, onItemSelected = {
-                    bottomSelectedState = it
-                })
-            }) {
+        Scaffold(bottomBar = {
+            BottomBarView(selectedPosition = bottomSelectedState, onItemSelected = {
+                bottomSelectedState = it
+            })
+        }) {
             when (bottomSelectedState) {
                 0 -> FuncListView()
                 1 -> ReaderView()
@@ -74,7 +74,6 @@ private fun MainPage() {
             }
         }
     }
-
 }
 
 data class FuncBean(
@@ -130,11 +129,6 @@ private fun ReaderView() {
     }
 }
 
-data class BottomItem(
-    val title: String,
-    val icon: ImageVector,
-)
-
 @Composable
 private fun BottomBarView(selectedPosition: Int, onItemSelected: (position: Int) -> Unit) {
     val itemList = arrayListOf(

+ 108 - 37
app/src/main/java/com/convenient/android/lib/ui/sample/read/ReaderActivity.kt

@@ -7,31 +7,39 @@ import androidx.activity.ComponentActivity
 import androidx.activity.compose.rememberLauncherForActivityResult
 import androidx.activity.compose.setContent
 import androidx.activity.result.contract.ActivityResultContracts
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.*
+import androidx.compose.material.*
 import androidx.compose.material.Text
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Add
+import androidx.compose.material.icons.filled.Settings
 import androidx.compose.material3.*
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.remember
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.runtime.*
+import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.platform.LocalContext
-import androidx.compose.ui.unit.dp
+import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.viewinterop.AndroidView
 import androidx.lifecycle.LifecycleCoroutineScope
 import androidx.lifecycle.lifecycleScope
 import com.compdfkit.core.document.CPDFDocument
-import com.compdfkit.core.document.CPDFSdk
-import com.compdfkit.ui.reader.ReaderView
+import com.compdfkit.ui.reader.CPDFReaderView
+import com.compdfkit.ui.reader.IReaderViewCallback
+import com.convenient.android.common.utils.ToastUtil
+import com.convenient.android.lib.ui.sample.read.setting.BottomSettingView
 import com.convenient.android.lib.ui.theme.SampleTheme
 import com.pdf.base.function.onVerifyDocument
+import kotlinx.coroutines.launch
 
 /**
  * @author: hubowen
  * @date: 2022/9/20
  * @description:
  */
+var readerView: CPDFReaderView? = null
+
 class ReaderActivity : ComponentActivity() {
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -40,48 +48,111 @@ class ReaderActivity : ComponentActivity() {
                 readerPage(lifecycleScope)
             }
         }
-        Log.e("AAAA", "${CPDFSdk.getSDKInitialResult()}")
     }
 }
 
-@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
-@OptIn(ExperimentalMaterial3Api::class)
+@Preview(showSystemUi = true)
 @Composable
-fun readerPage(life: LifecycleCoroutineScope) {
+fun MainPagePreview() {
+    SampleTheme {
+        readerPage(null)
+    }
+}
+
+@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class)
+@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter", "CoroutineCreationDuringComposition")
+@Composable
+fun readerPage(life: LifecycleCoroutineScope?) {
     val context = LocalContext.current
 
-    val currentDocument = remember { mutableStateOf<CPDFDocument?>(null) }
+    val coroutineScope = rememberCoroutineScope()
+
+    var currentDocument by remember { mutableStateOf<CPDFDocument?>(null) }
 
     val choosePDFFileLauncher = rememberLauncherForActivityResult(contract = ActivityResultContracts.OpenMultipleDocuments(), onResult = {
         //第一个文件
-        it[0].apply {
-            life.onVerifyDocument(context, this, "", "", { document ->
-                currentDocument.value = document
-            }, {
-                Log.e("AAAA", "初始化失败")
-            })
+        when (it.isNotEmpty()) {
+            true -> it[0].apply {
+                life?.onVerifyDocument(context, this, "", "", { document ->
+                    currentDocument = document
+                }, {
+                    Log.e("AAAA", "初始化失败")
+                })
+            }
+            else -> ToastUtil.showToast(context, "初始化失败")
         }
     })
 
-    Column {
-        SmallTopAppBar(title = {
-            Text(text = "ReadView", style = MaterialTheme.typography.titleMedium)
-        }, colors = TopAppBarDefaults.smallTopAppBarColors(
-            containerColor = MaterialTheme.colorScheme.primary.copy(alpha = .1F)
-        ))
-
-        ElevatedButton(modifier = Modifier
-            .fillMaxWidth()
-            .padding(horizontal = 16.dp), onClick = {
-            choosePDFFileLauncher.launch(arrayOf("*/*"))
+    val sheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)
+    ModalBottomSheetLayout(
+        modifier = Modifier.fillMaxSize(),
+        sheetState = sheetState,
+        sheetContent = {
+            BottomSettingView()
         }) {
-            Text(text = "选择文件")
-        }
+        Column {
+            Scaffold(
+                modifier = Modifier.fillMaxSize(),
+                topBar = {
+                    SmallTopAppBar(
+                        title = {
+                            Text(text = "ReadView", style = androidx.compose.material3.MaterialTheme.typography.titleMedium)
+                        },
+                        colors = TopAppBarDefaults.smallTopAppBarColors(
+                            containerColor = androidx.compose.material3.MaterialTheme.colorScheme.primary.copy(alpha = .1F)
+                        ),
+                        actions = {
+                            IconButton(onClick = {
+                                coroutineScope.launch {
+                                    sheetState.show()
+                                }
+                            }) {
+                                Icon(Icons.Filled.Settings, null)
+                            }
+                            IconButton(onClick = {
+                                choosePDFFileLauncher.launch(arrayOf("*/*"))
+                            }) {
+                                Icon(Icons.Filled.Add, null)
+                            }
+                        }
+                    )
+                }
+            ) {
+                Column(modifier = Modifier
+                    .fillMaxWidth()
+                    .wrapContentHeight(Alignment.CenterVertically)) {
+                    //ReaderView展示位置
+                    AndroidView(factory = { context ->
+                        CPDFReaderView(context).apply {
+                            readerView = this
+                            //监听设置
+                            setReaderViewCallback(object : IReaderViewCallback {
+                                override fun onTapMainDocArea() {
+                                    Log.e("AAAA", "onTapMainDocArea")
+                                }
+
+                                override fun onMoveToChild(p0: Int) {
+                                }
 
-        AndroidView(factory = { context ->
-            ReaderView(context).apply {
-                pdfDocument = currentDocument.value
+                                override fun onEndScroll() {
+                                }
+
+                                override fun onScrolling() {
+                                }
+
+                                override fun onRecordLastJumpPageNum(p0: Int) {
+                                    Log.e("AAAA", "onRecordLastJumpPageNum")
+                                }
+                            })
+                        }
+                    }, update = { readerView ->
+                        readerView.pdfDocument = currentDocument
+                        readerView.reloadPages()
+                    }, modifier = Modifier
+                        .fillMaxWidth()
+                        .fillMaxHeight())
+                }
             }
-        })
+        }
     }
 }

+ 2 - 0
app/src/main/java/com/convenient/android/lib/ui/sample/read/ReaderViewActivity.kt

@@ -20,5 +20,7 @@ class ReaderViewActivity : BaseBindingActivity<ActivityReaderViewBinding>(Activi
         }, {
             Log.e("AAAA", "error")
         })
+
+        readerView
     }
 }

+ 52 - 0
app/src/main/java/com/convenient/android/lib/ui/sample/read/annotation/AnnotationItem.kt

@@ -0,0 +1,52 @@
+package com.convenient.android.lib.ui.sample.read.annotation
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.vector.ImageVector
+
+/**
+ * @author: hubowen
+ * @date: 2022/9/29
+ * @description:
+ */
+
+data class BottomItem(
+    val title: String,
+    val icon: ImageVector,
+)
+
+@Composable
+fun AnnotationItem(
+    imageId: ImageVector,
+    annotationName: String,
+    onClick: () -> Unit,
+    modifier: Modifier = Modifier,
+) {
+    Column(
+        modifier = modifier,
+        horizontalAlignment = Alignment.CenterHorizontally
+    ) {
+        Text(text = annotationName)
+//        ProfilePicture(
+//            imageId = profileImageId,
+//            contentDescription = null,
+//            size = ProfileSizes.large,
+//            modifier = Modifier
+//                .border(
+//                    shape = CircleShape,
+//                    border = BorderStroke(width = 3.dp, brush = borderColor)
+//                )
+//                .clickable(
+//                    interactionSource = interactionSource,
+//                    indication = rememberRipple(bounded = false, radius = ProfileSizes.large / 2),
+//                    enabled = true,
+//                    onClickLabel = null,
+//                    onClick = onClick
+//                )
+//        )
+//        Text(text = profileName, style = textStyle, textAlign = TextAlign.Center, onClick = onClick.invoke())
+    }
+}

+ 57 - 0
app/src/main/java/com/convenient/android/lib/ui/sample/read/annotation/AnnotationList.kt

@@ -0,0 +1,57 @@
+package com.convenient.android.lib.ui.sample.read.annotation
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.lazy.LazyRow
+import androidx.compose.foundation.lazy.items
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.AddCircle
+import androidx.compose.material.icons.filled.Edit
+import androidx.compose.material.icons.filled.List
+import androidx.compose.material.icons.filled.Settings
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
+
+/**
+ * @author: hubowen
+ * @date: 2022/9/29
+ * @description:
+ */
+
+val annotationItemList = arrayListOf(
+    BottomItem(title = "注释", Icons.Filled.List),
+    BottomItem(title = "背景", Icons.Filled.AddCircle),
+    BottomItem(title = "编辑", Icons.Filled.Edit),
+    BottomItem(title = "设置", Icons.Filled.Settings),
+    BottomItem(title = "注释", Icons.Filled.List),
+    BottomItem(title = "背景", Icons.Filled.AddCircle),
+    BottomItem(title = "编辑", Icons.Filled.Edit),
+    BottomItem(title = "设置", Icons.Filled.Settings),
+    BottomItem(title = "注释", Icons.Filled.List),
+    BottomItem(title = "背景", Icons.Filled.AddCircle),
+    BottomItem(title = "编辑", Icons.Filled.Edit),
+    BottomItem(title = "设置", Icons.Filled.Settings)
+)
+
+@Composable
+fun AnnotationList(
+    annotationList: List<BottomItem>,
+    onClicked: () -> Unit,
+    modifier: Modifier = Modifier,
+) {
+    LazyRow(
+        modifier = modifier.padding(top = 8.dp, bottom = 8.dp),
+        horizontalArrangement = Arrangement.spacedBy(8.dp),
+        contentPadding = PaddingValues(horizontal = 8.dp)
+    ) {
+        items(annotationList) {
+            AnnotationItem(
+                imageId = it.icon,
+                annotationName = it.title,
+                onClick = onClicked
+            )
+        }
+    }
+}

+ 14 - 0
app/src/main/java/com/convenient/android/lib/ui/sample/read/data/ReaderData.kt

@@ -0,0 +1,14 @@
+package com.convenient.android.lib.ui.sample.read.data
+
+/**
+ * @author: hubowen
+ * @date: 2022/9/29
+ * @description:
+ */
+
+enum class ReaderMode(val mode: Int) {
+    VERTICAL_CONTINUE(0),
+    VERTICAL_N_CONTINUE(1),
+    HORIZONTAL_CONTINUE(2),
+    HORIZONTAL_N_CONTINUE(3)
+}

+ 155 - 0
app/src/main/java/com/convenient/android/lib/ui/sample/read/setting/SettingView.kt

@@ -0,0 +1,155 @@
+package com.convenient.android.lib.ui.sample.read.setting
+
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.layout.*
+import androidx.compose.material.Divider
+import androidx.compose.material.RadioButton
+import androidx.compose.material.Switch
+import androidx.compose.material.Text
+import androidx.compose.runtime.*
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
+import com.convenient.android.lib.ui.sample.read.data.ReaderMode
+import com.convenient.android.lib.ui.sample.read.readerView
+import com.pdf.base.function.annotationDeleteAll
+import kotlinx.coroutines.launch
+
+/**
+ * @author: hubowen
+ * @date: 2022/9/29
+ * @description:
+ */
+@Composable
+fun BottomSettingView() {
+    var readerModeRemember by remember { mutableStateOf(ReaderMode.VERTICAL_CONTINUE.mode) }
+    var readerSinglePageRemember by remember { mutableStateOf(true) }
+    var readerClipRemember by remember { mutableStateOf(true) }
+    var readerVisiblePageRemember by remember { mutableStateOf(true) }
+    var readerAnnotationDeleteAllRemember by remember { mutableStateOf(false) }
+
+    Column(modifier = Modifier.fillMaxSize()) {
+        Row(modifier = Modifier
+            .fillMaxWidth()
+            .padding(10.dp, 5.dp, 10.dp, 5.dp),
+            horizontalArrangement = Arrangement.SpaceBetween,
+            verticalAlignment = Alignment.CenterVertically
+        ) {
+            RadioButton(modifier = Modifier.width(15.dp), selected = readerModeRemember == ReaderMode.VERTICAL_CONTINUE.mode, onClick = { readerModeRemember = ReaderMode.VERTICAL_CONTINUE.mode })
+            Text(
+                text = "垂直连续",
+                modifier = Modifier
+                    .clickable(onClick = { readerModeRemember = ReaderMode.VERTICAL_CONTINUE.mode })
+            )
+            RadioButton(modifier = Modifier.width(15.dp), selected = readerModeRemember == ReaderMode.VERTICAL_N_CONTINUE.mode, onClick = { readerModeRemember = ReaderMode.VERTICAL_N_CONTINUE.mode })
+            Text(
+                text = "垂直不连续",
+                modifier = Modifier
+                    .clickable(onClick = { readerModeRemember = ReaderMode.VERTICAL_N_CONTINUE.mode })
+            )
+        }
+        Row(modifier = Modifier
+            .fillMaxWidth()
+            .padding(10.dp, 5.dp, 10.dp, 5.dp),
+            horizontalArrangement = Arrangement.SpaceBetween,
+            verticalAlignment = Alignment.CenterVertically) {
+            RadioButton(modifier = Modifier.width(15.dp), selected = readerModeRemember == ReaderMode.HORIZONTAL_CONTINUE.mode, onClick = { readerModeRemember = ReaderMode.HORIZONTAL_CONTINUE.mode })
+            Text(
+                text = "水平连续",
+                modifier = Modifier
+                    .clickable(onClick = { readerModeRemember = ReaderMode.HORIZONTAL_CONTINUE.mode })
+            )
+            RadioButton(modifier = Modifier.width(15.dp), selected = readerModeRemember == ReaderMode.HORIZONTAL_N_CONTINUE.mode, onClick = { readerModeRemember = ReaderMode.HORIZONTAL_N_CONTINUE.mode })
+            Text(
+                text = "水平不连续",
+                modifier = Modifier
+                    .clickable(onClick = { readerModeRemember = ReaderMode.HORIZONTAL_N_CONTINUE.mode })
+            )
+        }
+        Divider()
+        Row(modifier = Modifier
+            .fillMaxWidth()
+            .padding(10.dp, 5.dp, 10.dp, 5.dp),
+            horizontalArrangement = Arrangement.SpaceBetween,
+            verticalAlignment = Alignment.CenterVertically
+        ) {
+            Text(text = "单页模式")
+            Switch(checked = readerSinglePageRemember, onCheckedChange = {
+                readerSinglePageRemember = it
+            })
+        }
+        Divider()
+        Row(modifier = Modifier
+            .fillMaxWidth()
+            .padding(10.dp, 5.dp, 10.dp, 5.dp),
+            horizontalArrangement = Arrangement.SpaceBetween,
+            verticalAlignment = Alignment.CenterVertically
+        ) {
+            Text(text = "裁剪模式")
+            Switch(checked = readerClipRemember, onCheckedChange = {
+                readerClipRemember = it
+            })
+        }
+        Divider()
+        Row(modifier = Modifier
+            .fillMaxWidth()
+            .padding(10.dp, 5.dp, 10.dp, 5.dp),
+            horizontalArrangement = Arrangement.SpaceBetween,
+            verticalAlignment = Alignment.CenterVertically) {
+            Text(text = "页码显示")
+            Switch(checked = readerVisiblePageRemember, onCheckedChange = {
+                readerVisiblePageRemember = it
+            })
+        }
+        Divider()
+        Row(modifier = Modifier
+            .clickable(onClick = {
+                //删除所有注释
+                readerAnnotationDeleteAllRemember = !readerAnnotationDeleteAllRemember
+            })
+            .fillMaxWidth()
+            .height(50.dp)
+            .padding(10.dp, 5.dp, 10.dp, 5.dp),
+            horizontalArrangement = Arrangement.SpaceBetween,
+            verticalAlignment = Alignment.CenterVertically) {
+            Text(text = "删除所有注释")
+        }
+        //界面更改
+        readerView?.apply {
+            //阅读模式
+            when (readerModeRemember) {
+                ReaderMode.VERTICAL_CONTINUE.mode -> {
+                    isContinueMode = true
+                    isVerticalMode = true
+                }
+                ReaderMode.VERTICAL_N_CONTINUE.mode -> {
+                    isContinueMode = false
+                    isVerticalMode = true
+                }
+                ReaderMode.HORIZONTAL_CONTINUE.mode -> {
+                    isContinueMode = true
+                    isVerticalMode = false
+                }
+                ReaderMode.HORIZONTAL_N_CONTINUE.mode -> {
+                    isContinueMode = false
+                    isVerticalMode = false
+                }
+            }
+            //单页模式
+            isDoublePageMode = !readerSinglePageRemember
+            //裁剪模式
+            isCropMode = readerClipRemember
+        }
+        //删除所有注释
+        LaunchedEffect(readerAnnotationDeleteAllRemember) {
+            readerView?.apply {
+                pdfDocument?.annotationDeleteAll(onSuccess = {
+                    launch {
+                        //重新加载阅读界面
+                        if (it) reloadPages()
+                    }
+                })
+            }
+        }
+    }
+}

+ 5 - 2
app/src/main/res/layout/activity_reader_view.xml

@@ -1,13 +1,16 @@
 <?xml version="1.0" encoding="utf-8"?>
 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
 
     <com.compdfkit.ui.reader.CPDFReaderView
         android:id="@+id/id_reader_view"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
+        android:layout_height="300dp"
+        android:background="@color/black"
         android:focusable="true"
-        android:focusableInTouchMode="true" />
+        android:focusableInTouchMode="true"
+        app:layout_constraintTop_toBottomOf="parent" />
 
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 2 - 11
lib_pdf_base/src/main/AndroidManifest.xml

@@ -11,18 +11,9 @@
 
         <meta-data
             android:name="compdfkit_license"
-            android:value="jPM7/vfGVzP6qe4Wsxi9iRgZqIWJiBVomLgEyS+zM95lI2/LOWnBNM2B0V67Scnjf7nQm0KwqGhYAIHyr6VqWV731SzclTdkf6oB/jTfDeu6eHCUvcuGpjQnR856+mOeNawvXywBL/J0gNsmNlCT0o+JgfUNgqo4Zqa8woVZFuI=" />
+            android:value="pcOv67+7pqQzQZxshNAxbzQDlEn87rEBVI62psMMit+SHIvbCRtzIX4pTkkSTJQf+RXzm9DPrHBwLeyNDxEPcse3g4Yi8h1Xvl69bJ51iNnIVq19OESB+hKVPOlA2B/HjsEXl0LG6cf77iiEYnctAPSultXsF3yIBbTCXUb1yuo=" />
         <meta-data
             android:name="compdfkit_message"
-            android:value="mG0c3O3Mzeu5dkZJW3gpqotjgd+APU/4fMqIHQR4gdyvEHOmPIqbfhpDnKKj+7Ymj2rXQvfZRmke06HMV+3ttymszjpHdHxcF5YmSifbf+5hrp9sGpqfp0B228KI+IMTu4aGVjtYuk+Uxs/kosIBw1367/WkJ00tM7U7tttD6ccsvUiEnSpVC16x66CLYBR9Fjaev9srLHuFRmzAirXc1cVkDFxAGA3yaUD+S0mJwb3KM9XYTDYZ7Fbvrr2FSc2xQWj4WloROV3ABWxNU2bvuirbFFG14BCYiJmX+m1Ywrw=" />
-
-<!--        <meta-data-->
-<!--            android:name="compdfkit_license"-->
-<!--            android:value="pcOv67+7pqQzQZxshNAxbzQDlEn87rEBVI62psMMit+SHIvbCRtzIX4pTkkSTJQf+RXzm9DPrHBwLeyNDxEPcse3g4Yi8h1Xvl69bJ51iNnIVq19OESB+hKVPOlA2B/HjsEXl0LG6cf77iiEYnctAPSultXsF3yIBbTCXUb1yuo=" />-->
-<!--        <meta-data-->
-<!--            android:name="compdfkit_message"-->
-<!--            android:value="mG0c3O3Mzeu5dkZJW3gpqotjgd+APU/4fMqIHQR4gdz+30z7ZrkvRPNQzEZUYMfC/KpHF3vBDdXvniWHS5jZ1rB1MM7QuAecUmPxrlGlxm1hrp9sGpqfp0B228KI+IMTu4aGVjtYuk+Uxs/kosIBw1367/WkJ00tM7U7tttD6ccsvUiEnSpVC16x66CLYBR9R5wJulZG/lqZ+yY8RJ76kVojFdYAgEDr28thJZUNadxZXaMnP54N8XjGkv3pQv6HmKA5CPfJSxMUgz0GlzJk/w==" />-->
-
+            android:value="mG0c3O3Mzeu5dkZJW3gpqotjgd+APU/4fMqIHQR4gdz+30z7ZrkvRPNQzEZUYMfC/KpHF3vBDdXvniWHS5jZ1rB1MM7QuAecUmPxrlGlxm1hrp9sGpqfp0B228KI+IMTu4aGVjtYuk+Uxs/kosIBw1367/WkJ00tM7U7tttD6ccsvUiEnSpVC16x66CLYBR9R5wJulZG/lqZ+yY8RJ76kVojFdYAgEDr28thJZUNadxZXaMnP54N8XjGkv3pQv6HmKA5CPfJSxMUgz0GlzJk/w==" />
     </application>
-
 </manifest>

+ 28 - 1
lib_pdf_base/src/main/java/com/pdf/base/function/AnnotationFunction.kt

@@ -1,9 +1,36 @@
 package com.pdf.base.function
 
+import android.util.Log
+import com.compdfkit.core.document.CPDFDocument
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+
 /**
  * @author: hubowen
  * @date: 2022/9/20
  * @description:
  */
-class AnnotationFunction {
+
+/**
+ * 删除所有注释
+ */
+suspend fun CPDFDocument.annotationDeleteAll(onPre: (() -> Unit)? = null, onSuccess: ((Boolean) -> Unit)? = null, onComplete: (() -> Unit)? = null) {
+    withContext(Dispatchers.Main) {
+        onPre?.invoke()
+        withContext(Dispatchers.IO) {
+            runCatching {
+                //删除所有注释
+                removeAllAnnotations()
+                //保存Document
+                onSaveDocument()
+            }.onFailure {
+                Log.e("pdf_base", "delete_all_annotation_failed")
+                onSuccess?.invoke(false)
+            }.onSuccess {
+                Log.e("pdf_base", "delete_all_annotation_success")
+                onSuccess?.invoke(true)
+            }
+        }
+        onComplete?.invoke()
+    }
 }

+ 83 - 0
lib_pdf_base/src/main/java/com/pdf/base/function/EditFunction.kt

@@ -0,0 +1,83 @@
+package com.pdf.base.function
+
+import com.compdfkit.core.document.CPDFDocument
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+
+/**
+ * @author: hubowen
+ * @date: 2022/10/9
+ * @description:
+ */
+
+/**
+ * 页面旋转
+ * CPDFDocument 页面翻转 array -> 页面的Num
+ */
+suspend fun CPDFDocument.pageRotate(array: IntArray, onPre: (() -> Unit)? = null, onSuccess: ((Boolean) -> Unit)? = null, onComplete: (() -> Unit)? = null) {
+    var rotateSuccess = false
+    withContext(Dispatchers.Main) {
+        onPre?.invoke()
+        withContext(Dispatchers.IO) {
+            runCatching {
+                array.map { index ->
+                    pageAtIndex(index)?.apply {
+                        rotateSuccess = setRotation(this.rotation + 90)
+                        //如果有翻转失败就暂停
+                        if (!rotateSuccess) return@map
+                    }
+                }
+            }.onFailure {
+                onSuccess?.invoke(false)
+            }.onSuccess {
+                onSuccess?.invoke(rotateSuccess)
+            }
+        }
+        onComplete?.invoke()
+    }
+}
+
+/**
+ * 页面裁剪
+ * CPDFDocument 页面裁剪 array -> 页面的Num
+ */
+suspend fun CPDFDocument.pageSplit(array: IntArray, onPre: (() -> Unit)? = null, onSuccess: ((Boolean) -> Unit)? = null, onComplete: (() -> Unit)? = null) {
+    withContext(Dispatchers.Main) {
+        onPre?.invoke()
+        withContext(Dispatchers.IO) {
+            runCatching {
+                CPDFDocument.createDocument(context).apply {
+                    importPages(this@pageSplit, array, 0).also {
+
+                    }
+                }
+            }.onFailure {
+                onSuccess?.invoke(false)
+            }.onSuccess {
+                onSuccess?.invoke(true)
+            }
+        }
+        onComplete?.invoke()
+    }
+}
+
+/**
+ * 页面删除
+ * CPDFDocument 页面删除 array -> 页面的Num
+ */
+suspend fun CPDFDocument.pageDelete(array: IntArray, onPre: (() -> Unit)? = null, onSuccess: ((Boolean) -> Unit)? = null, onComplete: (() -> Unit)? = null) {
+    var deleteSuccess = false
+    withContext(Dispatchers.Main) {
+        onPre?.invoke()
+        withContext(Dispatchers.IO) {
+            runCatching {
+                deleteSuccess = removePages(array)
+            }.onFailure {
+                onSuccess?.invoke(false)
+            }.onSuccess {
+                onSuccess?.invoke(deleteSuccess)
+            }
+        }
+        onComplete?.invoke()
+    }
+}

+ 39 - 1
lib_pdf_base/src/main/java/com/pdf/base/function/LogicFunction.kt

@@ -107,4 +107,42 @@ suspend fun Context.toCPDFDocument(uri: Uri?, absolutePath: String?, password: S
     }.onFailure {
         onError?.invoke()
     }
-}
+}
+
+/**
+ * 保存Document 这里有一个逻辑,先增量保存如果失败则进行全量保存。
+ */
+suspend fun CPDFDocument.onSaveDocument(isNeedClose: Boolean = false, onPre: (() -> Unit)? = null, onSuccess: ((Boolean) -> Unit)? = null, onComplete: (() -> Unit)? = null) {
+    var isSaveSuccess: Boolean
+    withContext(Dispatchers.Main) {
+        onPre?.invoke()
+        withContext(Dispatchers.IO) {
+            runCatching {
+                if (hasChanges()) {
+                    //增量保存
+                    isSaveSuccess = save()
+                    //全量保存
+                    if (!isSaveSuccess) isSaveSuccess = save(CPDFDocument.PDFDocumentSaveType.PDFDocumentSaveNoIncremental)
+                }
+            }.onFailure {
+                Log.e("pdf_base", "save_failed")
+                onSuccess?.invoke(false)
+            }.onSuccess {
+                Log.e("pdf_base", "save_success")
+                onSuccess?.invoke(true)
+            }
+        }
+        //关闭文档
+        if (isNeedClose) close()
+        onComplete?.invoke()
+    }
+
+}
+
+/**
+ * 另存PDF文件
+ */
+
+/**
+ * 保存Flattened副本
+ */