Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#147 follower #167

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 80 additions & 106 deletions app/src/main/java/com/jjbaksa/jjbaksa/ui/follower/FollowerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,41 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {
get() = R.layout.activity_follower

private lateinit var followerAdapter: FollowerAdapter
private lateinit var followRequestAdapter: FollowRequestAdapter
private lateinit var userAdapter: FollowerAdapter
private lateinit var followRequestAdapter: FollowRequestAdapter
private lateinit var recentlyActiveAdapter: RecentlyActiveAdapter
private val viewModel: FollowerViewModel by viewModels()

override fun initView() {
binding.lifecycleOwner = this
viewModel.getFollower(null, 20)
viewModel.followRequestReceived(null, 20)
viewModel.followRequestSend(null, 20)
viewModel.getBeRequestedFollowers(null, 20)
viewModel.getRequestedFollowers(null, 20)
viewModel.getRecentlyActiveFollowers(20, null)

followerAdapter = FollowerAdapter({
toggleFollow(it)
}) {
viewModel.followRequest(it.account)
}, {
viewModel.followerDelete(it.account)
}, {
goToFollowerActivity(it)
}
followRequestAdapter = FollowRequestAdapter({
viewModel.followRequestAccept(it.id)
}) {
viewModel.followRequestReject(it.id)
}
})

userAdapter = FollowerAdapter({
toggleFollow(it)
}) {
viewModel.followRequest(it.account)
}, {
viewModel.followerDelete(it.account)
}, {
goToFollowerActivity(it)
}
})

followRequestAdapter = FollowRequestAdapter({
viewModel.followRequestAccept(it.id)
}, {
viewModel.followRequestReject(it.id)
}, {
viewModel.followRequestCancel(it.id)
})

recentlyActiveAdapter = RecentlyActiveAdapter()

Expand All @@ -61,70 +68,62 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {
}

override fun subscribe() {
binding.rvAllFollower.addOnScrollListener(
object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val itemCount = binding.rvAllFollower.layoutManager?.itemCount ?: 0
val lastPosition =
binding.rvAllFollower.layoutManager?.let { it as LinearLayoutManager }
?.findLastCompletelyVisibleItemPosition() ?: 0

if (lastPosition != -1 && lastPosition >= (itemCount - 1) && viewModel.followerHasMore.value == true) {
viewModel.followerHasMore.value = false
viewModel.getFollower(
null,
20
)
binding.loadingView.setLoading(true)
}
binding.rvAllFollower.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val itemCount = binding.rvAllFollower.layoutManager?.itemCount ?: 0
val lastPosition =
binding.rvAllFollower.layoutManager?.let { it as LinearLayoutManager }
?.findLastCompletelyVisibleItemPosition() ?: 0

if (lastPosition != -1 && lastPosition >= (itemCount - 1) && viewModel.followerHasMore.value == true) {
viewModel.followerHasMore.value = false
viewModel.getFollower(
null, 20
)
binding.loadingView.setLoading(true)
}
})

binding.rvRequestFollow.addOnScrollListener(
object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val itemCount = binding.rvRequestFollow.layoutManager?.itemCount ?: 0
val lastPosition =
binding.rvAllFollower.layoutManager?.let { it as LinearLayoutManager }
?.findLastCompletelyVisibleItemPosition() ?: 0

if (lastPosition != -1 && lastPosition >= (itemCount - 1) && viewModel.receivedFollowRequestHasMore.value == true && viewModel.sendFollowRequestHasMore.value == true) {
viewModel.receivedFollowRequestHasMore.value = false
viewModel.sendFollowRequestHasMore.value = false
viewModel.followRequestReceived(
null,
20
)
viewModel.followRequestSend(
null,
20
)
binding.loadingView.setLoading(true)
}
}
})

binding.rvRequestFollow.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val itemCount = binding.rvRequestFollow.layoutManager?.itemCount ?: 0
val lastPosition =
binding.rvAllFollower.layoutManager?.let { it as LinearLayoutManager }
?.findLastCompletelyVisibleItemPosition() ?: 0

if (lastPosition != -1 && lastPosition >= (itemCount - 1) && viewModel.receivedFollowRequestHasMore.value == true && viewModel.sendFollowRequestHasMore.value == true) {
viewModel.receivedFollowRequestHasMore.value = false
viewModel.sendFollowRequestHasMore.value = false
viewModel.getBeRequestedFollowers(
null, 20
)
viewModel.getRequestedFollowers(
null, 20
)
binding.loadingView.setLoading(true)
}
})

binding.rvSearchResult.addOnScrollListener(
object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val itemCount = binding.rvSearchResult.layoutManager?.itemCount ?: 0
val lastPosition =
binding.rvAllFollower.layoutManager?.let { it as LinearLayoutManager }
?.findLastCompletelyVisibleItemPosition() ?: 0

if (lastPosition != -1 && lastPosition >= (itemCount - 1)) {
viewModel.getUserSearch(
viewModel.searchKeyword.value!!,
20,
userAdapter.currentList.last().id
)
binding.loadingView.setLoading(true)
}
}
})

binding.rvSearchResult.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val itemCount = binding.rvSearchResult.layoutManager?.itemCount ?: 0
val lastPosition =
binding.rvAllFollower.layoutManager?.let { it as LinearLayoutManager }
?.findLastCompletelyVisibleItemPosition() ?: 0

if (lastPosition != -1 && lastPosition >= (itemCount - 1)) {
viewModel.getUserSearch(
viewModel.searchKeyword.value!!, 20, userAdapter.currentList.last().id
)
binding.loadingView.setLoading(true)
}
})
}
})

binding.rvRecentlyActiveFollower.addOnScrollListener(
object : RecyclerView.OnScrollListener() {
binding.rvRecentlyActiveFollower.addOnScrollListener(object :
RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val itemCount = binding.rvRecentlyActiveFollower.layoutManager?.itemCount ?: 0
val lastPosition =
Expand All @@ -134,8 +133,7 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {
if (lastPosition != -1 && lastPosition >= (itemCount - 1) && viewModel.recentlyActiveHasMore.value == true) {
viewModel.recentlyActiveHasMore.value = false
viewModel.getRecentlyActiveFollowers(
20,
recentlyActiveAdapter.currentList.last().id
20, recentlyActiveAdapter.currentList.last().id
)
binding.loadingView.setLoading(true)
}
Expand All @@ -161,29 +159,17 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {

viewModel.followerList.observe(this) {
binding.loadingView.setLoading(false)
if (it.content.isEmpty() && followerAdapter.currentList.isEmpty()) {
followerAdapter.submitList(emptyList())
} else {
followerAdapter.submitList(followerAdapter.currentList + it.content)
}
followerAdapter.submitList(followerAdapter.currentList + it.content)
}

viewModel.receivedFollowRequestList.observe(this) {
viewModel.beRequestedFollowers.observe(this) {
binding.loadingView.setLoading(false)
if (it.content.isEmpty() && followRequestAdapter.currentList.isEmpty()) {
followRequestAdapter.submitList(emptyList())
} else {
followRequestAdapter.submitList(followRequestAdapter.currentList + it.content)
}
followRequestAdapter.submitList(followRequestAdapter.currentList + it.content)
}

viewModel.sendFollowRequestList.observe(this) {
viewModel.requestFollowers.observe(this) {
binding.loadingView.setLoading(false)
if (it.content.isEmpty() && followRequestAdapter.currentList.isEmpty()) {
followRequestAdapter.submitList(emptyList())
} else {
followRequestAdapter.submitList(followRequestAdapter.currentList + it.content)
}
followRequestAdapter.submitList(followRequestAdapter.currentList + it.content)
}

viewModel.userList.observe(this) {
Expand All @@ -197,11 +183,7 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {

viewModel.recentlyActiveList.observe(this) {
binding.loadingView.setLoading(false)
if (it.content.isEmpty() && recentlyActiveAdapter.currentList.isEmpty()) {
recentlyActiveAdapter.submitList(emptyList())
} else {
recentlyActiveAdapter.submitList(recentlyActiveAdapter.currentList + it.content)
}
recentlyActiveAdapter.submitList(recentlyActiveAdapter.currentList + it.content)
}

viewModel.cursor.observe(this) {
Expand Down Expand Up @@ -236,14 +218,6 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {
}
}

private fun toggleFollow(user: User) {
if (viewModel.unfollowedUsers.contains(user.account)) {
viewModel.followRequest(user.account)
} else {
viewModel.followerDelete(user.account)
}
}

private fun goToFollowerActivity(user: User) {
val intent = Intent(this, FollowerProfileActivity::class.java).apply {
putExtra("nickname", user.nickname)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import com.jjbaksa.jjbaksa.R
import com.jjbaksa.jjbaksa.databinding.ItemFollowBinding

class FollowRequestAdapter(
private val onAcceptClicked: (FollowContent) -> Unit,
private val onDeleteClicked: (FollowContent) -> Unit,
private val onAcceptButtonClicked: (FollowContent) -> Unit,
private val onDeleteButtonClicked: (FollowContent) -> Unit,
private val onRequestedButtonClicked: (FollowContent) -> Unit
) : ListAdapter<FollowContent, FollowRequestAdapter.ViewHolder>(diffUtil) {

inner class ViewHolder(private val binding: ItemFollowBinding) :
Expand All @@ -27,15 +28,23 @@ class FollowRequestAdapter(
.circleCrop()
.into(binding.ivProfile)

binding.acceptButton.isVisible = item.user.followedType == NONE
binding.deleteButton.isVisible = item.user.followedType == NONE
binding.requestedButton.isVisible = item.user.followedType == REQUEST_SENT
binding.followingButton.isVisible = false
binding.followButton.isVisible = false
binding.acceptButton.isVisible = true
binding.deleteButton.isVisible = true

binding.acceptButton.setOnClickListener {
onAcceptClicked(item)
onAcceptButtonClicked(item)
submitList(currentList.filter { it != item })
}
binding.deleteButton.setOnClickListener {
onDeleteClicked(item)
onDeleteButtonClicked(item)
submitList(currentList.filter { it != item })
}
binding.requestedButton.setOnClickListener {
onRequestedButtonClicked(item)
submitList(currentList.filter { it != item })
}
}
}
Expand Down Expand Up @@ -68,5 +77,8 @@ class FollowRequestAdapter(
return oldItem == newItem
}
}
const val FOLLOWED = "FOLLOWED"
const val NONE = "NONE"
const val REQUEST_SENT = "REQUEST_SENT"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import com.jjbaksa.jjbaksa.R
import com.jjbaksa.jjbaksa.databinding.ItemFollowBinding

class FollowerAdapter(
private val onButtonClicked: (User) -> Unit,
private val onFollowButtonClicked: (User) -> Unit,
private val onFollowingButtonClicked: (User) -> Unit,
private val onItemClicked: (User) -> Unit
) : ListAdapter<User, FollowerAdapter.ViewHolder>(diffUtil) {

Expand All @@ -28,27 +29,23 @@ class FollowerAdapter(
.circleCrop()
.into(binding.ivProfile)

binding.followingButton.setOnClickListener {
onButtonClicked(item)
binding.followingButton.isVisible = false
binding.followButton.isVisible = true
binding.requestedButton.isVisible = false
}
binding.followingButton.isVisible = item.followedType == FOLLOWED
binding.followButton.isVisible = item.followedType == NONE
binding.requestedButton.isVisible = item.followedType == REQUEST_SENT

binding.followButton.setOnClickListener {
onButtonClicked(item)
binding.followingButton.isVisible = false
binding.followButton.isVisible = false
binding.requestedButton.isVisible = true
onFollowButtonClicked(item)
submitList(currentList.filter { it != item })
}

binding.followingButton.setOnClickListener {
onFollowingButtonClicked(item)
submitList(currentList.filter { it != item })
}

binding.clItemFollower.setOnClickListener {
onItemClicked(item)
}
binding.requestedButton.setOnClickListener {
onButtonClicked(item)
binding.followingButton.isVisible = false
binding.followButton.isVisible = true
binding.requestedButton.isVisible = false
}
}
}

Expand Down Expand Up @@ -77,5 +74,9 @@ class FollowerAdapter(
return oldItem == newItem
}
}

const val FOLLOWED = "FOLLOWED"
const val NONE = "NONE"
const val REQUEST_SENT = "REQUEST_SENT"
}
}
Loading
Loading