Skip to content

Commit

Permalink
fix: smol fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed May 23, 2024
1 parent 773b7f5 commit 3d187a0
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
45 changes: 41 additions & 4 deletions app/src/main/java/ani/dantotsu/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
13 changes: 8 additions & 5 deletions app/src/main/java/ani/dantotsu/download/DownloadCompat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -339,8 +341,9 @@ class AnimeDownloaderService : Service() {
DownloadedType(
task.title,
task.episode,
MediaType.ANIME,
)
MediaType.ANIME
),
false
) {}
Injekt.get<CrashlyticsInterface>().logException(
Exception(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3d187a0

Please sign in to comment.