Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/aniyomiorg/aniyomi into s…
Browse files Browse the repository at this point in the history
…torage-viewer

# Conflicts:
#	app/src/main/java/eu/kanade/presentation/more/storage/CumulativeStorage.kt
#	app/src/main/java/eu/kanade/presentation/more/storage/StorageItem.kt
#	app/src/main/java/eu/kanade/presentation/more/storage/StorageScreenContent.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/storage/CommonStorageScreenModel.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/storage/anime/AnimeStorageScreenModel.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/storage/manga/MangaStorageScreenModel.kt
  • Loading branch information
logickoder committed Nov 3, 2023
2 parents c46266d + 5fd00d4 commit 50f3537
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 31 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
defaultConfig {
applicationId = "xyz.jmir.tachiyomi.mi"

versionCode = 104
versionCode = 105
versionName = "0.14.6"

buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")
Expand Down Expand Up @@ -273,6 +273,8 @@ dependencies {
implementation(libs.arthenica.smartexceptions)
// seeker seek bar
implementation(libs.seeker)
// true type parser
implementation(libs.truetypeparser)
}

androidComponents {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package eu.kanade.tachiyomi.data.download.anime

import android.content.Context
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.animesource.AnimeSource
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.data.download.anime.model.AnimeDownload
import eu.kanade.tachiyomi.util.size
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.drop
Expand All @@ -23,6 +25,9 @@ import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.entries.anime.model.Anime
import tachiyomi.domain.items.episode.model.Episode
import tachiyomi.domain.source.anime.service.AnimeSourceManager
import tachiyomi.source.local.entries.anime.LocalAnimeSource
import tachiyomi.source.local.io.ArchiveAnime
import tachiyomi.source.local.io.anime.LocalAnimeSourceFileSystem
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get

Expand Down Expand Up @@ -214,12 +219,39 @@ class AnimeDownloadManager(
}

/**
* Returns the amount of downloaded episodes for an anime.
* Returns the amount of downloaded/local episodes for an anime.
*
* @param anime the anime to check.
*/
fun getDownloadCount(anime: Anime): Int {
return cache.getDownloadCount(anime)
return if (anime.source == LocalAnimeSource.ID) {
LocalAnimeSourceFileSystem(context).getFilesInAnimeDirectory(anime.url)
.filter { ArchiveAnime.isSupported(it) }
.count()
} else {
cache.getDownloadCount(anime)
}
}

/**
* Returns the size of downloaded episodes.
*/
fun getDownloadSize(): Long {
return cache.getTotalDownloadSize()
}

/**
* Returns the size of downloaded/local episodes for an anime.
*
* @param anime the anime to check.
*/
fun getDownloadSize(anime: Anime): Long {
return if (anime.source == LocalAnimeSource.ID) {
LocalAnimeSourceFileSystem(context).getAnimeDirectory(anime.url)
.let { UniFile.fromFile(it) }?.size() ?: 0L
} else {
cache.getDownloadSize(anime)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package eu.kanade.tachiyomi.data.download.manga

import android.content.Context
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.manga.model.MangaDownload
import eu.kanade.tachiyomi.source.MangaSource
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.util.size
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.drop
Expand All @@ -22,6 +24,9 @@ import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.entries.manga.model.Manga
import tachiyomi.domain.items.chapter.model.Chapter
import tachiyomi.domain.source.manga.service.MangaSourceManager
import tachiyomi.source.local.entries.manga.LocalMangaSource
import tachiyomi.source.local.io.ArchiveManga
import tachiyomi.source.local.io.manga.LocalMangaSourceFileSystem
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get

Expand Down Expand Up @@ -193,12 +198,39 @@ class MangaDownloadManager(
}

/**
* Returns the amount of downloaded chapters for a manga.
* Returns the amount of downloaded/local chapters for a manga.
*
* @param manga the manga to check.
*/
fun getDownloadCount(manga: Manga): Int {
return cache.getDownloadCount(manga)
return if (manga.source == LocalMangaSource.ID) {
LocalMangaSourceFileSystem(context).getFilesInMangaDirectory(manga.url)
.filter { it.isDirectory || ArchiveManga.isSupported(it) }
.count()
} else {
cache.getDownloadCount(manga)
}
}

/**
* Returns the size of downloaded chapters.
*/
fun getDownloadSize(): Long {
return cache.getTotalDownloadSize()
}

/**
* Returns the size of downloaded/local episodes for an manga.
*
* @param manga the manga to check.
*/
fun getDownloadSize(manga: Manga): Long {
return if (manga.source == LocalMangaSource.ID) {
LocalMangaSourceFileSystem(context).getMangaDirectory(manga.url)
.let { UniFile.fromFile(it) }?.size() ?: 0L
} else {
cache.getDownloadSize(manga)
}
}

/**
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.media.AudioManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.os.Handler
import android.os.Looper
import android.os.ParcelFileDescriptor
Expand Down Expand Up @@ -573,6 +574,21 @@ class PlayerActivity : BaseActivity() {
MPVLib.setPropertyDouble("sub-delay", subtitlesDelay().get() / 1000.0)
}

MPVLib.setPropertyString(
"sub-fonts-dir",
File(
Environment.getExternalStorageDirectory().absolutePath + File.separator +
getString(R.string.app_name),
"fonts",
).path,
)

if (playerPreferences.subtitleFont().get().trim() != "") {
MPVLib.setPropertyString("sub-font", playerPreferences.subtitleFont().get())
} else {
MPVLib.setPropertyString("sub-font", "Sans Serif")
}

MPVLib.setPropertyString("sub-bold", if (boldSubtitles().get()) "yes" else "no")
MPVLib.setPropertyString("sub-italic", if (italicSubtitles().get()) "yes" else "no")
MPVLib.setPropertyInt("sub-font-size", subtitleFontSize().get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class PlayerPreferences(

fun overrideSubsASS() = preferenceStore.getBoolean("pref_override_subtitles_ass", false)

fun subtitleFont() = preferenceStore.getString("pref_subtitle_font", "Sans Serif")

fun subtitleFontSize() = preferenceStore.getInt("pref_subtitles_font_size", 55)
fun boldSubtitles() = preferenceStore.getBoolean("pref_bold_subtitles", false)
fun italicSubtitles() = preferenceStore.getBoolean("pref_italic_subtitles", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ fun TracksCatalogSheet(
onTrackSelected = onAudioSelected,
)

when {
isEpisodeOnline == true && page == 0 -> QualityTracksPage()
page == 0 || page == 1 -> SubtitleTracksPage()
page == 2 -> AudioTracksPage()
when (page) {
0 -> if (isEpisodeOnline == true) QualityTracksPage() else SubtitleTracksPage()
1 -> if (isEpisodeOnline == true) SubtitleTracksPage() else AudioTracksPage()
2 -> if (isEpisodeOnline == true) AudioTracksPage()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ private fun SubtitleColors(
val borderColorPref = screenModel.preferences.borderColorSubtitles()
val backgroundColorPref = screenModel.preferences.backgroundColorSubtitles()

val font by screenModel.preferences.subtitleFont().collectAsState()

Row(horizontalArrangement = Arrangement.SpaceEvenly, modifier = Modifier.fillMaxWidth()) {
SubtitleColorSelector(
label = R.string.player_subtitle_text_color,
Expand All @@ -89,6 +91,7 @@ private fun SubtitleColors(

Column(horizontalAlignment = Alignment.CenterHorizontally) {
SubtitlePreview(
font = font,
isBold = screenModel.preferences.boldSubtitles().collectAsState().value,
isItalic = screenModel.preferences.italicSubtitles().collectAsState().value,
textColor = Color(textColorPref.collectAsState().value),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
package eu.kanade.tachiyomi.ui.player.settings.sheets.subtitle

import android.os.Environment
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.material.SnackbarDefaults.backgroundColor
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.outlined.FormatBold
import androidx.compose.material.icons.outlined.FormatItalic
import androidx.compose.material.icons.outlined.FormatSize
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.yubyf.truetypeparser.TTFFile
import eu.kanade.presentation.components.DropdownMenu
import eu.kanade.presentation.components.OutlinedNumericChooser
import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R
Expand All @@ -29,6 +40,7 @@ import eu.kanade.tachiyomi.ui.player.settings.PlayerSettingsScreenModel
import `is`.xyz.mpv.MPVLib
import tachiyomi.presentation.core.components.material.ReadItemAlpha
import tachiyomi.presentation.core.components.material.padding
import java.io.File

@Composable
fun SubtitleFontPage(screenModel: PlayerSettingsScreenModel) {
Expand All @@ -41,6 +53,7 @@ fun SubtitleFontPage(screenModel: PlayerSettingsScreenModel) {
private fun SubtitleFont(
screenModel: PlayerSettingsScreenModel,
) {
val font by screenModel.preferences.subtitleFont().collectAsState()
val boldSubtitles by screenModel.preferences.boldSubtitles().collectAsState()
val italicSubtitles by screenModel.preferences.italicSubtitles().collectAsState()
val subtitleFontSize by screenModel.preferences.subtitleFontSize().collectAsState()
Expand All @@ -65,6 +78,30 @@ private fun SubtitleFont(
screenModel.preferences.subtitleFontSize().set(it)
}

val updateFont: (String) -> Unit = {
MPVLib.setPropertyString("sub-font", it)
screenModel.preferences.subtitleFont().set(it)
}

val context = LocalContext.current
val fontList by remember {
derivedStateOf {
val customFonts = File(
Environment.getExternalStorageDirectory().absolutePath +
File.separator + context.getString(R.string.app_name) +
File.separator,
"fonts",
).listFiles { file ->
file.extension.equals("ttf", true) ||
file.extension.equals("otf", true)
}?.associate {
TTFFile.open(it).families.values.toTypedArray()[0] to it.absolutePath
} ?: emptyMap()
mapOf("Sans Serif" to ("" to null)) + customFonts
}
}
var selectingFont by remember { mutableStateOf(false) }

Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(MaterialTheme.padding.tiny),
Expand All @@ -74,11 +111,13 @@ private fun SubtitleFont(
horizontalArrangement = Arrangement.SpaceEvenly,
modifier = Modifier.fillMaxWidth(),
) {
Icon(
imageVector = Icons.Outlined.FormatSize,
contentDescription = null,
modifier = Modifier.size(32.dp),
)
IconButton(onClick = { selectingFont = true }) {
Icon(
imageVector = Icons.Outlined.FormatSize,
contentDescription = null,
modifier = Modifier.size(32.dp),
)
}

OutlinedNumericChooser(
label = stringResource(id = R.string.player_font_size_text_field),
Expand Down Expand Up @@ -111,7 +150,26 @@ private fun SubtitleFont(
)
}

DropdownMenu(expanded = selectingFont, onDismissRequest = { selectingFont = false }) {
fontList.map {
val fontName = it.key
DropdownMenuItem(
text = { Text(fontName) },
onClick = { updateFont(fontName) },
trailingIcon = {
if (font == fontName) {
Icon(
imageVector = Icons.Default.Check,
contentDescription = null,
)
}
},
)
}
}

SubtitlePreview(
font = font,
isBold = boldSubtitles,
isItalic = italicSubtitles,
textColor = Color(textColor),
Expand Down
Loading

0 comments on commit 50f3537

Please sign in to comment.