Android 5 fixes

This commit is contained in:
Koitharu
2023-06-06 10:10:24 +03:00
parent c42d0824b0
commit 9587cb439c
6 changed files with 29 additions and 7 deletions

View File

@@ -4,9 +4,11 @@ import android.graphics.Color
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.WindowManager import android.view.WindowManager
import androidx.core.content.ContextCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat import androidx.core.view.WindowInsetsControllerCompat
import androidx.viewbinding.ViewBinding import androidx.viewbinding.ViewBinding
import org.koitharu.kotatsu.R
abstract class BaseFullscreenActivity<B : ViewBinding> : abstract class BaseFullscreenActivity<B : ViewBinding> :
BaseActivity<B>() { BaseActivity<B>() {
@@ -18,7 +20,11 @@ abstract class BaseFullscreenActivity<B : ViewBinding> :
with(window) { with(window) {
insetsControllerCompat = WindowInsetsControllerCompat(this, decorView) insetsControllerCompat = WindowInsetsControllerCompat(this, decorView)
statusBarColor = Color.TRANSPARENT statusBarColor = Color.TRANSPARENT
navigationBarColor = Color.TRANSPARENT navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
ContextCompat.getColor(this@BaseFullscreenActivity, R.color.dim)
} else {
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

View File

@@ -244,7 +244,7 @@ class DetailsActivity :
bottomMargin = insets.bottom + marginEnd bottomMargin = insets.bottom + marginEnd
} }
viewBinding.dragHandle?.updateLayoutParams<MarginLayoutParams> { viewBinding.dragHandle?.updateLayoutParams<MarginLayoutParams> {
bottomMargin = insets.bottom bottomMargin = insets.top
} }
} }

View File

@@ -7,6 +7,7 @@ import android.view.MenuItem
import androidx.core.view.MenuProvider import androidx.core.view.MenuProvider
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.settings.SettingsActivity
class DownloadsMenuProvider( class DownloadsMenuProvider(
private val context: Context, private val context: Context,
@@ -23,6 +24,10 @@ class DownloadsMenuProvider(
R.id.action_resume -> viewModel.resumeAll() R.id.action_resume -> viewModel.resumeAll()
R.id.action_cancel_all -> confirmCancelAll() R.id.action_cancel_all -> confirmCancelAll()
R.id.action_remove_completed -> confirmRemoveCompleted() R.id.action_remove_completed -> confirmRemoveCompleted()
R.id.action_settings -> {
context.startActivity(SettingsActivity.newDownloadsSettingsIntent(context))
}
else -> return false else -> return false
} }
return true return true

View File

@@ -34,8 +34,8 @@ class PagesCache @Inject constructor(@ApplicationContext context: Context) {
} }
private val lruCache = SuspendLazy { private val lruCache = SuspendLazy {
val dir = cacheDir.get() val dir = cacheDir.get()
val availableSize = getAvailableSizeMb() val availableSize = (getAvailableSize() * 0.8).toLong()
val size = SIZE_DEFAULT.coerceIn(SIZE_MIN, availableSize) val size = SIZE_DEFAULT.coerceAtMost(availableSize).coerceAtLeast(SIZE_MIN)
runCatchingCancellable { runCatchingCancellable {
DiskLruCache.create(dir, size) DiskLruCache.create(dir, size)
}.recoverCatching { error -> }.recoverCatching { error ->
@@ -66,9 +66,9 @@ class PagesCache @Inject constructor(@ApplicationContext context: Context) {
} }
} }
private suspend fun getAvailableSizeMb(): Long = runCatchingCancellable { private suspend fun getAvailableSize(): Long = runCatchingCancellable {
val statFs = StatFs(cacheDir.get().absolutePath) val statFs = StatFs(cacheDir.get().absolutePath)
FileSize.BYTES.convert(statFs.availableBytes, FileSize.MEGABYTES) statFs.availableBytes
}.onFailure { }.onFailure {
it.printStackTraceDebug() it.printStackTraceDebug()
}.getOrDefault(SIZE_DEFAULT) }.getOrDefault(SIZE_DEFAULT)

View File

@@ -134,7 +134,7 @@ class SettingsActivity :
supportFragmentManager.commit { supportFragmentManager.commit {
setReorderingAllowed(true) setReorderingAllowed(true)
replace(R.id.container, fragment) replace(R.id.container, fragment)
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) setTransition(FragmentTransaction.TRANSIT_FRAGMENT_MATCH_ACTIVITY_OPEN)
if (!isMasterDetail || (hasFragment && !isFromRoot)) { if (!isMasterDetail || (hasFragment && !isFromRoot)) {
addToBackStack(null) addToBackStack(null)
} }
@@ -148,6 +148,7 @@ class SettingsActivity :
ACTION_SUGGESTIONS -> SuggestionsSettingsFragment() ACTION_SUGGESTIONS -> SuggestionsSettingsFragment()
ACTION_HISTORY -> UserDataSettingsFragment() ACTION_HISTORY -> UserDataSettingsFragment()
ACTION_TRACKER -> TrackerSettingsFragment() ACTION_TRACKER -> TrackerSettingsFragment()
ACTION_MANAGE_DOWNLOADS -> DownloadsSettingsFragment()
ACTION_SOURCE -> SourceSettingsFragment.newInstance( ACTION_SOURCE -> SourceSettingsFragment.newInstance(
intent.getSerializableExtraCompat(EXTRA_SOURCE) as? MangaSource ?: MangaSource.LOCAL, intent.getSerializableExtraCompat(EXTRA_SOURCE) as? MangaSource ?: MangaSource.LOCAL,
) )
@@ -177,6 +178,7 @@ class SettingsActivity :
private const val ACTION_HISTORY = "${BuildConfig.APPLICATION_ID}.action.MANAGE_HISTORY" private const val ACTION_HISTORY = "${BuildConfig.APPLICATION_ID}.action.MANAGE_HISTORY"
private const val ACTION_SOURCE = "${BuildConfig.APPLICATION_ID}.action.MANAGE_SOURCE_SETTINGS" private const val ACTION_SOURCE = "${BuildConfig.APPLICATION_ID}.action.MANAGE_SOURCE_SETTINGS"
private const val ACTION_MANAGE_SOURCES = "${BuildConfig.APPLICATION_ID}.action.MANAGE_SOURCES_LIST" private const val ACTION_MANAGE_SOURCES = "${BuildConfig.APPLICATION_ID}.action.MANAGE_SOURCES_LIST"
private const val ACTION_MANAGE_DOWNLOADS = "${BuildConfig.APPLICATION_ID}.action.MANAGE_DOWNLOADS"
private const val EXTRA_SOURCE = "source" private const val EXTRA_SOURCE = "source"
private const val HOST_ABOUT = "about" private const val HOST_ABOUT = "about"
private const val HOST_SYNC_SETTINGS = "sync-settings" private const val HOST_SYNC_SETTINGS = "sync-settings"
@@ -203,6 +205,10 @@ class SettingsActivity :
Intent(context, SettingsActivity::class.java) Intent(context, SettingsActivity::class.java)
.setAction(ACTION_MANAGE_SOURCES) .setAction(ACTION_MANAGE_SOURCES)
fun newDownloadsSettingsIntent(context: Context) =
Intent(context, SettingsActivity::class.java)
.setAction(ACTION_MANAGE_DOWNLOADS)
fun newSourceSettingsIntent(context: Context, source: MangaSource) = fun newSourceSettingsIntent(context: Context, source: MangaSource) =
Intent(context, SettingsActivity::class.java) Intent(context, SettingsActivity::class.java)
.setAction(ACTION_SOURCE) .setAction(ACTION_SOURCE)

View File

@@ -27,4 +27,9 @@
android:title="@string/remove_completed" android:title="@string/remove_completed"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/action_settings"
android:title="@string/settings"
app:showAsAction="never" />
</menu> </menu>