Always save pages/covers in subfolders

Ensures that pages and covers are grouped together.
This commit is contained in:
arkon 2023-10-08 17:04:02 -04:00
parent 7ed99fbbd6
commit 8568d5d6c3
6 changed files with 6 additions and 24 deletions

View File

@ -342,11 +342,6 @@ object SettingsReaderScreen : SearchableSettings {
pref = readerPreferences.readWithLongTap(), pref = readerPreferences.readWithLongTap(),
title = stringResource(R.string.pref_read_with_long_tap), 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

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

View File

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

View File

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

View File

@ -54,8 +54,6 @@ class ReaderPreferences(
fun readerHideThreshold() = preferenceStore.getEnum("reader_hide_threshold", ReaderHideThreshold.LOW) 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 skipRead() = preferenceStore.getBoolean("skip_read", false)
fun skipFiltered() = preferenceStore.getBoolean("skip_filtered", true) fun skipFiltered() = preferenceStore.getBoolean("skip_filtered", true)

View File

@ -363,8 +363,6 @@
<string name="tapping_inverted_both">Both</string> <string name="tapping_inverted_both">Both</string>
<string name="pref_reader_actions">Actions</string> <string name="pref_reader_actions">Actions</string>
<string name="pref_read_with_long_tap">Show actions on long tap</string> <string name="pref_read_with_long_tap">Show actions on long tap</string>
<string name="pref_create_folder_per_manga">Save pages into separate folders</string>
<string name="pref_create_folder_per_manga_summary">Creates folders according to entries\' title</string>
<string name="pref_reader_theme">Background color</string> <string name="pref_reader_theme">Background color</string>
<string name="white_background">White</string> <string name="white_background">White</string>
<string name="gray_background">Gray</string> <string name="gray_background">Gray</string>