diff --git a/app/build.gradle b/app/build.gradle index 1d643d0227..561e619112 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -129,7 +129,7 @@ dependencies { implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0' implementation 'com.alexvasilkov:gesture-views:2.8.3' implementation 'com.github.VipulOG:ebook-reader:0.1.6' - implementation 'androidx.paging:paging-runtime-ktx:3.3.0' + implementation 'androidx.paging:paging-runtime-ktx:3.2.1' implementation 'com.github.eltos:simpledialogfragments:v3.7' implementation 'com.github.AAChartModel:AAChartCore-Kotlin:7.2.1' diff --git a/app/src/main/java/ani/dantotsu/Functions.kt b/app/src/main/java/ani/dantotsu/Functions.kt index fb676247be..e7f8304eca 100644 --- a/app/src/main/java/ani/dantotsu/Functions.kt +++ b/app/src/main/java/ani/dantotsu/Functions.kt @@ -96,10 +96,12 @@ import ani.dantotsu.connections.bakaupdates.MangaUpdates import ani.dantotsu.connections.crashlytics.CrashlyticsInterface import ani.dantotsu.databinding.ItemCountDownBinding import ani.dantotsu.media.Media +import ani.dantotsu.media.MediaDetailsActivity import ani.dantotsu.notifications.IncognitoNotificationClickReceiver import ani.dantotsu.others.ImageViewDialog import ani.dantotsu.others.SpoilerPlugin import ani.dantotsu.parsers.ShowResponse +import ani.dantotsu.profile.ProfileActivity import ani.dantotsu.settings.saving.PrefManager import ani.dantotsu.settings.saving.PrefName import ani.dantotsu.settings.saving.internal.PreferenceKeystore @@ -118,6 +120,7 @@ import com.bumptech.glide.load.resource.gif.GifDrawable import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.Target +import com.bumptech.glide.request.target.ViewTarget import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -344,7 +347,8 @@ open class BottomSheetDialogFragment : BottomSheetDialogFragment() { val behavior = BottomSheetBehavior.from(requireView().parent as View) behavior.state = BottomSheetBehavior.STATE_EXPANDED } - window.navigationBarColor = requireContext().getThemeColor(com.google.android.material.R.attr.colorSurface) + window.navigationBarColor = + requireContext().getThemeColor(com.google.android.material.R.attr.colorSurface) } } @@ -643,7 +647,8 @@ fun ImageView.loadImage(file: FileUrl?, width: Int = 0, height: Int = 0) { .override(width, height).into(this) } else { val glideUrl = GlideUrl(file.url) { file.headers } - Glide.with(this.context).load(glideUrl).transition(withCrossFade()).override(width, height) + Glide.with(this.context).load(glideUrl).transition(withCrossFade()) + .override(width, height) .into(this) } } @@ -1389,18 +1394,21 @@ fun blurImage(imageView: ImageView, banner: String?) { imageView.setImageResource(R.drawable.linear_gradient_bg) } } + fun Context.getThemeColor(@AttrRes attribute: Int): Int { val typedValue = TypedValue() theme.resolveAttribute(attribute, typedValue, true) return typedValue.data } + fun ImageView.openImage(title: String, image: String) { - setOnLongClickListener{ + setOnLongClickListener { ImageViewDialog.newInstance( context as FragmentActivity, title, image ) } } + /** * Builds the markwon instance with all the plugins * @return the markwon instance @@ -1416,7 +1424,36 @@ fun buildMarkwon( .usePlugin(object : AbstractMarkwonPlugin() { override fun configureConfiguration(builder: MarkwonConfiguration.Builder) { builder.linkResolver { _, link -> - copyToClipboard(link, true) + if (link.startsWith("https://anilist.co/anime/") || link.startsWith("https://anilist.co/manga/")) { + val mangaAnime = link.substringAfter("https://anilist.co/").substringBefore("/") + val id = + link.substringAfter("https://anilist.co/$mangaAnime/").substringBefore("/") + .toIntOrNull() + if (id != null && currContext() != null) { + ContextCompat.startActivity( + currContext()!!, + Intent(currContext()!!, MediaDetailsActivity::class.java) + .putExtra("mediaId", id), + null + ) + } else { + copyToClipboard(link, true) + } + } else if (link.startsWith("https://anilist.co/user/")) { + val username = link.substringAfter("https://anilist.co/user/").substringBefore("/") + if (currContext() != null) { + ContextCompat.startActivity( + currContext()!!, + Intent(currContext()!!, ProfileActivity::class.java) + .putExtra("username", username), + null + ) + } else { + copyToClipboard(link, true) + } + } else { + copyToClipboard(link, true) + } } } }) diff --git a/app/src/main/java/ani/dantotsu/addons/download/DownloadAddonApiV2.kt b/app/src/main/java/ani/dantotsu/addons/download/DownloadAddonApiV2.kt index a54d18861d..7637416bb5 100644 --- a/app/src/main/java/ani/dantotsu/addons/download/DownloadAddonApiV2.kt +++ b/app/src/main/java/ani/dantotsu/addons/download/DownloadAddonApiV2.kt @@ -35,4 +35,6 @@ interface DownloadAddonApiV2 { fun getStackTrace(sessionId: Long): String? fun hadError(sessionId: Long): Boolean + + fun getFileExtension(): Pair<String, String> = Pair("mkv", "video/x-matroska") } diff --git a/app/src/main/java/ani/dantotsu/download/DownloadCompat.kt b/app/src/main/java/ani/dantotsu/download/DownloadCompat.kt index a003bb6442..892c652141 100644 --- a/app/src/main/java/ani/dantotsu/download/DownloadCompat.kt +++ b/app/src/main/java/ani/dantotsu/download/DownloadCompat.kt @@ -347,7 +347,7 @@ class DownloadCompat { } @Deprecated("external storage is deprecated, use SAF instead") - fun removeDownloadCompat(context: Context, downloadedType: DownloadedType) { + fun removeDownloadCompat(context: Context, downloadedType: DownloadedType, toast: Boolean) { val directory = if (downloadedType.type == MediaType.MANGA) { File( context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), @@ -368,10 +368,13 @@ class DownloadCompat { // Check if the directory exists and delete it recursively if (directory.exists()) { val deleted = directory.deleteRecursively() - if (deleted) { - Toast.makeText(context, "Successfully deleted", Toast.LENGTH_SHORT).show() - } else { - Toast.makeText(context, "Failed to delete directory", Toast.LENGTH_SHORT).show() + if (toast) { + if (deleted) { + Toast.makeText(context, "Successfully deleted", Toast.LENGTH_SHORT).show() + } else { + Toast.makeText(context, "Failed to delete directory", Toast.LENGTH_SHORT) + .show() + } } } } diff --git a/app/src/main/java/ani/dantotsu/download/DownloadsManager.kt b/app/src/main/java/ani/dantotsu/download/DownloadsManager.kt index 6d3a25cf0d..3b44e66dd8 100644 --- a/app/src/main/java/ani/dantotsu/download/DownloadsManager.kt +++ b/app/src/main/java/ani/dantotsu/download/DownloadsManager.kt @@ -60,7 +60,7 @@ class DownloadsManager(private val context: Context) { toast: Boolean = true, onFinished: () -> Unit ) { - removeDownloadCompat(context, downloadedType) + removeDownloadCompat(context, downloadedType, toast) downloadsList.remove(downloadedType) CoroutineScope(Dispatchers.IO).launch { removeDirectory(downloadedType, toast) diff --git a/app/src/main/java/ani/dantotsu/download/anime/AnimeDownloaderService.kt b/app/src/main/java/ani/dantotsu/download/anime/AnimeDownloaderService.kt index 237d3b5367..ebeb17b413 100644 --- a/app/src/main/java/ani/dantotsu/download/anime/AnimeDownloaderService.kt +++ b/app/src/main/java/ani/dantotsu/download/anime/AnimeDownloaderService.kt @@ -225,14 +225,16 @@ class AnimeDownloaderService : Service() { task.episode ) ?: throw Exception("Failed to create output directory") - outputDir.findFile("${task.getTaskName().findValidName()}.mkv")?.delete() + val extension = ffExtension!!.getFileExtension() + outputDir.findFile("${task.getTaskName().findValidName()}.${extension.first}")?.delete() + val outputFile = - outputDir.createFile("video/x-matroska", "${task.getTaskName()}.mkv") + outputDir.createFile(extension.second, "${task.getTaskName()}.${extension.first}") ?: throw Exception("Failed to create output file") var percent = 0 var totalLength = 0.0 - val path = ffExtension!!.setDownloadPath( + val path = ffExtension.setDownloadPath( this@AnimeDownloaderService, outputFile.uri ) @@ -339,8 +341,9 @@ class AnimeDownloaderService : Service() { DownloadedType( task.title, task.episode, - MediaType.ANIME, - ) + MediaType.ANIME + ), + false ) {} Injekt.get<CrashlyticsInterface>().logException( Exception( diff --git a/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchFragment.kt b/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchFragment.kt index 363d233a43..32b90910bd 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchFragment.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchFragment.kt @@ -528,10 +528,11 @@ class AnimeWatchFragment : Fragment() { } toast(context.getString(R.string.success) + " (1)") } else { + val ffExtension = Injekt.get<DownloadAddonManager>().extension?.extension!! + val extension = ffExtension.getFileExtension() val tempFile = - directory.createFile("video/x-matroska", "temp.mkv") + directory.createFile(extension.second, "temp.${extension.first}") ?: throw Exception("Temp file is null") - val ffExtension = Injekt.get<DownloadAddonManager>().extension?.extension!! val tempPath = ffExtension.setDownloadPath( context, tempFile.uri diff --git a/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt b/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt index 7f3aba2145..b0bacad592 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt @@ -101,6 +101,7 @@ import androidx.mediarouter.app.MediaRouteButton import ani.dantotsu.GesturesListener import ani.dantotsu.NoPaddingArrayAdapter import ani.dantotsu.R +import ani.dantotsu.addons.download.DownloadAddonManager import ani.dantotsu.brightnessConverter import ani.dantotsu.circularReveal import ani.dantotsu.connections.anilist.Anilist @@ -1507,6 +1508,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL println(files) val docFile = directory.listFiles().firstOrNull { it.name?.endsWith(".mp4") == true || it.name?.endsWith(".mkv") == true + || it.name?.endsWith(".${Injekt.get<DownloadAddonManager>().extension?.extension?.getFileExtension()?.first ?: "ts"}") == true } if (docFile != null) { val uri = docFile.uri