mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-27 00:35:29 +01:00
Suggested Start/Completed Date for Trackers based on reading history
This commit is contained in:
parent
1e3de8a67f
commit
9090f87756
@ -929,7 +929,7 @@ class LibraryPresenter(
|
|||||||
libraryManga.forEach { manga ->
|
libraryManga.forEach { manga ->
|
||||||
if (manga.date_added == 0L) {
|
if (manga.date_added == 0L) {
|
||||||
val chapters = db.getChapters(manga).executeAsBlocking()
|
val chapters = db.getChapters(manga).executeAsBlocking()
|
||||||
manga.date_added = chapters.minBy { it.date_fetch }?.date_fetch ?: 0L
|
manga.date_added = chapters.minByOrNull { it.date_fetch }?.date_fetch ?: 0L
|
||||||
db.insertManga(manga).executeAsBlocking()
|
db.insertManga(manga).executeAsBlocking()
|
||||||
}
|
}
|
||||||
db.resetMangaInfo(manga).executeAsBlocking()
|
db.resetMangaInfo(manga).executeAsBlocking()
|
||||||
|
@ -30,6 +30,7 @@ import eu.kanade.tachiyomi.source.Source
|
|||||||
import eu.kanade.tachiyomi.source.model.toSChapter
|
import eu.kanade.tachiyomi.source.model.toSChapter
|
||||||
import eu.kanade.tachiyomi.source.model.toSManga
|
import eu.kanade.tachiyomi.source.model.toSManga
|
||||||
import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem
|
import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem
|
||||||
|
import eu.kanade.tachiyomi.ui.manga.track.SetTrackReadingDatesDialog
|
||||||
import eu.kanade.tachiyomi.ui.manga.track.TrackItem
|
import eu.kanade.tachiyomi.ui.manga.track.TrackItem
|
||||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||||
import eu.kanade.tachiyomi.util.chapter.ChapterFilter
|
import eu.kanade.tachiyomi.util.chapter.ChapterFilter
|
||||||
@ -895,6 +896,15 @@ class MangaDetailsPresenter(
|
|||||||
updateRemote(track, item.service)
|
updateRemote(track, item.service)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getSuggestedDate(readingDate: SetTrackReadingDatesDialog.ReadingDate): Long? {
|
||||||
|
val chapters = db.getHistoryByMangaId(manga.id ?: 0L).executeAsBlocking()
|
||||||
|
val date = when (readingDate) {
|
||||||
|
SetTrackReadingDatesDialog.ReadingDate.Start -> chapters.minByOrNull { it.last_read }?.last_read
|
||||||
|
SetTrackReadingDatesDialog.ReadingDate.Finish -> chapters.maxByOrNull { it.last_read }?.last_read
|
||||||
|
} ?: return null
|
||||||
|
return if (date <= 0L) null else date
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val MULTIPLE_VOLUMES = 1
|
const val MULTIPLE_VOLUMES = 1
|
||||||
const val TENS_OF_CHAPTERS = 2
|
const val TENS_OF_CHAPTERS = 2
|
||||||
|
@ -3,15 +3,22 @@ package eu.kanade.tachiyomi.ui.manga.track
|
|||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
|
import com.afollestad.date.dayOfMonth
|
||||||
|
import com.afollestad.date.month
|
||||||
|
import com.afollestad.date.year
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import com.afollestad.materialdialogs.datetime.datePicker
|
import com.afollestad.materialdialogs.datetime.datePicker
|
||||||
import com.bluelinelabs.conductor.Controller
|
import com.bluelinelabs.conductor.Controller
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Track
|
import eu.kanade.tachiyomi.data.database.models.Track
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||||
|
import eu.kanade.tachiyomi.util.view.setDate
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
import java.text.DateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
|
|
||||||
class SetTrackReadingDatesDialog<T> : DialogController
|
class SetTrackReadingDatesDialog<T> : DialogController
|
||||||
@ -20,16 +27,23 @@ class SetTrackReadingDatesDialog<T> : DialogController
|
|||||||
private val item: TrackItem
|
private val item: TrackItem
|
||||||
|
|
||||||
private val dateToUpdate: ReadingDate
|
private val dateToUpdate: ReadingDate
|
||||||
|
private val suggestedDate: Long?
|
||||||
|
|
||||||
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
|
private val dateFormat: DateFormat by lazy {
|
||||||
|
preferences.dateFormat()
|
||||||
|
}
|
||||||
|
|
||||||
private lateinit var listener: Listener
|
private lateinit var listener: Listener
|
||||||
|
|
||||||
constructor(target: T, listener: Listener, dateToUpdate: ReadingDate, item: TrackItem) : super(
|
constructor(target: T, listener: Listener, dateToUpdate: ReadingDate, item: TrackItem, suggestedDate: Long?) : super(
|
||||||
bundleOf(KEY_ITEM_TRACK to item.track)
|
bundleOf(KEY_ITEM_TRACK to item.track)
|
||||||
) {
|
) {
|
||||||
targetController = target
|
targetController = target
|
||||||
this.listener = listener
|
this.listener = listener
|
||||||
this.item = item
|
this.item = item
|
||||||
this.dateToUpdate = dateToUpdate
|
this.dateToUpdate = dateToUpdate
|
||||||
|
this.suggestedDate = suggestedDate
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@ -38,6 +52,7 @@ class SetTrackReadingDatesDialog<T> : DialogController
|
|||||||
val service = Injekt.get<TrackManager>().getService(track.sync_id)!!
|
val service = Injekt.get<TrackManager>().getService(track.sync_id)!!
|
||||||
item = TrackItem(track, service)
|
item = TrackItem(track, service)
|
||||||
dateToUpdate = ReadingDate.Start
|
dateToUpdate = ReadingDate.Start
|
||||||
|
suggestedDate = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
||||||
@ -53,12 +68,59 @@ class SetTrackReadingDatesDialog<T> : DialogController
|
|||||||
}
|
}
|
||||||
.neutralButton(R.string.remove) {
|
.neutralButton(R.string.remove) {
|
||||||
listener.setReadingDate(item, dateToUpdate, 0L)
|
listener.setReadingDate(item, dateToUpdate, 0L)
|
||||||
|
}.apply {
|
||||||
|
getSuggestedDate()?.let {
|
||||||
|
message(text = it,
|
||||||
|
applySettings = {
|
||||||
|
messageTextView.setOnClickListener {
|
||||||
|
this@apply.setDate(suggestedDate ?: 0L)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSuggestedDate(): String? {
|
||||||
|
item.track ?: return null
|
||||||
|
val date = when (dateToUpdate) {
|
||||||
|
ReadingDate.Start -> item.track.started_reading_date
|
||||||
|
ReadingDate.Finish -> item.track.finished_reading_date
|
||||||
|
}
|
||||||
|
if (date != 0L) {
|
||||||
|
if (suggestedDate != null) {
|
||||||
|
val calendar = Calendar.getInstance()
|
||||||
|
calendar.timeInMillis = date
|
||||||
|
val suggestedCalendar = Calendar.getInstance()
|
||||||
|
suggestedCalendar.timeInMillis = suggestedDate
|
||||||
|
return if (date > suggestedDate &&
|
||||||
|
(suggestedCalendar.year != calendar.year ||
|
||||||
|
suggestedCalendar.month != calendar.month ||
|
||||||
|
suggestedCalendar.dayOfMonth != calendar.dayOfMonth)
|
||||||
|
) {
|
||||||
|
activity?.getString(
|
||||||
|
R.string.suggested_date_,
|
||||||
|
dateFormat.format(suggestedDate)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
suggestedDate?.let {
|
||||||
|
return activity?.getString(
|
||||||
|
R.string.suggested_date_,
|
||||||
|
dateFormat.format(suggestedDate)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCurrentDate(): Calendar {
|
private fun getCurrentDate(): Calendar {
|
||||||
// Today if no date is set, otherwise the already set date
|
// Today if no date is set, otherwise the already set date
|
||||||
return Calendar.getInstance().apply {
|
return Calendar.getInstance().apply {
|
||||||
|
suggestedDate?.let {
|
||||||
|
timeInMillis = it
|
||||||
|
}
|
||||||
item.track?.let {
|
item.track?.let {
|
||||||
val date = when (dateToUpdate) {
|
val date = when (dateToUpdate) {
|
||||||
ReadingDate.Start -> it.started_reading_date
|
ReadingDate.Start -> it.started_reading_date
|
||||||
|
@ -187,14 +187,26 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) :
|
|||||||
val item = adapter?.getItem(position) ?: return
|
val item = adapter?.getItem(position) ?: return
|
||||||
if (item.track == null) return
|
if (item.track == null) return
|
||||||
|
|
||||||
SetTrackReadingDatesDialog(controller, this, SetTrackReadingDatesDialog.ReadingDate.Start, item).showDialog(controller.router)
|
val suggestedDate = presenter.getSuggestedDate(SetTrackReadingDatesDialog.ReadingDate.Start)
|
||||||
|
SetTrackReadingDatesDialog(controller,
|
||||||
|
this,
|
||||||
|
SetTrackReadingDatesDialog.ReadingDate.Start,
|
||||||
|
item,
|
||||||
|
suggestedDate)
|
||||||
|
.showDialog(controller.router)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFinishDateClick(position: Int) {
|
override fun onFinishDateClick(position: Int) {
|
||||||
val item = adapter?.getItem(position) ?: return
|
val item = adapter?.getItem(position) ?: return
|
||||||
if (item.track == null) return
|
if (item.track == null) return
|
||||||
|
|
||||||
SetTrackReadingDatesDialog(controller, this, SetTrackReadingDatesDialog.ReadingDate.Finish, item).showDialog(controller.router)
|
val suggestedDate = presenter.getSuggestedDate(SetTrackReadingDatesDialog.ReadingDate.Finish)
|
||||||
|
SetTrackReadingDatesDialog(controller,
|
||||||
|
this,
|
||||||
|
SetTrackReadingDatesDialog.ReadingDate.Finish,
|
||||||
|
item,
|
||||||
|
suggestedDate)
|
||||||
|
.showDialog(controller.router)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setStatus(item: TrackItem, selection: Int) {
|
override fun setStatus(item: TrackItem, selection: Int) {
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package eu.kanade.tachiyomi.util.view
|
||||||
|
|
||||||
|
import com.afollestad.date.DatePicker
|
||||||
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
|
import java.util.Calendar
|
||||||
|
|
||||||
|
fun MaterialDialog.setDate(date: Long) {
|
||||||
|
val datePicker = findViewById<DatePicker>(com.afollestad.materialdialogs.datetime.R.id.datetimeDatePicker) ?: return
|
||||||
|
val calendar = Calendar.getInstance()
|
||||||
|
calendar.timeInMillis = date
|
||||||
|
datePicker.setDate(calendar)
|
||||||
|
}
|
@ -436,6 +436,7 @@
|
|||||||
<string name="started_reading_date">Started reading date</string>
|
<string name="started_reading_date">Started reading date</string>
|
||||||
<string name="finished_reading_date">Finished reading date</string>
|
<string name="finished_reading_date">Finished reading date</string>
|
||||||
<string name="myanimelist_relogin">Please login to MAL again</string>
|
<string name="myanimelist_relogin">Please login to MAL again</string>
|
||||||
|
<string name="suggested_date_">Suggested date: %1$s</string>
|
||||||
|
|
||||||
<!-- Migration -->
|
<!-- Migration -->
|
||||||
<string name="select_sources">Select sources</string>
|
<string name="select_sources">Select sources</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user