Skip to content

Commit

Permalink
Merge pull request #842 from NUmeroAndDev/update_target_sdk
Browse files Browse the repository at this point in the history
Bump target sdk version to 33
  • Loading branch information
takahirom authored Oct 4, 2022
2 parents 30adf56 + 99ea17a commit 59bb7e4
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
package io.github.droidkaigi.confsched2022

import android.content.pm.PackageManager
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.core.content.ContextCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import dagger.hilt.android.AndroidEntryPoint
import io.github.droidkaigi.confsched2022.strings.Strings
import android.Manifest as AndroidManifest

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

private val requestPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
if (!isGranted) {
Toast.makeText(
this,
getString(Strings.notification_not_granted_message.resourceId),
Toast.LENGTH_LONG
).show()
}
}

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)

askNotificationPermissionIfNeeded()

WindowCompat.setDecorFitsSystemWindows(window, false)
window.statusBarColor = Color.TRANSPARENT
window.navigationBarColor =
Expand All @@ -40,4 +62,25 @@ class MainActivity : AppCompatActivity() {
)
}
}

private fun askNotificationPermissionIfNeeded() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) return
if (
ContextCompat.checkSelfPermission(
this,
AndroidManifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
) {
// can post notifications
} else if (
shouldShowRequestPermissionRationale(AndroidManifest.permission.POST_NOTIFICATIONS)
) {
/*
* display an educational UI explaining to the user the features that will be enabled
* by them granting the POST_NOTIFICATION permission if needed.
*/
} else {
requestPermissionLauncher.launch(AndroidManifest.permission.POST_NOTIFICATIONS)
}
}
}
2 changes: 1 addition & 1 deletion core/model/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<string name="notification_title_session_start">マイセッション開始のお知らせ</string>
<string name="notification_message_session_title">%1$s がもうすぐ始まります。</string>
<string name="notification_message_session_start_time">%1$s - %2$s @ %3$s</string>

<string name="notification_not_granted_message">通知を受け取るには通知の権限を許可してください</string>

<!-- Error -->
<string name="error_common_message">情報の取得に失敗しました</string>
Expand Down
2 changes: 1 addition & 1 deletion core/model/src/commonMain/resources/MR/en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<string name="notification_title_session_start">Notice of favorite session start</string>
<string name="notification_message_session_title">%1$s will start soon</string>
<string name="notification_message_session_start_time">%1$s - %2$s @ %3$s</string>

<string name="notification_not_granted_message">Please allow notification permissions to receive notifications</string>


<!-- Error -->
Expand Down
1 change: 1 addition & 0 deletions core/model/src/commonMain/resources/MR/zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<string name="notification_title_session_start">Notice of favorite session start</string>
<string name="notification_message_session_title">%1$s will start soon</string>
<string name="notification_message_session_start_time">%1$s - %2$s @ %3$s</string>
<string name="notification_not_granted_message">Please allow notification permissions to receive notifications</string>

<!-- Error -->
<!-- TODO:Translation into Chinese -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.github.droidkaigi.confsched2022.feature.about

import android.content.Context
import android.content.pm.PackageManager.PackageInfoFlags
import android.net.Uri
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -304,11 +307,18 @@ private fun ExternalServiceImage(
}

private fun versionName(context: Context) = runCatching {
context.packageManager
.getPackageInfo(
val info = if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
context.packageManager.getPackageInfo(
context.packageName,
PackageInfoFlags.of(0)
)
} else {
context.packageManager.getPackageInfo(
context.packageName,
0
).versionName
)
}
info.versionName
}.getOrNull()

@Preview(showBackground = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ fun Project.setupAndroid() {
}
}

defaultConfig.targetSdk = 32
defaultConfig.targetSdk = 33
}
}

0 comments on commit 59bb7e4

Please sign in to comment.