Skip to content

Commit

Permalink
merge34
Browse files Browse the repository at this point in the history
  • Loading branch information
LuftVerbot committed Jul 9, 2023
1 parent afb88c9 commit 6b084c6
Show file tree
Hide file tree
Showing 74 changed files with 268 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fun TabbedDialog(
TabRow(
modifier = Modifier.weight(1f),
selectedTabIndex = pagerState.currentPage,
indicator = { TabIndicator(it[pagerState.currentPage]) },
indicator = { TabIndicator(it[pagerState.currentPage], pagerState.currentPageOffsetFraction) },
divider = {},
) {
tabTitles.fastForEachIndexed { i, tab ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fun TabbedScreen(
FlexibleTabRow(
scrollable = scrollable,
selectedTabIndex = state.currentPage,
indicator = { TabIndicator(it[state.currentPage]) },
indicator = { TabIndicator(it[state.currentPage], state.currentPageOffsetFraction) },
) {
tabs.forEachIndexed { index, tab ->
Tab(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,30 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import eu.kanade.presentation.category.visualName
import tachiyomi.domain.category.model.Category
import tachiyomi.presentation.core.components.PagerState
import tachiyomi.presentation.core.components.material.Divider
import tachiyomi.presentation.core.components.material.TabIndicator
import tachiyomi.presentation.core.components.material.TabText

@Composable
fun LibraryTabs(
categories: List<Category>,
currentPageIndex: Int,
pagerState: PagerState,
getNumberOfItemsForCategory: (Category) -> Int?,
onTabItemClick: (Int) -> Unit,
) {
Column {
ScrollableTabRow(
selectedTabIndex = currentPageIndex,
selectedTabIndex = pagerState.currentPage,
edgePadding = 0.dp,
indicator = { TabIndicator(it[currentPageIndex]) },
indicator = { TabIndicator(it[pagerState.currentPage], pagerState.currentPageOffsetFraction) },
// TODO: use default when width is fixed upstream
// https://issuetracker.google.com/issues/242879624
divider = {},
) {
categories.forEachIndexed { index, category ->
Tab(
selected = currentPageIndex == index,
selected = pagerState.currentPage == index,
onClick = { onTabItemClick(index) },
text = {
TabText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fun AnimeLibraryContent(
}
LibraryTabs(
categories = categories,
currentPageIndex = pagerState.currentPage,
pagerState = pagerState,
getNumberOfItemsForCategory = getNumberOfAnimeForCategory,
) { scope.launch { pagerState.animateScrollToPage(it) } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private fun ColumnScope.DisplayPage(
)
}

HeadingItem(R.string.badges_header)
HeadingItem(R.string.complications_header)
val downloadBadge by screenModel.libraryPreferences.downloadBadge().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_download_badge_anime),
Expand All @@ -210,6 +210,14 @@ private fun ColumnScope.DisplayPage(
screenModel.togglePreference(LibraryPreferences::languageBadge)
},
)
val showContinueViewingButton by screenModel.libraryPreferences.showContinueViewingButton().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_show_continue_reading_button),
checked = showContinueViewingButton,
onClick = {
screenModel.togglePreference(LibraryPreferences::showContinueViewingButton)
},
)

HeadingItem(R.string.tabs_header)
val categoryTabs by screenModel.libraryPreferences.categoryTabs().collectAsState()
Expand All @@ -228,14 +236,4 @@ private fun ColumnScope.DisplayPage(
screenModel.togglePreference(LibraryPreferences::categoryNumberOfItems)
},
)

HeadingItem(R.string.other_header)
val showContinueWatchingButton by screenModel.libraryPreferences.showContinueViewingButton().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_show_continue_reading_button),
checked = showContinueWatchingButton,
onClick = {
screenModel.togglePreference(LibraryPreferences::showContinueViewingButton)
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fun MangaLibraryContent(
}
LibraryTabs(
categories = categories,
currentPageIndex = pagerState.currentPage,
pagerState = pagerState,
getNumberOfItemsForCategory = getNumberOfMangaForCategory,
) { scope.launch { pagerState.animateScrollToPage(it) } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private fun ColumnScope.DisplayPage(
)
}

HeadingItem(R.string.badges_header)
HeadingItem(R.string.complications_header)
val downloadBadge by screenModel.libraryPreferences.downloadBadge().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_download_badge),
Expand All @@ -209,6 +209,14 @@ private fun ColumnScope.DisplayPage(
screenModel.togglePreference(LibraryPreferences::languageBadge)
},
)
val showContinueViewingButton by screenModel.libraryPreferences.showContinueViewingButton().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_show_continue_reading_button),
checked = showContinueViewingButton,
onClick = {
screenModel.togglePreference(LibraryPreferences::showContinueViewingButton)
},
)

HeadingItem(R.string.tabs_header)
val categoryTabs by screenModel.libraryPreferences.categoryTabs().collectAsState()
Expand All @@ -227,14 +235,4 @@ private fun ColumnScope.DisplayPage(
screenModel.togglePreference(LibraryPreferences::categoryNumberOfItems)
},
)

HeadingItem(R.string.other_header)
val showContinueReadingButton by screenModel.libraryPreferences.showContinueViewingButton().collectAsState()
CheckboxItem(
label = stringResource(R.string.action_display_show_continue_reading_button),
checked = showContinueReadingButton,
onClick = {
screenModel.togglePreference(LibraryPreferences::showContinueViewingButton)
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ object SettingsDownloadScreen : SearchableSettings {
pref = downloadPreferences.saveChaptersAsCBZ(),
title = stringResource(R.string.save_chapter_as_cbz),
),
Preference.PreferenceItem.SwitchPreference(
pref = downloadPreferences.splitTallImages(),
title = stringResource(R.string.split_tall_images),
subtitle = stringResource(R.string.split_tall_images_summary),
),
Preference.PreferenceItem.ListPreference(
pref = downloadPreferences.numberOfDownloads(),
title = stringResource(R.string.pref_download_slots),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,7 @@ class MangaDownloader(
}

// When the page is ready, set page path, progress (just in case) and status
val success = splitTallImageIfNeeded(page, tmpDir)
if (!success) {
notifier.onError(context.getString(R.string.download_notifier_split_failed), download.chapter.name, download.manga.title)
}
splitTallImageIfNeeded(page, tmpDir)
page.uri = file.uri
page.progress = 100
page.status = Page.State.READY
Expand Down Expand Up @@ -501,21 +498,18 @@ class MangaDownloader(
return ImageUtil.getExtensionFromMimeType(mime)
}

private fun splitTallImageIfNeeded(page: Page, tmpDir: UniFile): Boolean {
if (!downloadPreferences.splitTallImages().get()) return true

val filenamePrefix = String.format("%03d", page.number)
val imageFile = tmpDir.listFiles()?.firstOrNull { it.name.orEmpty().startsWith(filenamePrefix) }
?: throw Error(context.getString(R.string.download_notifier_split_page_not_found, page.number))
private fun splitTallImageIfNeeded(page: Page, tmpDir: UniFile) {
try {
val filenamePrefix = String.format("%03d", page.number)
val imageFile = tmpDir.listFiles()?.firstOrNull { it.name.orEmpty().startsWith(filenamePrefix) }
?: error(context.getString(R.string.download_notifier_split_page_not_found, page.number))

// If the original page was previously split, then skip
if (imageFile.name.orEmpty().startsWith("${filenamePrefix}__")) return true
// If the original page was previously split, then skip
if (imageFile.name.orEmpty().startsWith("${filenamePrefix}__")) return

return try {
ImageUtil.splitTallImage(tmpDir, imageFile, filenamePrefix)
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
false
logcat(LogPriority.ERROR, e) { "Failed to split downloaded image" }
}
}

Expand Down Expand Up @@ -550,14 +544,12 @@ class MangaDownloader(
}

download.status = if (downloadedImagesCount == downloadPageCount) {
// TODO: Uncomment when #8537 is resolved
// val chapterUrl = download.source.getChapterUrl(download.chapter)
// createComicInfoFile(
// tmpDir,
// download.manga,
// download.chapter.toDomainChapter()!!,
// chapterUrl,
// )
createComicInfoFile(
tmpDir,
download.manga,
download.chapter,
download.source,
)

// Only rename the directory if it's downloaded
if (downloadPreferences.saveChaptersAsCBZ().get()) {
Expand Down Expand Up @@ -611,23 +603,19 @@ class MangaDownloader(

/**
* Creates a ComicInfo.xml file inside the given directory.
*
* @param dir the directory in which the ComicInfo file will be generated.
* @param manga the manga.
* @param chapter the chapter.
* @param chapterUrl the resolved URL for the chapter.
*/
private fun createComicInfoFile(
dir: UniFile,
manga: Manga,
chapter: Chapter,
chapterUrl: String,
source: HttpSource,
) {
val chapterUrl = source.getChapterUrl(chapter.toSChapter())
val comicInfo = getComicInfo(manga, chapter, chapterUrl)
val comicInfoString = xml.encodeToString(ComicInfo.serializer(), comicInfo)
// Remove the old file
dir.findFile(COMIC_INFO_FILE)?.delete()
dir.createFile(COMIC_INFO_FILE).openOutputStream().use {
val comicInfoString = xml.encodeToString(ComicInfo.serializer(), comicInfo)
it.write(comicInfoString.toByteArray())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import eu.kanade.tachiyomi.util.removeCovers
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
Expand All @@ -48,7 +50,6 @@ import tachiyomi.core.util.system.logcat
import tachiyomi.domain.category.anime.interactor.GetAnimeCategories
import tachiyomi.domain.category.anime.interactor.SetAnimeCategories
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.entries.anime.interactor.GetAnime
import tachiyomi.domain.entries.anime.interactor.GetDuplicateLibraryAnime
import tachiyomi.domain.entries.anime.interactor.NetworkToLocalAnime
import tachiyomi.domain.entries.anime.model.Anime
Expand All @@ -72,7 +73,6 @@ class BrowseAnimeSourceScreenModel(
private val libraryPreferences: LibraryPreferences = Injekt.get(),
private val coverCache: AnimeCoverCache = Injekt.get(),
private val getRemoteAnime: GetRemoteAnime = Injekt.get(),
private val getAnime: GetAnime = Injekt.get(),
private val getDuplicateAnimelibAnime: GetDuplicateLibraryAnime = Injekt.get(),
private val getCategories: GetAnimeCategories = Injekt.get(),
private val getEpisodeByAnimeId: GetEpisodeByAnimeId = Injekt.get(),
Expand Down Expand Up @@ -122,11 +122,15 @@ class BrowseAnimeSourceScreenModel(
getRemoteAnime.subscribe(sourceId, listing.query ?: "", listing.filters)
}.flow.map { pagingData ->
pagingData
.map { withIOContext { networkToLocalAnime.await(it.toDomainAnime(sourceId)) } }
.filter { !sourcePreferences.hideInAnimeLibraryItems().get() || !it.favorite }
.map {
getAnime.subscribe(it.url, it.source)
flow {
val localAnime = withIOContext { networkToLocalAnime.await(it.toDomainAnime(sourceId)) }
emit(localAnime)
}
.filterNotNull()
.filter {
!sourcePreferences.hideInAnimeLibraryItems().get() || !it.favorite
}
.onEach(::initializeAnime)
.stateIn(coroutineScope)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import eu.kanade.tachiyomi.util.removeCovers
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
Expand All @@ -49,7 +51,6 @@ import tachiyomi.domain.category.manga.interactor.GetMangaCategories
import tachiyomi.domain.category.manga.interactor.SetMangaCategories
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.entries.manga.interactor.GetDuplicateLibraryManga
import tachiyomi.domain.entries.manga.interactor.GetManga
import tachiyomi.domain.entries.manga.interactor.NetworkToLocalManga
import tachiyomi.domain.entries.manga.model.Manga
import tachiyomi.domain.entries.manga.model.toMangaUpdate
Expand All @@ -72,7 +73,6 @@ class BrowseMangaSourceScreenModel(
private val libraryPreferences: LibraryPreferences = Injekt.get(),
private val coverCache: MangaCoverCache = Injekt.get(),
private val getRemoteManga: GetRemoteManga = Injekt.get(),
private val getManga: GetManga = Injekt.get(),
private val getDuplicateLibraryManga: GetDuplicateLibraryManga = Injekt.get(),
private val getCategories: GetMangaCategories = Injekt.get(),
private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(),
Expand Down Expand Up @@ -122,11 +122,15 @@ class BrowseMangaSourceScreenModel(
getRemoteManga.subscribe(sourceId, listing.query ?: "", listing.filters)
}.flow.map { pagingData ->
pagingData
.map { withIOContext { networkToLocalManga.await(it.toDomainManga(sourceId)) } }
.filter { !sourcePreferences.hideInMangaLibraryItems().get() || !it.favorite }
.map {
getManga.subscribe(it.url, it.source)
flow {
val localManga = withIOContext { networkToLocalManga.await(it.toDomainManga(sourceId)) }
emit(localManga)
}
.filterNotNull()
.filter {
!sourcePreferences.hideInMangaLibraryItems().get() || !it.favorite
}
.onEach(::initializeManga)
.stateIn(coroutineScope)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class DownloadPreferences(

fun saveChaptersAsCBZ() = preferenceStore.getBoolean("save_chapter_as_cbz", true)

fun splitTallImages() = preferenceStore.getBoolean("split_tall_images", false)

fun autoDownloadWhileReading() = preferenceStore.getInt("auto_download_while_reading", 0)
fun autoDownloadWhileWatching() = preferenceStore.getInt("auto_download_while_watching", 0)

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ junrar = "com.github.junrar:junrar:7.5.4"

sqlite-framework = { module = "androidx.sqlite:sqlite-framework", version.ref = "sqlite" }
sqlite-ktx = { module = "androidx.sqlite:sqlite-ktx", version.ref = "sqlite" }
sqlite-android = "com.github.requery:sqlite-android:3.39.2"
sqlite-android = "com.github.requery:sqlite-android:3.41.1"

preferencektx = "androidx.preference:preference-ktx:1.2.0"

Expand Down
12 changes: 6 additions & 6 deletions i18n/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,12 @@
<string name="action_global_search_query">إبحث عن \"%1$s\" بشكلٍ شامل</string>
<string name="updated_version">حُدِّث إلى الإصدار v%1$s</string>
<plurals name="missing_chapters_warning">
<item quantity="zero">لم يتخطَّى أيُّ فصل</item>
<item quantity="one">تُخطِّي فصل</item>
<item quantity="two">تُخطِّي فصلان</item>
<item quantity="few">تُخطِّيت %d فصول</item>
<item quantity="many">تُخطِّي %d فصلًا</item>
<item quantity="other">تُخطِّي %d فصل</item>
<item quantity="zero">لم يتم تخطِّي أي فصل</item>
<item quantity="one">تم تخطِّي فصل</item>
<item quantity="two">تم تخطِّي فصلان</item>
<item quantity="few">تم تخطِّي بعض الفصول</item>
<item quantity="many">تم تخطِّي فصول</item>
<item quantity="other">غير ذلك</item>
</plurals>
<string name="no_chapters_error">لم يتم العثور على الفصول</string>
<string name="share_page_info">%1$s: %2$s, صفحة %3$d</string>
Expand Down
1 change: 0 additions & 1 deletion i18n/src/main/res/values-b+es+419/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@
<string name="manga_tracking_tab">Seguimiento</string>
<string name="confirm_delete_chapters">¿Estás seguro de que deseas eliminar los capítulos seleccionados\?</string>
<string name="download_unread">No leídos</string>
<string name="download_all">Todo</string>
<string name="manga_download">Descargar</string>
<string name="sort_by_upload_date">Por fecha de subida</string>
<string name="sort_by_source">Por fuente</string>
Expand Down
1 change: 0 additions & 1 deletion i18n/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
<string name="sort_by_source">По източник</string>
<string name="sort_by_number">По ред на главите</string>
<string name="manga_download">Изтегли</string>
<string name="download_all">Всички</string>
<string name="download_unread">Непрочетени</string>
<string name="confirm_delete_chapters">Сигурни ли сте, че искате да изтриете избраните глави?</string>

Expand Down
Loading

0 comments on commit 6b084c6

Please sign in to comment.