Skip to content

Commit

Permalink
Merge branch 'master' into work-manager-2.8.0-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jays2Kings committed Apr 19, 2023
2 parents 3a0396d + c709206 commit 5418dba
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class ChapterCache(private val context: Context) {
*/
fun isImageInCache(imageUrl: String): Boolean {
return try {
diskCache.get(DiskUtil.hashKeyForDisk(imageUrl)) != null
diskCache.get(DiskUtil.hashKeyForDisk(imageUrl)).use { it != null }
} catch (e: IOException) {
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.data.notification.NotificationHandler
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.chapter.ChapterUtil.Companion.preferredChapterName
import eu.kanade.tachiyomi.util.lang.chop
import eu.kanade.tachiyomi.util.system.localeContext
import eu.kanade.tachiyomi.util.system.notificationBuilder
Expand Down Expand Up @@ -88,7 +89,8 @@ internal class DownloadNotifier(private val context: Context) {
if (download != null && !preferences.hideNotificationContent()) {
val title = download.manga.title.chop(15)
val quotedTitle = Pattern.quote(title)
val chapter = download.chapter.name.replaceFirst(
val name = download.chapter.preferredChapterName(context, download.manga, preferences)
val chapter = name.replaceFirst(
"$quotedTitle[\\s]*[-]*[\\s]*"
.toRegex(RegexOption.IGNORE_CASE),
"",
Expand Down Expand Up @@ -140,7 +142,8 @@ internal class DownloadNotifier(private val context: Context) {
} else {
val title = download.manga.title.chop(15)
val quotedTitle = Pattern.quote(title)
val chapter = download.chapter.name.replaceFirst(
val name = download.chapter.preferredChapterName(context, download.manga, preferences)
val chapter = name.replaceFirst(
"$quotedTitle[\\s]*[-]*[\\s]*".toRegex(RegexOption.IGNORE_CASE),
"",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.UnmeteredSource
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.util.chapter.ChapterUtil.Companion.preferredChapterName
import eu.kanade.tachiyomi.util.storage.DiskUtil
import eu.kanade.tachiyomi.util.storage.DiskUtil.NOMEDIA_FILE
import eu.kanade.tachiyomi.util.storage.saveTo
Expand Down Expand Up @@ -329,12 +330,10 @@ class Downloader(
val mangaDir = provider.getMangaDir(download.manga, download.source)

val availSpace = DiskUtil.getAvailableStorageSpace(mangaDir)
val chapName = download.chapter.preferredChapterName(context, download.manga, preferences)
if (availSpace != -1L && availSpace < MIN_DISK_SPACE) {
download.status = Download.State.ERROR
notifier.onError(
context.getString(R.string.couldnt_download_low_space),
download.chapter.name,
)
notifier.onError(context.getString(R.string.couldnt_download_low_space), chapName)
return
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
Expand All @@ -347,7 +346,7 @@ class Downloader(

notifier.onError(
context.getString(R.string.external_storage_download_notice),
download.chapter.name,
chapName,
download.manga.title,
intent,
)
Expand Down Expand Up @@ -416,7 +415,7 @@ class Downloader(
// If the page list threw, it will resume here
Timber.e(error)
download.status = Download.State.ERROR
notifier.onError(error.message, download.chapter.name, download.manga.title)
notifier.onError(error.message, chapName, download.manga.title)
}
}

Expand Down Expand Up @@ -448,6 +447,7 @@ class Downloader(
// Try to find the image file
val imageFile = tmpDir.listFiles()?.find { it.name!!.startsWith("$filename.") || it.name!!.startsWith("${filename}__001") }

val chapName = download.chapter.preferredChapterName(context, download.manga, preferences)
try {
// If the image is already downloaded, do nothing. Otherwise download from network
val file = when {
Expand All @@ -467,7 +467,7 @@ class Downloader(
if (!success) {
notifier.onError(
context.getString(R.string.download_notifier_split_failed),
download.chapter.name,
chapName,
download.manga.title,
)
}
Expand All @@ -479,7 +479,7 @@ class Downloader(
// Mark this page as error and allow to download the remaining
page.progress = 0
page.status = Page.State.ERROR
notifier.onError(e.message, download.chapter.name, download.manga.title)
notifier.onError(e.message, chapName, download.manga.title)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.util.chapter.ChapterUtil.Companion.preferredChapterName
import eu.kanade.tachiyomi.util.lang.chop
import eu.kanade.tachiyomi.util.system.notification
import eu.kanade.tachiyomi.util.system.notificationBuilder
Expand Down Expand Up @@ -176,7 +177,9 @@ class LibraryUpdateNotifier(private val context: Context) {
updates.forEach {
val manga = it.key
val chapters = it.value
val chapterNames = chapters.map { chapter -> chapter.name }
val chapterNames = chapters.map { chapter ->
chapter.preferredChapterName(context, manga, preferences)
}
notifications.add(
Pair(
context.notification(Notifications.CHANNEL_NEW_CHAPTERS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package eu.kanade.tachiyomi.ui.download
import android.view.MenuItem
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import uy.kohesive.injekt.injectLazy

/**
* Adapter storing a list of downloads.
Expand All @@ -19,6 +21,7 @@ class DownloadAdapter(controller: DownloadItemListener) : FlexibleAdapter<Abstra
* Listener called when an item of the list is released.
*/
val downloadItemListener: DownloadItemListener = controller
val preferences: PreferencesHelper by injectLazy()

interface DownloadItemListener {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.databinding.DownloadBottomSheetBinding
import eu.kanade.tachiyomi.ui.extension.ExtensionDividerItemDecoration
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.recents.RecentsController
import eu.kanade.tachiyomi.util.chapter.ChapterUtil.Companion.preferredChapterName
import eu.kanade.tachiyomi.util.view.collapse
import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsetsCompat
import eu.kanade.tachiyomi.util.view.expand
Expand Down Expand Up @@ -125,7 +126,7 @@ class DownloadBottomSheet @JvmOverloads constructor(
binding.titleText.text = if (extCount != null) {
resources.getString(
R.string.downloading_,
extCount.chapter.name,
extCount.chapter.preferredChapterName(context, extCount.manga, preferences),
)
} else {
""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.databinding.DownloadItemBinding
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.chapter.ChapterUtil.Companion.preferredChapterName
import eu.kanade.tachiyomi.util.view.setVectorCompat

/**
Expand Down Expand Up @@ -36,7 +37,8 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
fun bind(download: Download) {
this.download = download
// Update the chapter name.
binding.chapterTitle.text = download.chapter.name
binding.chapterTitle.text = download.chapter
.preferredChapterName(itemView.context, download.manga, adapter.preferences)

// Update the manga title
binding.title.text = download.manga.title
Expand Down
31 changes: 25 additions & 6 deletions app/src/main/java/eu/kanade/tachiyomi/ui/manga/EditMangaDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,20 @@ class EditMangaDialog : DialogController {
binding.addTagEditText.requestFocus()
showKeyboard()
}
binding.addTagEditText.setOnFocusChangeListener { v, hasFocus ->
if (!hasFocus && v.parent != null) {
addTags()
}
}
binding.addTagEditText.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
val tags: List<String> = binding.mangaGenresTags.tags.toList() + binding.addTagEditText.text.toString()
setGenreTags(tags)
binding.seriesType.setSelection(manga.seriesType(customTags = tags.joinToString(", ")) - 1)
addTags(true)
binding.addTagEditText.clearFocus()
binding.addTagEditText.setText("")
hideKeyboard()
} else {
binding.addTagChip.isVisible = true
binding.addTagEditText.isVisible = false
}
binding.addTagChip.isVisible = true
binding.addTagEditText.isVisible = false
true
}

Expand All @@ -221,6 +224,21 @@ class EditMangaDialog : DialogController {
}
}

private fun addTags(textCanBeBlank: Boolean = false) {
if ((textCanBeBlank || !binding.addTagEditText.text.isNullOrBlank()) &&
binding.addTagEditText.isVisible
) {
val newTags = binding.addTagEditText.text.toString().split(",")
.mapNotNull { tag -> tag.trim().takeUnless { it.isBlank() } }
val tags: List<String> = binding.mangaGenresTags.tags.toList() + newTags
binding.addTagEditText.setText("")
setGenreTags(tags)
binding.seriesType.setSelection(manga.seriesType(customTags = tags.joinToString(", ")) - 1)
binding.addTagChip.isVisible = true
binding.addTagEditText.isVisible = false
}
}

private fun TachiyomiTextInputEditText.appendOriginalTextOnLongClick(originalText: String?) {
setOnLongClickListener {
if (this.text.isNullOrBlank()) {
Expand Down Expand Up @@ -339,6 +357,7 @@ class EditMangaDialog : DialogController {
}

private fun onPositiveButtonClick() {
addTags()
infoController.presenter.updateManga(
binding.title.text.toString(),
binding.mangaAuthor.text.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ class ReaderActivity : BaseActivity<ReaderActivityBinding>() {
val text = "${manga.title}: ${if (chapter.isRecognizedNumber) {
getString(R.string.chapter_, decimalFormat.format(chapter.chapter_number))
} else {
chapter.name
chapter.preferredChapterName(this, manga, preferences)
}
}, $pageNumber"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import eu.kanade.tachiyomi.ui.reader.settings.OrientationType
import eu.kanade.tachiyomi.ui.reader.settings.ReadingModeType
import eu.kanade.tachiyomi.util.chapter.ChapterFilter
import eu.kanade.tachiyomi.util.chapter.ChapterSort
import eu.kanade.tachiyomi.util.chapter.ChapterUtil.Companion.preferredChapterName
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
import eu.kanade.tachiyomi.util.chapter.updateTrackChapterRead
import eu.kanade.tachiyomi.util.isLocal
Expand Down Expand Up @@ -734,14 +735,15 @@ class ReaderViewModel(
private fun saveImage(page: ReaderPage, directory: File, manga: Manga): File {
val stream = page.stream!!
val type = ImageUtil.findImageType(stream) ?: throw Exception("Not an image")
val context = Injekt.get<Application>()

directory.mkdirs()

val chapter = page.chapter.chapter

// Build destination file.
val filename = DiskUtil.buildValidFilename(
"${manga.title} - ${chapter.name}".take(225),
"${manga.title} - ${chapter.preferredChapterName(context, manga, preferences)}".take(225),
) + " - ${page.number}.${type.extension}"

val destFile = File(directory, filename)
Expand Down Expand Up @@ -771,10 +773,11 @@ class ReaderViewModel(
directory.mkdirs()

val chapter = page1.chapter.chapter
val context = Injekt.get<Application>()

// Build destination file.
val filename = DiskUtil.buildValidFilename(
"${manga.title} - ${chapter.name}".take(225),
"${manga.title} - ${chapter.preferredChapterName(context, manga, preferences)}".take(225),
) + " - ${page1.number}-${page2.number}.jpg"

val destFile = File(directory, filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ import androidx.core.view.isVisible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.ReaderTransitionViewBinding
import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition
import eu.kanade.tachiyomi.util.chapter.ChapterUtil.Companion.preferredChapterName
import eu.kanade.tachiyomi.util.system.contextCompatDrawable
import eu.kanade.tachiyomi.util.system.dpToPx
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import kotlin.math.roundToInt

class ReaderTransitionView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
LinearLayout(context, attrs) {

private val binding: ReaderTransitionViewBinding =
ReaderTransitionViewBinding.inflate(LayoutInflater.from(context), this, true)
private val preferences: PreferencesHelper by injectLazy()

init {
layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
Expand Down Expand Up @@ -57,12 +62,13 @@ class ReaderTransitionView @JvmOverloads constructor(context: Context, attrs: At
val isCurrentDownloaded = downloadManager.isChapterDownloaded(transition.from.chapter, manga)
binding.upperText.text = buildSpannedString {
bold { append(context.getString(R.string.previous_title)) }
append("\n${prevChapter.chapter.name}")
append("\n${prevChapter.chapter.preferredChapterName(context, manga, preferences)}")
if (isPrevDownloaded != isCurrentDownloaded) addDLImageSpan(isPrevDownloaded)
}
binding.lowerText.text = buildSpannedString {
bold { append(context.getString(R.string.current_chapter)) }
append("\n${transition.from.chapter.name}")
val name = transition.from.chapter.preferredChapterName(context, manga, preferences)
append("\n$name")
}
} else {
binding.upperText.textAlignment = TEXT_ALIGNMENT_CENTER
Expand All @@ -87,11 +93,12 @@ class ReaderTransitionView @JvmOverloads constructor(context: Context, attrs: At
val isNextDownloaded = downloadManager.isChapterDownloaded(nextChapter.chapter, manga)
binding.upperText.text = buildSpannedString {
bold { append(context.getString(R.string.finished_chapter)) }
append("\n${transition.from.chapter.name}")
val name = transition.from.chapter.preferredChapterName(context, manga, preferences)
append("\n$name")
}
binding.lowerText.text = buildSpannedString {
bold { append(context.getString(R.string.next_title)) }
append("\n${nextChapter.chapter.name}")
append("\n${nextChapter.chapter.preferredChapterName(context, manga, preferences)}")
if (isNextDownloaded != isCurrentDownloaded) addDLImageSpan(isNextDownloaded)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import kotlinx.coroutines.supervisorScope
import kotlinx.coroutines.suspendCancellableCoroutine
import timber.log.Timber
import java.io.BufferedInputStream
import java.io.InputStream

Expand Down Expand Up @@ -231,14 +232,19 @@ class WebtoonPageHolder(

val streamFn = page?.stream ?: return

val (openStream, isAnimated) = withIOContext {
val stream = streamFn().buffered(16)
val openStream = process(stream)
val (openStream, isAnimated) = try {
withIOContext {
val stream = streamFn().buffered(16)
val openStream = process(stream)

val isAnimated = ImageUtil.isAnimatedAndSupported(stream)
Pair(openStream, isAnimated)
val isAnimated = ImageUtil.isAnimatedAndSupported(stream)
Pair(openStream, isAnimated)
}
} catch (e: Exception) {
Timber.e(e)
setError()
return
}

withUIContext {
frame.setImage(
openStream,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/edit_manga_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:imeOptions="actionDone"
android:importantForAutofill="no"
android:hint="@string/add_tag"
android:inputType="text"
Expand Down

0 comments on commit 5418dba

Please sign in to comment.