Migrate to MVVM
parent
eaac271143
commit
7d24286c55
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.domain
|
package org.koitharu.kotatsu.base.domain
|
||||||
|
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.domain
|
package org.koitharu.kotatsu.base.domain
|
||||||
|
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.domain
|
package org.koitharu.kotatsu.base.domain
|
||||||
|
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.get
|
import org.koin.core.component.get
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.domain
|
package org.koitharu.kotatsu.base.domain
|
||||||
|
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@ -1,15 +1,15 @@
|
|||||||
package org.koitharu.kotatsu.ui.base
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import moxy.MvpAppCompatActivity
|
|
||||||
import org.koin.android.ext.android.get
|
import org.koin.android.ext.android.get
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
|
||||||
abstract class BaseActivity : MvpAppCompatActivity() {
|
abstract class BaseActivity : AppCompatActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
if (get<AppSettings>().isAmoledTheme) {
|
if (get<AppSettings>().isAmoledTheme) {
|
||||||
@ -1,14 +1,14 @@
|
|||||||
package org.koitharu.kotatsu.ui.base
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.annotation.LayoutRes
|
import androidx.annotation.LayoutRes
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import moxy.MvpAppCompatFragment
|
|
||||||
import org.koin.android.ext.android.inject
|
import org.koin.android.ext.android.inject
|
||||||
|
|
||||||
abstract class BaseFragment(
|
abstract class BaseFragment(
|
||||||
@LayoutRes contentLayoutId: Int
|
@LayoutRes contentLayoutId: Int
|
||||||
) : MvpAppCompatFragment(contentLayoutId) {
|
) : Fragment(contentLayoutId) {
|
||||||
|
|
||||||
protected val coil by inject<ImageLoader>()
|
protected val coil by inject<ImageLoader>()
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.base
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.base
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
|
import androidx.lifecycle.LifecycleService
|
||||||
|
|
||||||
|
abstract class BaseService : LifecycleService()
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
|
|
||||||
|
abstract class BaseViewModel : ViewModel() {
|
||||||
|
|
||||||
|
val onError = SingleLiveEvent<Throwable>()
|
||||||
|
val isLoading = MutableLiveData(false)
|
||||||
|
|
||||||
|
protected fun launchJob(
|
||||||
|
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||||
|
block: suspend CoroutineScope.() -> Unit
|
||||||
|
): Job = viewModelScope.launch(createErrorHandler(), start, block)
|
||||||
|
|
||||||
|
protected fun launchLoadingJob(
|
||||||
|
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||||
|
block: suspend CoroutineScope.() -> Unit
|
||||||
|
): Job = viewModelScope.launch(createErrorHandler(), start) {
|
||||||
|
isLoading.value = true
|
||||||
|
try {
|
||||||
|
block()
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createErrorHandler() = CoroutineExceptionHandler { _, throwable ->
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
throwable.printStackTrace()
|
||||||
|
}
|
||||||
|
if (throwable !is CancellationException) {
|
||||||
|
onError.call(throwable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.base.dialog
|
package org.koitharu.kotatsu.base.ui.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.base.dialog
|
package org.koitharu.kotatsu.base.ui.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.base.list
|
package org.koitharu.kotatsu.base.ui.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.base.list
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.base.list
|
package org.koitharu.kotatsu.base.ui.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.base.list
|
package org.koitharu.kotatsu.base.ui.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.base.list
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.base.list
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.base.list
|
package org.koitharu.kotatsu.base.ui.list
|
||||||
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.base.list
|
package org.koitharu.kotatsu.base.ui.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.base.list.decor
|
package org.koitharu.kotatsu.base.ui.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.base.list.decor
|
package org.koitharu.kotatsu.base.ui.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.base.list.decor
|
package org.koitharu.kotatsu.base.ui.list.decor
|
||||||
|
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.base.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.base.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.base.widgets
|
package org.koitharu.kotatsu.base.ui.widgets
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.browser
|
package org.koitharu.kotatsu.browser
|
||||||
|
|
||||||
interface BrowserCallback {
|
interface BrowserCallback {
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.browser
|
package org.koitharu.kotatsu.browser
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.webkit.WebResourceRequest
|
import android.webkit.WebResourceRequest
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.utils.cloudflare
|
package org.koitharu.kotatsu.browser.cloudflare
|
||||||
|
|
||||||
interface CloudFlareCallback {
|
interface CloudFlareCallback {
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.utils.cloudflare
|
package org.koitharu.kotatsu.browser.cloudflare
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
@ -1,3 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.exceptions
|
package org.koitharu.kotatsu.core.exceptions
|
||||||
|
|
||||||
class ParseException(message: String? = null, cause: Throwable? = null) : RuntimeException(message, cause)
|
class ParseException(message: String? = null, cause: Throwable? = null) :
|
||||||
|
RuntimeException(message, cause)
|
||||||
@ -1,22 +1,25 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
import org.koin.dsl.bind
|
import org.koin.core.qualifier.named
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
import org.koitharu.kotatsu.base.domain.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.core.model.MangaSource
|
||||||
import org.koitharu.kotatsu.core.parser.site.*
|
import org.koitharu.kotatsu.core.parser.site.*
|
||||||
|
|
||||||
val parserModule
|
val parserModule
|
||||||
get() = module {
|
get() = module {
|
||||||
single { LocalMangaRepository(get()) } bind MangaRepository::class
|
|
||||||
|
|
||||||
factory { ReadmangaRepository(get()) } bind MangaRepository::class
|
single { MangaLoaderContext() }
|
||||||
factory { MintMangaRepository(get()) } bind MangaRepository::class
|
|
||||||
factory { SelfMangaRepository(get()) } bind MangaRepository::class
|
factory<MangaRepository>(named(MangaSource.READMANGA_RU)) { ReadmangaRepository(get()) }
|
||||||
factory { MangaChanRepository(get()) } bind MangaRepository::class
|
factory<MangaRepository>(named(MangaSource.MINTMANGA)) { MintMangaRepository(get()) }
|
||||||
factory { DesuMeRepository(get()) } bind MangaRepository::class
|
factory<MangaRepository>(named(MangaSource.SELFMANGA)) { SelfMangaRepository(get()) }
|
||||||
factory { HenChanRepository(get()) } bind MangaRepository::class
|
factory<MangaRepository>(named(MangaSource.MANGACHAN)) { MangaChanRepository(get()) }
|
||||||
factory { YaoiChanRepository(get()) } bind MangaRepository::class
|
factory<MangaRepository>(named(MangaSource.DESUME)) { DesuMeRepository(get()) }
|
||||||
factory { MangaTownRepository(get()) } bind MangaRepository::class
|
factory<MangaRepository>(named(MangaSource.HENCHAN)) { HenChanRepository(get()) }
|
||||||
factory { MangaLibRepository(get()) } bind MangaRepository::class
|
factory<MangaRepository>(named(MangaSource.YAOICHAN)) { YaoiChanRepository(get()) }
|
||||||
factory { NudeMoonRepository(get()) } bind MangaRepository::class
|
factory<MangaRepository>(named(MangaSource.MANGATOWN)) { MangaTownRepository(get()) }
|
||||||
factory { MangareadRepository(get()) } bind MangaRepository::class
|
factory<MangaRepository>(named(MangaSource.MANGALIB)) { MangaLibRepository(get()) }
|
||||||
|
factory<MangaRepository>(named(MangaSource.NUDEMOON)) { NudeMoonRepository(get()) }
|
||||||
|
factory<MangaRepository>(named(MangaSource.MANGAREAD)) { MangareadRepository(get()) }
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.utils
|
package org.koitharu.kotatsu.core.ui
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.base
|
package org.koitharu.kotatsu.core.ui
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -1,11 +1,11 @@
|
|||||||
package org.koitharu.kotatsu.ui.base
|
package org.koitharu.kotatsu.core.ui
|
||||||
|
|
||||||
import coil.ComponentRegistry
|
import coil.ComponentRegistry
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import org.koin.android.ext.koin.androidContext
|
import org.koin.android.ext.koin.androidContext
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.koitharu.kotatsu.core.local.CbzFetcher
|
import org.koitharu.kotatsu.local.data.CbzFetcher
|
||||||
|
|
||||||
val uiModule
|
val uiModule
|
||||||
get() = module {
|
get() = module {
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
package org.koitharu.kotatsu.details
|
||||||
|
|
||||||
|
import org.koin.android.viewmodel.dsl.viewModel
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import org.koitharu.kotatsu.details.ui.DetailsViewModel
|
||||||
|
|
||||||
|
val detailsModule
|
||||||
|
get() = module {
|
||||||
|
|
||||||
|
viewModel { DetailsViewModel(get(), get(), get(), get(), get(), get()) }
|
||||||
|
}
|
||||||
@ -1,13 +1,13 @@
|
|||||||
package org.koitharu.kotatsu.ui.details
|
package org.koitharu.kotatsu.details.ui
|
||||||
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import kotlinx.android.synthetic.main.item_chapter.*
|
import kotlinx.android.synthetic.main.item_chapter.*
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.BaseViewHolder
|
||||||
import org.koitharu.kotatsu.core.model.MangaChapter
|
import org.koitharu.kotatsu.core.model.MangaChapter
|
||||||
import org.koitharu.kotatsu.domain.history.ChapterExtra
|
import org.koitharu.kotatsu.history.domain.ChapterExtra
|
||||||
import org.koitharu.kotatsu.ui.base.list.BaseViewHolder
|
|
||||||
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
|
||||||
class ChapterHolder(parent: ViewGroup) :
|
class ChapterHolder(parent: ViewGroup) :
|
||||||
@ -1,11 +1,11 @@
|
|||||||
package org.koitharu.kotatsu.ui.details
|
package org.koitharu.kotatsu.details.ui
|
||||||
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.BaseRecyclerAdapter
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.OnRecyclerItemClickListener
|
||||||
import org.koitharu.kotatsu.core.model.MangaChapter
|
import org.koitharu.kotatsu.core.model.MangaChapter
|
||||||
import org.koitharu.kotatsu.domain.history.ChapterExtra
|
import org.koitharu.kotatsu.history.domain.ChapterExtra
|
||||||
import org.koitharu.kotatsu.ui.base.list.BaseRecyclerAdapter
|
|
||||||
import org.koitharu.kotatsu.ui.base.list.OnRecyclerItemClickListener
|
|
||||||
|
|
||||||
class ChaptersAdapter(onItemClickListener: OnRecyclerItemClickListener<MangaChapter>) :
|
class ChaptersAdapter(onItemClickListener: OnRecyclerItemClickListener<MangaChapter>) :
|
||||||
BaseRecyclerAdapter<MangaChapter, ChapterExtra>(onItemClickListener) {
|
BaseRecyclerAdapter<MangaChapter, ChapterExtra>(onItemClickListener) {
|
||||||
@ -0,0 +1,135 @@
|
|||||||
|
package org.koitharu.kotatsu.details.ui
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.*
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.koitharu.kotatsu.base.domain.MangaDataRepository
|
||||||
|
import org.koitharu.kotatsu.core.exceptions.MangaNotFoundException
|
||||||
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
|
import org.koitharu.kotatsu.core.model.Manga
|
||||||
|
import org.koitharu.kotatsu.core.model.MangaHistory
|
||||||
|
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
||||||
|
import org.koitharu.kotatsu.favourites.domain.OnFavouritesChangeListener
|
||||||
|
import org.koitharu.kotatsu.history.domain.HistoryRepository
|
||||||
|
import org.koitharu.kotatsu.history.domain.OnHistoryChangeListener
|
||||||
|
import org.koitharu.kotatsu.list.ui.MangaListViewModel
|
||||||
|
import org.koitharu.kotatsu.local.domain.LocalMangaRepository
|
||||||
|
import org.koitharu.kotatsu.search.domain.MangaSearchRepository
|
||||||
|
import org.koitharu.kotatsu.tracker.domain.TrackingRepository
|
||||||
|
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||||
|
import org.koitharu.kotatsu.utils.ext.onFirst
|
||||||
|
import org.koitharu.kotatsu.utils.ext.safe
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
|
class DetailsViewModel(
|
||||||
|
private val historyRepository: HistoryRepository,
|
||||||
|
private val favouritesRepository: FavouritesRepository,
|
||||||
|
private val localMangaRepository: LocalMangaRepository,
|
||||||
|
private val trackingRepository: TrackingRepository,
|
||||||
|
private val searchRepository: MangaSearchRepository,
|
||||||
|
private val mangaDataRepository: MangaDataRepository
|
||||||
|
) : MangaListViewModel(), OnHistoryChangeListener, OnFavouritesChangeListener {
|
||||||
|
|
||||||
|
val mangaData = MutableLiveData<Manga>()
|
||||||
|
val newChapters = MutableLiveData<Int>(0)
|
||||||
|
val onMangaRemoved = SingleLiveEvent<Manga>()
|
||||||
|
val history = MutableLiveData<MangaHistory?>()
|
||||||
|
val favouriteCategories = MutableLiveData<List<FavouriteCategory>>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
HistoryRepository.subscribe(this)
|
||||||
|
FavouritesRepository.subscribe(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findMangaById(id: Long) {
|
||||||
|
launchLoadingJob {
|
||||||
|
val manga = mangaDataRepository.findMangaById(id)
|
||||||
|
?: throw MangaNotFoundException("Cannot find manga by id")
|
||||||
|
mangaData.value = manga
|
||||||
|
loadDetails(manga, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadDetails(manga: Manga, force: Boolean = false) {
|
||||||
|
if (!force && mangaData.value == manga) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loadHistory(manga)
|
||||||
|
mangaData.value = manga
|
||||||
|
loadFavourite(manga)
|
||||||
|
launchLoadingJob {
|
||||||
|
val data = withContext(Dispatchers.Default) {
|
||||||
|
manga.source.repository.getDetails(manga)
|
||||||
|
}
|
||||||
|
mangaData.value = data
|
||||||
|
newChapters.value = trackingRepository.getNewChaptersCount(manga.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteLocal(manga: Manga) {
|
||||||
|
launchLoadingJob {
|
||||||
|
withContext(Dispatchers.Default) {
|
||||||
|
val original = localMangaRepository.getRemoteManga(manga)
|
||||||
|
localMangaRepository.delete(manga) || throw IOException("Unable to delete file")
|
||||||
|
safe {
|
||||||
|
historyRepository.deleteOrSwap(manga, original)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onMangaRemoved.call(manga)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadHistory(manga: Manga) {
|
||||||
|
launchJob {
|
||||||
|
history.value = historyRepository.getOne(manga)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadFavourite(manga: Manga) {
|
||||||
|
launchJob {
|
||||||
|
favouriteCategories.value = favouritesRepository.getCategories(manga.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadRelated() {
|
||||||
|
val manga = mangaData.value ?: return
|
||||||
|
searchRepository.globalSearch(manga.title)
|
||||||
|
.map { list ->
|
||||||
|
list.filter { x -> x.id != manga.id }
|
||||||
|
}.filterNot { x -> x.isEmpty() }
|
||||||
|
.flowOn(Dispatchers.IO)
|
||||||
|
.catch { e ->
|
||||||
|
if (e is IOException) {
|
||||||
|
onError.call(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onEmpty {
|
||||||
|
content.value = emptyList()
|
||||||
|
isLoading.value = false
|
||||||
|
}.onCompletion {
|
||||||
|
// TODO
|
||||||
|
}.onFirst {
|
||||||
|
isLoading.value = false
|
||||||
|
}.onEach {
|
||||||
|
content.value = content.value.orEmpty() + it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onHistoryChanged() {
|
||||||
|
loadHistory(mangaData.value ?: return)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFavouritesChanged(mangaId: Long) {
|
||||||
|
val manga = mangaData.value ?: return
|
||||||
|
if (mangaId == manga.id) {
|
||||||
|
loadFavourite(manga)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
HistoryRepository.unsubscribe(this)
|
||||||
|
FavouritesRepository.unsubscribe(this)
|
||||||
|
super.onCleared()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
package org.koitharu.kotatsu.details.ui
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import org.koin.android.viewmodel.ext.android.sharedViewModel
|
||||||
|
import org.koitharu.kotatsu.list.ui.MangaListFragment
|
||||||
|
|
||||||
|
class RelatedMangaFragment : MangaListFragment() {
|
||||||
|
|
||||||
|
override val viewModel by sharedViewModel<DetailsViewModel>()
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
isSwipeRefreshEnabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRequestMoreItems(offset: Int) {
|
||||||
|
if (offset == 0) {
|
||||||
|
viewModel.loadRelated()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package org.koitharu.kotatsu.favourites
|
||||||
|
|
||||||
|
import org.koin.android.viewmodel.dsl.viewModel
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
||||||
|
import org.koitharu.kotatsu.favourites.ui.categories.FavouritesCategoriesViewModel
|
||||||
|
import org.koitharu.kotatsu.favourites.ui.list.FavouritesListViewModel
|
||||||
|
|
||||||
|
val favouritesModule
|
||||||
|
get() = module {
|
||||||
|
|
||||||
|
single { FavouritesRepository(get()) }
|
||||||
|
|
||||||
|
viewModel { (categoryId: Long) ->
|
||||||
|
FavouritesListViewModel(categoryId, get())
|
||||||
|
}
|
||||||
|
viewModel { FavouritesCategoriesViewModel(get()) }
|
||||||
|
}
|
||||||
@ -1,7 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.core.db.dao
|
package org.koitharu.kotatsu.favourites.data
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import org.koitharu.kotatsu.core.db.entity.FavouriteCategoryEntity
|
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
abstract class FavouriteCategoriesDao {
|
abstract class FavouriteCategoriesDao {
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.core.db.entity
|
package org.koitharu.kotatsu.favourites.data
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
@ -1,8 +1,9 @@
|
|||||||
package org.koitharu.kotatsu.core.db.entity
|
package org.koitharu.kotatsu.favourites.data
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.ForeignKey
|
import androidx.room.ForeignKey
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "favourites", primaryKeys = ["manga_id", "category_id"], foreignKeys = [
|
tableName = "favourites", primaryKeys = ["manga_id", "category_id"], foreignKeys = [
|
||||||
@ -1,8 +1,11 @@
|
|||||||
package org.koitharu.kotatsu.core.db.entity
|
package org.koitharu.kotatsu.favourites.data
|
||||||
|
|
||||||
import androidx.room.Embedded
|
import androidx.room.Embedded
|
||||||
import androidx.room.Junction
|
import androidx.room.Junction
|
||||||
import androidx.room.Relation
|
import androidx.room.Relation
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.MangaTagsEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
||||||
|
|
||||||
data class FavouriteManga(
|
data class FavouriteManga(
|
||||||
@Embedded val favourite: FavouriteEntity,
|
@Embedded val favourite: FavouriteEntity,
|
||||||
@ -1,8 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.core.db.dao
|
package org.koitharu.kotatsu.favourites.data
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import org.koitharu.kotatsu.core.db.entity.FavouriteEntity
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.FavouriteManga
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
@ -1,16 +1,16 @@
|
|||||||
package org.koitharu.kotatsu.domain.favourites
|
package org.koitharu.kotatsu.favourites.domain
|
||||||
|
|
||||||
import androidx.collection.ArraySet
|
import androidx.collection.ArraySet
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.db.entity.FavouriteCategoryEntity
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.FavouriteEntity
|
|
||||||
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
||||||
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
import org.koitharu.kotatsu.core.db.entity.TagEntity
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
import org.koitharu.kotatsu.core.model.Manga
|
import org.koitharu.kotatsu.core.model.Manga
|
||||||
|
import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity
|
||||||
|
import org.koitharu.kotatsu.favourites.data.FavouriteEntity
|
||||||
import org.koitharu.kotatsu.utils.ext.mapToSet
|
import org.koitharu.kotatsu.utils.ext.mapToSet
|
||||||
|
|
||||||
class FavouritesRepository(private val db: MangaDatabase) {
|
class FavouritesRepository(private val db: MangaDatabase) {
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.domain.favourites
|
package org.koitharu.kotatsu.favourites.domain
|
||||||
|
|
||||||
fun interface OnFavouritesChangeListener {
|
fun interface OnFavouritesChangeListener {
|
||||||
|
|
||||||
@ -1,12 +1,13 @@
|
|||||||
package org.koitharu.kotatsu.ui.list.favourites
|
package org.koitharu.kotatsu.favourites.ui
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||||
import com.google.android.material.tabs.TabLayout
|
import com.google.android.material.tabs.TabLayout
|
||||||
import com.google.android.material.tabs.TabLayoutMediator
|
import com.google.android.material.tabs.TabLayoutMediator
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.AdapterUpdater
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
import org.koitharu.kotatsu.ui.base.list.AdapterUpdater
|
import org.koitharu.kotatsu.favourites.ui.list.FavouritesListFragment
|
||||||
import org.koitharu.kotatsu.utils.ext.replaceWith
|
import org.koitharu.kotatsu.utils.ext.replaceWith
|
||||||
|
|
||||||
class FavouritesPagerAdapter(
|
class FavouritesPagerAdapter(
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.list.favourites
|
package org.koitharu.kotatsu.favourites.ui
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
@ -1,13 +1,13 @@
|
|||||||
package org.koitharu.kotatsu.ui.list.favourites.categories
|
package org.koitharu.kotatsu.favourites.ui.categories
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import kotlinx.android.synthetic.main.item_category.*
|
import kotlinx.android.synthetic.main.item_category.*
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.BaseRecyclerAdapter
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.BaseViewHolder
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.OnRecyclerItemClickListener
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
import org.koitharu.kotatsu.ui.base.list.BaseRecyclerAdapter
|
|
||||||
import org.koitharu.kotatsu.ui.base.list.BaseViewHolder
|
|
||||||
import org.koitharu.kotatsu.ui.base.list.OnRecyclerItemClickListener
|
|
||||||
|
|
||||||
class CategoriesAdapter(private val onItemClickListener: OnRecyclerItemClickListener<FavouriteCategory>) :
|
class CategoriesAdapter(private val onItemClickListener: OnRecyclerItemClickListener<FavouriteCategory>) :
|
||||||
BaseRecyclerAdapter<FavouriteCategory, Unit>() {
|
BaseRecyclerAdapter<FavouriteCategory, Unit>() {
|
||||||
@ -1,11 +1,11 @@
|
|||||||
package org.koitharu.kotatsu.ui.list.favourites.categories
|
package org.koitharu.kotatsu.favourites.ui.categories
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.text.InputType
|
import android.text.InputType
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.dialog.TextInputDialog
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
import org.koitharu.kotatsu.ui.base.dialog.TextInputDialog
|
|
||||||
|
|
||||||
class CategoriesEditDelegate(
|
class CategoriesEditDelegate(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
@ -1,10 +1,10 @@
|
|||||||
package org.koitharu.kotatsu.ui.list.favourites.categories
|
package org.koitharu.kotatsu.favourites.ui.categories
|
||||||
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import kotlinx.android.synthetic.main.item_category.*
|
import kotlinx.android.synthetic.main.item_category.*
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.BaseViewHolder
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
import org.koitharu.kotatsu.ui.base.list.BaseViewHolder
|
|
||||||
|
|
||||||
class CategoryHolder(parent: ViewGroup) :
|
class CategoryHolder(parent: ViewGroup) :
|
||||||
BaseViewHolder<FavouriteCategory, Unit>(parent, R.layout.item_category) {
|
BaseViewHolder<FavouriteCategory, Unit>(parent, R.layout.item_category) {
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
package org.koitharu.kotatsu.favourites.ui.categories
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
||||||
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
|
import org.koitharu.kotatsu.core.model.Manga
|
||||||
|
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
||||||
|
import org.koitharu.kotatsu.utils.ext.mapToSet
|
||||||
|
|
||||||
|
class FavouritesCategoriesViewModel(
|
||||||
|
private val repository: FavouritesRepository
|
||||||
|
) : BaseViewModel() {
|
||||||
|
|
||||||
|
private var reorderJob: Job? = null
|
||||||
|
|
||||||
|
val categories = MutableLiveData<List<FavouriteCategory>>()
|
||||||
|
val mangaCategories = MutableLiveData<Set<Int>>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
loadAllCategories()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadAllCategories() {
|
||||||
|
launchJob {
|
||||||
|
categories.value = repository.getAllCategories()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadMangaCategories(manga: Manga) {
|
||||||
|
launchJob {
|
||||||
|
val categories = repository.getCategories(manga.id)
|
||||||
|
mangaCategories.value = categories.mapToSet { it.id.toInt() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createCategory(name: String) {
|
||||||
|
launchJob {
|
||||||
|
repository.addCategory(name)
|
||||||
|
categories.value = repository.getAllCategories()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun renameCategory(id: Long, name: String) {
|
||||||
|
launchJob {
|
||||||
|
repository.renameCategory(id, name)
|
||||||
|
categories.value = repository.getAllCategories()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteCategory(id: Long) {
|
||||||
|
launchJob {
|
||||||
|
repository.removeCategory(id)
|
||||||
|
categories.value = repository.getAllCategories()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun storeCategoriesOrder(orderedIds: List<Long>) {
|
||||||
|
val prevJob = reorderJob
|
||||||
|
reorderJob = launchJob {
|
||||||
|
prevJob?.join()
|
||||||
|
repository.reorderCategories(orderedIds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addToCategory(manga: Manga, categoryId: Long) {
|
||||||
|
launchJob {
|
||||||
|
repository.addToCategory(manga, categoryId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeFromCategory(manga: Manga, categoryId: Long) {
|
||||||
|
launchJob {
|
||||||
|
repository.removeFromCategory(manga, categoryId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
package org.koitharu.kotatsu.ui.list.favourites.categories.select
|
package org.koitharu.kotatsu.favourites.ui.categories.select
|
||||||
|
|
||||||
import android.util.SparseBooleanArray
|
import android.util.SparseBooleanArray
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Checkable
|
import android.widget.Checkable
|
||||||
import androidx.core.util.set
|
import androidx.core.util.set
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.BaseRecyclerAdapter
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.BaseViewHolder
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
import org.koitharu.kotatsu.ui.base.list.BaseRecyclerAdapter
|
|
||||||
import org.koitharu.kotatsu.ui.base.list.BaseViewHolder
|
|
||||||
|
|
||||||
class CategoriesSelectAdapter(private val listener: OnCategoryCheckListener) :
|
class CategoriesSelectAdapter(private val listener: OnCategoryCheckListener) :
|
||||||
BaseRecyclerAdapter<FavouriteCategory, Boolean>() {
|
BaseRecyclerAdapter<FavouriteCategory, Boolean>() {
|
||||||
@ -1,10 +1,10 @@
|
|||||||
package org.koitharu.kotatsu.ui.list.favourites.categories.select
|
package org.koitharu.kotatsu.favourites.ui.categories.select
|
||||||
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import kotlinx.android.synthetic.main.item_category_checkable.*
|
import kotlinx.android.synthetic.main.item_category_checkable.*
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.BaseViewHolder
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
import org.koitharu.kotatsu.ui.base.list.BaseViewHolder
|
|
||||||
|
|
||||||
class CategoryCheckableHolder(parent: ViewGroup) :
|
class CategoryCheckableHolder(parent: ViewGroup) :
|
||||||
BaseViewHolder<FavouriteCategory, Boolean>(parent, R.layout.item_category_checkable) {
|
BaseViewHolder<FavouriteCategory, Boolean>(parent, R.layout.item_category_checkable) {
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.ui.list.favourites.categories.select
|
package org.koitharu.kotatsu.favourites.ui.categories.select
|
||||||
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
|
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
package org.koitharu.kotatsu.favourites.ui.list
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.core.model.Manga
|
||||||
|
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
||||||
|
import org.koitharu.kotatsu.list.ui.MangaListViewModel
|
||||||
|
|
||||||
|
class FavouritesListViewModel(
|
||||||
|
private val categoryId: Long,
|
||||||
|
private val repository: FavouritesRepository
|
||||||
|
) : MangaListViewModel() {
|
||||||
|
|
||||||
|
fun loadList(offset: Int) {
|
||||||
|
launchLoadingJob {
|
||||||
|
val list = if (categoryId == 0L) {
|
||||||
|
repository.getAllManga(offset = offset)
|
||||||
|
} else {
|
||||||
|
repository.getManga(categoryId = categoryId, offset = offset)
|
||||||
|
}
|
||||||
|
if (offset == 0) {
|
||||||
|
content.value = list
|
||||||
|
} else {
|
||||||
|
content.value = content.value.orEmpty() + list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeFromFavourites(manga: Manga) {
|
||||||
|
launchJob {
|
||||||
|
if (categoryId == 0L) {
|
||||||
|
repository.removeFromFavourites(manga)
|
||||||
|
} else {
|
||||||
|
repository.removeFromCategory(manga, categoryId)
|
||||||
|
}
|
||||||
|
content.value = content.value?.filterNot { it.id == manga.id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue