WIP follow profile
This commit is contained in:
parent
38e46d72f2
commit
1d358a403b
@ -0,0 +1,8 @@
|
|||||||
|
package com.isolaatti.followers.domain
|
||||||
|
|
||||||
|
enum class FollowingState {
|
||||||
|
FollowingThisUser,
|
||||||
|
MutuallyFollowing,
|
||||||
|
ThisUserIsFollowingMe,
|
||||||
|
NotMutuallyFollowing
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData
|
|||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import com.isolaatti.followers.domain.FollowingState
|
||||||
import com.isolaatti.posting.posts.data.remote.FeedDto
|
import com.isolaatti.posting.posts.data.remote.FeedDto
|
||||||
import com.isolaatti.posting.posts.data.remote.FeedFilterDto
|
import com.isolaatti.posting.posts.data.remote.FeedFilterDto
|
||||||
import com.isolaatti.posting.posts.presentation.PostListingViewModelBase
|
import com.isolaatti.posting.posts.presentation.PostListingViewModelBase
|
||||||
@ -32,11 +33,23 @@ class ProfileViewModel @Inject constructor(private val getProfileUseCase: GetPro
|
|||||||
|
|
||||||
var profileId: Int = 0
|
var profileId: Int = 0
|
||||||
|
|
||||||
|
val followingState: MutableLiveData<FollowingState> = MutableLiveData()
|
||||||
|
|
||||||
fun getProfile() {
|
fun getProfile() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
getProfileUseCase(profileId).onEach {
|
getProfileUseCase(profileId).onEach {
|
||||||
if(it is Resource.Success) {
|
if(it is Resource.Success) {
|
||||||
_profile.postValue(it.data!!)
|
_profile.postValue(it.data!!)
|
||||||
|
followingState.postValue(
|
||||||
|
it.data.let {user->
|
||||||
|
when {
|
||||||
|
user.followingThisUser && user.thisUserIsFollowingMe -> FollowingState.MutuallyFollowing
|
||||||
|
user.followingThisUser -> FollowingState.FollowingThisUser
|
||||||
|
user.thisUserIsFollowingMe -> FollowingState.ThisUserIsFollowingMe
|
||||||
|
else -> FollowingState.NotMutuallyFollowing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}.flowOn(Dispatchers.IO).launchIn(this)
|
}.flowOn(Dispatchers.IO).launchIn(this)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||||||
import com.isolaatti.BuildConfig
|
import com.isolaatti.BuildConfig
|
||||||
import com.isolaatti.R
|
import com.isolaatti.R
|
||||||
import com.isolaatti.databinding.FragmentDiscussionsBinding
|
import com.isolaatti.databinding.FragmentDiscussionsBinding
|
||||||
|
import com.isolaatti.followers.domain.FollowingState
|
||||||
import com.isolaatti.home.FeedFragment
|
import com.isolaatti.home.FeedFragment
|
||||||
import com.isolaatti.posting.PostViewerActivity
|
import com.isolaatti.posting.PostViewerActivity
|
||||||
import com.isolaatti.posting.comments.presentation.BottomSheetPostComments
|
import com.isolaatti.posting.comments.presentation.BottomSheetPostComments
|
||||||
@ -68,6 +69,27 @@ class ProfileMainFragment : Fragment() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val followingStateObserver: Observer<FollowingState> = Observer {
|
||||||
|
when(it) {
|
||||||
|
FollowingState.FollowingThisUser -> {
|
||||||
|
viewBinding.textViewFollowingState.setText(R.string.following_user)
|
||||||
|
viewBinding.followButton.setText(R.string.unfollow)
|
||||||
|
}
|
||||||
|
FollowingState.MutuallyFollowing -> {
|
||||||
|
viewBinding.textViewFollowingState.setText(R.string.mutually_following)
|
||||||
|
viewBinding.followButton.setText(R.string.unfollow)
|
||||||
|
}
|
||||||
|
FollowingState.ThisUserIsFollowingMe -> {
|
||||||
|
viewBinding.textViewFollowingState.setText(R.string.following_you)
|
||||||
|
viewBinding.followButton.setText(R.string.follow)
|
||||||
|
}
|
||||||
|
FollowingState.NotMutuallyFollowing -> {
|
||||||
|
viewBinding.textViewFollowingState.text = ""
|
||||||
|
viewBinding.followButton.setText(R.string.follow)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private lateinit var postListingRecyclerViewAdapterWiring: PostListingRecyclerViewAdapterWiring
|
private lateinit var postListingRecyclerViewAdapterWiring: PostListingRecyclerViewAdapterWiring
|
||||||
|
|
||||||
|
|
||||||
@ -117,6 +139,7 @@ class ProfileMainFragment : Fragment() {
|
|||||||
private fun setObservers() {
|
private fun setObservers() {
|
||||||
viewModel.profile.observe(viewLifecycleOwner, profileObserver)
|
viewModel.profile.observe(viewLifecycleOwner, profileObserver)
|
||||||
viewModel.posts.observe(viewLifecycleOwner, postsObserver)
|
viewModel.posts.observe(viewLifecycleOwner, postsObserver)
|
||||||
|
viewModel.followingState.observe(viewLifecycleOwner, followingStateObserver)
|
||||||
viewModel.loadingPosts.observe(viewLifecycleOwner) {
|
viewModel.loadingPosts.observe(viewLifecycleOwner) {
|
||||||
viewBinding.swipeToRefresh.isRefreshing = it
|
viewBinding.swipeToRefresh.isRefreshing = it
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,12 +70,13 @@
|
|||||||
tools:text="Following this profile" />
|
tools:text="Following this profile" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/follow_button"
|
||||||
style="?attr/materialIconButtonFilledTonalStyle"
|
style="?attr/materialIconButtonFilledTonalStyle"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
|
||||||
|
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/text_view_following_state" />
|
app:layout_constraintTop_toBottomOf="@id/text_view_following_state" />
|
||||||
|
|||||||
@ -57,4 +57,6 @@
|
|||||||
<string name="mutually_following">Mutually following</string>
|
<string name="mutually_following">Mutually following</string>
|
||||||
<string name="following_you">Following you</string>
|
<string name="following_you">Following you</string>
|
||||||
<string name="user_link">User link</string>
|
<string name="user_link">User link</string>
|
||||||
|
<string name="follow">Follow</string>
|
||||||
|
<string name="unfollow">Unfollow</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
x
Reference in New Issue
Block a user