Dialog Fixes and Update Notification Fixes

This commit is contained in:
Shabinder Singh 2021-05-29 15:56:26 +05:30
parent ae96e37ba2
commit 1c0b8fd2db
5 changed files with 81 additions and 12 deletions

View File

@ -35,6 +35,10 @@ import org.matomo.sdk.TrackerBuilder
class App: Application(), KoinComponent { class App: Application(), KoinComponent {
companion object {
const val SIGNATURE_HEX = "53304f6d75736a2f30484230334c454b714753525763724259444d3d0a"
}
val tracker: Tracker by lazy { val tracker: Tracker by lazy {
TrackerBuilder.createDefault( TrackerBuilder.createDefault(
"https://kind-grasshopper-73.telebit.io/matomo/matomo.php", 1) "https://kind-grasshopper-73.telebit.io/matomo/matomo.php", 1)

View File

@ -124,9 +124,13 @@ class MainActivity : ComponentActivity() {
var askForAnalyticsPermission by remember { mutableStateOf(false) } var askForAnalyticsPermission by remember { mutableStateOf(false) }
AnalyticsDialog( AnalyticsDialog(
askForAnalyticsPermission, askForAnalyticsPermission,
dir::enableAnalytics, enableAnalytics = {
dir.enableAnalytics()
dir.firstLaunchDone()
},
dismissDialog = { dismissDialog = {
askForAnalyticsPermission = false askForAnalyticsPermission = false
dir.firstLaunchDone()
} }
) )
@ -136,7 +140,6 @@ class MainActivity : ComponentActivity() {
delay(2500) delay(2500)
// Ask For Analytics Permission on first Dialog // Ask For Analytics Permission on first Dialog
askForAnalyticsPermission = true askForAnalyticsPermission = true
dir.firstLaunchDone()
} }
} }
} }
@ -147,12 +150,20 @@ class MainActivity : ComponentActivity() {
} }
private fun initialise() { private fun initialise() {
checkIfLatestVersion() val isGithubRelease = checkAppSignature(this).also {
handleIntentFromExternalActivity() Log.i("SpotiFlyer Github Rel.:",it.toString())
if(dir.isAnalyticsEnabled){ }
// Download/App Install Event /*
* Only Send an `Update Notification` on Github Release Builds
* and Track Downloads for all other releases like F-Droid,
* for `Github Downloads` we will track Downloads using : https://tooomm.github.io/github-release-stats/?username=Shabinder&repository=SpotiFlyer
* */
if(isGithubRelease) { checkIfLatestVersion() }
if(dir.isAnalyticsEnabled && !isGithubRelease) {
// Download/App Install Event for F-Droid builds
TrackHelper.track().download().with(tracker) TrackHelper.track().download().with(tracker)
} }
handleIntentFromExternalActivity()
} }
@Composable @Composable

View File

@ -3,6 +3,9 @@ package com.shabinder.spotiflyer.ui
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
@ -13,6 +16,7 @@ import androidx.compose.material.Icon
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.TextButton import androidx.compose.material.TextButton
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Close
import androidx.compose.material.icons.rounded.Insights import androidx.compose.material.icons.rounded.Insights
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -38,10 +42,17 @@ fun AnalyticsDialog(
AlertDialog( AlertDialog(
onDismissRequest = dismissDialog, onDismissRequest = dismissDialog,
title = { title = {
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically,horizontalArrangement = Arrangement.SpaceBetween) {
Icon(Icons.Rounded.Insights,"Analytics", Modifier.size(52.dp)) Icon(Icons.Rounded.Insights,"Analytics", Modifier.size(32.dp))
Spacer(Modifier.padding(horizontal = 4.dp)) Spacer(Modifier.padding(horizontal = 8.dp))
Text("Grant Analytics",style = SpotiFlyerTypography.h5,textAlign = TextAlign.Center) Text("Grant Analytics",style = SpotiFlyerTypography.h5,textAlign = TextAlign.Center)
Spacer(Modifier.padding(horizontal = 8.dp))
Column {
Icon(Icons.Rounded.Close,"Decline Analytics", Modifier.size(24.dp).clickable {
dismissDialog()
})
Spacer(Modifier.padding(vertical = 8.dp))
}
} }
}, },
backgroundColor = Color.DarkGray, backgroundColor = Color.DarkGray,
@ -61,7 +72,7 @@ fun AnalyticsDialog(
text = { text = {
Text("Your Data is Anonymized and will never be shared with any 3rd party service",style = SpotiFlyerTypography.body2,textAlign = TextAlign.Center) Text("Your Data is Anonymized and will never be shared with any 3rd party service",style = SpotiFlyerTypography.body2,textAlign = TextAlign.Center)
}, },
properties = DialogProperties(dismissOnBackPress = true,dismissOnClickOutside = false) properties = DialogProperties(dismissOnBackPress = false,dismissOnClickOutside = false)
) )
} }
} }

View File

@ -104,7 +104,7 @@ fun PermissionDialog(
) )
} }
} }
Row( /*Row(
modifier = Modifier.fillMaxWidth().padding(top = 6.dp), modifier = Modifier.fillMaxWidth().padding(top = 6.dp),
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
@ -120,7 +120,7 @@ fun PermissionDialog(
style = SpotiFlyerTypography.subtitle2, style = SpotiFlyerTypography.subtitle2,
) )
} }
} }*/
} }
} }
) )

View File

@ -0,0 +1,43 @@
package com.shabinder.spotiflyer.utils
import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.util.Base64
import android.util.Log
import com.shabinder.spotiflyer.App
import java.security.MessageDigest
@Suppress("DEPRECATION")
@SuppressLint("PackageManagerGetSignatures")
fun checkAppSignature(context: Context): Boolean {
try {
val packageInfo: PackageInfo =
context.packageManager.getPackageInfo(context.packageName, PackageManager.GET_SIGNATURES)
for (signature in packageInfo.signatures) {
val md: MessageDigest = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
val currentSignature: String = Base64.encodeToString(md.digest(), Base64.DEFAULT)
// Log.d("REMOVE_ME", "Include this string as a value for SIGNATURE:$currentSignature")
// Log.d("REMOVE_ME HEX", "Include this string as a value for SIGNATURE Hex:${currentSignature.toByteArray().toHEX()}")
//compare signatures
if (App.SIGNATURE_HEX == currentSignature.toByteArray().toHEX()) {
return true
}
}
} catch (e: Exception) {
e.printStackTrace()
//assumes an issue in checking signature., but we let the caller decide on what to do.
}
return false
}
fun ByteArray.toHEX(): String {
val builder = StringBuilder()
for (aByte in this) {
builder.append(String.format("%02x", aByte))
}
return builder.toString()
}