Skip to content

Commit

Permalink
💄 Added UI elements for rating the app and feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartozo committed Nov 2, 2022
1 parent d5c805e commit ebfc7e7
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.outlined.Person
import androidx.compose.material.icons.outlined.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -20,6 +21,7 @@ import com.bartozo.lifeprogress.data.Life
import com.bartozo.lifeprogress.ui.components.*
import com.bartozo.lifeprogress.ui.theme.LifeProgressTheme
import com.bartozo.lifeprogress.ui.viewmodels.HomeViewModel
import com.bartozo.lifeprogress.util.sendMail

@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable
Expand Down Expand Up @@ -55,14 +57,26 @@ fun HomeScreen(
life.numberOfWeeksLeft
)
}
val context = LocalContext.current
val uriHandler = LocalUriHandler.current

Scaffold(
topBar = {
HomeTopBar(
title = title,
subtitle = subtitle,
navigateToProfileScreen = navigateToProfileScreen,
navigateToAboutScreen = navigateToAboutScreen
navigateToAboutScreen = navigateToAboutScreen,
onShareFeedbackPressed = {
context.sendMail(
to = "[email protected]",
subject = "Life Progress - Feedback",
onError = {}
)
},
onRateAppPressed = {
uriHandler.openUri("https://play.google.com/store/apps/details?id=com.bartozo.lifeprogress")
}
)
},
content = { innerPaddings ->
Expand Down Expand Up @@ -92,7 +106,9 @@ private fun HomeTopBar(
title: String,
subtitle: String,
navigateToProfileScreen: () -> Unit,
navigateToAboutScreen: () -> Unit
navigateToAboutScreen: () -> Unit,
onShareFeedbackPressed: () -> Unit,
onRateAppPressed: () -> Unit,
) {
Column {
LargeTopAppBar(
Expand All @@ -106,7 +122,9 @@ private fun HomeTopBar(
actions = {
NavigationDropDownMenu(
navigateToProfileScreen = navigateToProfileScreen,
navigateToAboutScreen = navigateToAboutScreen
navigateToAboutScreen = navigateToAboutScreen,
onShareFeedbackPressed = onShareFeedbackPressed,
onRateAppPressed = onRateAppPressed
)
},
colors = TopAppBarDefaults.largeTopAppBarColors(
Expand All @@ -128,7 +146,9 @@ private fun HomeTopBar(
private fun NavigationDropDownMenu(
modifier: Modifier = Modifier,
navigateToProfileScreen: () -> Unit,
navigateToAboutScreen: () -> Unit
navigateToAboutScreen: () -> Unit,
onShareFeedbackPressed: () -> Unit,
onRateAppPressed: () -> Unit,
) {
val isExpanded = remember { mutableStateOf(false) }

Expand Down Expand Up @@ -174,6 +194,38 @@ private fun NavigationDropDownMenu(
navigateToAboutScreen.invoke()
},
)
Divider()
DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.share_feedback_button_text))
},
leadingIcon = {
Icon(
imageVector = Icons.Outlined.Mail,
contentDescription = "Mail Icon"
)
},
onClick = {
isExpanded.value = false
onShareFeedbackPressed.invoke()
},
)
Divider()
DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.rate_app_button_text))
},
leadingIcon = {
Icon(
imageVector = Icons.Outlined.StarOutline,
contentDescription = "Star Icon"
)
},
onClick = {
isExpanded.value = false
onRateAppPressed.invoke()
},
)
}
}
}
Expand All @@ -192,7 +244,9 @@ private fun HomeTopBarPreview() {
Life.example.currentYearRemainingWeeks
),
navigateToProfileScreen = {},
navigateToAboutScreen = {}
navigateToAboutScreen = {},
onShareFeedbackPressed = {},
onRateAppPressed = {}
)
}
}
Expand All @@ -203,7 +257,9 @@ fun NavigationDropDownMenuPreview() {
LifeProgressTheme {
NavigationDropDownMenu(
navigateToAboutScreen = {},
navigateToProfileScreen = {}
navigateToProfileScreen = {},
onShareFeedbackPressed = {},
onRateAppPressed = {}
)
}
}
25 changes: 25 additions & 0 deletions app/src/main/java/com/bartozo/lifeprogress/util/Helpers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.bartozo.lifeprogress.util

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri

fun Context.sendMail(
to: String,
subject: String,
onError: () -> Unit
) {
try {
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:")
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(to))
intent.putExtra(Intent.EXTRA_SUBJECT, subject)

startActivity(intent)
} catch (e: ActivityNotFoundException) {
onError.invoke()
} catch (t: Throwable) {
onError.invoke()
}
}

0 comments on commit ebfc7e7

Please sign in to comment.