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 50f9146
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 14 deletions.
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 50f9146

Please sign in to comment.