Skip to content

Commit

Permalink
Merge pull request #8 from aritra-tech/develop
Browse files Browse the repository at this point in the history
v 1.1.0
  • Loading branch information
aritra-tech authored Jul 10, 2024
2 parents 335b501 + 42c28e9 commit 5037a0e
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 48 deletions.
4 changes: 2 additions & 2 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ android {
applicationId = "com.aritra.coinify"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
versionCode = 2
versionName = "1.1.0"
}
packaging {
resources {
Expand Down
4 changes: 4 additions & 0 deletions composeApp/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
<string name="total_supply">Total Supply</string>
<string name="theme">Theme</string>
<string name="invite_others">Invite others</string>
<string name="top_movers">Top Movers</string>
<string name="top_losing">Top Losing</string>
<string name="search_for_coins">Search for coins</string>
<string name="loading">Loading...</string>
</resources>
3 changes: 0 additions & 3 deletions composeApp/src/commonMain/kotlin/component/CryptoCard.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package component

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -22,7 +21,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.TextStyle
Expand Down Expand Up @@ -66,7 +64,6 @@ fun CryptoCard(
.clip(RoundedCornerShape(10.dp))
.background(MaterialTheme.colorScheme.surfaceContainer)
.clickable { onClick(jsonData) }
// .border(width = 1.dp, color = Color(0xFFEEEEEE), RoundedCornerShape(10.dp))
.padding(16.dp),
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.Center
Expand Down
5 changes: 4 additions & 1 deletion composeApp/src/commonMain/kotlin/component/LoadingDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coinify.composeapp.generated.resources.Res
import coinify.composeapp.generated.resources.loading
import org.jetbrains.compose.resources.stringResource

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand All @@ -38,7 +41,7 @@ fun LoadingDialog() {
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
"Loading",
text = stringResource(Res.string.loading),
style = TextStyle(color = MaterialTheme.colorScheme.onSecondaryContainer, fontSize = 20.sp)
)
Spacer(modifier = Modifier.padding(12.dp))
Expand Down
5 changes: 4 additions & 1 deletion composeApp/src/commonMain/kotlin/component/SearchBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.ImeAction
import coinify.composeapp.generated.resources.Res
import coinify.composeapp.generated.resources.search_for_coins
import org.jetbrains.compose.resources.stringResource

@Composable
fun SearchBar(
Expand Down Expand Up @@ -80,7 +83,7 @@ fun SearchBar(
),
placeholder = {
Text(
text = "Search Coins",
text = stringResource(Res.string.search_for_coins),
style = TextStyle(color = MaterialTheme.colorScheme.onSecondaryContainer)
)
}
Expand Down
111 changes: 111 additions & 0 deletions composeApp/src/commonMain/kotlin/component/StatsCard.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package component

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
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowUpward
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp
import coinify.composeapp.generated.resources.Res
import coinify.composeapp.generated.resources.poppins_medium
import coinify.composeapp.generated.resources.poppins_regular
import domain.model.Data
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.jetbrains.compose.resources.Font
import kotlin.math.roundToInt

@Composable
fun StatsCard(
data: Data,
onClick: (String) -> Unit
) {
val encodedData = remember(data) { Json.encodeToString(data) }
val percentage24h = data.quote.USD.percentChange24h
val textColor24h = if (percentage24h > 0) Color.Green else Color.Red

Column(
modifier = Modifier
.width(200.dp)
.height(130.dp)
.clip(RoundedCornerShape(10.dp))
.background(MaterialTheme.colorScheme.surfaceContainer)
.clickable { onClick(encodedData) }
.padding(16.dp),
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.SpaceBetween
) {

Column(
horizontalAlignment = Alignment.Start
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = data.name,
style = MaterialTheme.typography.bodyMedium.copy(
fontFamily = FontFamily(Font(Res.font.poppins_medium))
)
)

Spacer(modifier = Modifier.weight(1f))

val formattedPrice = data.quote.USD.price?.times(100)?.roundToInt()?.div(100.0)
Text(
text = "$ $formattedPrice",
style = MaterialTheme.typography.bodyMedium.copy(
fontFamily = FontFamily(Font(Res.font.poppins_regular))
)
)
}

Text(
text = "${data.symbol}",
style = MaterialTheme.typography.bodySmall.copy(
fontFamily = FontFamily(Font(Res.font.poppins_regular))
)
)
}

Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.End
) {
Icon(
imageVector = Icons.Default.ArrowUpward,
contentDescription = if (percentage24h > 0) "Gain" else "Loss",
tint = textColor24h,
modifier = Modifier.size(20.dp)
)
Text(
text = "${percentage24h.roundToInt()}%",
color = textColor24h,
style = MaterialTheme.typography.bodySmall.copy(
fontFamily = FontFamily(Font(Res.font.poppins_medium))
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package navigation

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Newspaper
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.outlined.StackedLineChart
import androidx.compose.ui.graphics.vector.ImageVector

sealed class BottomNavScreens(val route: String, val icon: ImageVector, val title: String) {
object Home: BottomNavScreens(Screens.Home.route, Icons.Default.Home,"Home")
object News: BottomNavScreens(Screens.Settings.route, Icons.Default.Settings, "Settings")
data object Home: BottomNavScreens(Screens.Home.route, Icons.Default.Home,"Home")
data object Statistics: BottomNavScreens(Screens.Statistics.route, Icons.Outlined.StackedLineChart, "Statistics")
data object News: BottomNavScreens(Screens.Settings.route, Icons.Default.Settings, "Settings")
}
65 changes: 43 additions & 22 deletions composeApp/src/commonMain/kotlin/navigation/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package navigation

import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material.Scaffold
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontFamily
Expand All @@ -28,11 +28,14 @@ import domain.model.Data
import kotlinx.serialization.json.Json
import presentation.DetailsScreen
import presentation.HomeScreen
import presentation.NewsScreen
import presentation.SettingsScreen
import presentation.StatisticsScreen
import ui.backgroundLight
import ui.onPrimaryContainerLight
import ui.onSurfaceVariantLight
import ui.primaryDark
import utils.FadeIn
import utils.FadeOut

val LocalNavHost = staticCompositionLocalOf<NavHostController> {
error("No Parameter is available")
Expand Down Expand Up @@ -62,6 +65,8 @@ fun Navigation() {
modifier = Modifier.fillMaxWidth(),
navController = navController,
startDestination = Screens.Home.route,
enterTransition = { FadeIn },
exitTransition = { FadeOut }
) {

composable(route = Screens.Home.route) {
Expand All @@ -79,6 +84,10 @@ fun Navigation() {
composable(route = Screens.Settings.route) {
SettingsScreen()
}

composable(route = Screens.Statistics.route) {
StatisticsScreen()
}
}
}
}
Expand All @@ -90,48 +99,60 @@ fun BottomNavigationBar(
backStackEntry: State<NavBackStackEntry?>,
screensWithoutNavigationBar: MutableList<String>
) {
val items = listOf(
BottomNavScreens.Home,
BottomNavScreens.News
)

if (backStackEntry.value?.destination?.route !in screensWithoutNavigationBar) {
BottomAppBar(
NavigationBar(
containerColor = backgroundLight
) {
val currentBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = currentBackStackEntry?.destination
val items = listOf(
BottomNavScreens.Home,
BottomNavScreens.Statistics,
BottomNavScreens.News
)
val currentDestination = navController.currentBackStackEntry?.destination?.route

items.forEach { screen ->
BottomNavigationItem(
NavigationBarItem(
alwaysShowLabel = true,
icon = {
Icon(
imageVector = screen.icon,
contentDescription = screen.title,
tint = if (backStackEntry.value?.destination?.route == screen.route) onPrimaryContainerLight else onSurfaceVariantLight
tint = if (backStackEntry.value?.destination?.route == screen.route)
onPrimaryContainerLight
else
onSurfaceVariantLight
)
},
label = {
Text(
text = screen.title,
color = if (backStackEntry.value?.destination?.route == screen.route) onPrimaryContainerLight else onSurfaceVariantLight,
color = if (backStackEntry.value?.destination?.route == screen.route)
onPrimaryContainerLight
else
onSurfaceVariantLight,
fontFamily = FontFamily(org.jetbrains.compose.resources.Font(Res.font.poppins_regular)),
fontWeight = if (backStackEntry.value?.destination?.route == screen.route)
FontWeight.SemiBold
FontWeight.Medium
else
FontWeight.Normal,
)
},
selected = currentDestination?.route == screen.route,
selected = backStackEntry.value?.destination?.route == screen.route,
onClick = {
navController.navigate(screen.route) {
popUpTo(navController.graph.startDestinationRoute.toString()) {
saveState = true
if (screen.route != currentDestination) {
navController.navigate(screen.route) {
popUpTo(navController.graph.startDestinationRoute.toString()) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
launchSingleTop = true
restoreState = true
}
}
},
colors = NavigationBarItemDefaults.colors(
indicatorColor = primaryDark
)
)
}
}
Expand Down
1 change: 1 addition & 0 deletions composeApp/src/commonMain/kotlin/navigation/Screens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ sealed class Screens(val route: String) {
data object Home : Screens("home_screen")
data object Details : Screens("details_screen")
data object Settings : Screens("settings_screen")
data object Statistics : Screens("stats_screen")
}
Loading

0 comments on commit 5037a0e

Please sign in to comment.