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
a8ce5300
Commit
a8ce5300
authored
2 years ago
by
62160052
Browse files
Options
Downloads
Patches
Plain Diff
Update Summary fragment to use view model
parent
b2eb00c0
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
+15
-4
15 additions, 4 deletions
...src/main/java/com/example/cupcake/model/OrderViewModel.kt
app/src/main/res/layout/fragment_summary.xml
+3
-0
3 additions, 0 deletions
app/src/main/res/layout/fragment_summary.xml
with
18 additions
and
4 deletions
app/src/main/java/com/example/cupcake/model/OrderViewModel.kt
+
15
−
4
View file @
a8ce5300
...
...
@@ -8,20 +8,24 @@ import java.util.Calendar
import
java.util.Locale
class
OrderViewModel
:
ViewModel
()
{
private
val
_quantity
=
MutableLiveData
<
Int
>(
0
)
private
val
_quantity
=
MutableLiveData
<
Int
>()
val
quantity
:
LiveData
<
Int
>
=
_quantity
private
val
_flavor
=
MutableLiveData
<
String
>(
""
)
private
val
_flavor
=
MutableLiveData
<
String
>()
val
flavor
:
LiveData
<
String
>
=
_flavor
private
val
_date
=
MutableLiveData
<
String
>(
""
)
private
val
_date
=
MutableLiveData
<
String
>()
val
date
:
LiveData
<
String
>
=
_date
private
val
_price
=
MutableLiveData
<
Double
>(
0.0
)
private
val
_price
=
MutableLiveData
<
Double
>()
val
price
:
LiveData
<
Double
>
=
_price
val
dateOptions
=
getPickupOptions
()
init
{
resetOrder
()
}
private
fun
getPickupOptions
():
List
<
String
>
{
val
options
=
mutableListOf
<
String
>()
val
formatter
=
SimpleDateFormat
(
"E MMM d"
,
Locale
.
getDefault
())
...
...
@@ -34,6 +38,13 @@ class OrderViewModel : ViewModel() {
return
options
}
fun
resetOrder
()
{
_quantity
.
value
=
0
_flavor
.
value
=
""
_date
.
value
=
dateOptions
[
0
]
_price
.
value
=
0.0
}
fun
setQuantity
(
numberCupcakes
:
Int
)
{
_quantity
.
value
=
numberCupcakes
}
...
...
This diff is collapsed.
Click to expand it.
app/src/main/res/layout/fragment_summary.xml
+
3
−
0
View file @
a8ce5300
...
...
@@ -58,6 +58,7 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"@dimen/order_summary_margin"
android:text=
"@{viewModel.quantity.toString()}"
tools:text=
"6 cupcakes"
/>
<View
...
...
@@ -81,6 +82,7 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"@dimen/order_summary_margin"
android:text=
"@{viewModel.flavor}"
tools:text=
"Chocolate"
/>
<View
...
...
@@ -104,6 +106,7 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"@dimen/order_summary_margin"
android:text=
"@{viewModel.date}"
tools:text=
"Sunday"
/>
<View
...
...
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