Skip to content

Commit

Permalink
fix home sections visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed-Alhams committed Apr 21, 2023
1 parent 9b76e1b commit 7232d33
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(), HomeView {
override fun showPersonalTodos(getAllPersonalTodosResponse: GetAllPersonalTodosResponse) {
showHiddenSections()
requireActivity().runOnUiThread {
adapter.setTodoListVisibilty(
binding.recyclerViewHome,
getAllPersonalTodosResponse.value.isEmpty()
)
adapter.setPersonalCount(getAllPersonalTodosResponse.value.size)
personalTodos.data = getAllPersonalTodosResponse
adapter.notifyDataSetChanged()
Expand Down Expand Up @@ -145,10 +141,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(), HomeView {
override fun showTeamTodos(getAllTeamTodosResponse: GetAllTeamTodosResponse) {
showHiddenSections()
requireActivity().runOnUiThread {
adapter.setTodoListVisibilty(
binding.recyclerViewHome,
getAllTeamTodosResponse.value.isEmpty()
)
adapter.setTeamCount(getAllTeamTodosResponse.value.size)
teamTodos.data = getAllTeamTodosResponse
adapter.notifyDataSetChanged()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class HomeAdapter(
private val onClickAllPersonalTodos: () -> Unit
) : RecyclerView.Adapter<HomeAdapter.BaseHomeHolder>() {

private var isTeamTodoVisible = false
private var isPersonalTodoVisible = false
private var teamPendingTodosCount: Int = 0
private var personalPendingTodosCount: Int = 0
private var pendingTeamTodosCount: Int = 0
Expand Down Expand Up @@ -63,13 +61,6 @@ class HomeAdapter(
}
}

fun setTodoListVisibilty(itemView: View, isVisible: Boolean) {
if (!isVisible) {
itemView.visibility = View.GONE
}
itemView.visibility = View.VISIBLE
}

fun setTeamCount(newTeamPendingTodosCount: Int) {
teamPendingTodosCount = newTeamPendingTodosCount
notifyDataSetChanged()
Expand Down Expand Up @@ -161,13 +152,23 @@ class HomeAdapter(

}

private fun setTodoListVisibilty(itemView: View, isEmpty: Boolean) {
if (isEmpty) {
itemView.visibility = View.GONE
} else {
itemView.visibility = View.VISIBLE
}
}

inner class PersonalTodosHolder(viewItem: View) : BaseHomeHolder(viewItem) {
private val binding = ItemSectionPersonalTodosBinding.bind(viewItem)
override fun bind(item: HomeItems<Any>) {
val adapter = GetAllPersonalTodosAdapter(
item.data as GetAllPersonalTodosResponse,
onClickPersonalTodoItem
)
val response = item.data as GetAllPersonalTodosResponse

setTodoListVisibilty(binding.root, response.value.isEmpty())

val adapter = GetAllPersonalTodosAdapter(response, onClickPersonalTodoItem)

binding.recyclerViewPersonalTodos.adapter = adapter
binding.textViewShowShowAll.setOnClickListener {
onClickAllPersonalTodos()
Expand All @@ -178,11 +179,11 @@ class HomeAdapter(
inner class TeamTodosHolder(viewItem: View) : BaseHomeHolder(viewItem) {
private val binding = ItemSectionTeamTodosBinding.bind(viewItem)
override fun bind(item: HomeItems<Any>) {
val adapter =
GetAllTeamTodosAdapter(
item.data as GetAllTeamTodosResponse,
onClickTeamTodoItem
)
val response = item.data as GetAllTeamTodosResponse

setTodoListVisibilty(binding.root, response.value.isEmpty())

val adapter = GetAllTeamTodosAdapter(response, onClickTeamTodoItem)
binding.recyclerViewTeamTodos.adapter = adapter
binding.textViewShowShowAll.setOnClickListener {
onClickAllTeamTodos()
Expand Down

0 comments on commit 7232d33

Please sign in to comment.