Skip to content

Commit

Permalink
Fix Download of Update and Request Notification Permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
AkosPaha01 committed Dec 11, 2022
1 parent b7c3e16 commit a36f42e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 33 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
Expand Down Expand Up @@ -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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down Expand Up @@ -180,7 +182,8 @@
android:name=".services.AppThemeService"
android:enabled="true"
android:exported="true"
android:process=":remote">
android:process=":remote"
tools:ignore="ExportedService">
<intent-filter>
<action android:name="de.dertyp7214.rboard.IAppTheme" />
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Repos(
doAsync({
it.toList().map { url -> url.parseRepo() }
}, { data ->
repositories.addAll(data.filterNotNull())
repositories.addAll(data)
onRequestReload()
})
}
Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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()
}
}
}
}
Expand Down

0 comments on commit a36f42e

Please sign in to comment.