DI refactoring
parent
fb60b26f08
commit
56e145420c
@ -0,0 +1,25 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db
|
||||||
|
|
||||||
|
import androidx.room.Room
|
||||||
|
import org.koin.android.ext.koin.androidContext
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import org.koitharu.kotatsu.core.db.migrations.*
|
||||||
|
|
||||||
|
val databaseModule
|
||||||
|
get() = module {
|
||||||
|
single {
|
||||||
|
Room.databaseBuilder(
|
||||||
|
androidContext(),
|
||||||
|
MangaDatabase::class.java,
|
||||||
|
"kotatsu-db"
|
||||||
|
).addMigrations(
|
||||||
|
Migration1To2(),
|
||||||
|
Migration2To3(),
|
||||||
|
Migration3To4(),
|
||||||
|
Migration4To5(),
|
||||||
|
Migration5To6()
|
||||||
|
).addCallback(
|
||||||
|
DatabasePrePopulateCallback(androidContext().resources)
|
||||||
|
).build()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,47 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.db
|
|
||||||
|
|
||||||
import androidx.room.*
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.HistoryEntity
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.HistoryWithManga
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
|
||||||
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
abstract class HistoryDao {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
@Transaction
|
|
||||||
@Query("SELECT * FROM history ORDER BY updated_at DESC LIMIT :limit OFFSET :offset")
|
|
||||||
abstract suspend fun findAll(offset: Int, limit: Int): List<HistoryWithManga>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM manga WHERE manga_id IN (SELECT manga_id FROM history)")
|
|
||||||
abstract suspend fun findAllManga(): List<MangaEntity>
|
|
||||||
|
|
||||||
@Query("SELECT * FROM history WHERE manga_id = :id")
|
|
||||||
abstract suspend fun find(id: Long): HistoryEntity?
|
|
||||||
|
|
||||||
@Query("DELETE FROM history")
|
|
||||||
abstract suspend fun clear()
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
|
||||||
abstract suspend fun insert(entity: HistoryEntity): Long
|
|
||||||
|
|
||||||
@Query("UPDATE history SET page = :page, chapter_id = :chapterId, scroll = :scroll, updated_at = :updatedAt WHERE manga_id = :mangaId")
|
|
||||||
abstract suspend fun update(mangaId: Long, page: Int, chapterId: Long, scroll: Float, updatedAt: Long): Int
|
|
||||||
|
|
||||||
@Query("DELETE FROM history WHERE manga_id = :mangaId")
|
|
||||||
abstract suspend fun delete(mangaId: Long)
|
|
||||||
|
|
||||||
suspend fun update(entity: HistoryEntity) = update(entity.mangaId, entity.page, entity.chapterId, entity.scroll, entity.updatedAt)
|
|
||||||
|
|
||||||
@Transaction
|
|
||||||
open suspend fun upsert(entity: HistoryEntity): Boolean {
|
|
||||||
return if (update(entity) == 0) {
|
|
||||||
insert(entity)
|
|
||||||
true
|
|
||||||
} else false
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.db
|
package org.koitharu.kotatsu.core.db.dao
|
||||||
|
|
||||||
import androidx.room.Dao
|
import androidx.room.Dao
|
||||||
import androidx.room.Insert
|
import androidx.room.Insert
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.db
|
package org.koitharu.kotatsu.core.db.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import org.koitharu.kotatsu.core.db.entity.FavouriteEntity
|
import org.koitharu.kotatsu.core.db.entity.FavouriteEntity
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
package org.koitharu.kotatsu.core.db.dao
|
||||||
|
|
||||||
|
import androidx.room.*
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.HistoryEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.HistoryWithManga
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||||
|
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
abstract class HistoryDao {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@Transaction
|
||||||
|
@Query("SELECT * FROM history ORDER BY updated_at DESC LIMIT :limit OFFSET :offset")
|
||||||
|
abstract suspend fun findAll(offset: Int, limit: Int): List<HistoryWithManga>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM manga WHERE manga_id IN (SELECT manga_id FROM history)")
|
||||||
|
abstract suspend fun findAllManga(): List<MangaEntity>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM history WHERE manga_id = :id")
|
||||||
|
abstract suspend fun find(id: Long): HistoryEntity?
|
||||||
|
|
||||||
|
@Query("DELETE FROM history")
|
||||||
|
abstract suspend fun clear()
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
abstract suspend fun insert(entity: HistoryEntity): Long
|
||||||
|
|
||||||
|
@Query("UPDATE history SET page = :page, chapter_id = :chapterId, scroll = :scroll, updated_at = :updatedAt WHERE manga_id = :mangaId")
|
||||||
|
abstract suspend fun update(
|
||||||
|
mangaId: Long,
|
||||||
|
page: Int,
|
||||||
|
chapterId: Long,
|
||||||
|
scroll: Float,
|
||||||
|
updatedAt: Long
|
||||||
|
): Int
|
||||||
|
|
||||||
|
@Query("DELETE FROM history WHERE manga_id = :mangaId")
|
||||||
|
abstract suspend fun delete(mangaId: Long)
|
||||||
|
|
||||||
|
suspend fun update(entity: HistoryEntity) =
|
||||||
|
update(entity.mangaId, entity.page, entity.chapterId, entity.scroll, entity.updatedAt)
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
open suspend fun upsert(entity: HistoryEntity): Boolean {
|
||||||
|
return if (update(entity) == 0) {
|
||||||
|
insert(entity)
|
||||||
|
true
|
||||||
|
} else false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.db
|
package org.koitharu.kotatsu.core.db.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.db
|
package org.koitharu.kotatsu.core.db.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaPrefsEntity
|
import org.koitharu.kotatsu.core.db.entity.MangaPrefsEntity
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.db
|
package org.koitharu.kotatsu.core.db.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.db
|
package org.koitharu.kotatsu.core.db.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import org.koitharu.kotatsu.core.db.entity.TrackLogEntity
|
import org.koitharu.kotatsu.core.db.entity.TrackLogEntity
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.db
|
package org.koitharu.kotatsu.core.db.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import org.koitharu.kotatsu.core.db.entity.TrackEntity
|
import org.koitharu.kotatsu.core.db.entity.TrackEntity
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package org.koitharu.kotatsu.core.github
|
||||||
|
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val githubModule
|
||||||
|
get() = module {
|
||||||
|
single {
|
||||||
|
GithubRepository(get())
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package org.koitharu.kotatsu.core.network
|
||||||
|
|
||||||
|
import okhttp3.CookieJar
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import org.koin.android.ext.koin.androidContext
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import org.koitharu.kotatsu.core.network.cookies.PersistentCookieJar
|
||||||
|
import org.koitharu.kotatsu.core.network.cookies.cache.SetCookieCache
|
||||||
|
import org.koitharu.kotatsu.core.network.cookies.persistence.SharedPrefsCookiePersistor
|
||||||
|
import org.koitharu.kotatsu.core.parser.UserAgentInterceptor
|
||||||
|
import org.koitharu.kotatsu.utils.CacheUtils
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
val networkModule
|
||||||
|
get() = module {
|
||||||
|
single<CookieJar> {
|
||||||
|
PersistentCookieJar(
|
||||||
|
SetCookieCache(),
|
||||||
|
SharedPrefsCookiePersistor(androidContext())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
single {
|
||||||
|
OkHttpClient.Builder().apply {
|
||||||
|
connectTimeout(20, TimeUnit.SECONDS)
|
||||||
|
readTimeout(60, TimeUnit.SECONDS)
|
||||||
|
writeTimeout(20, TimeUnit.SECONDS)
|
||||||
|
cookieJar(get())
|
||||||
|
cache(CacheUtils.createHttpCache(androidContext()))
|
||||||
|
addInterceptor(UserAgentInterceptor())
|
||||||
|
}.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
|
import org.koin.dsl.bind
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val parserModule
|
||||||
|
get() = module {
|
||||||
|
single { LocalMangaRepository() } bind MangaRepository::class
|
||||||
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package org.koitharu.kotatsu.domain.favourites
|
package org.koitharu.kotatsu.domain.favourites
|
||||||
|
|
||||||
interface OnFavouritesChangeListener {
|
fun interface OnFavouritesChangeListener {
|
||||||
|
|
||||||
fun onFavouritesChanged(mangaId: Long)
|
fun onFavouritesChanged(mangaId: Long)
|
||||||
|
|
||||||
fun onCategoriesChanged()
|
fun onCategoriesChanged() = Unit
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common
|
package org.koitharu.kotatsu.ui.base
|
||||||
|
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -1,14 +1,19 @@
|
|||||||
package org.koitharu.kotatsu.ui.common
|
package org.koitharu.kotatsu.ui.base
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import androidx.annotation.LayoutRes
|
import androidx.annotation.LayoutRes
|
||||||
|
import coil.ImageLoader
|
||||||
import moxy.MvpAppCompatFragment
|
import moxy.MvpAppCompatFragment
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
import org.koitharu.kotatsu.utils.delegates.ParcelableArgumentDelegate
|
import org.koitharu.kotatsu.utils.delegates.ParcelableArgumentDelegate
|
||||||
import org.koitharu.kotatsu.utils.delegates.StringArgumentDelegate
|
import org.koitharu.kotatsu.utils.delegates.StringArgumentDelegate
|
||||||
|
|
||||||
abstract class BaseFragment(@LayoutRes contentLayoutId: Int) :
|
abstract class BaseFragment(
|
||||||
MvpAppCompatFragment(contentLayoutId) {
|
@LayoutRes contentLayoutId: Int
|
||||||
|
) : MvpAppCompatFragment(contentLayoutId) {
|
||||||
|
|
||||||
|
protected val coil by inject<ImageLoader>()
|
||||||
|
|
||||||
fun stringArg(name: String) = StringArgumentDelegate(name)
|
fun stringArg(name: String) = StringArgumentDelegate(name)
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common
|
package org.koitharu.kotatsu.ui.base
|
||||||
|
|
||||||
import moxy.MvpView
|
import moxy.MvpView
|
||||||
import moxy.viewstate.strategy.alias.AddToEndSingle
|
import moxy.viewstate.strategy.alias.AddToEndSingle
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common
|
package org.koitharu.kotatsu.ui.base
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common
|
package org.koitharu.kotatsu.ui.base
|
||||||
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import moxy.MvpPresenter
|
import moxy.MvpPresenter
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common
|
package org.koitharu.kotatsu.ui.base
|
||||||
|
|
||||||
import android.util.ArrayMap
|
import android.util.ArrayMap
|
||||||
import moxy.MvpPresenter
|
import moxy.MvpPresenter
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.dialog
|
package org.koitharu.kotatsu.ui.base.dialog
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.dialog
|
package org.koitharu.kotatsu.ui.base.dialog
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.list
|
package org.koitharu.kotatsu.ui.base.list
|
||||||
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.list
|
package org.koitharu.kotatsu.ui.base.list
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.list
|
package org.koitharu.kotatsu.ui.base.list
|
||||||
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.list
|
package org.koitharu.kotatsu.ui.base.list
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.list
|
package org.koitharu.kotatsu.ui.base.list
|
||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.list
|
package org.koitharu.kotatsu.ui.base.list
|
||||||
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.list
|
package org.koitharu.kotatsu.ui.base.list
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.list.decor
|
package org.koitharu.kotatsu.ui.base.list.decor
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.list.decor
|
package org.koitharu.kotatsu.ui.base.list.decor
|
||||||
|
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.list.decor
|
package org.koitharu.kotatsu.ui.base.list.decor
|
||||||
|
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package org.koitharu.kotatsu.ui.base
|
||||||
|
|
||||||
|
import coil.ComponentRegistry
|
||||||
|
import coil.ImageLoader
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import org.koin.android.ext.koin.androidContext
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import org.koitharu.kotatsu.core.local.CbzFetcher
|
||||||
|
|
||||||
|
val uiModule
|
||||||
|
get() = module {
|
||||||
|
single {
|
||||||
|
ImageLoader.Builder(androidContext())
|
||||||
|
.okHttpClient(get<OkHttpClient>())
|
||||||
|
.componentRegistry(
|
||||||
|
ComponentRegistry.Builder()
|
||||||
|
.add(CbzFetcher())
|
||||||
|
.build()
|
||||||
|
).build()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.common.widgets
|
package org.koitharu.kotatsu.ui.base.widgets
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
@ -1,27 +1,35 @@
|
|||||||
package org.koitharu.kotatsu.ui.list
|
package org.koitharu.kotatsu.ui.list
|
||||||
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import coil.clear
|
import coil.ImageLoader
|
||||||
import coil.load
|
import coil.request.Disposable
|
||||||
import kotlinx.android.synthetic.main.item_manga_grid.*
|
import kotlinx.android.synthetic.main.item_manga_grid.*
|
||||||
|
import org.koin.core.component.inject
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.model.Manga
|
import org.koitharu.kotatsu.core.model.Manga
|
||||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||||
import org.koitharu.kotatsu.ui.common.list.BaseViewHolder
|
import org.koitharu.kotatsu.ui.base.list.BaseViewHolder
|
||||||
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
|
|
||||||
class MangaGridHolder(parent: ViewGroup) : BaseViewHolder<Manga, MangaHistory?>(parent, R.layout.item_manga_grid) {
|
class MangaGridHolder(parent: ViewGroup) :
|
||||||
|
BaseViewHolder<Manga, MangaHistory?>(parent, R.layout.item_manga_grid) {
|
||||||
|
|
||||||
|
private val coil by inject<ImageLoader>()
|
||||||
|
private var imageRequest: Disposable? = null
|
||||||
|
|
||||||
override fun onBind(data: Manga, extra: MangaHistory?) {
|
override fun onBind(data: Manga, extra: MangaHistory?) {
|
||||||
imageView_cover.clear()
|
|
||||||
textView_title.text = data.title
|
textView_title.text = data.title
|
||||||
imageView_cover.load(data.coverUrl) {
|
imageRequest?.dispose()
|
||||||
placeholder(R.drawable.ic_placeholder)
|
imageRequest = imageView_cover.newImageRequest(data.coverUrl)
|
||||||
fallback(R.drawable.ic_placeholder)
|
.placeholder(R.drawable.ic_placeholder)
|
||||||
error(R.drawable.ic_placeholder)
|
.fallback(R.drawable.ic_placeholder)
|
||||||
}
|
.error(R.drawable.ic_placeholder)
|
||||||
|
.enqueueWith(coil)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRecycled() {
|
override fun onRecycled() {
|
||||||
imageView_cover.clear()
|
imageRequest?.dispose()
|
||||||
|
imageView_cover.setImageDrawable(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,30 +1,38 @@
|
|||||||
package org.koitharu.kotatsu.ui.list
|
package org.koitharu.kotatsu.ui.list
|
||||||
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import coil.clear
|
import coil.ImageLoader
|
||||||
import coil.load
|
import coil.request.Disposable
|
||||||
import kotlinx.android.synthetic.main.item_manga_list.*
|
import kotlinx.android.synthetic.main.item_manga_list.*
|
||||||
|
import org.koin.core.component.inject
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.model.Manga
|
import org.koitharu.kotatsu.core.model.Manga
|
||||||
import org.koitharu.kotatsu.core.model.MangaHistory
|
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||||
import org.koitharu.kotatsu.ui.common.list.BaseViewHolder
|
import org.koitharu.kotatsu.ui.base.list.BaseViewHolder
|
||||||
|
import org.koitharu.kotatsu.utils.ext.enqueueWith
|
||||||
|
import org.koitharu.kotatsu.utils.ext.newImageRequest
|
||||||
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
||||||
|
|
||||||
class MangaListHolder(parent: ViewGroup) :
|
class MangaListHolder(
|
||||||
BaseViewHolder<Manga, MangaHistory?>(parent, R.layout.item_manga_list) {
|
parent: ViewGroup
|
||||||
|
) : BaseViewHolder<Manga, MangaHistory?>(parent, R.layout.item_manga_list) {
|
||||||
|
|
||||||
|
private val coil by inject<ImageLoader>()
|
||||||
|
private var imageRequest: Disposable? = null
|
||||||
|
|
||||||
override fun onBind(data: Manga, extra: MangaHistory?) {
|
override fun onBind(data: Manga, extra: MangaHistory?) {
|
||||||
imageView_cover.clear()
|
imageRequest?.dispose()
|
||||||
textView_title.text = data.title
|
textView_title.text = data.title
|
||||||
textView_subtitle.textAndVisible = data.tags.joinToString(", ") { it.title }
|
textView_subtitle.textAndVisible = data.tags.joinToString(", ") { it.title }
|
||||||
imageView_cover.load(data.coverUrl) {
|
imageRequest = imageView_cover.newImageRequest(data.coverUrl)
|
||||||
placeholder(R.drawable.ic_placeholder)
|
.placeholder(R.drawable.ic_placeholder)
|
||||||
fallback(R.drawable.ic_placeholder)
|
.fallback(R.drawable.ic_placeholder)
|
||||||
error(R.drawable.ic_placeholder)
|
.error(R.drawable.ic_placeholder)
|
||||||
}
|
.enqueueWith(coil)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRecycled() {
|
override fun onRecycled() {
|
||||||
imageView_cover.clear()
|
imageRequest?.dispose()
|
||||||
|
imageView_cover.setImageDrawable(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue