-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
afreakyelf
committed
Jan 4, 2021
1 parent
c1b0975
commit 251184f
Showing
8 changed files
with
156 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Sat Jul 11 15:48:36 IST 2020 | ||
#Mon Jan 04 10:33:44 IST 2021 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
pdfViewer/src/main/java/com/rajat/pdfviewer/util/FileUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.rajat.pdfviewer.util | ||
|
||
import android.content.Context | ||
import android.os.Environment | ||
import android.provider.MediaStore | ||
import android.text.TextUtils | ||
import java.io.* | ||
|
||
object FileUtils { | ||
@Throws(IOException::class) | ||
fun fileFromAsset(context: Context, assetName: String): File { | ||
val outFile = File(context.cacheDir, "$assetName") | ||
if (assetName.contains("/")) { | ||
outFile.parentFile.mkdirs() | ||
} | ||
copy(context.assets.open(assetName), outFile) | ||
return outFile | ||
} | ||
|
||
@Throws(IOException::class) | ||
fun copy(inputStream: InputStream?, output: File?) { | ||
var outputStream: OutputStream? = null | ||
try { | ||
outputStream = FileOutputStream(output) | ||
var read = 0 | ||
val bytes = ByteArray(1024) | ||
while (inputStream!!.read(bytes).also { read = it } != -1) { | ||
outputStream.write(bytes, 0, read) | ||
} | ||
} finally { | ||
try { | ||
inputStream?.close() | ||
} finally { | ||
outputStream?.close() | ||
} | ||
} | ||
} | ||
|
||
@Throws(IOException::class) | ||
fun downloadFile(context: Context, assetName: String, filePath: String, fileName: String?){ | ||
|
||
val dirPath = "${Environment.getExternalStorageDirectory()}/${filePath}" | ||
val outFile = File(dirPath) | ||
//Create New File if not present | ||
if (!outFile.exists()) { | ||
outFile.mkdirs() | ||
} | ||
val outFile1 = File(dirPath, "/$fileName.pdf") | ||
copy(context.assets.open(assetName), outFile1) | ||
} | ||
} |