Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Advance Navigation and ViewModel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
android
Advance Navigation and ViewModel
Commits
1edc16f0
Commit
1edc16f0
authored
2 years ago
by
62160052
Browse files
Options
Downloads
Patches
Plain Diff
Create pickup options list
parent
bd0c5580
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/src/main/java/com/example/cupcake/model/OrderViewModel.kt
+17
-0
17 additions, 0 deletions
...src/main/java/com/example/cupcake/model/OrderViewModel.kt
app/src/main/res/layout/fragment_flavor.xml
+8
-8
8 additions, 8 deletions
app/src/main/res/layout/fragment_flavor.xml
with
25 additions
and
8 deletions
app/src/main/java/com/example/cupcake/model/OrderViewModel.kt
+
17
−
0
View file @
1edc16f0
...
@@ -3,6 +3,9 @@ package com.example.cupcake.model
...
@@ -3,6 +3,9 @@ package com.example.cupcake.model
import
androidx.lifecycle.LiveData
import
androidx.lifecycle.LiveData
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.ViewModel
import
java.text.SimpleDateFormat
import
java.util.Calendar
import
java.util.Locale
class
OrderViewModel
:
ViewModel
()
{
class
OrderViewModel
:
ViewModel
()
{
private
val
_quantity
=
MutableLiveData
<
Int
>(
0
)
private
val
_quantity
=
MutableLiveData
<
Int
>(
0
)
...
@@ -17,6 +20,20 @@ class OrderViewModel : ViewModel() {
...
@@ -17,6 +20,20 @@ class OrderViewModel : ViewModel() {
private
val
_price
=
MutableLiveData
<
Double
>(
0.0
)
private
val
_price
=
MutableLiveData
<
Double
>(
0.0
)
val
price
:
LiveData
<
Double
>
=
_price
val
price
:
LiveData
<
Double
>
=
_price
val
dateOptions
=
getPickupOptions
()
private
fun
getPickupOptions
():
List
<
String
>
{
val
options
=
mutableListOf
<
String
>()
val
formatter
=
SimpleDateFormat
(
"E MMM d"
,
Locale
.
getDefault
())
val
calendar
=
Calendar
.
getInstance
()
// Create a list of dates starting with the current date and the following 3 dates
repeat
(
4
)
{
options
.
add
(
formatter
.
format
(
calendar
.
time
))
calendar
.
add
(
Calendar
.
DATE
,
1
)
}
return
options
}
fun
setQuantity
(
numberCupcakes
:
Int
)
{
fun
setQuantity
(
numberCupcakes
:
Int
)
{
_quantity
.
value
=
numberCupcakes
_quantity
.
value
=
numberCupcakes
}
}
...
...
This diff is collapsed.
Click to expand it.
app/src/main/res/layout/fragment_flavor.xml
+
8
−
8
View file @
1edc16f0
...
@@ -55,32 +55,32 @@
...
@@ -55,32 +55,32 @@
android:id=
"@+id/chocolate"
android:id=
"@+id/chocolate"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:checked=
"@{viewModel.flavor.equals(@string/
vanilla
)}"
android:checked=
"@{viewModel.flavor.equals(@string/
chocolate
)}"
android:onClick=
"@{() -> viewModel.setFlavor(@string/
vanilla
)}"
android:onClick=
"@{() -> viewModel.setFlavor(@string/
chocolate
)}"
android:text=
"@string/chocolate"
/>
android:text=
"@string/chocolate"
/>
<RadioButton
<RadioButton
android:id=
"@+id/red_velvet"
android:id=
"@+id/red_velvet"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:checked=
"@{viewModel.flavor.equals(@string/
vanilla
)}"
android:checked=
"@{viewModel.flavor.equals(@string/
red_velvet
)}"
android:onClick=
"@{() -> viewModel.setFlavor(@string/
vanilla
)}"
android:onClick=
"@{() -> viewModel.setFlavor(@string/
red_velvet
)}"
android:text=
"@string/red_velvet"
/>
android:text=
"@string/red_velvet"
/>
<RadioButton
<RadioButton
android:id=
"@+id/salted_caramel"
android:id=
"@+id/salted_caramel"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:checked=
"@{viewModel.flavor.equals(@string/
vanilla
)}"
android:checked=
"@{viewModel.flavor.equals(@string/
salted_caramel
)}"
android:onClick=
"@{() -> viewModel.setFlavor(@string/
vanilla
)}"
android:onClick=
"@{() -> viewModel.setFlavor(@string/
salted_caramel
)}"
android:text=
"@string/salted_caramel"
/>
android:text=
"@string/salted_caramel"
/>
<RadioButton
<RadioButton
android:id=
"@+id/coffee"
android:id=
"@+id/coffee"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:checked=
"@{viewModel.flavor.equals(@string/
vanilla
)}"
android:checked=
"@{viewModel.flavor.equals(@string/
coffee
)}"
android:onClick=
"@{() -> viewModel.setFlavor(@string/
vanilla
)}"
android:onClick=
"@{() -> viewModel.setFlavor(@string/
coffee
)}"
android:text=
"@string/coffee"
/>
android:text=
"@string/coffee"
/>
</RadioGroup>
</RadioGroup>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment