Skip to content

Commit

Permalink
Merge pull request #15 from binayshaw7777/account-flow
Browse files Browse the repository at this point in the history
Account flow
  • Loading branch information
binayshaw7777 authored Mar 5, 2024
2 parents 066396a + 1569daa commit 7f23d29
Show file tree
Hide file tree
Showing 24 changed files with 651 additions and 30 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ android {
buildFeatures {
viewBinding = true
compose = true
buildConfig = true
}

buildTypes {
Expand Down Expand Up @@ -227,6 +228,9 @@ dependencies {
//Circular ImageView
implementation("de.hdodenhof:circleimageview:3.1.0")

// Coil - Image Loading
implementation("io.coil-kt:coil-compose:2.4.0")

//Custom AlertBar (Top)
implementation("com.github.tapadoo:alerter:7.2.4")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class BaseFragment : Fragment() {
super.onCreate(savedInstanceState)
val firebaseUserId = FirebaseAuth.getInstance().uid
if (firebaseUserId == null) {
clearDataAndLogout(lifecycleScope, requireContext(), requireActivity())
clearDataAndLogout(lifecycleScope, requireContext())
Toast.makeText(requireContext(), getString(R.string.anErrorOccurred), Toast.LENGTH_SHORT).show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ class DataStoreUtil @Inject constructor(context: Context) {
companion object {
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore("settings")
val IS_DARK_MODE_KEY = booleanPreferencesKey("dark_mode")
val IS_DYNAMIC_THEME_MODE_KEY = booleanPreferencesKey("dynamic_theme")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.binay.shaw.justap.presentation.account

import com.binay.shaw.justap.R
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf

enum class AccountOptions(val displayName: String, val iconId: Int) {
EDIT_PROFILE("Edit Profile", R.drawable.ic_account),
CUSTOMIZE_QR("Customize QR", R.drawable.ic_customize_qr),
THEME("Theme", R.drawable.ic_theme),
INVITE_FRIENDS("Invite your friends", R.drawable.ic_invite_friends),
LANGUAGE("Language", R.drawable.ic_language),
PRIVACY_POLICY("Privacy Policy", R.drawable.ic_privacy_policy),
RATE_US("Rate us", R.drawable.ic_google_playstore),
HELP_AND_SUPPORT("Help and Support", R.drawable.ic_help),
LOGOUT("Logout", R.drawable.ic_logout);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,284 @@
package com.binay.shaw.justap.presentation.account

import android.app.Activity
import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.binay.shaw.justap.presentation.themes.medium20
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.binay.shaw.justap.BuildConfig
import com.binay.shaw.justap.R
import com.binay.shaw.justap.presentation.components.OptionItem
import com.binay.shaw.justap.presentation.components.ThemeDialog
import com.binay.shaw.justap.presentation.themes.medium14
import com.binay.shaw.justap.presentation.themes.medium16
import com.binay.shaw.justap.presentation.themes.normal14
import com.binay.shaw.justap.presentation.themes.normal16
import com.binay.shaw.justap.utilities.Constants
import com.binay.shaw.justap.utilities.Util
import com.binay.shaw.justap.utilities.rememberReviewTask
import com.google.android.play.core.review.ReviewManagerFactory

@Composable
fun AccountScreen(
modifier: Modifier = Modifier

) {
Column(modifier = Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background)) {
Text(text = "This is account screen", style = medium20.copy(color = MaterialTheme.colorScheme.onPrimaryContainer))

var openThemeDialog by remember { mutableStateOf(false) }

val context = LocalContext.current
val scope = rememberCoroutineScope()

val reviewManager = remember {
ReviewManagerFactory.create(context)
}

var openLogoutDialog by remember { mutableStateOf(false) }

var reviewInfo = rememberReviewTask(reviewManager)

LaunchedEffect(reviewInfo) {
reviewInfo?.let {
reviewManager.launchReviewFlow(context as Activity, it)
}
}

when {
openThemeDialog -> {
ThemeDialog(onDismissRequest = { openThemeDialog = false })
}

openLogoutDialog -> {
AlertDialog(
onDismissRequest = { openLogoutDialog = false },
icon = {
Icon(
painter = painterResource(id = R.drawable.ic_logout),
contentDescription = null,
tint = MaterialTheme.colorScheme.onPrimaryContainer
)
},
title = {
Text(
text = "Logout?",
style = normal16.copy(color = MaterialTheme.colorScheme.onPrimaryContainer)
)
},
text = {
Text(
text = "Are you sure you want to logout?",
style = normal16.copy(color = MaterialTheme.colorScheme.onSurfaceVariant)
)
},
confirmButton = {
TextButton(
onClick = {
Util.clearDataAndLogout(scope, context)
openLogoutDialog = false
},
colors = ButtonDefaults.buttonColors(
containerColor = Color.Transparent,
contentColor = MaterialTheme.colorScheme.onPrimaryContainer
)
) {
Text(
"Logout",
style = medium14
)
}
},
dismissButton = {
TextButton(
onClick = {
openLogoutDialog = false
},
colors = ButtonDefaults.buttonColors(
containerColor = Color.Transparent,
contentColor = MaterialTheme.colorScheme.onPrimaryContainer
)
) {
Text(
stringResource(id = R.string.cancel),
style = medium14
)
}
},
containerColor = MaterialTheme.colorScheme.background
)
}
}

Column(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
.windowInsetsPadding(WindowInsets.statusBars)
.then(modifier)
) {

Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 14.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.Start),
verticalAlignment = Alignment.CenterVertically
) {

AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(R.drawable.aboutme_pfp)
.size(coil.size.Size.ORIGINAL) // Set the target size to load the image at.
.build(), contentDescription = null,
modifier = Modifier
.size(56.dp)
.clip(CircleShape)
)

Column {
Text(text = "John Doe", style = medium16)
Text(
text = "johndoe123@gmail.com",
style = normal14.copy(color = MaterialTheme.colorScheme.surfaceTint)
)
}
}

LazyColumn(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
) {
item {
Text(
text = "Account",
style = medium14.copy(color = MaterialTheme.colorScheme.onPrimaryContainer),
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, top = 18.dp, bottom = 18.dp)
)
}
items(AccountOptions.entries.subList(0, 3)) {
OptionItem(it) { onClickOption ->
when (onClickOption) {
AccountOptions.EDIT_PROFILE -> {

}

AccountOptions.CUSTOMIZE_QR -> {

}

AccountOptions.THEME -> {
openThemeDialog = true
}

else -> {}
}
}
}
item {
Text(
text = "General",
style = medium14.copy(color = MaterialTheme.colorScheme.onPrimaryContainer),
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, top = 18.dp, bottom = 18.dp)
)
}
items(AccountOptions.entries.subList(3, AccountOptions.entries.size)) {
OptionItem(it) { onClickOption ->
when (onClickOption) {
AccountOptions.INVITE_FRIENDS -> {
val sendIntent = Intent(Intent.ACTION_SEND).apply {
putExtra(Intent.EXTRA_TEXT, Constants.inviteFriendsMessage)
type = "text/plain"
}
val shareIntent = Intent.createChooser(sendIntent, null)
context.startActivity(shareIntent)
}

AccountOptions.LANGUAGE -> {

}

AccountOptions.PRIVACY_POLICY -> {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(Constants.privacyPolicyUrl)
context.startActivity(intent)
}

AccountOptions.RATE_US -> {
// reviewManager.requestReviewFlow().addOnCompleteListener { reviewTask ->
// if (reviewTask.isSuccessful) {
// reviewInfo = reviewTask.result
// }
// }
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(Constants.APP_URL)
context.startActivity(intent)
}

AccountOptions.HELP_AND_SUPPORT -> {
val openURL = Intent(Intent.ACTION_VIEW)
openURL.data = Uri.parse(context.resources.getString(R.string.mailTo))
context.startActivity(openURL)
}

AccountOptions.LOGOUT -> {
openLogoutDialog = true
}

else -> {}
}
}
}
item {
Text(
text = "App Version: ${BuildConfig.VERSION_NAME}",
style = normal14.copy(color = MaterialTheme.colorScheme.surfaceTint)
)
}
}
}
}


@Preview
@Composable
private fun AccountScreenPreview() {
AccountScreen()
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import com.binay.shaw.justap.presentation.themes.JusTapTheme

@Composable
fun MyButton(
modifier: Modifier = Modifier,
text: String,
modifier: Modifier = Modifier,
enabled: Boolean = true,
shape: Shape = ButtonDefaults.shape,
colors: ButtonColors = ButtonDefaults.buttonColors(
Expand Down Expand Up @@ -56,7 +56,7 @@ fun MyButton(

@Preview
@Composable
fun MyButtonPreview() {
private fun MyButtonPreview() {
JusTapTheme {
MyButton(text = "My Button") {
Logger.debugLog("Log this message!")
Expand Down
Loading

0 comments on commit 7f23d29

Please sign in to comment.