fix: smol changes

This commit is contained in:
rebelonion 2024-04-30 19:39:19 -05:00
parent 2d2f058d27
commit 1431027cf3
6 changed files with 26 additions and 28 deletions

View file

@ -377,7 +377,7 @@
<activity <activity
android:name="eu.kanade.tachiyomi.extension.util.ExtensionInstallActivity" android:name="eu.kanade.tachiyomi.extension.util.ExtensionInstallActivity"
android:exported="false" android:exported="false"
android:theme="@android:style/Theme.Translucent.NoTitleBar" /> android:theme="@style/Theme.AppCompat" />
<receiver <receiver
android:name=".notifications.AlarmPermissionStateReceiver" android:name=".notifications.AlarmPermissionStateReceiver"
@ -441,7 +441,7 @@
android:exported="true" android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" /> android:permission="android.permission.BIND_JOB_SERVICE" />
<service <service
android:name=".addons.torrent.ServerService" android:name=".addons.torrent.TorrentServerService"
android:exported="false" android:exported="false"
android:foregroundServiceType="dataSync" android:foregroundServiceType="dataSync"
android:stopWithTask="true" /> android:stopWithTask="true" />

View file

@ -13,7 +13,6 @@ import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.provider.Settings import android.provider.Settings
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.animation.AnticipateInterpolator import android.view.animation.AnticipateInterpolator
@ -34,8 +33,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.media3.common.util.UnstableApi import androidx.media3.common.util.UnstableApi
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.work.OneTimeWorkRequest import ani.dantotsu.addons.torrent.TorrentServerService
import ani.dantotsu.addons.torrent.ServerService
import ani.dantotsu.addons.torrent.TorrentAddonManager import ani.dantotsu.addons.torrent.TorrentAddonManager
import ani.dantotsu.connections.anilist.Anilist import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.anilist.AnilistHomeViewModel import ani.dantotsu.connections.anilist.AnilistHomeViewModel
@ -49,8 +47,6 @@ import ani.dantotsu.home.MangaFragment
import ani.dantotsu.home.NoInternet import ani.dantotsu.home.NoInternet
import ani.dantotsu.media.MediaDetailsActivity import ani.dantotsu.media.MediaDetailsActivity
import ani.dantotsu.notifications.TaskScheduler import ani.dantotsu.notifications.TaskScheduler
import ani.dantotsu.notifications.anilist.AnilistNotificationWorker
import ani.dantotsu.notifications.comment.CommentNotificationWorker
import ani.dantotsu.others.CustomBottomDialog import ani.dantotsu.others.CustomBottomDialog
import ani.dantotsu.profile.ProfileActivity import ani.dantotsu.profile.ProfileActivity
import ani.dantotsu.profile.activity.FeedActivity import ani.dantotsu.profile.activity.FeedActivity
@ -456,8 +452,8 @@ class MainActivity : AppCompatActivity() {
fun startTorrent() { fun startTorrent() {
if (torrentManager.isAvailable() && PrefManager.getVal(PrefName.TorrentEnabled)) { if (torrentManager.isAvailable() && PrefManager.getVal(PrefName.TorrentEnabled)) {
launchIO { launchIO {
if (!ServerService.isRunning()) { if (!TorrentServerService.isRunning()) {
ServerService.start() TorrentServerService.start()
} }
} }
} }

View file

@ -22,10 +22,10 @@ import uy.kohesive.injekt.api.get
import kotlin.coroutines.EmptyCoroutineContext import kotlin.coroutines.EmptyCoroutineContext
class ServerService : Service() { class TorrentServerService : Service() {
private val serviceScope = CoroutineScope(EmptyCoroutineContext) private val serviceScope = CoroutineScope(EmptyCoroutineContext)
private val applicationContext = Injekt.get<Application>() private val applicationContext = Injekt.get<Application>()
private val extension = Injekt.get<TorrentAddonManager>().extension!!.extension private lateinit var extension: TorrentAddonApi
override fun onBind(intent: Intent?): IBinder? = null override fun onBind(intent: Intent?): IBinder? = null
@ -34,6 +34,7 @@ class ServerService : Service() {
flags: Int, flags: Int,
startId: Int, startId: Int,
): Int { ): Int {
extension = Injekt.get<TorrentAddonManager>().extension?.extension ?: return START_NOT_STICKY
intent?.let { intent?.let {
if (it.action != null) { if (it.action != null) {
when (it.action) { when (it.action) {
@ -75,7 +76,7 @@ class ServerService : Service() {
PendingIntent.getService( PendingIntent.getService(
applicationContext, applicationContext,
0, 0,
Intent(applicationContext, ServerService::class.java).apply { Intent(applicationContext, TorrentServerService::class.java).apply {
action = ACTION_STOP action = ACTION_STOP
}, },
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
@ -113,7 +114,7 @@ class ServerService : Service() {
with(Injekt.get<Application>().getSystemService(ACTIVITY_SERVICE) as ActivityManager) { with(Injekt.get<Application>().getSystemService(ACTIVITY_SERVICE) as ActivityManager) {
@Suppress("DEPRECATION") // We only need our services @Suppress("DEPRECATION") // We only need our services
getRunningServices(Int.MAX_VALUE).forEach { getRunningServices(Int.MAX_VALUE).forEach {
if (ServerService::class.java.name.equals(it.service.className)) { if (TorrentServerService::class.java.name.equals(it.service.className)) {
return true return true
} }
} }
@ -122,9 +123,12 @@ class ServerService : Service() {
} }
fun start() { fun start() {
if (Injekt.get<TorrentAddonManager>().extension?.extension == null) {
return
}
try { try {
val intent = val intent =
Intent(Injekt.get<Application>(), ServerService::class.java).apply { Intent(Injekt.get<Application>(), TorrentServerService::class.java).apply {
action = ACTION_START action = ACTION_START
} }
Injekt.get<Application>().startService(intent) Injekt.get<Application>().startService(intent)
@ -137,7 +141,7 @@ class ServerService : Service() {
fun stop() { fun stop() {
try { try {
val intent = val intent =
Intent(Injekt.get<Application>(), ServerService::class.java).apply { Intent(Injekt.get<Application>(), TorrentServerService::class.java).apply {
action = ACTION_STOP action = ACTION_STOP
} }
Injekt.get<Application>().startService(intent) Injekt.get<Application>().startService(intent)

View file

@ -11,7 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.addons.AddonDownloader import ani.dantotsu.addons.AddonDownloader
import ani.dantotsu.addons.download.DownloadAddonManager import ani.dantotsu.addons.download.DownloadAddonManager
import ani.dantotsu.addons.torrent.ServerService import ani.dantotsu.addons.torrent.TorrentServerService
import ani.dantotsu.addons.torrent.TorrentAddonManager import ani.dantotsu.addons.torrent.TorrentAddonManager
import ani.dantotsu.databinding.ActivitySettingsAddonsBinding import ani.dantotsu.databinding.ActivitySettingsAddonsBinding
import ani.dantotsu.databinding.ItemSettingsBinding import ani.dantotsu.databinding.ItemSettingsBinding
@ -141,7 +141,7 @@ class SettingsAddonActivity : AppCompatActivity() {
} }
it.settingsIconRight.setOnClickListener { _ -> it.settingsIconRight.setOnClickListener { _ ->
if (it.settingsDesc.text == getString(R.string.installed)) { if (it.settingsDesc.text == getString(R.string.installed)) {
ServerService.stop() TorrentServerService.stop()
torrentAddonManager.uninstall() torrentAddonManager.uninstall()
return@setOnClickListener return@setOnClickListener
} else { } else {
@ -190,14 +190,14 @@ class SettingsAddonActivity : AppCompatActivity() {
Injekt.get<TorrentAddonManager>().extension?.let { Injekt.get<TorrentAddonManager>().extension?.let {
if (isChecked) { if (isChecked) {
lifecycleScope.launchIO { lifecycleScope.launchIO {
if (!ServerService.isRunning()) { if (!TorrentServerService.isRunning()) {
ServerService.start() TorrentServerService.start()
} }
} }
} else { } else {
lifecycleScope.launchIO { lifecycleScope.launchIO {
if (ServerService.isRunning()) { if (TorrentServerService.isRunning()) {
ServerService.stop() TorrentServerService.stop()
} }
} }
} }

View file

@ -10,7 +10,6 @@ import ani.dantotsu.addons.torrent.TorrentAddonManager
import ani.dantotsu.media.AddonType import ani.dantotsu.media.AddonType
import ani.dantotsu.media.MediaType import ani.dantotsu.media.MediaType
import ani.dantotsu.parsers.novel.NovelExtensionManager import ani.dantotsu.parsers.novel.NovelExtensionManager
import ani.dantotsu.themes.ThemeManager
import eu.kanade.tachiyomi.extension.InstallStep import eu.kanade.tachiyomi.extension.InstallStep
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
@ -38,8 +37,6 @@ class ExtensionInstallActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
ThemeManager(this).applyTheme()
if (intent.hasExtra(ExtensionInstaller.EXTRA_EXTENSION_TYPE)) if (intent.hasExtra(ExtensionInstaller.EXTRA_EXTENSION_TYPE))
mediaType = mediaType =
intent.getSerializableExtraCompat<MediaType>(ExtensionInstaller.EXTRA_EXTENSION_TYPE) intent.getSerializableExtraCompat<MediaType>(ExtensionInstaller.EXTRA_EXTENSION_TYPE)
@ -86,6 +83,7 @@ class ExtensionInstallActivity : AppCompatActivity() {
} }
} }
@Suppress("all")
private fun checkInstallationResult(resultCode: Int) { private fun checkInstallationResult(resultCode: Int) {
val downloadId = intent.extras!!.getLong(ExtensionInstaller.EXTRA_DOWNLOAD_ID) val downloadId = intent.extras!!.getLong(ExtensionInstaller.EXTRA_DOWNLOAD_ID)
val newStep = when (resultCode) { val newStep = when (resultCode) {
@ -103,11 +101,9 @@ class ExtensionInstallActivity : AppCompatActivity() {
Injekt.get<MangaExtensionManager>().updateInstallStep(downloadId, newStep) Injekt.get<MangaExtensionManager>().updateInstallStep(downloadId, newStep)
} }
MediaType.NOVEL -> { else -> {
Injekt.get<NovelExtensionManager>().updateInstallStep(downloadId, newStep) Injekt.get<NovelExtensionManager>().updateInstallStep(downloadId, newStep)
} }
null -> {}
} }
} else { } else {
when (addonType) { when (addonType) {

View file

@ -62,7 +62,9 @@ class ExtensionInstaller(private val context: Context) {
* step in the installation process. * step in the installation process.
* *
* @param url The url of the apk. * @param url The url of the apk.
* @param extension The extension to install. * @param pkgName The package name of the extension.
* @param name The name of the extension.
* @param type The type of the extension.
*/ */
fun <T : Type> downloadAndInstall( fun <T : Type> downloadAndInstall(
url: String, url: String,