From 0cd551d4fd94703aa49ede6db811fd07c712b2bc Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 14 Jan 2021 17:37:54 -0500 Subject: [PATCH] Revert removal of tracker start/end date --- .../data/backup/full/models/BackupTracking.kt | 8 +- .../data/database/mappers/TrackTypeMapping.kt | 8 +- .../tachiyomi/data/database/models/Track.kt | 6 ++ .../data/database/models/TrackImpl.kt | 4 + .../tachiyomi/data/track/TrackService.kt | 3 + .../tachiyomi/data/track/model/TrackSearch.kt | 4 + .../manga/track/SetTrackReadingDatesDialog.kt | 85 +++++++++++++++++++ .../tachiyomi/ui/manga/track/TrackAdapter.kt | 2 + .../ui/manga/track/TrackController.kt | 25 +++++- .../tachiyomi/ui/manga/track/TrackHolder.kt | 19 +++++ .../ui/manga/track/TrackPresenter.kt | 12 +++ app/src/main/res/layout/track_item.xml | 57 ++++++++++++- app/src/main/res/values/strings.xml | 2 + 13 files changed, 226 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupTracking.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupTracking.kt index c47897c8f9..270adf2bfa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupTracking.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupTracking.kt @@ -22,9 +22,9 @@ data class BackupTracking( @ProtoNumber(8) var score: Float = 0F, @ProtoNumber(9) var status: Int = 0, // startedReadingDate is called startReadTime in 1.x - // @ProtoNumber(10) var startedReadingDate: Long = 0, + @ProtoNumber(10) var startedReadingDate: Long = 0, // finishedReadingDate is called endReadTime in 1.x - // @ProtoNumber(11) var finishedReadingDate: Long = 0, + @ProtoNumber(11) var finishedReadingDate: Long = 0, ) { fun getTrackingImpl(): TrackImpl { return TrackImpl().apply { @@ -37,6 +37,8 @@ data class BackupTracking( total_chapters = this@BackupTracking.totalChapters score = this@BackupTracking.score status = this@BackupTracking.status + started_reading_date = this@BackupTracking.startedReadingDate + finished_reading_date = this@BackupTracking.finishedReadingDate tracking_url = this@BackupTracking.trackingUrl } } @@ -54,6 +56,8 @@ data class BackupTracking( totalChapters = track.total_chapters, score = track.score, status = track.status, + startedReadingDate = track.started_reading_date, + finishedReadingDate = track.finished_reading_date, trackingUrl = track.tracking_url ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/TrackTypeMapping.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/TrackTypeMapping.kt index ce7d137265..94de567ad5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/TrackTypeMapping.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/TrackTypeMapping.kt @@ -56,10 +56,8 @@ class TrackPutResolver : DefaultPutResolver() { put(COL_STATUS, obj.status) put(COL_TRACKING_URL, obj.tracking_url) put(COL_SCORE, obj.score) - - // These aren't used anymore - put(COL_START_DATE, 0) - put(COL_FINISH_DATE, 0) + put(COL_START_DATE, obj.started_reading_date) + put(COL_FINISH_DATE, obj.finished_reading_date) } } @@ -77,6 +75,8 @@ class TrackGetResolver : DefaultGetResolver() { status = cursor.getInt(cursor.getColumnIndex(COL_STATUS)) score = cursor.getFloat(cursor.getColumnIndex(COL_SCORE)) tracking_url = cursor.getString(cursor.getColumnIndex(COL_TRACKING_URL)) + started_reading_date = cursor.getLong(cursor.getColumnIndex(COL_START_DATE)) + finished_reading_date = cursor.getLong(cursor.getColumnIndex(COL_FINISH_DATE)) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Track.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Track.kt index c64363efa0..0f3815c544 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Track.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Track.kt @@ -24,12 +24,18 @@ interface Track : Serializable { var status: Int + var started_reading_date: Long + + var finished_reading_date: Long + var tracking_url: String fun copyPersonalFrom(other: Track) { last_chapter_read = other.last_chapter_read score = other.score status = other.status + started_reading_date = other.started_reading_date + finished_reading_date = other.finished_reading_date } companion object { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/TrackImpl.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/TrackImpl.kt index 03a878e146..6f5991133c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/TrackImpl.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/TrackImpl.kt @@ -22,6 +22,10 @@ class TrackImpl : Track { override var status: Int = 0 + override var started_reading_date: Long = 0 + + override var finished_reading_date: Long = 0 + override var tracking_url: String = "" override fun equals(other: Any?): Boolean { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt index 906edc040b..884fdf4c05 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt @@ -21,6 +21,9 @@ abstract class TrackService(val id: Int) { // Name of the manga sync service to display abstract val name: String + // Application and remote support for reading dates + open val supportsReadingDates: Boolean = false + @DrawableRes abstract fun getLogo(): Int diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt index ee1100b763..9035f55502 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt @@ -24,6 +24,10 @@ class TrackSearch : Track { override var status: Int = 0 + override var started_reading_date: Long = 0 + + override var finished_reading_date: Long = 0 + override lateinit var tracking_url: String var cover_url: String = "" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt new file mode 100644 index 0000000000..f1e0ee5ffe --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/SetTrackReadingDatesDialog.kt @@ -0,0 +1,85 @@ +package eu.kanade.tachiyomi.ui.manga.track + +import android.app.Dialog +import android.os.Bundle +import androidx.core.os.bundleOf +import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.datetime.datePicker +import com.bluelinelabs.conductor.Controller +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.database.models.Track +import eu.kanade.tachiyomi.data.track.TrackManager +import eu.kanade.tachiyomi.ui.base.controller.DialogController +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get +import java.util.Calendar + +class SetTrackReadingDatesDialog : DialogController + where T : Controller, T : SetTrackReadingDatesDialog.Listener { + + private val item: TrackItem + + private val dateToUpdate: ReadingDate + + constructor(target: T, dateToUpdate: ReadingDate, item: TrackItem) : super( + bundleOf(KEY_ITEM_TRACK to item.track) + ) { + targetController = target + this.item = item + this.dateToUpdate = dateToUpdate + } + + @Suppress("unused") + constructor(bundle: Bundle) : super(bundle) { + val track = bundle.getSerializable(KEY_ITEM_TRACK) as Track + val service = Injekt.get().getService(track.sync_id)!! + item = TrackItem(track, service) + dateToUpdate = ReadingDate.Start + } + + override fun onCreateDialog(savedViewState: Bundle?): Dialog { + val listener = (targetController as? Listener) + + return MaterialDialog(activity!!) + .title( + when (dateToUpdate) { + ReadingDate.Start -> R.string.track_started_reading_date + ReadingDate.Finish -> R.string.track_finished_reading_date + } + ) + .datePicker(currentDate = getCurrentDate()) { _, date -> + listener?.setReadingDate(item, dateToUpdate, date.timeInMillis) + } + .neutralButton(R.string.action_remove) { + listener?.setReadingDate(item, dateToUpdate, 0L) + } + } + + private fun getCurrentDate(): Calendar { + // Today if no date is set, otherwise the already set date + return Calendar.getInstance().apply { + item.track?.let { + val date = when (dateToUpdate) { + ReadingDate.Start -> it.started_reading_date + ReadingDate.Finish -> it.finished_reading_date + } + if (date != 0L) { + timeInMillis = date + } + } + } + } + + interface Listener { + fun setReadingDate(item: TrackItem, type: ReadingDate, date: Long) + } + + enum class ReadingDate { + Start, + Finish + } + + companion object { + private const val KEY_ITEM_TRACK = "SetTrackReadingDatesDialog.item.track" + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackAdapter.kt index 28b50c1b3f..221212ef7f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackAdapter.kt @@ -43,5 +43,7 @@ class TrackAdapter(controller: TrackController) : RecyclerView.Adapter presenter.setStartDate(item, date) + SetTrackReadingDatesDialog.ReadingDate.Finish -> presenter.setFinishDate(item, date) + } + binding.swipeRefresh.isRefreshing = true + } + private companion object { const val MANGA_EXTRA = "manga" const val TAG_SEARCH_CONTROLLER = "track_search_controller" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt index 4e98f8178c..1279335aa9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt @@ -6,11 +6,16 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.TrackItemBinding import eu.kanade.tachiyomi.ui.base.holder.BaseViewHolder import uy.kohesive.injekt.injectLazy +import java.text.DateFormat class TrackHolder(private val binding: TrackItemBinding, adapter: TrackAdapter) : BaseViewHolder(binding.root) { private val preferences: PreferencesHelper by injectLazy() + private val dateFormat: DateFormat by lazy { + preferences.dateFormat() + } + init { val listener = adapter.rowClickListener @@ -24,6 +29,8 @@ class TrackHolder(private val binding: TrackItemBinding, adapter: TrackAdapter) binding.trackStatus.setOnClickListener { listener.onStatusClick(bindingAdapterPosition) } binding.trackChapters.setOnClickListener { listener.onChaptersClick(bindingAdapterPosition) } binding.trackScore.setOnClickListener { listener.onScoreClick(bindingAdapterPosition) } + binding.trackStartDate.setOnClickListener { listener.onStartDateClick(bindingAdapterPosition) } + binding.trackFinishDate.setOnClickListener { listener.onFinishDateClick(bindingAdapterPosition) } } @SuppressLint("SetTextI18n") @@ -42,6 +49,18 @@ class TrackHolder(private val binding: TrackItemBinding, adapter: TrackAdapter) if (track.total_chapters > 0) track.total_chapters else "-" binding.trackStatus.text = item.service.getStatus(track.status) binding.trackScore.text = if (track.score == 0f) "-" else item.service.displayScore(track) + + if (item.service.supportsReadingDates) { + binding.trackStartDate.text = + if (track.started_reading_date != 0L) dateFormat.format(track.started_reading_date) else "-" + binding.trackFinishDate.text = + if (track.finished_reading_date != 0L) dateFormat.format(track.finished_reading_date) else "-" + } else { + binding.bottomDivider.isVisible = false + binding.vertDivider3.isVisible = false + binding.trackStartDate.isVisible = false + binding.trackFinishDate.isVisible = false + } } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackPresenter.kt index 341ac207d4..4e12028176 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackPresenter.kt @@ -149,4 +149,16 @@ class TrackPresenter( } updateRemote(track, item.service) } + + fun setStartDate(item: TrackItem, date: Long) { + val track = item.track!! + track.started_reading_date = date + updateRemote(track, item.service) + } + + fun setFinishDate(item: TrackItem, date: Long) { + val track = item.track!! + track.finished_reading_date = date + updateRemote(track, item.service) + } } diff --git a/app/src/main/res/layout/track_item.xml b/app/src/main/res/layout/track_item.xml index 350476d46e..47b2f94717 100644 --- a/app/src/main/res/layout/track_item.xml +++ b/app/src/main/res/layout/track_item.xml @@ -105,7 +105,7 @@ android:layout_marginBottom="8dp" android:alpha="0.25" android:background="?android:attr/textColorHint" - app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintBottom_toTopOf="@+id/bottom_divider" app:layout_constraintEnd_toStartOf="@+id/track_chapters" app:layout_constraintStart_toEndOf="@+id/track_status" app:layout_constraintTop_toTopOf="parent" /> @@ -133,7 +133,7 @@ android:layout_marginBottom="8dp" android:alpha="0.25" android:background="?android:attr/textColorHint" - app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintBottom_toTopOf="@+id/bottom_divider" app:layout_constraintEnd_toStartOf="@+id/track_score" app:layout_constraintStart_toEndOf="@+id/track_chapters" app:layout_constraintTop_toTopOf="parent" /> @@ -153,6 +153,59 @@ app:layout_constraintTop_toBottomOf="@+id/top_divider" tools:text="10" /> + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 50e121a78f..599ee6098c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -569,6 +569,8 @@ Status Status Started + Started reading date + Finished reading date Type Author Invalid date supplied