fix: address deprecated code (#256)

* fix: address deprecated code

Build.RADIO has been deprecated since API 15, which means it hasn't worked since before the lowest target API of the app, and versioncode is deprecated in API 28.

* fix: use the convenience method

This takes the unused convenience method and the individually declared uses and merges them.

* fix: simplify compat switch
This commit is contained in:
TwistedUmbrellaX 2024-03-18 00:10:38 -04:00 committed by GitHub
parent 5c2ae57d77
commit cf10229574
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 26 deletions

View file

@ -54,6 +54,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import tachiyomi.core.util.lang.launchIO
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.io.File import java.io.File
@ -357,7 +358,7 @@ class AnimeDownloaderService : Service() {
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
private fun saveMediaInfo(task: AnimeDownloadTask) { private fun saveMediaInfo(task: AnimeDownloadTask) {
GlobalScope.launch(Dispatchers.IO) { launchIO {
val directory = File( val directory = File(
getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
"${DownloadsManager.animeLocation}/${task.title}" "${DownloadsManager.animeLocation}/${task.title}"

View file

@ -37,6 +37,7 @@ import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SChapterImpl import eu.kanade.tachiyomi.source.model.SChapterImpl
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred import kotlinx.coroutines.Deferred
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@ -47,6 +48,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import tachiyomi.core.util.lang.launchIO
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.io.File import java.io.File
@ -287,8 +289,9 @@ class MangaDownloaderService : Service() {
} }
} }
@OptIn(DelicateCoroutinesApi::class)
private fun saveMediaInfo(task: DownloadTask) { private fun saveMediaInfo(task: DownloadTask) {
GlobalScope.launch(Dispatchers.IO) { launchIO {
val directory = File( val directory = File(
getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
"Dantotsu/Manga/${task.title}" "Dantotsu/Manga/${task.title}"

View file

@ -31,6 +31,7 @@ import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SChapterImpl import eu.kanade.tachiyomi.source.model.SChapterImpl
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@ -42,6 +43,7 @@ import kotlinx.coroutines.withContext
import okhttp3.Request import okhttp3.Request
import okio.buffer import okio.buffer
import okio.sink import okio.sink
import tachiyomi.core.util.lang.launchIO
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.io.File import java.io.File
@ -347,8 +349,9 @@ class NovelDownloaderService : Service() {
} }
} }
@OptIn(DelicateCoroutinesApi::class)
private fun saveMediaInfo(task: DownloadTask) { private fun saveMediaInfo(task: DownloadTask) {
GlobalScope.launch(Dispatchers.IO) { launchIO {
val directory = File( val directory = File(
getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
"Dantotsu/Novel/${task.title}" "Dantotsu/Novel/${task.title}"

View file

@ -2,6 +2,7 @@ package ani.dantotsu.util
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import android.util.Log import android.util.Log
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import ani.dantotsu.BuildConfig import ani.dantotsu.BuildConfig
@ -31,8 +32,8 @@ object Logger {
} }
file?.writeText("log started\n") file?.writeText("log started\n")
file?.appendText("date/time: ${Date()}\n") file?.appendText("date/time: ${Date()}\n")
file?.appendText("device: ${android.os.Build.MODEL}\n") file?.appendText("device: ${Build.MODEL}\n")
file?.appendText("os version: ${android.os.Build.VERSION.RELEASE}\n") file?.appendText("os version: ${Build.VERSION.RELEASE}\n")
file?.appendText( file?.appendText(
"app version: ${ "app version: ${
context.packageManager.getPackageInfo( context.packageManager.getPackageInfo(
@ -46,29 +47,35 @@ object Logger {
context.packageManager.getPackageInfo( context.packageManager.getPackageInfo(
context.packageName, context.packageName,
0 0
).versionCode ).run {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
longVersionCode
else
@Suppress("DEPRECATION") versionCode
}
}\n" }\n"
) )
file?.appendText("sdk version: ${android.os.Build.VERSION.SDK_INT}\n") file?.appendText("sdk version: ${Build.VERSION.SDK_INT}\n")
file?.appendText("manufacturer: ${android.os.Build.MANUFACTURER}\n") file?.appendText("manufacturer: ${Build.MANUFACTURER}\n")
file?.appendText("brand: ${android.os.Build.BRAND}\n") file?.appendText("brand: ${Build.BRAND}\n")
file?.appendText("product: ${android.os.Build.PRODUCT}\n") file?.appendText("product: ${Build.PRODUCT}\n")
file?.appendText("device: ${android.os.Build.DEVICE}\n") file?.appendText("device: ${Build.DEVICE}\n")
file?.appendText("hardware: ${android.os.Build.HARDWARE}\n") file?.appendText("hardware: ${Build.HARDWARE}\n")
file?.appendText("host: ${android.os.Build.HOST}\n") file?.appendText("host: ${Build.HOST}\n")
file?.appendText("id: ${android.os.Build.ID}\n") file?.appendText("id: ${Build.ID}\n")
file?.appendText("type: ${android.os.Build.TYPE}\n") file?.appendText("type: ${Build.TYPE}\n")
file?.appendText("user: ${android.os.Build.USER}\n") file?.appendText("user: ${Build.USER}\n")
file?.appendText("tags: ${android.os.Build.TAGS}\n") file?.appendText("tags: ${Build.TAGS}\n")
file?.appendText("time: ${android.os.Build.TIME}\n") file?.appendText("time: ${Build.TIME}\n")
file?.appendText("radio: ${android.os.Build.RADIO}\n") file?.appendText("radio: ${Build.getRadioVersion()}\n")
file?.appendText("bootloader: ${android.os.Build.BOOTLOADER}\n") file?.appendText("bootloader: ${Build.BOOTLOADER}\n")
file?.appendText("board: ${android.os.Build.BOARD}\n") file?.appendText("board: ${Build.BOARD}\n")
file?.appendText("fingerprint: ${android.os.Build.FINGERPRINT}\n") file?.appendText("fingerprint: ${Build.FINGERPRINT}\n")
file?.appendText("supported_abis: ${android.os.Build.SUPPORTED_ABIS.joinToString()}\n") file?.appendText("supported_abis: ${Build.SUPPORTED_ABIS.joinToString()}\n")
file?.appendText("supported_32_bit_abis: ${android.os.Build.SUPPORTED_32_BIT_ABIS.joinToString()}\n") file?.appendText("supported_32_bit_abis: ${Build.SUPPORTED_32_BIT_ABIS.joinToString()}\n")
file?.appendText("supported_64_bit_abis: ${android.os.Build.SUPPORTED_64_BIT_ABIS.joinToString()}\n") file?.appendText("supported_64_bit_abis: ${Build.SUPPORTED_64_BIT_ABIS.joinToString()}\n")
file?.appendText("is emulator: ${android.os.Build.FINGERPRINT.contains("generic")}\n") file?.appendText("is emulator: ${Build.FINGERPRINT.contains("generic")}\n")
file?.appendText("--------------------------------\n") file?.appendText("--------------------------------\n")
} catch (e: Exception) { } catch (e: Exception) {
Injekt.get<CrashlyticsInterface>().logException(e) Injekt.get<CrashlyticsInterface>().logException(e)