Skip to content

Commit

Permalink
Changelog Updated and Dialog Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shabinder committed May 16, 2021
1 parent a780d03 commit 6461603
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 42 deletions.
25 changes: 21 additions & 4 deletions android/src/main/java/com/shabinder/spotiflyer/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import com.shabinder.common.root.SpotiFlyerRoot
import com.shabinder.common.root.SpotiFlyerRoot.Analytics
import com.shabinder.common.root.callbacks.SpotiFlyerRootCallBacks
import com.shabinder.common.uikit.*
import com.shabinder.spotiflyer.ui.AnalyticsDialog
import com.shabinder.spotiflyer.ui.NetworkDialog
import com.shabinder.spotiflyer.ui.PermissionDialog
import com.shabinder.spotiflyer.utils.*
Expand Down Expand Up @@ -112,16 +113,32 @@ class MainActivity : ComponentActivity() {
)
}

LaunchedEffect(view) {
permissionGranted.value = checkPermissions()
}
NetworkDialog(isInternetAvailableState())

PermissionDialog(
permissionGranted.value,
{ requestStoragePermission() },
{ disableDozeMode(disableDozeCode) },
dir::enableAnalytics
)

var askForAnalyticsPermission by remember { mutableStateOf(false) }
AnalyticsDialog(
askForAnalyticsPermission,
dir::enableAnalytics,
dismissDialog = {
askForAnalyticsPermission = false
}
)

LaunchedEffect(view) {
permissionGranted.value = checkPermissions()
if(dir.isFirstLaunch) {
delay(2500)
// Ask For Analytics Permission on first Dialog
askForAnalyticsPermission = true
dir.firstLaunchDone()
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.shabinder.spotiflyer.ui

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.AlertDialog
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.Insights
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.DialogProperties
import com.shabinder.common.uikit.SpotiFlyerShapes
import com.shabinder.common.uikit.SpotiFlyerTypography
import com.shabinder.common.uikit.colorPrimary

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun AnalyticsDialog(
isVisible:Boolean,
enableAnalytics: ()->Unit,
dismissDialog: () -> Unit,
) {
// Analytics Permission Dialog
AnimatedVisibility(isVisible) {
AlertDialog(
onDismissRequest = dismissDialog,
title = {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(Icons.Rounded.Insights,"Analytics", Modifier.size(52.dp))
Spacer(Modifier.padding(horizontal = 4.dp))
Text("Grant Analytics Access",style = SpotiFlyerTypography.h5,textAlign = TextAlign.Center)
}
},
backgroundColor = Color.DarkGray,
buttons = {
TextButton(
{
dismissDialog()
enableAnalytics()
},
Modifier.padding(bottom = 16.dp, start = 16.dp, end = 16.dp).fillMaxWidth()
.background(colorPrimary, shape = SpotiFlyerShapes.medium)
.padding(horizontal = 8.dp),
) {
Text("Sure!",color = Color.Black,fontSize = 18.sp,textAlign = TextAlign.Center)
}
},
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)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,49 +42,13 @@ fun PermissionDialog(
permissionGranted: Boolean,
requestStoragePermission:() -> Unit,
disableDozeMode:() -> Unit,
enableAnalytics:() -> Unit
){
var askForPermission by remember { mutableStateOf(false) }
LaunchedEffect(Unit) {
delay(2000)
delay(2600)
askForPermission = true
}

// Analytics Permission Dialog
var askForAnalyticsPermission by remember { mutableStateOf(false) }
AnimatedVisibility(askForAnalyticsPermission) {
AlertDialog(
onDismissRequest = {
askForAnalyticsPermission = false
},
title = {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(Icons.Rounded.Insights,"Analytics",Modifier.size(52.dp))
Spacer(Modifier.padding(horizontal = 4.dp))
Text("Grant Analytics Access",style = SpotiFlyerTypography.h5,textAlign = TextAlign.Center)
}
},
backgroundColor = Color.DarkGray,
buttons = {
TextButton(
{
askForAnalyticsPermission = false
enableAnalytics()
},
Modifier.padding(bottom = 16.dp, start = 16.dp, end = 16.dp).fillMaxWidth()
.background(colorPrimary, shape = SpotiFlyerShapes.medium)
.padding(horizontal = 8.dp),
) {
Text("Sure!",color = Color.Black,fontSize = 18.sp,textAlign = TextAlign.Center)
}
},
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)
)
}

AnimatedVisibility(
askForPermission && !permissionGranted
) {
Expand All @@ -95,7 +59,6 @@ fun PermissionDialog(
{
requestStoragePermission()
disableDozeMode()
askForAnalyticsPermission = true
},
Modifier.padding(bottom = 16.dp, start = 16.dp, end = 16.dp).fillMaxWidth()
.background(colorPrimary, shape = SpotiFlyerShapes.medium)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ actual class Dir actual constructor(
companion object {
const val DirKey = "downloadDir"
const val AnalyticsKey = "analytics"
const val firstLaunch = "firstLaunch"
}

actual val isFirstLaunch get() = settings.getBooleanOrNull(firstLaunch) ?: true

actual fun firstLaunchDone(){
settings.putBoolean(firstLaunch,false)
}

/*
* Do we have Analytics Permission?
* - Defaults to `False`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ expect class Dir (
) {
val db: Database?
val isAnalyticsEnabled:Boolean
val isFirstLaunch:Boolean
fun enableAnalytics()
fun firstLaunchDone()
fun isPresent(path: String): Boolean
fun fileSeparator(): String
fun defaultDir(): String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@ actual class Dir actual constructor(
private val settings: Settings,
private val spotiFlyerDatabase: SpotiFlyerDatabase,
) {

companion object {
const val DirKey = "downloadDir"
const val AnalyticsKey = "analytics"
const val firstLaunch = "firstLaunch"
}

actual val isFirstLaunch get() = settings.getBooleanOrNull(firstLaunch) ?: true

actual fun firstLaunchDone(){
settings.putBoolean(firstLaunch,false)
}

actual val isAnalyticsEnabled get() = settings.getBooleanOrNull(AnalyticsKey) ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ actual class Dir actual constructor(
companion object {
const val DirKey = "downloadDir"
const val AnalyticsKey = "analytics"
const val firstLaunch = "firstLaunch"
}

actual val isFirstLaunch get() = settings.getBooleanOrNull(firstLaunch) ?: true

actual fun firstLaunchDone() {
settings.putBoolean(firstLaunch,false)
}

actual val isAnalyticsEnabled get() = settings.getBooleanOrNull(AnalyticsKey) ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ actual class Dir actual constructor(
companion object {
const val DirKey = "downloadDir"
const val AnalyticsKey = "analytics"
const val firstLaunch = "firstLaunch"
}

actual val isFirstLaunch get() = settings.getBooleanOrNull(firstLaunch) ?: true

actual fun firstLaunchDone() {
settings.putBoolean(firstLaunch,false)
}

actual val isAnalyticsEnabled get() = settings.getBooleanOrNull(AnalyticsKey) ?: false
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/19.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- F-Droid Initial Release.
- Size Reduced to 4.9 MB (14% smalled than previous apk).
- Firebase Analytics/Crashlytics Removed, Self-Hosted Alternatives Used (100% Open Source).
- Dependencies Updated.

0 comments on commit 6461603

Please sign in to comment.