Minor cleanup
This commit is contained in:
parent
6f4a46b437
commit
cec181f444
@ -349,7 +349,7 @@ class LibraryUpdateService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
LibraryGroup.BY_SOURCE -> {
|
LibraryGroup.BY_SOURCE -> {
|
||||||
val sourceExtra = groupExtra.nullIfBlank()?.toIntOrNull()
|
val sourceExtra = groupExtra?.nullIfBlank()?.toIntOrNull()
|
||||||
val source = libraryManga.map { it.source }
|
val source = libraryManga.map { it.source }
|
||||||
.distinct()
|
.distinct()
|
||||||
.sorted()
|
.sorted()
|
||||||
|
@ -124,7 +124,7 @@ open class SourceFeedController :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSearchViewQueryTextSubmit(query: String?) {
|
override fun onSearchViewQueryTextSubmit(query: String?) {
|
||||||
onBrowseClick(query.nullIfBlank())
|
onBrowseClick(query?.nullIfBlank())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSearchViewQueryTextChange(newText: String?) {
|
override fun onSearchViewQueryTextChange(newText: String?) {
|
||||||
|
@ -54,7 +54,6 @@ import exh.source.PERV_EDEN_IT_SOURCE_ID
|
|||||||
import exh.source.isEhBasedManga
|
import exh.source.isEhBasedManga
|
||||||
import exh.source.mangaDexSourceIds
|
import exh.source.mangaDexSourceIds
|
||||||
import exh.source.nHentaiSourceIds
|
import exh.source.nHentaiSourceIds
|
||||||
import exh.ui.LoaderManager
|
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
@ -121,7 +120,6 @@ class LibraryController(
|
|||||||
|
|
||||||
// Favorites
|
// Favorites
|
||||||
private var favoritesSyncJob: Job? = null
|
private var favoritesSyncJob: Job? = null
|
||||||
val loaderManager = LoaderManager()
|
|
||||||
// <-- EH
|
// <-- EH
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -462,7 +460,7 @@ class LibraryController(
|
|||||||
.setTitle(R.string.favorites_sync)
|
.setTitle(R.string.favorites_sync)
|
||||||
.setMessage(R.string.favorites_sync_conformation_message)
|
.setMessage(R.string.favorites_sync_conformation_message)
|
||||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
presenter.favoritesSync.runSync()
|
presenter.runSync()
|
||||||
}
|
}
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
.show()
|
.show()
|
||||||
|
@ -168,13 +168,12 @@ class LibraryPresenter(
|
|||||||
|
|
||||||
var groupType = preferences.groupLibraryBy().get()
|
var groupType = preferences.groupLibraryBy().get()
|
||||||
|
|
||||||
private val libraryIsGrouped
|
|
||||||
get() = groupType != LibraryGroup.UNGROUPED
|
|
||||||
|
|
||||||
private val loggedServices by lazy { trackManager.services.filter { it.isLogged } }
|
private val loggedServices by lazy { trackManager.services.filter { it.isLogged } }
|
||||||
|
|
||||||
private val services = trackManager.services.associate { service ->
|
private val services by lazy {
|
||||||
service.id to context.getString(service.nameRes())
|
trackManager.services.associate { service ->
|
||||||
|
service.id to context.getString(service.nameRes())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -570,7 +569,7 @@ class LibraryPresenter(
|
|||||||
var editedCategories = categories
|
var editedCategories = categories
|
||||||
val items = if (groupType == LibraryGroup.BY_DEFAULT) {
|
val items = if (groupType == LibraryGroup.BY_DEFAULT) {
|
||||||
map
|
map
|
||||||
} else if (!libraryIsGrouped) {
|
} else if (groupType == LibraryGroup.UNGROUPED) {
|
||||||
editedCategories = listOf(Category(0, "All", 0, 0))
|
editedCategories = listOf(Category(0, "All", 0, 0))
|
||||||
mapOf(
|
mapOf(
|
||||||
0L to map.values.flatten().distinctBy { it.manga.id },
|
0L to map.values.flatten().distinctBy { it.manga.id },
|
||||||
@ -1123,9 +1122,8 @@ class LibraryPresenter(
|
|||||||
return map to categories
|
return map to categories
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
fun runSync() {
|
||||||
super.onDestroy()
|
favoritesSync.runSync(presenterScope)
|
||||||
favoritesSync.onDestroy()
|
|
||||||
}
|
}
|
||||||
// SY <--
|
// SY <--
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,6 @@ import exh.util.ignore
|
|||||||
import exh.util.wifiManager
|
import exh.util.wifiManager
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.cancel
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import okhttp3.FormBody
|
import okhttp3.FormBody
|
||||||
@ -60,8 +58,6 @@ class FavoritesSyncHelper(val context: Context) {
|
|||||||
|
|
||||||
private val prefs: PreferencesHelper by injectLazy()
|
private val prefs: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
|
||||||
|
|
||||||
private val exh by lazy {
|
private val exh by lazy {
|
||||||
Injekt.get<SourceManager>().get(EXH_SOURCE_ID) as? EHentai
|
Injekt.get<SourceManager>().get(EXH_SOURCE_ID) as? EHentai
|
||||||
?: EHentai(0, true, context)
|
?: EHentai(0, true, context)
|
||||||
@ -81,7 +77,7 @@ class FavoritesSyncHelper(val context: Context) {
|
|||||||
val status: MutableStateFlow<FavoritesSyncStatus> = MutableStateFlow(FavoritesSyncStatus.Idle(context))
|
val status: MutableStateFlow<FavoritesSyncStatus> = MutableStateFlow(FavoritesSyncStatus.Idle(context))
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun runSync() {
|
fun runSync(scope: CoroutineScope) {
|
||||||
if (status.value !is FavoritesSyncStatus.Idle) {
|
if (status.value !is FavoritesSyncStatus.Idle) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -407,10 +403,6 @@ class FavoritesSyncHelper(val context: Context) {
|
|||||||
|
|
||||||
class IgnoredException : RuntimeException()
|
class IgnoredException : RuntimeException()
|
||||||
|
|
||||||
fun onDestroy() {
|
|
||||||
scope.cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val THROTTLE_WARN = 1.seconds
|
private val THROTTLE_WARN = 1.seconds
|
||||||
}
|
}
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
package exh.ui
|
|
||||||
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import java.util.UUID
|
|
||||||
import kotlin.coroutines.CoroutineContext
|
|
||||||
import kotlin.coroutines.EmptyCoroutineContext
|
|
||||||
|
|
||||||
typealias LoadingHandle = String
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class used to manage loader UIs
|
|
||||||
*/
|
|
||||||
class LoaderManager(parentContext: CoroutineContext = EmptyCoroutineContext) : CoroutineScope {
|
|
||||||
override val coroutineContext = Dispatchers.Main + parentContext
|
|
||||||
|
|
||||||
private val openLoadingHandles = mutableListOf<LoadingHandle>()
|
|
||||||
var loadingChangeListener: (suspend (newIsLoading: Boolean) -> Unit)? = null
|
|
||||||
|
|
||||||
fun openProgressBar(): LoadingHandle {
|
|
||||||
val (handle, shouldUpdateLoadingStatus) = synchronized(this) {
|
|
||||||
val handle = UUID.randomUUID().toString()
|
|
||||||
openLoadingHandles += handle
|
|
||||||
handle to (openLoadingHandles.size == 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldUpdateLoadingStatus) {
|
|
||||||
launch {
|
|
||||||
updateLoadingStatus(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return handle
|
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
fun closeProgressBar(handle: LoadingHandle?) {
|
|
||||||
if (handle == null) return
|
|
||||||
|
|
||||||
val shouldUpdateLoadingStatus = synchronized(this) {
|
|
||||||
openLoadingHandles.remove(handle) && openLoadingHandles.isEmpty()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldUpdateLoadingStatus) {
|
|
||||||
launch {
|
|
||||||
updateLoadingStatus(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun updateLoadingStatus(newStatus: Boolean) {
|
|
||||||
loadingChangeListener?.invoke(newStatus)
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,8 +8,7 @@ import eu.kanade.tachiyomi.util.lang.withIOContext
|
|||||||
import exh.GalleryAddEvent
|
import exh.GalleryAddEvent
|
||||||
import exh.GalleryAdder
|
import exh.GalleryAdder
|
||||||
import exh.log.xLogE
|
import exh.log.xLogE
|
||||||
import exh.util.dropEmpty
|
import exh.util.trimOrNull
|
||||||
import exh.util.trimAll
|
|
||||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
@ -30,25 +29,21 @@ class BatchAddPresenter : BasePresenter<BatchAddController>() {
|
|||||||
|
|
||||||
fun addGalleries(context: Context, galleries: String) {
|
fun addGalleries(context: Context, galleries: String) {
|
||||||
eventFlow = MutableSharedFlow(1)
|
eventFlow = MutableSharedFlow(1)
|
||||||
val regex =
|
|
||||||
"""[0-9]*?\.[a-z0-9]*?:""".toRegex()
|
|
||||||
|
|
||||||
val testedGalleries = if (regex.containsMatchIn(galleries)) {
|
val splitGalleries = if (ehVisitedRegex.containsMatchIn(galleries)) {
|
||||||
val url = if (preferences.enableExhentai().get()) {
|
val url = if (preferences.enableExhentai().get()) {
|
||||||
"https://exhentai.org/g/"
|
"https://exhentai.org/g/"
|
||||||
} else {
|
} else {
|
||||||
"https://e-hentai.org/g/"
|
"https://e-hentai.org/g/"
|
||||||
}
|
}
|
||||||
regex.findAll(galleries).map { galleryKeys ->
|
ehVisitedRegex.findAll(galleries).map { galleryKeys ->
|
||||||
val linkParts = galleryKeys.value.split(".")
|
val linkParts = galleryKeys.value.split(".")
|
||||||
url + linkParts[0] + "/" + linkParts[1].replace(":", "")
|
url + linkParts[0] + "/" + linkParts[1].replace(":", "")
|
||||||
}.joinToString(separator = "\n")
|
}.toList()
|
||||||
} else {
|
} else {
|
||||||
galleries
|
galleries.split("\n")
|
||||||
|
.mapNotNull(String::trimOrNull)
|
||||||
}
|
}
|
||||||
val splitGalleries = testedGalleries.split("\n")
|
|
||||||
.trimAll()
|
|
||||||
.dropEmpty()
|
|
||||||
|
|
||||||
progressFlow.value = 0
|
progressFlow.value = 0
|
||||||
progressTotalFlow.value = splitGalleries.size
|
progressTotalFlow.value = splitGalleries.size
|
||||||
@ -92,5 +87,7 @@ class BatchAddPresenter : BasePresenter<BatchAddController>() {
|
|||||||
const val STATE_IDLE = 0
|
const val STATE_IDLE = 0
|
||||||
const val STATE_INPUT_TO_PROGRESS = 1
|
const val STATE_INPUT_TO_PROGRESS = 1
|
||||||
const val STATE_PROGRESS_TO_INPUT = 2
|
const val STATE_PROGRESS_TO_INPUT = 2
|
||||||
|
|
||||||
|
val ehVisitedRegex = """[0-9]*?\.[a-z0-9]*?:""".toRegex()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,6 @@ fun String.removeArticles(): String {
|
|||||||
return replace(articleRegex, "")
|
return replace(articleRegex, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.trimOrNull(): String? {
|
fun String.trimOrNull() = trim().nullIfBlank()
|
||||||
val trimmed = trim()
|
|
||||||
return trimmed.ifBlank { null }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun String?.nullIfBlank(): String? = if (isNullOrBlank()) {
|
fun String.nullIfBlank(): String? = ifBlank { null }
|
||||||
null
|
|
||||||
} else {
|
|
||||||
this
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user