mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-18 12:02:23 +00:00
display avatar again
This commit is contained in:
parent
0be269ee7e
commit
0a155a6840
9 changed files with 62 additions and 21 deletions
|
|
@ -5,13 +5,13 @@ import com.squareup.moshi.JsonClass
|
|||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class Preferences: AvatarPreferences {
|
||||
override val hair: Hair? = null
|
||||
override val costume: Boolean = false
|
||||
override val sleep: Boolean = false
|
||||
override val shirt: String? = null
|
||||
override val skin: String? = null
|
||||
override val size: String? = null
|
||||
override val background: String? = null
|
||||
override val chair: String? = null
|
||||
override val disableClasses: Boolean = false
|
||||
override var hair: Hair? = null
|
||||
override var costume: Boolean = false
|
||||
override var sleep: Boolean = false
|
||||
override var shirt: String? = null
|
||||
override var skin: String? = null
|
||||
override var size: String? = null
|
||||
override var background: String? = null
|
||||
override var chair: String? = null
|
||||
override var disableClasses: Boolean = false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ open class Gear {
|
|||
@JsonClass(generateAdapter = true)
|
||||
class Items {
|
||||
var gear: Gear? = null
|
||||
|
||||
var currentMount: String? = null
|
||||
var currentPet: String? = null
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
|
|
@ -21,8 +24,10 @@ class Profile {
|
|||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class User: Avatar {
|
||||
override var currentMount: String? = null
|
||||
override var currentPet: String? = null
|
||||
override val currentMount: String?
|
||||
get() = items?.currentMount
|
||||
override val currentPet: String?
|
||||
get() = items?.currentPet
|
||||
override var sleep: Boolean = false
|
||||
override var stats: Stats? = null
|
||||
override var preferences: Preferences? = null
|
||||
|
|
|
|||
|
|
@ -1,12 +1,21 @@
|
|||
package com.habitrpg.wearos.habitica.ui.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.viewModels
|
||||
import com.habitrpg.wearos.habitica.databinding.ActivityAvatarBinding
|
||||
import com.habitrpg.wearos.habitica.ui.viewmodels.AvatarViewModel
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AvatarActivity: BaseActivity<ActivityAvatarBinding>() {
|
||||
val viewModel: AvatarViewModel by viewModels()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
binding = ActivityAvatarBinding.inflate(layoutInflater)
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
viewModel.user.observe(this) {
|
||||
binding.root.setAvatar(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||
AppCompatResources.getDrawable(this, R.drawable.ic_avatar),
|
||||
ContextCompat.getColor(this, R.color.brand_400)
|
||||
) {
|
||||
|
||||
openAvatarActivity()
|
||||
},
|
||||
MenuItem(
|
||||
"Stats",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package com.habitrpg.wearos.habitica.ui.viewmodels
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.habitrpg.wearos.habitica.data.repositories.UserRepository
|
||||
import com.habitrpg.wearos.habitica.models.User
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class AvatarViewModel @Inject constructor(userRepository: UserRepository) : BaseViewModel(userRepository) {
|
||||
val _user = MutableLiveData<User>()
|
||||
val user: LiveData<User> = _user
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
_user.value = userRepository.retrieveUser()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,4 +3,4 @@ package com.habitrpg.wearos.habitica.ui.viewmodels
|
|||
import androidx.lifecycle.ViewModel
|
||||
import com.habitrpg.wearos.habitica.data.repositories.UserRepository
|
||||
|
||||
open class BaseViewModel(val userRepository: UserRepository): ViewModel()
|
||||
open class BaseViewModel(val userRepository: UserRepository): ViewModel()
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.habitrpg.wearos.habitica.ui.viewmodels
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.habitrpg.wearos.habitica.data.repositories.UserRepository
|
||||
|
|
@ -10,11 +11,12 @@ import javax.inject.Inject
|
|||
|
||||
@HiltViewModel
|
||||
class MainViewModel @Inject constructor(userRepository: UserRepository) : BaseViewModel(userRepository) {
|
||||
val user = MutableLiveData<User>()
|
||||
val _user = MutableLiveData<User>()
|
||||
val user: LiveData<User> = _user
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
user.value = userRepository.retrieveUser()
|
||||
_user.value = userRepository.retrieveUser()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.habitrpg.wearos.habitica.ui.viewmodels
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
|
|
@ -17,12 +18,14 @@ class TaskListViewModel @Inject constructor(
|
|||
private val taskRepository: TaskRepository,
|
||||
userRepository: UserRepository
|
||||
) : BaseViewModel(userRepository) {
|
||||
val tasks = MutableLiveData<List<Task>>()
|
||||
val _tasks = MutableLiveData<List<Task>>()
|
||||
val tasks: LiveData<List<Task>> = _tasks
|
||||
|
||||
val taskType = TaskType.from(savedStateHandle.get<String>("task_type"))
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
tasks.value = taskRepository.retrieveTasks()?.tasks?.values?.filter {
|
||||
_tasks.value = taskRepository.retrieveTasks()?.tasks?.values?.filter {
|
||||
it.type == taskType
|
||||
}?.toList()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
<com.habitrpg.common.habitica.views.AvatarView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center">
|
||||
|
||||
</LinearLayout>
|
||||
</com.habitrpg.common.habitica.views.AvatarView>
|
||||
Loading…
Reference in a new issue