Skip to content

Commit

Permalink
feat(java): add support from Android 21 (instead of 24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Sep 26, 2023
1 parent b4a37f9 commit 119f853
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 14 deletions.
2 changes: 2 additions & 0 deletions config/android-uploader.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
changelog:
- 1.3.2 (2023-09-26):
- Extend Android minSdkVersion to 21
- 1.3.1 (2023-08-22):
- Fix cancellation of upload workers for the WorkManager API
- 1.3.0 (2023-08-21):
Expand Down
2 changes: 2 additions & 0 deletions config/android.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
changelog:
- 1.5.2 (2023-09-26):
- Extend Android minSdkVersion to 21
- 1.5.1 (2023-08-22):
- Fix cancellation of upload workers for the WorkManager API
- 1.5.0 (2023-08-21):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import android.content.Context
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat

fun NotificationCompat.Builder.setStyle(
context: Context,
@DrawableRes notificationIconResourceId: Int,
@ColorRes notificationColorResourceId: Int
): NotificationCompat.Builder = apply {
setSmallIcon(notificationIconResourceId)
color = context.getColor(notificationColorResourceId)
color = ContextCompat.getColor(context, notificationColorResourceId)
}
2 changes: 1 addition & 1 deletion templates/java/libraries/okhttp-gson/build.gradle.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if(hasProperty('target') && target == 'android') {
compileSdkVersion 33
buildToolsVersion '30.0.3'
defaultConfig {
minSdkVersion 24
minSdkVersion 21
targetSdkVersion 33
multiDexEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {

defaultConfig {
applicationId "video.api.uploader.service.example"
minSdk 24
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ class ReadStorePermissionManager(
} else {
android.Manifest.permission.READ_EXTERNAL_STORAGE
}

private val hasPermission: Boolean
get() = activity.checkSelfPermission(requiredPermission) == PackageManager.PERMISSION_GRANTED
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.checkSelfPermission(requiredPermission) == PackageManager.PERMISSION_GRANTED
} else {
true
}

fun requestPermission() {
if (hasPermission) {
onGranted()
} else {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
throw IllegalStateException("Permission should be granted")
}
if (activity.shouldShowRequestPermissionRationale(requiredPermission)) {
onShowPermissionRationale(requiredPermission) {
requestPermission.launch(requiredPermission)
Expand All @@ -41,4 +49,4 @@ class ReadStorePermissionManager(
onDenied()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {

defaultConfig {
applicationId "video.api.uploader.work.example"
minSdkVersion 24
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ class ReadStorePermissionManager(
} else {
android.Manifest.permission.READ_EXTERNAL_STORAGE
}

private val hasPermission: Boolean
get() = activity.checkSelfPermission(requiredPermission) == PackageManager.PERMISSION_GRANTED
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.checkSelfPermission(requiredPermission) == PackageManager.PERMISSION_GRANTED
} else {
true
}

fun requestPermission() {
if (hasPermission) {
onGranted()
} else {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
throw IllegalStateException("Permission should be granted")
}
if (activity.shouldShowRequestPermissionRationale(requiredPermission)) {
onShowPermissionRationale(requiredPermission) {
requestPermission.launch(requiredPermission)
Expand All @@ -41,4 +49,4 @@ class ReadStorePermissionManager(
onDenied()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {

defaultConfig {
applicationId "video.api.client.service.example"
minSdkVersion 24
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ class ReadStorePermissionManager(
} else {
android.Manifest.permission.READ_EXTERNAL_STORAGE
}

private val hasPermission: Boolean
get() = activity.checkSelfPermission(requiredPermission) == PackageManager.PERMISSION_GRANTED
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.checkSelfPermission(requiredPermission) == PackageManager.PERMISSION_GRANTED
} else {
true
}

fun requestPermission() {
if (hasPermission) {
onGranted()
} else {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
throw IllegalStateException("Permission should be granted")
}
if (activity.shouldShowRequestPermissionRationale(requiredPermission)) {
onShowPermissionRationale(requiredPermission) {
requestPermission.launch(requiredPermission)
Expand All @@ -41,4 +49,4 @@ class ReadStorePermissionManager(
onDenied()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {

defaultConfig {
applicationId "video.api.client.work.example"
minSdkVersion 24
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ class ReadStorePermissionManager(
} else {
android.Manifest.permission.READ_EXTERNAL_STORAGE
}

private val hasPermission: Boolean
get() = activity.checkSelfPermission(requiredPermission) == PackageManager.PERMISSION_GRANTED
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.checkSelfPermission(requiredPermission) == PackageManager.PERMISSION_GRANTED
} else {
true
}

fun requestPermission() {
if (hasPermission) {
onGranted()
} else {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
throw IllegalStateException("Permission should be granted")
}
if (activity.shouldShowRequestPermissionRationale(requiredPermission)) {
onShowPermissionRationale(requiredPermission) {
requestPermission.launch(requiredPermission)
Expand All @@ -41,4 +49,4 @@ class ReadStorePermissionManager(
onDenied()
}
}
}
}

0 comments on commit 119f853

Please sign in to comment.