Skip to content

Commit

Permalink
Merge remote-tracking branch 'j2k/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Saud-97 committed Nov 10, 2023
2 parents eda5370 + 6ed4ff0 commit 1467854
Show file tree
Hide file tree
Showing 24 changed files with 269 additions and 63 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ dependencies {
implementation("com.squareup.okhttp3:okhttp:$okhttpVersion")
implementation("com.squareup.okhttp3:logging-interceptor:$okhttpVersion")
implementation("com.squareup.okhttp3:okhttp-dnsoverhttps:$okhttpVersion")
implementation("com.squareup.okhttp3:okhttp-brotli:$okhttpVersion")
implementation("com.squareup.okio:okio:3.4.0")

// Chucker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ val libraryQuery =
"""
SELECT M.*, COALESCE(MC.${MangaCategory.COL_CATEGORY_ID}, 0) AS ${Manga.COL_CATEGORY}
FROM (
SELECT ${Manga.TABLE}.*, COALESCE(C.unread, 0) AS ${Manga.COL_UNREAD}, COALESCE(R.hasread, 0) AS ${Manga.COL_HAS_READ}, COALESCE(B.bookmarkCount, 0) AS ${Manga.COL_BOOKMARK_COUNT}
SELECT ${Manga.TABLE}.*, COALESCE(C.unread, '') AS ${Manga.COL_UNREAD}, COALESCE(R.hasread, '') AS ${Manga.COL_HAS_READ}, COALESCE(B.bookmarkCount, 0) AS ${Manga.COL_BOOKMARK_COUNT}
FROM ${Manga.TABLE}
LEFT JOIN (
SELECT ${Chapter.COL_MANGA_ID}, COUNT(*) AS unread
SELECT ${Chapter.COL_MANGA_ID}, GROUP_CONCAT(IFNULL(${Chapter.TABLE}.${Chapter.COL_SCANLATOR}, "N/A"), " [.] ") AS unread
FROM ${Chapter.TABLE}
WHERE ${Chapter.COL_READ} = 0
GROUP BY ${Chapter.COL_MANGA_ID}
) AS C
ON ${Manga.COL_ID} = C.${Chapter.COL_MANGA_ID}
LEFT JOIN (
SELECT ${Chapter.COL_MANGA_ID}, COUNT(*) AS hasread
SELECT ${Chapter.COL_MANGA_ID}, GROUP_CONCAT(IFNULL(${Chapter.TABLE}.${Chapter.COL_SCANLATOR}, "N/A"), " [.] ") AS hasread
FROM ${Chapter.TABLE}
WHERE ${Chapter.COL_READ} = 1
GROUP BY ${Chapter.COL_MANGA_ID}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.pushtorefresh.storio.sqlite.operations.get.DefaultGetResolver
import eu.kanade.tachiyomi.data.database.mappers.BaseMangaGetResolver
import eu.kanade.tachiyomi.data.database.models.LibraryManga
import eu.kanade.tachiyomi.data.database.tables.MangaTable
import eu.kanade.tachiyomi.util.chapter.ChapterUtil

class LibraryMangaGetResolver : DefaultGetResolver<LibraryManga>(), BaseMangaGetResolver {

Expand All @@ -16,11 +17,22 @@ class LibraryMangaGetResolver : DefaultGetResolver<LibraryManga>(), BaseMangaGet
val manga = LibraryManga()

mapBaseFromCursor(manga, cursor)
manga.unread = cursor.getInt(cursor.getColumnIndex(MangaTable.COL_UNREAD))
manga.unread = cursor.getString(cursor.getColumnIndex(MangaTable.COL_UNREAD))
.filterChaptersByScanlators(manga)
manga.category = cursor.getInt(cursor.getColumnIndex(MangaTable.COL_CATEGORY))
manga.read = cursor.getInt(cursor.getColumnIndex(MangaTable.COL_HAS_READ))
manga.read = cursor.getString(cursor.getColumnIndex(MangaTable.COL_HAS_READ))
.filterChaptersByScanlators(manga)
manga.bookmarkCount = cursor.getInt(cursor.getColumnIndex(MangaTable.COL_BOOKMARK_COUNT))

return manga
}

private fun String.filterChaptersByScanlators(manga: LibraryManga): Int {
if (isEmpty()) return 0
val list = split(" [.] ")
return manga.filtered_scanlators?.let { filteredScanlatorString ->
val filteredScanlators = ChapterUtil.getScanlators(filteredScanlatorString)
list.count { ChapterUtil.getScanlators(it).none { group -> filteredScanlators.contains(group) } }
} ?: list.size
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ class PreferencesHelper(val context: Context) {

fun downloadOnlyOverWifi() = prefs.getBoolean(Keys.downloadOnlyOverWifi, true)

fun folderPerManga() = flowPrefs.getBoolean("create_folder_per_manga", false)

fun librarySearchSuggestion() = flowPrefs.getString(Keys.librarySearchSuggestion, "")

fun showLibrarySearchSuggestions() = flowPrefs.getBoolean(Keys.showLibrarySearchSuggestions, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.network.interceptor.UncaughtExceptionInterceptor
import eu.kanade.tachiyomi.network.interceptor.UserAgentInterceptor
import okhttp3.Cache
import okhttp3.OkHttpClient
import okhttp3.brotli.BrotliInterceptor
import uy.kohesive.injekt.injectLazy
import java.io.File
import java.util.concurrent.TimeUnit
Expand All @@ -36,6 +37,7 @@ class NetworkHelper(val context: Context) {
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.callTimeout(2, TimeUnit.MINUTES)
.addInterceptor(BrotliInterceptor)
.addInterceptor(UncaughtExceptionInterceptor())
.addInterceptor(userAgentInterceptor)
.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import androidx.viewbinding.ViewBinding
import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.view.BackHandlerControllerInterface
import eu.kanade.tachiyomi.util.view.activityBinding
import eu.kanade.tachiyomi.util.view.backgroundColor
import eu.kanade.tachiyomi.util.view.isControllerVisible
import eu.kanade.tachiyomi.util.view.removeQueryListener
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -64,6 +67,7 @@ abstract class BaseController<VB : ViewBinding>(bundle: Bundle? = null) :

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View {
binding = createBinding(inflater)
binding.root.backgroundColor = binding.root.context.getResourceColor(R.attr.background)
return binding.root
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package eu.kanade.tachiyomi.ui.base.controller

import android.animation.Animator
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.view.View
import android.view.ViewGroup
import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.changehandler.AnimatorChangeHandler
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler

/**
* A variation of the original [FadeChangeHandler] that will cross fade two views, but keep
* the from view's alpha as 0
*/
class FadeChangeHandler : AnimatorChangeHandler {
constructor() : super()
constructor(removesFromViewOnPush: Boolean) : super(removesFromViewOnPush)
constructor(duration: Long) : super(duration)
constructor(duration: Long, removesFromViewOnPush: Boolean) : super(duration, removesFromViewOnPush)

override fun getAnimator(
container: ViewGroup,
from: View?,
to: View?,
isPush: Boolean,
toAddedToContainer: Boolean,
): Animator {
val animator = AnimatorSet()
if (to != null) {
val start = if (toAddedToContainer) 0F else to.alpha
animator.play(ObjectAnimator.ofFloat(to, View.ALPHA, start, 1f))
}
if (from != null && (!isPush || removesFromViewOnPush)) {
animator.play(ObjectAnimator.ofFloat(from, View.ALPHA, 0f))
}
return animator
}

override fun resetFromView(from: View) {}

override fun copy(): ControllerChangeHandler = eu.kanade.tachiyomi.ui.base.controller.FadeChangeHandler(animationDuration, removesFromViewOnPush)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import android.view.MenuItem
import android.view.View
import androidx.preference.DialogPreference
import androidx.preference.EditTextPreference
import androidx.preference.EditTextPreferenceDialogController
import androidx.preference.ListPreference
import androidx.preference.ListPreferenceDialogController
import androidx.preference.MultiSelectListPreference
import androidx.preference.MultiSelectListPreferenceDialogController
import androidx.preference.Preference
import androidx.preference.PreferenceGroupAdapter
import androidx.preference.PreferenceManager
Expand All @@ -39,6 +36,7 @@ import eu.kanade.tachiyomi.source.preferenceKey
import eu.kanade.tachiyomi.source.sourcePreferences
import eu.kanade.tachiyomi.ui.base.controller.BaseCoroutineController
import eu.kanade.tachiyomi.ui.setting.DSL
import eu.kanade.tachiyomi.ui.setting.defaultValue
import eu.kanade.tachiyomi.ui.setting.onChange
import eu.kanade.tachiyomi.ui.setting.switchPreference
import eu.kanade.tachiyomi.util.system.LocaleHelper
Expand All @@ -48,6 +46,9 @@ import eu.kanade.tachiyomi.util.view.scrollViewWith
import eu.kanade.tachiyomi.util.view.snack
import eu.kanade.tachiyomi.widget.LinearLayoutManagerAccurateOffset
import eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText.Companion.setIncognito
import eu.kanade.tachiyomi.widget.preference.EditTextResetPreference
import eu.kanade.tachiyomi.widget.preference.ListMatPreference
import eu.kanade.tachiyomi.widget.preference.MultiListMatPreference
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import okhttp3.HttpUrl.Companion.toHttpUrl
Expand Down Expand Up @@ -326,23 +327,53 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
screen.getPreference(it) === preference
}

val f = when (preference) {
is EditTextPreference ->
EditTextPreferenceDialogController
.newInstance(preference.getKey())
is ListPreference ->
ListPreferenceDialogController
.newInstance(preference.getKey())
is MultiSelectListPreference ->
MultiSelectListPreferenceDialogController
.newInstance(preference.getKey())
val context = preferences.context
val matPref = when (preference) {
is EditTextPreference -> EditTextResetPreference(activity, context).apply {
dialogSummary = preference.dialogMessage
onPreferenceChangeListener = preference.onPreferenceChangeListener
}

is ListPreference -> ListMatPreference(activity, context).apply {
isPersistent = false
defaultValue = preference.value
entries = preference.entries.map { it.toString() }
entryValues = preference.entryValues.map { it.toString() }
onChange {
if (preference.callChangeListener(it)) {
preference.value = it as? String
true
} else {
false
}
}
}

is MultiSelectListPreference -> MultiListMatPreference(activity, context).apply {
isPersistent = false
defaultValue = preference.values
entries = preference.entries.map { it.toString() }
entryValues = preference.entryValues.map { it.toString() }
onChange { newValue ->
if (newValue is Set<*> && preference.callChangeListener(newValue)) {
preference.values = newValue.map { it.toString() }.toSet()
true
} else {
false
}
}
}

else -> throw IllegalArgumentException(
"Tried to display dialog for unknown " +
"preference type. Did you forget to override onDisplayPreferenceDialog()?",
)
}
f.targetController = this
f.showDialog(router)
matPref.apply {
key = preference.key
preferenceDataStore = preference.preferenceDataStore
title = (preference as? DialogPreference)?.dialogTitle ?: preference.title
}.performClick()
}

private fun Source.isEnabled(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import android.os.Bundle
import androidx.core.view.isVisible
import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.ui.base.SmallToolbarInterface
import eu.kanade.tachiyomi.ui.base.controller.BaseController
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.base.controller.FadeChangeHandler
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,19 @@ class MangaDetailsPresenter(

fun saveCover(): Boolean {
return try {
val baseDir = Environment.getExternalStorageDirectory().absolutePath +
File.separator + Environment.DIRECTORY_PICTURES +
File.separator + preferences.context.getString(R.string.app_name)
val directory =
File(baseDir + File.separator + DiskUtil.buildValidFilename(manga.title))
val directory = if (preferences.folderPerManga().get()) {
val baseDir = Environment.getExternalStorageDirectory().absolutePath +
File.separator + Environment.DIRECTORY_PICTURES +
File.separator + preferences.context.getString(R.string.app_name)

File(baseDir + File.separator + DiskUtil.buildValidFilename(manga.title))
} else {
File(
Environment.getExternalStorageDirectory().absolutePath +
File.separator + Environment.DIRECTORY_PICTURES +
File.separator + preferences.context.getString(R.string.app_name),
)
}
val file = saveCover(directory)
DiskUtil.scanMedia(preferences.context, file)
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.core.graphics.ColorUtils
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Manga
Expand All @@ -29,6 +28,7 @@ import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.ui.base.controller.BaseController
import eu.kanade.tachiyomi.ui.base.controller.FadeChangeHandler
import eu.kanade.tachiyomi.ui.main.BottomNavBarInterface
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
import eu.kanade.tachiyomi.ui.migration.SearchController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,11 @@ class ReaderViewModel(
val baseDir = Environment.getExternalStorageDirectory().absolutePath +
File.separator + Environment.DIRECTORY_PICTURES +
File.separator + context.getString(R.string.app_name)
val destDir =
val destDir = if (preferences.folderPerManga().get()) {
File(baseDir + File.separator + DiskUtil.buildValidFilename(manga.title))
} else {
File(baseDir)
}

// Copy file in background.
viewModelScope.launchNonCancellable {
Expand Down Expand Up @@ -848,8 +851,11 @@ class ReaderViewModel(
val baseDir = Environment.getExternalStorageDirectory().absolutePath +
File.separator + Environment.DIRECTORY_PICTURES +
File.separator + context.getString(R.string.app_name)
val destDir =
val destDir = if (preferences.folderPerManga().get()) {
File(baseDir + File.separator + DiskUtil.buildValidFilename(manga.title))
} else {
File(baseDir)
}

try {
val file = saveImages(firstPage, secondPage, isLTR, bg, destDir, manga)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package eu.kanade.tachiyomi.ui.setting

import android.app.ActivityManager
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.core.content.getSystemService
import androidx.preference.PreferenceScreen
import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.main.FloatingSearchInterface
import eu.kanade.tachiyomi.ui.more.AboutController
import eu.kanade.tachiyomi.ui.setting.search.SettingsSearchController
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.view.activityBinding
import eu.kanade.tachiyomi.util.view.fadeTransactionHandler
import eu.kanade.tachiyomi.util.view.openInBrowser
import eu.kanade.tachiyomi.util.view.withFadeTransaction

Expand Down Expand Up @@ -108,7 +112,12 @@ class SettingsMainController : SettingsController(), FloatingSearchInterface {
}

override fun onActionViewExpand(item: MenuItem?) {
router.pushController(RouterTransaction.with(SettingsSearchController()))
val isLowRam = activity?.getSystemService<ActivityManager>()?.isLowRamDevice == true
router.pushController(
RouterTransaction.with(SettingsSearchController())
.pushChangeHandler(SimpleSwapChangeHandler(removesFromViewOnPush = isLowRam))
.popChangeHandler(fadeTransactionHandler()),
)
}

private fun navigateTo(controller: Controller) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,11 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.show_on_long_press
defaultValue = true
}
switchPreference {
bindTo(preferences.folderPerManga())
titleRes = R.string.save_pages_separately
summaryRes = R.string.create_folders_by_manga_title
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class BrowseSourceGridHolder(
.setParameter(MangaCoverFetcher.useCustomCover, false)
.build()
Coil.imageLoader(view.context).enqueue(request)

binding.coverThumbnail.alpha = if (manga.favorite) 0.34f else 1.0f
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class BrowseSourceListHolder(
.setParameter(MangaCoverFetcher.useCustomCover, false)
.build()
Coil.imageLoader(view.context).enqueue(request)

binding.coverThumbnail.alpha = if (manga.favorite) 0.34f else 1.0f
}
}
}
Loading

0 comments on commit 1467854

Please sign in to comment.