Fix warnings

This commit is contained in:
Koitharu
2023-05-29 13:06:50 +03:00
parent 4522c478cb
commit 2442e7cbe1
17 changed files with 34 additions and 66 deletions

View File

@@ -101,7 +101,7 @@ class RemoteMangaRepository(
}
fun getAvailableMirrors(): List<String> {
return parser.configKeyDomain.presetValues?.toList().orEmpty()
return parser.configKeyDomain.presetValues.toList()
}
private fun getConfig() = parser.config as SourceSettings

View File

@@ -86,7 +86,7 @@ class FaviconFetcher(
if (!options.diskCachePolicy.readEnabled) {
return null
}
val snapshot = diskCache.value?.get(diskCacheKey) ?: return null
val snapshot = diskCache.value?.openSnapshot(diskCacheKey) ?: return null
return SourceResult(
source = snapshot.toImageSource(),
mimeType = null,
@@ -98,12 +98,12 @@ class FaviconFetcher(
if (!options.diskCachePolicy.writeEnabled || body.contentLength() == 0L) {
return null
}
val editor = diskCache.value?.edit(diskCacheKey) ?: return null
val editor = diskCache.value?.openEditor(diskCacheKey) ?: return null
try {
fileSystem.write(editor.data) {
body.source().readAll(this)
}
return editor.commitAndGet()
return editor.commitAndOpenSnapshot()
} catch (e: Throwable) {
try {
editor.abort()

View File

@@ -3,57 +3,35 @@ package org.koitharu.kotatsu.core.ui
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.viewbinding.ViewBinding
@Suppress("DEPRECATION")
private const val SYSTEM_UI_FLAGS_SHOWN = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
@Suppress("DEPRECATION")
private const val SYSTEM_UI_FLAGS_HIDDEN = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
abstract class BaseFullscreenActivity<B : ViewBinding> :
BaseActivity<B>(),
View.OnSystemUiVisibilityChangeListener {
BaseActivity<B>() {
private lateinit var insetsControllerCompat: WindowInsetsControllerCompat
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
with(window) {
insetsControllerCompat = WindowInsetsControllerCompat(this, decorView)
statusBarColor = Color.TRANSPARENT
navigationBarColor = Color.TRANSPARENT
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
attributes.layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
}
decorView.setOnSystemUiVisibilityChangeListener(this@BaseFullscreenActivity)
}
showSystemUI()
}
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
@Deprecated("Deprecated in Java")
final override fun onSystemUiVisibilityChange(visibility: Int) {
onSystemUiVisibilityChanged(visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0)
}
// TODO WindowInsetsControllerCompat works incorrect
@Suppress("DEPRECATION")
protected fun hideSystemUI() {
window.decorView.systemUiVisibility = SYSTEM_UI_FLAGS_HIDDEN
insetsControllerCompat.hide(WindowInsetsCompat.Type.systemBars())
}
@Suppress("DEPRECATION")
protected fun showSystemUI() {
window.decorView.systemUiVisibility = SYSTEM_UI_FLAGS_SHOWN
insetsControllerCompat.show(WindowInsetsCompat.Type.systemBars())
}
protected open fun onSystemUiVisibilityChanged(isVisible: Boolean) = Unit
}

View File

@@ -8,7 +8,7 @@ class Event<T>(
private var isConsumed = false
suspend fun consume(collector: FlowCollector<T>) {
if (isConsumed) {
if (!isConsumed) {
collector.emit(data)
isConsumed = true
}

View File

@@ -23,6 +23,8 @@ import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.annotation.IntegerRes
import androidx.core.app.ActivityOptionsCompat
import androidx.core.content.IntentCompat
import androidx.core.content.PackageManagerCompat
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.coroutineScope

View File

@@ -9,13 +9,9 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.core.util.Event
fun <T> Flow<T>.observe(owner: LifecycleOwner, collector: FlowCollector<T>) {
if (BuildConfig.DEBUG) {
require((this as? StateFlow)?.value !is Event<*>)
}
val start = if (this is StateFlow) CoroutineStart.UNDISPATCHED else CoroutineStart.DEFAULT
owner.lifecycleScope.launch(start = start) {
owner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {

View File

@@ -80,7 +80,7 @@ class ExploreFragment :
viewModel.onOpenManga.observeEvent(viewLifecycleOwner, ::onOpenManga)
viewModel.onActionDone.observeEvent(viewLifecycleOwner, ReversibleActionObserver(binding.recyclerView))
viewModel.isGrid.observe(viewLifecycleOwner, ::onGridModeChanged)
viewModel.onShowSuggestionsTip.observe(viewLifecycleOwner) {
viewModel.onShowSuggestionsTip.observeEvent(viewLifecycleOwner) {
showSuggestionsTip()
}
}

View File

@@ -18,9 +18,7 @@ sealed interface ExploreItem : ListModel {
other as Buttons
if (isSuggestionsEnabled != other.isSuggestionsEnabled) return false
return true
return isSuggestionsEnabled == other.isSuggestionsEnabled
}
override fun hashCode(): Int {
@@ -40,9 +38,7 @@ sealed interface ExploreItem : ListModel {
other as Header
if (titleResId != other.titleResId) return false
if (isButtonVisible != other.isButtonVisible) return false
return true
return isButtonVisible == other.isButtonVisible
}
override fun hashCode(): Int {
@@ -64,9 +60,7 @@ sealed interface ExploreItem : ListModel {
other as Source
if (source != other.source) return false
if (isGrid != other.isGrid) return false
return true
return isGrid == other.isGrid
}
override fun hashCode(): Int {
@@ -76,7 +70,6 @@ sealed interface ExploreItem : ListModel {
}
}
@Deprecated("")
class EmptyHint(
@DrawableRes icon: Int,
@StringRes textPrimary: Int,

View File

@@ -130,7 +130,6 @@ class LocalMangaDirInput(root: File) : LocalMangaInput(root) {
}
val cbz = root.listFilesRecursive(CbzFilter()).firstOrNull() ?: return null
return ZipFile(cbz).use { zip ->
val filter = ImageFileFilter()
zip.entries().asSequence()
.firstOrNull { x -> !x.isDirectory && filter.accept(x) }
?.let { entry -> zipUri(cbz, entry.name) }

View File

@@ -129,7 +129,7 @@ class MainActivity :
navigationDelegate =
MainNavigationDelegate(checkNotNull(bottomNav ?: viewBinding.navRail), supportFragmentManager)
navigationDelegate.addOnFragmentChangedListener(this)
navigationDelegate.onCreate(savedInstanceState)
navigationDelegate.onCreate()
onBackPressedDispatcher.addCallback(ExitCallback(this, viewBinding.container))
onBackPressedDispatcher.addCallback(navigationDelegate)

View File

@@ -1,6 +1,5 @@
package org.koitharu.kotatsu.main.ui
import android.os.Bundle
import android.view.MenuItem
import androidx.activity.OnBackPressedCallback
import androidx.annotation.IdRes
@@ -57,7 +56,7 @@ class MainNavigationDelegate(
navBar.selectedItemId = R.id.nav_shelf
}
fun onCreate(savedInstanceState: Bundle?) {
fun onCreate() {
primaryFragment?.let {
onFragmentChanged(it, fromUser = false)
val itemId = getItemId(it)

View File

@@ -67,7 +67,7 @@ class ScrobblerConfigActivity : BaseActivity<ActivityScrobblerConfigBinding>(),
viewModel.user.observe(this, this::onUserChanged)
viewModel.isLoading.observe(this, this::onLoadingStateChanged)
viewModel.onError.observeEvent(this, SnackbarErrorObserver(viewBinding.recyclerView, null))
viewModel.onLoggedOut.observe(this) {
viewModel.onLoggedOut.observeEvent(this) {
finishAfterTransition()
}

View File

@@ -19,6 +19,7 @@ import dagger.hilt.android.AndroidEntryPoint
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.ui.BaseActivity
import org.koitharu.kotatsu.core.util.ext.observe
import org.koitharu.kotatsu.core.util.ext.observeEvent
import org.koitharu.kotatsu.databinding.ActivitySetupProtectBinding
private const val MIN_PASSWORD_LENGTH = 4
@@ -46,13 +47,13 @@ class ProtectSetupActivity :
viewBinding.switchBiometric.setOnCheckedChangeListener(this)
viewModel.isSecondStep.observe(this, this::onStepChanged)
viewModel.onPasswordSet.observe(this) {
viewModel.onPasswordSet.observeEvent(this) {
finishAfterTransition()
}
viewModel.onPasswordMismatch.observe(this) {
viewModel.onPasswordMismatch.observeEvent(this) {
viewBinding.editPassword.error = getString(R.string.passwords_mismatch)
}
viewModel.onClearText.observe(this) {
viewModel.onClearText.observeEvent(this) {
viewBinding.editPassword.text?.clear()
}
}

View File

@@ -57,7 +57,7 @@ class SyncAuthActivity : BaseActivity<ActivitySyncAuthBinding>(), View.OnClickLi
viewModel.onTokenObtained.observeEvent(this, ::onTokenReceived)
viewModel.onError.observeEvent(this, ::onError)
viewModel.isLoading.observe(this, ::onLoadingStateChanged)
viewModel.onAccountAlreadyExists.observe(this) {
viewModel.onAccountAlreadyExists.observeEvent(this) {
onAccountAlreadyExists()
}

View File

@@ -79,7 +79,7 @@ class FeedFragment :
viewModel.content.observe(viewLifecycleOwner, this::onListChanged)
viewModel.onError.observeEvent(viewLifecycleOwner, SnackbarErrorObserver(binding.recyclerView, this))
viewModel.onFeedCleared.observe(viewLifecycleOwner) {
viewModel.onFeedCleared.observeEvent(viewLifecycleOwner) {
onFeedCleared()
}
TrackWorker.observeIsRunning(binding.root.context.applicationContext)