Skip to content

Commit

Permalink
DatePicker Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ashgautamDev committed Sep 16, 2021
1 parent d426ec4 commit 0f6100f
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 79 deletions.
7 changes: 6 additions & 1 deletion app/src/main/java/com/ashish/weighter/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package com.ashish.weighter
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import com.ashish.weighter.ui.theme.WeighterTheme
import com.ashish.weighter.ui.screens.MainScreen
Expand All @@ -16,13 +19,15 @@ import dagger.hilt.android.AndroidEntryPoint
class MainActivity : ComponentActivity() {


@ExperimentalComposeUiApi
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val activity = LocalContext.current as AppCompatActivity
WeighterTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
MainScreen()
MainScreen(activity)
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/com/ashish/weighter/navigation/Screens.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.ashish.weighter.navigation

import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountBox
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material.icons.filled.AddCircle
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.HiltViewModelFactory
Expand All @@ -13,18 +15,20 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.ashish.weighter.ui.WeightViewmodel
import com.ashish.weighter.ui.screens.AddWeightScreen
import com.ashish.weighter.ui.screens.addweight.AddWeightScreen
import com.ashish.weighter.ui.screens.MyWeightScreen
import com.ashish.weighter.ui.screens.TargetScreen
import com.ashish.weighter.ui.screens.addweight.AddWeightViewModel

sealed class Screens(var route: String, var icon: ImageVector, var title: String) {
object MyWeight : Screens("home", Icons.Default.AccountBox, "My Weight")
object Target : Screens("target", Icons.Default.AccountCircle, "Target")
object AddWeight : Screens("add", Icons.Default.AddCircle, "")
}

@ExperimentalComposeUiApi
@Composable
fun NavigateToScreen(navController: NavHostController) {
fun NavigateToScreen(navController: NavHostController, activity : AppCompatActivity) {
NavHost(navController, startDestination = Screens.MyWeight.route) {
composable(Screens.MyWeight.route) {

Expand All @@ -43,10 +47,10 @@ fun NavigateToScreen(navController: NavHostController) {
}
composable(Screens.AddWeight.route) {

val viewModel: WeightViewmodel = viewModel(
val viewModel: AddWeightViewModel = viewModel(
factory = HiltViewModelFactory(LocalContext.current, it)
)
AddWeightScreen(navController , viewModel = viewModel)
AddWeightScreen(navController , viewModel = viewModel , activity )
}
}

Expand Down
28 changes: 24 additions & 4 deletions app/src/main/java/com/ashish/weighter/ui/component/WeightCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ashish.weighter.ui.component
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
Expand All @@ -11,23 +12,42 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.ashish.weighter.model.Weight
import com.ashish.weighter.ui.theme.WeighterTheme

@Composable
fun WeightCard(weight : Weight) {
fun WeightCard(weight: Weight) {

Card(modifier = Modifier.fillMaxWidth()) {
Row(verticalAlignment = Alignment.Bottom,
Card(modifier = Modifier) {
Row(modifier = Modifier
.fillMaxWidth()
.padding(start = 12.dp , end = 12.dp), verticalAlignment = Alignment.Bottom,
horizontalArrangement = Arrangement.SpaceBetween) {

Text(text = weight.date,
color = MaterialTheme.colors.primary.copy(alpha = .7f),
fontSize = 24.sp,
fontWeight = FontWeight.SemiBold)

Text(text = weight.weight,
color = Color.Green,
fontSize = 28.sp,
fontWeight = FontWeight.Bold)
}
Text(text = weight.weight, color = Color.Green, fontSize = 24.sp, fontWeight = FontWeight.Bold)

}


}

@Preview
@Composable
fun WeightCardprv() {
WeighterTheme() {
WeightCard(weight = Weight(0, "74", "22/09/2021"))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ashish.weighter.ui.component
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.AbsoluteRoundedCornerShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.LinearProgressIndicator
Expand All @@ -28,7 +29,9 @@ fun WeightGraph() {
.fillMaxWidth()
.height(300.dp),
border = BorderStroke(1.dp, color = textColor),
backgroundColor = background) {
backgroundColor = background ,
shape = AbsoluteRoundedCornerShape(25)
) {
Row(horizontalArrangement = Arrangement.spacedBy(15.dp) , modifier = Modifier.padding(16.dp)) {
Column( Modifier.fillMaxHeight(1f).padding(bottom = 30.dp),verticalArrangement = Arrangement.SpaceEvenly) {
TextNo(70)
Expand All @@ -55,7 +58,7 @@ fun WeightGraph() {

@Composable
fun TextNo(value : Int) {
Text(text = value.toString() , color = textDark.copy(alpha = .8f) , fontSize = 16.sp , fontWeight = FontWeight.SemiBold)
Text(text = value.toString() , color = textDark.copy(alpha = .7f) , fontSize = 16.sp , fontWeight = FontWeight.SemiBold)

}

Expand All @@ -68,9 +71,9 @@ fun DayProgress( day : String , dayProgress : Float) {
.background(color = Color.Blue.copy(alpha = .6f) , shape = RoundedCornerShape(100)))
Spacer(modifier = Modifier.heightIn(15.dp))
Text(text = day.uppercase(),
color = textDark.copy(alpha = .7f),
color = textDark.copy(alpha = .5f),
fontWeight = FontWeight.SemiBold,
fontSize = 16.sp)
fontSize = 14.sp)


}
Expand Down
14 changes: 5 additions & 9 deletions app/src/main/java/com/ashish/weighter/ui/screens/MainScreen.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
package com.ashish.weighter.ui.screens

import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.rememberNavController
import com.ashish.weighter.navigation.NavigateToScreen
import com.ashish.weighter.ui.WeightViewmodel
import com.ashish.weighter.ui.component.BottomNavigationBar
import com.ashish.weighter.ui.theme.WeighterTheme

@ExperimentalComposeUiApi
@Composable
fun MainScreen() {
fun MainScreen(activity : AppCompatActivity) {
val navController = rememberNavController()

Scaffold(
bottomBar = { BottomNavigationBar(navController = navController) }
) {

NavigateToScreen(navController = navController)
NavigateToScreen(navController = navController , activity)

}
}

@Preview
@Composable
fun MainScreenPrv() {
WeighterTheme {
MainScreen()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.FabPosition
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.icons.Icons
Expand All @@ -29,6 +30,7 @@ import com.ashish.weighter.ui.view.YourProgressView
import com.ashish.weighter.utils.WeightState



@Composable
fun MyWeightScreen(viewModel: WeightViewmodel, navController: NavController) {

Expand All @@ -46,9 +48,9 @@ fun MyWeightScreen(viewModel: WeightViewmodel, navController: NavController) {
contentDescription = null,
modifier = Modifier
.size(56.dp)
.background(color = MaterialTheme.colors.primary)
.background(color = background)
.clickable { navController.navigate(Screens.AddWeight.route) })
},
}, floatingActionButtonPosition = FabPosition.Center ,isFloatingActionButtonDocked = true,
content = { padding ->
Column(modifier = Modifier.padding(top = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fun TargetScreen(viewModel: WeightViewmodel , navController: NavController ) {
is ViewState.Success -> {
// pass result to Card
WeightHistoryList(weight = result.weight, navController = navController)

}

}
Expand Down
Loading

0 comments on commit 0f6100f

Please sign in to comment.