forked from hardcoresushi/DroidFS
PDF viewer
This commit is contained in:
parent
83efc53edc
commit
b18232615d
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +1,6 @@
|
|||||||
[submodule "app/libgocryptfs"]
|
[submodule "app/libgocryptfs"]
|
||||||
path = app/libgocryptfs
|
path = app/libgocryptfs
|
||||||
url = https://forge.chapril.org/hardcoresushi/libgocryptfs.git
|
url = https://forge.chapril.org/hardcoresushi/libgocryptfs.git
|
||||||
|
[submodule "libpdfviewer"]
|
||||||
|
path = libpdfviewer
|
||||||
|
url = https://forge.chapril.org/hardcoresushi/libpdfviewer.git
|
||||||
|
@ -101,14 +101,10 @@ You also need to install the Android SDK build tools and the [Android NDK](https
|
|||||||
|
|
||||||
#### Download Sources
|
#### Download Sources
|
||||||
```
|
```
|
||||||
$ git clone https://github.com/hardcore-sushi/DroidFS.git
|
$ git clone --recurse-submodules https://github.com/hardcore-sushi/DroidFS.git
|
||||||
```
|
|
||||||
Download [libgocryptfs](https://forge.chapril.org/hardcoresushi/libgocryptfs):
|
|
||||||
```
|
|
||||||
$ cd DroidFS
|
$ cd DroidFS
|
||||||
$ git submodule update --init
|
|
||||||
```
|
```
|
||||||
libgocryptfs needs OpenSSL:
|
[libgocryptfs](https://forge.chapril.org/hardcoresushi/libgocryptfs) needs OpenSSL:
|
||||||
```
|
```
|
||||||
$ cd app/libgocryptfs
|
$ cd app/libgocryptfs
|
||||||
$ wget https://www.openssl.org/source/openssl-1.1.1m.tar.gz
|
$ wget https://www.openssl.org/source/openssl-1.1.1m.tar.gz
|
||||||
|
@ -55,6 +55,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation project(":libpdfviewer:app")
|
||||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
implementation 'androidx.core:core-ktx:1.7.0'
|
implementation 'androidx.core:core-ktx:1.7.0'
|
||||||
|
@ -77,6 +77,9 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".file_viewers.VideoPlayer"
|
android:name=".file_viewers.VideoPlayer"
|
||||||
android:configChanges="screenSize|orientation" />
|
android:configChanges="screenSize|orientation" />
|
||||||
|
<activity
|
||||||
|
android:name=".file_viewers.PdfViewer"
|
||||||
|
android:configChanges="screenSize|orientation" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".file_viewers.AudioPlayer"
|
android:name=".file_viewers.AudioPlayer"
|
||||||
android:configChanges="screenSize|orientation" />
|
android:configChanges="screenSize|orientation" />
|
||||||
|
@ -19,6 +19,7 @@ class ConstValues {
|
|||||||
Pair("image", listOf("png", "jpg", "jpeg", "gif", "webp", "bmp")),
|
Pair("image", listOf("png", "jpg", "jpeg", "gif", "webp", "bmp")),
|
||||||
Pair("video", listOf("mp4", "webm", "mkv", "mov")),
|
Pair("video", listOf("mp4", "webm", "mkv", "mov")),
|
||||||
Pair("audio", listOf("mp3", "ogg", "m4a", "wav", "flac")),
|
Pair("audio", listOf("mp3", "ogg", "m4a", "wav", "flac")),
|
||||||
|
Pair("pdf", listOf("pdf")),
|
||||||
Pair("text", listOf("txt", "json", "conf", "log", "xml", "java", "kt", "py", "pl", "rb", "go", "c", "h", "cpp", "hpp", "rs", "sh", "bat", "js", "html", "css", "php", "yml", "yaml", "toml", "ini", "md", "properties"))
|
Pair("text", listOf("txt", "json", "conf", "log", "xml", "java", "kt", "py", "pl", "rb", "go", "c", "h", "cpp", "hpp", "rs", "sh", "bat", "js", "html", "css", "php", "yml", "yaml", "toml", "ini", "md", "properties"))
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,6 +36,9 @@ class ConstValues {
|
|||||||
fun isAudio(path: String): Boolean {
|
fun isAudio(path: String): Boolean {
|
||||||
return isExtensionType("audio", path)
|
return isExtensionType("audio", path)
|
||||||
}
|
}
|
||||||
|
fun isPDF(path: String): Boolean {
|
||||||
|
return isExtensionType("pdf", path)
|
||||||
|
}
|
||||||
fun isText(path: String): Boolean {
|
fun isText(path: String): Boolean {
|
||||||
return isExtensionType("text", path)
|
return isExtensionType("text", path)
|
||||||
}
|
}
|
||||||
|
@ -238,8 +238,8 @@ class GocryptfsVolume(val applicationContext: Context, var sessionID: Int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadWholeFile(fullPath: String, maxSize: Long? = null): Pair<ByteArray?, Int> {
|
fun loadWholeFile(fullPath: String, size: Long? = null, maxSize: Long? = null): Pair<ByteArray?, Int> {
|
||||||
val fileSize = getSize(fullPath)
|
val fileSize = size ?: getSize(fullPath)
|
||||||
return if (fileSize >= 0) {
|
return if (fileSize >= 0) {
|
||||||
maxSize?.let {
|
maxSize?.let {
|
||||||
if (fileSize > it) {
|
if (fileSize > it) {
|
||||||
|
@ -127,7 +127,7 @@ class ExplorerElementAdapter(
|
|||||||
adapter.gocryptfsVolume?.let { volume ->
|
adapter.gocryptfsVolume?.let { volume ->
|
||||||
displayThumbnail = true
|
displayThumbnail = true
|
||||||
Thread {
|
Thread {
|
||||||
volume.loadWholeFile(fullPath, 50_000_000).first?.let {
|
volume.loadWholeFile(fullPath, maxSize = 50_000_000).first?.let {
|
||||||
if (displayThumbnail) {
|
if (displayThumbnail) {
|
||||||
adapter.activity.runOnUiThread {
|
adapter.activity.runOnUiThread {
|
||||||
if (displayThumbnail) {
|
if (displayThumbnail) {
|
||||||
|
@ -25,6 +25,7 @@ import sushi.hardcore.droidfs.BaseActivity
|
|||||||
import sushi.hardcore.droidfs.ConstValues
|
import sushi.hardcore.droidfs.ConstValues
|
||||||
import sushi.hardcore.droidfs.ConstValues.Companion.isAudio
|
import sushi.hardcore.droidfs.ConstValues.Companion.isAudio
|
||||||
import sushi.hardcore.droidfs.ConstValues.Companion.isImage
|
import sushi.hardcore.droidfs.ConstValues.Companion.isImage
|
||||||
|
import sushi.hardcore.droidfs.ConstValues.Companion.isPDF
|
||||||
import sushi.hardcore.droidfs.ConstValues.Companion.isText
|
import sushi.hardcore.droidfs.ConstValues.Companion.isText
|
||||||
import sushi.hardcore.droidfs.ConstValues.Companion.isVideo
|
import sushi.hardcore.droidfs.ConstValues.Companion.isVideo
|
||||||
import sushi.hardcore.droidfs.GocryptfsVolume
|
import sushi.hardcore.droidfs.GocryptfsVolume
|
||||||
@ -35,10 +36,7 @@ import sushi.hardcore.droidfs.content_providers.ExternalProvider
|
|||||||
import sushi.hardcore.droidfs.content_providers.RestrictedFileProvider
|
import sushi.hardcore.droidfs.content_providers.RestrictedFileProvider
|
||||||
import sushi.hardcore.droidfs.file_operations.FileOperationService
|
import sushi.hardcore.droidfs.file_operations.FileOperationService
|
||||||
import sushi.hardcore.droidfs.file_operations.OperationFile
|
import sushi.hardcore.droidfs.file_operations.OperationFile
|
||||||
import sushi.hardcore.droidfs.file_viewers.AudioPlayer
|
import sushi.hardcore.droidfs.file_viewers.*
|
||||||
import sushi.hardcore.droidfs.file_viewers.ImageViewer
|
|
||||||
import sushi.hardcore.droidfs.file_viewers.TextEditor
|
|
||||||
import sushi.hardcore.droidfs.file_viewers.VideoPlayer
|
|
||||||
import sushi.hardcore.droidfs.util.PathUtils
|
import sushi.hardcore.droidfs.util.PathUtils
|
||||||
import sushi.hardcore.droidfs.widgets.CustomAlertDialogBuilder
|
import sushi.hardcore.droidfs.widgets.CustomAlertDialogBuilder
|
||||||
|
|
||||||
@ -164,6 +162,7 @@ open class BaseExplorerActivity : BaseActivity() {
|
|||||||
"image" -> startFileViewer(ImageViewer::class.java, path)
|
"image" -> startFileViewer(ImageViewer::class.java, path)
|
||||||
"video" -> startFileViewer(VideoPlayer::class.java, path)
|
"video" -> startFileViewer(VideoPlayer::class.java, path)
|
||||||
"audio" -> startFileViewer(AudioPlayer::class.java, path)
|
"audio" -> startFileViewer(AudioPlayer::class.java, path)
|
||||||
|
"pdf" -> startFileViewer(PdfViewer::class.java, path)
|
||||||
"text" -> startFileViewer(TextEditor::class.java, path)
|
"text" -> startFileViewer(TextEditor::class.java, path)
|
||||||
"external" -> if (usf_open) {
|
"external" -> if (usf_open) {
|
||||||
openWithExternalApp(path)
|
openWithExternalApp(path)
|
||||||
@ -197,6 +196,9 @@ open class BaseExplorerActivity : BaseActivity() {
|
|||||||
isText(fullPath) -> {
|
isText(fullPath) -> {
|
||||||
startFileViewer(TextEditor::class.java, fullPath)
|
startFileViewer(TextEditor::class.java, fullPath)
|
||||||
}
|
}
|
||||||
|
isPDF(fullPath) -> {
|
||||||
|
startFileViewer(PdfViewer::class.java, fullPath)
|
||||||
|
}
|
||||||
isAudio(fullPath) -> {
|
isAudio(fullPath) -> {
|
||||||
startFileViewer(AudioPlayer::class.java, fullPath)
|
startFileViewer(AudioPlayer::class.java, fullPath)
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,8 @@ abstract class FileViewerActivity: BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun loadWholeFile(path: String): ByteArray? {
|
protected fun loadWholeFile(path: String, fileSize: Long? = null): ByteArray? {
|
||||||
val result = gocryptfsVolume.loadWholeFile(path)
|
val result = gocryptfsVolume.loadWholeFile(path, size = fileSize)
|
||||||
if (result.second != 0) {
|
if (result.second != 0) {
|
||||||
val dialog = CustomAlertDialogBuilder(this, themeValue)
|
val dialog = CustomAlertDialogBuilder(this, themeValue)
|
||||||
.setTitle(R.string.error)
|
.setTitle(R.string.error)
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package sushi.hardcore.droidfs.file_viewers
|
||||||
|
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.appcompat.widget.Toolbar
|
||||||
|
import sushi.hardcore.droidfs.R
|
||||||
|
import sushi.hardcore.droidfs.databinding.ActivityPdfViewerBinding
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class PdfViewer: FileViewerActivity() {
|
||||||
|
private lateinit var binding: ActivityPdfViewerBinding
|
||||||
|
|
||||||
|
override fun hideSystemUi() {
|
||||||
|
//don't hide system ui
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getFileType(): String {
|
||||||
|
return "pdf"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun viewFile() {
|
||||||
|
binding = ActivityPdfViewerBinding.inflate(layoutInflater)
|
||||||
|
val toolbar = binding.root.findViewById<Toolbar>(R.id.toolbar)
|
||||||
|
setSupportActionBar(toolbar)
|
||||||
|
title = ""
|
||||||
|
val titleText = toolbar.findViewById<TextView>(R.id.title_text)
|
||||||
|
val fileName = File(filePath).name
|
||||||
|
titleText.text = fileName
|
||||||
|
binding.pdfViewer.activity = this
|
||||||
|
setContentView(binding.root)
|
||||||
|
val fileSize = gocryptfsVolume.getSize(filePath)
|
||||||
|
loadWholeFile(filePath, fileSize)?.let {
|
||||||
|
binding.pdfViewer.loadPdf(ByteArrayInputStream(it), fileName, fileSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
|
binding.pdfViewer.onCreateOptionMenu(menu)
|
||||||
|
return super.onCreateOptionsMenu(menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
|
||||||
|
return binding.pdfViewer.onPrepareOptionsMenu(menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
return binding.pdfViewer.onOptionsItemSelected(item) || super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
|
}
|
14
app/src/main/res/layout/activity_pdf_viewer.xml
Normal file
14
app/src/main/res/layout/activity_pdf_viewer.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<include android:id="@+id/toolbar" layout="@layout/toolbar"/>
|
||||||
|
|
||||||
|
<org.grapheneos.pdfviewer.PdfViewer
|
||||||
|
android:id="@+id/pdf_viewer"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_width="match_parent"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -6,7 +6,7 @@ buildscript {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:7.0.4'
|
classpath 'com.android.tools.build:gradle:7.1.1'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
libpdfviewer
Submodule
1
libpdfviewer
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 4e4b7c5da4dddbc3841abd450fa250936be70f4e
|
@ -1,2 +1,2 @@
|
|||||||
include ':app'
|
include ':app', ':libpdfviewer:app'
|
||||||
rootProject.name = "DroidFS"
|
rootProject.name = "DroidFS"
|
Loading…
Reference in New Issue
Block a user