-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d14ab59
commit 27e9726
Showing
17 changed files
with
366 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/roshan/calorietracker/CalorieTrackerApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.roshan.calorietracker | ||
|
||
import android.app.Application | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class CalorieTrackerApplication : Application() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/roshan/calorietracker/di/AppModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.roshan.calorietracker.di | ||
|
||
import android.app.Application | ||
import android.content.Context.MODE_PRIVATE | ||
import android.content.SharedPreferences | ||
import com.roshan.core.domain.DefaultPreferences | ||
import com.roshan.core.domain.preferences.Preferences | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object AppModule { | ||
@Provides | ||
@Singleton | ||
fun providesSharedPreferences(app: Application): SharedPreferences { | ||
return app.getSharedPreferences("shared_pref", MODE_PRIVATE) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun providesPreferences(sharedPreferences: SharedPreferences): Preferences { | ||
return DefaultPreferences(sharedPreferences) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/roshan/calorietracker/navigation/NavControllerExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.roshan.calorietracker.navigation | ||
|
||
import androidx.navigation.NavController | ||
import com.roshan.core.util.UiEvent | ||
|
||
fun NavController.navigate(event: UiEvent.Navigate) { | ||
this.navigate(event.route) | ||
} |
89 changes: 89 additions & 0 deletions
89
core/src/main/java/com/roshan/core/domain/DefaultPreferences.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.roshan.core.domain | ||
|
||
import android.content.SharedPreferences | ||
import com.roshan.core.domain.model.ActivityLevel | ||
import com.roshan.core.domain.model.Gender | ||
import com.roshan.core.domain.model.GoalType | ||
import com.roshan.core.domain.model.UserInfo | ||
import com.roshan.core.domain.preferences.Preferences | ||
|
||
class DefaultPreferences(private val sharedPref: SharedPreferences) : Preferences { | ||
override fun saveGender(gender: Gender) { | ||
sharedPref.edit() | ||
.putString(Preferences.KEY_GENDER, gender.name) | ||
.apply() | ||
} | ||
|
||
override fun saveAge(age: Int) { | ||
sharedPref.edit() | ||
.putInt(Preferences.KEY_AGE, age) | ||
.apply() | ||
} | ||
|
||
override fun saveWeight(weight: Float) { | ||
sharedPref.edit() | ||
.putFloat(Preferences.KEY_WEIGHT, weight) | ||
.apply() | ||
} | ||
|
||
override fun saveHeight(height: Int) { | ||
sharedPref.edit() | ||
.putInt(Preferences.KEY_HEIGHT, height) | ||
.apply() | ||
} | ||
|
||
override fun saveActivityLevel(level: ActivityLevel) { | ||
sharedPref.edit() | ||
.putString(Preferences.KEY_ACTIVITY_LEVEL, level.name) | ||
.apply() | ||
} | ||
|
||
override fun saveGoalType(type: GoalType) { | ||
sharedPref.edit() | ||
.putString(Preferences.KEY_GOAL_TYPE, type.name) | ||
.apply() | ||
} | ||
|
||
override fun saveCarbRatio(ratio: Float) { | ||
sharedPref.edit() | ||
.putFloat(Preferences.KEY_CARB_RATIO, ratio) | ||
.apply() | ||
} | ||
|
||
override fun saveProteinRatio(ratio: Float) { | ||
sharedPref.edit() | ||
.putFloat(Preferences.KEY_PROTEIN_RATIO, ratio) | ||
.apply() | ||
} | ||
|
||
override fun saveFatRatio(ratio: Float) { | ||
sharedPref.edit() | ||
.putFloat(Preferences.KEY_FAT_RATIO, ratio) | ||
.apply() | ||
} | ||
|
||
override fun loadUserInfo(): UserInfo { | ||
val age = sharedPref.getInt(Preferences.KEY_AGE, -1) | ||
val height = sharedPref.getInt(Preferences.KEY_HEIGHT, -1) | ||
val weight = sharedPref.getFloat(Preferences.KEY_WEIGHT, -1f) | ||
val genderString = sharedPref.getString(Preferences.KEY_GENDER, null) | ||
val activityLevelString = sharedPref | ||
.getString(Preferences.KEY_ACTIVITY_LEVEL, null) | ||
val goalType = sharedPref.getString(Preferences.KEY_GOAL_TYPE, null) | ||
val carbRatio = sharedPref.getFloat(Preferences.KEY_CARB_RATIO, -1f) | ||
val proteinRatio = sharedPref.getFloat(Preferences.KEY_PROTEIN_RATIO, -1f) | ||
val fatRatio = sharedPref.getFloat(Preferences.KEY_FAT_RATIO, -1f) | ||
|
||
return UserInfo( | ||
gender = Gender.fromString(genderString ?: "male"), | ||
age = age, | ||
weight = weight, | ||
height = height, | ||
activityLevel = ActivityLevel.fromString(activityLevelString ?: "medium"), | ||
goalType = GoalType.fromString(goalType ?: "keep_weight"), | ||
carbRatio = carbRatio, | ||
proteinRatio = proteinRatio, | ||
fatRatio = fatRatio | ||
) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
core/src/main/java/com/roshan/core/domain/model/ActivityLevel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.roshan.core.domain.model | ||
|
||
sealed class ActivityLevel(val name: String) { | ||
object Low : ActivityLevel("low") | ||
object High : ActivityLevel("high") | ||
object Medium : ActivityLevel("medium") | ||
|
||
companion object { | ||
fun fromString(name: String): ActivityLevel { | ||
return when (name) { | ||
"low" -> Low | ||
"high" -> High | ||
"medium" -> Medium | ||
else -> Medium | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.roshan.core.domain.model | ||
|
||
sealed class Gender(val name: String) { | ||
object Male : Gender("male") | ||
object Female : Gender("female") | ||
companion object { | ||
fun fromString(name: String): Gender { | ||
return when (name) { | ||
"male" -> Male | ||
"female" -> Female | ||
else -> Female | ||
} | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
core/src/main/java/com/roshan/core/domain/model/GoalType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.roshan.core.domain.model | ||
|
||
sealed class GoalType(val name: String) { | ||
object LoseWeight : GoalType("lose_weight") | ||
object KeepWeight : GoalType("keep_weight") | ||
object GainWeight : GoalType("gain_weight") | ||
|
||
companion object { | ||
fun fromString(name: String): GoalType { | ||
return when (name) { | ||
"lose_weight" -> LoseWeight | ||
"gain_weight" -> GainWeight | ||
"keep_weight" -> KeepWeight | ||
else -> KeepWeight | ||
} | ||
} | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
core/src/main/java/com/roshan/core/domain/model/UserInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.roshan.core.domain.model | ||
|
||
data class UserInfo( | ||
val gender: Gender, | ||
val age: Int, | ||
val weight: Float, | ||
val height:Int, | ||
val activityLevel: ActivityLevel, | ||
val goalType: GoalType, | ||
val fatRatio: Float, | ||
val carbRatio: Float, | ||
val proteinRatio: Float | ||
) |
32 changes: 32 additions & 0 deletions
32
core/src/main/java/com/roshan/core/domain/preferences/Preferences.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.roshan.core.domain.preferences | ||
|
||
import com.roshan.core.domain.model.ActivityLevel | ||
import com.roshan.core.domain.model.Gender | ||
import com.roshan.core.domain.model.GoalType | ||
import com.roshan.core.domain.model.UserInfo | ||
|
||
interface Preferences { | ||
fun saveGender(gender: Gender) | ||
fun saveAge(age: Int) | ||
fun saveWeight(weight: Float) | ||
fun saveHeight(height: Int) | ||
fun saveActivityLevel(level: ActivityLevel) | ||
fun saveGoalType(type: GoalType) | ||
fun saveCarbRatio(ratio: Float) | ||
fun saveProteinRatio(ratio: Float) | ||
fun saveFatRatio(ratio: Float) | ||
|
||
fun loadUserInfo(): UserInfo | ||
|
||
companion object { | ||
const val KEY_GENDER = "gender" | ||
const val KEY_AGE = "age" | ||
const val KEY_WEIGHT = "weight" | ||
const val KEY_HEIGHT = "height" | ||
const val KEY_ACTIVITY_LEVEL = "activity_level" | ||
const val KEY_GOAL_TYPE = "goal_type" | ||
const val KEY_CARB_RATIO = "carb_ratio" | ||
const val KEY_PROTEIN_RATIO = "protein_ratio" | ||
const val KEY_FAT_RATIO = "fat_ratio" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.roshan.core.navigation | ||
|
||
object Route { | ||
const val WELCOME = "welcome" | ||
const val AGE = "age" | ||
const val GENDER = "gender" | ||
const val HEIGHT = "height" | ||
const val WEIGHT = "weight" | ||
const val NUTRIENT_GOAL = "nutrient_goal" | ||
const val ACTIVITY = "activity" | ||
const val GOAL = "goal" | ||
|
||
const val TRACKER_OVERVIEW = "tracker_overview" | ||
const val SEARCH = "search" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.roshan.core.util | ||
|
||
sealed class UiEvent { | ||
data class Navigate(val route: String) : UiEvent() | ||
object NavigateUp : UiEvent() | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
apply { | ||
from("$rootDir/base-module.gradle") | ||
from("$rootDir/compose-module.gradle") | ||
} | ||
|
||
dependencies { | ||
|
36 changes: 36 additions & 0 deletions
36
..._presentation/src/main/java/com/roshan/onboarding_presentation/components/ActionButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.roshan.onboarding_presentation.components | ||
|
||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.unit.dp | ||
import com.roshan.core_ui.LocalSpacing | ||
|
||
@Composable | ||
fun ActionButton( | ||
text: String, | ||
onClick: () -> Unit, | ||
modifier: Modifier, | ||
isEnabled: Boolean = true, | ||
textStyle: TextStyle = MaterialTheme.typography.button | ||
) { | ||
Button( | ||
onClick = onClick, | ||
modifier = modifier, | ||
enabled = isEnabled, | ||
shape = RoundedCornerShape(100.dp) | ||
) { | ||
Text( | ||
text = text, | ||
style = textStyle, | ||
color = MaterialTheme.colors.onPrimary, | ||
modifier = Modifier.padding(LocalSpacing.current.spaceSmall) | ||
) | ||
|
||
} | ||
} |
Oops, something went wrong.