Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into aniyomi-mpv
Browse files Browse the repository at this point in the history
  • Loading branch information
jmir1 committed Apr 14, 2022
2 parents d250cbd + 5da2c82 commit 11d46ac
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 32 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ on:
- '**.md'
- 'app/src/main/res/**/strings.xml'

permissions:
contents: read

jobs:
build:
name: Build app
runs-on: ubuntu-latest

steps:
- name: Clone repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Dependency Review
uses: actions/dependency-review-action@v1

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
all_but_latest: true

- name: Clone repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
android:name=".App"
android:allowBackup="false"
android:hardwareAccelerated="true"
android:hasFragileUserData="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ class AnimelibUpdateNotifier(private val context: Context) {
Notifications.ID_LIBRARY_SKIPPED,
context.notificationBuilder(Notifications.CHANNEL_LIBRARY_SKIPPED) {
setContentTitle(context.resources.getString(R.string.notification_update_skipped, skipped))
setContentText(context.getString(R.string.learn_more))
setSmallIcon(R.drawable.ic_ani)
addAction(R.drawable.ic_help_24dp, context.getString(R.string.learn_more), NotificationHandler.openUrl(context, HELP_SKIPPED_URL))
setContentIntent(NotificationHandler.openUrl(context, HELP_SKIPPED_URL))
}
.build(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ class LibraryUpdateNotifier(private val context: Context) {
Notifications.ID_LIBRARY_SKIPPED,
context.notificationBuilder(Notifications.CHANNEL_LIBRARY_SKIPPED) {
setContentTitle(context.resources.getString(R.string.notification_update_skipped, skipped))
setContentText(context.getString(R.string.learn_more))
setSmallIcon(R.drawable.ic_ani)
addAction(R.drawable.ic_help_24dp, context.getString(R.string.learn_more), NotificationHandler.openUrl(context, HELP_SKIPPED_URL))
setContentIntent(NotificationHandler.openUrl(context, HELP_SKIPPED_URL))
}
.build(),
)
Expand Down
23 changes: 13 additions & 10 deletions app/src/main/java/eu/kanade/tachiyomi/data/saver/ImageSaver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import eu.kanade.tachiyomi.util.storage.DiskUtil
import eu.kanade.tachiyomi.util.storage.cacheImageDir
import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.ImageUtil
import eu.kanade.tachiyomi.util.system.logcat
import logcat.LogPriority
import okio.IOException
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
Expand All @@ -30,11 +32,7 @@ class ImageSaver(
val type = ImageUtil.findImageType(data) ?: throw Exception("Not an image")
val filename = DiskUtil.buildValidFilename("${image.name}.${type.extension}")

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
return save(data(), image.location.directory(context), filename)
}

if (image.location !is Location.Pictures) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || image.location !is Location.Pictures) {
return save(data(), image.location.directory(context), filename)
}

Expand All @@ -54,13 +52,18 @@ class ImageSaver(
val picture = context.contentResolver.insert(
pictureDir,
contentValues,
) ?: throw IOException("Couldn't create file")
) ?: throw IOException(context.getString(R.string.error_saving_picture))

data().use { input ->
@Suppress("BlockingMethodInNonBlockingContext")
context.contentResolver.openOutputStream(picture, "w").use { output ->
input.copyTo(output!!)
try {
data().use { input ->
@Suppress("BlockingMethodInNonBlockingContext")
context.contentResolver.openOutputStream(picture, "w").use { output ->
input.copyTo(output!!)
}
}
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
throw IOException(context.getString(R.string.error_saving_picture))
}

DiskUtil.scanMedia(context, picture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.network.await
import eu.kanade.tachiyomi.network.parseAs
import eu.kanade.tachiyomi.util.lang.withIOContext
import eu.kanade.tachiyomi.util.system.getInstallerPackageName
import uy.kohesive.injekt.injectLazy
import java.util.Date
import java.util.concurrent.TimeUnit
Expand All @@ -33,14 +34,19 @@ class AppUpdateChecker {

// Check if latest version is different from current version
if (isNewVersion(it.version)) {
AppUpdateResult.NewUpdate(it)
if (context.getInstallerPackageName() == "org.fdroid.fdroid") {
AppUpdateResult.NewUpdateFdroidInstallation
} else {
AppUpdateResult.NewUpdate(it)
}
} else {
AppUpdateResult.NoNewUpdate
}
}

if (result is AppUpdateResult.NewUpdate) {
AppUpdateNotifier(context).promptUpdate(result.release)
when (result) {
is AppUpdateResult.NewUpdate -> AppUpdateNotifier(context).promptUpdate(result.release)
is AppUpdateResult.NewUpdateFdroidInstallation -> AppUpdateNotifier(context).promptFdroidUpdate()
}

result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ internal class AppUpdateNotifier(private val context: Context) {
notificationBuilder.show()
}

/**
* Some people are still installing the app from F-Droid, so we avoid prompting GitHub-based
* updates.
*
* We can prompt them to migrate to the GitHub version though.
*/
fun promptFdroidUpdate() {
with(notificationBuilder) {
setContentTitle(context.getString(R.string.update_check_notification_update_available))
setContentText(context.getString(R.string.update_check_fdroid_migration_info))
setSmallIcon(R.drawable.ic_ani)
setContentIntent(NotificationHandler.openUrl(context, "https://tachiyomi.org/help/guides/troubleshooting/#unable-to-install-the-app-or-extensions"))
}
notificationBuilder.show()
}

/**
* Call when apk download starts.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package eu.kanade.tachiyomi.data.updater

sealed class AppUpdateResult {
class NewUpdate(val release: GithubRelease) : AppUpdateResult()
object NewUpdateFdroidInstallation : AppUpdateResult()
object NoNewUpdate : AppUpdateResult()
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class AndroidCookieJar : CookieJar {
}
}

fun remove(url: HttpUrl, cookieNames: List<String>? = null, maxAge: Int = -1) {
fun remove(url: HttpUrl, cookieNames: List<String>? = null, maxAge: Int = -1): Int {
val urlString = url.toString()
val cookies = manager.getCookie(urlString) ?: return
val cookies = manager.getCookie(urlString) ?: return 0

fun List<String>.filterNames(): List<String> {
return if (cookieNames != null) {
Expand All @@ -41,10 +41,11 @@ class AndroidCookieJar : CookieJar {
}
}

cookies.split(";")
return cookies.split(";")
.map { it.substringBefore("=") }
.filterNames()
.onEach { manager.setCookie(urlString, "$it=;Max-Age=$maxAge") }
.count()
}

fun removeAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
?.map { it.baseUrl }
?.distinct() ?: emptyList()

urls.forEach {
val cleared = urls.sumOf {
network.cookieManager.remove(it.toHttpUrl())
}

logcat { "Cleared cookies for: ${urls.joinToString()}" }
logcat { "Cleared $cleared cookies for: ${urls.joinToString()}" }
}

private fun Source.isEnabled(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.WebviewActivityBinding
import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
import eu.kanade.tachiyomi.util.system.WebViewClientCompat
import eu.kanade.tachiyomi.util.system.WebViewUtil
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.logcat
import eu.kanade.tachiyomi.util.system.openInBrowser
import eu.kanade.tachiyomi.util.system.setDefaultSettings
import eu.kanade.tachiyomi.util.system.toast
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import okhttp3.HttpUrl.Companion.toHttpUrl
import reactivecircus.flowbinding.appcompat.navigationClicks
import reactivecircus.flowbinding.swiperefreshlayout.refreshes
import uy.kohesive.injekt.injectLazy
Expand All @@ -37,11 +40,16 @@ class WebViewActivity : BaseActivity() {
private lateinit var binding: WebviewActivityBinding

private val sourceManager: SourceManager by injectLazy()
private val network: NetworkHelper by injectLazy()

private var bundle: Bundle? = null

private var isRefreshing: Boolean = false

init {
registerSecureActivity(this)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand Down Expand Up @@ -176,6 +184,7 @@ class WebViewActivity : BaseActivity() {
R.id.action_web_refresh -> refreshPage()
R.id.action_web_share -> shareWebpage()
R.id.action_web_browser -> openInBrowser()
R.id.action_clear_cookies -> clearCookies()
}
return super.onOptionsItemSelected(item)
}
Expand Down Expand Up @@ -207,8 +216,10 @@ class WebViewActivity : BaseActivity() {
openInBrowser(binding.webview.url!!, forceDefaultBrowser = true)
}

init {
registerSecureActivity(this)
private fun clearCookies() {
val url = binding.webview.url!!
val cleared = network.cookieManager.remove(url.toHttpUrl())
logcat { "Cleared $cleared cookies for: $url" }
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,19 @@ fun Context.isPackageInstalled(packageName: String): Boolean {
}
}

fun Context.getInstallerPackageName(): String? {
return try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
packageManager.getInstallSourceInfo(packageName).installingPackageName
} else {
@Suppress("DEPRECATION")
packageManager.getInstallerPackageName(packageName)
}
} catch (e: Exception) {
null
}
}

fun Context.getApplicationIcon(pkgName: String): Drawable? {
return try {
packageManager.getApplicationIcon(pkgName)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/webview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@
android:title="@string/action_open_in_browser"
app:showAsAction="never" />

<item
android:id="@+id/action_clear_cookies"
android:title="@string/pref_clear_cookies"
app:showAsAction="never" />

</menu>
14 changes: 8 additions & 6 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@
<string name="restrictions">Restrictions: %s</string>
<string name="only_update_restrictions">Only update: %s</string>

<string name="pref_library_update_manga_restriction">Skip updating</string>
<string name="pref_update_only_completely_read">Has unseen episodes/unread chapters</string>
<string name="pref_update_only_non_completed">Is completed series</string>
<string name="pref_update_only_started">No seen episodes/read chapters</string>
<string name="pref_library_update_show_tab_badge">Show unread/unseen count on Updates icon</string>
<string name="pref_library_update_manga_restriction">Skip updating titles</string>
<string name="pref_update_only_completely_read">With unseen episode(s)/unread chapter(s)</string>
<string name="pref_update_only_non_completed">With \"Completed\" status</string>
<string name="pref_update_only_started">That haven\'t been started</string>
<string name="pref_library_update_show_tab_badge">Show unseen/unread count on Updates icon</string>
<string name="pref_library_update_refresh_metadata">Automatically refresh metadata</string>
<string name="pref_library_update_refresh_metadata_summary">Check for new cover and details when updating library</string>
<string name="pref_library_update_refresh_trackers">Automatically refresh trackers</string>
Expand Down Expand Up @@ -781,6 +781,7 @@

<!-- Image notifier -->
<string name="picture_saved">Picture saved</string>
<string name="error_saving_picture">Error saving picture</string>

<!-- Reader activity -->
<string name="custom_filter">Custom filter</string>
Expand Down Expand Up @@ -875,7 +876,7 @@
</plurals>
<string name="notification_update_error">%1$d update(s) failed</string>
<string name="notification_update_skipped">%1$d update(s) skipped</string>
<string name="learn_more">Learn more</string>
<string name="learn_more">Tap to learn more</string>
<string name="notification_cover_update_failed">Failed to update cover</string>
<string name="notification_first_add_to_library">Please add the title to your library before doing this</string>
<string name="library_errors_help">For help on how to fix library update errors, see %1$s</string>
Expand All @@ -900,6 +901,7 @@
<string name="update_check_notification_download_complete">Download complete</string>
<string name="update_check_notification_download_error">Download error</string>
<string name="update_check_notification_update_available">New version available!</string>
<string name="update_check_fdroid_migration_info">A new version is available from the official releases. Tap to learn how to migrate from unofficial F-Droid releases.</string>

<!--Extension Updates Notifications-->
<plurals name="update_check_notification_ext_updates">
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ flowbinding-viewpager = { module = "io.github.reactivecircus.flowbinding:flowbin

logcat = "com.squareup.logcat:logcat:0.1"

acra-http = "ch.acra:acra-http:5.9.0"
acra-http = "ch.acra:acra-http:5.9.1"
firebase-analytics = "com.google.firebase:firebase-analytics-ktx:20.0.2"
firebase-crashlytics = "com.google.firebase:firebase-crashlytics-ktx:18.2.6"

Expand Down

0 comments on commit 11d46ac

Please sign in to comment.