feat: support API 21 with compat

This commit is contained in:
TwistedUmbrellaX 2024-03-17 14:32:24 -04:00
parent c033bb0445
commit a8ad018c44
5 changed files with 35 additions and 20 deletions

View file

@ -11,7 +11,7 @@ android {
defaultConfig {
applicationId "ani.dantotsu"
minSdk 23
minSdk 21
targetSdk 34
versionCode((System.currentTimeMillis() / 60000).toInteger())
versionName "2.2.0"

View file

@ -244,6 +244,7 @@ fun isOnline(context: Context): Boolean {
val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
return tryWith {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val cap = connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
return@tryWith if (cap != null) {
when {
@ -259,6 +260,19 @@ fun isOnline(context: Context): Boolean {
else -> false
}
} else false
} else {
@Suppress("DEPRECATION")
return@tryWith connectivityManager.activeNetworkInfo?.run {
type == ConnectivityManager.TYPE_BLUETOOTH ||
type == ConnectivityManager.TYPE_ETHERNET ||
type == ConnectivityManager.TYPE_MOBILE ||
type == ConnectivityManager.TYPE_MOBILE_DUN ||
type == ConnectivityManager.TYPE_MOBILE_HIPRI ||
type == ConnectivityManager.TYPE_WIFI ||
type == ConnectivityManager.TYPE_WIMAX ||
type == ConnectivityManager.TYPE_VPN
} ?: false
}
} ?: false
}

View file

@ -214,7 +214,7 @@ class MainActivity : AppCompatActivity() {
binding.root.doOnAttach {
initActivity(this)
window.navigationBarColor = getColor(android.R.color.transparent)
window.navigationBarColor = ContextCompat.getColor(this, android.R.color.transparent)
selectedOption = if (fragment != null) {
when (fragment) {
AnimeFragment::class.java.name -> 0
@ -381,7 +381,7 @@ class MainActivity : AppCompatActivity() {
override fun onRestart() {
super.onRestart()
window.navigationBarColor = getColor(android.R.color.transparent)
window.navigationBarColor = ContextCompat.getColor(this, android.R.color.transparent)
}
private val Int.toPx get() = TypedValue.applyDimension(

View file

@ -5,6 +5,7 @@ import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import ani.dantotsu.R
import ani.dantotsu.databinding.ItemNovelResponseBinding
@ -59,11 +60,11 @@ class NovelResponseAdapter(
}
if (binding.itemEpisodeFiller.text.contains("Downloading")) {
binding.itemEpisodeFiller.setTextColor(
fragment.requireContext().getColor(android.R.color.holo_blue_light)
ContextCompat.getColor(fragment.requireContext(), android.R.color.holo_blue_light)
)
} else if (binding.itemEpisodeFiller.text.contains("Downloaded")) {
binding.itemEpisodeFiller.setTextColor(
fragment.requireContext().getColor(android.R.color.holo_green_light)
ContextCompat.getColor(fragment.requireContext(), android.R.color.holo_green_light)
)
} else {
binding.itemEpisodeFiller.setTextColor(color)

View file

@ -65,7 +65,7 @@ class ProfileFragment : Fragment() {
binding.profileUserBio.setInitialScale(1)
val styledHtml = getFullAniHTML(
user.about ?: "",
activity.getColor(R.color.bg_opp)
ContextCompat.getColor(activity, R.color.bg_opp)
)
binding.profileUserBio.loadDataWithBaseURL(
null,