Updating to min sdk 23

This commit is contained in:
Jay 2020-03-15 23:09:40 -07:00
parent 4734cc1668
commit 1d5163163d
16 changed files with 35 additions and 79 deletions

View File

@ -31,7 +31,7 @@ android {
buildToolsVersion("29.0.2") buildToolsVersion("29.0.2")
defaultConfig { defaultConfig {
minSdkVersion(21) minSdkVersion(23)
targetSdkVersion(29) targetSdkVersion(29)
applicationId = "eu.kanade.tachiyomi" applicationId = "eu.kanade.tachiyomi"
versionCode = 60 versionCode = 60

View File

@ -114,9 +114,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor {
} }
// HTTP error codes are only received since M // HTTP error codes are only received since M
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && if (url == origRequestUrl && !challengeFound) {
url == origRequestUrl && !challengeFound
) {
// The first request didn't return the challenge, abort. // The first request didn't return the challenge, abort.
latch.countDown() latch.countDown()
} }

View File

@ -1,7 +1,6 @@
package eu.kanade.tachiyomi.ui.base.controller package eu.kanade.tachiyomi.ui.base.controller
import android.content.pm.PackageManager.PERMISSION_GRANTED import android.content.pm.PackageManager.PERMISSION_GRANTED
import android.os.Build
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.Router
@ -19,11 +18,9 @@ fun Router.popControllerWithTag(tag: String): Boolean {
fun Controller.requestPermissionsSafe(permissions: Array<String>, requestCode: Int) { fun Controller.requestPermissionsSafe(permissions: Array<String>, requestCode: Int) {
val activity = activity ?: return val activity = activity ?: return
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { permissions.forEach { permission ->
permissions.forEach { permission -> if (ContextCompat.checkSelfPermission(activity, permission) != PERMISSION_GRANTED) {
if (ContextCompat.checkSelfPermission(activity, permission) != PERMISSION_GRANTED) { requestPermissions(arrayOf(permission), requestCode)
requestPermissions(arrayOf(permission), requestCode)
}
} }
} }
} }

View File

@ -39,9 +39,7 @@ class DisplayBottomSheet(private val controller: LibraryController) : BottomShee
sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup) sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup)
setEdgeToEdge(activity, bottom_sheet, view, false) setEdgeToEdge(activity, bottom_sheet, view, false)
val height = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
} else 0
sheetBehavior.peekHeight = 220.dpToPx + height sheetBehavior.peekHeight = 220.dpToPx + height
sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {

View File

@ -83,10 +83,6 @@ class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int
updateButton.setOnClickListener { addCategoryToUpdate() } updateButton.setOnClickListener { addCategoryToUpdate() }
sortText.setOnClickListener { it.post { showCatSortOptions() } } sortText.setOnClickListener { it.post { showCatSortOptions() } }
checkboxImage.setOnClickListener { selectAll() } checkboxImage.setOnClickListener { selectAll() }
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
sortText.compoundDrawablesRelative[2]?.mutate()?.setTint(
ContextCompat.getColor(contentView.context, R.color.gray_button))
}
updateButton.drawable.mutate() updateButton.drawable.mutate()
} }

View File

@ -390,13 +390,9 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle),
if (headerPosition > -1) { if (headerPosition > -1) {
val appbar = activity?.appbar val appbar = activity?.appbar
recycler.suppressLayout(true) recycler.suppressLayout(true)
val appbarOffset = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val appbarOffset = if (appbar?.y ?: 0f > -20) 0 else (appbar?.y?.plus(
if (appbar?.y ?: 0f > -20) 0 else (appbar?.y?.plus(
view?.rootWindowInsets?.systemWindowInsetTop ?: 0 view?.rootWindowInsets?.systemWindowInsetTop ?: 0
) ?: 0f).roundToInt() + 30.dpToPx ) ?: 0f).roundToInt() + 30.dpToPx
} else {
0
}
(recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset( (recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
headerPosition, (if (headerPosition == 0) 0 else (-28).dpToPx) + appbarOffset headerPosition, (if (headerPosition == 0) 0 else (-28).dpToPx) + appbarOffset
) )

View File

@ -223,7 +223,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
// if device doesn't support light nav bar // if device doesn't support light nav bar
window.navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { window.navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
// basically if in landscape on a phone // basically if in landscape on a phone
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && (v.rootWindowInsets.systemWindowInsetLeft > 0 || v.rootWindowInsets.systemWindowInsetRight > 0)) if (v.rootWindowInsets.systemWindowInsetLeft > 0 || v.rootWindowInsets.systemWindowInsetRight > 0))
// For lollipop, draw opaque nav bar // For lollipop, draw opaque nav bar
Color.BLACK Color.BLACK
else Color.argb(179, 0, 0, 0) else Color.argb(179, 0, 0, 0)
@ -283,7 +283,7 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
) )
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && currentNightMode == Configuration.UI_MODE_NIGHT_NO) content.systemUiVisibility = if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) content.systemUiVisibility =
content.systemUiVisibility.or( content.systemUiVisibility.or(
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
) )
@ -364,13 +364,12 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
} }
override fun startSupportActionMode(callback: androidx.appcompat.view.ActionMode.Callback): androidx.appcompat.view.ActionMode? { override fun startSupportActionMode(callback: androidx.appcompat.view.ActionMode.Callback): androidx.appcompat.view.ActionMode? {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) window?.statusBarColor = window?.statusBarColor = getResourceColor(R.attr.colorPrimary)
getResourceColor(R.attr.colorPrimary)
return super.startSupportActionMode(callback) return super.startSupportActionMode(callback)
} }
override fun onSupportActionModeFinished(mode: androidx.appcompat.view.ActionMode) { override fun onSupportActionModeFinished(mode: androidx.appcompat.view.ActionMode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) launchUI { launchUI {
val scale = Settings.Global.getFloat( val scale = Settings.Global.getFloat(
contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f
) )

View File

@ -31,9 +31,7 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : BottomSheetD
sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup) sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup)
setEdgeToEdge(activity, bottom_sheet, view, false) setEdgeToEdge(activity, bottom_sheet, view, false)
val height = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
} else 0
sheetBehavior.peekHeight = 380.dpToPx + height sheetBehavior.peekHeight = 380.dpToPx + height
sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {

View File

@ -48,9 +48,7 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) : Bott
sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup) sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup)
setEdgeToEdge(activity, display_bottom_sheet, view, false) setEdgeToEdge(activity, display_bottom_sheet, view, false)
val height = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
} else 0
sheetBehavior.peekHeight = 380.dpToPx + height sheetBehavior.peekHeight = 380.dpToPx + height
sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {

View File

@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.migration.manga.design
import android.app.Activity import android.app.Activity
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.WindowManager import android.view.WindowManager
import android.widget.CompoundButton import android.widget.CompoundButton
@ -78,9 +77,7 @@ class MigrationBottomSheetDialog(
initPreferences() initPreferences()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
window?.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) window?.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
}
fab.setOnClickListener { fab.setOnClickListener {
preferences.skipPreMigration().set(skip_step.isChecked) preferences.skipPreMigration().set(skip_step.isChecked)

View File

@ -57,9 +57,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) :
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && preferences.readerTheme() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && preferences.readerTheme()
.getOrDefault() == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0 .getOrDefault() == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0
) window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR ) window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
val height = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
} else 0
sheetBehavior.peekHeight = 200.dpToPx + height sheetBehavior.peekHeight = 200.dpToPx + height
sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {

View File

@ -5,10 +5,10 @@ import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import uy.kohesive.injekt.injectLazy
import java.text.DateFormat import java.text.DateFormat
import java.text.DecimalFormat import java.text.DecimalFormat
import java.text.DecimalFormatSymbols import java.text.DecimalFormatSymbols
import uy.kohesive.injekt.injectLazy
/** /**
* Adapter of RecentlyReadHolder. * Adapter of RecentlyReadHolder.
@ -48,6 +48,6 @@ FlexibleAdapter<IFlexible<*>>(null, controller, true) {
} }
interface OnCoverClickListener { interface OnCoverClickListener {
fun onCoverClick(position: Int, lastTouchY: Float) fun onCoverClick(position: Int)
} }
} }

View File

@ -181,7 +181,7 @@ class RecentlyReadController(bundle: Bundle? = null) : BaseController(bundle),
RemoveHistoryDialog(this, manga, history).showDialog(router) RemoveHistoryDialog(this, manga, history).showDialog(router)
} }
override fun onCoverClick(position: Int, lastTouchY: Float) { override fun onCoverClick(position: Int) {
val manga = (adapter?.getItem(position) as? RecentlyReadItem)?.mch?.manga ?: return val manga = (adapter?.getItem(position) as? RecentlyReadItem)?.mch?.manga ?: return
router.pushController(MangaDetailsController(manga).withFadeTransaction()) router.pushController(MangaDetailsController(manga).withFadeTransaction())
} }

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.ui.recently_read package eu.kanade.tachiyomi.ui.recently_read
import android.os.Build
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
@ -9,9 +8,9 @@ import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.lang.toTimestampString import eu.kanade.tachiyomi.util.lang.toTimestampString
import kotlinx.android.synthetic.main.recently_read_item.*
import java.util.Date import java.util.Date
import kotlin.math.max import kotlin.math.max
import kotlinx.android.synthetic.main.recently_read_item.*
/** /**
* Holder that contains recent manga item * Holder that contains recent manga item
@ -27,7 +26,6 @@ class RecentlyReadHolder(
val adapter: RecentlyReadAdapter val adapter: RecentlyReadAdapter
) : BaseFlexibleViewHolder(view, adapter) { ) : BaseFlexibleViewHolder(view, adapter) {
private var lastTouchUpY = 0f
init { init {
remove.setOnClickListener { remove.setOnClickListener {
adapter.removeClickListener.onRemoveClick(adapterPosition) adapter.removeClickListener.onRemoveClick(adapterPosition)
@ -38,17 +36,7 @@ class RecentlyReadHolder(
} }
cover.setOnClickListener { cover.setOnClickListener {
adapter.coverClickListener.onCoverClick(adapterPosition, lastTouchUpY) adapter.coverClickListener.onCoverClick(adapterPosition)
}
cover.setOnTouchListener { v, event ->
when (event?.action) {
MotionEvent.ACTION_UP -> {
val topH = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
v.rootWindowInsets.systemWindowInsetTop else 38
lastTouchUpY = max(topH + 175f, event.rawY - topH - 154f)
}
}
false
} }
} }

View File

@ -121,8 +121,7 @@ class WebViewActivity : BaseActivity() {
if (Build.VERSION.SDK_INT >= 26 && currentNightMode == Configuration.UI_MODE_NIGHT_NO) { if (Build.VERSION.SDK_INT >= 26 && currentNightMode == Configuration.UI_MODE_NIGHT_NO) {
content.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR content.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && currentNightMode == Configuration if (currentNightMode == Configuration.UI_MODE_NIGHT_NO && preferences.theme() >= 8)
.UI_MODE_NIGHT_NO && preferences.theme() >= 8)
content.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR content.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
insets insets
} }
@ -215,7 +214,7 @@ class WebViewActivity : BaseActivity() {
web_linear_layout.systemUiVisibility = web_linear_layout.systemUiVisibility.or(View web_linear_layout.systemUiVisibility = web_linear_layout.systemUiVisibility.or(View
.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) .SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR)
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && lightMode && preferences.theme() >= 8) if (lightMode && preferences.theme() >= 8)
web_linear_layout.systemUiVisibility = web_linear_layout.systemUiVisibility web_linear_layout.systemUiVisibility = web_linear_layout.systemUiVisibility
.or(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) .or(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
invalidateOptionsMenu() invalidateOptionsMenu()

View File

@ -35,11 +35,11 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import kotlin.math.abs
import kotlin.math.min
import kotlinx.android.synthetic.main.main_activity.* import kotlinx.android.synthetic.main.main_activity.*
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import kotlin.math.abs
import kotlin.math.min
/** /**
* Returns coordinates of view. * Returns coordinates of view.
@ -391,13 +391,13 @@ fun BottomSheetDialog.setEdgeToEdge(
contentView: View, contentView: View,
setTopMargin: Boolean setTopMargin: Boolean
) { ) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) window?.setBackgroundDrawable(null) window?.setBackgroundDrawable(null)
val currentNightMode = val currentNightMode =
activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0) window?.decorView?.systemUiVisibility = if (activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0) window?.decorView?.systemUiVisibility =
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && layout is ConstraintLayout) { } else if (layout is ConstraintLayout) {
val nView = View(context) val nView = View(context)
val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
val params = ConstraintLayout.LayoutParams( val params = ConstraintLayout.LayoutParams(
@ -414,25 +414,19 @@ fun BottomSheetDialog.setEdgeToEdge(
) )
layout.addView(nView) layout.addView(nView)
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { window?.findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows =
// window?.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) false
window?.findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows = contentView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
false if (setTopMargin) topMargin =
contentView.updateLayoutParams<ViewGroup.MarginLayoutParams> { activity.window.decorView.rootWindowInsets.systemWindowInsetTop
if (setTopMargin) topMargin = leftMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetLeft
activity.window.decorView.rootWindowInsets.systemWindowInsetTop rightMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetRight
leftMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetLeft
rightMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetRight
}
} }
} }
fun setBottomEdge(view: View, activity: Activity) { fun setBottomEdge(view: View, activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val marginB = view.marginBottom
val marginB = view.marginBottom view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
view.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin = marginB + activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
bottomMargin =
marginB + activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
}
} }
} }