diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 46c6c3cb..ab023cfe 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -377,7 +377,7 @@ + android:theme="@style/Theme.AppCompat" /> diff --git a/app/src/main/java/ani/dantotsu/MainActivity.kt b/app/src/main/java/ani/dantotsu/MainActivity.kt index 8c27a718..328e4a01 100644 --- a/app/src/main/java/ani/dantotsu/MainActivity.kt +++ b/app/src/main/java/ani/dantotsu/MainActivity.kt @@ -13,7 +13,6 @@ import android.os.Bundle import android.os.Handler import android.os.Looper import android.provider.Settings -import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.view.animation.AnticipateInterpolator @@ -34,8 +33,7 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.media3.common.util.UnstableApi import androidx.viewpager2.adapter.FragmentStateAdapter -import androidx.work.OneTimeWorkRequest -import ani.dantotsu.addons.torrent.ServerService +import ani.dantotsu.addons.torrent.TorrentServerService import ani.dantotsu.addons.torrent.TorrentAddonManager import ani.dantotsu.connections.anilist.Anilist import ani.dantotsu.connections.anilist.AnilistHomeViewModel @@ -49,8 +47,6 @@ import ani.dantotsu.home.MangaFragment import ani.dantotsu.home.NoInternet import ani.dantotsu.media.MediaDetailsActivity 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.profile.ProfileActivity import ani.dantotsu.profile.activity.FeedActivity @@ -456,8 +452,8 @@ class MainActivity : AppCompatActivity() { fun startTorrent() { if (torrentManager.isAvailable() && PrefManager.getVal(PrefName.TorrentEnabled)) { launchIO { - if (!ServerService.isRunning()) { - ServerService.start() + if (!TorrentServerService.isRunning()) { + TorrentServerService.start() } } } diff --git a/app/src/main/java/ani/dantotsu/addons/torrent/TorrentService.kt b/app/src/main/java/ani/dantotsu/addons/torrent/TorrentService.kt index 414df069..582bbf83 100644 --- a/app/src/main/java/ani/dantotsu/addons/torrent/TorrentService.kt +++ b/app/src/main/java/ani/dantotsu/addons/torrent/TorrentService.kt @@ -22,10 +22,10 @@ import uy.kohesive.injekt.api.get import kotlin.coroutines.EmptyCoroutineContext -class ServerService : Service() { +class TorrentServerService : Service() { private val serviceScope = CoroutineScope(EmptyCoroutineContext) private val applicationContext = Injekt.get() - private val extension = Injekt.get().extension!!.extension + private lateinit var extension: TorrentAddonApi override fun onBind(intent: Intent?): IBinder? = null @@ -34,6 +34,7 @@ class ServerService : Service() { flags: Int, startId: Int, ): Int { + extension = Injekt.get().extension?.extension ?: return START_NOT_STICKY intent?.let { if (it.action != null) { when (it.action) { @@ -75,7 +76,7 @@ class ServerService : Service() { PendingIntent.getService( applicationContext, 0, - Intent(applicationContext, ServerService::class.java).apply { + Intent(applicationContext, TorrentServerService::class.java).apply { action = ACTION_STOP }, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE, @@ -113,7 +114,7 @@ class ServerService : Service() { with(Injekt.get().getSystemService(ACTIVITY_SERVICE) as ActivityManager) { @Suppress("DEPRECATION") // We only need our services 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 } } @@ -122,9 +123,12 @@ class ServerService : Service() { } fun start() { + if (Injekt.get().extension?.extension == null) { + return + } try { val intent = - Intent(Injekt.get(), ServerService::class.java).apply { + Intent(Injekt.get(), TorrentServerService::class.java).apply { action = ACTION_START } Injekt.get().startService(intent) @@ -137,7 +141,7 @@ class ServerService : Service() { fun stop() { try { val intent = - Intent(Injekt.get(), ServerService::class.java).apply { + Intent(Injekt.get(), TorrentServerService::class.java).apply { action = ACTION_STOP } Injekt.get().startService(intent) diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsAddonActivity.kt b/app/src/main/java/ani/dantotsu/settings/SettingsAddonActivity.kt index 205d4833..dd8f7c5f 100644 --- a/app/src/main/java/ani/dantotsu/settings/SettingsAddonActivity.kt +++ b/app/src/main/java/ani/dantotsu/settings/SettingsAddonActivity.kt @@ -11,7 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import ani.dantotsu.R import ani.dantotsu.addons.AddonDownloader 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.databinding.ActivitySettingsAddonsBinding import ani.dantotsu.databinding.ItemSettingsBinding @@ -141,7 +141,7 @@ class SettingsAddonActivity : AppCompatActivity() { } it.settingsIconRight.setOnClickListener { _ -> if (it.settingsDesc.text == getString(R.string.installed)) { - ServerService.stop() + TorrentServerService.stop() torrentAddonManager.uninstall() return@setOnClickListener } else { @@ -190,14 +190,14 @@ class SettingsAddonActivity : AppCompatActivity() { Injekt.get().extension?.let { if (isChecked) { lifecycleScope.launchIO { - if (!ServerService.isRunning()) { - ServerService.start() + if (!TorrentServerService.isRunning()) { + TorrentServerService.start() } } } else { lifecycleScope.launchIO { - if (ServerService.isRunning()) { - ServerService.stop() + if (TorrentServerService.isRunning()) { + TorrentServerService.stop() } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt index 673ef920..fe81aa19 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt @@ -10,7 +10,6 @@ import ani.dantotsu.addons.torrent.TorrentAddonManager import ani.dantotsu.media.AddonType import ani.dantotsu.media.MediaType import ani.dantotsu.parsers.novel.NovelExtensionManager -import ani.dantotsu.themes.ThemeManager import eu.kanade.tachiyomi.extension.InstallStep import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager @@ -38,8 +37,6 @@ class ExtensionInstallActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - ThemeManager(this).applyTheme() - if (intent.hasExtra(ExtensionInstaller.EXTRA_EXTENSION_TYPE)) mediaType = intent.getSerializableExtraCompat(ExtensionInstaller.EXTRA_EXTENSION_TYPE) @@ -86,6 +83,7 @@ class ExtensionInstallActivity : AppCompatActivity() { } } + @Suppress("all") private fun checkInstallationResult(resultCode: Int) { val downloadId = intent.extras!!.getLong(ExtensionInstaller.EXTRA_DOWNLOAD_ID) val newStep = when (resultCode) { @@ -103,11 +101,9 @@ class ExtensionInstallActivity : AppCompatActivity() { Injekt.get().updateInstallStep(downloadId, newStep) } - MediaType.NOVEL -> { + else -> { Injekt.get().updateInstallStep(downloadId, newStep) } - - null -> {} } } else { when (addonType) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt index 4d7a0fed..a2f9e83d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt @@ -62,7 +62,9 @@ class ExtensionInstaller(private val context: Context) { * step in the installation process. * * @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 downloadAndInstall( url: String,