Revert "Always save pages/covers in subfolders"

This reverts commit 8568d5d6c3.

Closes #10052
This commit is contained in:
arkon
2023-11-04 16:37:03 -04:00
parent 4a2ee0b596
commit 4b225a4ff1
61 changed files with 133 additions and 6 deletions

View File

@ -347,6 +347,11 @@ object SettingsReaderScreen : SearchableSettings {
pref = readerPreferences.readWithLongTap(),
title = stringResource(R.string.pref_read_with_long_tap),
),
Preference.PreferenceItem.SwitchPreference(
pref = readerPreferences.folderPerManga(),
title = stringResource(R.string.pref_create_folder_per_manga),
subtitle = stringResource(R.string.pref_create_folder_per_manga_summary),
),
),
)
}

View File

@ -168,12 +168,19 @@ sealed class Image(
}
sealed interface Location {
data class Pictures(val relativePath: String) : Location
data class Pictures private constructor(val relativePath: String) : Location {
companion object {
fun create(relativePath: String = ""): Pictures {
return Pictures(relativePath)
}
}
}
data object Cache : Location
fun directory(context: Context): File {
return when (this) {
Cache -> context.cacheImageDir
is Pictures -> {
val file = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
@ -187,7 +194,6 @@ sealed interface Location {
}
file
}
Cache -> context.cacheImageDir
}
}
}

View File

@ -102,8 +102,8 @@ class MangaCoverScreenModel(
imageSaver.save(
Image.Cover(
bitmap = bitmap,
name = "cover",
location = if (temp) Location.Cache else Location.Pictures(manga.title),
name = manga.title,
location = if (temp) Location.Cache else Location.Pictures.create(),
),
)
}

View File

@ -758,14 +758,17 @@ class ReaderViewModel @JvmOverloads constructor(
val filename = generateFilename(manga, page)
// Copy file in background
// Pictures directory.
val relativePath = if (readerPreferences.folderPerManga().get()) DiskUtil.buildValidFilename(manga.title) else ""
// Copy file in background.
viewModelScope.launchNonCancellable {
try {
val uri = imageSaver.save(
image = Image.Page(
inputStream = page.stream!!,
name = filename,
location = Location.Pictures(DiskUtil.buildValidFilename(manga.title)),
location = Location.Pictures.create(relativePath),
),
)
withUIContext {

View File

@ -56,6 +56,8 @@ class ReaderPreferences(
fun readerHideThreshold() = preferenceStore.getEnum("reader_hide_threshold", ReaderHideThreshold.LOW)
fun folderPerManga() = preferenceStore.getBoolean("create_folder_per_manga", false)
fun skipRead() = preferenceStore.getBoolean("skip_read", false)
fun skipFiltered() = preferenceStore.getBoolean("skip_filtered", true)