-
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.
Browse files
Browse the repository at this point in the history
[Feature] 타이머를 종료할 때 StudyDay 기록을 firebase에 전송합니다.
- Loading branch information
Showing
8 changed files
with
106 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<resources> | ||
<string name="app_name">HongikYeolgong2</string> | ||
</resources> | ||
<string name="app_name">홍익열공이</string> | ||
</resources> |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<resources xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<style name="Theme.HongikYeolgong2" parent="Theme.AppCompat.DayNight.NoActionBar" /> | ||
<style name="Theme.HongikYeolgong2" parent="Theme.AppCompat.DayNight.NoActionBar"> | ||
<item name="android:windowSplashScreenBackground" tools:ignore="NewApi">#0C0D11</item> | ||
</style> | ||
</resources> |
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
51 changes: 51 additions & 0 deletions
51
main-data/src/main/java/com/teamhy2/main/data/repository/DefaultStudyDayRepository.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,51 @@ | ||
package com.teamhy2.main.data.repository | ||
|
||
import com.google.firebase.firestore.CollectionReference | ||
import com.google.firebase.firestore.DocumentReference | ||
import com.google.firebase.firestore.FirebaseFirestore | ||
import com.teamhy2.main.domain.StudyDayRepository | ||
import com.teamhy2.main.model.StudyDay | ||
import com.teamhy2.main.model.toMap | ||
import kotlinx.coroutines.tasks.await | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
import java.time.LocalTime | ||
import java.time.temporal.ChronoUnit | ||
import javax.inject.Inject | ||
|
||
class DefaultStudyDayRepository | ||
@Inject | ||
constructor() : StudyDayRepository { | ||
private val firestore = FirebaseFirestore.getInstance() | ||
|
||
override suspend fun addStudyDay( | ||
uid: String, | ||
startTime: String, | ||
) { | ||
val now = LocalDateTime.now() | ||
var startTimeParsed = LocalDateTime.of(now.toLocalDate(), LocalTime.parse(startTime)) | ||
|
||
if (startTimeParsed.isAfter(now)) { | ||
startTimeParsed = startTimeParsed.minusDays(1) | ||
} | ||
|
||
val duration: Long = ChronoUnit.SECONDS.between(startTimeParsed, now) | ||
|
||
val studyDay = | ||
StudyDay( | ||
date = LocalDate.now(), | ||
secondDuration = duration, | ||
) | ||
|
||
val userDocumentReference: DocumentReference = | ||
firestore.collection(USERS_COLLECTION).document(uid) | ||
val studyDayCollection: CollectionReference = | ||
userDocumentReference.collection(STUDYDAY_COLLECTION) | ||
studyDayCollection.add(studyDay.toMap()).await() | ||
} | ||
|
||
companion object { | ||
private const val USERS_COLLECTION = "User" | ||
private const val STUDYDAY_COLLECTION = "StudyDay" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
main-domain/src/main/java/com/teamhy2/main/domain/StudyDayRepository.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.teamhy2.main.domain | ||
|
||
interface StudyDayRepository { | ||
suspend fun addStudyDay( | ||
uid: String, | ||
startTime: String, | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
main-domain/src/main/java/com/teamhy2/main/model/StudyDay.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,15 @@ | ||
package com.teamhy2.main.model | ||
|
||
import java.time.LocalDate | ||
|
||
data class StudyDay( | ||
val date: LocalDate, | ||
val secondDuration: Long, | ||
) | ||
|
||
fun StudyDay.toMap(): Map<String, Any> { | ||
return mapOf( | ||
"date" to this.date.toString(), | ||
"secondDuration" to this.secondDuration, | ||
) | ||
} |
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
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