Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
PDF Viewer Scanner White ago
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kuxulei
PDF Viewer Scanner White ago
Commits
118a1bd6
Commit
118a1bd6
authored
Sep 30, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
2327df15
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
35 deletions
+54
-35
PdfMergeActivity.kt
...pdfviewerscannerwhite/ui/document/pdf/PdfMergeActivity.kt
+37
-28
PdfPresenter.kt
...ase/pdfviewerscannerwhite/ui/document/pdf/PdfPresenter.kt
+17
-7
No files found.
app/src/main/java/com/base/pdfviewerscannerwhite/ui/document/pdf/PdfMergeActivity.kt
View file @
118a1bd6
...
@@ -12,7 +12,9 @@ import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentRenameDialo
...
@@ -12,7 +12,9 @@ import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentRenameDialo
import
com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfPwdDialog
import
com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfPwdDialog
import
com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime2
import
com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime2
import
com.base.pdfviewerscannerwhite.utils.LogEx
import
com.base.pdfviewerscannerwhite.utils.LogEx
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.cancel
import
kotlinx.coroutines.cancel
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.isActive
import
kotlinx.coroutines.isActive
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
import
java.util.concurrent.ArrayBlockingQueue
import
java.util.concurrent.ArrayBlockingQueue
...
@@ -47,62 +49,69 @@ class PdfMergeActivity : BaseActivity<ActivityPdfMergeBinding>() {
...
@@ -47,62 +49,69 @@ class PdfMergeActivity : BaseActivity<ActivityPdfMergeBinding>() {
}
}
binding
.
tvBtnNext
.
setOnClickListener
{
binding
.
tvBtnNext
.
setOnClickListener
{
verificationPasswordDialogs
{
verificationPasswordDialogs
{
showDocumentRenameDialog
(
name
=
"Merge_${System.currentTimeMillis().toFormatTime2()}"
,
okAction
=
{
name
->
showDocumentRenameDialog
(
name
=
"Merge_${System.currentTimeMillis().toFormatTime2()}"
,
okAction
=
{
name
->
startActivity
(
Intent
(
this
,
PdfLoadingActivity
::
class
.
java
).
apply
{
startActivity
(
Intent
(
this
,
PdfLoadingActivity
::
class
.
java
).
apply
{
putExtra
(
"doWhat"
,
DO_MERGE_PDF
)
putExtra
(
"doWhat"
,
DO_MERGE_PDF
)
putExtra
(
"newPath"
,
pdfPresenter
.
createNewPdfPath
(
name
))
putExtra
(
"newPath"
,
pdfPresenter
.
createNewPdfPath
(
name
))
})
})
})
})
}
}
}
}
}
}
private
fun
verificationPasswordDialogs
(
callBack
:
(
isContinue
:
Boolean
)
->
Unit
)
{
private
fun
verificationPasswordDialogs
(
callBack
:
()
->
Unit
)
{
val
queue
:
BlockingQueue
<
DocumentBean
>
=
ArrayBlockingQueue
(
1
)
val
queue
:
BlockingQueue
<
DocumentBean
>
=
ArrayBlockingQueue
(
1
)
val
pwdItemList
=
mergePdfList
.
filter
{
it
.
state
==
1
}
val
pwdItemList
=
mergePdfList
.
filter
{
it
.
state
==
1
}
.
toMutableList
()
if
(
pwdItemList
.
isNotEmpty
())
{
if
(
pwdItemList
.
isNotEmpty
())
{
LogEx
.
logDebug
(
TAG
,
"verificationPasswordDialogs1"
)
LogEx
.
logDebug
(
TAG
,
"verificationPasswordDialogs1"
)
val
verifiedList
=
arrayListOf
<
DocumentBean
>()
val
verifiedList
=
arrayListOf
<
DocumentBean
>()
val
first
=
pwdItemList
[
0
]
val
first
=
pwdItemList
[
0
]
queue
.
put
(
first
)
queue
.
put
(
first
)
mergePdfList
.
removeAt
(
0
)
pwdItemList
.
removeAt
(
0
)
var
isCancel
:
Boolean
=
false
LogEx
.
logDebug
(
TAG
,
"verificationPasswordDialogs2"
)
LogEx
.
logDebug
(
TAG
,
"verificationPasswordDialogs2"
)
lifecycleScope
.
launch
()
{
lifecycleScope
.
launch
(
Dispatchers
.
IO
)
{
while
(
isActive
)
{
while
(
isActive
)
{
val
item
:
DocumentBean
=
queue
.
take
()
val
item
:
DocumentBean
=
queue
.
take
()
LogEx
.
logDebug
(
TAG
,
"verificationPasswordDialogs3"
)
LogEx
.
logDebug
(
TAG
,
"pwdItem =${item.path}"
)
showPdfPwdDialog
(
item
.
state
,
item
.
path
,
isCheckPwd
=
true
,
verificationAction
=
{
pwd
->
if
(
item
.
path
==
"Cancel"
)
{
item
.
password
=
pwd
break
verifiedList
.
add
(
item
)
}
if
(
pwdItemList
.
isNotEmpty
())
{
launch
(
Dispatchers
.
Main
)
{
val
next
=
mergePdfList
[
0
]
showPdfPwdDialog
(
item
.
state
,
item
.
path
,
isCheckPwd
=
true
,
verificationAction
=
{
pwd
->
queue
.
put
(
next
)
item
.
password
=
pwd
}
else
{
verifiedList
.
add
(
item
)
if
(
pwdItemList
.
isNotEmpty
())
{
val
next
=
pwdItemList
[
0
]
queue
.
put
(
next
)
pwdItemList
.
removeAt
(
0
)
}
else
{
queue
.
put
(
DocumentBean
(
path
=
"Cancel"
))
}
},
cancelAction
=
{
cancel
()
cancel
()
}
})
},
cancelAction
=
{
}
isCancel
=
true
cancel
()
})
}
}
}
LogEx
.
logDebug
(
TAG
,
"verificationPasswordDialogs3 ${verifiedList.size}"
)
if
(
isCancel
)
{
callBack
.
invoke
(
false
)
return
}
else
{
verifiedList
.
forEach
{
verifiedItem
->
verifiedList
.
forEach
{
verifiedItem
->
mergePdfList
.
find
{
it
.
path
==
verifiedItem
.
path
}
?.
password
=
verifiedItem
.
password
mergePdfList
.
find
{
it
.
path
==
verifiedItem
.
path
}
?.
password
=
verifiedItem
.
password
}
}
mergePdfList
.
forEach
{
LogEx
.
logDebug
(
TAG
,
"密码="
+
it
.
password
)
}
launch
(
Dispatchers
.
Main
)
{
callBack
.
invoke
()
}
}
}
mergePdfList
.
forEach
{
LogEx
.
logDebug
(
TAG
,
"密码="
+
it
.
password
)
}
else
{
}
callBack
.
invoke
()
}
}
callBack
.
invoke
(
true
)
}
}
private
fun
initAdapter
()
{
private
fun
initAdapter
()
{
...
...
app/src/main/java/com/base/pdfviewerscannerwhite/ui/document/pdf/PdfPresenter.kt
View file @
118a1bd6
...
@@ -142,17 +142,27 @@ class PdfPresenter(
...
@@ -142,17 +142,27 @@ class PdfPresenter(
val
mergerUtility
=
PDFMergerUtility
()
val
mergerUtility
=
PDFMergerUtility
()
mergerUtility
.
destinationFileName
=
mergePath
mergerUtility
.
destinationFileName
=
mergePath
LogEx
.
logDebug
(
TAG
,
"mergePdf ${mergePdfList.size}"
)
PdfMergeActivity
.
mergePdfList
.
forEach
{
documentBean
->
PdfMergeActivity
.
mergePdfList
.
forEach
{
documentBean
->
LogEx
.
logDebug
(
TAG
,
"mergePdf item= ${documentBean.path} ${documentBean.state}"
)
if
(
documentBean
.
state
==
0
)
{
if
(
documentBean
.
state
==
0
)
{
mergerUtility
.
addSource
(
File
(
documentBean
.
path
))
mergerUtility
.
addSource
(
File
(
documentBean
.
path
))
}
else
{
}
else
{
LogEx
.
logDebug
(
TAG
,
"documentBean.password=${documentBean.password}"
)
LogEx
.
logDebug
(
TAG
,
"mergePdf password=${documentBean.password}"
)
val
pdfDocument
=
PDDocument
.
load
(
File
(
documentBean
.
path
),
documentBean
.
password
)
try
{
val
byteArrayOutputStream
=
ByteArrayOutputStream
()
val
pdfDocument
=
PDDocument
.
load
(
File
(
documentBean
.
path
),
documentBean
.
password
)
pdfDocument
.
save
(
byteArrayOutputStream
)
LogEx
.
logDebug
(
TAG
,
"mergePdf pdfDocument ${pdfDocument.numberOfPages}"
)
pdfDocument
.
close
()
val
byteArrayOutputStream
=
ByteArrayOutputStream
(
1024
*
2
)
val
inputStream
=
ByteArrayInputStream
(
byteArrayOutputStream
.
toByteArray
())
pdfDocument
.
save
(
byteArrayOutputStream
)
mergerUtility
.
addSource
(
inputStream
)
LogEx
.
logDebug
(
TAG
,
"mergePdf byteArrayOutputStream ${byteArrayOutputStream.size()}"
)
pdfDocument
.
close
()
val
inputStream
=
ByteArrayInputStream
(
byteArrayOutputStream
.
toByteArray
())
LogEx
.
logDebug
(
TAG
,
"mergePdf inputStream"
)
mergerUtility
.
addSource
(
inputStream
)
}
catch
(
e
:
Exception
)
{
LogEx
.
logDebug
(
TAG
,
"mergePdf Exception ${e.printStackTrace()}"
)
}
LogEx
.
logDebug
(
TAG
,
"mergePdf inputStream"
)
}
}
}
}
mergerUtility
.
mergeDocuments
(
null
)
mergerUtility
.
mergeDocuments
(
null
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment