Update moxy

pull/1/head
Koitharu 6 years ago
parent a2a0e62b47
commit e6befc57e0

@ -60,7 +60,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.0-alpha01' implementation 'androidx.core:core-ktx:1.3.0-alpha01'
implementation "androidx.fragment:fragment-ktx:1.2.2" implementation "androidx.fragment:fragment-ktx:1.2.2"
implementation 'androidx.appcompat:appcompat:1.2.0-alpha02' implementation 'androidx.appcompat:appcompat:1.2.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha03' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha03'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01' implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
implementation 'androidx.preference:preference:1.1.0' implementation 'androidx.preference:preference:1.1.0'
@ -70,17 +70,17 @@ dependencies {
implementation 'androidx.room:room-ktx:2.2.4' implementation 'androidx.room:room-ktx:2.2.4'
kapt 'androidx.room:room-compiler:2.2.4' kapt 'androidx.room:room-compiler:2.2.4'
implementation 'com.github.moxy-community:moxy:2.0.2' implementation 'com.github.moxy-community:moxy:2.1.1'
implementation 'com.github.moxy-community:moxy-androidx:2.0.2' implementation 'com.github.moxy-community:moxy-androidx:2.1.1'
implementation 'com.github.moxy-community:moxy-material:2.0.2' implementation 'com.github.moxy-community:moxy-material:2.1.1'
implementation 'com.github.moxy-community:moxy-ktx:2.0.2' implementation 'com.github.moxy-community:moxy-ktx:2.1.1'
kapt 'com.github.moxy-community:moxy-compiler:2.0.2' kapt 'com.github.moxy-community:moxy-compiler:2.1.1'
implementation 'com.squareup.okhttp3:okhttp:4.4.0' implementation 'com.squareup.okhttp3:okhttp:4.4.0'
implementation 'com.squareup.okio:okio:2.4.3' implementation 'com.squareup.okio:okio:2.4.3'
implementation 'org.jsoup:jsoup:1.12.2' implementation 'org.jsoup:jsoup:1.12.2'
implementation 'org.koin:koin-android:2.0.1' implementation 'org.koin:koin-android:2.1.0'
implementation 'io.coil-kt:coil:0.9.5' implementation 'io.coil-kt:coil:0.9.5'
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0' implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
implementation 'com.tomclaw.cache:cache:1.0' implementation 'com.tomclaw.cache:cache:1.0'

@ -1,22 +1,7 @@
package org.koitharu.kotatsu.ui.common package org.koitharu.kotatsu.ui.common
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import moxy.MvpPresenter import moxy.MvpPresenter
import moxy.MvpView import moxy.MvpView
import org.koin.core.KoinComponent import org.koin.core.KoinComponent
import kotlin.coroutines.CoroutineContext
abstract class BasePresenter<V : MvpView> : MvpPresenter<V>(), KoinComponent, CoroutineScope { abstract class BasePresenter<V : MvpView> : MvpPresenter<V>(), KoinComponent
private val job = SupervisorJob()
override val coroutineContext: CoroutineContext
get() = Dispatchers.Main + job
override fun onDestroy() {
job.cancel()
super.onDestroy()
}
}

@ -22,7 +22,7 @@ class ChaptersFragment : BaseFragment(R.layout.fragment_chapters), MangaDetailsV
OnRecyclerItemClickListener<MangaChapter> { OnRecyclerItemClickListener<MangaChapter> {
@Suppress("unused") @Suppress("unused")
private val presenter by moxyPresenter { (activity as MangaDetailsActivity).presenter } private val presenter by moxyPresenter(factory = MangaDetailsPresenter.Companion::getInstance)
private var manga: Manga? = null private var manga: Manga? = null

@ -28,7 +28,7 @@ import org.koitharu.kotatsu.utils.ext.getDisplayMessage
class MangaDetailsActivity : BaseActivity(), MangaDetailsView { class MangaDetailsActivity : BaseActivity(), MangaDetailsView {
val presenter by moxyPresenter(factory = ::MangaDetailsPresenter) private val presenter by moxyPresenter(factory = MangaDetailsPresenter.Companion::getInstance)
private var manga: Manga? = null private var manga: Manga? = null

@ -19,7 +19,7 @@ import kotlin.math.roundToInt
class MangaDetailsFragment : BaseFragment(R.layout.fragment_details), MangaDetailsView { class MangaDetailsFragment : BaseFragment(R.layout.fragment_details), MangaDetailsView {
@Suppress("unused") @Suppress("unused")
private val presenter by moxyPresenter { (activity as MangaDetailsActivity).presenter } private val presenter by moxyPresenter(factory = MangaDetailsPresenter.Companion::getInstance)
private var manga: Manga? = null private var manga: Manga? = null
private var history: MangaHistory? = null private var history: MangaHistory? = null

@ -4,6 +4,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import moxy.InjectViewState import moxy.InjectViewState
import moxy.presenterScope
import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.core.model.Manga import org.koitharu.kotatsu.core.model.Manga
import org.koitharu.kotatsu.domain.MangaProviderFactory import org.koitharu.kotatsu.domain.MangaProviderFactory
@ -14,7 +15,7 @@ import org.koitharu.kotatsu.domain.history.OnHistoryChangeListener
import org.koitharu.kotatsu.ui.common.BasePresenter import org.koitharu.kotatsu.ui.common.BasePresenter
@InjectViewState @InjectViewState
class MangaDetailsPresenter : BasePresenter<MangaDetailsView>(), OnHistoryChangeListener, class MangaDetailsPresenter private constructor(): BasePresenter<MangaDetailsView>(), OnHistoryChangeListener,
OnFavouritesChangeListener { OnFavouritesChangeListener {
private lateinit var historyRepository: HistoryRepository private lateinit var historyRepository: HistoryRepository
@ -37,7 +38,7 @@ class MangaDetailsPresenter : BasePresenter<MangaDetailsView>(), OnHistoryChange
loadHistory(manga) loadHistory(manga)
viewState.onMangaUpdated(manga) viewState.onMangaUpdated(manga)
loadFavourite(manga) loadFavourite(manga)
launch { presenterScope.launch {
try { try {
viewState.onLoadingStateChanged(true) viewState.onLoadingStateChanged(true)
val data = withContext(Dispatchers.IO) { val data = withContext(Dispatchers.IO) {
@ -57,7 +58,7 @@ class MangaDetailsPresenter : BasePresenter<MangaDetailsView>(), OnHistoryChange
} }
private fun loadHistory(manga: Manga) { private fun loadHistory(manga: Manga) {
launch { presenterScope.launch {
try { try {
val history = withContext(Dispatchers.IO) { val history = withContext(Dispatchers.IO) {
historyRepository.getOne(manga) historyRepository.getOne(manga)
@ -72,7 +73,7 @@ class MangaDetailsPresenter : BasePresenter<MangaDetailsView>(), OnHistoryChange
} }
private fun loadFavourite(manga: Manga) { private fun loadFavourite(manga: Manga) {
launch { presenterScope.launch {
try { try {
val categories = withContext(Dispatchers.IO) { val categories = withContext(Dispatchers.IO) {
favouritesRepository.getCategories(manga.id) favouritesRepository.getCategories(manga.id)
@ -99,6 +100,18 @@ class MangaDetailsPresenter : BasePresenter<MangaDetailsView>(), OnHistoryChange
override fun onDestroy() { override fun onDestroy() {
HistoryRepository.unsubscribe(this) HistoryRepository.unsubscribe(this)
FavouritesRepository.unsubscribe(this) FavouritesRepository.unsubscribe(this)
instance = null
super.onDestroy() super.onDestroy()
} }
companion object {
private var instance: MangaDetailsPresenter? = null
fun getInstance(): MangaDetailsPresenter = instance ?: synchronized(this) {
MangaDetailsPresenter().also {
instance = it
}
}
}
} }

@ -4,6 +4,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import moxy.InjectViewState import moxy.InjectViewState
import moxy.presenterScope
import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.domain.favourites.FavouritesRepository import org.koitharu.kotatsu.domain.favourites.FavouritesRepository
import org.koitharu.kotatsu.ui.common.BasePresenter import org.koitharu.kotatsu.ui.common.BasePresenter
@ -20,7 +21,7 @@ class FavouritesListPresenter : BasePresenter<MangaListView<Unit>>() {
} }
fun loadList(offset: Int) { fun loadList(offset: Int) {
launch { presenterScope.launch {
viewState.onLoadingChanged(true) viewState.onLoadingChanged(true)
try { try {
val list = withContext(Dispatchers.IO) { val list = withContext(Dispatchers.IO) {

@ -4,6 +4,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import moxy.InjectViewState import moxy.InjectViewState
import moxy.presenterScope
import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.core.model.Manga import org.koitharu.kotatsu.core.model.Manga
import org.koitharu.kotatsu.domain.favourites.FavouritesRepository import org.koitharu.kotatsu.domain.favourites.FavouritesRepository
@ -21,7 +22,7 @@ class FavouriteCategoriesPresenter : BasePresenter<FavouriteCategoriesView>() {
} }
fun loadAllCategories() { fun loadAllCategories() {
launch { presenterScope.launch {
try { try {
val categories = withContext(Dispatchers.IO) { val categories = withContext(Dispatchers.IO) {
repository.getAllCategories() repository.getAllCategories()
@ -37,7 +38,7 @@ class FavouriteCategoriesPresenter : BasePresenter<FavouriteCategoriesView>() {
} }
fun loadMangaCategories(manga: Manga) { fun loadMangaCategories(manga: Manga) {
launch { presenterScope.launch {
try { try {
val categories = withContext(Dispatchers.IO) { val categories = withContext(Dispatchers.IO) {
repository.getCategories(manga.id) repository.getCategories(manga.id)
@ -53,7 +54,7 @@ class FavouriteCategoriesPresenter : BasePresenter<FavouriteCategoriesView>() {
} }
fun createCategory(name: String) { fun createCategory(name: String) {
launch { presenterScope.launch {
try { try {
val categories = withContext(Dispatchers.IO) { val categories = withContext(Dispatchers.IO) {
repository.addCategory(name) repository.addCategory(name)
@ -70,7 +71,7 @@ class FavouriteCategoriesPresenter : BasePresenter<FavouriteCategoriesView>() {
} }
fun addToCategory(manga: Manga, categoryId: Long) { fun addToCategory(manga: Manga, categoryId: Long) {
launch { presenterScope.launch {
try { try {
val categories = withContext(Dispatchers.IO) { val categories = withContext(Dispatchers.IO) {
repository.addToCategory(manga,categoryId) repository.addToCategory(manga,categoryId)
@ -85,7 +86,7 @@ class FavouriteCategoriesPresenter : BasePresenter<FavouriteCategoriesView>() {
} }
fun removeFromCategory(manga: Manga, categoryId: Long) { fun removeFromCategory(manga: Manga, categoryId: Long) {
launch { presenterScope.launch {
try { try {
val categories = withContext(Dispatchers.IO) { val categories = withContext(Dispatchers.IO) {
repository.removeFromCategory(manga, categoryId) repository.removeFromCategory(manga, categoryId)

@ -4,6 +4,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import moxy.InjectViewState import moxy.InjectViewState
import moxy.presenterScope
import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.BuildConfig
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
@ -22,7 +23,7 @@ class HistoryListPresenter : BasePresenter<MangaListView<MangaHistory>>() {
} }
fun loadList(offset: Int) { fun loadList(offset: Int) {
launch { presenterScope.launch {
viewState.onLoadingChanged(true) viewState.onLoadingChanged(true)
try { try {
val list = withContext(Dispatchers.IO) { val list = withContext(Dispatchers.IO) {
@ -45,7 +46,7 @@ class HistoryListPresenter : BasePresenter<MangaListView<MangaHistory>>() {
} }
fun clearHistory() { fun clearHistory() {
launch { presenterScope.launch {
viewState.onLoadingChanged(true) viewState.onLoadingChanged(true)
try { try {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
@ -64,7 +65,7 @@ class HistoryListPresenter : BasePresenter<MangaListView<MangaHistory>>() {
} }
fun removeFromHistory(manga: Manga) { fun removeFromHistory(manga: Manga) {
launch { presenterScope.launch {
try { try {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
repository.delete(manga) repository.delete(manga)

@ -7,6 +7,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import moxy.InjectViewState import moxy.InjectViewState
import moxy.presenterScope
import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.core.exceptions.UnsupportedFileException import org.koitharu.kotatsu.core.exceptions.UnsupportedFileException
import org.koitharu.kotatsu.core.model.Manga import org.koitharu.kotatsu.core.model.Manga
@ -33,7 +34,7 @@ class LocalListPresenter : BasePresenter<MangaListView<File>>() {
} }
fun loadList() { fun loadList() {
launch { presenterScope.launch {
viewState.onLoadingChanged(true) viewState.onLoadingChanged(true)
try { try {
val list = withContext(Dispatchers.IO) { val list = withContext(Dispatchers.IO) {
@ -53,7 +54,7 @@ class LocalListPresenter : BasePresenter<MangaListView<File>>() {
} }
fun importFile(context: Context, uri: Uri) { fun importFile(context: Context, uri: Uri) {
launch(Dispatchers.IO) { presenterScope.launch(Dispatchers.IO) {
try { try {
val name = MediaStoreCompat.getName(context, uri) val name = MediaStoreCompat.getName(context, uri)
?: throw IOException("Cannot fetch name from uri: $uri") ?: throw IOException("Cannot fetch name from uri: $uri")
@ -84,7 +85,7 @@ class LocalListPresenter : BasePresenter<MangaListView<File>>() {
} }
fun delete(manga: Manga) { fun delete(manga: Manga) {
launch { presenterScope.launch {
try { try {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
repository.delete(manga) || throw IOException("Unable to delete file") repository.delete(manga) || throw IOException("Unable to delete file")

@ -4,6 +4,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import moxy.InjectViewState import moxy.InjectViewState
import moxy.presenterScope
import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.core.model.MangaFilter import org.koitharu.kotatsu.core.model.MangaFilter
import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.model.MangaSource
@ -18,7 +19,7 @@ class RemoteListPresenter : BasePresenter<MangaListView<Unit>>() {
private var filter: MangaFilter? = null private var filter: MangaFilter? = null
fun loadList(source: MangaSource, offset: Int) { fun loadList(source: MangaSource, offset: Int) {
launch { presenterScope.launch {
viewState.onLoadingChanged(true) viewState.onLoadingChanged(true)
try { try {
val list = withContext(Dispatchers.IO) { val list = withContext(Dispatchers.IO) {
@ -55,7 +56,7 @@ class RemoteListPresenter : BasePresenter<MangaListView<Unit>>() {
private fun loadFilter(source: MangaSource) { private fun loadFilter(source: MangaSource) {
isFilterInitialized = true isFilterInitialized = true
launch { presenterScope.launch {
try { try {
val (sorts, tags) = withContext(Dispatchers.IO) { val (sorts, tags) = withContext(Dispatchers.IO) {
val repo = MangaProviderFactory.create(source) val repo = MangaProviderFactory.create(source)

@ -7,6 +7,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import moxy.InjectViewState import moxy.InjectViewState
import moxy.presenterScope
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.BuildConfig
@ -23,7 +24,7 @@ import org.koitharu.kotatsu.utils.ext.mimeType
class ReaderPresenter : BasePresenter<ReaderView>() { class ReaderPresenter : BasePresenter<ReaderView>() {
fun loadChapter(state: ReaderState) { fun loadChapter(state: ReaderState) {
launch { presenterScope.launch {
viewState.onLoadingStateChanged(isLoading = true) viewState.onLoadingStateChanged(isLoading = true)
try { try {
val pages = withContext(Dispatchers.IO) { val pages = withContext(Dispatchers.IO) {
@ -46,7 +47,7 @@ class ReaderPresenter : BasePresenter<ReaderView>() {
} }
fun saveState(state: ReaderState) { fun saveState(state: ReaderState) {
launch(Dispatchers.IO) { presenterScope.launch(Dispatchers.IO) {
HistoryRepository().addOrUpdate( HistoryRepository().addOrUpdate(
manga = state.manga, manga = state.manga,
chapterId = state.chapterId, chapterId = state.chapterId,
@ -56,7 +57,7 @@ class ReaderPresenter : BasePresenter<ReaderView>() {
} }
fun savePage(resolver: ContentResolver, page: MangaPage) { fun savePage(resolver: ContentResolver, page: MangaPage) {
launch(Dispatchers.IO) { presenterScope.launch(Dispatchers.IO) {
try { try {
val repo = MangaProviderFactory.create(page.source) val repo = MangaProviderFactory.create(page.source)
val url = repo.getPageFullUrl(page) val url = repo.getPageFullUrl(page)

@ -4,6 +4,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import moxy.InjectViewState import moxy.InjectViewState
import moxy.presenterScope
import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.domain.MangaProviderFactory import org.koitharu.kotatsu.domain.MangaProviderFactory
@ -21,7 +22,7 @@ class SearchPresenter : BasePresenter<MangaListView<Unit>>() {
} }
fun loadList(query: String, offset: Int) { fun loadList(query: String, offset: Int) {
launch { presenterScope.launch {
viewState.onLoadingChanged(true) viewState.onLoadingChanged(true)
try { try {
//TODO select source //TODO select source

Loading…
Cancel
Save