From 51a34c9bef4355f472b0e8a42747d93045e9be26 Mon Sep 17 00:00:00 2001 From: NoodleMage Date: Sat, 21 May 2016 20:55:27 +0200 Subject: [PATCH] Added recently read tab --- .../tachiyomi/data/database/DatabaseHelper.kt | 3 +- .../tachiyomi/data/database/DbOpenHelper.kt | 8 +- .../data/database/models/History.java | 29 +++++ .../data/database/queries/HistoryQueries.kt | 33 ++++++ .../data/database/queries/RawQueries.kt | 11 ++ .../data/database/tables/HistoryTable.kt | 25 ++++ .../injection/component/AppComponent.kt | 4 +- .../kanade/tachiyomi/ui/main/MainActivity.kt | 4 +- .../tachiyomi/ui/reader/ReaderPresenter.kt | 14 +++ .../{ => chapters}/RecentChaptersAdapter.kt | 4 +- .../{ => chapters}/RecentChaptersFragment.kt | 4 +- .../{ => chapters}/RecentChaptersHolder.kt | 8 +- .../{ => chapters}/RecentChaptersPresenter.kt | 2 +- .../{ => chapters}/SectionViewHolder.kt | 2 +- .../ui/recent/manga/RecentMangaAdapter.kt | 44 +++++++ .../ui/recent/manga/RecentMangaFragment.kt | 108 ++++++++++++++++++ .../ui/recent/manga/RecentMangaHolder.kt | 43 +++++++ .../ui/recent/manga/RecentMangaPresenter.kt | 73 ++++++++++++ .../res/drawable/ic_glasses_black_128dp.xml | 9 ++ .../res/drawable/ic_glasses_black_24dp.xml | 9 ++ .../res/drawable/ic_history_black_128dp.xml | 9 -- .../res/drawable/ic_history_black_24dp.xml | 9 -- .../res/drawable/ic_update_black_128dp.xml | 9 ++ .../res/drawable/ic_update_black_24dp.xml | 9 ++ .../res/layout/fragment_recent_chapters.xml | 3 +- .../main/res/layout/fragment_recent_manga.xml | 16 +++ ...t_chapter.xml => item_recent_chapters.xml} | 0 app/src/main/res/layout/item_recent_manga.xml | 76 ++++++++++++ app/src/main/res/menu/menu_navigation.xml | 7 +- app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/strings.xml | 4 + app/src/main/res/values/styles.xml | 10 ++ 32 files changed, 556 insertions(+), 35 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/models/History.java create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/tables/HistoryTable.kt rename app/src/main/java/eu/kanade/tachiyomi/ui/recent/{ => chapters}/RecentChaptersAdapter.kt (98%) rename app/src/main/java/eu/kanade/tachiyomi/ui/recent/{ => chapters}/RecentChaptersFragment.kt (97%) rename app/src/main/java/eu/kanade/tachiyomi/ui/recent/{ => chapters}/RecentChaptersHolder.kt (95%) rename app/src/main/java/eu/kanade/tachiyomi/ui/recent/{ => chapters}/RecentChaptersPresenter.kt (99%) rename app/src/main/java/eu/kanade/tachiyomi/ui/recent/{ => chapters}/SectionViewHolder.kt (92%) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaAdapter.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaFragment.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaHolder.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaPresenter.kt create mode 100644 app/src/main/res/drawable/ic_glasses_black_128dp.xml create mode 100644 app/src/main/res/drawable/ic_glasses_black_24dp.xml delete mode 100644 app/src/main/res/drawable/ic_history_black_128dp.xml delete mode 100644 app/src/main/res/drawable/ic_history_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_update_black_128dp.xml create mode 100644 app/src/main/res/drawable/ic_update_black_24dp.xml create mode 100644 app/src/main/res/layout/fragment_recent_manga.xml rename app/src/main/res/layout/{item_recent_chapter.xml => item_recent_chapters.xml} (100%) create mode 100644 app/src/main/res/layout/item_recent_manga.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt index 39245162d5..778376f5be 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt @@ -9,7 +9,7 @@ import eu.kanade.tachiyomi.data.database.queries.* * This class provides operations to manage the database through its interfaces. */ open class DatabaseHelper(context: Context) -: MangaQueries, ChapterQueries, MangaSyncQueries, CategoryQueries, MangaCategoryQueries { +: MangaQueries, ChapterQueries, MangaSyncQueries, CategoryQueries, MangaCategoryQueries, HistoryQueries { override val db = DefaultStorIOSQLite.builder() .sqliteOpenHelper(DbOpenHelper(context)) @@ -18,6 +18,7 @@ open class DatabaseHelper(context: Context) .addTypeMapping(MangaSync::class.java, MangaSyncSQLiteTypeMapping()) .addTypeMapping(Category::class.java, CategorySQLiteTypeMapping()) .addTypeMapping(MangaCategory::class.java, MangaCategorySQLiteTypeMapping()) + .addTypeMapping(History::class.java, HistorySQLiteTypeMapping()) .build() inline fun inTransaction(block: () -> Unit) = db.inTransaction(block) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenHelper.kt index 7e1a53445e..27cc6ea26d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenHelper.kt @@ -17,7 +17,7 @@ class DbOpenHelper(context: Context) /** * Version of the database. */ - const val DATABASE_VERSION = 2 + const val DATABASE_VERSION = 3 } override fun onCreate(db: SQLiteDatabase) = with(db) { @@ -26,17 +26,23 @@ class DbOpenHelper(context: Context) execSQL(MangaSyncTable.createTableQuery) execSQL(CategoryTable.createTableQuery) execSQL(MangaCategoryTable.createTableQuery) + execSQL(HistoryTable.createTableQuery) // DB indexes execSQL(MangaTable.createUrlIndexQuery) execSQL(MangaTable.createFavoriteIndexQuery) execSQL(ChapterTable.createMangaIdIndexQuery) + execSQL(HistoryTable.createMangaIdIndexQuery) } override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { if (oldVersion < 2) { db.execSQL(ChapterTable.sourceOrderUpdateQuery) } + if (oldVersion < 3) { + db.execSQL(HistoryTable.createTableQuery) + db.execSQL(HistoryTable.createMangaIdIndexQuery) + } } override fun onConfigure(db: SQLiteDatabase) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/History.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/History.java new file mode 100644 index 0000000000..f3eb26add7 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/History.java @@ -0,0 +1,29 @@ +package eu.kanade.tachiyomi.data.database.models; + +import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn; +import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType; + +import eu.kanade.tachiyomi.data.database.tables.HistoryTable; + +@StorIOSQLiteType(table = HistoryTable.TABLE) +public class History { + + @StorIOSQLiteColumn(name = HistoryTable.COL_ID, key = true) + public Long id; + + @StorIOSQLiteColumn(name = HistoryTable.COL_MANGA_ID) + public long manga_id; + + @StorIOSQLiteColumn(name = HistoryTable.COL_LAST_READ) + public long last_read; + + public History() { + } + + public static History create(Manga manga) { + History history = new History(); + history.manga_id = manga.id; + return history; + } + +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt new file mode 100644 index 0000000000..d0a8714344 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt @@ -0,0 +1,33 @@ +package eu.kanade.tachiyomi.data.database.queries + +import com.pushtorefresh.storio.sqlite.queries.Query +import com.pushtorefresh.storio.sqlite.queries.RawQuery +import eu.kanade.tachiyomi.data.database.DbProvider +import eu.kanade.tachiyomi.data.database.models.History +import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.database.tables.HistoryTable +import java.util.* + +interface HistoryQueries : DbProvider { + + fun insertHistory(history: History) = db.put().`object`(history).prepare() + + fun getRecentManga(date: Date) = db.get() + .listOfObjects(Manga::class.java) + .withQuery(RawQuery.builder() + .query(getRecentMangasQuery()) + .args(date.time) + .observesTables(HistoryTable.TABLE) + .build()) + .prepare() + + fun getHistoryByMangaId(id: Long) = db.get() + .`object`(History::class.java) + .withQuery(Query.builder() + .table(HistoryTable.TABLE) + .where("${HistoryTable.COL_MANGA_ID} = ?") + .whereArgs(id) + .build()) + .prepare() + +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt index 305fd3824e..4160b8f906 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.database.queries import eu.kanade.tachiyomi.data.database.tables.CategoryTable as Category import eu.kanade.tachiyomi.data.database.tables.ChapterTable as Chapter +import eu.kanade.tachiyomi.data.database.tables.HistoryTable as History import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable as MangaCategory import eu.kanade.tachiyomi.data.database.tables.MangaTable as Manga @@ -39,6 +40,16 @@ fun getRecentsQuery() = """ ORDER BY ${Chapter.COL_DATE_UPLOAD} DESC """ +/** + * Query to get the recent chapters of manga from the library up to a date. + */ +fun getRecentMangasQuery() = """ + SELECT ${Manga.TABLE}.* FROM ${Manga.TABLE} JOIN ${History.TABLE} + ON ${Manga.TABLE}.${Manga.COL_ID} = ${History.TABLE}.${History.COL_MANGA_ID} + WHERE ${History.COL_LAST_READ} > ? + ORDER BY ${History.COL_LAST_READ} DESC +""" + /** * Query to get the categories for a manga. diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/HistoryTable.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/HistoryTable.kt new file mode 100644 index 0000000000..9d63311714 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/HistoryTable.kt @@ -0,0 +1,25 @@ +package eu.kanade.tachiyomi.data.database.tables + +object HistoryTable { + + const val TABLE = "history" + + const val COL_ID = "_id" + + const val COL_MANGA_ID = "manga_id" + + const val COL_LAST_READ = "last_read" + + + val createTableQuery: String + get() = """CREATE TABLE $TABLE( + $COL_ID INTEGER NOT NULL PRIMARY KEY, + $COL_MANGA_ID INTEGER NOT NULL, + $COL_LAST_READ LONG, + FOREIGN KEY($COL_MANGA_ID) REFERENCES ${MangaTable.TABLE} (${MangaTable.COL_ID}) + ON DELETE CASCADE + )""" + + val createMangaIdIndexQuery: String + get() = "CREATE INDEX ${HistoryTable.TABLE}_${HistoryTable.COL_MANGA_ID}_index ON ${HistoryTable.TABLE}(${HistoryTable.COL_MANGA_ID})" +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/injection/component/AppComponent.kt b/app/src/main/java/eu/kanade/tachiyomi/injection/component/AppComponent.kt index 65ca31cc53..0616915e91 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/injection/component/AppComponent.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/injection/component/AppComponent.kt @@ -24,7 +24,8 @@ import eu.kanade.tachiyomi.ui.manga.chapter.ChaptersPresenter import eu.kanade.tachiyomi.ui.manga.info.MangaInfoPresenter import eu.kanade.tachiyomi.ui.manga.myanimelist.MyAnimeListPresenter import eu.kanade.tachiyomi.ui.reader.ReaderPresenter -import eu.kanade.tachiyomi.ui.recent.RecentChaptersPresenter +import eu.kanade.tachiyomi.ui.recent.chapters.RecentChaptersPresenter +import eu.kanade.tachiyomi.ui.recent.manga.RecentMangaPresenter import eu.kanade.tachiyomi.ui.setting.SettingsActivity import javax.inject.Singleton @@ -42,6 +43,7 @@ interface AppComponent { fun inject(myAnimeListPresenter: MyAnimeListPresenter) fun inject(categoryPresenter: CategoryPresenter) fun inject(recentChaptersPresenter: RecentChaptersPresenter) + fun inject(recentMangaPresenter: RecentMangaPresenter) fun inject(backupPresenter: BackupPresenter) fun inject(mainActivity: MainActivity) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 300cef6a42..569447365b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -13,7 +13,8 @@ import eu.kanade.tachiyomi.ui.base.activity.BaseActivity import eu.kanade.tachiyomi.ui.catalogue.CatalogueFragment import eu.kanade.tachiyomi.ui.download.DownloadFragment import eu.kanade.tachiyomi.ui.library.LibraryFragment -import eu.kanade.tachiyomi.ui.recent.RecentChaptersFragment +import eu.kanade.tachiyomi.ui.recent.chapters.RecentChaptersFragment +import eu.kanade.tachiyomi.ui.recent.manga.RecentMangaFragment import eu.kanade.tachiyomi.ui.setting.SettingsActivity import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.toolbar.* @@ -50,6 +51,7 @@ class MainActivity : BaseActivity() { when (item.itemId) { R.id.nav_drawer_library -> setFragment(LibraryFragment.newInstance()) R.id.nav_drawer_recent_updates -> setFragment(RecentChaptersFragment.newInstance()) + R.id.nav_drawer_recent_manga -> setFragment(RecentMangaFragment.newInstance()) R.id.nav_drawer_catalogues -> setFragment(CatalogueFragment.newInstance()) R.id.nav_drawer_downloads -> setFragment(DownloadFragment.newInstance()) R.id.nav_drawer_settings -> startActivity(Intent(this, SettingsActivity::class.java)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index c21217683f..dde4ba2bde 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -4,6 +4,7 @@ import android.os.Bundle import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Chapter +import eu.kanade.tachiyomi.data.database.models.History import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaSync import eu.kanade.tachiyomi.data.download.DownloadManager @@ -24,6 +25,7 @@ import rx.schedulers.Schedulers import rx.subjects.PublishSubject import timber.log.Timber import java.io.File +import java.util.* import javax.inject.Inject class ReaderPresenter : BasePresenter() { @@ -83,6 +85,8 @@ class ReaderPresenter : BasePresenter() { initializeSubjects() + setMangaLastRead() + startableLatestCache(GET_ADJACENT_CHAPTERS, { getAdjacentChaptersObservable() }, { view, pair -> view.onAdjacentChapters(pair.first, pair.second) }) @@ -222,6 +226,15 @@ class ReaderPresenter : BasePresenter() { .doOnNext { mangaSyncList = it } } + private fun setMangaLastRead() { + var history = db.getHistoryByMangaId(manga.id).executeAsBlocking() + if (history == null) { + history = History.create(manga) + } + history?.last_read = Date().time + db.insertHistory(history!!).executeAsBlocking() + } + // Loads the given chapter private fun loadChapter(chapter: Chapter, requestedPage: Int = 0) { if (isSeamlessMode) { @@ -283,6 +296,7 @@ class ReaderPresenter : BasePresenter() { } } + // Check whether the given chapter is downloaded fun isChapterDownloaded(chapter: Chapter): Boolean { return downloadManager.isChapterDownloaded(source, manga, chapter) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/RecentChaptersAdapter.kt similarity index 98% rename from app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersAdapter.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/RecentChaptersAdapter.kt index 1bfe5ef522..a98e979a6d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/RecentChaptersAdapter.kt @@ -1,4 +1,4 @@ -package eu.kanade.tachiyomi.ui.recent +package eu.kanade.tachiyomi.ui.recent.chapters import android.support.v7.widget.RecyclerView import android.view.View @@ -72,7 +72,7 @@ class RecentChaptersAdapter(val fragment: RecentChaptersFragment) : FlexibleAdap // Check which view type and set correct values. when (viewType) { VIEW_TYPE_CHAPTER -> { - view = parent.inflate(R.layout.item_recent_chapter) + view = parent.inflate(R.layout.item_recent_chapters) return RecentChaptersHolder(view, this, fragment) } VIEW_TYPE_SECTION -> { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/RecentChaptersFragment.kt similarity index 97% rename from app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersFragment.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/RecentChaptersFragment.kt index 2b114236cd..2d729911c9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/RecentChaptersFragment.kt @@ -1,4 +1,4 @@ -package eu.kanade.tachiyomi.ui.recent +package eu.kanade.tachiyomi.ui.recent.chapters import android.os.Bundle import android.support.v4.app.DialogFragment @@ -115,7 +115,7 @@ class RecentChaptersFragment : BaseRxFragment(), Flexib */ fun onNextMangaChapters(chapters: List) { (activity as MainActivity).updateEmptyView(chapters.isEmpty(), - R.string.information_no_recent, R.drawable.ic_history_black_128dp) + R.string.information_no_recent, R.drawable.ic_update_black_128dp) adapter.setItems(chapters) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/RecentChaptersHolder.kt similarity index 95% rename from app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersHolder.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/RecentChaptersHolder.kt index 13cb78fe07..2678687c4a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/RecentChaptersHolder.kt @@ -1,4 +1,4 @@ -package eu.kanade.tachiyomi.ui.recent +package eu.kanade.tachiyomi.ui.recent.chapters import android.view.View import android.widget.PopupMenu @@ -7,11 +7,11 @@ import eu.kanade.tachiyomi.data.database.models.MangaChapter import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder import eu.kanade.tachiyomi.util.getResourceColor -import kotlinx.android.synthetic.main.item_recent_chapter.view.* +import kotlinx.android.synthetic.main.item_recent_chapters.view.* /** * Holder that contains chapter item - * Uses R.layout.item_recent_chapter. + * Uses R.layout.item_recent_chapters. * UI related actions should be called from here. * * @param view the inflated view for this holder. @@ -19,7 +19,7 @@ import kotlinx.android.synthetic.main.item_recent_chapter.view.* * @param listener a listener to react to single tap and long tap events. * @constructor creates a new recent chapter holder. */ -class RecentChaptersHolder(view: View, private val adapter: RecentChaptersAdapter, listener: FlexibleViewHolder.OnListItemClickListener) : +class RecentChaptersHolder(view: View, private val adapter: RecentChaptersAdapter, listener: OnListItemClickListener) : FlexibleViewHolder(view, adapter, listener) { /** * Color of read chapter diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/RecentChaptersPresenter.kt similarity index 99% rename from app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersPresenter.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/RecentChaptersPresenter.kt index b482048e70..372cd12ff4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/RecentChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/RecentChaptersPresenter.kt @@ -1,4 +1,4 @@ -package eu.kanade.tachiyomi.ui.recent +package eu.kanade.tachiyomi.ui.recent.chapters import android.os.Bundle import eu.kanade.tachiyomi.data.database.DatabaseHelper diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/SectionViewHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/SectionViewHolder.kt similarity index 92% rename from app/src/main/java/eu/kanade/tachiyomi/ui/recent/SectionViewHolder.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/SectionViewHolder.kt index a629ce2074..d561cd71e7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/SectionViewHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/chapters/SectionViewHolder.kt @@ -1,4 +1,4 @@ -package eu.kanade.tachiyomi.ui.recent +package eu.kanade.tachiyomi.ui.recent.chapters import android.support.v7.widget.RecyclerView import android.text.format.DateUtils diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaAdapter.kt new file mode 100644 index 0000000000..343a1bd3bd --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaAdapter.kt @@ -0,0 +1,44 @@ +package eu.kanade.tachiyomi.ui.recent.manga + +import android.support.v7.widget.RecyclerView +import android.view.ViewGroup +import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.util.inflate + +class RecentMangaAdapter(val fragment: RecentMangaFragment) : FlexibleAdapter() { + /** + * Called when ViewHolder is created + * @param parent parent View + * @param viewType int containing viewType + */ + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder? { + val view = parent.inflate(R.layout.item_recent_manga) + return RecentMangaHolder(view, this) + } + + /** + * Called when ViewHolder is bind + * @param holder bind holder + * @param position position of holder + */ + override fun onBindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { + val item = getItem(position) as Manga + (holder as RecentMangaHolder).onSetValues(item) + } + + /** + * Update items + * @param items items + */ + fun setItems(items: List) { + mItems = items + notifyDataSetChanged() + } + + override fun updateDataSet(param: String?) { + // Empty function + } + +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaFragment.kt new file mode 100644 index 0000000000..8482cdfc35 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaFragment.kt @@ -0,0 +1,108 @@ +package eu.kanade.tachiyomi.ui.recent.manga + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +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.ui.base.fragment.BaseRxFragment +import eu.kanade.tachiyomi.ui.main.MainActivity +import eu.kanade.tachiyomi.ui.manga.MangaActivity +import eu.kanade.tachiyomi.ui.reader.ReaderActivity +import eu.kanade.tachiyomi.util.toast +import eu.kanade.tachiyomi.widget.NpaLinearLayoutManager +import kotlinx.android.synthetic.main.fragment_recent_manga.* +import nucleus.factory.RequiresPresenter + +/** + * TODO + */ +@RequiresPresenter(RecentMangaPresenter::class) +class RecentMangaFragment : BaseRxFragment() { + companion object { + /** + * Create new RecentChaptersFragment. + * + */ + @JvmStatic + fun newInstance(): RecentMangaFragment { + return RecentMangaFragment() + } + } + + /** + * Adapter containing the recent manga. + */ + lateinit var adapter: RecentMangaAdapter + private set + + /** + * Called when view gets created + * + * @param inflater layout inflater + * @param container view group + * @param savedState status of saved state + */ + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedState: Bundle?): View? { + return inflater.inflate(R.layout.fragment_recent_manga, container, false) + } + + /** + * Called when view is created + * + * @param view created view + * @param savedInstanceState status of saved sate + */ + override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { + recycler.layoutManager = NpaLinearLayoutManager(activity) + adapter = RecentMangaAdapter(this) + recycler.setHasFixedSize(true) + recycler.adapter = adapter + + // Update toolbar text + setToolbarTitle(R.string.label_recent_manga) + } + + /** + * Populate adapter with chapters + * + * @param chapters list of chapters + */ + fun onNextMangaChapters(chapters: List) { + (activity as MainActivity).updateEmptyView(chapters.isEmpty(), + R.string.information_no_recent_manga, R.drawable.ic_glasses_black_128dp) + + adapter.setItems(chapters) + } + + fun removeFromHistory(id: Long) { + presenter.removeFromHistory(id) + adapter.notifyDataSetChanged() + } + + fun getNextUnreadChapter(manga: Manga): Chapter? { + return presenter.getNextUnreadChapter(manga) + } + + + fun openChapter(chapter: Chapter?, manga: Manga) { + if (chapter != null) { + val intent = ReaderActivity.newIntent(activity, manga, chapter) + startActivity(intent) + } else { + adapter.fragment.context.toast(R.string.no_next_chapter) + } + } + + fun openMangaInfo(manga: Manga) { + val intent = MangaActivity.newIntent(activity, manga, true) + startActivity(intent) + } + + fun getLastRead(id: Long): String? { + return presenter.getLastRead(id) + } + +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaHolder.kt new file mode 100644 index 0000000000..f592a6213f --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaHolder.kt @@ -0,0 +1,43 @@ +package eu.kanade.tachiyomi.ui.recent.manga + +import android.support.v7.widget.RecyclerView +import android.view.View +import com.bumptech.glide.Glide +import com.bumptech.glide.load.engine.DiskCacheStrategy +import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.source.SourceManager +import kotlinx.android.synthetic.main.item_recent_manga.view.* + +class RecentMangaHolder(view: View, private val adapter: RecentMangaAdapter) : + RecyclerView.ViewHolder(view) { + + + fun onSetValues(manga: Manga) { + // Set manga title + itemView.manga_title.text = manga.title + itemView.manga_source.text = SourceManager(adapter.fragment.context).get(manga.source)?.visibleName + itemView.last_read.text = adapter.fragment.getLastRead(manga.id) + + itemView.remove.setOnClickListener { + adapter.fragment.removeFromHistory(manga.id) + } + + itemView.continue_reading.setOnClickListener { + val chapter = adapter.fragment.getNextUnreadChapter(manga) + adapter.fragment.openChapter(chapter, manga) + } + + itemView.cover.setOnClickListener { + adapter.fragment.openMangaInfo(manga) + } + + // Set cover + if (!manga.thumbnail_url.isNullOrEmpty()) { + Glide.with(itemView.context) + .load(manga) + .diskCacheStrategy(DiskCacheStrategy.RESULT) + .centerCrop() + .into(itemView.cover) + } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaPresenter.kt new file mode 100644 index 0000000000..823897423c --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/manga/RecentMangaPresenter.kt @@ -0,0 +1,73 @@ +package eu.kanade.tachiyomi.ui.recent.manga + +import android.os.Bundle +import eu.kanade.tachiyomi.data.database.DatabaseHelper +import eu.kanade.tachiyomi.data.database.models.Chapter +import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter +import rx.Observable +import rx.android.schedulers.AndroidSchedulers +import java.text.SimpleDateFormat +import java.util.* +import javax.inject.Inject + +/** + * The id of the restartable. + */ +const private val GET_RECENT_MANGA = 1 + +class RecentMangaPresenter : BasePresenter() { + /** + * Used to connect to database + */ + @Inject lateinit var db: DatabaseHelper + + + override fun onCreate(savedState: Bundle?) { + super.onCreate(savedState) + + // Used to get recent manga + restartableLatestCache(GET_RECENT_MANGA, + { getRecentMangaObservable() }, + { recentChaptersFragment, chapters -> + // Update adapter to show recent manga's + recentChaptersFragment.onNextMangaChapters(chapters) + } + ) + + if (savedState == null) { + // Start fetching recent chapters + start(GET_RECENT_MANGA) + } + } + + fun getRecentMangaObservable(): Observable>? { + // Set date for recent chapters + val cal = Calendar.getInstance() + cal.time = Date() + cal.add(Calendar.MONTH, -1) + + return db.getRecentManga(cal.time).asRxObservable() + .observeOn(AndroidSchedulers.mainThread()) + } + + fun removeFromHistory(id: Long) { + val history = db.getHistoryByMangaId(id).executeAsBlocking() + history?.let { + it.last_read = 0L + } + db.insertHistory(history!!).executeAsBlocking() + } + + fun getNextUnreadChapter(manga: Manga): Chapter? { + return db.getNextUnreadChapter(manga).executeAsBlocking() + } + + fun getLastRead(id: Long): String? { + val history = db.getHistoryByMangaId(id).executeAsBlocking() + return SimpleDateFormat("dd-MM-yyyy HH:mm", + java.util.Locale.getDefault()).format(Date(history?.last_read as Long)); + + } + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_glasses_black_128dp.xml b/app/src/main/res/drawable/ic_glasses_black_128dp.xml new file mode 100644 index 0000000000..fbf52def5a --- /dev/null +++ b/app/src/main/res/drawable/ic_glasses_black_128dp.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_glasses_black_24dp.xml b/app/src/main/res/drawable/ic_glasses_black_24dp.xml new file mode 100644 index 0000000000..d2977ea352 --- /dev/null +++ b/app/src/main/res/drawable/ic_glasses_black_24dp.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_history_black_128dp.xml b/app/src/main/res/drawable/ic_history_black_128dp.xml deleted file mode 100644 index fb950d63bf..0000000000 --- a/app/src/main/res/drawable/ic_history_black_128dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_history_black_24dp.xml b/app/src/main/res/drawable/ic_history_black_24dp.xml deleted file mode 100644 index a61de1bc9e..0000000000 --- a/app/src/main/res/drawable/ic_history_black_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_update_black_128dp.xml b/app/src/main/res/drawable/ic_update_black_128dp.xml new file mode 100644 index 0000000000..5b89fc3c3b --- /dev/null +++ b/app/src/main/res/drawable/ic_update_black_128dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_update_black_24dp.xml b/app/src/main/res/drawable/ic_update_black_24dp.xml new file mode 100644 index 0000000000..a1a7cbdfd3 --- /dev/null +++ b/app/src/main/res/drawable/ic_update_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/fragment_recent_chapters.xml b/app/src/main/res/layout/fragment_recent_chapters.xml index a0cef992e1..88737848a8 100644 --- a/app/src/main/res/layout/fragment_recent_chapters.xml +++ b/app/src/main/res/layout/fragment_recent_chapters.xml @@ -9,8 +9,7 @@ android:id="@+id/recycler" android:layout_width="match_parent" android:layout_height="match_parent" - android:descendantFocusability="blocksDescendants" - tools:listitem="@layout/item_recent_chapter"> + tools:listitem="@layout/item_recent_manga"> diff --git a/app/src/main/res/layout/fragment_recent_manga.xml b/app/src/main/res/layout/fragment_recent_manga.xml new file mode 100644 index 0000000000..88737848a8 --- /dev/null +++ b/app/src/main/res/layout/fragment_recent_manga.xml @@ -0,0 +1,16 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_recent_chapter.xml b/app/src/main/res/layout/item_recent_chapters.xml similarity index 100% rename from app/src/main/res/layout/item_recent_chapter.xml rename to app/src/main/res/layout/item_recent_chapters.xml diff --git a/app/src/main/res/layout/item_recent_manga.xml b/app/src/main/res/layout/item_recent_manga.xml new file mode 100644 index 0000000000..03a77c37d4 --- /dev/null +++ b/app/src/main/res/layout/item_recent_manga.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_navigation.xml b/app/src/main/res/menu/menu_navigation.xml index 279f437726..f236741f58 100644 --- a/app/src/main/res/menu/menu_navigation.xml +++ b/app/src/main/res/menu/menu_navigation.xml @@ -7,10 +7,15 @@ android:id="@+id/nav_drawer_library" android:icon="@drawable/ic_book_black_24dp" android:title="@string/label_library" /> + + #263238 + #F44336 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d33c420a48..25ffba1d8d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -7,6 +7,7 @@ Settings Download queue My library + Recently read Recent updates Catalogues Categories @@ -46,6 +47,8 @@ Previous chapter Next chapter Retry + Remove + Continue Reading Open in browser Change display mode Cancel @@ -308,6 +311,7 @@ No downloads No recent chapters + No recently read manga Empty library diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9a942d5962..3b2f876507 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -121,6 +121,10 @@ ?attr/colorAccent + + @@ -137,6 +141,12 @@ eu.kanade.tachiyomi.ui.base.fab.FABAnimationUpDown + +