external downloader support part 3

This commit is contained in:
jmir1 2021-07-13 15:25:09 +02:00
parent 101fd1dcff
commit 704d809914
5 changed files with 53 additions and 15 deletions

View file

@ -459,16 +459,31 @@ class AnimeDownloader(
// TODO: support other file formats!!
// start download with intent
val pm = context.packageManager
val intent = pm.getLaunchIntentForPackage("idm.internet.download.manager")
intent!!.apply {
component = ComponentName("idm.internet.download.manager", "idm.internet.download.manager.Downloader")
action = Intent.ACTION_VIEW
data = Uri.parse(video.videoUrl!!)
putExtra("extra_filename", filename)
val pkgName = preferences.externalDownloaderSelection()
Timber.w(pkgName)
val intent: Intent
if (!pkgName.isNullOrEmpty()) {
intent = pm.getLaunchIntentForPackage(pkgName)!!
intent.apply {
// TODO: this only works for 1DM
component = ComponentName(pkgName, "${pkgName.substringBeforeLast(".")}.Downloader")
action = Intent.ACTION_VIEW
data = video.uri ?: Uri.parse(video.videoUrl)
putExtra("extra_filename", filename)
}
} else {
Timber.w("emtpy")
intent = Intent(Intent.ACTION_VIEW)
intent.apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
data = video.uri ?: Uri.parse(video.videoUrl)
putExtra("extra_filename", filename)
}
}
context.startActivity(intent)
} catch (e: Exception) {
it.delete()
Timber.w(e.message)
throw e
}
it

View file

@ -128,6 +128,8 @@ object PreferenceKeys {
const val useExternalDownloader = "use_external_downloader"
const val externalDownloaderSelection = "external_downloader_selection"
const val downloadOnlyOverWifi = "pref_download_only_over_wifi_key"
const val folderPerManga = "create_folder_per_manga"

View file

@ -233,6 +233,8 @@ class PreferencesHelper(val context: Context) {
fun useExternalDownloader() = prefs.getBoolean(Keys.useExternalDownloader, false)
fun externalDownloaderSelection() = prefs.getString(Keys.externalDownloaderSelection, "")
fun downloadOnlyOverWifi() = prefs.getBoolean(Keys.downloadOnlyOverWifi, true)
fun folderPerManga() = prefs.getBoolean(Keys.folderPerManga, false)

View file

@ -19,14 +19,7 @@ import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.preference.defaultValue
import eu.kanade.tachiyomi.util.preference.entriesRes
import eu.kanade.tachiyomi.util.preference.intListPreference
import eu.kanade.tachiyomi.util.preference.onClick
import eu.kanade.tachiyomi.util.preference.preference
import eu.kanade.tachiyomi.util.preference.preferenceCategory
import eu.kanade.tachiyomi.util.preference.switchPreference
import eu.kanade.tachiyomi.util.preference.titleRes
import eu.kanade.tachiyomi.util.preference.*
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.widget.materialdialogs.QuadStateCheckBox
import eu.kanade.tachiyomi.widget.materialdialogs.listItemsQuadStateMultiChoice
@ -158,6 +151,31 @@ class SettingsDownloadController : SettingsController() {
titleRes = R.string.pref_use_external_downloader
defaultValue = false
}
listPreference {
key = Keys.externalDownloaderSelection
titleRes = R.string.pref_external_downloader_selection
val pm = context.packageManager
val installedPackages = pm.getInstalledPackages(0)
val supportedDownloaders = installedPackages.filter {
when (it.packageName) {
"idm.internet.download.manager" -> true
"idm.internet.download.manager.plus" -> true
"idm.internet.download.manager.lite" -> true
else -> false
}
}
val packageNames = supportedDownloaders.map { it.packageName }
val packageNamesReadable = supportedDownloaders
.map { pm.getApplicationLabel(it.applicationInfo).toString() }
entries = arrayOf("None") + packageNamesReadable.toTypedArray()
entryValues = arrayOf("") + packageNames.toTypedArray()
defaultValue = ""
summary = "%s"
}
}
}

View file

@ -414,7 +414,8 @@
<string name="fifth_to_last">Fifth to last chapter</string>
<string name="pref_category_auto_download">Auto-download</string>
<string name="pref_category_anime_download">Anime downloads</string>
<string name="pref_use_external_downloader">Use external downloader for anime</string>
<string name="pref_use_external_downloader">Always use external downloader for anime</string>
<string name="pref_external_downloader_selection">Downloader app preference</string>
<string name="pref_download_new">Download new chapters</string>
<string name="pref_download_new_categories_details">Manga in excluded categories will not be downloaded even if they are also in included categories.</string>