oculta boton de agregar imagen en fragmento de imagenes
This commit is contained in:
parent
1767cfb4ee
commit
36c25a37d6
@ -3,6 +3,7 @@ package com.isolaatti.images.image_list.presentation
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.isolaatti.auth.domain.AuthRepository
|
||||
import com.isolaatti.images.common.domain.entity.Image
|
||||
import com.isolaatti.images.common.domain.repository.ImagesRepository
|
||||
import com.isolaatti.utils.Resource
|
||||
@ -16,7 +17,7 @@ import javax.inject.Inject
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
@HiltViewModel
|
||||
class ImageListViewModel @Inject constructor(private val imagesRepository: ImagesRepository) : ViewModel() {
|
||||
class ImageListViewModel @Inject constructor(private val imagesRepository: ImagesRepository, private val authRepository: AuthRepository) : ViewModel() {
|
||||
|
||||
enum class Event {
|
||||
REMOVED_IMAGE, ADDED_IMAGE_BEGINNING
|
||||
@ -31,6 +32,8 @@ class ImageListViewModel @Inject constructor(private val imagesRepository: Image
|
||||
private var loadedFirstTime = false
|
||||
var userId by Delegates.notNull<Int>()
|
||||
|
||||
val isUserItself: MutableLiveData<Boolean> = MutableLiveData()
|
||||
|
||||
private val list: List<Image> get() {
|
||||
return liveList.value ?: listOf()
|
||||
}
|
||||
@ -95,4 +98,12 @@ class ImageListViewModel @Inject constructor(private val imagesRepository: Image
|
||||
}.flowOn(Dispatchers.IO).launchIn(this)
|
||||
}
|
||||
}
|
||||
|
||||
fun getUserId() {
|
||||
viewModelScope.launch {
|
||||
authRepository.getUserId().onEach {
|
||||
isUserItself.postValue(userId == it)
|
||||
}.flowOn(Dispatchers.IO).launchIn(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -95,6 +95,7 @@ class ImagesFragment : Fragment() {
|
||||
SOURCE_SQUAD -> {}
|
||||
SOURCE_PROFILE -> {
|
||||
viewModel.userId = arguments.sourceId.toInt()
|
||||
viewModel.getUserId()
|
||||
viewModel.loadNext()
|
||||
}
|
||||
}
|
||||
@ -239,6 +240,14 @@ class ImagesFragment : Fragment() {
|
||||
deletingImagesDialog = null
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.isUserItself.observe(viewLifecycleOwner) {
|
||||
setupUiForUser(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupUiForUser(isUserItSelf: Boolean) {
|
||||
viewBinding.newPictureButton.visibility = if(isUserItSelf) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@ -42,6 +42,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
app:srcCompat="@drawable/baseline_add_24"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
android:contentDescription="@string/upload_a_picture" />
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user