parent
625822766a
commit
e4ce9c147a
@ -1,4 +1,12 @@
|
|||||||
package iut.android.pierrepierre.model.Class
|
package iut.android.pierrepierre.model.Class
|
||||||
|
|
||||||
class User (var score: Int = 0, var nbMiss : Int = 0){
|
import iut.android.pierrepierre.model.DB.Entity.UserEntity
|
||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
|
|
||||||
|
class User (var id : String, var score: Int = 0, var nbMiss : Int = 0) : Serializable {
|
||||||
|
// User en UserEntity
|
||||||
|
fun User.toUserEntity(): UserEntity {
|
||||||
|
return UserEntity( id=this.id, score = this.score, nbMiss = this.nbMiss)
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package iut.android.pierrepierre.model.Viewmodel
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import iut.android.pierrepierre.model.Class.User
|
||||||
|
import iut.android.pierrepierre.model.DB.DAO.UserDAO
|
||||||
|
import iut.android.pierrepierre.model.DB.Entity.UserEntity
|
||||||
|
|
||||||
|
class UserViewModel(private val userDao: UserDAO) : ViewModel() {
|
||||||
|
|
||||||
|
private var user = User("0")
|
||||||
|
|
||||||
|
fun getUser(): User {
|
||||||
|
return user
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setUser(user : User) {
|
||||||
|
this.user = user
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateUserScore(score: Int) {
|
||||||
|
user.score = score
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getUserById(id: String): UserEntity? {
|
||||||
|
return userDao.getUserById(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserEntity en User
|
||||||
|
fun UserEntity.toUser(): User {
|
||||||
|
return User( id=this.id ,score = this.score, nbMiss = this.nbMiss)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue