mirror of
https://github.com/Shabinder/SpotiFlyer.git
synced 2024-11-22 17:14:32 +01:00
Dialog Fixes and Update Notification Fixes
This commit is contained in:
parent
ae96e37ba2
commit
1c0b8fd2db
@ -35,6 +35,10 @@ import org.matomo.sdk.TrackerBuilder
|
||||
|
||||
class App: Application(), KoinComponent {
|
||||
|
||||
companion object {
|
||||
const val SIGNATURE_HEX = "53304f6d75736a2f30484230334c454b714753525763724259444d3d0a"
|
||||
}
|
||||
|
||||
val tracker: Tracker by lazy {
|
||||
TrackerBuilder.createDefault(
|
||||
"https://kind-grasshopper-73.telebit.io/matomo/matomo.php", 1)
|
||||
|
@ -124,9 +124,13 @@ class MainActivity : ComponentActivity() {
|
||||
var askForAnalyticsPermission by remember { mutableStateOf(false) }
|
||||
AnalyticsDialog(
|
||||
askForAnalyticsPermission,
|
||||
dir::enableAnalytics,
|
||||
enableAnalytics = {
|
||||
dir.enableAnalytics()
|
||||
dir.firstLaunchDone()
|
||||
},
|
||||
dismissDialog = {
|
||||
askForAnalyticsPermission = false
|
||||
dir.firstLaunchDone()
|
||||
}
|
||||
)
|
||||
|
||||
@ -136,7 +140,6 @@ class MainActivity : ComponentActivity() {
|
||||
delay(2500)
|
||||
// Ask For Analytics Permission on first Dialog
|
||||
askForAnalyticsPermission = true
|
||||
dir.firstLaunchDone()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -147,12 +150,20 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
private fun initialise() {
|
||||
checkIfLatestVersion()
|
||||
handleIntentFromExternalActivity()
|
||||
if(dir.isAnalyticsEnabled){
|
||||
// Download/App Install Event
|
||||
val isGithubRelease = checkAppSignature(this).also {
|
||||
Log.i("SpotiFlyer Github Rel.:",it.toString())
|
||||
}
|
||||
/*
|
||||
* 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)
|
||||
}
|
||||
handleIntentFromExternalActivity()
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
@ -3,6 +3,9 @@ package com.shabinder.spotiflyer.ui
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
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.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
@ -13,6 +16,7 @@ import androidx.compose.material.Icon
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.TextButton
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Close
|
||||
import androidx.compose.material.icons.rounded.Insights
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
@ -38,10 +42,17 @@ fun AnalyticsDialog(
|
||||
AlertDialog(
|
||||
onDismissRequest = dismissDialog,
|
||||
title = {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(Icons.Rounded.Insights,"Analytics", Modifier.size(52.dp))
|
||||
Spacer(Modifier.padding(horizontal = 4.dp))
|
||||
Row(verticalAlignment = Alignment.CenterVertically,horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
Icon(Icons.Rounded.Insights,"Analytics", Modifier.size(32.dp))
|
||||
Spacer(Modifier.padding(horizontal = 8.dp))
|
||||
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,
|
||||
@ -61,7 +72,7 @@ fun AnalyticsDialog(
|
||||
text = {
|
||||
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)
|
||||
)
|
||||
}
|
||||
}
|
@ -104,7 +104,7 @@ fun PermissionDialog(
|
||||
)
|
||||
}
|
||||
}
|
||||
Row(
|
||||
/*Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
@ -120,7 +120,7 @@ fun PermissionDialog(
|
||||
style = SpotiFlyerTypography.subtitle2,
|
||||
)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user