feat: custom downloader and downloader location (#313)
* feat: custom downloader (novel broken) * fix: send headers to ffmpeg ffmpeg can be a real bitch to work with * fix: offline page for new download system * feat: novel to new system | load freezing * chore: clean manifest * fix: notification incrementing * feat: changing the downloads dir
This commit is contained in:
parent
75e90541c9
commit
720b40afa7
35 changed files with 1162 additions and 1018 deletions
|
@ -5,6 +5,7 @@ import android.app.AlertDialog
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Build.BRAND
|
||||
import android.os.Build.DEVICE
|
||||
|
@ -52,8 +53,6 @@ import ani.dantotsu.databinding.ActivitySettingsMangaBinding
|
|||
import ani.dantotsu.databinding.ActivitySettingsNotificationsBinding
|
||||
import ani.dantotsu.databinding.ActivitySettingsThemeBinding
|
||||
import ani.dantotsu.download.DownloadsManager
|
||||
import ani.dantotsu.download.video.ExoplayerDownloadService
|
||||
import ani.dantotsu.downloadsPermission
|
||||
import ani.dantotsu.initActivity
|
||||
import ani.dantotsu.loadImage
|
||||
import ani.dantotsu.media.MediaType
|
||||
|
@ -82,7 +81,10 @@ import ani.dantotsu.startMainActivity
|
|||
import ani.dantotsu.statusBarHeight
|
||||
import ani.dantotsu.themes.ThemeManager
|
||||
import ani.dantotsu.toast
|
||||
import ani.dantotsu.util.LauncherWrapper
|
||||
import ani.dantotsu.util.Logger
|
||||
import ani.dantotsu.util.StoragePermissions.Companion.accessAlertDialog
|
||||
import ani.dantotsu.util.StoragePermissions.Companion.downloadsPermission
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import eltos.simpledialogfragment.SimpleDialog
|
||||
|
@ -91,7 +93,9 @@ import eltos.simpledialogfragment.color.SimpleColorDialog
|
|||
import eu.kanade.domain.base.BasePreferences
|
||||
import io.noties.markwon.Markwon
|
||||
import io.noties.markwon.SoftBreakAddsNewLinePlugin
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import uy.kohesive.injekt.Injekt
|
||||
|
@ -104,6 +108,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
|
|||
override fun handleOnBackPressed() = startMainActivity(this@SettingsActivity)
|
||||
}
|
||||
lateinit var binding: ActivitySettingsBinding
|
||||
lateinit var launcher: LauncherWrapper
|
||||
private lateinit var bindingAccounts: ActivitySettingsAccountsBinding
|
||||
private lateinit var bindingTheme: ActivitySettingsThemeBinding
|
||||
private lateinit var bindingExtensions: ActivitySettingsExtensionsBinding
|
||||
|
@ -115,6 +120,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
|
|||
private val extensionInstaller = Injekt.get<BasePreferences>().extensionInstaller()
|
||||
private var cursedCounter = 0
|
||||
|
||||
@kotlin.OptIn(DelicateCoroutinesApi::class)
|
||||
@OptIn(UnstableApi::class)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -166,6 +172,8 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
|
|||
}
|
||||
}
|
||||
}
|
||||
val contract = ActivityResultContracts.OpenDocumentTree()
|
||||
launcher = LauncherWrapper(this, contract)
|
||||
|
||||
binding.settingsVersion.text = getString(R.string.version_current, BuildConfig.VERSION_NAME)
|
||||
binding.settingsVersion.setOnLongClickListener {
|
||||
|
@ -457,11 +465,6 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
|
|||
.setPositiveButton(R.string.yes) { dialog, _ ->
|
||||
val downloadsManager = Injekt.get<DownloadsManager>()
|
||||
downloadsManager.purgeDownloads(MediaType.ANIME)
|
||||
DownloadService.sendRemoveAllDownloads(
|
||||
this@SettingsActivity,
|
||||
ExoplayerDownloadService::class.java,
|
||||
false
|
||||
)
|
||||
dialog.dismiss()
|
||||
}
|
||||
.setNegativeButton(R.string.no) { dialog, _ ->
|
||||
|
@ -724,20 +727,6 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
|
|||
restartApp(binding.root)
|
||||
}
|
||||
|
||||
settingsDownloadInSd.isChecked = PrefManager.getVal(PrefName.SdDl)
|
||||
settingsDownloadInSd.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
val arrayOfFiles = ContextCompat.getExternalFilesDirs(this@SettingsActivity, null)
|
||||
if (arrayOfFiles.size > 1 && arrayOfFiles[1] != null) {
|
||||
PrefManager.setVal(PrefName.SdDl, true)
|
||||
} else {
|
||||
settingsDownloadInSd.isChecked = false
|
||||
PrefManager.setVal(PrefName.SdDl, true)
|
||||
snackString(getString(R.string.noSdFound))
|
||||
}
|
||||
} else PrefManager.setVal(PrefName.SdDl, true)
|
||||
}
|
||||
|
||||
settingsContinueMedia.isChecked = PrefManager.getVal(PrefName.ContinueMedia)
|
||||
settingsContinueMedia.setOnCheckedChangeListener { _, isChecked ->
|
||||
PrefManager.setVal(PrefName.ContinueMedia, isChecked)
|
||||
|
@ -757,6 +746,44 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
|
|||
PrefManager.setVal(PrefName.AdultOnly, isChecked)
|
||||
restartApp(binding.root)
|
||||
}
|
||||
|
||||
settingsDownloadLocation.setOnClickListener {
|
||||
val dialog = AlertDialog.Builder(this@SettingsActivity, R.style.MyPopup)
|
||||
.setTitle(R.string.change_download_location)
|
||||
.setMessage(R.string.download_location_msg)
|
||||
.setPositiveButton(R.string.ok) { dialog, _ ->
|
||||
val oldUri = PrefManager.getVal<String>(PrefName.DownloadsDir)
|
||||
launcher.registerForCallback { success ->
|
||||
if (success) {
|
||||
toast(getString(R.string.please_wait))
|
||||
val newUri = PrefManager.getVal<String>(PrefName.DownloadsDir)
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
Injekt.get<DownloadsManager>().moveDownloadsDir(
|
||||
this@SettingsActivity,
|
||||
Uri.parse(oldUri), Uri.parse(newUri)
|
||||
) { finished, message ->
|
||||
if (finished) {
|
||||
toast(getString(R.string.success))
|
||||
} else {
|
||||
toast(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast(getString(R.string.error))
|
||||
}
|
||||
}
|
||||
launcher.launch()
|
||||
dialog.dismiss()
|
||||
}
|
||||
.setNeutralButton(R.string.cancel) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}
|
||||
.create()
|
||||
dialog.window?.setDimAmount(0.8f)
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
var previousStart: View = when (PrefManager.getVal<Int>(PrefName.DefaultStartUpTab)) {
|
||||
0 -> uiSettingsAnime
|
||||
1 -> uiSettingsHome
|
||||
|
|
|
@ -13,7 +13,6 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files
|
|||
OfflineView(Pref(Location.General, Int::class, 0)),
|
||||
DownloadManager(Pref(Location.General, Int::class, 0)),
|
||||
NSFWExtension(Pref(Location.General, Boolean::class, true)),
|
||||
SdDl(Pref(Location.General, Boolean::class, false)),
|
||||
ContinueMedia(Pref(Location.General, Boolean::class, true)),
|
||||
SearchSources(Pref(Location.General, Boolean::class, true)),
|
||||
RecentlyListOnly(Pref(Location.General, Boolean::class, false)),
|
||||
|
@ -182,6 +181,7 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files
|
|||
RecentGlobalNotification(Pref(Location.Irrelevant, Int::class, 0)),
|
||||
CommentNotificationStore(Pref(Location.Irrelevant, List::class, listOf<CommentStore>())),
|
||||
UnreadCommentNotifications(Pref(Location.Irrelevant, Int::class, 0)),
|
||||
DownloadsDir(Pref(Location.Irrelevant, String::class, "")),
|
||||
|
||||
//Protected
|
||||
DiscordToken(Pref(Location.Protected, String::class, "")),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue