Skip to content

Commit 7266455

Browse files
authored
Merge pull request libre-tube#7047 from Pittvandewitt/feat/bump-minsdk
BREAKING CHANGE: bump minSdk to 26
2 parents 3a09869 + 8816e61 commit 7266455

61 files changed

Lines changed: 42 additions & 558 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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 & 12 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,8 +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)
33-
updateResourcesLegacy(context, locale)
31+
updateResources(context, locale)
3432
}
3533

3634
private fun updateResources(context: Context, locale: Locale) {
@@ -40,15 +38,6 @@ object LocaleHelper {
4038
context.createConfigurationContext(configuration)
4139
}
4240

43-
@Suppress("DEPRECATION")
44-
private fun updateResourcesLegacy(context: Context, locale: Locale) {
45-
Locale.setDefault(locale)
46-
val resources = context.resources
47-
val configuration = resources.configuration
48-
configuration.locale = locale
49-
resources.updateConfiguration(configuration, resources.displayMetrics)
50-
}
51-
5241
private fun getDetectedCountry(context: Context): String {
5342
return detectSIMCountry(context)
5443
?: detectNetworkCountry(context)

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
@@ -742,27 +742,23 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
742742
DownloadHelper.startDownloadDialog(requireContext(), childFragmentManager, videoId)
743743
}
744744

745-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
746-
binding.relPlayerScreenshot.setOnClickListener {
747-
if (!this::streams.isInitialized) return@setOnClickListener
748-
val surfaceView =
749-
binding.player.videoSurfaceView as? SurfaceView ?: return@setOnClickListener
750-
751-
val bmp = Bitmap.createBitmap(
752-
surfaceView.width,
753-
surfaceView.height,
754-
Bitmap.Config.ARGB_8888
755-
)
745+
binding.relPlayerScreenshot.setOnClickListener {
746+
if (!this::streams.isInitialized) return@setOnClickListener
747+
val surfaceView =
748+
binding.player.videoSurfaceView as? SurfaceView ?: return@setOnClickListener
756749

757-
PixelCopy.request(surfaceView, bmp, { _ ->
758-
screenshotBitmap = bmp
759-
val currentPosition =
760-
playerController.currentPosition.toFloat() / 1000
761-
openScreenshotFile.launch("${streams.title}-${currentPosition}.png")
762-
}, Handler(Looper.getMainLooper()))
763-
}
764-
} else {
765-
binding.relPlayerScreenshot.isGone = true
750+
val bmp = Bitmap.createBitmap(
751+
surfaceView.width,
752+
surfaceView.height,
753+
Bitmap.Config.ARGB_8888
754+
)
755+
756+
PixelCopy.request(surfaceView, bmp, { _ ->
757+
screenshotBitmap = bmp
758+
val currentPosition =
759+
playerController.currentPosition.toFloat() / 1000
760+
openScreenshotFile.launch("${streams.title}-${currentPosition}.png")
761+
}, Handler(Looper.getMainLooper()))
766762
}
767763

768764
binding.playerChannel.setOnClickListener {

0 commit comments

Comments
 (0)