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

@@ -106,7 +106,7 @@ dependencies {
implementation 'androidx.work:work-runtime-ktx:2.8.1' implementation 'androidx.work:work-runtime-ktx:2.8.1'
//noinspection GradleDependency //noinspection GradleDependency
implementation('com.google.guava:guava:31.1-android') { implementation('com.google.guava:guava:32.0.0-android') {
exclude group: 'com.google.guava', module: 'failureaccess' exclude group: 'com.google.guava', module: 'failureaccess'
exclude group: 'org.checkerframework', module: 'checker-qual' exclude group: 'org.checkerframework', module: 'checker-qual'
exclude group: 'com.google.j2objc', module: 'j2objc-annotations' exclude group: 'com.google.j2objc', module: 'j2objc-annotations'
@@ -116,8 +116,8 @@ dependencies {
implementation 'androidx.room:room-ktx:2.5.1' implementation 'androidx.room:room-ktx:2.5.1'
kapt 'androidx.room:room-compiler:2.5.1' kapt 'androidx.room:room-compiler:2.5.1'
implementation 'com.squareup.okhttp3:okhttp:4.10.0' implementation 'com.squareup.okhttp3:okhttp:4.11.0'
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3' implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.11.0'
implementation 'com.squareup.okio:okio:3.3.0' implementation 'com.squareup.okio:okio:3.3.0'
implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2' implementation 'com.hannesdorfmann:adapterdelegates4-kotlin-dsl:4.3.2'
@@ -128,8 +128,8 @@ dependencies {
implementation 'androidx.hilt:hilt-work:1.0.0' implementation 'androidx.hilt:hilt-work:1.0.0'
kapt 'androidx.hilt:hilt-compiler:1.0.0' kapt 'androidx.hilt:hilt-compiler:1.0.0'
implementation 'io.coil-kt:coil-base:2.3.0' implementation 'io.coil-kt:coil-base:2.4.0'
implementation 'io.coil-kt:coil-svg:2.3.0' implementation 'io.coil-kt:coil-svg:2.4.0'
implementation 'com.github.KotatsuApp:subsampling-scale-image-view:1b19231b2f' implementation 'com.github.KotatsuApp:subsampling-scale-image-view:1b19231b2f'
implementation 'com.github.solkin:disk-lru-cache:1.4' implementation 'com.github.solkin:disk-lru-cache:1.4'
implementation 'io.noties.markwon:core:4.6.2' implementation 'io.noties.markwon:core:4.6.2'

View File

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

View File

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

View File

@@ -3,57 +3,35 @@ package org.koitharu.kotatsu.core.ui
import android.graphics.Color import android.graphics.Color
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.View
import android.view.WindowManager import android.view.WindowManager
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.viewbinding.ViewBinding 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> : abstract class BaseFullscreenActivity<B : ViewBinding> :
BaseActivity<B>(), BaseActivity<B>() {
View.OnSystemUiVisibilityChangeListener {
private lateinit var insetsControllerCompat: WindowInsetsControllerCompat
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
with(window) { with(window) {
insetsControllerCompat = WindowInsetsControllerCompat(this, decorView)
statusBarColor = Color.TRANSPARENT statusBarColor = Color.TRANSPARENT
navigationBarColor = Color.TRANSPARENT navigationBarColor = Color.TRANSPARENT
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
attributes.layoutInDisplayCutoutMode = attributes.layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
} }
decorView.setOnSystemUiVisibilityChangeListener(this@BaseFullscreenActivity)
} }
showSystemUI() 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() { protected fun hideSystemUI() {
window.decorView.systemUiVisibility = SYSTEM_UI_FLAGS_HIDDEN insetsControllerCompat.hide(WindowInsetsCompat.Type.systemBars())
} }
@Suppress("DEPRECATION")
protected fun showSystemUI() { 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 private var isConsumed = false
suspend fun consume(collector: FlowCollector<T>) { suspend fun consume(collector: FlowCollector<T>) {
if (isConsumed) { if (!isConsumed) {
collector.emit(data) collector.emit(data)
isConsumed = true isConsumed = true
} }

View File

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

View File

@@ -9,13 +9,9 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.core.util.Event import org.koitharu.kotatsu.core.util.Event
fun <T> Flow<T>.observe(owner: LifecycleOwner, collector: FlowCollector<T>) { 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 val start = if (this is StateFlow) CoroutineStart.UNDISPATCHED else CoroutineStart.DEFAULT
owner.lifecycleScope.launch(start = start) { owner.lifecycleScope.launch(start = start) {
owner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { owner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -4,7 +4,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:8.0.1' classpath 'com.android.tools.build:gradle:8.0.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21' classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21'
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.46.1' classpath 'com.google.dagger:hilt-android-gradle-plugin:2.46.1'
} }