Skip to content

Commit

Permalink
Share feature for all files!
Browse files Browse the repository at this point in the history
- Added “share” button also for files opened by external apps
  • Loading branch information
Sav22999 committed Aug 1, 2023
1 parent cc17da6 commit b7ec52c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
1 change: 0 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 20 additions & 8 deletions app/src/main/java/com/saverio/pdfviewer/PDFViewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class PDFViewer : AppCompatActivity() {
val PDF_SELECTION_CODE = 100

var fileOpened: String? = ""
var fileId: String = ""
var uriOpened: Uri? = null

val timesAfterOpenReviewMessage = 500
Expand Down Expand Up @@ -94,9 +95,11 @@ class PDFViewer : AppCompatActivity() {
) {
uriToUse = intent.data.toString()
//println(uriToUse)
uriOpened = intent.data
}

println(">>> "+intent.data?.path)
fileOpened = RealPathUtil.getRealPath(this, intent.data!!)
isSupportedShareFeature = true
} catch (e: Exception) {
uriToUse = ""
}
Expand All @@ -114,7 +117,6 @@ class PDFViewer : AppCompatActivity() {
openFromStorage(Uri.parse(uriToUse))
}


checkReviewFollowApp()

val backButton: ImageView = findViewById(R.id.buttonGoBackToolbar)
Expand Down Expand Up @@ -279,7 +281,7 @@ class PDFViewer : AppCompatActivity() {
browserStorage.type = "application/pdf"
browserStorage.addCategory(Intent.CATEGORY_OPENABLE)
startActivityForResult(
Intent.createChooser(browserStorage, "Select the file"), PDF_SELECTION_CODE
Intent.createChooser(browserStorage, getString(R.string.select_file_intent)), PDF_SELECTION_CODE
)
}

Expand All @@ -299,8 +301,12 @@ class PDFViewer : AppCompatActivity() {

fun selectPdfFromURI(uri: Uri?) {
try {
//Toast.makeText(this, fileOpened, Toast.LENGTH_LONG).show()
//Toast.makeText(this, uri.toString(), Toast.LENGTH_LONG).show()
incrementHideTopBarCounter()
var lastPosition = 0
fileId = fileOpened!!.toString()
//Toast.makeText(this, fileId, Toast.LENGTH_LONG).show()
pdfViewer.fromUri(uri)
.enableSwipe(true) //leave as "true" (it causes a bug with scrolling when zoom is "100%")
.swipeHorizontal(false) //horizontal scrolling disable
Expand All @@ -327,7 +333,7 @@ class PDFViewer : AppCompatActivity() {
//.onPageError { page, t -> println(page) }
.onPageChange { page, pageCount ->
run {
updatePdfPage(uri.toString(), page)
updatePdfPage(fileId, page)
//setPositionScrollbarByPage(page.toFloat())
}
}.onPageScroll { page, positionOffset ->
Expand All @@ -349,7 +355,7 @@ class PDFViewer : AppCompatActivity() {
}*/
}
.onLoad {
lastPosition = getPdfPage(uri.toString())
lastPosition = getPdfPage(fileId)
/*pdfViewer.positionOffset = 1F
totalPages = pdfViewer.currentPage + 1*/
//TODO
Expand Down Expand Up @@ -413,7 +419,7 @@ class PDFViewer : AppCompatActivity() {
fullView.isGone = true
startY = minPositionScrollbar

updatePdfPage(uri.toString(), lastPosition)
updatePdfPage(fileId, lastPosition)
if (totalPages == 1) {
isSupportedGoTop = false
isSupportedScrollbarButton = false
Expand Down Expand Up @@ -590,7 +596,7 @@ class PDFViewer : AppCompatActivity() {
if (requestCode == PDF_SELECTION_CODE && resultCode == Activity.RESULT_OK && data != null) {
try {
val selectedPdf = data.data
selectPdfFromURI(selectedPdf)


val shareButton: ImageView = findViewById(R.id.buttonShareToolbar)
val fullscreenButton: ImageView = findViewById(R.id.buttonFullScreenToolbar)
Expand Down Expand Up @@ -623,6 +629,8 @@ class PDFViewer : AppCompatActivity() {
pagesNumber.isGone = true

//setTitle(getTheFileName(selectedPdf.toString(), -1))

selectPdfFromURI(selectedPdf)
} catch (e: Exception) {
println("Exception 4: Loading failed")
}
Expand Down Expand Up @@ -867,7 +875,11 @@ class PDFViewer : AppCompatActivity() {
shareIntent.putExtra(Intent.EXTRA_STREAM, uriOpened)
shareIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
shareIntent.type = "application/pdf"
startActivity(Intent.createChooser(shareIntent, "Share"))
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_file_intent)))
}

fun setSaveButton() {
//TODO
}

fun setFullscreenButton(button: ImageView) {
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name" translatable="false">Sav PDF Viewer</string>
<string name="app_name" translatable="false">Beta Sav PDF Viewer</string>
<string name="title_activity_main2" translatable="false">@string/app_name</string>
<string name="title_home">Home</string>
<string name="title_open">Open</string>
Expand All @@ -14,6 +14,8 @@

<string name="text_follow_on_instagram_the_app">I\'ve just created the Instagram account of the app.\nThere, you will find tips, curiosities and something else! 😉\nFollow it now 💙</string>
<string name="button_follow_instagram_the_app_now">Follow on Instagram</string>
<string name="select_file_intent">Select file</string>
<string name="share_file_intent">Share file</string>

<string name="text_tap_here_to_show_the_top_bar">Tap the transparent red section to show the top bar again, which disappears when you scroll.\nAfter 5 seconds the bar is also hidden and to show it again scroll.</string>
<string name="text_tap_here_to_show_go_to_dialog">Tap here to show the \"Go to\" panel, so you can quickly go to a specific page.</string>
Expand Down Expand Up @@ -50,6 +52,7 @@
<string name="tooltip_open_menu_panel">Open menu panel</string>
<string name="tooltip_hide_menu_panel">Hide menu panel</string>
<string name="tooltip_share_file">Share this file</string>
<string name="tooltip_save_file">Save this file</string>
<string name="tooltip_close_app">Close app</string>
<string name="tooltip_go_to_the_page">Go to the inserted page</string>
<string name="tooltip_close_panel">Close this panel</string>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.android.tools.build:gradle:7.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Tue Aug 01 11:35:59 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit b7ec52c

Please sign in to comment.