Add preference to toggle chapter URL hash for downloads (#1533)

This commit is contained in:
NGB-Was-Taken
2025-12-26 03:32:56 +05:45
committed by GitHub
parent ad5a76741a
commit 0ffc798e9a
4 changed files with 30 additions and 1 deletions
@@ -89,6 +89,7 @@ import tachiyomi.core.common.util.lang.withUIContext
import tachiyomi.core.common.util.system.ImageUtil
import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.manga.interactor.GetAllManga
import tachiyomi.domain.manga.interactor.ResetViewerFlags
@@ -117,6 +118,7 @@ object SettingsAdvancedScreen : SearchableSettings {
val basePreferences = remember { Injekt.get<BasePreferences>() }
val networkPreferences = remember { Injekt.get<NetworkPreferences>() }
val libraryPreferences = remember { Injekt.get<LibraryPreferences>() }
val downloadPreferences = remember { Injekt.get<DownloadPreferences>() }
return listOf(
Preference.PreferenceItem.TextPreference(
@@ -167,6 +169,7 @@ object SettingsAdvancedScreen : SearchableSettings {
getDataGroup(),
getNetworkGroup(networkPreferences = networkPreferences),
getLibraryGroup(libraryPreferences = libraryPreferences),
getDownloadsGroup(downloadPreferences = downloadPreferences),
getReaderGroup(basePreferences = basePreferences),
getExtensionsGroup(basePreferences = basePreferences),
// SY -->
@@ -378,6 +381,24 @@ object SettingsAdvancedScreen : SearchableSettings {
)
}
// SY ->
@Composable
private fun getDownloadsGroup(
downloadPreferences: DownloadPreferences,
): Preference.PreferenceGroup {
return Preference.PreferenceGroup(
title = stringResource(MR.strings.pref_category_downloads),
preferenceItems = persistentListOf(
Preference.PreferenceItem.SwitchPreference(
preference = downloadPreferences.includeChapterUrlHash(),
title = stringResource(SYMR.strings.pref_include_chapter_url_hash),
subtitle = stringResource(SYMR.strings.pref_include_chapter_url_hash_desc),
),
),
)
}
// <- SY
@Composable
private fun getReaderGroup(
basePreferences: BasePreferences,
@@ -10,6 +10,7 @@ import tachiyomi.core.common.i18n.stringResource
import tachiyomi.core.common.storage.displayablePath
import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.storage.service.StorageManager
@@ -28,6 +29,7 @@ class DownloadProvider(
private val context: Context,
private val storageManager: StorageManager = Injekt.get(),
private val libraryPreferences: LibraryPreferences = Injekt.get(),
private val downloadPreferences: DownloadPreferences = Injekt.get(),
) {
private val downloadsDir: UniFile?
@@ -190,6 +192,7 @@ class DownloadProvider(
chapterScanlator: String?,
chapterUrl: String,
disallowNonAsciiFilenames: Boolean = libraryPreferences.disallowNonAsciiFilenames().get(),
includeChapterUrlHash: Boolean = downloadPreferences.includeChapterUrlHash().get(),
): String {
var dirName = sanitizeChapterName(chapterName)
if (!chapterScanlator.isNullOrBlank()) {
@@ -197,7 +200,7 @@ class DownloadProvider(
}
// Subtract 7 bytes for hash and underscore, 4 bytes for .cbz
dirName = DiskUtil.buildValidFilename(dirName, DiskUtil.MAX_FILE_NAME_BYTES - 11, disallowNonAsciiFilenames)
dirName += "_" + md5(chapterUrl).take(6)
if (includeChapterUrlHash) dirName += "_" + md5(chapterUrl).take(6)
return dirName
}
@@ -233,6 +236,7 @@ class DownloadProvider(
chapterScanlator,
chapterUrl,
!libraryPreferences.disallowNonAsciiFilenames().get(),
!downloadPreferences.includeChapterUrlHash().get(),
)
return buildList(2) {