Skip to content

Commit

Permalink
adapt homescreen viewmodel and create profile viewmodel to the reposi…
Browse files Browse the repository at this point in the history
…tory
  • Loading branch information
yoan committed May 29, 2024
1 parent cd17061 commit 5d7d998
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ constructor(
followedTagFilter = getTagsAndSubTags(_followedTags.value).toList()
sectionTags = repository.getSubTags(sectionTagId)
semesterTags = repository.getSubTags(semesterTagId)
val profilePictureFile = repository.getUserProfilePicture(userId)
val pictureByteArray = repository.getUserProfilePicture(userId)
_profilePicture.value =
if (profilePictureFile != null) {
BitmapFactory.decodeStream(profilePictureFile.inputStream())
if (pictureByteArray != null) {
BitmapFactory.decodeByteArray(pictureByteArray, 0, pictureByteArray.size)
} else {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.github.swent.echo.data.model.Tag
import com.github.swent.echo.data.model.UserProfile
import com.github.swent.echo.data.repository.Repository
import dagger.hilt.android.lifecycle.HiltViewModel
import java.io.File
import java.io.ByteArrayOutputStream
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand Down Expand Up @@ -100,10 +100,14 @@ constructor(
_tagList.value = userProfile.tags
_committeeMember.value = userProfile.committeeMember
_associationSubscriptions.value = userProfile.associationsSubscriptions
val pictureFile = repository.getUserProfilePicture(userId)
val pictureByteArray = repository.getUserProfilePicture(userId)
_picture.value =
if (pictureFile != null) {
BitmapFactory.decodeStream(pictureFile.inputStream())
if (pictureByteArray != null) {
BitmapFactory.decodeByteArray(
pictureByteArray,
0,
pictureByteArray.size
)
} else {
null
}
Expand Down Expand Up @@ -140,18 +144,9 @@ constructor(
if (picture.value == null) {
repository.deleteUserProfilePicture(userId)
} else {
val pictureFile =
File.createTempFile(
userId,
".jpeg",
null
) // the cache directory is used by default
picture.value!!.compress(
Bitmap.CompressFormat.JPEG,
100,
pictureFile.outputStream()
)
repository.setUserProfilePicture(userId, pictureFile)
val pictureStream = ByteArrayOutputStream()
picture.value!!.compress(Bitmap.CompressFormat.JPEG, 100, pictureStream)
repository.setUserProfilePicture(userId, pictureStream.toByteArray())
}
}
}
Expand Down

0 comments on commit 5d7d998

Please sign in to comment.