se permite eliminar foto de perfil, y varios fixes
This commit is contained in:
parent
837b38ef97
commit
8a345fc59b
@ -18,4 +18,7 @@ interface ProfileApi {
|
||||
@POST("EditProfile/UpdateProfile")
|
||||
fun updateProfile(@Body updateProfileDto: UpdateProfileDto): Call<UserProfileDto>
|
||||
|
||||
@POST("EditProfile/RemoveProfileImage")
|
||||
fun removeCurrentProfilePicture(): Call<Void>
|
||||
|
||||
}
|
||||
@ -67,4 +67,21 @@ class ProfileRepositoryImpl @Inject constructor(
|
||||
emit(Resource.Error(Resource.Error.ErrorType.NetworkError))
|
||||
}
|
||||
}
|
||||
|
||||
override fun removeProfileImage(): Flow<Resource<Boolean>> = flow {
|
||||
emit(Resource.Loading())
|
||||
|
||||
try {
|
||||
val response = profileApi.removeCurrentProfilePicture().awaitResponse()
|
||||
|
||||
if(response.isSuccessful) {
|
||||
emit(Resource.Success(true))
|
||||
} else {
|
||||
emit(Resource.Error(Resource.Error.mapErrorCode(response.code())))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("ProfileRepositoryImpl", e.message.toString())
|
||||
emit(Resource.Error(Resource.Error.ErrorType.NetworkError))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,4 +12,6 @@ interface ProfileRepository {
|
||||
fun setProfileImage(image: Image): Flow<Resource<Boolean>>
|
||||
|
||||
fun updateProfile(newDisplayName: String, newDescription: String): Flow<Resource<Boolean>>
|
||||
|
||||
fun removeProfileImage(): Flow<Resource<Boolean>>
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.isolaatti.profile.domain.use_case
|
||||
|
||||
import com.isolaatti.profile.domain.ProfileRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class RemoveProfilePicture @Inject constructor(private val profileRepository: ProfileRepository) {
|
||||
|
||||
operator fun invoke() = profileRepository.removeProfileImage()
|
||||
}
|
||||
@ -11,6 +11,7 @@ import com.isolaatti.profile.domain.entity.UserProfile
|
||||
import com.isolaatti.profile.domain.use_case.FollowUser
|
||||
import com.isolaatti.profile.domain.use_case.GetProfile
|
||||
import com.isolaatti.profile.domain.use_case.GetProfilePosts
|
||||
import com.isolaatti.profile.domain.use_case.RemoveProfilePicture
|
||||
import com.isolaatti.profile.domain.use_case.SetProfileImage
|
||||
import com.isolaatti.utils.Resource
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@ -26,7 +27,8 @@ class ProfileViewModel @Inject constructor(
|
||||
private val getProfileUseCase: GetProfile,
|
||||
private val getProfilePostsUseCase: GetProfilePosts,
|
||||
private val setProfileImageUC: SetProfileImage,
|
||||
private val followUserUC: FollowUser
|
||||
private val followUserUC: FollowUser,
|
||||
private val removeProfilePictureUC: RemoveProfilePicture
|
||||
) : PostListingViewModelBase() {
|
||||
private val _profile = MutableLiveData<UserProfile>()
|
||||
val profile: LiveData<UserProfile> get() = _profile
|
||||
@ -143,4 +145,18 @@ class ProfileViewModel @Inject constructor(
|
||||
fun setProfile(profile: UserProfile) {
|
||||
_profile.value = profile
|
||||
}
|
||||
|
||||
fun removeCurrentProfileImage() {
|
||||
viewModelScope.launch {
|
||||
removeProfilePictureUC().onEach {
|
||||
when(it) {
|
||||
is Resource.Error -> {}
|
||||
is Resource.Loading -> {}
|
||||
is Resource.Success -> {
|
||||
_profile.postValue(_profile.value?.copy(profileImageId = null))
|
||||
}
|
||||
}
|
||||
}.flowOn(Dispatchers.IO).launchIn(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -292,18 +292,25 @@ class ProfileMainFragment : Fragment() {
|
||||
.setTitle(R.string.remove_photo)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.yes_continue) { _, _ ->
|
||||
// TODO remove image here
|
||||
viewModel.removeCurrentProfileImage()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private lateinit var postListingRecyclerViewAdapterWiring: PostListingRecyclerViewAdapterWiring
|
||||
|
||||
|
||||
// counter variable to prevent calling appBarLayout.totalScrollRange many times
|
||||
private var i = 0
|
||||
private fun setupCollapsingBar() {
|
||||
|
||||
viewBinding.topAppBarLayout.addOnOffsetChangedListener { appBarLayout, verticalOffset ->
|
||||
if (scrollRange == -1) scrollRange = appBarLayout.totalScrollRange
|
||||
// prevent calling appBarLayout.totalScrollRange many times
|
||||
if (i == 30) {
|
||||
scrollRange = appBarLayout.totalScrollRange
|
||||
i = 0
|
||||
} else {
|
||||
i++
|
||||
}
|
||||
|
||||
if (scrollRange + verticalOffset == 0) {
|
||||
viewBinding.collapsingToolbarLayout.title = viewModel.profile.value?.name
|
||||
isShow = true
|
||||
|
||||
@ -106,20 +106,11 @@
|
||||
android:maxLines="4"
|
||||
android:textAlignment="center"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/description_options_button"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/play_button_container"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Hi there, I am software developer!" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/description_options_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
style="?attr/materialIconButtonStyle"
|
||||
app:icon="@drawable/baseline_more_horiz_24"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:title="Mark as read" />
|
||||
<item android:title="Remove all" />
|
||||
<!-- <item android:title="Mark as read" />-->
|
||||
<!-- <item android:title="Remove all" />-->
|
||||
</menu>
|
||||
Loading…
x
Reference in New Issue
Block a user