Skip to content

Commit 4adcbb9

Browse files
committed
Bump minSdk to 26
1 parent cde9bc3 commit 4adcbb9

12 files changed

Lines changed: 42 additions & 117 deletions

File tree

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ android {
1313

1414
defaultConfig {
1515
applicationId = "com.github.libretube"
16-
minSdk = 21
16+
minSdk = 26
1717
targetSdk = 34
1818
versionCode = 59
1919
versionName = "0.27.0"

app/src/main/java/com/github/libretube/compat/PictureInPictureCompat.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@ package com.github.libretube.compat
33
import android.app.Activity
44
import android.content.Context
55
import android.content.pm.PackageManager
6-
import android.os.Build
76

87
object PictureInPictureCompat {
9-
fun isPictureInPictureAvailable(context: Context): Boolean {
10-
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
11-
context.packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
12-
}
138

14-
fun isInPictureInPictureMode(activity: Activity): Boolean {
15-
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && activity.isInPictureInPictureMode
16-
}
9+
fun isPictureInPictureAvailable(context: Context) =
10+
context.packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
11+
12+
fun isInPictureInPictureMode(activity: Activity) = activity.isInPictureInPictureMode
1713

1814
fun setPictureInPictureParams(activity: Activity, params: PictureInPictureParamsCompat) {
1915
if (isPictureInPictureAvailable(activity)) {
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
package com.github.libretube.extensions
22

33
import android.icu.text.CompactDecimalFormat
4-
import android.os.Build
54
import com.github.libretube.helpers.LocaleHelper
6-
import kotlin.math.pow
75

8-
fun Long?.formatShort(): String {
9-
val value = this ?: 0
10-
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
11-
CompactDecimalFormat
12-
.getInstance(LocaleHelper.getAppLocale(), CompactDecimalFormat.CompactStyle.SHORT)
13-
.format(value)
14-
} else {
15-
val units = arrayOf("", "K", "M", "B", "T")
16-
for (i in units.size downTo 1) {
17-
val step = 1000.0.pow(i.toDouble())
18-
if (value > step) return "%3.0f%s".format(value / step, units[i]).trim()
19-
}
20-
value.toString()
21-
}
22-
}
6+
fun Long?.formatShort(): String = CompactDecimalFormat
7+
.getInstance(LocaleHelper.getAppLocale(), CompactDecimalFormat.CompactStyle.SHORT)
8+
.format(this ?: 0)
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
package com.github.libretube.helpers
22

33
import android.content.Context
4-
import android.os.Build
54
import androidx.core.content.ContextCompat
65

76
object DisplayHelper {
87
/**
98
* Detect whether the device supports HDR as the ExoPlayer doesn't handle it properly
109
* Returns false below SDK 24
1110
*/
12-
fun supportsHdr(context: Context): Boolean {
13-
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
14-
val display = ContextCompat.getDisplayOrDefault(context)
15-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
16-
display.isHdr
17-
} else {
18-
@Suppress("DEPRECATION")
19-
display.hdrCapabilities?.supportedHdrTypes?.isNotEmpty() ?: false
20-
}
21-
} else {
22-
false
23-
}
24-
}
11+
fun supportsHdr(context: Context) = ContextCompat.getDisplayOrDefault(context).isHdr
2512
}

app/src/main/java/com/github/libretube/helpers/DownloadHelper.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.github.libretube.helpers
22

33
import android.content.Context
44
import android.content.Intent
5-
import android.os.Build
65
import androidx.core.content.ContextCompat
76
import androidx.core.net.toUri
87
import androidx.core.os.bundleOf
@@ -40,15 +39,12 @@ object DownloadHelper {
4039
private const val VIDEO_MIMETYPE = "video/*"
4140

4241
fun getDownloadDir(context: Context, path: String): Path {
43-
val storageDir = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
44-
context.filesDir
45-
} else {
42+
val storageDir =
4643
try {
4744
context.getExternalFilesDir(null)!!
4845
} catch (e: Exception) {
4946
context.filesDir
5047
}
51-
}
5248
return (storageDir.toPath() / path).createDirectories()
5349
}
5450

app/src/main/java/com/github/libretube/helpers/LocaleHelper.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.github.libretube.helpers
22

33
import android.content.Context
44
import android.content.res.Configuration
5-
import android.os.Build
65
import android.telephony.TelephonyManager
76
import androidx.core.content.getSystemService
87
import androidx.core.os.ConfigurationCompat
@@ -29,7 +28,7 @@ object LocaleHelper {
2928

3029
fun updateLanguage(context: Context) {
3130
val locale = getAppLocale()
32-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) updateResources(context, locale)
31+
updateResources(context, locale)
3332
updateResourcesLegacy(context, locale)
3433
}
3534

app/src/main/java/com/github/libretube/helpers/NetworkHelper.kt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,20 @@ package com.github.libretube.helpers
33
import android.content.Context
44
import android.net.ConnectivityManager
55
import android.net.NetworkCapabilities
6-
import android.os.Build
76
import androidx.core.content.getSystemService
87

98
object NetworkHelper {
109
/**
1110
* Detect whether network is available
1211
*/
13-
@Suppress("DEPRECATION")
1412
fun isNetworkAvailable(context: Context): Boolean {
1513
// In case we are using a VPN, we return true since we might be using reverse tethering
1614
val connectivityManager = context.getSystemService<ConnectivityManager>() ?: return false
1715

18-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
19-
val activeNetwork = connectivityManager.activeNetwork
20-
val caps = connectivityManager.getNetworkCapabilities(activeNetwork) ?: return false
21-
return caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) ||
22-
caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN)
23-
} else {
24-
// activeNetworkInfo might return null instead of the VPN, so better check it explicitly
25-
val networkInfo = connectivityManager.activeNetworkInfo
26-
?: connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_VPN)
27-
return networkInfo?.isConnected == true
28-
}
16+
val activeNetwork = connectivityManager.activeNetwork
17+
val caps = connectivityManager.getNetworkCapabilities(activeNetwork) ?: return false
18+
return caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) ||
19+
caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN)
2920
}
3021

3122
/**

app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import android.content.Context
66
import android.content.pm.PackageManager
77
import android.content.res.Configuration
88
import android.graphics.Color
9-
import android.os.Build
109
import android.text.Spanned
1110
import android.view.Window
1211
import androidx.annotation.ColorInt
@@ -35,12 +34,7 @@ object ThemeHelper {
3534
* Set the background color of the status bar
3635
*/
3736
private fun setStatusBarColor(context: Context, window: Window) {
38-
window.statusBarColor =
39-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M && !isDarkMode(context)) {
40-
getThemeColor(context, com.google.android.material.R.attr.colorOnBackground)
41-
} else {
42-
getThemeColor(context, android.R.attr.colorBackground)
43-
}
37+
window.statusBarColor = getThemeColor(context, android.R.attr.colorBackground)
4438
WindowCompat.getInsetsController(window, window.decorView)
4539
.isAppearanceLightStatusBars = !isDarkMode(context)
4640
}
@@ -54,11 +48,7 @@ object ThemeHelper {
5448
@ColorInt bottomNavColor: Int?
5549
) {
5650
window.navigationBarColor =
57-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M && !isDarkMode(context)) {
58-
getThemeColor(context, com.google.android.material.R.attr.colorOnBackground)
59-
} else {
60-
bottomNavColor ?: getThemeColor(context, android.R.attr.colorBackground)
61-
}
51+
bottomNavColor ?: getThemeColor(context, android.R.attr.colorBackground)
6252
}
6353

6454
/**

app/src/main/java/com/github/libretube/ui/base/BaseActivity.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.github.libretube.ui.base
22

33
import android.content.pm.ActivityInfo
4-
import android.os.Build
54
import android.os.Bundle
65
import androidx.appcompat.app.AppCompatActivity
76
import com.github.libretube.R
@@ -40,11 +39,6 @@ open class BaseActivity : AppCompatActivity() {
4039
ThemeHelper.updateTheme(this)
4140
if (isDialogActivity) ThemeHelper.applyDialogActivityTheme(this)
4241

43-
// Set the navigation and statusBar color if SDK < 23
44-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
45-
ThemeHelper.setSystemBarColors(this, window)
46-
}
47-
4842
// set the apps language
4943
LocaleHelper.updateLanguage(this)
5044

app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -733,27 +733,23 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
733733
DownloadHelper.startDownloadDialog(requireContext(), childFragmentManager, videoId)
734734
}
735735

736-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
737-
binding.relPlayerScreenshot.setOnClickListener {
738-
if (!this::streams.isInitialized) return@setOnClickListener
739-
val surfaceView =
740-
binding.player.videoSurfaceView as? SurfaceView ?: return@setOnClickListener
741-
742-
val bmp = Bitmap.createBitmap(
743-
surfaceView.width,
744-
surfaceView.height,
745-
Bitmap.Config.ARGB_8888
746-
)
736+
binding.relPlayerScreenshot.setOnClickListener {
737+
if (!this::streams.isInitialized) return@setOnClickListener
738+
val surfaceView =
739+
binding.player.videoSurfaceView as? SurfaceView ?: return@setOnClickListener
747740

748-
PixelCopy.request(surfaceView, bmp, { _ ->
749-
screenshotBitmap = bmp
750-
val currentPosition =
751-
playerController.currentPosition.toFloat() / 1000
752-
openScreenshotFile.launch("${streams.title}-${currentPosition}.png")
753-
}, Handler(Looper.getMainLooper()))
754-
}
755-
} else {
756-
binding.relPlayerScreenshot.isGone = true
741+
val bmp = Bitmap.createBitmap(
742+
surfaceView.width,
743+
surfaceView.height,
744+
Bitmap.Config.ARGB_8888
745+
)
746+
747+
PixelCopy.request(surfaceView, bmp, { _ ->
748+
screenshotBitmap = bmp
749+
val currentPosition =
750+
playerController.currentPosition.toFloat() / 1000
751+
openScreenshotFile.launch("${streams.title}-${currentPosition}.png")
752+
}, Handler(Looper.getMainLooper()))
757753
}
758754

759755
binding.playerChannel.setOnClickListener {

0 commit comments

Comments
 (0)