Skip to content

Commit

Permalink
HomeAdapter modifications such that Calendar, Dining, and Laundry cel…
Browse files Browse the repository at this point in the history
…ls can have their own viewholders
  • Loading branch information
baronhsieh2005 committed Oct 6, 2024
1 parent c7bce3b commit 3647511
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ import com.pennapps.labs.pennmobile.databinding.HomePostCardBinding
import com.pennapps.labs.pennmobile.databinding.PollCardBinding
import com.pennapps.labs.pennmobile.utils.Utils
import com.pennapps.labs.pennmobile.viewholders.HomeBaseHolder
import com.pennapps.labs.pennmobile.viewholders.HomeCalendarHolder
import com.pennapps.labs.pennmobile.viewholders.HomeDiningHolder
import com.pennapps.labs.pennmobile.viewholders.HomeGSRHolder
import com.pennapps.labs.pennmobile.viewholders.HomeLaundryHolder
import com.pennapps.labs.pennmobile.viewholders.HomeNewsCardHolder
import com.pennapps.labs.pennmobile.viewholders.HomePollHolder
import com.pennapps.labs.pennmobile.viewholders.HomePostHolder
Expand Down Expand Up @@ -111,6 +114,21 @@ class HomeAdapter(
mActivity = mContext as MainActivity

return when (viewType) {
DINING -> {
val itemBinding = HomeBaseCardBinding.inflate(LayoutInflater.from(mContext), parent, false)
return HomeDiningHolder(itemBinding)
}

CALENDAR -> {
val itemBinding = HomeBaseCardBinding.inflate(LayoutInflater.from(mContext), parent, false)
return HomeCalendarHolder(itemBinding)
}

LAUNDRY -> {
val itemBinding = HomeBaseCardBinding.inflate(LayoutInflater.from(mContext), parent, false)
return HomeLaundryHolder(itemBinding)
}

NEWS -> {
val itemBinding = HomeNewsCardBinding.inflate(LayoutInflater.from(mContext), parent, false)
return HomeNewsCardHolder(itemBinding)
Expand Down Expand Up @@ -155,10 +173,10 @@ class HomeAdapter(
) {
val cell = dataModel.getCell(position)
when (cell.type) {
"dining" -> bindDiningCell(holder as HomeBaseHolder, cell as DiningCell)
"calendar" -> bindCalendarCell(holder as HomeBaseHolder, cell as CalendarCell)
"dining" -> bindDiningCell(holder as HomeDiningHolder, cell as DiningCell)
"calendar" -> bindCalendarCell(holder as HomeCalendarHolder, cell as CalendarCell)
"news" -> bindNewsCard(holder as HomeNewsCardHolder, cell as NewsCell)
"laundry" -> bindLaundryCell(holder as HomeBaseHolder, cell as LaundryCell)
"laundry" -> bindLaundryCell(holder as HomeLaundryHolder, cell as LaundryCell)
"post" -> bindPostCell(holder as HomePostHolder, cell as PostCell)
"poll" -> bindPollCell(holder as HomePollHolder, position, cell as PollCell)
"gsr_booking" -> bindGSRCell(holder as HomeGSRHolder, cell as GSRCell)
Expand Down Expand Up @@ -212,7 +230,7 @@ class HomeAdapter(
}

private fun bindLaundryCell(
holder: HomeBaseHolder,
holder: HomeLaundryHolder,
cell: LaundryCell,
) {
val roomID = cell.roomId
Expand Down Expand Up @@ -246,7 +264,7 @@ class HomeAdapter(
}

private fun bindDiningCell(
holder: HomeBaseHolder,
holder: HomeDiningHolder,
cell: DiningCell,
) {
holder.homeTitle.text = "Favorites"
Expand Down Expand Up @@ -293,7 +311,7 @@ class HomeAdapter(
}

private fun bindCalendarCell(
holder: HomeBaseHolder,
holder: HomeCalendarHolder,
cell: CalendarCell,
) {
val events = cell.events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.pennapps.labs.pennmobile.viewholders
import androidx.recyclerview.widget.RecyclerView
import com.pennapps.labs.pennmobile.databinding.HomeBaseCardBinding

class HomeBaseHolder(
open class HomeBaseHolder(
val itemBinding: HomeBaseCardBinding,
) : RecyclerView.ViewHolder(itemBinding.root) {
var homeTitle = itemBinding.homeCardTitle
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pennapps.labs.pennmobile.viewholders

import com.pennapps.labs.pennmobile.databinding.HomeBaseCardBinding

class HomeCalendarHolder(
itemBinding: HomeBaseCardBinding,
) : HomeBaseHolder(itemBinding)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pennapps.labs.pennmobile.viewholders

import com.pennapps.labs.pennmobile.databinding.HomeBaseCardBinding

class HomeDiningHolder(
itemBinding: HomeBaseCardBinding,
) : HomeBaseHolder(itemBinding)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pennapps.labs.pennmobile.viewholders

import com.pennapps.labs.pennmobile.databinding.HomeBaseCardBinding

class HomeLaundryHolder(
itemBinding: HomeBaseCardBinding,
) : HomeBaseHolder(itemBinding)

0 comments on commit 3647511

Please sign in to comment.