Skip to content
This repository was archived by the owner on Jul 2, 2025. It is now read-only.

Commit c88db07

Browse files
adjust timestamp format
1 parent 964684b commit c88db07

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

android/canonical/app/src/main/java/com/google/samples/quickstart/canonical/ProfileViewModel.kt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,33 @@ class ProfileViewModel : ViewModel() {
115115
syncAppUserStatistic()
116116
}
117117

118-
fun uploadNewRecord(singleRunningTimeMillionSeconds : Long, time : String) {
118+
fun uploadNewRecord(singleRunningTimeMillionSeconds : Long, timestamp : String) {
119119

120120
val newTotalTimeMillisecond = getTotalTimeMillisecond()?.plus(
121121
singleRunningTimeMillionSeconds
122122
)
123123
Log.d(PROFILE_VM_TAG, "newTotalTimeMillisecond $newTotalTimeMillisecond")
124124

125-
// val singleRunDocRef = Firebase.firestore.collection(RUN_COLLECTION_NAME).document()
125+
val singleRunDocRef = Firebase.firestore.collection(RUN_COLLECTION_NAME).document()
126+
val singleRunData = hashMapOf(
127+
KEY_SINGLE_RUN_TIME to singleRunningTimeMillionSeconds,
128+
KEY_SINGLE_RUN_TIMESTAMP to timestamp
129+
)
130+
val updateRunUserData = hashMapOf(
131+
KEY_TOTAL_TIME_MS to newTotalTimeMillisecond,
132+
KEY_SINGLE_RUN_ID_LIST to FieldValue.arrayUnion(singleRunDocRef.id)
133+
)
126134

127135
Firebase.firestore.runBatch { batch ->
128-
// TODO update single run list
136+
// Create single run record
137+
batch.set(singleRunDocRef, singleRunData)
129138

130-
// update total time
131-
val updateRunUserData = hashMapOf(
132-
KEY_TOTAL_TIME_MS to newTotalTimeMillisecond,
133-
KEY_SINGLE_RUN_ID_LIST to FieldValue.arrayUnion("This is test")
134-
)
139+
// update user statistics
135140
batch.update(runUserDocRef, updateRunUserData)
136141

137142
}
138143
.addOnSuccessListener {
139-
Log.d(PROFILE_VM_TAG, "")
144+
Log.d(PROFILE_VM_TAG, "Upload record successfully")
140145
syncAppUserStatistic()
141146
}
142147
}
@@ -152,6 +157,10 @@ class ProfileViewModel : ViewModel() {
152157
const val KEY_TOTAL_EN_CAL = "TotalEnergyCalories"
153158
const val KEY_TOTAL_TIME_MS = "TotalTimeMillisecond"
154159
const val KEY_SINGLE_RUN_ID_LIST = "SingleRunIDList"
160+
161+
const val KEY_SINGLE_RUN_TIME = "Time"
162+
const val KEY_SINGLE_RUN_TIMESTAMP = "Timestamp"
163+
155164
const val DEFAULT_TIME = "00:00:00"
156165
}
157166
}

android/canonical/app/src/main/java/com/google/samples/quickstart/canonical/RunFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class RunFragment : Fragment() {
8383
}
8484

8585
private fun getCurDateAndTime() : String {
86-
val date = SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.US).format(Date())
87-
Log.d(RUN_FRAGMENT_TAG,"record date $date")
86+
val date = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(Date())
87+
Log.d(RUN_FRAGMENT_TAG,"date $date")
8888
return date
8989
}
9090

android/canonical/app/src/main/java/com/google/samples/quickstart/canonical/StopwatchViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.google.samples.quickstart.canonical
33
import android.os.SystemClock
44
import androidx.lifecycle.MutableLiveData
55
import androidx.lifecycle.ViewModel
6-
import kotlinx.android.synthetic.main.fragment_run.*
76

87
class StopwatchViewModel : ViewModel() {
98

0 commit comments

Comments
 (0)