From a12a34e3bb8e1868c6451607bf9dbbd89bdaad6a Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 15 Aug 2017 09:05:41 -0400 Subject: [PATCH] Add Batoto Scanlator to Chapter view (#789) * Added scanlator for Batoto on chapter list * adjusted item_chapter layout for scanlator adjusted so db chapters get updated if scanlator does not match source scanlator * adjusted item_chapter layout for scanlator adjusted chapter holder to dynamically set title max lines depending on if scanlator exists * fixed excess blank line * changed scanlator to be instantiated instead lateint to prevent toast message erro when viewing chapters by catalog * changed item_chapter.xml to constraint layout * removed accidental changes to catalog * cleaned up code. * fixed issue where long title was running into 3 dot menu fixed issue where no scanlator for manga was causing date to not be bottom lined fixed general chapter layout to be more similar to existing * allow scanlator to be null * fixed merge issue * fixed merge issue * attempt to fix whitespace carriage return issue * attempt to fix whitespace carriage return issue * attempt to fix whitespace carriage return issue --- .../tachiyomi/data/database/DbOpenHelper.kt | 5 +- .../database/mappers/ChapterTypeMapping.kt | 3 + .../data/database/models/ChapterImpl.kt | 6 +- .../data/database/tables/ChapterTable.kt | 6 + .../kanade/tachiyomi/source/model/SChapter.kt | 3 + .../tachiyomi/source/model/SChapterImpl.kt | 2 + .../tachiyomi/source/online/english/Batoto.kt | 1 + .../ui/manga/chapter/ChapterHolder.kt | 11 ++ app/src/main/res/layout/chapters_item.xml | 179 +++++++++--------- 9 files changed, 124 insertions(+), 92 deletions(-) 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 40e5d129aa..a1b902a6ec 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 = 4 + const val DATABASE_VERSION = 5 } override fun onCreate(db: SQLiteDatabase) = with(db) { @@ -51,6 +51,9 @@ class DbOpenHelper(context: Context) if (oldVersion < 4) { db.execSQL(ChapterTable.bookmarkUpdateQuery) } + if (oldVersion < 5){ + db.execSQL(ChapterTable.addScanlator) + } } override fun onConfigure(db: SQLiteDatabase) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/ChapterTypeMapping.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/ChapterTypeMapping.kt index 0065f5f447..2e903a64ba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/ChapterTypeMapping.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/ChapterTypeMapping.kt @@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_LAST_PAGE_READ import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_MANGA_ID import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_NAME import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_READ +import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_SCANLATOR import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_SOURCE_ORDER import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_URL import eu.kanade.tachiyomi.data.database.tables.ChapterTable.TABLE @@ -48,6 +49,7 @@ class ChapterPutResolver : DefaultPutResolver() { put(COL_URL, obj.url) put(COL_NAME, obj.name) put(COL_READ, obj.read) + put(COL_SCANLATOR, obj.scanlator) put(COL_BOOKMARK, obj.bookmark) put(COL_DATE_FETCH, obj.date_fetch) put(COL_DATE_UPLOAD, obj.date_upload) @@ -64,6 +66,7 @@ class ChapterGetResolver : DefaultGetResolver() { manga_id = cursor.getLong(cursor.getColumnIndex(COL_MANGA_ID)) url = cursor.getString(cursor.getColumnIndex(COL_URL)) name = cursor.getString(cursor.getColumnIndex(COL_NAME)) + scanlator = cursor.getString(cursor.getColumnIndex(COL_SCANLATOR)) read = cursor.getInt(cursor.getColumnIndex(COL_READ)) == 1 bookmark = cursor.getInt(cursor.getColumnIndex(COL_BOOKMARK)) == 1 date_fetch = cursor.getLong(cursor.getColumnIndex(COL_DATE_FETCH)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/ChapterImpl.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/ChapterImpl.kt index f7f1d06628..461c943a2c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/ChapterImpl.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/ChapterImpl.kt @@ -10,6 +10,8 @@ class ChapterImpl : Chapter { override lateinit var name: String + override var scanlator: String? = null + override var read: Boolean = false override var bookmark: Boolean = false @@ -29,8 +31,8 @@ class ChapterImpl : Chapter { if (other == null || javaClass != other.javaClass) return false val chapter = other as Chapter - - return url == chapter.url + //forces updates on manga if scanlator changes. This will allow existing manga in library with scanlator to update + return url == chapter.url && scanlator == chapter.scanlator } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.kt index e28f848cc6..7dc99f6fa3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.kt @@ -14,6 +14,8 @@ object ChapterTable { const val COL_READ = "read" + const val COL_SCANLATOR ="scanlator" + const val COL_BOOKMARK = "bookmark" const val COL_DATE_FETCH = "date_fetch" @@ -32,6 +34,7 @@ object ChapterTable { $COL_MANGA_ID INTEGER NOT NULL, $COL_URL TEXT NOT NULL, $COL_NAME TEXT NOT NULL, + $COL_SCANLATOR TEXT, $COL_READ BOOLEAN NOT NULL, $COL_BOOKMARK BOOLEAN NOT NULL, $COL_LAST_PAGE_READ INT NOT NULL, @@ -52,4 +55,7 @@ object ChapterTable { val bookmarkUpdateQuery: String get() = "ALTER TABLE $TABLE ADD COLUMN $COL_BOOKMARK BOOLEAN DEFAULT FALSE" + val addScanlator:String + get ()= "ALTER TABLE $TABLE ADD COLUMN $COL_SCANLATOR TEXT DEFAULT" + } diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapter.kt b/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapter.kt index a54a36b40d..991d24d413 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapter.kt @@ -12,11 +12,14 @@ interface SChapter : Serializable { var chapter_number: Float + var scanlator: String? + fun copyFrom(other: SChapter) { name = other.name url = other.url date_upload = other.date_upload chapter_number = other.chapter_number + scanlator = other.scanlator } companion object { diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapterImpl.kt b/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapterImpl.kt index 026d437e03..cfc4c39999 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapterImpl.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/model/SChapterImpl.kt @@ -10,4 +10,6 @@ class SChapterImpl : SChapter { override var chapter_number: Float = -1f + override var scanlator: String? = null + } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/english/Batoto.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/english/Batoto.kt index 08cdc3bd75..ef7cd2f4c4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/english/Batoto.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/english/Batoto.kt @@ -197,6 +197,7 @@ class Batoto : ParsedHttpSource(), LoginSource { chapter.date_upload = element.select("td").getOrNull(4)?.let { parseDateFromElement(it) } ?: 0 + chapter.scanlator = element.select("td").getOrNull(2)?.text() return chapter } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt index aa9ef4179e..b5ef25f1ae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt @@ -6,6 +6,7 @@ import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.model.Download +import eu.kanade.tachiyomi.util.gone import kotlinx.android.synthetic.main.chapters_item.view.* import java.util.* @@ -43,6 +44,16 @@ class ChapterHolder( chapter_date.text = "" } + //add scanlator if exists + chapter_scanlator.text = chapter.scanlator + //allow longer titles if there is no scanlator (most sources) + if (chapter_scanlator.text.isNullOrBlank()) { + chapter_title.setMaxLines(2) + chapter_scanlator.gone() + } else { + chapter_title.setMaxLines(1) + } + chapter_pages.text = if (!chapter.read && chapter.last_page_read > 0) { context.getString(R.string.chapter_progress, chapter.last_page_read + 1) } else { diff --git a/app/src/main/res/layout/chapters_item.xml b/app/src/main/res/layout/chapters_item.xml index 3aab2d412e..e823535641 100644 --- a/app/src/main/res/layout/chapters_item.xml +++ b/app/src/main/res/layout/chapters_item.xml @@ -1,100 +1,101 @@ - - + - + - + - + - - + - - - - - - + android:layout_width="wrap_content" + android:layout_height="wrap_content" + app:srcCompat="@drawable/ic_more_horiz_black_24dp" + app:layout_constraintRight_toLeftOf="@+id/guideline4" + app:layout_constraintTop_toTopOf="parent" + android:paddingStart="12dp" + android:paddingEnd="0dp" + android:paddingBottom="12dp" + android:paddingTop="12dp" + android:contentDescription="@string/description_cover" + /> - + - + + - \ No newline at end of file +