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 #157

Merged
merged 7 commits into from
Jan 31, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jjbaksa.jjbaksa.ui.follower

import android.content.Intent
import android.view.View
import android.widget.ImageView
import com.jjbaksa.jjbaksa.R
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -25,11 +26,6 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {
private lateinit var followRequestAdapter: FollowRequestAdapter
private lateinit var userAdapter: FollowerAdapter
private lateinit var recentlyActiveAdapter: RecentlyActiveAdapter
private lateinit var linearLayoutManager: LinearLayoutManager
private lateinit var requestLinearLayoutManager: LinearLayoutManager
private lateinit var userLinearLayoutManager: LinearLayoutManager
private lateinit var followRequestLinearLayoutManager: LinearLayoutManager
private lateinit var recentlyActiveLinearLayoutManager: LinearLayoutManager
private val viewModel: FollowerViewModel by viewModels()

override fun initView() {
Expand Down Expand Up @@ -58,40 +54,20 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {

recentlyActiveAdapter = RecentlyActiveAdapter()

linearLayoutManager = LinearLayoutManager(this)
requestLinearLayoutManager = LinearLayoutManager(this)
userLinearLayoutManager = LinearLayoutManager(this)
followRequestLinearLayoutManager = LinearLayoutManager(this)
recentlyActiveLinearLayoutManager = LinearLayoutManager(this)
recentlyActiveLinearLayoutManager.orientation = LinearLayoutManager.HORIZONTAL

binding.rvAllFollower.apply {
layoutManager = linearLayoutManager
adapter = followerAdapter
}
binding.rvRequestFollow.apply {
layoutManager = requestLinearLayoutManager
adapter = followRequestAdapter
}

binding.rvSearchResult.apply {
layoutManager = userLinearLayoutManager
adapter = userAdapter
}

binding.rvRecentlyActiveFollower.apply {
layoutManager = recentlyActiveLinearLayoutManager
adapter = recentlyActiveAdapter
}
binding.rvAllFollower.adapter = followerAdapter
binding.rvRequestFollow.adapter = followRequestAdapter
binding.rvSearchResult.adapter = userAdapter
binding.rvRecentlyActiveFollower.adapter = recentlyActiveAdapter
}

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

if (lastPosition != -1 && lastPosition >= (itemCount - 1) && viewModel.followerHasMore.value == true) {
viewModel.followerHasMore.value = false
Expand All @@ -107,9 +83,10 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {
binding.rvRequestFollow.addOnScrollListener(
object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val itemCount = requestLinearLayoutManager.itemCount
val itemCount = binding.rvRequestFollow.layoutManager?.itemCount ?: 0
val lastPosition =
requestLinearLayoutManager.findLastCompletelyVisibleItemPosition()
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
Expand All @@ -130,9 +107,10 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {
binding.rvSearchResult.addOnScrollListener(
object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val itemCount = userLinearLayoutManager.itemCount
val itemCount = binding.rvSearchResult.layoutManager?.itemCount ?: 0
val lastPosition =
userLinearLayoutManager.findLastCompletelyVisibleItemPosition()
binding.rvAllFollower.layoutManager?.let { it as LinearLayoutManager }
?.findLastCompletelyVisibleItemPosition() ?: 0

if (lastPosition != -1 && lastPosition >= (itemCount - 1)) {
viewModel.getUserSearch(
Expand All @@ -148,9 +126,10 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {
binding.rvRecentlyActiveFollower.addOnScrollListener(
object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
val itemCount = recentlyActiveLinearLayoutManager.itemCount
val itemCount = binding.rvRecentlyActiveFollower.layoutManager?.itemCount ?: 0
val lastPosition =
recentlyActiveLinearLayoutManager.findLastCompletelyVisibleItemPosition()
binding.rvAllFollower.layoutManager?.let { it as LinearLayoutManager }
?.findLastCompletelyVisibleItemPosition() ?: 0

if (lastPosition != -1 && lastPosition >= (itemCount - 1) && viewModel.recentlyActiveHasMore.value == true) {
viewModel.recentlyActiveHasMore.value = false
Expand Down Expand Up @@ -242,6 +221,19 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {
}
}
}

binding.clRecentlyActiveFollower.setOnClickListener {
expandView(binding.rvRecentlyActiveFollower, binding.ivRecentlyActiveExpand)
}
binding.clAllFollower.setOnClickListener {
expandView(binding.rvAllFollower, binding.ivAllFollowerExpand)
}
binding.clRequestFollow.setOnClickListener {
expandView(binding.rvRequestFollow, binding.ivRequestFollowExpand)
}
binding.clSearchResult.setOnClickListener {
expandView(binding.rvSearchResult, binding.ivSearchExpand)
}
}

private fun toggleFollow(user: User) {
Expand All @@ -262,4 +254,14 @@ class FollowerActivity : BaseActivity<ActivityFollowerBinding>() {
}
startActivity(intent)
}

private fun expandView(view: View, ivExpand: ImageView) {
if (view.visibility == View.VISIBLE) {
view.visibility = View.GONE
ivExpand.setImageResource(R.drawable.sel_jj_check_box_more_info_opened)
} else {
view.visibility = View.VISIBLE
ivExpand.setImageResource(R.drawable.sel_jj_check_box_more_info_closed)
}
}
}
5 changes: 4 additions & 1 deletion app/src/main/res/layout/activity_follower.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@
android:id="@+id/rv_search_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintTop_toBottomOf="@+id/tv_search_result" />

<ImageView
android:id="@+id/iv_user_search"
android:id="@+id/iv_search_expand"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="17dp"
Expand Down Expand Up @@ -172,6 +173,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/tv_all_follower"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="2"
tools:listitem="@layout/item_follow" />

Expand Down Expand Up @@ -212,6 +214,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/tv_request_follow"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="4"
tools:listitem="@layout/item_follow" />

Expand Down
Loading