mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-23 05:01:12 +01:00
Cleaning up Recents and MainActivity
This commit is contained in:
parent
5963c09691
commit
9a4894ba95
@ -144,17 +144,11 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
|
|||||||
preferences.lastTab().set(item.itemId)
|
preferences.lastTab().set(item.itemId)
|
||||||
val currentRoot = router.backstack.firstOrNull()
|
val currentRoot = router.backstack.firstOrNull()
|
||||||
if (currentRoot?.tag()?.toIntOrNull() != id) {
|
if (currentRoot?.tag()?.toIntOrNull() != id) {
|
||||||
when (id) {
|
setRoot(when (id) {
|
||||||
R.id.nav_library -> setRoot(LibraryListController(), id)
|
R.id.nav_library -> LibraryListController()
|
||||||
R.id.nav_recents -> {
|
R.id.nav_recents -> RecentsController()
|
||||||
setRoot(RecentsController(), id)
|
else -> CatalogueController()
|
||||||
// if (preferences.showRecentUpdates().getOrDefault()) setRoot(
|
}, id)
|
||||||
// RecentChaptersController(), id
|
|
||||||
// )
|
|
||||||
// else setRoot(RecentlyReadController(), id)
|
|
||||||
}
|
|
||||||
R.id.nav_catalogues -> setRoot(CatalogueController(), id)
|
|
||||||
}
|
|
||||||
} else if (currentRoot.tag()?.toIntOrNull() == id) {
|
} else if (currentRoot.tag()?.toIntOrNull() == id) {
|
||||||
if (router.backstackSize == 1) {
|
if (router.backstackSize == 1) {
|
||||||
when (id) {
|
when (id) {
|
||||||
@ -163,7 +157,6 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
|
|||||||
if (!showRecents) setRoot(RecentChaptersController(), id)
|
if (!showRecents) setRoot(RecentChaptersController(), id)
|
||||||
else setRoot(RecentlyReadController(), id)
|
else setRoot(RecentlyReadController(), id)
|
||||||
preferences.showRecentUpdates().set(!showRecents)
|
preferences.showRecentUpdates().set(!showRecents)
|
||||||
updateRecentsIcon()
|
|
||||||
}*/
|
}*/
|
||||||
R.id.nav_library -> {
|
R.id.nav_library -> {
|
||||||
val controller =
|
val controller =
|
||||||
@ -188,7 +181,6 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
|
|||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
container.systemUiVisibility =
|
container.systemUiVisibility =
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
// updateRecentsIcon()
|
|
||||||
|
|
||||||
supportActionBar?.setDisplayShowCustomEnabled(true)
|
supportActionBar?.setDisplayShowCustomEnabled(true)
|
||||||
|
|
||||||
@ -209,10 +201,6 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
|
|||||||
top = insets.systemWindowInsetTop
|
top = insets.systemWindowInsetTop
|
||||||
)
|
)
|
||||||
bottom_nav.updatePadding(bottom = insets.systemWindowInsetBottom)
|
bottom_nav.updatePadding(bottom = insets.systemWindowInsetBottom)
|
||||||
|
|
||||||
/*insets.replaceSystemWindowInsets(
|
|
||||||
0, insets.systemWindowInsetTop, 0, insets.systemWindowInsetBottom
|
|
||||||
)*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
router = Conductor.attachRouter(this, container, savedInstanceState)
|
router = Conductor.attachRouter(this, container, savedInstanceState)
|
||||||
@ -306,16 +294,6 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*fun updateRecentsIcon() {
|
|
||||||
bottom_nav.menu.findItem(R.id.nav_recents).icon = AppCompatResources.getDrawable(
|
|
||||||
this,
|
|
||||||
if (preferences.showRecentUpdates()
|
|
||||||
.getOrDefault()
|
|
||||||
) R.drawable.recent_updates_selector_24dp
|
|
||||||
else R.drawable.recent_read_selector_24dp
|
|
||||||
)
|
|
||||||
}*/
|
|
||||||
|
|
||||||
override fun startSupportActionMode(callback: androidx.appcompat.view.ActionMode.Callback): androidx.appcompat.view.ActionMode? {
|
override fun startSupportActionMode(callback: androidx.appcompat.view.ActionMode.Callback): androidx.appcompat.view.ActionMode? {
|
||||||
window?.statusBarColor = getResourceColor(R.attr.colorPrimaryVariant)
|
window?.statusBarColor = getResourceColor(R.attr.colorPrimaryVariant)
|
||||||
return super.startSupportActionMode(callback)
|
return super.startSupportActionMode(callback)
|
||||||
@ -356,6 +334,11 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
|
|||||||
DownloadService.callListeners()
|
DownloadService.callListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
snackBar?.dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
private fun getExtensionUpdates() {
|
private fun getExtensionUpdates() {
|
||||||
if (Date().time >= preferences.lastExtCheck().getOrDefault() + TimeUnit.HOURS.toMillis(1)) {
|
if (Date().time >= preferences.lastExtCheck().getOrDefault() + TimeUnit.HOURS.toMillis(1)) {
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package eu.kanade.tachiyomi.ui.recents
|
package eu.kanade.tachiyomi.ui.recents
|
||||||
|
|
||||||
import android.widget.ImageView
|
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
import eu.davidea.flexibleadapter.items.IFlexible
|
import eu.davidea.flexibleadapter.items.IFlexible
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
|
||||||
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterAdapter
|
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterAdapter
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.text.DecimalFormatSymbols
|
import java.text.DecimalFormatSymbols
|
||||||
@ -21,10 +19,8 @@ class RecentMangaAdapter(val delegate: RecentsInterface) :
|
|||||||
interface RecentsInterface : RecentMangaInterface, DownloadInterface
|
interface RecentsInterface : RecentMangaInterface, DownloadInterface
|
||||||
|
|
||||||
interface RecentMangaInterface {
|
interface RecentMangaInterface {
|
||||||
fun onHeaderClick(position: Int)
|
|
||||||
fun onCoverClick(position: Int)
|
fun onCoverClick(position: Int)
|
||||||
fun markAsRead(position: Int)
|
fun markAsRead(position: Int)
|
||||||
fun setCover(manga: Manga, view: ImageView)
|
|
||||||
fun isSearching(): Boolean
|
fun isSearching(): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,11 +58,17 @@ class RecentMangaHeaderItem(val recentsType: Int) :
|
|||||||
|
|
||||||
fun bind(recentsType: Int) {
|
fun bind(recentsType: Int) {
|
||||||
title.setText(when (recentsType) {
|
title.setText(when (recentsType) {
|
||||||
RecentsItem.CONTINUE_READING -> R.string.continue_reading
|
CONTINUE_READING -> R.string.continue_reading
|
||||||
RecentsItem.NEW_CHAPTERS -> R.string.new_chapters
|
NEW_CHAPTERS -> R.string.new_chapters
|
||||||
RecentsItem.NEWLY_ADDED -> R.string.new_additions
|
NEWLY_ADDED -> R.string.new_additions
|
||||||
else -> R.string.continue_reading
|
else -> R.string.continue_reading
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val CONTINUE_READING = 0
|
||||||
|
const val NEW_CHAPTERS = 1
|
||||||
|
const val NEWLY_ADDED = 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,12 @@ package eu.kanade.tachiyomi.ui.recents
|
|||||||
|
|
||||||
import android.text.format.DateUtils
|
import android.text.format.DateUtils
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
|
import com.bumptech.glide.signature.ObjectKey
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.data.database.models.MangaImpl
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
|
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||||
import eu.kanade.tachiyomi.source.LocalSource
|
import eu.kanade.tachiyomi.source.LocalSource
|
||||||
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterHolder
|
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterHolder
|
||||||
import eu.kanade.tachiyomi.util.view.visibleIf
|
import eu.kanade.tachiyomi.util.view.visibleIf
|
||||||
@ -22,10 +26,10 @@ class RecentMangaHolder(
|
|||||||
|
|
||||||
fun bind(recentsType: Int) {
|
fun bind(recentsType: Int) {
|
||||||
when (recentsType) {
|
when (recentsType) {
|
||||||
RecentsItem.CONTINUE_READING -> {
|
RecentMangaHeaderItem.CONTINUE_READING -> {
|
||||||
title.setText(R.string.view_history)
|
title.setText(R.string.view_history)
|
||||||
}
|
}
|
||||||
RecentsItem.NEW_CHAPTERS -> {
|
RecentMangaHeaderItem.NEW_CHAPTERS -> {
|
||||||
title.setText(R.string.view_all_updates)
|
title.setText(R.string.view_all_updates)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,7 +72,10 @@ class RecentMangaHolder(
|
|||||||
)
|
)
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
adapter.delegate.setCover(item.mch.manga, cover_thumbnail)
|
GlideApp.with(itemView.context).load(item.mch.manga).diskCacheStrategy(DiskCacheStrategy
|
||||||
|
.AUTOMATIC)
|
||||||
|
.signature(ObjectKey(MangaImpl.getLastCoverFetch(item.mch.manga.id!!).toString())).into(cover_thumbnail)
|
||||||
|
// adapter.delegate.setCover(item.mch.manga, cover_thumbnail)
|
||||||
notifyStatus(
|
notifyStatus(
|
||||||
if (adapter.isSelected(adapterPosition)) Download.CHECKED else item.status,
|
if (adapter.isSelected(adapterPosition)) Download.CHECKED else item.status,
|
||||||
item.progress
|
item.progress
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package eu.kanade.tachiyomi.ui.recents
|
|
||||||
|
|
||||||
import android.widget.ImageView
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
|
||||||
import eu.davidea.flexibleadapter.items.IFlexible
|
|
||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
|
||||||
|
|
||||||
class RecentsAdapter(val delegate: RecentsInterface) :
|
|
||||||
FlexibleAdapter<IFlexible<RecentsHolder>>(null, delegate, true) {
|
|
||||||
|
|
||||||
interface RecentsInterface {
|
|
||||||
fun resumeManga(manga: Manga, chapter: Chapter)
|
|
||||||
fun showManga(manga: Manga)
|
|
||||||
fun markAsRead(manga: Manga, chapter: Chapter)
|
|
||||||
fun downloadChapter(item: RecentMangaItem)
|
|
||||||
fun downloadChapterNow(chapter: Chapter)
|
|
||||||
fun setCover(manga: Manga, view: ImageView)
|
|
||||||
fun viewAll(position: Int)
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,25 +8,18 @@ import android.view.MenuInflater
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.bluelinelabs.conductor.Controller
|
import com.bluelinelabs.conductor.Controller
|
||||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||||
import com.bluelinelabs.conductor.ControllerChangeType
|
import com.bluelinelabs.conductor.ControllerChangeType
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|
||||||
import com.bumptech.glide.signature.ObjectKey
|
|
||||||
import com.google.android.material.snackbar.BaseTransientBottomBar
|
import com.google.android.material.snackbar.BaseTransientBottomBar
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
|
||||||
import eu.kanade.tachiyomi.data.database.models.MangaImpl
|
|
||||||
import eu.kanade.tachiyomi.data.download.DownloadService
|
import eu.kanade.tachiyomi.data.download.DownloadService
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
|
||||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.BaseController
|
import eu.kanade.tachiyomi.ui.base.controller.BaseController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||||
@ -50,7 +43,6 @@ import kotlinx.android.synthetic.main.recently_read_controller.*
|
|||||||
*/
|
*/
|
||||||
class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
|
class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
|
||||||
RecentMangaAdapter.RecentsInterface,
|
RecentMangaAdapter.RecentsInterface,
|
||||||
RecentsAdapter.RecentsInterface,
|
|
||||||
FlexibleAdapter.OnItemClickListener,
|
FlexibleAdapter.OnItemClickListener,
|
||||||
RootSearchInterface {
|
RootSearchInterface {
|
||||||
|
|
||||||
@ -61,7 +53,6 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
|
|||||||
/**
|
/**
|
||||||
* Adapter containing the recent manga.
|
* Adapter containing the recent manga.
|
||||||
*/
|
*/
|
||||||
// private val adapter = RecentsAdapter(this)
|
|
||||||
private var adapter = RecentMangaAdapter(this)
|
private var adapter = RecentMangaAdapter(this)
|
||||||
|
|
||||||
private var presenter = RecentsPresenter(this)
|
private var presenter = RecentsPresenter(this)
|
||||||
@ -92,11 +83,6 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
|
|||||||
recycler.setHasFixedSize(true)
|
recycler.setHasFixedSize(true)
|
||||||
recycler.recycledViewPool.setMaxRecycledViews(0, 0)
|
recycler.recycledViewPool.setMaxRecycledViews(0, 0)
|
||||||
adapter.isSwipeEnabled = true
|
adapter.isSwipeEnabled = true
|
||||||
/*recycler.addItemDecoration(
|
|
||||||
DividerItemDecoration(
|
|
||||||
recycler.context, DividerItemDecoration.VERTICAL
|
|
||||||
)
|
|
||||||
)*/
|
|
||||||
adapter.itemTouchHelperCallback.setSwipeFlags(
|
adapter.itemTouchHelperCallback.setSwipeFlags(
|
||||||
ItemTouchHelper.LEFT
|
ItemTouchHelper.LEFT
|
||||||
)
|
)
|
||||||
@ -128,7 +114,6 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
|
|||||||
refreshItem(lastChapterId ?: 0L)
|
refreshItem(lastChapterId ?: 0L)
|
||||||
lastChapterId = null
|
lastChapterId = null
|
||||||
}
|
}
|
||||||
// recycler.removeItemDecorationAt(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateChapterDownload(download: Download) {
|
fun updateChapterDownload(download: Download) {
|
||||||
@ -136,10 +121,6 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
|
|||||||
val id = download.chapter.id ?: return
|
val id = download.chapter.id ?: return
|
||||||
val holder = recycler.findViewHolderForItemId(id) as? RecentMangaHolder ?: return
|
val holder = recycler.findViewHolderForItemId(id) as? RecentMangaHolder ?: return
|
||||||
holder.notifyStatus(download.status, download.progress)
|
holder.notifyStatus(download.status, download.progress)
|
||||||
/* (i in 0 until adapter.itemCount) {
|
|
||||||
val holder = recycler.findViewHolderForAdapterPosition(i) as? RecentsHolder ?: continue
|
|
||||||
if (holder.updateChapterDownload(download)) break
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshItem(chapterId: Long) {
|
private fun refreshItem(chapterId: Long) {
|
||||||
@ -147,20 +128,11 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
|
|||||||
it is RecentMangaItem &&
|
it is RecentMangaItem &&
|
||||||
it.mch.chapter.id == chapterId }
|
it.mch.chapter.id == chapterId }
|
||||||
if (recentItemPos > -1) adapter.notifyItemChanged(recentItemPos)
|
if (recentItemPos > -1) adapter.notifyItemChanged(recentItemPos)
|
||||||
/*holder.notifyStatus(download.status, download.progress)
|
|
||||||
for (i in 0 until adapter.itemCount) {
|
|
||||||
val holder = recycler.findViewHolderForAdapterPosition(i) as? RecentsHolder ?: continue
|
|
||||||
holder.refreshChapter(chapterId)
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun downloadChapter(position: Int) {
|
override fun downloadChapter(position: Int) {
|
||||||
val item = adapter.getItem(position) as? RecentMangaItem ?: return
|
|
||||||
downloadChapter(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun downloadChapter(item: RecentMangaItem) {
|
|
||||||
val view = view ?: return
|
val view = view ?: return
|
||||||
|
val item = adapter.getItem(position) as? RecentMangaItem ?: return
|
||||||
val chapter = item.chapter
|
val chapter = item.chapter
|
||||||
val manga = item.mch.manga
|
val manga = item.mch.manga
|
||||||
if (item.status != Download.NOT_DOWNLOADED && item.status != Download.ERROR) {
|
if (item.status != Download.NOT_DOWNLOADED && item.status != Download.ERROR) {
|
||||||
@ -176,51 +148,40 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
|
|||||||
presenter.startDownloadChapterNow(chapter)
|
presenter.startDownloadChapterNow(chapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun downloadChapterNow(chapter: Chapter) {
|
|
||||||
presenter.startDownloadChapterNow(chapter)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCoverClick(position: Int) {
|
override fun onCoverClick(position: Int) {
|
||||||
val manga = (adapter.getItem(position) as? RecentMangaItem)?.mch?.manga ?: return
|
val manga = (adapter.getItem(position) as? RecentMangaItem)?.mch?.manga ?: return
|
||||||
router.pushController(MangaDetailsController(manga).withFadeTransaction())
|
router.pushController(MangaDetailsController(manga).withFadeTransaction())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showManga(manga: Manga) = router.pushController(MangaDetailsController(manga).withFadeTransaction())
|
|
||||||
|
|
||||||
override fun onItemClick(view: View?, position: Int): Boolean {
|
override fun onItemClick(view: View?, position: Int): Boolean {
|
||||||
val item = adapter.getItem(position) ?: return false
|
val item = adapter.getItem(position) ?: return false
|
||||||
if (item is RecentMangaItem) {
|
if (item is RecentMangaItem) {
|
||||||
if (item.mch.manga.id == null) {
|
if (item.mch.manga.id == null) {
|
||||||
val headerItem = adapter.getHeaderOf(item) as? RecentMangaHeaderItem
|
val headerItem = adapter.getHeaderOf(item) as? RecentMangaHeaderItem
|
||||||
val controller: Controller = when (headerItem?.recentsType) {
|
val controller: Controller = when (headerItem?.recentsType) {
|
||||||
RecentsItem.NEW_CHAPTERS -> RecentChaptersController()
|
RecentMangaHeaderItem.NEW_CHAPTERS -> RecentChaptersController()
|
||||||
RecentsItem.CONTINUE_READING -> RecentlyReadController()
|
RecentMangaHeaderItem.CONTINUE_READING -> RecentlyReadController()
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
router.pushController(controller.withFadeTransaction())
|
router.pushController(controller.withFadeTransaction())
|
||||||
} else resumeManga(item.mch.manga, item.chapter)
|
} else {
|
||||||
} else if (item is RecentMangaHeaderItem) return false // onHeaderClick(position)
|
val activity = activity ?: return false
|
||||||
return true
|
val intent = ReaderActivity.newIntent(activity, item.mch.manga, item.chapter)
|
||||||
}
|
|
||||||
|
|
||||||
override fun resumeManga(manga: Manga, chapter: Chapter) {
|
|
||||||
val activity = activity ?: return
|
|
||||||
val intent = ReaderActivity.newIntent(activity, manga, chapter)
|
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
} else if (item is RecentMangaHeaderItem) return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
override fun markAsRead(position: Int) {
|
override fun markAsRead(position: Int) {
|
||||||
val item = adapter.getItem(position) as? RecentMangaItem ?: return
|
val item = adapter.getItem(position) as? RecentMangaItem ?: return
|
||||||
markAsRead(item.mch.manga, item.chapter)
|
val chapter = item.chapter
|
||||||
}
|
val manga = item.mch.manga
|
||||||
|
|
||||||
override fun markAsRead(manga: Manga, chapter: Chapter) {
|
|
||||||
val lastRead = chapter.last_page_read
|
val lastRead = chapter.last_page_read
|
||||||
val pagesLeft = chapter.pages_left
|
val pagesLeft = chapter.pages_left
|
||||||
lastChapterId = chapter.id
|
lastChapterId = chapter.id
|
||||||
presenter.markChapterRead(chapter, true)
|
presenter.markChapterRead(chapter, true)
|
||||||
snack =
|
snack = view?.snack(R.string.marked_as_read, Snackbar.LENGTH_INDEFINITE) {
|
||||||
view?.snack(R.string.marked_as_read, Snackbar.LENGTH_INDEFINITE) {
|
|
||||||
anchorView = activity?.bottom_nav
|
anchorView = activity?.bottom_nav
|
||||||
var undoing = false
|
var undoing = false
|
||||||
setAction(R.string.action_undo) {
|
setAction(R.string.action_undo) {
|
||||||
@ -274,33 +235,6 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setCover(manga: Manga, view: ImageView) {
|
|
||||||
val activity = activity ?: return
|
|
||||||
GlideApp.with(activity).load(manga).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
|
|
||||||
.signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString())).into(view)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onHeaderClick(position: Int) {
|
|
||||||
val recentsType = (adapter.getItem(position) as? RecentMangaHeaderItem)?.recentsType
|
|
||||||
?: return
|
|
||||||
val controller: Controller = when (recentsType) {
|
|
||||||
RecentsItem.NEW_CHAPTERS -> RecentChaptersController()
|
|
||||||
RecentsItem.CONTINUE_READING -> RecentlyReadController()
|
|
||||||
else -> return
|
|
||||||
}
|
|
||||||
router.pushController(controller.withFadeTransaction())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun viewAll(position: Int) {
|
|
||||||
/*val recentsType = (adapter.getItem(position) as? RecentsItem)?.recentType ?: return
|
|
||||||
val controller: Controller = when (recentsType) {
|
|
||||||
RecentsItem.NEW_CHAPTERS -> RecentChaptersController()
|
|
||||||
RecentsItem.CONTINUE_READING -> RecentlyReadController()
|
|
||||||
else -> return
|
|
||||||
}
|
|
||||||
router.pushController(controller.withFadeTransaction())*/
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.action_refresh -> {
|
R.id.action_refresh -> {
|
||||||
|
@ -1,136 +0,0 @@
|
|||||||
package eu.kanade.tachiyomi.ui.recents
|
|
||||||
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.ImageView
|
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration
|
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
|
||||||
import eu.kanade.tachiyomi.R
|
|
||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
|
||||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
|
||||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
|
||||||
import eu.kanade.tachiyomi.util.view.updateLayoutParams
|
|
||||||
import eu.kanade.tachiyomi.util.view.visibleIf
|
|
||||||
import kotlinx.android.synthetic.main.recents_item.*
|
|
||||||
|
|
||||||
class RecentsHolder(
|
|
||||||
view: View,
|
|
||||||
val adapter: RecentsAdapter
|
|
||||||
) : BaseFlexibleViewHolder(view, adapter),
|
|
||||||
FlexibleAdapter.OnItemClickListener,
|
|
||||||
FlexibleAdapter.OnUpdateListener,
|
|
||||||
RecentMangaAdapter.RecentsInterface {
|
|
||||||
|
|
||||||
private val subAdapter = RecentMangaAdapter(this)
|
|
||||||
|
|
||||||
init {
|
|
||||||
recycler.adapter = subAdapter
|
|
||||||
subAdapter.isSwipeEnabled = true
|
|
||||||
val manager = LinearLayoutManager(view.context)
|
|
||||||
recycler.layoutManager = manager
|
|
||||||
recycler.addItemDecoration(
|
|
||||||
DividerItemDecoration(
|
|
||||||
recycler.context, DividerItemDecoration.VERTICAL
|
|
||||||
)
|
|
||||||
)
|
|
||||||
recycler.setHasFixedSize(true)
|
|
||||||
view_all.setOnClickListener { adapter.delegate.viewAll(adapterPosition) }
|
|
||||||
subAdapter.itemTouchHelperCallback.setSwipeFlags(
|
|
||||||
ItemTouchHelper.LEFT
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bind(item: RecentsItem) {
|
|
||||||
when (item.recentType) {
|
|
||||||
RecentsItem.CONTINUE_READING -> {
|
|
||||||
title.setText(R.string.continue_reading)
|
|
||||||
view_all.setText(R.string.view_history)
|
|
||||||
}
|
|
||||||
RecentsItem.NEW_CHAPTERS -> {
|
|
||||||
title.setText(R.string.new_chapters)
|
|
||||||
view_all.setText(R.string.view_all_updates)
|
|
||||||
}
|
|
||||||
RecentsItem.NEWLY_ADDED -> {
|
|
||||||
title.setText(R.string.new_additions)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
title.visibleIf(item.recentType != RecentsItem.SEARCH)
|
|
||||||
view_all.visibleIf(item.recentType == RecentsItem.CONTINUE_READING || item.recentType == RecentsItem.NEW_CHAPTERS)
|
|
||||||
recycler.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
|
||||||
bottomMargin = if (adapterPosition == adapter.itemCount - 1) 0 else 12.dpToPx
|
|
||||||
}
|
|
||||||
subAdapter.updateDataSet(item.mangaList)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun downloadChapter(position: Int) {
|
|
||||||
val item = (subAdapter.getItem(position) as? RecentMangaItem) ?: return
|
|
||||||
adapter.delegate.downloadChapter(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun startDownloadNow(position: Int) {
|
|
||||||
val chapter = (subAdapter.getItem(position) as? RecentMangaItem)?.chapter ?: return
|
|
||||||
adapter.delegate.downloadChapterNow(chapter)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCoverClick(position: Int) {
|
|
||||||
val manga = (subAdapter.getItem(position) as? RecentMangaItem)?.mch?.manga ?: return
|
|
||||||
adapter.delegate.showManga(manga)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemClick(view: View?, position: Int): Boolean {
|
|
||||||
val item = (subAdapter.getItem(position) as? RecentMangaItem) ?: return false
|
|
||||||
adapter.delegate.resumeManga(item.mch.manga, item.chapter)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateChapterDownload(download: Download): Boolean {
|
|
||||||
val holder = getHolder(download.chapter) ?: return false
|
|
||||||
holder.notifyStatus(download.status, download.progress)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun refreshChapter(chapterId: Long) {
|
|
||||||
val item = (adapter.getItem(adapterPosition) as? RecentsItem) ?: return
|
|
||||||
val recentItemPos = item.mangaList.indexOfFirst { it.mch.chapter.id == chapterId }
|
|
||||||
if (recentItemPos > -1) subAdapter.notifyItemChanged(recentItemPos)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onUpdateEmptyView(size: Int) {
|
|
||||||
if (size > 0) {
|
|
||||||
empty_view?.hide()
|
|
||||||
} else {
|
|
||||||
val recentsType = (adapter.getItem(adapterPosition) as? RecentsItem)?.recentType ?: return
|
|
||||||
when (recentsType) {
|
|
||||||
RecentsItem.CONTINUE_READING ->
|
|
||||||
empty_view?.show(R.drawable.ic_history_white_128dp, R.string.information_no_recent_manga)
|
|
||||||
RecentsItem.NEW_CHAPTERS ->
|
|
||||||
empty_view?.show(R.drawable.ic_update_black_128dp, R.string.information_no_recent)
|
|
||||||
RecentsItem.NEWLY_ADDED ->
|
|
||||||
empty_view?.show(R.drawable.recent_read_outline_128dp, R.string.information_no_recent)
|
|
||||||
RecentsItem.SEARCH ->
|
|
||||||
empty_view?.show(R.drawable.search_128dp, R.string.no_search_result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getHolder(chapter: Chapter): RecentMangaHolder? {
|
|
||||||
return recycler?.findViewHolderForItemId(chapter.id!!) as? RecentMangaHolder
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setCover(manga: Manga, view: ImageView) {
|
|
||||||
adapter.delegate.setCover(manga, view)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun markAsRead(position: Int) {
|
|
||||||
val item = (subAdapter.getItem(position) as RecentMangaItem)
|
|
||||||
adapter.delegate.markAsRead(item.mch.manga, item.chapter)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onHeaderClick(position: Int) {
|
|
||||||
}
|
|
||||||
override fun isSearching() = false
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
package eu.kanade.tachiyomi.ui.recents
|
|
||||||
|
|
||||||
import android.view.View
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
|
||||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
|
||||||
import eu.davidea.flexibleadapter.items.IFlexible
|
|
||||||
import eu.kanade.tachiyomi.R
|
|
||||||
|
|
||||||
class RecentsItem(val recentType: Int, val mangaList: List<RecentMangaItem>) :
|
|
||||||
AbstractFlexibleItem<RecentsHolder>() {
|
|
||||||
|
|
||||||
override fun getLayoutRes(): Int {
|
|
||||||
return R.layout.recents_item
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun createViewHolder(
|
|
||||||
view: View,
|
|
||||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
|
|
||||||
): RecentsHolder {
|
|
||||||
return RecentsHolder(view, adapter as RecentsAdapter)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun bindViewHolder(
|
|
||||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>,
|
|
||||||
holder: RecentsHolder,
|
|
||||||
position: Int,
|
|
||||||
payloads: MutableList<Any?>?
|
|
||||||
) {
|
|
||||||
|
|
||||||
holder.bind(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (other is RecentsItem) {
|
|
||||||
return recentType == other.recentType
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
return recentType.hashCode()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val CONTINUE_READING = 0
|
|
||||||
const val NEW_CHAPTERS = 1
|
|
||||||
const val NEWLY_ADDED = 2
|
|
||||||
const val SEARCH = 3
|
|
||||||
}
|
|
||||||
}
|
|
@ -32,12 +32,12 @@ class RecentsPresenter(
|
|||||||
|
|
||||||
private var scope = CoroutineScope(Job() + Dispatchers.Default)
|
private var scope = CoroutineScope(Job() + Dispatchers.Default)
|
||||||
|
|
||||||
var recentItems = listOf<RecentMangaItem>()
|
private var recentItems = listOf<RecentMangaItem>()
|
||||||
// var groupedRecentItems = listOf<RecentsItem>()
|
|
||||||
var query = ""
|
var query = ""
|
||||||
var newAdditionsHeader = RecentMangaHeaderItem(RecentsItem.NEWLY_ADDED)
|
private val newAdditionsHeader = RecentMangaHeaderItem(RecentMangaHeaderItem.NEWLY_ADDED)
|
||||||
var newChaptersHeader = RecentMangaHeaderItem(RecentsItem.NEW_CHAPTERS)
|
private val newChaptersHeader = RecentMangaHeaderItem(RecentMangaHeaderItem.NEW_CHAPTERS)
|
||||||
var continueReadingHeader = RecentMangaHeaderItem(RecentsItem.CONTINUE_READING)
|
private val continueReadingHeader = RecentMangaHeaderItem(RecentMangaHeaderItem
|
||||||
|
.CONTINUE_READING)
|
||||||
|
|
||||||
fun onCreate() {
|
fun onCreate() {
|
||||||
downloadManager.addListener(this)
|
downloadManager.addListener(this)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user