-
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.
Firebase Storage 연결 및 MainActivity 수정
- Loading branch information
Showing
18 changed files
with
250 additions
and
123 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,42 @@ | ||
package com.dna.beyoureyes.model | ||
|
||
class FoodHistory(val label: String, val kcal: Int, val img:Int) { | ||
import android.net.Uri | ||
import android.util.Log | ||
import com.bumptech.glide.Glide | ||
import com.google.firebase.Firebase | ||
import com.google.firebase.Timestamp | ||
import com.google.firebase.firestore.DocumentSnapshot | ||
import com.google.firebase.storage.storage | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.tasks.await | ||
|
||
} | ||
class FoodHistory( | ||
val timestamp:Timestamp? = null, | ||
val kcal: Int? = null, | ||
val nutritions: List<Nutrition>, | ||
var imgUri: Uri? = null) { | ||
|
||
constructor(document: DocumentSnapshot) : this( | ||
timestamp = document.getTimestamp("date"), | ||
kcal = document.getLong("calories")?.toInt() ?:0, | ||
nutritions = listOf( | ||
Natrium(), Carbs(), Sugar(), Protein(), Fat(), SaturatedFat(), Cholesterol() | ||
).mapNotNull { type -> type.fromFirestore(document) }) | ||
{ | ||
val imgPath = document.getString("imgPath") | ||
// 이미지 Uri 로드는 파이어스토어와의 통신이 필요하므로 CouroutineScoope에서 정의하여 값 동기화 | ||
CoroutineScope(Dispatchers.Main).launch { | ||
imgUri = try { | ||
imgPath?.let { | ||
val storageRef = Firebase.storage.reference.child(it) | ||
storageRef.downloadUrl.await() // 비동기 작업을 동기적으로 기다림 | ||
} | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
null | ||
} | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.