chore: code cleanup
This commit is contained in:
parent
386e02a564
commit
24147e746a
198 changed files with 1367 additions and 965 deletions
|
@ -343,6 +343,7 @@ class MangaChapterAdapter(
|
|||
fun updateType(t: Int) {
|
||||
type = t
|
||||
}
|
||||
|
||||
private fun formatDate(timestamp: Long?): String {
|
||||
timestamp ?: return "" // Return empty string if timestamp is null
|
||||
|
||||
|
@ -366,6 +367,7 @@ class MangaChapterAdapter(
|
|||
else -> "Just now"
|
||||
}
|
||||
}
|
||||
|
||||
1L -> "1 day ago"
|
||||
in 2..6 -> "$daysDifference days ago"
|
||||
else -> SimpleDateFormat("dd MMM yyyy", Locale.getDefault()).format(targetDate)
|
||||
|
|
|
@ -229,7 +229,7 @@ class MangaReadAdapter(
|
|||
refresh = true
|
||||
val intent = Intent(fragment.requireContext(), CookieCatcher::class.java)
|
||||
.putExtra("url", url)
|
||||
ContextCompat.startActivity(fragment.requireContext(), intent, null)
|
||||
startActivity(fragment.requireContext(), intent, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -258,8 +258,10 @@ class MangaReadAdapter(
|
|||
dialogBinding.animeScanlatorContainer.isVisible = options.count() > 1
|
||||
dialogBinding.scanlatorNo.text = "${options.count()}"
|
||||
dialogBinding.animeScanlatorTop.setOnClickListener {
|
||||
val dialogView2 = LayoutInflater.from(currContext()).inflate(R.layout.custom_dialog_layout, null)
|
||||
val checkboxContainer = dialogView2.findViewById<LinearLayout>(R.id.checkboxContainer)
|
||||
val dialogView2 =
|
||||
LayoutInflater.from(currContext()).inflate(R.layout.custom_dialog_layout, null)
|
||||
val checkboxContainer =
|
||||
dialogView2.findViewById<LinearLayout>(R.id.checkboxContainer)
|
||||
val tickAllButton = dialogView2.findViewById<ImageButton>(R.id.toggleButton)
|
||||
|
||||
// Function to get the right image resource for the toggle button
|
||||
|
@ -441,7 +443,11 @@ class MangaReadAdapter(
|
|||
if (media.manga?.chapters != null) {
|
||||
val chapters = media.manga.chapters!!.keys.toTypedArray()
|
||||
val anilistEp = (media.userProgress ?: 0).plus(1)
|
||||
val appEp = PrefManager.getNullableCustomVal("${media.id}_current_chp", null, String::class.java)
|
||||
val appEp = PrefManager.getNullableCustomVal(
|
||||
"${media.id}_current_chp",
|
||||
null,
|
||||
String::class.java
|
||||
)
|
||||
?.toIntOrNull() ?: 1
|
||||
var continueEp = (if (anilistEp > appEp) anilistEp else appEp).toString()
|
||||
val filteredChapters = chapters.filter { chapterKey ->
|
||||
|
@ -470,7 +476,11 @@ class MangaReadAdapter(
|
|||
val ep = media.manga.chapters!![continueEp]!!
|
||||
binding.itemEpisodeImage.loadImage(media.banner ?: media.cover)
|
||||
binding.animeSourceContinueText.text =
|
||||
currActivity()!!.getString(R.string.continue_chapter, ep.number, if (!ep.title.isNullOrEmpty()) ep.title else "")
|
||||
currActivity()!!.getString(
|
||||
R.string.continue_chapter,
|
||||
ep.number,
|
||||
if (!ep.title.isNullOrEmpty()) ep.title else ""
|
||||
)
|
||||
binding.animeSourceContinue.setOnClickListener {
|
||||
fragment.onMangaChapterClick(continueEp)
|
||||
}
|
||||
|
@ -491,11 +501,14 @@ class MangaReadAdapter(
|
|||
if (!sourceFound && PrefManager.getVal(PrefName.SearchSources)) {
|
||||
if (binding.animeSource.adapter.count > media.selected!!.sourceIndex + 1) {
|
||||
val nextIndex = media.selected!!.sourceIndex + 1
|
||||
binding.animeSource.setText(binding.animeSource.adapter
|
||||
.getItem(nextIndex).toString(), false)
|
||||
binding.animeSource.setText(
|
||||
binding.animeSource.adapter
|
||||
.getItem(nextIndex).toString(), false
|
||||
)
|
||||
fragment.onSourceChange(nextIndex).apply {
|
||||
binding.animeSourceTitle.text = showUserText
|
||||
showUserTextListener = { MainScope().launch { binding.animeSourceTitle.text = it } }
|
||||
showUserTextListener =
|
||||
{ MainScope().launch { binding.animeSourceTitle.text = it } }
|
||||
setLanguageList(0, nextIndex)
|
||||
}
|
||||
subscribeButton(false)
|
||||
|
|
|
@ -42,8 +42,8 @@ import ani.dantotsu.isOnline
|
|||
import ani.dantotsu.media.Media
|
||||
import ani.dantotsu.media.MediaDetailsActivity
|
||||
import ani.dantotsu.media.MediaDetailsViewModel
|
||||
import ani.dantotsu.media.MediaType
|
||||
import ani.dantotsu.media.MediaNameAdapter
|
||||
import ani.dantotsu.media.MediaType
|
||||
import ani.dantotsu.media.manga.mangareader.ChapterLoaderDialog
|
||||
import ani.dantotsu.navBarHeight
|
||||
import ani.dantotsu.notifications.subscription.SubscriptionHelper
|
||||
|
@ -203,8 +203,10 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
|||
ConcatAdapter(headerAdapter, chapterAdapter)
|
||||
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val offline = !isOnline(binding.root.context) || PrefManager.getVal(PrefName.OfflineMode)
|
||||
if (offline) media.selected!!.sourceIndex = model.mangaReadSources!!.list.lastIndex
|
||||
val offline =
|
||||
!isOnline(binding.root.context) || PrefManager.getVal(PrefName.OfflineMode)
|
||||
if (offline) media.selected!!.sourceIndex =
|
||||
model.mangaReadSources!!.list.lastIndex
|
||||
model.loadMangaChapters(media, media.selected!!.sourceIndex)
|
||||
}
|
||||
loaded = true
|
||||
|
|
|
@ -42,7 +42,8 @@ abstract class BaseImageAdapter(
|
|||
|
||||
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
|
||||
images = if (settings.layout == CurrentReaderSettings.Layouts.PAGED
|
||||
&& settings.direction == CurrentReaderSettings.Directions.BOTTOM_TO_TOP) {
|
||||
&& settings.direction == CurrentReaderSettings.Directions.BOTTOM_TO_TOP
|
||||
) {
|
||||
chapterImages.reversed()
|
||||
} else {
|
||||
chapterImages
|
||||
|
|
|
@ -56,8 +56,8 @@ import ani.dantotsu.isOnline
|
|||
import ani.dantotsu.logError
|
||||
import ani.dantotsu.media.Media
|
||||
import ani.dantotsu.media.MediaDetailsViewModel
|
||||
import ani.dantotsu.media.MediaSingleton
|
||||
import ani.dantotsu.media.MediaNameAdapter
|
||||
import ani.dantotsu.media.MediaSingleton
|
||||
import ani.dantotsu.media.manga.MangaCache
|
||||
import ani.dantotsu.media.manga.MangaChapter
|
||||
import ani.dantotsu.others.ImageViewDialog
|
||||
|
@ -129,10 +129,12 @@ class MangaReaderActivity : AppCompatActivity() {
|
|||
var sliding = false
|
||||
var isAnimating = false
|
||||
|
||||
private val directionRLBT get() = defaultSettings.direction == RIGHT_TO_LEFT
|
||||
|| defaultSettings.direction == BOTTOM_TO_TOP
|
||||
private val directionPagedBT get() = defaultSettings.layout == CurrentReaderSettings.Layouts.PAGED
|
||||
&& defaultSettings.direction == CurrentReaderSettings.Directions.BOTTOM_TO_TOP
|
||||
private val directionRLBT
|
||||
get() = defaultSettings.direction == RIGHT_TO_LEFT
|
||||
|| defaultSettings.direction == BOTTOM_TO_TOP
|
||||
private val directionPagedBT
|
||||
get() = defaultSettings.layout == CurrentReaderSettings.Layouts.PAGED
|
||||
&& defaultSettings.direction == CurrentReaderSettings.Directions.BOTTOM_TO_TOP
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && !PrefManager.getVal<Boolean>(PrefName.ShowSystemBars)) {
|
||||
|
@ -229,7 +231,7 @@ class MangaReaderActivity : AppCompatActivity() {
|
|||
binding.mangaReaderRecycler.scrollToPosition((value.toInt() - 1) / (dualPage { 2 }
|
||||
?: 1))
|
||||
else
|
||||
if (defaultSettings.direction == CurrentReaderSettings.Directions.BOTTOM_TO_TOP ) {
|
||||
if (defaultSettings.direction == CurrentReaderSettings.Directions.BOTTOM_TO_TOP) {
|
||||
binding.mangaReaderPager.currentItem =
|
||||
(maxChapterPage.toInt() - value.toInt()) / (dualPage { 2 } ?: 1)
|
||||
} else {
|
||||
|
@ -345,7 +347,11 @@ class MangaReaderActivity : AppCompatActivity() {
|
|||
if (currentChapterIndex > 0) change(currentChapterIndex - 1)
|
||||
else snackString(getString(R.string.first_chapter))
|
||||
} else {
|
||||
if (chaptersArr.size > currentChapterIndex + 1) progress { change(currentChapterIndex + 1) }
|
||||
if (chaptersArr.size > currentChapterIndex + 1) progress {
|
||||
change(
|
||||
currentChapterIndex + 1
|
||||
)
|
||||
}
|
||||
else snackString(getString(R.string.next_chapter_not_found))
|
||||
}
|
||||
}
|
||||
|
@ -355,7 +361,11 @@ class MangaReaderActivity : AppCompatActivity() {
|
|||
}
|
||||
binding.mangaReaderPreviousChapter.setOnClickListener {
|
||||
if (directionRLBT) {
|
||||
if (chaptersArr.size > currentChapterIndex + 1) progress { change(currentChapterIndex + 1) }
|
||||
if (chaptersArr.size > currentChapterIndex + 1) progress {
|
||||
change(
|
||||
currentChapterIndex + 1
|
||||
)
|
||||
}
|
||||
else snackString(getString(R.string.next_chapter_not_found))
|
||||
} else {
|
||||
if (currentChapterIndex > 0) change(currentChapterIndex - 1)
|
||||
|
@ -372,11 +382,15 @@ class MangaReaderActivity : AppCompatActivity() {
|
|||
currentChapterIndex = chaptersArr.indexOf(chap.number)
|
||||
binding.mangaReaderChapterSelect.setSelection(currentChapterIndex)
|
||||
if (directionRLBT) {
|
||||
binding.mangaReaderNextChap.text = chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: ""
|
||||
binding.mangaReaderPrevChap.text = chaptersTitleArr.getOrNull(currentChapterIndex + 1) ?: ""
|
||||
binding.mangaReaderNextChap.text =
|
||||
chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: ""
|
||||
binding.mangaReaderPrevChap.text =
|
||||
chaptersTitleArr.getOrNull(currentChapterIndex + 1) ?: ""
|
||||
} else {
|
||||
binding.mangaReaderNextChap.text = chaptersTitleArr.getOrNull(currentChapterIndex + 1) ?: ""
|
||||
binding.mangaReaderPrevChap.text = chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: ""
|
||||
binding.mangaReaderNextChap.text =
|
||||
chaptersTitleArr.getOrNull(currentChapterIndex + 1) ?: ""
|
||||
binding.mangaReaderPrevChap.text =
|
||||
chaptersTitleArr.getOrNull(currentChapterIndex - 1) ?: ""
|
||||
}
|
||||
applySettings()
|
||||
val context = this
|
||||
|
@ -389,10 +403,12 @@ class MangaReaderActivity : AppCompatActivity() {
|
|||
"nothing" -> mutableListOf(
|
||||
RPC.Link(getString(R.string.view_manga), media.shareLink ?: ""),
|
||||
)
|
||||
|
||||
"dantotsu" -> mutableListOf(
|
||||
RPC.Link(getString(R.string.view_manga), media.shareLink ?: ""),
|
||||
RPC.Link("Read on Dantotsu", getString(R.string.dantotsu))
|
||||
)
|
||||
|
||||
"anilist" -> {
|
||||
val userId = PrefManager.getVal<String>(PrefName.AnilistUserId)
|
||||
val anilistLink = "https://anilist.co/user/$userId/"
|
||||
|
@ -401,6 +417,7 @@ class MangaReaderActivity : AppCompatActivity() {
|
|||
RPC.Link("View My AniList", anilistLink)
|
||||
)
|
||||
}
|
||||
|
||||
else -> mutableListOf()
|
||||
}
|
||||
val presence = RPC.createPresence(
|
||||
|
@ -411,7 +428,12 @@ class MangaReaderActivity : AppCompatActivity() {
|
|||
details = chap.title?.takeIf { it.isNotEmpty() }
|
||||
?: getString(R.string.chapter_num, chap.number),
|
||||
state = "${chap.number}/${media.manga?.totalChapters ?: "??"}",
|
||||
largeImage = media.cover?.let { cover -> RPC.Link(media.userPreferredName, cover) },
|
||||
largeImage = media.cover?.let { cover ->
|
||||
RPC.Link(
|
||||
media.userPreferredName,
|
||||
cover
|
||||
)
|
||||
},
|
||||
buttons = buttons
|
||||
)
|
||||
)
|
||||
|
@ -918,7 +940,12 @@ class MangaReaderActivity : AppCompatActivity() {
|
|||
isAnimating = true
|
||||
ObjectAnimator.ofFloat(binding.mangaReaderCont, "alpha", 1f, 0f)
|
||||
.setDuration(controllerDuration).start()
|
||||
ObjectAnimator.ofFloat(binding.mangaReaderBottomLayout, "translationY", 0f, 128f)
|
||||
ObjectAnimator.ofFloat(
|
||||
binding.mangaReaderBottomLayout,
|
||||
"translationY",
|
||||
0f,
|
||||
128f
|
||||
)
|
||||
.apply { interpolator = overshoot;duration = controllerDuration;start() }
|
||||
ObjectAnimator.ofFloat(binding.mangaReaderTopLayout, "translationY", 0f, -128f)
|
||||
.apply { interpolator = overshoot;duration = controllerDuration;start() }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue