Skip to content

Commit

Permalink
manga "working" :D
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Oct 20, 2023
1 parent 57a584a commit 41b90e3
Show file tree
Hide file tree
Showing 32 changed files with 1,176 additions and 406 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Dantotsu is crafted from the ashes of Saikou and based on simplistic yet state-o
| Type | Status |
| ---------------- | ------- |
| Anime Extensions | Working |
| Manga Extensions | Not Working |
| Manga Extensions | "Working" |
| Light Novel Extensions | Not Working |


Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
minSdk 23
targetSdk 34
versionCode ((System.currentTimeMillis() / 60000).toInteger())
versionName "0.0.2"
versionName "0.1.0"
signingConfig signingConfigs.debug
}

Expand Down
14 changes: 13 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="eu.kanade.tachiyomi.extension.manga.util.MangaExtensionInstallActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:exported="false" />

<activity
android:name="eu.kanade.tachiyomi.extension.anime.util.AnimeExtensionInstallActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:exported="false" />

<receiver
android:name=".subcriptions.AlarmReceiver"
Expand Down Expand Up @@ -242,7 +251,10 @@
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
<service android:name=".aniyomi.anime.util.AnimeExtensionInstallService"
<service android:name="eu.kanade.tachiyomi.extension.manga.util.MangaExtensionInstallService"
android:exported="false" />

<service android:name="eu.kanade.tachiyomi.extension.anime.util.AnimeExtensionInstallService"
android:exported="false" />
</application>

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/ani/dantotsu/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ani.dantotsu

import android.animation.ObjectAnimator
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.drawable.Animatable
import android.net.Uri
import android.os.Build
Expand All @@ -17,6 +18,8 @@ import androidx.activity.addCallback
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.animation.doOnEnd
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.doOnAttach
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -222,6 +225,7 @@ class MainActivity : AppCompatActivity() {
}
}
}

}

//ViewPager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ani.dantotsu.aniyomi.anime.custom


import android.app.Application
import ani.dantotsu.media.manga.MangaCache
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
import tachiyomi.core.preference.PreferenceStore
import eu.kanade.domain.base.BasePreferences
Expand Down Expand Up @@ -31,6 +33,8 @@ class AppModule(val app: Application) : InjektModule {
explicitNulls = false
}
}

addSingletonFactory { MangaCache() }
}
}

Expand Down
42 changes: 35 additions & 7 deletions app/src/main/java/ani/dantotsu/media/MediaDetailsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ import ani.dantotsu.snackString
import ani.dantotsu.tryWithSuspend
import ani.dantotsu.currContext
import ani.dantotsu.R
import ani.dantotsu.parsers.AnimeSources
import ani.dantotsu.parsers.AniyomiAdapter
import ani.dantotsu.parsers.DynamicMangaParser
import ani.dantotsu.parsers.HAnimeSources
import ani.dantotsu.parsers.HMangaSources
import ani.dantotsu.parsers.MangaSources
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

class MediaDetailsViewModel : ViewModel() {
val scrolledToTop = MutableLiveData(true)
Expand All @@ -41,15 +49,34 @@ class MediaDetailsViewModel : ViewModel() {
}

fun loadSelected(media: Media): Selected {
return loadData<Selected>("${media.id}-select") ?: Selected().let {
it.source = if (media.isAdult) 0 else when (media.anime != null) {
true -> loadData("settings_def_anime_source") ?: 0
else -> loadData("settings_def_manga_source") ?: 0
val data = loadData<Selected>("${media.id}-select") ?: Selected().let {
it.source = if (media.isAdult) "" else when (media.anime != null) {
true -> loadData("settings_def_anime_source") ?: ""
else -> loadData("settings_def_manga_source") ?: ""
}
it.preferDub = loadData("settings_prefer_dub") ?: false
it.sourceIndex = loadSelectedStringLocation(it.source)
saveSelected(media.id, it)
it
}
if (media.anime != null) {
val sources = if (media.isAdult) HAnimeSources else AnimeSources
data.sourceIndex = sources.list.indexOfFirst { it.name == data.source }
} else {
val sources = if (media.isAdult) HMangaSources else MangaSources
data.sourceIndex = sources.list.indexOfFirst { it.name == data.source }
}
if (data.sourceIndex == -1) {
data.sourceIndex = 0
}
return data
}

fun loadSelectedStringLocation(sourceName: String): Int {
//find the location of the source in the list
var location = watchSources?.list?.indexOfFirst { it.name == sourceName } ?: 0
if (location == -1) {location = 0}
return location
}

var continueMedia: Boolean? = null
Expand Down Expand Up @@ -167,7 +194,8 @@ class MediaDetailsViewModel : ViewModel() {
val server = selected.server ?: return false
val link = ep.link ?: return false

ep.extractors = mutableListOf(watchSources?.get(selected.source)?.let {
ep.extractors = mutableListOf(watchSources?.get(loadSelectedStringLocation(selected.source))?.let {
selected.sourceIndex = loadSelectedStringLocation(selected.source)
if (!post && !it.allowsPreloading) null
else ep.sEpisode?.let { it1 ->
it.loadSingleVideoServer(server, link, ep.extra,
Expand Down Expand Up @@ -238,7 +266,7 @@ class MediaDetailsViewModel : ViewModel() {
suspend fun loadMangaChapterImages(chapter: MangaChapter, selected: Selected, post: Boolean = true): Boolean {
return tryWithSuspend(true) {
chapter.addImages(
mangaReadSources?.get(selected.source)?.loadImages(chapter.link, chapter.sChapter) ?: return@tryWithSuspend false
mangaReadSources?.get(loadSelectedStringLocation(selected.source))?.loadImages(chapter.link, chapter.sChapter) ?: return@tryWithSuspend false
)
if (post) mangaChapter.postValue(chapter)
true
Expand All @@ -261,7 +289,7 @@ class MediaDetailsViewModel : ViewModel() {
}

suspend fun autoSearchNovels(media: Media) {
val source = novelSources[media.selected?.source ?: 0]
val source = novelSources[loadSelectedStringLocation(media.selected?.source?:"")]
tryWithSuspend(post = true) {
if (source != null) {
novelResponses.postValue(source.sortedSearch(media))
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/ani/dantotsu/media/Selected.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ data class Selected(
var recyclerStyle: Int? = null,
var recyclerReversed: Boolean = false,
var chip: Int = 0,
var source: Int = 0,
var source: String = "",
var sourceIndex: Int = 0,
var preferDub: Boolean = false,
var server: String? = null,
var video: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SourceSearchDialogFragment : BottomSheetDialogFragment() {
binding.searchRecyclerView.visibility = View.GONE
binding.searchProgress.visibility = View.VISIBLE

i = media!!.selected!!.source
i = media!!.selected!!.sourceIndex

val source = if (media!!.anime != null) {
(if (!media!!.isAdult) AnimeSources else HAnimeSources)[i!!]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AnimeWatchAdapter(
}

//Source Selection
val source = media.selected!!.source.let { if (it >= watchSources.names.size) 0 else it }
val source = media.selected!!.sourceIndex.let { if (it >= watchSources.names.size) 0 else it }
if (watchSources.names.isNotEmpty() && source in 0 until watchSources.names.size) {
binding.animeSource.setText(watchSources.names[source])
watchSources[source].apply {
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/ani/dantotsu/media/anime/AnimeWatchFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class AnimeWatchFragment : Fragment() {
async { model.loadKitsuEpisodes(media) },
async { model.loadFillerEpisodes(media) }
)
model.loadEpisodes(media, media.selected!!.source)
model.loadEpisodes(media, media.selected!!.sourceIndex)
}
loaded = true
} else {
Expand All @@ -140,7 +140,7 @@ class AnimeWatchFragment : Fragment() {
}
model.getEpisodes().observe(viewLifecycleOwner) { loadedEpisodes ->
if (loadedEpisodes != null) {
val episodes = loadedEpisodes[media.selected!!.source]
val episodes = loadedEpisodes[media.selected!!.sourceIndex]
if (episodes != null) {
episodes.forEach { (i, episode) ->
if (media.anime?.fillerEpisodes != null) {
Expand Down Expand Up @@ -206,8 +206,8 @@ class AnimeWatchFragment : Fragment() {
media.anime?.episodes = null
reload()
val selected = model.loadSelected(media)
model.watchSources?.get(selected.source)?.showUserTextListener = null
selected.source = i
model.watchSources?.get(selected.sourceIndex)?.showUserTextListener = null
selected.sourceIndex = i
selected.server = null
model.saveSelected(media.id, selected, requireActivity())
media.selected = selected
Expand All @@ -216,11 +216,11 @@ class AnimeWatchFragment : Fragment() {

fun onDubClicked(checked: Boolean) {
val selected = model.loadSelected(media)
model.watchSources?.get(selected.source)?.selectDub = checked
model.watchSources?.get(selected.sourceIndex)?.selectDub = checked
selected.preferDub = checked
model.saveSelected(media.id, selected, requireActivity())
media.selected = selected
lifecycleScope.launch(Dispatchers.IO) { model.forceLoadEpisode(media, selected.source) }
lifecycleScope.launch(Dispatchers.IO) { model.forceLoadEpisode(media, selected.sourceIndex) }
}

fun loadEpisodes(i: Int) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener {
}

model.watchSources = if (media.isAdult) HAnimeSources else AnimeSources
serverInfo.text = model.watchSources!!.names.getOrNull(media.selected!!.source) ?: model.watchSources!!.names[0]
serverInfo.text = model.watchSources!!.names.getOrNull(media.selected!!.sourceIndex) ?: model.watchSources!!.names[0]

model.epChanged.observe(this) {
epChanging = !it
Expand Down Expand Up @@ -1353,7 +1353,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener {
if (media.selected!!.server != null)
model.loadEpisodeSingleVideo(ep, selected, false)
else
model.loadEpisodeVideos(ep, selected.source, false)
model.loadEpisodeVideos(ep, selected.sourceIndex, false)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
}
}
scope.launch(Dispatchers.IO) {
model.loadEpisodeVideos(ep, media!!.selected!!.source)
model.loadEpisodeVideos(ep, media!!.selected!!.sourceIndex)
withContext(Dispatchers.Main){
binding.selectorProgressBar.visibility = View.GONE
}
Expand Down
64 changes: 64 additions & 0 deletions app/src/main/java/ani/dantotsu/media/manga/MangaCache.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package ani.dantotsu.media.manga

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.util.LruCache
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

data class ImageData(
val page: Page,
val source: HttpSource,
){
suspend fun fetchAndProcessImage(page: Page, httpSource: HttpSource): Bitmap? {
return withContext(Dispatchers.IO) {
try {
// Fetch the image
val response = httpSource.getImage(page)

// Convert the Response to an InputStream
val inputStream = response.body?.byteStream()

// Convert InputStream to Bitmap
val bitmap = BitmapFactory.decodeStream(inputStream)

inputStream?.close()

return@withContext bitmap
} catch (e: Exception) {
// Handle any exceptions
println("An error occurred: ${e.message}")
return@withContext null
}
}
}
}

class MangaCache() {
private val maxMemory = (Runtime.getRuntime().maxMemory() / 1024 / 2).toInt()
private val cache = LruCache<String, ImageData>(maxMemory)

@Synchronized
fun put(key: String, imageDate: ImageData) {
cache.put(key, imageDate)
}

@Synchronized
fun get(key: String): ImageData? = cache.get(key)

@Synchronized
fun remove(key: String) {
cache.remove(key)
}

@Synchronized
fun clear() {
cache.evictAll()
}

fun size(): Int = cache.size()


}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MangaReadAdapter(
}

//Source Selection
val source = media.selected!!.source.let { if (it >= mangaReadSources.names.size) 0 else it }
val source = media.selected!!.sourceIndex.let { if (it >= mangaReadSources.names.size) 0 else it }
if (mangaReadSources.names.isNotEmpty() && source in 0 until mangaReadSources.names.size) {
binding.animeSource.setText(mangaReadSources.names[source])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ open class MangaReadFragment : Fragment() {
binding.animeSourceRecycler.adapter = ConcatAdapter(headerAdapter, chapterAdapter)

lifecycleScope.launch(Dispatchers.IO) {
model.loadMangaChapters(media, media.selected!!.source)
model.loadMangaChapters(media, media.selected!!.sourceIndex)
}
loaded = true
} else {
Expand All @@ -136,7 +136,7 @@ open class MangaReadFragment : Fragment() {

model.getMangaChapters().observe(viewLifecycleOwner) { loadedChapters ->
if (loadedChapters != null) {
val chapters = loadedChapters[media.selected!!.source]
val chapters = loadedChapters[media.selected!!.sourceIndex]
if (chapters != null) {
media.manga?.chapters = chapters

Expand Down Expand Up @@ -177,8 +177,8 @@ open class MangaReadFragment : Fragment() {
media.manga?.chapters = null
reload()
val selected = model.loadSelected(media)
model.mangaReadSources?.get(selected.source)?.showUserTextListener = null
selected.source = i
model.mangaReadSources?.get(selected.sourceIndex)?.showUserTextListener = null
selected.sourceIndex = i
selected.server = null
model.saveSelected(media.id, selected, requireActivity())
media.selected = selected
Expand Down
Loading

0 comments on commit 41b90e3

Please sign in to comment.