From a36f42e043cfc84375009a535f42732f120ff42f Mon Sep 17 00:00:00 2001 From: AkosPaha Date: Sun, 11 Dec 2022 22:54:42 +0100 Subject: [PATCH] Fix Download of Update and Request Notification Permissions --- app/build.gradle.kts | 4 +- app/src/main/AndroidManifest.xml | 7 ++- .../rboardthememanager/preferences/Repos.kt | 16 ++----- .../screens/InstallPackActivity.kt | 1 - .../screens/MainActivity.kt | 11 +++-- .../rboardthememanager/utils/AppStartUp.kt | 43 +++++++++++++------ 6 files changed, 49 insertions(+), 33 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1af236c1..7facdc5a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -23,8 +23,8 @@ android { applicationId = "de.dertyp7214.rboardthememanager" minSdk = 23 targetSdk = 33 - versionCode = 373000 - versionName = "3.7.3" + versionCode = 374000 + versionName = "3.7.4" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f120e2d0..a13200c0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,6 +8,7 @@ tools:ignore="ScopedStorage" /> + @@ -96,7 +97,8 @@ android:exported="true" android:screenOrientation="portrait" android:theme="@style/Theme.RboardThemeManagerV3.Main" - android:windowSoftInputMode="adjustNothing"> + android:windowSoftInputMode="adjustNothing" + tools:ignore="LockedOrientationActivity"> @@ -180,7 +182,8 @@ android:name=".services.AppThemeService" android:enabled="true" android:exported="true" - android:process=":remote"> + android:process=":remote" + tools:ignore="ExportedService"> diff --git a/app/src/main/java/de/dertyp7214/rboardthememanager/preferences/Repos.kt b/app/src/main/java/de/dertyp7214/rboardthememanager/preferences/Repos.kt index c6b13dd9..a64de9e3 100644 --- a/app/src/main/java/de/dertyp7214/rboardthememanager/preferences/Repos.kt +++ b/app/src/main/java/de/dertyp7214/rboardthememanager/preferences/Repos.kt @@ -45,7 +45,7 @@ class Repos( doAsync({ it.toList().map { url -> url.parseRepo() } }, { data -> - repositories.addAll(data.filterNotNull()) + repositories.addAll(data) onRequestReload() }) } @@ -113,17 +113,9 @@ class Repos( activity.openInputDialog(R.string.repository) { dialog, text -> doAsync("true:$text"::parseRepo) { dialog.dismiss() - if (it != null) { - repositories.add(it) - onRequestReload() - modified = true - } else activity.openDialog( - R.string.invalid_repo_long, - R.string.invalid_repo, - false, - ::dismiss, - ::dismiss - ) + repositories.add(it) + onRequestReload() + modified = true } } } diff --git a/app/src/main/java/de/dertyp7214/rboardthememanager/screens/InstallPackActivity.kt b/app/src/main/java/de/dertyp7214/rboardthememanager/screens/InstallPackActivity.kt index 1623097e..fef23b24 100644 --- a/app/src/main/java/de/dertyp7214/rboardthememanager/screens/InstallPackActivity.kt +++ b/app/src/main/java/de/dertyp7214/rboardthememanager/screens/InstallPackActivity.kt @@ -87,7 +87,6 @@ class InstallPackActivity : AppCompatActivity() { val path = file.absolutePath val imageFile = SuFile(file.absolutePath.removeSuffix(".zip")) val image = imageFile.exists().let { - Log.d("IMAGE", "$it $name") if (it) { imageFile.decodeBitmap() } else null diff --git a/app/src/main/java/de/dertyp7214/rboardthememanager/screens/MainActivity.kt b/app/src/main/java/de/dertyp7214/rboardthememanager/screens/MainActivity.kt index a1257827..98add433 100644 --- a/app/src/main/java/de/dertyp7214/rboardthememanager/screens/MainActivity.kt +++ b/app/src/main/java/de/dertyp7214/rboardthememanager/screens/MainActivity.kt @@ -720,11 +720,14 @@ class MainActivity : AppCompatActivity() { this@MainActivity.intent.getBooleanExtra("update", false) ) ) { - openDialog(R.string.update_ready, R.string.update) { update() } + openDialog( + R.string.update_ready, + R.string.update + ) { update(intent.getStringExtra("versionName") ?: "3.7.3") } } } - private fun update() { + private fun update(versionName: String) { val maxProgress = 100 val notificationId = 42069 val builder = @@ -740,8 +743,8 @@ class MainActivity : AppCompatActivity() { notify(this, notificationId, builder.build()) } var finished = false - val versionName = this.intent.getStringExtra("versionName") ?: "3.7.1" - val url = if (URL(updateUrl(versionName)).isReachable()) updateUrl(versionName) else updateUrlGitlab + val url = + if (URL(Config.GITHUB_REPO_PREFIX).isReachable()) updateUrl(versionName) else updateUrlGitlab UpdateHelper(url, this).apply { addOnProgressListener { progress, bytes, total -> if (!finished) { diff --git a/app/src/main/java/de/dertyp7214/rboardthememanager/utils/AppStartUp.kt b/app/src/main/java/de/dertyp7214/rboardthememanager/utils/AppStartUp.kt index 8ebe243c..cdf7fc78 100644 --- a/app/src/main/java/de/dertyp7214/rboardthememanager/utils/AppStartUp.kt +++ b/app/src/main/java/de/dertyp7214/rboardthememanager/utils/AppStartUp.kt @@ -16,6 +16,7 @@ import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.core.animation.doOnEnd +import androidx.core.app.NotificationManagerCompat import androidx.core.content.FileProvider import androidx.core.content.edit import androidx.preference.PreferenceManager @@ -204,7 +205,12 @@ class AppStartUp(private val activity: AppCompatActivity) { } } - val initialized = preferences.getBoolean("initialized", false) + val notificationPermissionGranted = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) + NotificationManagerCompat.from(this).areNotificationsEnabled() + else true + val initialized = + preferences.getBoolean("initialized", false) && notificationPermissionGranted val scheme = intent.scheme val data = intent.data @@ -396,17 +402,8 @@ class AppStartUp(private val activity: AppCompatActivity) { FirebaseMessaging.getInstance() .subscribeToTopic("update-v3-r-${BuildConfig.BUILD_TYPE.lowercase()}") - isReady = !gboardInstalled || !rootAccess - when { - !gboardInstalled -> openDialog( - R.string.install_gboard, - R.string.gboard_not_installed - ) { - openUrl(gboardPlayStoreUrl) - finish() - } - !rootAccess -> NoRootDialog.open(this) - else -> checkForUpdate { update, versionName -> + val checkUpdate = { + checkForUpdate { update, versionName -> checkedForUpdate = true isReady = true validApp(this) { @@ -421,6 +418,28 @@ class AppStartUp(private val activity: AppCompatActivity) { } } } + + val pushNotificationPermissionLauncher = + activity.registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted -> + checkUpdate() + } + + isReady = !gboardInstalled || !rootAccess + when { + !gboardInstalled -> openDialog( + R.string.install_gboard, + R.string.gboard_not_installed + ) { + openUrl(gboardPlayStoreUrl) + } + + !rootAccess -> NoRootDialog.open(this) + !notificationPermissionGranted && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> pushNotificationPermissionLauncher.launch( + android.Manifest.permission.POST_NOTIFICATIONS + ) + + else -> checkUpdate() + } } } }