Skip to content

Commit

Permalink
Merge remote-tracking branch 'j2k/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/ISSUE_TEMPLATE.md
#	.github/ISSUE_TEMPLATE/feature_request.yml
#	.github/ISSUE_TEMPLATE/issue_report.yml
#	app/src/main/res/values-in/strings.xml
#	app/src/main/res/values-ko/strings.xml
#	build.gradle.kts
  • Loading branch information
Saud-97 committed Mar 14, 2023
2 parents 682cfc4 + b6d11b7 commit 63afbd6
Show file tree
Hide file tree
Showing 101 changed files with 3,049 additions and 1,330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.appwidget.components.CoverHeight
import eu.kanade.tachiyomi.appwidget.components.CoverWidth
import eu.kanade.tachiyomi.appwidget.components.LockedWidget
import eu.kanade.tachiyomi.appwidget.components.UpdatesWidget
import eu.kanade.tachiyomi.appwidget.util.appWidgetBackgroundRadius
import eu.kanade.tachiyomi.appwidget.util.calculateRowAndColumnCount
import eu.kanade.tachiyomi.data.database.models.Manga
Expand All @@ -33,7 +34,6 @@ import eu.kanade.tachiyomi.ui.recents.RecentsPresenter
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.launchIO
import kotlinx.coroutines.MainScope
import tachiyomi.presentation.widget.components.UpdatesWidget
import uy.kohesive.injekt.injectLazy
import java.util.Calendar
import java.util.Date
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tachiyomi.presentation.widget.components
package eu.kanade.tachiyomi.appwidget.components

import android.content.Intent
import android.graphics.Bitmap
Expand All @@ -19,16 +19,18 @@ import androidx.glance.layout.padding
import androidx.glance.text.Text
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.appwidget.ContainerModifier
import eu.kanade.tachiyomi.appwidget.components.UpdatesMangaCover
import eu.kanade.tachiyomi.appwidget.util.calculateRowAndColumnCount
import eu.kanade.tachiyomi.appwidget.util.stringResource
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.main.SearchActivity

@Composable
fun UpdatesWidget(data: List<Pair<Long, Bitmap?>>?) {
val (rowCount, columnCount) = LocalSize.current.calculateRowAndColumnCount()
val mainIntent = Intent(LocalContext.current, MainActivity::class.java).setAction(MainActivity.SHORTCUT_RECENTS)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
Column(
modifier = ContainerModifier,
modifier = ContainerModifier.clickable(actionStartActivity(mainIntent)),
verticalAlignment = Alignment.CenterVertically,
horizontalAlignment = Alignment.CenterHorizontally,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ package eu.kanade.tachiyomi.data.database.models
* @param chapter object containing chater
* @param history object containing history
*/
data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val history: History) {
data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val history: History, var extraChapters: List<ChapterHistory> = emptyList()) {

companion object {
fun createBlank() = MangaChapterHistory(MangaImpl(), ChapterImpl(), HistoryImpl())
}
}

data class ChapterHistory(val chapter: Chapter, var history: History? = null) : Chapter by chapter
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@ interface ChapterQueries : DbProvider {
.withQuery(
RawQuery.builder()
.query(getRecentsQuery(search.sqLite, offset, isResuming))
// .args(date.time, startDate.time)
.observesTables(ChapterTable.TABLE)
.build(),
)
.withGetResolver(MangaChapterGetResolver.INSTANCE)
.prepare()

/**
* Returns history of recent manga containing last read chapter in 25s
* @param date recent date range
* @offset offset the db by
*/
fun getUpdatedChaptersDistinct(search: String = "", offset: Int, isResuming: Boolean) = db.get()
.listOfObjects(MangaChapter::class.java)
.withQuery(
RawQuery.builder()
.query(getRecentsQueryDistinct(search.sqLite, offset, isResuming))
// .args(date.time, startDate.time)
.observesTables(ChapterTable.TABLE)
.build(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,6 @@ interface HistoryQueries : DbProvider {
// .withGetResolver(MangaChapterHistoryGetResolver.INSTANCE)
// .prepare()

/**
* Returns history of recent manga containing last read chapter in 25s
* @param date recent date range
* @offset offset the db by
*/
fun getRecentMangaLimit(search: String = "", offset: Int, isResuming: Boolean) = db.get()
.listOfObjects(MangaChapterHistory::class.java)
.withQuery(
RawQuery.builder()
.query(getRecentMangasLimitQuery(search.sqLite, offset, isResuming))
// .args(date.time, startDate.time)
.observesTables(HistoryTable.TABLE)
.build(),
)
.withGetResolver(MangaChapterHistoryGetResolver.INSTANCE)
.prepare()

/**
* Returns history of recent manga containing last read chapter in 25s
* @param date recent date range
Expand All @@ -62,7 +45,6 @@ interface HistoryQueries : DbProvider {
.withQuery(
RawQuery.builder()
.query(getRecentHistoryUngrouped(search.sqLite, offset, isResuming))
// .args(date.time, startDate.time)
.observesTables(HistoryTable.TABLE)
.build(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,6 @@ fun getRecentsQuery(search: String, offset: Int, isResuming: Boolean) =
${limitAndOffset(true, isResuming, offset)}
"""

/**
* Query to get the recently added manga
*/
fun getRecentAdditionsQuery(search: String, endless: Boolean, offset: Int, isResuming: Boolean) =
"""
SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, * FROM ${Manga.TABLE}
WHERE ${Manga.COL_FAVORITE} = 1
AND lower(${Manga.COL_TITLE}) LIKE '%$search%'
ORDER BY ${Manga.COL_DATE_ADDED} DESC
${limitAndOffset(endless, isResuming, offset)}
"""

fun limitAndOffset(endless: Boolean, isResuming: Boolean, offset: Int): String {
return when {
isResuming && endless && offset > 0 -> "LIMIT $offset"
Expand All @@ -81,60 +69,6 @@ fun limitAndOffset(endless: Boolean, isResuming: Boolean, offset: Int): String {
}
}

/**
* Query to get the manga with recently uploaded chapters
*/
fun getRecentsQueryDistinct(search: String, offset: Int = 0, isResuming: Boolean) =
"""
SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, ${Manga.TABLE}.*, ${Chapter.TABLE}.*
FROM ${Manga.TABLE}
JOIN ${Chapter.TABLE}
ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}
JOIN (
SELECT ${Chapter.TABLE}.${Chapter.COL_MANGA_ID},${Chapter.TABLE}.${Chapter.COL_ID},MAX(${Chapter.TABLE}.${Chapter.COL_DATE_FETCH})
FROM ${Chapter.TABLE} JOIN ${Manga.TABLE}
ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}
GROUP BY ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}) AS newest_chapter
ON ${Chapter.TABLE}.${Chapter.COL_MANGA_ID} = newest_chapter.${Chapter.COL_MANGA_ID}
WHERE ${Manga.COL_FAVORITE} = 1
AND newest_chapter.${Chapter.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_ID}
AND ${Chapter.COL_DATE_FETCH} > ${Manga.COL_DATE_ADDED}
AND lower(${Manga.COL_TITLE}) LIKE '%$search%'
ORDER BY ${Chapter.COL_DATE_FETCH} DESC
${limitAndOffset(true, isResuming, offset)}
"""

/**
* Query to get the recently read chapters of manga from the library up to a date.
* The max_last_read table contains the most recent chapters grouped by manga
* The select statement returns all information of chapters that have the same id as the chapter in max_last_read
* and are read after the given time period
*/
fun getRecentMangasLimitQuery(
search: String = "",
offset: Int = 0,
isResuming: Boolean,
) =
"""
SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, ${Manga.TABLE}.*, ${Chapter.TABLE}.*, ${History.TABLE}.*
FROM ${Manga.TABLE}
JOIN ${Chapter.TABLE}
ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}
JOIN ${History.TABLE}
ON ${Chapter.TABLE}.${Chapter.COL_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID}
JOIN (
SELECT ${Chapter.TABLE}.${Chapter.COL_MANGA_ID},${Chapter.TABLE}.${Chapter.COL_ID} as ${History.COL_CHAPTER_ID}, MAX(${History.TABLE}.${History.COL_LAST_READ}) as ${History.COL_LAST_READ}
FROM ${Chapter.TABLE} JOIN ${History.TABLE}
ON ${Chapter.TABLE}.${Chapter.COL_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID}
GROUP BY ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}) AS max_last_read
ON ${Chapter.TABLE}.${Chapter.COL_MANGA_ID} = max_last_read.${Chapter.COL_MANGA_ID}
AND max_last_read.${History.COL_CHAPTER_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID}
AND max_last_read.${History.COL_LAST_READ} > 0
AND lower(${Manga.TABLE}.${Manga.COL_TITLE}) LIKE '%$search%'
ORDER BY max_last_read.${History.COL_LAST_READ} DESC
${limitAndOffset(true, isResuming, offset)}
"""

/**
* Query to get the recently read chapters of manga from the library up to a date.
* The max_last_read table contains the most recent chapters grouped by manga
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class Download(val source: HttpSource, val manga: Manga, val chapter: Chapter) {
DOWNLOADING,
DOWNLOADED,
ERROR,

;

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ object PreferenceKeys {
const val groupChaptersHistory = "group_chapters_history"

const val showUpdatedTime = "show_updated_time"
const val groupChaptersUpdates = "group_chapters_updates"

const val categoryNumberOfItems = "display_number_of_items"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,12 @@ class PreferencesHelper(val context: Context) {

fun sortFetchedTime() = flowPrefs.getBoolean("sort_fetched_time", false)

fun groupChaptersUpdates() = flowPrefs.getBoolean(Keys.groupChaptersUpdates, false)
fun collapseGroupedUpdates() = flowPrefs.getBoolean("group_chapters_updates", false)

fun groupChaptersHistory() = flowPrefs.getBoolean(Keys.groupChaptersHistory, true)

fun collapseGroupedHistory() = flowPrefs.getBoolean("collapse_group_history", false)

fun showTitleFirstInRecents() = flowPrefs.getBoolean(Keys.showTitleFirstInRecents, false)

fun lastExtCheck() = flowPrefs.getLong("last_ext_check", 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.network.interceptor.CloudflareInterceptor
import eu.kanade.tachiyomi.network.interceptor.UncaughtExceptionInterceptor
import eu.kanade.tachiyomi.network.interceptor.UserAgentInterceptor
import okhttp3.Cache
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -31,6 +32,7 @@ class NetworkHelper(val context: Context) {
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.callTimeout(2, TimeUnit.MINUTES)
.addInterceptor(UncaughtExceptionInterceptor())
.addInterceptor(userAgentInterceptor)
.apply {
if (BuildConfig.DEBUG) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package eu.kanade.tachiyomi.network.interceptor

import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

/**
* Catches any uncaught exceptions from later in the chain and rethrows as a non-fatal
* IOException to avoid catastrophic failure.
*
* This should be the first interceptor in the client.
*
* See https://square.github.io/okhttp/4.x/okhttp/okhttp3/-interceptor/
*/
class UncaughtExceptionInterceptor : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
return try {
chain.proceed(chain.request())
} catch (e: Exception) {
throw IOException(e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MangaPlus : DelegatedHttpSource() {
return withContext(Dispatchers.IO) {
val response = network.client.newCall(request).await()
if (response.code != 200) throw Exception("HTTP error ${response.code}")
val body = response.body!!.string()
val body = response.body.string()
val match = titleIdRegex.find(body)
val titleId = match?.groupValues?.firstOrNull()?.substringAfterLast("/")
?: error("Title not found")
Expand All @@ -66,7 +66,7 @@ class MangaPlus : DelegatedHttpSource() {
manga.apply {
this.title = trimmedTitle
},
chapters.orEmpty(),
chapters,
)
} else {
null
Expand Down
87 changes: 30 additions & 57 deletions app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadButton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,40 @@ import eu.kanade.tachiyomi.util.system.getResourceColor
class DownloadButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
FrameLayout(context, attrs) {

var colorSecondary = context.getResourceColor(R.attr.colorSecondary)
var accentColor = context.getResourceColor(R.attr.colorSecondary)
set(value) {
field = value
activeColor = ColorUtils.blendARGB(
colorSecondary,
context.getResourceColor(R.attr.background),
0.05f,
)
downloadedColor = ColorUtils.blendARGB(
colorSecondary,
context.getResourceColor(R.attr.colorOnBackground),
0.3f,
)
activeColor = ColorUtils.blendARGB(value, bgColor, 0.05f)
downloadedColor = ColorUtils.blendARGB(value, cOnBgColor, 0.3f)
}
private var activeColor = ColorUtils.blendARGB(
colorSecondary,
context.getResourceColor(R.attr.background),
0.05f,
)
private val progressBGColor = ContextCompat.getColor(
context,
R.color.divider,
)
private val disabledColor = ContextCompat.getColor(
context,
R.color.material_on_surface_disabled,
)
private var downloadedColor = ColorUtils.blendARGB(
colorSecondary,
context.getResourceColor(R.attr.colorOnBackground),
0.3f,
)
private val bgColor = context.getResourceColor(R.attr.background)
private val cOnBgColor = context.getResourceColor(R.attr.colorOnBackground)
private var activeColor = ColorUtils.blendARGB(accentColor, bgColor, 0.05f)
private var downloadedColor = ColorUtils.blendARGB(accentColor, cOnBgColor, 0.3f)
private val progressBGColor by lazy { ContextCompat.getColor(context, R.color.divider) }
private val disabledColor by lazy {
ContextCompat.getColor(context, R.color.material_on_surface_disabled)
}
private val downloadedTextColor = context.getResourceColor(R.attr.background)
private val errorColor = ContextCompat.getColor(
context,
R.color.material_red_500,
)
private val filledCircle = ContextCompat.getDrawable(
context,
R.drawable.filled_circle,
)?.mutate()
private val borderCircle = ContextCompat.getDrawable(
context,
R.drawable.border_circle,
)?.mutate()
private val downloadDrawable = ContextCompat.getDrawable(
context,
R.drawable.ic_arrow_downward_24dp,
)?.mutate()
private val checkDrawable = ContextCompat.getDrawable(
context,
R.drawable.ic_check_24dp,
)?.mutate()
private val filledAnim = AnimatedVectorDrawableCompat.create(
context,
R.drawable.anim_outline_to_filled,
)
private val checkAnim = AnimatedVectorDrawableCompat.create(
context,
R.drawable.anim_dl_to_check_to_dl,
)
private val errorColor by lazy { ContextCompat.getColor(context, R.color.material_red_500) }
private val filledCircle by lazy {
ContextCompat.getDrawable(context, R.drawable.filled_circle)?.mutate()
}
private val borderCircle by lazy {
ContextCompat.getDrawable(context, R.drawable.border_circle)?.mutate()
}
private val downloadDrawable by lazy {
ContextCompat.getDrawable(context, R.drawable.ic_arrow_downward_24dp)?.mutate()
}
private val checkDrawable by lazy {
ContextCompat.getDrawable(context, R.drawable.ic_check_24dp)?.mutate()
}
private val filledAnim by lazy {
AnimatedVectorDrawableCompat.create(context, R.drawable.anim_outline_to_filled)
}
private val checkAnim by lazy {
AnimatedVectorDrawableCompat.create(context, R.drawable.anim_dl_to_check_to_dl)
}
private var isAnimating = false
private var iconAnimation: ObjectAnimator? = null

Expand Down
Loading

0 comments on commit 63afbd6

Please sign in to comment.