Hide manga updates if tracker is disabled

pull/293/head
Koitharu 3 years ago
parent bd692fc60c
commit 61784bcfc4
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -89,8 +89,14 @@ class DetailsViewModel @AssistedInject constructor(
private val favourite = favouritesRepository.observeCategoriesIds(delegate.mangaId).map { it.isNotEmpty() } private val favourite = favouritesRepository.observeCategoriesIds(delegate.mangaId).map { it.isNotEmpty() }
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, false) .stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, false)
private val newChapters = trackingRepository.observeNewChaptersCount(delegate.mangaId) private val newChapters = settings.observeAsFlow(AppSettings.KEY_TRACKER_ENABLED) { isTrackerEnabled }
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, 0) .flatMapLatest { isEnabled ->
if (isEnabled) {
trackingRepository.observeNewChaptersCount(delegate.mangaId)
} else {
flowOf(0)
}
}.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Eagerly, 0)
private val chaptersQuery = MutableStateFlow("") private val chaptersQuery = MutableStateFlow("")

@ -117,7 +117,11 @@ class FavouritesListViewModel @AssistedInject constructor(
} }
override suspend fun getCounter(mangaId: Long): Int { override suspend fun getCounter(mangaId: Long): Int {
return trackingRepository.getNewChaptersCount(mangaId) return if (settings.isTrackerEnabled) {
trackingRepository.getNewChaptersCount(mangaId)
} else {
0
}
} }
override suspend fun getProgress(mangaId: Long): Float { override suspend fun getProgress(mangaId: Long): Float {

@ -3,9 +3,6 @@ package org.koitharu.kotatsu.history.ui
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import java.util.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
@ -21,11 +18,20 @@ import org.koitharu.kotatsu.history.domain.HistoryRepository
import org.koitharu.kotatsu.history.domain.MangaWithHistory import org.koitharu.kotatsu.history.domain.MangaWithHistory
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
import org.koitharu.kotatsu.list.ui.MangaListViewModel import org.koitharu.kotatsu.list.ui.MangaListViewModel
import org.koitharu.kotatsu.list.ui.model.* import org.koitharu.kotatsu.list.ui.model.EmptyState
import org.koitharu.kotatsu.list.ui.model.ListModel
import org.koitharu.kotatsu.list.ui.model.LoadingState
import org.koitharu.kotatsu.list.ui.model.toErrorState
import org.koitharu.kotatsu.list.ui.model.toGridModel
import org.koitharu.kotatsu.list.ui.model.toListDetailedModel
import org.koitharu.kotatsu.list.ui.model.toListModel
import org.koitharu.kotatsu.tracker.domain.TrackingRepository import org.koitharu.kotatsu.tracker.domain.TrackingRepository
import org.koitharu.kotatsu.utils.asFlowLiveData import org.koitharu.kotatsu.utils.asFlowLiveData
import org.koitharu.kotatsu.utils.ext.daysDiff import org.koitharu.kotatsu.utils.ext.daysDiff
import org.koitharu.kotatsu.utils.ext.onFirst import org.koitharu.kotatsu.utils.ext.onFirst
import java.util.Date
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class HistoryListViewModel @Inject constructor( class HistoryListViewModel @Inject constructor(
@ -53,6 +59,7 @@ class HistoryListViewModel @Inject constructor(
actionStringRes = 0, actionStringRes = 0,
), ),
) )
else -> mapList(list, grouped, mode) else -> mapList(list, grouped, mode)
} }
}.onStart { }.onStart {
@ -103,7 +110,11 @@ class HistoryListViewModel @Inject constructor(
} }
prevDate = date prevDate = date
} }
val counter = trackingRepository.getNewChaptersCount(manga.id) val counter = if (settings.isTrackerEnabled) {
trackingRepository.getNewChaptersCount(manga.id)
} else {
0
}
val percent = if (showPercent) history.percent else PROGRESS_NONE val percent = if (showPercent) history.percent else PROGRESS_NONE
result += when (mode) { result += when (mode) {
ListMode.LIST -> manga.toListModel(counter, percent) ListMode.LIST -> manga.toListModel(counter, percent)

@ -4,14 +4,16 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.asFlow import androidx.lifecycle.asFlow
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import java.io.IOException import kotlinx.coroutines.CancellationException
import java.util.* import kotlinx.coroutines.Dispatchers
import javax.inject.Inject import kotlinx.coroutines.Job
import kotlinx.coroutines.* import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.base.ui.widgets.ChipsView import org.koitharu.kotatsu.base.ui.widgets.ChipsView
import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.AppSettings
@ -20,7 +22,11 @@ import org.koitharu.kotatsu.history.domain.HistoryRepository
import org.koitharu.kotatsu.history.domain.PROGRESS_NONE import org.koitharu.kotatsu.history.domain.PROGRESS_NONE
import org.koitharu.kotatsu.list.domain.ListExtraProvider import org.koitharu.kotatsu.list.domain.ListExtraProvider
import org.koitharu.kotatsu.list.ui.MangaListViewModel import org.koitharu.kotatsu.list.ui.MangaListViewModel
import org.koitharu.kotatsu.list.ui.model.* import org.koitharu.kotatsu.list.ui.model.EmptyState
import org.koitharu.kotatsu.list.ui.model.ListHeader2
import org.koitharu.kotatsu.list.ui.model.LoadingState
import org.koitharu.kotatsu.list.ui.model.toErrorState
import org.koitharu.kotatsu.list.ui.model.toUi
import org.koitharu.kotatsu.local.domain.LocalMangaRepository import org.koitharu.kotatsu.local.domain.LocalMangaRepository
import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaTag import org.koitharu.kotatsu.parsers.model.MangaTag
@ -30,6 +36,9 @@ import org.koitharu.kotatsu.utils.SingleLiveEvent
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
import org.koitharu.kotatsu.utils.ext.runCatchingCancellable import org.koitharu.kotatsu.utils.ext.runCatchingCancellable
import java.io.IOException
import java.util.LinkedList
import javax.inject.Inject
@HiltViewModel @HiltViewModel
class LocalListViewModel @Inject constructor( class LocalListViewModel @Inject constructor(
@ -181,7 +190,11 @@ class LocalListViewModel @Inject constructor(
} }
override suspend fun getCounter(mangaId: Long): Int { override suspend fun getCounter(mangaId: Long): Int {
return trackingRepository.getNewChaptersCount(mangaId) return if (settings.isTrackerEnabled) {
trackingRepository.getNewChaptersCount(mangaId)
} else {
0
}
} }
override suspend fun getProgress(mangaId: Long): Float { override suspend fun getProgress(mangaId: Long): Float {

@ -53,17 +53,22 @@ class ShelfViewModel @Inject constructor(
val content: LiveData<List<ListModel>> = combine( val content: LiveData<List<ListModel>> = combine(
settings.observeAsFlow(AppSettings.KEY_SHELF_SECTIONS) { shelfSections }, settings.observeAsFlow(AppSettings.KEY_SHELF_SECTIONS) { shelfSections },
settings.observeAsFlow(AppSettings.KEY_TRACKER_ENABLED) { isTrackerEnabled },
networkState, networkState,
repository.observeShelfContent(), repository.observeShelfContent(),
) { sections, isConnected, content -> ) { sections, isTrackerEnabled, isConnected, content ->
mapList(content, sections, isConnected) mapList(content, isTrackerEnabled, sections, isConnected)
}.debounce(500) }.debounce(500)
.catch { e -> .catch { e ->
emit(listOf(e.toErrorState(canRetry = false))) emit(listOf(e.toErrorState(canRetry = false)))
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState)) }.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, listOf(LoadingState))
override suspend fun getCounter(mangaId: Long): Int { override suspend fun getCounter(mangaId: Long): Int {
return trackingRepository.getNewChaptersCount(mangaId) return if (settings.isTrackerEnabled) {
trackingRepository.getNewChaptersCount(mangaId)
} else {
0
}
} }
override suspend fun getProgress(mangaId: Long): Float { override suspend fun getProgress(mangaId: Long): Float {
@ -135,6 +140,7 @@ class ShelfViewModel @Inject constructor(
private suspend fun mapList( private suspend fun mapList(
content: ShelfContent, content: ShelfContent,
isTrackerEnabled: Boolean,
sections: List<ShelfSection>, sections: List<ShelfSection>,
isNetworkAvailable: Boolean, isNetworkAvailable: Boolean,
): List<ListModel> { ): List<ListModel> {
@ -144,7 +150,10 @@ class ShelfViewModel @Inject constructor(
when (section) { when (section) {
ShelfSection.HISTORY -> mapHistory(result, content.history) ShelfSection.HISTORY -> mapHistory(result, content.history)
ShelfSection.LOCAL -> mapLocal(result, content.local) ShelfSection.LOCAL -> mapLocal(result, content.local)
ShelfSection.UPDATED -> mapUpdated(result, content.updated) ShelfSection.UPDATED -> if (isTrackerEnabled) {
mapUpdated(result, content.updated)
}
ShelfSection.FAVORITES -> mapFavourites(result, content.favourites) ShelfSection.FAVORITES -> mapFavourites(result, content.favourites)
} }
} }
@ -194,7 +203,7 @@ class ShelfViewModel @Inject constructor(
val showPercent = settings.isReadingIndicatorsEnabled val showPercent = settings.isReadingIndicatorsEnabled
destination += ShelfSectionModel.History( destination += ShelfSectionModel.History(
items = list.map { (manga, history) -> items = list.map { (manga, history) ->
val counter = trackingRepository.getNewChaptersCount(manga.id) val counter = getCounter(manga.id)
val percent = if (showPercent) history.percent else PROGRESS_NONE val percent = if (showPercent) history.percent else PROGRESS_NONE
manga.toGridModel(counter, percent) manga.toGridModel(counter, percent)
}, },

@ -23,9 +23,10 @@ class ShelfSettingsViewModel @Inject constructor(
val content = combine( val content = combine(
settings.observeAsFlow(AppSettings.KEY_SHELF_SECTIONS) { shelfSections }, settings.observeAsFlow(AppSettings.KEY_SHELF_SECTIONS) { shelfSections },
settings.observeAsFlow(AppSettings.KEY_TRACKER_ENABLED) { isTrackerEnabled },
favouritesRepository.observeCategories(), favouritesRepository.observeCategories(),
) { sections, categories -> ) { sections, isTrackerEnabled, categories ->
buildList(sections, categories) buildList(sections, isTrackerEnabled, categories)
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, emptyList()) }.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, emptyList())
private var updateJob: Job? = null private var updateJob: Job? = null
@ -64,13 +65,18 @@ class ShelfSettingsViewModel @Inject constructor(
private fun buildList( private fun buildList(
sections: List<ShelfSection>, sections: List<ShelfSection>,
isTrackerEnabled: Boolean,
categories: List<FavouriteCategory> categories: List<FavouriteCategory>
): List<ShelfSettingsItemModel> { ): List<ShelfSettingsItemModel> {
val result = ArrayList<ShelfSettingsItemModel>() val result = ArrayList<ShelfSettingsItemModel>()
val sectionsList = ShelfSection.values().toMutableList() val sectionsList = ShelfSection.values().toMutableList()
if (!isTrackerEnabled) {
sectionsList.remove(ShelfSection.UPDATED)
}
for (section in sections) { for (section in sections) {
sectionsList.remove(section) if (sectionsList.remove(section)) {
result.addSection(section, true, categories) result.addSection(section, true, categories)
}
} }
for (section in sectionsList) { for (section in sectionsList) {
result.addSection(section, false, categories) result.addSection(section, false, categories)

Loading…
Cancel
Save