Skip to content

Commit

Permalink
bump libs + img focus + download location
Browse files Browse the repository at this point in the history
  • Loading branch information
LagradOst committed Dec 7, 2023
1 parent f3518cd commit ba6575e
Show file tree
Hide file tree
Showing 18 changed files with 464 additions and 160 deletions.
22 changes: 10 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 33
compileSdkVersion 34
buildToolsVersion "30.0.3"

viewBinding {
Expand All @@ -12,10 +12,10 @@ android {

defaultConfig {
applicationId "com.lagradost.quicknovel"
minSdkVersion 22
targetSdkVersion 33
minSdkVersion 21
targetSdkVersion 34
versionCode 54
versionName "3.1.4"
versionName "3.1.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down Expand Up @@ -55,17 +55,17 @@ repositories {

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'org.jsoup:jsoup:1.15.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.6.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.5'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'com.github.bumptech.glide:glide:4.13.1'
implementation 'com.github.bumptech.glide:glide:4.15.1'
kapt 'com.github.bumptech.glide:compiler:4.13.1'
implementation 'jp.wasabeef:glide-transformations:4.3.0'
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.13.1"
Expand All @@ -85,12 +85,10 @@ dependencies {
implementation("com.google.android.material:material:1.5.0")

implementation 'androidx.media:media:1.6.0'

implementation 'com.github.LagradOst:SafeFile:0.0.6' // To Prevent the URI File Fu*kery
implementation 'com.jaredrummler:colorpicker:1.1.0'

// Util to skip the URI file fuckery 🙏
implementation "com.github.tachiyomiorg:unifile:17bec43"
implementation 'com.github.Blatzar:NiceHttp:0.4.3'
implementation 'com.github.Blatzar:NiceHttp:0.4.4'

implementation "io.noties.markwon:core:4.6.2"
implementation "io.noties.markwon:image-glide:4.6.2"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</queries>

<application
android:enableOnBackInvokedCallback="true"
android:name=".BaseApplication"
android:requestLegacyExternalStorage="true"
android:allowBackup="true"
Expand Down
51 changes: 33 additions & 18 deletions app/src/main/java/com/lagradost/quicknovel/BookDownloader2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.app.NotificationManager
import android.app.PendingIntent
import android.content.ContentResolver
import android.content.ContentUris
import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
Expand All @@ -27,7 +26,6 @@ import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.core.net.toUri
import androidx.preference.PreferenceManager
import com.bumptech.glide.Glide
Expand All @@ -50,6 +48,8 @@ import com.lagradost.quicknovel.extractors.ExtractorApi
import com.lagradost.quicknovel.mvvm.logError
import com.lagradost.quicknovel.services.DownloadService
import com.lagradost.quicknovel.ui.download.DownloadFragment
import com.lagradost.quicknovel.ui.settings.SettingsFragment.Companion.getBasePath
import com.lagradost.quicknovel.ui.settings.SettingsFragment.Companion.getDefaultDir
import com.lagradost.quicknovel.util.Apis.Companion.getApiFromName
import com.lagradost.quicknovel.util.Coroutines.ioSafe
import com.lagradost.quicknovel.util.Coroutines.main
Expand All @@ -69,8 +69,7 @@ import nl.siegmann.epublib.domain.Resource
import nl.siegmann.epublib.epub.EpubWriter
import nl.siegmann.epublib.service.MediatypeService
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream
import java.io.IOException


enum class DownloadActionType {
Expand Down Expand Up @@ -135,7 +134,7 @@ object BookDownloader2Helper {
for (c in reservedChars) {
tempName = tempName.replace(c, ' ')
}
return tempName.replace(" ", " ")
return tempName.replace(Regex("\\s+"), " ").trim()
}

fun getDirectory(apiName: String, author: String, name: String): String {
Expand Down Expand Up @@ -458,6 +457,15 @@ object BookDownloader2Helper {
}

val settingsManager = PreferenceManager.getDefaultSharedPreferences(activity)
val subDir = activity.getBasePath().first ?: getDefaultDir(activity) ?: throw IOException("No file")

//val subDir = baseFile.gotoDirectory("Epub", createMissingDirectories = false) ?: return false
val displayName = "${sanitizeFilename(name)}.epub"

val foundFile = subDir.findFile(displayName) ?: return false

//val relativePath = (Environment.DIRECTORY_DOWNLOADS + "${fs}Epub${fs}")


if (openInApp ?: !(settingsManager.getBoolean(
activity.getString(R.string.external_reader_key),
Expand All @@ -466,8 +474,7 @@ object BookDownloader2Helper {
) {
val myIntent = Intent(activity, ReadActivity2::class.java)

val relativePath = (Environment.DIRECTORY_DOWNLOADS + "${fs}Epub${fs}")
val displayName = "${sanitizeFilename(name)}.epub"
/*val relativePath = (Environment.DIRECTORY_DOWNLOADS + "${fs}Epub${fs}")
val fileUri = if (isScopedStorage()) {
val cr = activity.contentResolver ?: return false
Expand All @@ -478,15 +485,15 @@ object BookDownloader2Helper {
val bookFile = File(normalPath)
bookFile.toUri()
}
myIntent.setDataAndType(fileUri, "application/epub+zip")
}*/

myIntent.setDataAndType(foundFile.uri() ?: return false, "application/epub+zip")

activity.startActivity(myIntent)
return true
}

val relativePath = (Environment.DIRECTORY_DOWNLOADS + "${fs}Epub${fs}")
val displayName = "${sanitizeFilename(name)}.epub"
// val relativePath = (Environment.DIRECTORY_DOWNLOADS + "${fs}Epub${fs}")

try {
val intent = Intent()
Expand All @@ -498,8 +505,10 @@ object BookDownloader2Helper {
// val mime = MimeTypeMap.getSingleton()
// val ext: String = ".epub" //bookFile.name.substring(bookFile.name.lastIndexOf(".") + 1)
val type = "application/epub+zip"//mime.getMimeTypeFromExtension(ext)

if (isScopedStorage()) {
intent.setDataAndType(
foundFile.uri() ?: return false, type
)
/*if (isScopedStorage()) {
val cr = activity.contentResolver ?: return false
val fileUri =
Expand All @@ -520,7 +529,7 @@ object BookDownloader2Helper {
bookFile
), type
) // THIS IS NEEDED BECAUSE A REGULAR INTENT WONT OPEN MOONREADER
}
}*/

activity.startActivity(intent)
//this.startActivityForResult(intent,1337) // SEE @moonreader
Expand Down Expand Up @@ -600,12 +609,18 @@ object BookDownloader2Helper {
val sName = sanitizeFilename(name)
val id = "$sApiName$sAuthor$sName".hashCode()

val fileStream: OutputStream
val subDir = activity.getBasePath().first ?: getDefaultDir(activity) ?: throw IOException("No file")

val relativePath = (Environment.DIRECTORY_DOWNLOADS + "${fs}Epub${fs}")
//val subDir = baseFile.gotoDirectoryOrThrow("Epub", createMissingDirectories = true)
val displayName = "${sanitizeFilename(name)}.epub"

if (isScopedStorage()) {
//val relativePath = (Environment.DIRECTORY_DOWNLOADS + "${fs}Epub${fs}")
subDir.findFile(displayName)?.delete()
val file = subDir.createFileOrThrow(displayName)

val fileStream = file.openOutputStream(append = false) ?: throw IOException("No outputfile")

/*if (isScopedStorage()) {
val cr = activity.contentResolver ?: return false
val currentExistingFile =
Expand Down Expand Up @@ -654,7 +669,7 @@ object BookDownloader2Helper {
if (!rFile.createNewFile()) return false
}
fileStream = FileOutputStream(rFile, false)
}
}*/

val epubFile = File(
activity.filesDir.toString() + getDirectory(sApiName, sAuthor, sName),
Expand Down
Loading

0 comments on commit ba6575e

Please sign in to comment.