Update dependencies and fix some warnings
This commit is contained in:
@@ -42,4 +42,4 @@ abstract class AlertDialogFragment<B : ViewBinding> : DialogFragment() {
|
||||
protected fun bindingOrNull(): B? = viewBinding
|
||||
|
||||
protected abstract fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): B
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,11 @@ package org.koitharu.kotatsu.base.ui
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
import kotlinx.coroutines.*
|
||||
import org.koitharu.kotatsu.BuildConfig
|
||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
|
||||
abstract class BaseViewModel : ViewModel() {
|
||||
|
||||
@@ -33,7 +33,7 @@ abstract class BaseViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
protected fun createErrorHandler() = CoroutineExceptionHandler { _, throwable ->
|
||||
private fun createErrorHandler() = CoroutineExceptionHandler { _, throwable ->
|
||||
if (BuildConfig.DEBUG) {
|
||||
throwable.printStackTrace()
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.webkit.WebChromeClient
|
||||
import android.webkit.WebView
|
||||
import androidx.core.view.isVisible
|
||||
import com.google.android.material.progressindicator.BaseProgressIndicator
|
||||
import org.koitharu.kotatsu.utils.ext.setIndeterminateCompat
|
||||
|
||||
private const val PROGRESS_MAX = 100
|
||||
|
||||
@@ -22,10 +21,10 @@ class ProgressChromeClient(
|
||||
return
|
||||
}
|
||||
if (newProgress in 1 until PROGRESS_MAX) {
|
||||
progressIndicator.setIndeterminateCompat(false)
|
||||
progressIndicator.isIndeterminate = false
|
||||
progressIndicator.setProgressCompat(newProgress.coerceAtMost(PROGRESS_MAX), true)
|
||||
} else {
|
||||
progressIndicator.setIndeterminateCompat(true)
|
||||
progressIndicator.setIndeterminate(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.koitharu.kotatsu.core.backup
|
||||
|
||||
import android.content.Context
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runInterruptible
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -8,8 +10,6 @@ import org.json.JSONArray
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.utils.MutableZipFile
|
||||
import org.koitharu.kotatsu.utils.ext.format
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class BackupArchive(file: File) : MutableZipFile(file) {
|
||||
|
||||
@@ -40,7 +40,7 @@ class BackupArchive(file: File) : MutableZipFile(file) {
|
||||
}
|
||||
dir.mkdirs()
|
||||
val filename = buildString {
|
||||
append(context.getString(R.string.app_name).toLowerCase(Locale.ROOT))
|
||||
append(context.getString(R.string.app_name).lowercase(Locale.ROOT))
|
||||
append('_')
|
||||
append(Date().format("ddMMyyyy"))
|
||||
append(".bak")
|
||||
|
||||
@@ -18,7 +18,8 @@ import org.koitharu.kotatsu.suggestions.data.SuggestionEntity
|
||||
MangaEntity::class, TagEntity::class, HistoryEntity::class, MangaTagsEntity::class,
|
||||
FavouriteCategoryEntity::class, FavouriteEntity::class, MangaPrefsEntity::class,
|
||||
TrackEntity::class, TrackLogEntity::class, SuggestionEntity::class
|
||||
], version = 9
|
||||
],
|
||||
version = 9
|
||||
)
|
||||
abstract class MangaDatabase : RoomDatabase() {
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ fun downloadItemAD(
|
||||
) {
|
||||
|
||||
var job: Job? = null
|
||||
val percentPattern = context.resources.getString(R.string.percent_string_pattern)
|
||||
|
||||
bind {
|
||||
job?.cancel()
|
||||
@@ -37,21 +38,21 @@ fun downloadItemAD(
|
||||
when (state) {
|
||||
is DownloadManager.State.Cancelling -> {
|
||||
binding.textViewStatus.setText(R.string.cancelling_)
|
||||
binding.progressBar.setIndeterminateCompat(true)
|
||||
binding.progressBar.isIndeterminate = true
|
||||
binding.progressBar.isVisible = true
|
||||
binding.textViewPercent.isVisible = false
|
||||
binding.textViewDetails.isVisible = false
|
||||
}
|
||||
is DownloadManager.State.Done -> {
|
||||
binding.textViewStatus.setText(R.string.download_complete)
|
||||
binding.progressBar.setIndeterminateCompat(false)
|
||||
binding.progressBar.isIndeterminate = false
|
||||
binding.progressBar.isVisible = false
|
||||
binding.textViewPercent.isVisible = false
|
||||
binding.textViewDetails.isVisible = false
|
||||
}
|
||||
is DownloadManager.State.Error -> {
|
||||
binding.textViewStatus.setText(R.string.error_occurred)
|
||||
binding.progressBar.setIndeterminateCompat(false)
|
||||
binding.progressBar.isIndeterminate = false
|
||||
binding.progressBar.isVisible = false
|
||||
binding.textViewPercent.isVisible = false
|
||||
binding.textViewDetails.text = state.error.getDisplayMessage(context.resources)
|
||||
@@ -59,38 +60,38 @@ fun downloadItemAD(
|
||||
}
|
||||
is DownloadManager.State.PostProcessing -> {
|
||||
binding.textViewStatus.setText(R.string.processing_)
|
||||
binding.progressBar.setIndeterminateCompat(true)
|
||||
binding.progressBar.isIndeterminate = true
|
||||
binding.progressBar.isVisible = true
|
||||
binding.textViewPercent.isVisible = false
|
||||
binding.textViewDetails.isVisible = false
|
||||
}
|
||||
is DownloadManager.State.Preparing -> {
|
||||
binding.textViewStatus.setText(R.string.preparing_)
|
||||
binding.progressBar.setIndeterminateCompat(true)
|
||||
binding.progressBar.isIndeterminate = true
|
||||
binding.progressBar.isVisible = true
|
||||
binding.textViewPercent.isVisible = false
|
||||
binding.textViewDetails.isVisible = false
|
||||
}
|
||||
is DownloadManager.State.Progress -> {
|
||||
binding.textViewStatus.setText(R.string.manga_downloading_)
|
||||
binding.progressBar.setIndeterminateCompat(false)
|
||||
binding.progressBar.isIndeterminate = false
|
||||
binding.progressBar.isVisible = true
|
||||
binding.progressBar.max = state.max
|
||||
binding.progressBar.setProgressCompat(state.progress, true)
|
||||
binding.textViewPercent.text = (state.percent * 100f).format(1) + "%"
|
||||
binding.textViewPercent.text = percentPattern.format((state.percent * 100f).format(1))
|
||||
binding.textViewPercent.isVisible = true
|
||||
binding.textViewDetails.isVisible = false
|
||||
}
|
||||
is DownloadManager.State.Queued -> {
|
||||
binding.textViewStatus.setText(R.string.queued)
|
||||
binding.progressBar.setIndeterminateCompat(false)
|
||||
binding.progressBar.isIndeterminate = false
|
||||
binding.progressBar.isVisible = false
|
||||
binding.textViewPercent.isVisible = false
|
||||
binding.textViewDetails.isVisible = false
|
||||
}
|
||||
is DownloadManager.State.WaitingForNetwork -> {
|
||||
binding.textViewStatus.setText(R.string.waiting_for_network)
|
||||
binding.progressBar.setIndeterminateCompat(false)
|
||||
binding.progressBar.isIndeterminate = false
|
||||
binding.progressBar.isVisible = false
|
||||
binding.textViewPercent.isVisible = false
|
||||
binding.textViewDetails.isVisible = false
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package org.koitharu.kotatsu.reader.ui.pager.reversed
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.children
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlinx.coroutines.async
|
||||
import org.koin.android.ext.android.get
|
||||
import org.koitharu.kotatsu.databinding.FragmentReaderStandardBinding
|
||||
@@ -17,7 +19,6 @@ import org.koitharu.kotatsu.utils.ext.doOnPageChanged
|
||||
import org.koitharu.kotatsu.utils.ext.recyclerView
|
||||
import org.koitharu.kotatsu.utils.ext.resetTransformations
|
||||
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
class ReversedReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
|
||||
|
||||
@@ -28,6 +29,7 @@ class ReversedReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
|
||||
container: ViewGroup?
|
||||
) = FragmentReaderStandardBinding.inflate(inflater, container, false)
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
pagerAdapter = ReversedPagesAdapter(viewModel.pageLoader, get(), exceptionResolver)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.koitharu.kotatsu.reader.ui.pager.standard
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.PointF
|
||||
import android.net.Uri
|
||||
import android.view.View
|
||||
@@ -27,10 +28,12 @@ open class PageHolder(
|
||||
|
||||
init {
|
||||
binding.ssiv.setOnImageEventListener(delegate)
|
||||
@Suppress("LeakingThis")
|
||||
binding.buttonRetry.setOnClickListener(this)
|
||||
binding.textViewNumber.isVisible = settings.isPagesNumbersEnabled
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onBind(data: ReaderPage) {
|
||||
delegate.onBind(data.toMangaPage())
|
||||
binding.textViewNumber.text = (data.index + 1).toString()
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package org.koitharu.kotatsu.reader.ui.pager.standard
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.children
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlinx.coroutines.async
|
||||
import org.koin.android.ext.android.get
|
||||
import org.koitharu.kotatsu.databinding.FragmentReaderStandardBinding
|
||||
@@ -16,7 +18,6 @@ import org.koitharu.kotatsu.utils.ext.doOnPageChanged
|
||||
import org.koitharu.kotatsu.utils.ext.recyclerView
|
||||
import org.koitharu.kotatsu.utils.ext.resetTransformations
|
||||
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
class PagerReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
|
||||
|
||||
@@ -27,6 +28,7 @@ class PagerReaderFragment : BaseReader<FragmentReaderStandardBinding>() {
|
||||
container: ViewGroup?
|
||||
) = FragmentReaderStandardBinding.inflate(inflater, container, false)
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
pagesAdapter = PagesAdapter(viewModel.pageLoader, get(), exceptionResolver)
|
||||
|
||||
@@ -17,15 +17,14 @@ class SearchBehavior(context: Context?, attrs: AttributeSet?) :
|
||||
child: SearchToolbar,
|
||||
dependency: View,
|
||||
): Boolean {
|
||||
return if (dependency is AppBarLayout) {
|
||||
true
|
||||
} else
|
||||
if (dependency is LinearLayout || dependency is BottomNavigationView) {
|
||||
return when (dependency) {
|
||||
is AppBarLayout -> true
|
||||
is LinearLayout, is BottomNavigationView -> {
|
||||
dependency.z = child.z + 1
|
||||
true
|
||||
} else {
|
||||
super.layoutDependsOn(parent, child, dependency)
|
||||
}
|
||||
else -> super.layoutDependsOn(parent, child, dependency)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDependentViewChanged(
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.base.ui.AlertDialogFragment
|
||||
import org.koitharu.kotatsu.databinding.DialogProgressBinding
|
||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||
import org.koitharu.kotatsu.utils.ext.setIndeterminateCompat
|
||||
import org.koitharu.kotatsu.utils.progress.Progress
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
@@ -65,7 +64,7 @@ class BackupDialogFragment : AlertDialogFragment<DialogProgressBinding>() {
|
||||
|
||||
private fun onProgressChanged(progress: Progress?) {
|
||||
with(binding.progressBar) {
|
||||
setIndeterminateCompat(progress == null)
|
||||
isIndeterminate = progress == null
|
||||
isVisible = true
|
||||
if (progress != null) {
|
||||
this.max = progress.total
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.io.File
|
||||
|
||||
class BackupViewModel(
|
||||
private val repository: BackupRepository,
|
||||
private val context: Context
|
||||
context: Context
|
||||
) : BaseViewModel() {
|
||||
|
||||
val progress = MutableLiveData<Progress?>(null)
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.koitharu.kotatsu.settings.backup
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
import kotlinx.coroutines.runInterruptible
|
||||
@@ -14,13 +16,11 @@ import org.koitharu.kotatsu.core.backup.CompositeResult
|
||||
import org.koitharu.kotatsu.core.backup.RestoreRepository
|
||||
import org.koitharu.kotatsu.utils.SingleLiveEvent
|
||||
import org.koitharu.kotatsu.utils.progress.Progress
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
class RestoreViewModel(
|
||||
uri: Uri?,
|
||||
private val repository: RestoreRepository,
|
||||
private val context: Context
|
||||
context: Context
|
||||
) : BaseViewModel() {
|
||||
|
||||
val progress = MutableLiveData<Progress?>(null)
|
||||
@@ -35,8 +35,7 @@ class RestoreViewModel(
|
||||
|
||||
val backup = runInterruptible(Dispatchers.IO) {
|
||||
val tempFile = File.createTempFile("backup_", ".tmp")
|
||||
(contentResolver.openInputStream(uri)
|
||||
?: throw FileNotFoundException()).use { input ->
|
||||
(contentResolver.openInputStream(uri) ?: throw FileNotFoundException()).use { input ->
|
||||
tempFile.outputStream().use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import android.net.ConnectivityManager
|
||||
import android.net.Network
|
||||
import android.net.NetworkRequest
|
||||
import android.net.Uri
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import kotlin.coroutines.resume
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
|
||||
val Context.connectivityManager: ConnectivityManager
|
||||
get() = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
|
||||
@@ -14,7 +14,6 @@ import androidx.core.view.children
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.google.android.material.progressindicator.BaseProgressIndicator
|
||||
import com.google.android.material.slider.Slider
|
||||
import com.hannesdorfmann.adapterdelegates4.dsl.AdapterDelegateViewBindingViewHolder
|
||||
import kotlin.math.roundToInt
|
||||
@@ -138,19 +137,6 @@ inline fun <reified T> RecyclerView.ViewHolder.getItem(): T? {
|
||||
return ((this as? AdapterDelegateViewBindingViewHolder<*, *>)?.item as? T)
|
||||
}
|
||||
|
||||
@Deprecated("Useless")
|
||||
fun BaseProgressIndicator<*>.setIndeterminateCompat(indeterminate: Boolean) {
|
||||
if (isIndeterminate != indeterminate) {
|
||||
if (indeterminate && visibility == View.VISIBLE) {
|
||||
visibility = View.INVISIBLE
|
||||
isIndeterminate = indeterminate
|
||||
visibility = View.VISIBLE
|
||||
} else {
|
||||
isIndeterminate = indeterminate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Slider.setValueRounded(newValue: Float) {
|
||||
val step = stepSize
|
||||
value = (newValue / step).roundToInt() * step
|
||||
|
||||
Reference in New Issue
Block a user