Linting fixes
This commit is contained in:
@@ -26,8 +26,11 @@ class HistoryAdapter(controller: HistoryController) :
|
||||
/**
|
||||
* DecimalFormat used to display correct chapter number
|
||||
*/
|
||||
val decimalFormat = DecimalFormat("#.###", DecimalFormatSymbols()
|
||||
.apply { decimalSeparator = '.' })
|
||||
val decimalFormat = DecimalFormat(
|
||||
"#.###",
|
||||
DecimalFormatSymbols()
|
||||
.apply { decimalSeparator = '.' }
|
||||
)
|
||||
|
||||
init {
|
||||
setDisplayHeadersAtStartUp(true)
|
||||
|
||||
@@ -22,14 +22,15 @@ import eu.kanade.tachiyomi.util.system.toast
|
||||
* Uses [R.layout.history_controller].
|
||||
* UI related actions should be called from here.
|
||||
*/
|
||||
class HistoryController : NucleusController<HistoryControllerBinding, HistoryPresenter>(),
|
||||
RootController,
|
||||
NoToolbarElevationController,
|
||||
FlexibleAdapter.OnUpdateListener,
|
||||
HistoryAdapter.OnRemoveClickListener,
|
||||
HistoryAdapter.OnResumeClickListener,
|
||||
HistoryAdapter.OnItemClickListener,
|
||||
RemoveHistoryDialog.Listener {
|
||||
class HistoryController :
|
||||
NucleusController<HistoryControllerBinding, HistoryPresenter>(),
|
||||
RootController,
|
||||
NoToolbarElevationController,
|
||||
FlexibleAdapter.OnUpdateListener,
|
||||
HistoryAdapter.OnRemoveClickListener,
|
||||
HistoryAdapter.OnResumeClickListener,
|
||||
HistoryAdapter.OnItemClickListener,
|
||||
RemoveHistoryDialog.Listener {
|
||||
|
||||
/**
|
||||
* Adapter containing the recent manga.
|
||||
|
||||
@@ -59,16 +59,16 @@ class HistoryHolder(
|
||||
// Set chapter number + timestamp
|
||||
val formattedNumber = adapter.decimalFormat.format(chapter.chapter_number.toDouble())
|
||||
manga_subtitle.text = itemView.context.getString(R.string.recent_manga_time)
|
||||
.format(formattedNumber, Date(history.last_read).toTimestampString())
|
||||
.format(formattedNumber, Date(history.last_read).toTimestampString())
|
||||
|
||||
// Set cover
|
||||
GlideApp.with(itemView.context).clear(cover)
|
||||
if (!manga.thumbnail_url.isNullOrEmpty()) {
|
||||
GlideApp.with(itemView.context)
|
||||
.load(manga.toMangaThumbnail())
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.centerCrop()
|
||||
.into(cover)
|
||||
.load(manga.toMangaThumbnail())
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.centerCrop()
|
||||
.into(cover)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory
|
||||
import eu.kanade.tachiyomi.ui.recent.DateSectionItem
|
||||
|
||||
class HistoryItem(val mch: MangaChapterHistory, header: DateSectionItem) :
|
||||
AbstractSectionableItem<HistoryHolder, DateSectionItem>(header) {
|
||||
AbstractSectionableItem<HistoryHolder, DateSectionItem>(header) {
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return R.layout.history_item
|
||||
|
||||
@@ -34,7 +34,7 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
|
||||
|
||||
// Used to get a list of recently read manga
|
||||
getRecentMangaObservable()
|
||||
.subscribeLatestCache(HistoryController::onNextManga)
|
||||
.subscribeLatestCache(HistoryController::onNextManga)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,16 +49,16 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
|
||||
}
|
||||
|
||||
return db.getRecentManga(cal.time).asRxObservable()
|
||||
.map { recents ->
|
||||
val map = TreeMap<Date, MutableList<MangaChapterHistory>> { d1, d2 -> d2.compareTo(d1) }
|
||||
val byDay = recents
|
||||
.groupByTo(map, { it.history.last_read.toDateKey() })
|
||||
byDay.flatMap { entry ->
|
||||
val dateItem = DateSectionItem(entry.key)
|
||||
entry.value.map { HistoryItem(it, dateItem) }
|
||||
}
|
||||
.map { recents ->
|
||||
val map = TreeMap<Date, MutableList<MangaChapterHistory>> { d1, d2 -> d2.compareTo(d1) }
|
||||
val byDay = recents
|
||||
.groupByTo(map, { it.history.last_read.toDateKey() })
|
||||
byDay.flatMap { entry ->
|
||||
val dateItem = DateSectionItem(entry.key)
|
||||
entry.value.map { HistoryItem(it, dateItem) }
|
||||
}
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +68,7 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
|
||||
fun removeFromHistory(history: History) {
|
||||
history.last_read = 0L
|
||||
db.updateHistoryLastRead(history).asRxObservable()
|
||||
.subscribe()
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,11 +77,11 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
|
||||
*/
|
||||
fun removeAllFromHistory(mangaId: Long) {
|
||||
db.getHistoryByMangaId(mangaId).asRxSingle()
|
||||
.map { list ->
|
||||
list.forEach { it.last_read = 0L }
|
||||
db.updateHistoryLastRead(list).executeAsBlocking()
|
||||
}
|
||||
.subscribe()
|
||||
.map { list ->
|
||||
list.forEach { it.last_read = 0L }
|
||||
db.updateHistoryLastRead(list).executeAsBlocking()
|
||||
}
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +102,7 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
|
||||
}
|
||||
|
||||
val chapters = db.getChapters(manga).executeAsBlocking()
|
||||
.sortedWith(Comparator { c1, c2 -> sortFunction(c1, c2) })
|
||||
.sortedWith(Comparator { c1, c2 -> sortFunction(c1, c2) })
|
||||
|
||||
val currChapterIndex = chapters.indexOfFirst { chapter.id == it.id }
|
||||
return when (manga.sorting) {
|
||||
@@ -111,11 +111,11 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
|
||||
val chapterNumber = chapter.chapter_number
|
||||
|
||||
((currChapterIndex + 1) until chapters.size)
|
||||
.map { chapters[it] }
|
||||
.firstOrNull {
|
||||
it.chapter_number > chapterNumber &&
|
||||
it.chapter_number <= chapterNumber + 1
|
||||
}
|
||||
.map { chapters[it] }
|
||||
.firstOrNull {
|
||||
it.chapter_number > chapterNumber &&
|
||||
it.chapter_number <= chapterNumber + 1
|
||||
}
|
||||
}
|
||||
else -> throw NotImplementedError("Unknown sorting method")
|
||||
}
|
||||
|
||||
@@ -34,10 +34,10 @@ class RemoveHistoryDialog<T>(bundle: Bundle? = null) : DialogController(bundle)
|
||||
}
|
||||
|
||||
return MaterialDialog(activity)
|
||||
.title(R.string.action_remove)
|
||||
.customView(view = dialogCheckboxView, horizontalPadding = true)
|
||||
.positiveButton(R.string.action_remove) { onPositive(dialogCheckboxView.isChecked()) }
|
||||
.negativeButton(android.R.string.cancel)
|
||||
.title(R.string.action_remove)
|
||||
.customView(view = dialogCheckboxView, horizontalPadding = true)
|
||||
.positiveButton(R.string.action_remove) { onPositive(dialogCheckboxView.isChecked()) }
|
||||
.negativeButton(android.R.string.cancel)
|
||||
}
|
||||
|
||||
private fun onPositive(checked: Boolean) {
|
||||
|
||||
+5
-5
@@ -19,11 +19,11 @@ class ConfirmDeleteChaptersDialog<T>(bundle: Bundle? = null) : DialogController(
|
||||
|
||||
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
||||
return MaterialDialog(activity!!)
|
||||
.message(R.string.confirm_delete_chapters)
|
||||
.positiveButton(android.R.string.ok) {
|
||||
(targetController as? Listener)?.deleteChapters(chaptersToDelete)
|
||||
}
|
||||
.negativeButton(android.R.string.cancel)
|
||||
.message(R.string.confirm_delete_chapters)
|
||||
.positiveButton(android.R.string.ok) {
|
||||
(targetController as? Listener)?.deleteChapters(chaptersToDelete)
|
||||
}
|
||||
.negativeButton(android.R.string.cancel)
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
|
||||
@@ -4,7 +4,7 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
|
||||
class UpdatesAdapter(val controller: UpdatesController) :
|
||||
FlexibleAdapter<IFlexible<*>>(null, controller, true) {
|
||||
FlexibleAdapter<IFlexible<*>>(null, controller, true) {
|
||||
|
||||
val coverClickListener: OnCoverClickListener = controller
|
||||
|
||||
|
||||
@@ -37,15 +37,16 @@ import timber.log.Timber
|
||||
* Uses [R.layout.updates_controller].
|
||||
* UI related actions should be called from here.
|
||||
*/
|
||||
class UpdatesController : NucleusController<UpdatesControllerBinding, UpdatesPresenter>(),
|
||||
RootController,
|
||||
NoToolbarElevationController,
|
||||
ActionMode.Callback,
|
||||
FlexibleAdapter.OnItemClickListener,
|
||||
FlexibleAdapter.OnItemLongClickListener,
|
||||
FlexibleAdapter.OnUpdateListener,
|
||||
ConfirmDeleteChaptersDialog.Listener,
|
||||
UpdatesAdapter.OnCoverClickListener {
|
||||
class UpdatesController :
|
||||
NucleusController<UpdatesControllerBinding, UpdatesPresenter>(),
|
||||
RootController,
|
||||
NoToolbarElevationController,
|
||||
ActionMode.Callback,
|
||||
FlexibleAdapter.OnItemClickListener,
|
||||
FlexibleAdapter.OnItemLongClickListener,
|
||||
FlexibleAdapter.OnUpdateListener,
|
||||
ConfirmDeleteChaptersDialog.Listener,
|
||||
UpdatesAdapter.OnCoverClickListener {
|
||||
|
||||
/**
|
||||
* Action mode for multiple selection.
|
||||
@@ -172,8 +173,8 @@ class UpdatesController : NucleusController<UpdatesControllerBinding, UpdatesPre
|
||||
if (actionMode == null) {
|
||||
actionMode = (activity as AppCompatActivity).startSupportActionMode(this)
|
||||
binding.actionToolbar.show(
|
||||
actionMode!!,
|
||||
R.menu.updates_chapter_selection
|
||||
actionMode!!,
|
||||
R.menu.updates_chapter_selection
|
||||
) { onActionItemClicked(actionMode!!, it!!) }
|
||||
}
|
||||
|
||||
@@ -334,7 +335,8 @@ class UpdatesController : NucleusController<UpdatesControllerBinding, UpdatesPre
|
||||
R.id.action_select_all -> selectAll()
|
||||
R.id.action_select_inverse -> selectInverse()
|
||||
R.id.action_download -> downloadChapters(getSelectedChapters())
|
||||
R.id.action_delete -> ConfirmDeleteChaptersDialog(this, getSelectedChapters())
|
||||
R.id.action_delete ->
|
||||
ConfirmDeleteChaptersDialog(this, getSelectedChapters())
|
||||
.showDialog(router)
|
||||
R.id.action_mark_as_read -> markAsRead(getSelectedChapters())
|
||||
R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters())
|
||||
|
||||
@@ -25,7 +25,7 @@ import kotlinx.android.synthetic.main.updates_item.manga_title
|
||||
* @constructor creates a new recent chapter holder.
|
||||
*/
|
||||
class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
|
||||
private var readColor = ContextCompat.getColor(view.context, R.color.material_on_surface_disabled)
|
||||
private var unreadColor = view.context.getResourceColor(R.attr.colorOnSurface)
|
||||
@@ -59,10 +59,10 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
|
||||
GlideApp.with(itemView.context).clear(manga_cover)
|
||||
if (!item.manga.thumbnail_url.isNullOrEmpty()) {
|
||||
GlideApp.with(itemView.context)
|
||||
.load(item.manga.toMangaThumbnail())
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.circleCrop()
|
||||
.into(manga_cover)
|
||||
.load(item.manga.toMangaThumbnail())
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.circleCrop()
|
||||
.into(manga_cover)
|
||||
}
|
||||
|
||||
// Check if chapter is read and set correct color
|
||||
|
||||
@@ -12,7 +12,7 @@ import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.ui.recent.DateSectionItem
|
||||
|
||||
class UpdatesItem(val chapter: Chapter, val manga: Manga, header: DateSectionItem) :
|
||||
AbstractSectionableItem<UpdatesHolder, DateSectionItem>(header) {
|
||||
AbstractSectionableItem<UpdatesHolder, DateSectionItem>(header) {
|
||||
|
||||
private var _status: Int = 0
|
||||
|
||||
|
||||
@@ -36,13 +36,13 @@ class UpdatesPresenter(
|
||||
super.onCreate(savedState)
|
||||
|
||||
getUpdatesObservable()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeLatestCache(UpdatesController::onNextRecentChapters)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeLatestCache(UpdatesController::onNextRecentChapters)
|
||||
|
||||
getChapterStatusObservable()
|
||||
.subscribeLatestCache(UpdatesController::onChapterStatusChange) { _, error ->
|
||||
Timber.e(error)
|
||||
}
|
||||
.subscribeLatestCache(UpdatesController::onChapterStatusChange) { _, error ->
|
||||
Timber.e(error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,32 +58,32 @@ class UpdatesPresenter(
|
||||
}
|
||||
|
||||
return db.getRecentChapters(cal.time).asRxObservable()
|
||||
// Convert to a list of recent chapters.
|
||||
.map { mangaChapters ->
|
||||
val map = TreeMap<Date, MutableList<MangaChapter>> { d1, d2 -> d2.compareTo(d1) }
|
||||
val byDay = mangaChapters
|
||||
.groupByTo(map, { it.chapter.date_fetch.toDateKey() })
|
||||
byDay.flatMap { entry ->
|
||||
val dateItem = DateSectionItem(entry.key)
|
||||
entry.value
|
||||
.sortedWith(compareBy({ it.chapter.date_fetch }, { it.chapter.chapter_number })).asReversed()
|
||||
.map { UpdatesItem(it.chapter, it.manga, dateItem) }
|
||||
}
|
||||
// Convert to a list of recent chapters.
|
||||
.map { mangaChapters ->
|
||||
val map = TreeMap<Date, MutableList<MangaChapter>> { d1, d2 -> d2.compareTo(d1) }
|
||||
val byDay = mangaChapters
|
||||
.groupByTo(map, { it.chapter.date_fetch.toDateKey() })
|
||||
byDay.flatMap { entry ->
|
||||
val dateItem = DateSectionItem(entry.key)
|
||||
entry.value
|
||||
.sortedWith(compareBy({ it.chapter.date_fetch }, { it.chapter.chapter_number })).asReversed()
|
||||
.map { UpdatesItem(it.chapter, it.manga, dateItem) }
|
||||
}
|
||||
.doOnNext { list ->
|
||||
list.forEach { item ->
|
||||
// Find an active download for this chapter.
|
||||
val download = downloadManager.queue.find { it.chapter.id == item.chapter.id }
|
||||
}
|
||||
.doOnNext { list ->
|
||||
list.forEach { item ->
|
||||
// Find an active download for this chapter.
|
||||
val download = downloadManager.queue.find { it.chapter.id == item.chapter.id }
|
||||
|
||||
// If there's an active download, assign it, otherwise ask the manager if
|
||||
// the chapter is downloaded and assign it to the status.
|
||||
if (download != null) {
|
||||
item.download = download
|
||||
}
|
||||
// If there's an active download, assign it, otherwise ask the manager if
|
||||
// the chapter is downloaded and assign it to the status.
|
||||
if (download != null) {
|
||||
item.download = download
|
||||
}
|
||||
setDownloadedChapters(list)
|
||||
chapters = list
|
||||
}
|
||||
setDownloadedChapters(list)
|
||||
chapters = list
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,8 +93,8 @@ class UpdatesPresenter(
|
||||
*/
|
||||
private fun getChapterStatusObservable(): Observable<Download> {
|
||||
return downloadManager.queue.getStatusObservable()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnNext { download -> onDownloadStatusChange(download) }
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnNext { download -> onDownloadStatusChange(download) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,8 +144,8 @@ class UpdatesPresenter(
|
||||
}
|
||||
|
||||
Observable.fromCallable { db.updateChaptersProgress(chapters).executeAsBlocking() }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,12 +155,15 @@ class UpdatesPresenter(
|
||||
*/
|
||||
fun deleteChapters(chapters: List<UpdatesItem>) {
|
||||
Observable.just(chapters)
|
||||
.doOnNext { deleteChaptersInternal(it) }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeFirst({ view, _ ->
|
||||
.doOnNext { deleteChaptersInternal(it) }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeFirst(
|
||||
{ view, _ ->
|
||||
view.onChaptersDeleted()
|
||||
}, UpdatesController::onChaptersDeletedError)
|
||||
},
|
||||
UpdatesController::onChaptersDeletedError
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user