From 845de039e26aeb3b3e75004420068f6040ca0cd7 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 03:07:42 -0400 Subject: [PATCH 01/34] Dining Adapter Binding Implementation --- .../labs/pennmobile/adapters/DiningAdapter.kt | 68 +++++++++---------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt index 3449ca25..6c3a080d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt @@ -18,14 +18,8 @@ import com.pennapps.labs.pennmobile.MenuFragment import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.api.StudentLife import com.pennapps.labs.pennmobile.classes.DiningHall +import com.pennapps.labs.pennmobile.databinding.DiningListItemBinding import com.squareup.picasso.Picasso -import kotlinx.android.synthetic.main.dining_list_item.view.dining_hall_menu_indicator -import kotlinx.android.synthetic.main.dining_list_item.view.dining_list_item_layout -import kotlinx.android.synthetic.main.dining_list_item.view.dining_progress -import kotlinx.android.synthetic.main.dining_list_item.view.item_dining_hours -import kotlinx.android.synthetic.main.dining_list_item.view.item_dining_image -import kotlinx.android.synthetic.main.dining_list_item.view.item_dining_name -import kotlinx.android.synthetic.main.dining_list_item.view.item_dining_status import rx.android.schedulers.AndroidSchedulers import java.util.Collections @@ -41,14 +35,14 @@ class DiningAdapter( parent: ViewGroup, viewType: Int, ): DiningViewHolder { - val view = LayoutInflater.from(parent.context).inflate(R.layout.dining_list_item, parent, false) + val itemBinding = DiningListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) mStudentLife = MainActivity.studentLifeInstance loaded = BooleanArray(diningHalls.size) context = parent.context val sp = PreferenceManager.getDefaultSharedPreferences(context) sortBy = sp.getString("dining_sortBy", "RESIDENTIAL") ?: "RESIDENTIAL" Collections.sort(diningHalls, MenuComparator()) - return DiningViewHolder(view) + return DiningViewHolder(itemBinding) } override fun onBindViewHolder( @@ -59,11 +53,11 @@ class DiningAdapter( val diningHall = diningHalls[position] // Show dining hall name, photo, status, and hours on the screen - holder.menuArrow?.visibility = View.GONE - holder.progressBar?.visibility = View.VISIBLE + holder.menuArrow.visibility = View.GONE + holder.progressBar.visibility = View.VISIBLE - holder.hallNameTV?.text = diningHall.name - holder.hallNameTV?.isSelected = true + holder.hallNameTV.text = diningHall.name + holder.hallNameTV.isSelected = true Picasso .get() .load(diningHall.image) @@ -72,45 +66,45 @@ class DiningAdapter( .into(holder.hallImage) if (diningHall.isOpen) { - holder.hallStatus?.background = ContextCompat.getDrawable(context, R.drawable.label_green) + holder.hallStatus.background = ContextCompat.getDrawable(context, R.drawable.label_green) if (diningHall.openMeal() != "all" && diningHall.openMeal() != null) { - holder.hallStatus?.setText(getOpenStatusLabel(diningHall.openMeal() ?: "")) + holder.hallStatus.setText(getOpenStatusLabel(diningHall.openMeal() ?: "")) } - holder.hallHours?.text = diningHall.openTimes().lowercase() + holder.hallHours.text = diningHall.openTimes().lowercase() } else { - holder.hallStatus?.setText(R.string.dining_hall_closed) - holder.hallStatus?.background = ContextCompat.getDrawable(context, R.drawable.label_red) + holder.hallStatus.setText(R.string.dining_hall_closed) + holder.hallStatus.background = ContextCompat.getDrawable(context, R.drawable.label_red) val openTimes = diningHall.openTimes() if (openTimes.isEmpty()) { - holder.hallHours?.setText(R.string.dining_closed) + holder.hallHours.setText(R.string.dining_closed) } else { - holder.hallHours?.text = diningHall.openTimes().lowercase() + holder.hallHours.text = diningHall.openTimes().lowercase() } } // Load the menu for each dining hall if (diningHall.isResidential && !loaded[position]) { - holder.progressBar?.visibility = View.VISIBLE + holder.progressBar.visibility = View.VISIBLE try { mStudentLife .daily_menu(diningHall.id) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ newDiningHall -> diningHall.sortMeals(newDiningHall.menus) - holder.progressBar?.visibility = View.INVISIBLE - holder.menuArrow?.visibility = View.VISIBLE + holder.progressBar.visibility = View.INVISIBLE + holder.menuArrow.visibility = View.VISIBLE loaded[position] = true }, { - holder.progressBar?.visibility = View.VISIBLE - holder.menuArrow?.visibility = View.GONE + holder.progressBar.visibility = View.VISIBLE + holder.menuArrow.visibility = View.GONE }) } catch (e: Exception) { e.printStackTrace() } } else { - holder.progressBar?.visibility = View.GONE - holder.menuArrow?.visibility = View.VISIBLE + holder.progressBar.visibility = View.GONE + holder.menuArrow.visibility = View.VISIBLE } - holder.layout?.setOnClickListener { + holder.layout.setOnClickListener { val mainActivity = context as MainActivity val fragment = MenuFragment() @@ -175,14 +169,14 @@ class DiningAdapter( } class DiningViewHolder( - view: View, - ) : RecyclerView.ViewHolder(view) { - val layout: ConstraintLayout? = view.dining_list_item_layout - val hallNameTV: TextView? = view.item_dining_name - val hallStatus: TextView? = view.item_dining_status - val hallImage: ImageView? = view.item_dining_image - val hallHours: TextView? = view.item_dining_hours - val menuArrow: ImageView? = view.dining_hall_menu_indicator - val progressBar: ProgressBar? = view.dining_progress + private val itemBinding: DiningListItemBinding, + ) : RecyclerView.ViewHolder(itemBinding.root) { + val layout: ConstraintLayout = itemBinding.diningListItemLayout + val hallNameTV: TextView = itemBinding.itemDiningName + val hallStatus: TextView = itemBinding.itemDiningStatus + val hallImage: ImageView = itemBinding.itemDiningImage + val hallHours: TextView = itemBinding.itemDiningHours + val menuArrow: ImageView = itemBinding.diningHallMenuIndicator + val progressBar: ProgressBar = itemBinding.diningProgress } } From 9bb12c3294abac0c7d695a99fafe51ded383a29b Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 03:22:12 -0400 Subject: [PATCH 02/34] UniversityEventAdapter Binding Implementation --- .../adapters/UniversityEventAdapter.kt | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt index 738c21b1..efab8f3e 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt @@ -4,13 +4,11 @@ import android.annotation.SuppressLint import android.content.Context import android.util.Log import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup +import android.widget.TextView import androidx.recyclerview.widget.RecyclerView -import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.classes.CalendarEvent -import kotlinx.android.synthetic.main.university_event.view.event_month -import kotlinx.android.synthetic.main.university_event.view.event_name_tv +import com.pennapps.labs.pennmobile.databinding.UniversityEventBinding class UniversityEventAdapter( private var events: ArrayList, @@ -21,9 +19,9 @@ class UniversityEventAdapter( parent: ViewGroup, viewType: Int, ): UniversityEventViewHolder { - val view = LayoutInflater.from(parent.context).inflate(R.layout.university_event, parent, false) + val itemBinding = UniversityEventBinding.inflate(LayoutInflater.from(parent.context), parent, false) mContext = parent.context - return UniversityEventViewHolder(view) + return UniversityEventViewHolder(itemBinding) } @SuppressLint("SetTextI18n") @@ -45,9 +43,9 @@ class UniversityEventAdapter( // holder.itemView.event_day.text = dayOfMonth // holder.itemView.event_month.text = month - holder.itemView.event_month.text = event.date - holder.itemView.event_name_tv.text = name - holder.itemView.event_name_tv.isSelected = true + holder.event_month.text = event.date + holder.event_name.text = name + holder.event_name.isSelected = true /* if (from == to) { holder.itemView.event_day_of_week.text = start } else { @@ -58,8 +56,9 @@ class UniversityEventAdapter( override fun getItemCount(): Int = events.size inner class UniversityEventViewHolder( - itemView: View, - ) : RecyclerView.ViewHolder(itemView) { - val view = itemView + itemBinding: UniversityEventBinding, + ) : RecyclerView.ViewHolder(itemBinding.root) { + val event_month : TextView = itemBinding.eventMonth + val event_name : TextView = itemBinding.eventNameTv } } From a25d77ae7fd893a5a8f5b54bb12bb629945d6abc Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 03:46:15 -0400 Subject: [PATCH 03/34] GSRReservationAdapter Change to ViewBinding --- .../adapters/HomeGsrReservationAdapter.kt | 58 ++++++++----------- .../labs/pennmobile/api/StudentLife.java | 2 +- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt index 29a72509..068795e1 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt @@ -2,38 +2,43 @@ package com.pennapps.labs.pennmobile.adapters import android.content.Context import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.pennapps.labs.pennmobile.GsrTabbedFragment import com.pennapps.labs.pennmobile.MainActivity -import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.api.StudentLife import com.pennapps.labs.pennmobile.classes.GSRReservation +import com.pennapps.labs.pennmobile.databinding.GsrListItemBinding import com.squareup.picasso.Picasso -import kotlinx.android.synthetic.main.gsr_list_item.view.item_gsr_date -import kotlinx.android.synthetic.main.gsr_list_item.view.item_gsr_image -import kotlinx.android.synthetic.main.gsr_list_item.view.item_gsr_location import org.joda.time.format.DateTimeFormat import org.joda.time.format.DateTimeFormatter class HomeGsrReservationAdapter( reservations: List, -) : RecyclerView.Adapter() { +) : RecyclerView.Adapter() { private var activeReservations: List = reservations - private lateinit var itemImage: ImageView - private lateinit var itemLocation: TextView - private lateinit var itemDate: TextView - private lateinit var mContext: Context private lateinit var mActivity: MainActivity private lateinit var mStudentLife: StudentLife + override fun onCreateViewHolder( + parent: ViewGroup, + viewType: Int, + ): GSRReservationViewHolder { + mContext = parent.context + mActivity = mContext as MainActivity + mStudentLife = MainActivity.studentLifeInstance + + val itemBinding = GsrListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) + + return GSRReservationViewHolder(itemBinding) + } + override fun onBindViewHolder( - holder: HomeGsrReservationAdapter.ViewHolder, + holder: GSRReservationViewHolder, position: Int, ) { val currentReservation = activeReservations[position] @@ -51,10 +56,10 @@ class HomeGsrReservationAdapter( .load(imageUrl) .fit() .centerCrop() - .into(holder.itemView.item_gsr_image) + .into(holder.itemImage) - holder.itemView.item_gsr_location.text = location - holder.itemView.item_gsr_date.text = day + "\n" + fromHour + "-" + toHour + holder.itemLocation.text = location + holder.itemDate.text = day + "\n" + fromHour + "-" + toHour holder.itemView.setOnClickListener { // Moves to GSR Booking Tab @@ -71,25 +76,12 @@ class HomeGsrReservationAdapter( override fun getItemCount(): Int = activeReservations.size - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int, - ): HomeGsrReservationAdapter.ViewHolder { - mContext = parent.context - mActivity = mContext as MainActivity - mStudentLife = MainActivity.studentLifeInstance - - val view = LayoutInflater.from(parent.context).inflate(R.layout.gsr_list_item, parent, false) - return ViewHolder(view) - } - inner class ViewHolder( - itemView: View, - ) : RecyclerView.ViewHolder(itemView) { - init { - itemImage = itemView.item_gsr_image - itemLocation = itemView.item_gsr_location - itemDate = itemView.item_gsr_date - } + inner class GSRReservationViewHolder( + itemBinding: GsrListItemBinding, + ) : RecyclerView.ViewHolder(itemBinding.root) { + val itemImage : ImageView = itemBinding.itemGsrImage + val itemLocation : TextView = itemBinding.itemGsrLocation + val itemDate : TextView = itemBinding.itemGsrDate } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/StudentLife.java b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/StudentLife.java index 2d462505..89be0e7c 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/StudentLife.java +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/StudentLife.java @@ -131,7 +131,7 @@ Observable> getGsrReservations( void cancelReservation( @Header("Authorization") String bearerToken, @Header("X-Device-ID") String deviceID, - @Field("bookingId") String bookingID, + @Field("booking_id") String bookingID, @Field("sessionid") String sessionID, Callback callback); From 12c958b9d31161fa3eb1689dbedd0d785180d59e Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 04:03:03 -0400 Subject: [PATCH 04/34] AboutAdapter ViewBinding Implementation --- .../labs/pennmobile/adapters/AboutAdapter.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/AboutAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/AboutAdapter.kt index c4a9e42d..54d57f82 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/AboutAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/AboutAdapter.kt @@ -2,12 +2,13 @@ package com.pennapps.labs.pennmobile.adapters import android.content.Context import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.pennapps.labs.pennmobile.R -import kotlinx.android.synthetic.main.team_member.view.name_tv -import kotlinx.android.synthetic.main.team_member.view.person_iv +import com.pennapps.labs.pennmobile.databinding.TeamMemberBinding + class AboutAdapter( private var members: ArrayList, @@ -18,9 +19,9 @@ class AboutAdapter( parent: ViewGroup, viewType: Int, ): TeamViewHolder { - val view = LayoutInflater.from(parent.context).inflate(R.layout.team_member, parent, false) mContext = parent.context - return TeamViewHolder(view) + val itemBinding = TeamMemberBinding.inflate(LayoutInflater.from(mContext), parent, false) + return TeamViewHolder(itemBinding) } override fun getItemCount(): Int = members.count() @@ -29,7 +30,7 @@ class AboutAdapter( holder: TeamViewHolder, position: Int, ) { - holder.view.name_tv?.text = members[position] + holder.name_tv.text = members[position] val imageId = when (members[position]) { "Marta García Ferreiro" -> R.drawable.marta @@ -51,12 +52,13 @@ class AboutAdapter( "Baron Ping-Yeh Hsieh" -> R.drawable.baron else -> null } - if (imageId != null) holder.view.person_iv?.setImageResource(imageId) + if (imageId != null) holder.person_iv.setImageResource(imageId) } inner class TeamViewHolder( - itemView: View, - ) : RecyclerView.ViewHolder(itemView) { - val view = itemView + itemBinding: TeamMemberBinding, + ) : RecyclerView.ViewHolder(itemBinding.root) { + val person_iv: ImageView = itemBinding.personIv + val name_tv: TextView = itemBinding.nameTv } } From 4c875a38e0d2f62c6ab0c2d064b8c9e7b6878cb8 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 04:16:13 -0400 Subject: [PATCH 05/34] Fling Adapter ViewBinding Implementation --- .../adapters/FlingRecyclerViewAdapter.kt | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt index 408e7e62..bda75728 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt @@ -9,11 +9,8 @@ import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.classes.FlingEvent +import com.pennapps.labs.pennmobile.databinding.FlingPerformanceItemBinding import com.squareup.picasso.Picasso -import kotlinx.android.synthetic.main.fling_performance_item.view.flingview_description -import kotlinx.android.synthetic.main.fling_performance_item.view.flingview_image -import kotlinx.android.synthetic.main.fling_performance_item.view.flingview_name -import kotlinx.android.synthetic.main.fling_performance_item.view.flingview_time import org.joda.time.format.DateTimeFormat import org.joda.time.format.DateTimeFormatter import org.joda.time.format.ISODateTimeFormat @@ -30,8 +27,8 @@ class FlingRecyclerViewAdapter( parent: ViewGroup, viewType: Int, ): ViewHolder { - val view = LayoutInflater.from(context).inflate(R.layout.fling_performance_item, parent, false) - return ViewHolder(view) + val itemBinding = FlingPerformanceItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return ViewHolder(itemBinding) } override fun onBindViewHolder( @@ -59,11 +56,11 @@ class FlingRecyclerViewAdapter( } class ViewHolder( - view: View, - ) : RecyclerView.ViewHolder(view) { - internal var flingviewImage: ImageView? = view.flingview_image - internal var flingviewName: TextView? = view.flingview_name - internal var flingviewDescription: TextView? = view.flingview_description - internal var flingviewTime: TextView? = view.flingview_time + itemBinding: FlingPerformanceItemBinding, + ) : RecyclerView.ViewHolder(itemBinding.root) { + internal var flingviewImage: ImageView? = itemBinding.flingviewImage + internal var flingviewName: TextView? = itemBinding.flingviewName + internal var flingviewDescription: TextView? = itemBinding.flingviewDescription + internal var flingviewTime: TextView? = itemBinding.flingviewTime } } From 9c32fcfd8887d625e940a2baa52c0749ea14d16f Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 04:24:55 -0400 Subject: [PATCH 06/34] HomeGsrBuildingAdapter ViewBinding Implementation (but seems to be never used?) --- .../adapters/HomeGsrBuildingAdapter.kt | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrBuildingAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrBuildingAdapter.kt index d9e6b1c6..e2feb4be 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrBuildingAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrBuildingAdapter.kt @@ -3,8 +3,9 @@ package com.pennapps.labs.pennmobile.adapters import android.content.Context import android.util.Log import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentManager @@ -12,8 +13,7 @@ import androidx.recyclerview.widget.RecyclerView import com.pennapps.labs.pennmobile.GsrTabbedFragment import com.pennapps.labs.pennmobile.MainActivity import com.pennapps.labs.pennmobile.R -import kotlinx.android.synthetic.main.home_gsr_building.view.home_gsr_building_iv -import kotlinx.android.synthetic.main.home_gsr_building.view.home_gsr_building_tv +import com.pennapps.labs.pennmobile.databinding.HomeGsrBuildingBinding class HomeGsrBuildingAdapter( private var buildings: ArrayList, @@ -24,9 +24,9 @@ class HomeGsrBuildingAdapter( parent: ViewGroup, viewType: Int, ): HomeGsrBuildingViewHolder { - val view = LayoutInflater.from(parent.context).inflate(R.layout.home_gsr_building, parent, false) mContext = parent.context - return HomeGsrBuildingViewHolder(view) + val itemBinding = HomeGsrBuildingBinding.inflate(LayoutInflater.from(mContext), parent, false) + return HomeGsrBuildingViewHolder(itemBinding) } override fun onBindViewHolder( @@ -34,13 +34,11 @@ class HomeGsrBuildingAdapter( position: Int, ) { val building = buildings[position] - - holder.itemView.home_gsr_building_tv.text = building - holder.itemView.home_gsr_building_iv + holder.home_gsr_building_tv.text = building if (building == "Huntsman Hall") { - holder.itemView.home_gsr_building_iv.setImageResource(R.drawable.huntsman) + holder.home_gsr_building_iv.setImageResource(R.drawable.huntsman) } else { - holder.itemView.home_gsr_building_iv.setImageResource(R.drawable.weigle) + holder.home_gsr_building_iv.setImageResource(R.drawable.weigle) } holder.itemView.setOnClickListener { fragmentTransact(GsrTabbedFragment(), false) @@ -50,9 +48,10 @@ class HomeGsrBuildingAdapter( override fun getItemCount(): Int = buildings.size inner class HomeGsrBuildingViewHolder( - itemView: View, - ) : RecyclerView.ViewHolder(itemView) { - val view = itemView + itemBinding: HomeGsrBuildingBinding, + ) : RecyclerView.ViewHolder(itemBinding.root) { + val home_gsr_building_iv: ImageView = itemBinding.homeGsrBuildingIv + val home_gsr_building_tv: TextView = itemBinding.homeGsrBuildingTv } private fun fragmentTransact( From a48af7bad039e09af688e0492575c87f156c4114 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 04:28:14 -0400 Subject: [PATCH 07/34] Warning Cleaning --- .../com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt | 2 +- .../labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt | 1 - .../java/com/pennapps/labs/pennmobile/api/StudentLife.java | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt index 6c3a080d..cbdc5274 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt @@ -169,7 +169,7 @@ class DiningAdapter( } class DiningViewHolder( - private val itemBinding: DiningListItemBinding, + itemBinding: DiningListItemBinding, ) : RecyclerView.ViewHolder(itemBinding.root) { val layout: ConstraintLayout = itemBinding.diningListItemLayout val hallNameTV: TextView = itemBinding.itemDiningName diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt index bda75728..892ae062 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt @@ -2,7 +2,6 @@ package com.pennapps.labs.pennmobile.adapters import android.content.Context import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/StudentLife.java b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/StudentLife.java index 89be0e7c..aa344921 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/StudentLife.java +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/StudentLife.java @@ -15,10 +15,7 @@ import com.pennapps.labs.pennmobile.classes.GSRBookingResult; import com.pennapps.labs.pennmobile.classes.GSRLocation; import com.pennapps.labs.pennmobile.classes.GSRReservation; -import com.pennapps.labs.pennmobile.classes.LaundryRequest; import com.pennapps.labs.pennmobile.classes.LaundryRoom; -import com.pennapps.labs.pennmobile.classes.LaundryRoomSimple; -import com.pennapps.labs.pennmobile.classes.LaundryUsage; import com.pennapps.labs.pennmobile.classes.Poll; import com.pennapps.labs.pennmobile.classes.Post; import com.pennapps.labs.pennmobile.classes.SaveAccountResponse; From 2027003a505d31b32b35324c42f82a88d78711c9 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 12:27:52 -0400 Subject: [PATCH 08/34] GsrRoomAdapter ViewBinding Implementation --- .../pennapps/labs/pennmobile/GsrRoomHolder.kt | 21 +++++++------------ .../pennmobile/adapters/GsrRoomAdapter.kt | 5 +++-- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrRoomHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrRoomHolder.kt index 1157a143..64ae4603 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrRoomHolder.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrRoomHolder.kt @@ -1,21 +1,16 @@ package com.pennapps.labs.pennmobile -import android.view.View import android.widget.LinearLayout import android.widget.TextView import androidx.recyclerview.widget.RecyclerView -import kotlinx.android.synthetic.main.gsr_room.view.gsr_end_time -import kotlinx.android.synthetic.main.gsr_room.view.gsr_id -import kotlinx.android.synthetic.main.gsr_room.view.gsr_room -import kotlinx.android.synthetic.main.gsr_room.view.gsr_start_time -import kotlinx.android.synthetic.main.gsr_room.view.locationId +import com.pennapps.labs.pennmobile.databinding.GsrRoomBinding class GsrRoomHolder( - itemView: View, -) : RecyclerView.ViewHolder(itemView) { - internal var gsrRoom: LinearLayout = itemView.gsr_room - internal var gsrStartTime: TextView = itemView.gsr_start_time - internal var gsrEndTime: TextView = itemView.gsr_end_time - internal var gsrId: TextView = itemView.gsr_id - internal var locationId: TextView = itemView.locationId + itemBinding: GsrRoomBinding, +) : RecyclerView.ViewHolder(itemBinding.root) { + internal var gsrRoom: LinearLayout = itemBinding.gsrRoom + internal var gsrStartTime: TextView = itemBinding.gsrStartTime + internal var gsrEndTime: TextView = itemBinding.gsrEndTime + internal var gsrId: TextView = itemBinding.gsrId + internal var locationId: TextView = itemBinding.locationId } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrRoomAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrRoomAdapter.kt index 6c82f8b0..b7643234 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrRoomAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrRoomAdapter.kt @@ -9,6 +9,7 @@ import com.pennapps.labs.pennmobile.BookGsrFragment import com.pennapps.labs.pennmobile.GsrRoomHolder import com.pennapps.labs.pennmobile.MainActivity import com.pennapps.labs.pennmobile.R +import com.pennapps.labs.pennmobile.databinding.GsrRoomBinding import org.joda.time.DateTime class GsrRoomAdapter( @@ -27,8 +28,8 @@ class GsrRoomAdapter( parent: ViewGroup, viewType: Int, ): GsrRoomHolder { - val view = LayoutInflater.from(parent.context).inflate(R.layout.gsr_room, parent, false) - val gsrRoomHolder = GsrRoomHolder(view) + val itemBinding = GsrRoomBinding.inflate(LayoutInflater.from(parent.context), parent, false) + val gsrRoomHolder = GsrRoomHolder(itemBinding) // whenever a time slot is clicked, open spinner to let user pick a duration gsrRoomHolder.gsrRoom.setOnClickListener { From 1aaa40971a27560ebb1181715ba093b7627d7cef Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 12:37:14 -0400 Subject: [PATCH 09/34] GSRRservationsFragement LoadingPanel Redefine --- .../com/pennapps/labs/pennmobile/GsrReservationsFragment.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt index 6dcf060c..b0ac756f 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt @@ -16,10 +16,10 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.google.firebase.crashlytics.FirebaseCrashlytics import com.pennapps.labs.pennmobile.adapters.GsrReservationsAdapter import com.pennapps.labs.pennmobile.databinding.FragmentGsrReservationsBinding -import kotlinx.android.synthetic.main.loading_panel.loadingPanel class GsrReservationsFragment : Fragment() { private lateinit var mActivity: MainActivity + private lateinit var loadingPanel: View private var _binding: FragmentGsrReservationsBinding? = null val binding get() = _binding!! @@ -65,6 +65,7 @@ class GsrReservationsFragment : Fragment() { savedInstanceState: Bundle?, ) { super.onViewCreated(view, savedInstanceState) + loadingPanel = view.findViewById(R.id.loadingPanel) if (!isOnline(context)) { binding.internetConnectionGSRReservations.setBackgroundColor(resources.getColor(R.color.darkRedBackground)) binding.internetConnectionMessageGsrReservations.text = "Not Connected to Internet" From 267ed8e750168a5582bd10cb1ffee4dfdec39b83 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 13:01:35 -0400 Subject: [PATCH 10/34] GSRRservationsFragement LoadingPanel Redefine --- .../pennmobile/adapters/PollOptionAdapter.kt | 63 +++++++++++-------- .../adapters/UniversityEventAdapter.kt | 2 +- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PollOptionAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PollOptionAdapter.kt index 7ef1f488..38e81cb6 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PollOptionAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PollOptionAdapter.kt @@ -6,34 +6,35 @@ import android.view.LayoutInflater import android.view.MotionEvent import android.view.View import android.view.ViewGroup +import android.widget.SeekBar +import android.widget.TextView +import androidx.cardview.widget.CardView import androidx.recyclerview.widget.RecyclerView import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.classes.Poll import com.pennapps.labs.pennmobile.classes.PollOption -import kotlinx.android.synthetic.main.poll_list_item.view.card_view -import kotlinx.android.synthetic.main.poll_list_item.view.seek_bar -import kotlinx.android.synthetic.main.poll_list_item.view.tv_option -import kotlinx.android.synthetic.main.poll_list_item.view.tv_percent -import kotlinx.android.synthetic.main.poll_list_item.view.tv_votes +import com.pennapps.labs.pennmobile.databinding.PollListItemBinding import kotlin.math.abs import kotlin.math.round class PollOptionAdapter( private var pollOptions: ArrayList, private var poll: Poll, -) : RecyclerView.Adapter() { +) : RecyclerView.Adapter() { private lateinit var mContext: Context override fun onCreateViewHolder( parent: ViewGroup, viewType: Int, - ): ViewHolder { + ): PollHolder { mContext = parent.context - return ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.poll_list_item, parent, false)) + val itemBinding = PollListItemBinding.inflate(LayoutInflater.from(mContext), parent, false) + val pollHolder = PollHolder(itemBinding) + return pollHolder } override fun onBindViewHolder( - holder: ViewHolder, + holder: PollHolder, position: Int, ) { val pollOption = pollOptions[position] @@ -51,14 +52,14 @@ class PollOptionAdapter( override fun getItemViewType(position: Int): Int = 0 private fun bindPollOption( - holder: ViewHolder, + holder: PollHolder, pollOption: PollOption, ) { - holder.itemView.tv_option?.text = pollOption.choice + holder.tv_option.text = pollOption.choice var startX: Float? = null var startY: Float? = null - holder.itemView.seek_bar?.setOnTouchListener { v, event -> + holder.seek_bar.setOnTouchListener { v, event -> when (event.action) { MotionEvent.ACTION_DOWN -> { startX = event.x @@ -76,24 +77,24 @@ class PollOptionAdapter( true } if (pollOption.selected) { - holder.itemView.tv_option?.setTextColor(mContext.resources.getColor(R.color.color_secondary)) - holder.itemView.tv_percent?.setTextColor(mContext.resources.getColor(R.color.color_secondary)) - holder.itemView.tv_votes?.setTextColor(mContext.resources.getColor(R.color.color_secondary)) - holder.itemView.seek_bar?.progressDrawable = mContext.getDrawable(R.drawable.poll_track_selected) - holder.itemView.card_view?.foreground = mContext.getDrawable(R.drawable.card_view_border) + holder.tv_option.setTextColor(mContext.resources.getColor(R.color.color_secondary)) + holder.tv_percent.setTextColor(mContext.resources.getColor(R.color.color_secondary)) + holder.tv_votes.setTextColor(mContext.resources.getColor(R.color.color_secondary)) + holder.seek_bar.progressDrawable = mContext.getDrawable(R.drawable.poll_track_selected) + holder.card_view.foreground = mContext.getDrawable(R.drawable.card_view_border) } else { - holder.itemView.tv_option?.setTextColor(Color.parseColor("#13284B")) - holder.itemView.tv_percent?.setTextColor(Color.parseColor("#13284B")) - holder.itemView.tv_votes?.setTextColor(Color.parseColor("#13284B")) - holder.itemView.seek_bar?.progressDrawable = mContext.getDrawable(R.drawable.poll_track) - holder.itemView.card_view?.foreground = null + holder.tv_option.setTextColor(Color.parseColor("#13284B")) + holder.tv_percent.setTextColor(Color.parseColor("#13284B")) + holder.tv_votes.setTextColor(Color.parseColor("#13284B")) + holder.seek_bar.progressDrawable = mContext.getDrawable(R.drawable.poll_track) + holder.card_view.foreground = null } if (poll.isVisible) { - holder.itemView.tv_votes?.text = "${pollOption.voteCount}" + holder.tv_votes.text = "${pollOption.voteCount}" val votePercent = (pollOption.voteCount.div(poll.totalVotes.toDouble())) * 100 - holder.itemView.tv_percent?.text = String.format("%.2f%%", votePercent) - holder.itemView.seek_bar?.progress = round(votePercent).toInt() - holder.itemView.seek_bar?.setOnTouchListener { v, event -> true } + holder.tv_percent.text = String.format("%.2f%%", votePercent) + holder.seek_bar.progress = round(votePercent).toInt() + holder.seek_bar.setOnTouchListener { v, event -> true } } } @@ -108,6 +109,16 @@ class PollOptionAdapter( return !(differenceX > CLICK_ACTION_THRESHOLD || differenceY > CLICK_ACTION_THRESHOLD) // =5 } + class PollHolder( + itemBinding: PollListItemBinding, + ) : RecyclerView.ViewHolder(itemBinding.root) { + internal var tv_option: TextView = itemBinding.tvOption + internal var tv_percent: TextView = itemBinding.tvPercent + internal var seek_bar: SeekBar = itemBinding.seekBar + internal var card_view: CardView = itemBinding.cardView + internal var tv_votes: TextView = itemBinding.tvVotes + } + companion object { private const val CLICK_ACTION_THRESHOLD: Int = 200 } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt index efab8f3e..3d7c767e 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt @@ -19,8 +19,8 @@ class UniversityEventAdapter( parent: ViewGroup, viewType: Int, ): UniversityEventViewHolder { - val itemBinding = UniversityEventBinding.inflate(LayoutInflater.from(parent.context), parent, false) mContext = parent.context + val itemBinding = UniversityEventBinding.inflate(LayoutInflater.from(mContext), parent, false) return UniversityEventViewHolder(itemBinding) } From 9cdd415221f4ff816b5ffa788f1d753287ee01ff Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 14:12:24 -0400 Subject: [PATCH 11/34] GSRRservationsAdapter transition to ViewBinding --- .../adapters/GsrReservationsAdapter.kt | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationsAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationsAdapter.kt index 9d31dd12..449d09a1 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationsAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationsAdapter.kt @@ -4,7 +4,6 @@ import android.content.Context import android.content.Intent import android.util.Log import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import android.widget.Toast import android.widget.Toast.LENGTH_SHORT @@ -15,11 +14,8 @@ import androidx.recyclerview.widget.RecyclerView import com.pennapps.labs.pennmobile.MainActivity import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.classes.GSRReservation +import com.pennapps.labs.pennmobile.databinding.GsrReservationBinding import com.squareup.picasso.Picasso -import kotlinx.android.synthetic.main.gsr_reservation.view.gsr_reservation_cancel_btn -import kotlinx.android.synthetic.main.gsr_reservation.view.gsr_reservation_date_tv -import kotlinx.android.synthetic.main.gsr_reservation.view.gsr_reservation_iv -import kotlinx.android.synthetic.main.gsr_reservation.view.gsr_reservation_location_tv import org.joda.time.format.DateTimeFormat import org.joda.time.format.DateTimeFormatter import retrofit.ResponseCallback @@ -35,9 +31,9 @@ class GsrReservationsAdapter( parent: ViewGroup, viewType: Int, ): GsrReservationViewHolder { - val view = LayoutInflater.from(parent.context).inflate(R.layout.gsr_reservation, parent, false) mContext = parent.context - return GsrReservationViewHolder(view) + val itemBinding = GsrReservationBinding.inflate(LayoutInflater.from(mContext), parent, false) + return GsrReservationViewHolder(itemBinding) } override fun onBindViewHolder( @@ -62,12 +58,12 @@ class GsrReservationsAdapter( .load(imageUrl) .fit() .centerCrop() - .into(holder.itemView.gsr_reservation_iv) + .into(holder.gsr_reservation_iv) - holder.itemView.gsr_reservation_location_tv.text = roomName - holder.itemView.gsr_reservation_date_tv.text = day + "\n" + fromHour + "-" + toHour + holder.gsr_reservation_location_tv.text = roomName + holder.gsr_reservation_date_tv.text = day + "\n" + fromHour + "-" + toHour - holder.itemView.gsr_reservation_cancel_btn.setOnClickListener { + holder.gsr_reservation_cancel_button.setOnClickListener { // create dialog to confirm that you want to cancel reservation val builder = AlertDialog.Builder(mContext) builder.setTitle("Are you sure?") @@ -144,8 +140,11 @@ class GsrReservationsAdapter( override fun getItemCount(): Int = reservations.size inner class GsrReservationViewHolder( - itemView: View, - ) : RecyclerView.ViewHolder(itemView) { - val view = itemView + itemBinding: GsrReservationBinding, + ) : RecyclerView.ViewHolder(itemBinding.root) { + val gsr_reservation_cancel_button = itemBinding.gsrReservationCancelBtn + val gsr_reservation_location_tv = itemBinding.gsrReservationLocationTv + val gsr_reservation_date_tv = itemBinding.gsrReservationDateTv + val gsr_reservation_iv = itemBinding.gsrReservationIv } } From 7b627ac2c7573e0931ea9a4d8cc1f06c49f9b665 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 15:03:11 -0400 Subject: [PATCH 12/34] Implement ViewBinding in MoreFragment --- .../pennmobile/morefragments/MoreFragment.kt | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt index bf073268..cc93d3bf 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt @@ -12,15 +12,17 @@ import androidx.preference.PreferenceManager import com.pennapps.labs.pennmobile.MainActivity import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior +import com.pennapps.labs.pennmobile.databinding.FragmentHomeBinding +import com.pennapps.labs.pennmobile.databinding.FragmentMoreBinding import com.pennapps.labs.pennmobile.utils.Utils -import kotlinx.android.synthetic.main.fragment_home.initials -import kotlinx.android.synthetic.main.fragment_home.profile_background -import kotlinx.android.synthetic.main.fragment_home.view.appbar_home -import kotlinx.android.synthetic.main.fragment_home.view.date_view + class MoreFragment : Fragment() { private lateinit var mActivity: MainActivity + private var _binding: FragmentMoreBinding? = null + val binding get() = _binding!! + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mActivity = activity as MainActivity @@ -31,11 +33,11 @@ class MoreFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, - ): View? { - val view = inflater.inflate(R.layout.fragment_more, container, false) - - initAppBar(view) - return view + ): View { + _binding = FragmentMoreBinding.inflate(inflater, container, false) + val v = binding.root + initAppBar(v) + return v } override fun onViewCreated( @@ -51,12 +53,12 @@ class MoreFragment : Fragment() { } private fun initAppBar(view: View) { - view.date_view.text = Utils.getCurrentSystemTime() + binding.dateView.text = Utils.getCurrentSystemTime() // Appbar behavior init ( - view.appbar_home.layoutParams - as CoordinatorLayout.LayoutParams - ).behavior = ToolbarBehavior() + binding.appbarHome.layoutParams + as CoordinatorLayout.LayoutParams + ).behavior = ToolbarBehavior() } override fun onResume() { @@ -65,9 +67,9 @@ class MoreFragment : Fragment() { .getDefaultSharedPreferences(mActivity) .getString(getString(R.string.initials), null) if (initials != null && initials.isNotEmpty()) { - this.initials.text = initials + binding.initials.text = initials } else { - this.profile_background.setImageDrawable( + binding.profileBackground.setImageDrawable( ResourcesCompat.getDrawable( resources, R.drawable.ic_guest_avatar, @@ -78,4 +80,9 @@ class MoreFragment : Fragment() { mActivity.setSelectedTab(MainActivity.MORE) super.onResume() } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } } From 9197ca110b4b0373ce2fe2c89869d4e9542165b6 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 15:08:21 -0400 Subject: [PATCH 13/34] initAppBar modifications --- .../pennmobile/morefragments/MoreFragment.kt | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt index cc93d3bf..1eb1ad44 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt @@ -12,7 +12,6 @@ import androidx.preference.PreferenceManager import com.pennapps.labs.pennmobile.MainActivity import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior -import com.pennapps.labs.pennmobile.databinding.FragmentHomeBinding import com.pennapps.labs.pennmobile.databinding.FragmentMoreBinding import com.pennapps.labs.pennmobile.utils.Utils @@ -36,7 +35,11 @@ class MoreFragment : Fragment() { ): View { _binding = FragmentMoreBinding.inflate(inflater, container, false) val v = binding.root - initAppBar(v) + binding.dateView.text = Utils.getCurrentSystemTime() + ( + binding.appbarHome.layoutParams + as CoordinatorLayout.LayoutParams + ).behavior = ToolbarBehavior() return v } @@ -52,15 +55,6 @@ class MoreFragment : Fragment() { .commit() } - private fun initAppBar(view: View) { - binding.dateView.text = Utils.getCurrentSystemTime() - // Appbar behavior init - ( - binding.appbarHome.layoutParams - as CoordinatorLayout.LayoutParams - ).behavior = ToolbarBehavior() - } - override fun onResume() { val initials = PreferenceManager From 1a8b9c6f1ebe00f208578d9ec47e4b1ef9ee1a09 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 20:46:32 -0400 Subject: [PATCH 14/34] linting --- .../labs/pennmobile/adapters/AboutAdapter.kt | 9 ++-- .../adapters/GsrReservationsAdapter.kt | 16 +++---- .../adapters/HomeGsrBuildingAdapter.kt | 10 ++--- .../adapters/HomeGsrReservationAdapter.kt | 7 ++-- .../pennmobile/adapters/PollOptionAdapter.kt | 42 +++++++++---------- .../adapters/UniversityEventAdapter.kt | 10 ++--- .../pennmobile/morefragments/MoreFragment.kt | 7 ++-- 7 files changed, 49 insertions(+), 52 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/AboutAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/AboutAdapter.kt index 54d57f82..ab40b70e 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/AboutAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/AboutAdapter.kt @@ -9,7 +9,6 @@ import androidx.recyclerview.widget.RecyclerView import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.databinding.TeamMemberBinding - class AboutAdapter( private var members: ArrayList, ) : RecyclerView.Adapter() { @@ -30,7 +29,7 @@ class AboutAdapter( holder: TeamViewHolder, position: Int, ) { - holder.name_tv.text = members[position] + holder.nameTv.text = members[position] val imageId = when (members[position]) { "Marta García Ferreiro" -> R.drawable.marta @@ -52,13 +51,13 @@ class AboutAdapter( "Baron Ping-Yeh Hsieh" -> R.drawable.baron else -> null } - if (imageId != null) holder.person_iv.setImageResource(imageId) + if (imageId != null) holder.personIv.setImageResource(imageId) } inner class TeamViewHolder( itemBinding: TeamMemberBinding, ) : RecyclerView.ViewHolder(itemBinding.root) { - val person_iv: ImageView = itemBinding.personIv - val name_tv: TextView = itemBinding.nameTv + val personIv: ImageView = itemBinding.personIv + val nameTv: TextView = itemBinding.nameTv } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationsAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationsAdapter.kt index 449d09a1..12a86b8e 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationsAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationsAdapter.kt @@ -58,12 +58,12 @@ class GsrReservationsAdapter( .load(imageUrl) .fit() .centerCrop() - .into(holder.gsr_reservation_iv) + .into(holder.gsrReservationIv) - holder.gsr_reservation_location_tv.text = roomName - holder.gsr_reservation_date_tv.text = day + "\n" + fromHour + "-" + toHour + holder.gsrReservationLocationTv.text = roomName + holder.gsrReservationDateTv.text = day + "\n" + fromHour + "-" + toHour - holder.gsr_reservation_cancel_button.setOnClickListener { + holder.gsrReservationCancelButton.setOnClickListener { // create dialog to confirm that you want to cancel reservation val builder = AlertDialog.Builder(mContext) builder.setTitle("Are you sure?") @@ -142,9 +142,9 @@ class GsrReservationsAdapter( inner class GsrReservationViewHolder( itemBinding: GsrReservationBinding, ) : RecyclerView.ViewHolder(itemBinding.root) { - val gsr_reservation_cancel_button = itemBinding.gsrReservationCancelBtn - val gsr_reservation_location_tv = itemBinding.gsrReservationLocationTv - val gsr_reservation_date_tv = itemBinding.gsrReservationDateTv - val gsr_reservation_iv = itemBinding.gsrReservationIv + val gsrReservationCancelButton = itemBinding.gsrReservationCancelBtn + val gsrReservationLocationTv = itemBinding.gsrReservationLocationTv + val gsrReservationDateTv = itemBinding.gsrReservationDateTv + val gsrReservationIv = itemBinding.gsrReservationIv } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrBuildingAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrBuildingAdapter.kt index e2feb4be..e278226d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrBuildingAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrBuildingAdapter.kt @@ -34,11 +34,11 @@ class HomeGsrBuildingAdapter( position: Int, ) { val building = buildings[position] - holder.home_gsr_building_tv.text = building + holder.homeGsrBuildingTv.text = building if (building == "Huntsman Hall") { - holder.home_gsr_building_iv.setImageResource(R.drawable.huntsman) + holder.homeGsrBuildingIv.setImageResource(R.drawable.huntsman) } else { - holder.home_gsr_building_iv.setImageResource(R.drawable.weigle) + holder.homeGsrBuildingIv.setImageResource(R.drawable.weigle) } holder.itemView.setOnClickListener { fragmentTransact(GsrTabbedFragment(), false) @@ -50,8 +50,8 @@ class HomeGsrBuildingAdapter( inner class HomeGsrBuildingViewHolder( itemBinding: HomeGsrBuildingBinding, ) : RecyclerView.ViewHolder(itemBinding.root) { - val home_gsr_building_iv: ImageView = itemBinding.homeGsrBuildingIv - val home_gsr_building_tv: TextView = itemBinding.homeGsrBuildingTv + val homeGsrBuildingIv: ImageView = itemBinding.homeGsrBuildingIv + val homeGsrBuildingTv: TextView = itemBinding.homeGsrBuildingTv } private fun fragmentTransact( diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt index 068795e1..0b6ea455 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt @@ -76,12 +76,11 @@ class HomeGsrReservationAdapter( override fun getItemCount(): Int = activeReservations.size - inner class GSRReservationViewHolder( itemBinding: GsrListItemBinding, ) : RecyclerView.ViewHolder(itemBinding.root) { - val itemImage : ImageView = itemBinding.itemGsrImage - val itemLocation : TextView = itemBinding.itemGsrLocation - val itemDate : TextView = itemBinding.itemGsrDate + val itemImage: ImageView = itemBinding.itemGsrImage + val itemLocation: TextView = itemBinding.itemGsrLocation + val itemDate: TextView = itemBinding.itemGsrDate } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PollOptionAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PollOptionAdapter.kt index 38e81cb6..2b8bebbf 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PollOptionAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PollOptionAdapter.kt @@ -55,11 +55,11 @@ class PollOptionAdapter( holder: PollHolder, pollOption: PollOption, ) { - holder.tv_option.text = pollOption.choice + holder.tvOption.text = pollOption.choice var startX: Float? = null var startY: Float? = null - holder.seek_bar.setOnTouchListener { v, event -> + holder.seekBar.setOnTouchListener { v, event -> when (event.action) { MotionEvent.ACTION_DOWN -> { startX = event.x @@ -77,24 +77,24 @@ class PollOptionAdapter( true } if (pollOption.selected) { - holder.tv_option.setTextColor(mContext.resources.getColor(R.color.color_secondary)) - holder.tv_percent.setTextColor(mContext.resources.getColor(R.color.color_secondary)) - holder.tv_votes.setTextColor(mContext.resources.getColor(R.color.color_secondary)) - holder.seek_bar.progressDrawable = mContext.getDrawable(R.drawable.poll_track_selected) - holder.card_view.foreground = mContext.getDrawable(R.drawable.card_view_border) + holder.tvOption.setTextColor(mContext.resources.getColor(R.color.color_secondary)) + holder.tvPercent.setTextColor(mContext.resources.getColor(R.color.color_secondary)) + holder.tvVotes.setTextColor(mContext.resources.getColor(R.color.color_secondary)) + holder.seekBar.progressDrawable = mContext.getDrawable(R.drawable.poll_track_selected) + holder.cardView.foreground = mContext.getDrawable(R.drawable.card_view_border) } else { - holder.tv_option.setTextColor(Color.parseColor("#13284B")) - holder.tv_percent.setTextColor(Color.parseColor("#13284B")) - holder.tv_votes.setTextColor(Color.parseColor("#13284B")) - holder.seek_bar.progressDrawable = mContext.getDrawable(R.drawable.poll_track) - holder.card_view.foreground = null + holder.tvOption.setTextColor(Color.parseColor("#13284B")) + holder.tvPercent.setTextColor(Color.parseColor("#13284B")) + holder.tvVotes.setTextColor(Color.parseColor("#13284B")) + holder.seekBar.progressDrawable = mContext.getDrawable(R.drawable.poll_track) + holder.cardView.foreground = null } if (poll.isVisible) { - holder.tv_votes.text = "${pollOption.voteCount}" + holder.tvVotes.text = "${pollOption.voteCount}" val votePercent = (pollOption.voteCount.div(poll.totalVotes.toDouble())) * 100 - holder.tv_percent.text = String.format("%.2f%%", votePercent) - holder.seek_bar.progress = round(votePercent).toInt() - holder.seek_bar.setOnTouchListener { v, event -> true } + holder.tvPercent.text = String.format("%.2f%%", votePercent) + holder.seekBar.progress = round(votePercent).toInt() + holder.seekBar.setOnTouchListener { v, event -> true } } } @@ -112,11 +112,11 @@ class PollOptionAdapter( class PollHolder( itemBinding: PollListItemBinding, ) : RecyclerView.ViewHolder(itemBinding.root) { - internal var tv_option: TextView = itemBinding.tvOption - internal var tv_percent: TextView = itemBinding.tvPercent - internal var seek_bar: SeekBar = itemBinding.seekBar - internal var card_view: CardView = itemBinding.cardView - internal var tv_votes: TextView = itemBinding.tvVotes + internal var tvOption: TextView = itemBinding.tvOption + internal var tvPercent: TextView = itemBinding.tvPercent + internal var seekBar: SeekBar = itemBinding.seekBar + internal var cardView: CardView = itemBinding.cardView + internal var tvVotes: TextView = itemBinding.tvVotes } companion object { diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt index 3d7c767e..64bff5ab 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt @@ -43,9 +43,9 @@ class UniversityEventAdapter( // holder.itemView.event_day.text = dayOfMonth // holder.itemView.event_month.text = month - holder.event_month.text = event.date - holder.event_name.text = name - holder.event_name.isSelected = true + holder.eventMonth.text = event.date + holder.eventName.text = name + holder.eventName.isSelected = true /* if (from == to) { holder.itemView.event_day_of_week.text = start } else { @@ -58,7 +58,7 @@ class UniversityEventAdapter( inner class UniversityEventViewHolder( itemBinding: UniversityEventBinding, ) : RecyclerView.ViewHolder(itemBinding.root) { - val event_month : TextView = itemBinding.eventMonth - val event_name : TextView = itemBinding.eventNameTv + val eventMonth: TextView = itemBinding.eventMonth + val eventName: TextView = itemBinding.eventNameTv } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt index 1eb1ad44..00cb67c7 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt @@ -15,7 +15,6 @@ import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior import com.pennapps.labs.pennmobile.databinding.FragmentMoreBinding import com.pennapps.labs.pennmobile.utils.Utils - class MoreFragment : Fragment() { private lateinit var mActivity: MainActivity @@ -37,9 +36,9 @@ class MoreFragment : Fragment() { val v = binding.root binding.dateView.text = Utils.getCurrentSystemTime() ( - binding.appbarHome.layoutParams - as CoordinatorLayout.LayoutParams - ).behavior = ToolbarBehavior() + binding.appbarHome.layoutParams + as CoordinatorLayout.LayoutParams + ).behavior = ToolbarBehavior() return v } From 72eb287bf0ae6d9e818ab2e1b24fa12f876f4e75 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 22:04:49 -0400 Subject: [PATCH 15/34] LaundryFragment loadingPanel fix --- .../java/com/pennapps/labs/pennmobile/LaundryFragment.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt index 871cc00f..e8bf1e36 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt @@ -20,13 +20,13 @@ import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior import com.pennapps.labs.pennmobile.databinding.FragmentLaundryBinding import com.pennapps.labs.pennmobile.utils.Utils import com.pennapps.labs.pennmobile.viewmodels.LaundryViewModel -import kotlinx.android.synthetic.main.loading_panel.loadingPanel class LaundryFragment : Fragment() { private lateinit var mActivity: MainActivity private lateinit var mStudentLife: StudentLifeRf2 private lateinit var mContext: Context + private lateinit var loadingPanel: View private lateinit var sharedPreferences: SharedPreferences @@ -84,10 +84,12 @@ class LaundryFragment : Fragment() { mActivity.removeTabs() mActivity.setTitle(R.string.laundry) + loadingPanel = view.findViewById(R.id.loadingPanel) + mAdapter = LaundryRoomAdapter(mContext, laundryRooms, roomsData, false) binding.favoriteLaundryList.adapter = mAdapter - loadingPanel?.visibility = View.VISIBLE + loadingPanel.visibility = View.VISIBLE laundryViewModel.favoriteRooms.observe(viewLifecycleOwner) { favorites -> binding.laundryMachineRefresh.isRefreshing = false @@ -106,7 +108,7 @@ class LaundryFragment : Fragment() { mAdapter!!.notifyItemChanged(pos) } - loadingPanel?.visibility = View.GONE + loadingPanel.visibility = View.GONE binding.laundryHelpText.visibility = View.INVISIBLE } From fa9f31542c3d1fffefa8c15d1ea6f358902ba13f Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sat, 28 Sep 2024 22:36:07 -0400 Subject: [PATCH 16/34] DiningCardAdapter ViewBinding Implementation --- .../pennmobile/adapters/DiningCardAdapter.kt | 66 +++++++++---------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningCardAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningCardAdapter.kt index d1028443..1a0f6c62 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningCardAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningCardAdapter.kt @@ -4,7 +4,6 @@ import android.content.Context import android.os.Bundle import android.util.Log import android.view.LayoutInflater -import android.view.View import android.view.View.GONE import android.view.ViewGroup import android.widget.ImageView @@ -19,11 +18,7 @@ import com.pennapps.labs.pennmobile.MenuFragment import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.api.StudentLife import com.pennapps.labs.pennmobile.classes.DiningHall -import kotlinx.android.synthetic.main.dining_list_item.view.dining_progress -import kotlinx.android.synthetic.main.dining_list_item.view.item_dining_hours -import kotlinx.android.synthetic.main.dining_list_item.view.item_dining_image -import kotlinx.android.synthetic.main.dining_list_item.view.item_dining_name -import kotlinx.android.synthetic.main.dining_list_item.view.item_dining_status +import com.pennapps.labs.pennmobile.databinding.DiningListItemBinding import rx.android.schedulers.AndroidSchedulers class DiningCardAdapter( @@ -39,6 +34,29 @@ class DiningCardAdapter( private lateinit var mActivity: MainActivity private lateinit var mStudentLife: StudentLife + override fun onCreateViewHolder( + parent: ViewGroup, + viewType: Int, + ): ViewHolder { + mContext = parent.context + mActivity = mContext as MainActivity + mStudentLife = MainActivity.studentLifeInstance + val itemBinding = DiningListItemBinding.inflate(LayoutInflater.from(mContext), parent, false) + itemBinding.diningProgress.visibility = GONE + return ViewHolder(itemBinding) + } + + // Converts the String representation of a meal name to its corresponding resource ID + private fun getOpenStatusLabel(openMeal: String): Int = + when (openMeal) { + "Breakfast" -> R.string.dining_hall_breakfast + "Brunch" -> R.string.dining_hall_brunch + "Lunch" -> R.string.dining_hall_lunch + "Dinner" -> R.string.dining_hall_dinner + "Late Night" -> R.string.dining_hall_late_night + else -> R.string.dining_hall_open + } + override fun onBindViewHolder( holder: ViewHolder, position: Int, @@ -104,38 +122,14 @@ class DiningCardAdapter( override fun getItemCount(): Int = favoriteHalls.size - override fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int, - ): ViewHolder { - mContext = parent.context - mActivity = mContext as MainActivity - mStudentLife = MainActivity.studentLifeInstance - - val view = LayoutInflater.from(parent.context).inflate(R.layout.dining_list_item, parent, false) - view?.dining_progress?.visibility = GONE - return ViewHolder(view) - } - - // Converts the String representation of a meal name to its corresponding resource ID - private fun getOpenStatusLabel(openMeal: String): Int = - when (openMeal) { - "Breakfast" -> R.string.dining_hall_breakfast - "Brunch" -> R.string.dining_hall_brunch - "Lunch" -> R.string.dining_hall_lunch - "Dinner" -> R.string.dining_hall_dinner - "Late Night" -> R.string.dining_hall_late_night - else -> R.string.dining_hall_open - } - inner class ViewHolder( - itemView: View, - ) : RecyclerView.ViewHolder(itemView) { + itemBinding: DiningListItemBinding, + ) : RecyclerView.ViewHolder(itemBinding.root) { init { - itemImage = itemView.item_dining_image - itemName = itemView.item_dining_name - itemStatus = itemView.item_dining_status - itemHours = itemView.item_dining_hours + itemImage = itemBinding.itemDiningImage + itemName = itemBinding.itemDiningName + itemStatus = itemBinding.itemDiningStatus + itemHours = itemBinding.itemDiningHours } } } From 2a94c8285abe98d5f850b415a3b4d635d2b33374 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sun, 29 Sep 2024 01:49:32 -0400 Subject: [PATCH 17/34] SupportFragment ToolBar Reimplementation (finally figured this jawn out) --- .../labs/pennmobile/SupportFragment.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SupportFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SupportFragment.kt index ee0435e6..b77f3bd2 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SupportFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SupportFragment.kt @@ -7,14 +7,15 @@ import android.view.MenuInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup +import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentTransaction import androidx.fragment.app.ListFragment import com.pennapps.labs.pennmobile.adapters.SupportAdapter import com.pennapps.labs.pennmobile.classes.Contact -import kotlinx.android.synthetic.main.include_main.toolbar class SupportFragment : ListFragment() { private lateinit var mActivity: MainActivity + private lateinit var toolbar: Toolbar override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -49,12 +50,20 @@ class SupportFragment : ListFragment() { ): View? { val view = inflater.inflate(R.layout.fragment_support, container, false) setHasOptionsMenu(false) - mActivity.toolbar.visibility = View.VISIBLE - mActivity.toolbar.setNavigationIcon(R.drawable.ic_back_navigation) - mActivity.toolbar.setNavigationOnClickListener { mActivity.onBackPressed() } return view } + override fun onViewCreated( + view: View, + savedInstanceState: Bundle?, + ) { + super.onViewCreated(view, savedInstanceState) + toolbar = mActivity.findViewById(R.id.toolbar) + toolbar.visibility = View.VISIBLE + toolbar.setNavigationIcon(R.drawable.ic_back_navigation) + toolbar.setNavigationOnClickListener { mActivity.onBackPressed() } + } + override fun onCreateOptionsMenu( menu: Menu, inflater: MenuInflater, @@ -81,7 +90,7 @@ class SupportFragment : ListFragment() { override fun onPause() { super.onPause() - mActivity.toolbar.visibility = View.GONE + toolbar.visibility = View.GONE } override fun onResume() { @@ -93,7 +102,7 @@ class SupportFragment : ListFragment() { } override fun onDestroyView() { - mActivity.toolbar.setNavigationOnClickListener(null) + toolbar.setNavigationOnClickListener(null) super.onDestroyView() } } From ada39e30afdd814f4eb8a858c2a83a4a5c2cced7 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:56:42 -0400 Subject: [PATCH 18/34] MenuFragment toolbar fix --- .../pennapps/labs/pennmobile/MenuFragment.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt index 5fc59b81..c0026a7c 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt @@ -8,18 +8,20 @@ import android.view.MenuInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup +import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter import androidx.viewpager.widget.PagerAdapter import androidx.viewpager.widget.ViewPager import com.pennapps.labs.pennmobile.classes.DiningHall -import kotlinx.android.synthetic.main.include_main.toolbar import org.apache.commons.lang3.StringUtils class MenuFragment : Fragment() { - private var mDiningHall: DiningHall? = null private lateinit var mActivity: MainActivity + private lateinit var toolBar: Toolbar + + private var mDiningHall: DiningHall? = null private var pageAdapter: PagerAdapter? = null inner class TabAdapter( @@ -88,9 +90,7 @@ class MenuFragment : Fragment() { super.onCreate(savedInstanceState) mDiningHall = arguments?.getParcelable("DiningHall") mActivity = activity as MainActivity - mActivity.toolbar.visibility = View.VISIBLE setHasOptionsMenu(true) - mActivity.hideBottomBar() } override fun onCreateView( @@ -108,6 +108,16 @@ class MenuFragment : Fragment() { return v } + override fun onViewCreated( + view: View, + savedInstanceState: Bundle?, + ) { + super.onViewCreated(view, savedInstanceState) + toolBar = mActivity.findViewById(R.id.toolbar) + toolBar.visibility = View.VISIBLE + mActivity.hideBottomBar() + } + override fun onCreateOptionsMenu( menu: Menu, inflater: MenuInflater, From 8d317d63a23f0fad562806a8b108b193a212ae12 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:46:38 -0400 Subject: [PATCH 19/34] LaundrtMachine Adapter viewBinding + Switch to SwitchCompat for alarmswitch widget --- .../adapters/LaundryMachineAdapter.kt | 442 ++++++++++++------ .../morefragments/PreferenceFragment.kt | 6 +- .../main/res/layout/laundry_dryer_item.xml | 2 +- .../main/res/layout/laundry_machine_item.xml | 2 +- 4 files changed, 307 insertions(+), 145 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/LaundryMachineAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/LaundryMachineAdapter.kt index 08cc23d0..e0832d4f 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/LaundryMachineAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/LaundryMachineAdapter.kt @@ -13,8 +13,8 @@ import android.view.View import android.view.ViewGroup import android.widget.CompoundButton import android.widget.ImageView -import android.widget.Switch import android.widget.TextView +import androidx.appcompat.widget.SwitchCompat import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import androidx.vectordrawable.graphics.drawable.Animatable2Compat @@ -23,190 +23,350 @@ import com.airbnb.lottie.LottieAnimationView import com.pennapps.labs.pennmobile.LaundryBroadcastReceiver import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.classes.MachineDetail +import com.pennapps.labs.pennmobile.databinding.LaundryDryerItemBinding +import com.pennapps.labs.pennmobile.databinding.LaundryMachineItemBinding import com.pennapps.labs.pennmobile.showSneakerToast -import kotlinx.android.synthetic.main.laundry_dryer_item.view.bell_notification_icon -import kotlinx.android.synthetic.main.laundry_dryer_item.view.laundry_machine_image_view -import kotlinx.android.synthetic.main.laundry_dryer_item.view.min_left_time class LaundryMachineAdapter( var context: Context, var mMachineDetails: List, machineType: String, roomName: String, -) : RecyclerView.Adapter() { +) : RecyclerView.Adapter() { private var mRoomName: String private var mMachineType: String override fun onCreateViewHolder( parent: ViewGroup, viewType: Int, - ): CustomViewHolder { - val view: View = - if (mMachineType == context.resources.getString(R.string.washer)) { - LayoutInflater.from(parent.context).inflate(R.layout.laundry_machine_item, parent, false) - } else { - LayoutInflater.from(parent.context).inflate(R.layout.laundry_dryer_item, parent, false) - } - return CustomViewHolder(view, context, mMachineDetails) + ): RecyclerView.ViewHolder { + if (mMachineType == "washer") { + val itemBinding = LaundryMachineItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return LaundryMachineViewHolder(itemBinding, context, mMachineDetails) + } else { + val itemBinding = LaundryDryerItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return LaundryDryerViewHolder(itemBinding, context, mMachineDetails) + } } override fun onBindViewHolder( - holder: CustomViewHolder, + holder: RecyclerView.ViewHolder, position: Int, ) { - val detail = mMachineDetails[position] - holder.alarmSwitch.visibility = View.GONE + when (holder) { + is LaundryMachineViewHolder -> holder.bind(position) + is LaundryDryerViewHolder -> holder.bind(position) + } + } - when (val timeRemaining = detail.timeRemaining) { - NOT_AVAILABLE_LABEL -> { - if (mMachineType == context.getString(R.string.washer)) { - holder.machineView!!.setImageResource(R.drawable.washer_na) - } else { - holder.machineView!!.setImageResource(R.drawable.dryer_na) + override fun getItemCount(): Int = mMachineDetails.size + + inner class LaundryMachineViewHolder( + val itemBinding: LaundryMachineItemBinding, + var context: Context, + var machineDetails: List, + ) : RecyclerView.ViewHolder( + itemBinding.root, + ) { + var machineView: ImageView? = itemBinding.laundryMachineImageView + var timeTextView: TextView? = itemBinding.minLeftTime + var notificationBell: LottieAnimationView = itemBinding.bellNotificationIcon + var alarmSwitch: SwitchCompat = itemBinding.laundryAlarmSwitch + + fun bind(position: Int) { + with(itemBinding.root) { + val detail = mMachineDetails[position] + alarmSwitch.visibility = View.GONE + + when (val timeRemaining = detail.timeRemaining) { + NOT_AVAILABLE_LABEL -> { + if (mMachineType == context.getString(R.string.washer)) { + machineView!!.setImageResource(R.drawable.washer_na) + } else { + machineView!!.setImageResource(R.drawable.dryer_na) + } + timeTextView!!.setText(R.string.not_updating_status) + alarmSwitch.visibility = View.GONE + } + OPEN_LABEL -> { + if (mMachineType == context.getString(R.string.washer)) { + machineView!!.setImageResource(R.drawable.ic_washer_available) + } else { + machineView!!.setImageResource(R.drawable.ic_dryer_available) + } + timeTextView!!.setText(R.string.open) + alarmSwitch.visibility = View.GONE + val time = detail.timeRemaining + val id = detail.id + setSwitchState(time, id) + } + else -> { + if (mMachineType == context.getString(R.string.washer)) { + // holder.machineView!!.setImageResource(R.drawable.ic_washer_in_use) + val animated = AnimatedVectorDrawableCompat.create(context, R.drawable.ic_washer_in_use) + animated?.registerAnimationCallback( + object : Animatable2Compat.AnimationCallback() { + override fun onAnimationEnd(drawable: Drawable?) { + animated.start() + } + }, + ) + machineView!!.setImageDrawable(animated) + animated?.start() + } else { + machineView!!.setImageResource(R.drawable.ic_dryer_in_use) + } + timeTextView!!.setTextColor(ContextCompat.getColor(context, R.color.secondary_text_color)) + timeTextView!!.text = timeRemaining.toString() + val time = detail.timeRemaining + val id = detail.id + setSwitchState(time, id) + machineView?.setOnClickListener { + itemView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP) + alarmSwitch.performClick() + } + } } - holder.timeTextView!!.setText(R.string.not_updating_status) - holder.alarmSwitch.visibility = View.GONE } - OPEN_LABEL -> { - if (mMachineType == context.getString(R.string.washer)) { - holder.machineView!!.setImageResource(R.drawable.ic_washer_available) - } else { - holder.machineView!!.setImageResource(R.drawable.ic_dryer_available) - } - holder.timeTextView!!.setText(R.string.open) - holder.alarmSwitch.visibility = View.GONE - val time = detail.timeRemaining - val id = detail.id - setSwitchState(time, holder, id) + } + + fun setSwitchState( + time: Int, + machineId: Int, + ) { + val id = (mRoomName + mMachineType).hashCode() + machineId + val intent = Intent(context, LaundryBroadcastReceiver::class.java) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + intent.putExtra(context.resources.getString(R.string.laundry_room_name), mRoomName) + intent.putExtra(context.resources.getString(R.string.laundry_machine_type), mMachineType) + intent.putExtra(context.resources.getString(R.string.laundry_machine_id), id) + val alarmIntent: PendingIntent? = + PendingIntent.getBroadcast( + context, + id, + intent, + PendingIntent.FLAG_NO_CREATE or PendingIntent.FLAG_IMMUTABLE, + ) + + // switch is off if no alarm + if (alarmIntent != null) { + alarmSwitch.isChecked = true + notificationBell.visibility = View.VISIBLE + notificationBell.playAnimation() + } else { + alarmSwitch.isChecked = false } - else -> { - if (mMachineType == context.getString(R.string.washer)) { - // holder.machineView!!.setImageResource(R.drawable.ic_washer_in_use) - val animated = AnimatedVectorDrawableCompat.create(context, R.drawable.ic_washer_in_use) - animated?.registerAnimationCallback( - object : Animatable2Compat.AnimationCallback() { - override fun onAnimationEnd(drawable: Drawable?) { - animated.start() - } - }, + alarmSwitch.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> + val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager + + if (isChecked) { + notificationBell.visibility = View.VISIBLE + notificationBell.playAnimation() + + val alarmIntent1 = + PendingIntent.getBroadcast( + context, + id, + intent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE, + ) + // for testing 10 second notification + // alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 10000, alarmIntent); + alarmManager[AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + time * 60000] = alarmIntent1 + + val message = context.resources.getQuantityString(R.plurals.laundry_alarm_on, time, time) + ( + ((context as Activity).window?.decorView as ViewGroup).showSneakerToast( + message, + null, + R.color.sneakerBlurColorOverlay, + ) ) - holder.machineView!!.setImageDrawable(animated) - animated?.start() } else { - holder.machineView!!.setImageResource(R.drawable.ic_dryer_in_use) - } - holder.timeTextView!!.setTextColor(ContextCompat.getColor(context, R.color.secondary_text_color)) - holder.timeTextView!!.text = timeRemaining.toString() - val time = detail.timeRemaining - val id = detail.id - setSwitchState(time, holder, id) - holder.machineView?.setOnClickListener { - holder.itemView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP) - holder.alarmSwitch.performClick() + notificationBell.visibility = View.INVISIBLE + // cancel alarm if exists + val alarmIntent1 = + PendingIntent.getBroadcast( + context, + id, + intent, + PendingIntent.FLAG_NO_CREATE or PendingIntent.FLAG_IMMUTABLE, + ) + if (alarmIntent1 != null) { + alarmManager.cancel(alarmIntent1) + alarmIntent1.cancel() + } + if (buttonView.context == null) { + return@setOnCheckedChangeListener + } + + val message = context.resources.getString(R.string.laundry_alarm_off) + ( + ((context as Activity).window?.decorView as ViewGroup).showSneakerToast( + message, + null, + R.color.sneakerBlurColorOverlay, + ) + ) } } } } - override fun getItemCount(): Int = mMachineDetails.size - - inner class CustomViewHolder( - view: View, + inner class LaundryDryerViewHolder( + val itemBinding: LaundryDryerItemBinding, var context: Context, var machineDetails: List, ) : RecyclerView.ViewHolder( - view, + itemBinding.root, ) { - var machineView: ImageView? = view.laundry_machine_image_view - var timeTextView: TextView? = view.min_left_time - var notificationBell: LottieAnimationView = view.bell_notification_icon - var alarmSwitch: Switch = view.findViewById(R.id.laundry_alarm_switch) as Switch - } + var machineView: ImageView? = itemBinding.laundryMachineImageView + var timeTextView: TextView? = itemBinding.minLeftTime + var notificationBell: LottieAnimationView = itemBinding.bellNotificationIcon + var alarmSwitch: SwitchCompat = itemBinding.laundryAlarmSwitch - // adds alarm to machine - private fun setSwitchState( - time: Int, - holder: CustomViewHolder, - machineId: Int, - ) { - val id = (mRoomName + mMachineType).hashCode() + machineId - val intent = Intent(context, LaundryBroadcastReceiver::class.java) - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK - intent.putExtra(context.resources.getString(R.string.laundry_room_name), mRoomName) - intent.putExtra(context.resources.getString(R.string.laundry_machine_type), mMachineType) - intent.putExtra(context.resources.getString(R.string.laundry_machine_id), id) - val alarmIntent: PendingIntent? = - PendingIntent.getBroadcast( - context, - id, - intent, - PendingIntent.FLAG_NO_CREATE or PendingIntent.FLAG_IMMUTABLE, - ) - - // switch is off if no alarm - if (alarmIntent != null) { - holder.alarmSwitch.isChecked = true - holder.notificationBell.visibility = View.VISIBLE - holder.notificationBell.playAnimation() - } else { - holder.alarmSwitch.isChecked = false + fun bind(position: Int) { + with(itemBinding.root) { + val detail = mMachineDetails[position] + alarmSwitch.visibility = View.GONE + + when (val timeRemaining = detail.timeRemaining) { + NOT_AVAILABLE_LABEL -> { + if (mMachineType == context.getString(R.string.washer)) { + machineView!!.setImageResource(R.drawable.washer_na) + } else { + machineView!!.setImageResource(R.drawable.dryer_na) + } + timeTextView!!.setText(R.string.not_updating_status) + alarmSwitch.visibility = View.GONE + } + OPEN_LABEL -> { + if (mMachineType == context.getString(R.string.washer)) { + machineView!!.setImageResource(R.drawable.ic_washer_available) + } else { + machineView!!.setImageResource(R.drawable.ic_dryer_available) + } + timeTextView!!.setText(R.string.open) + alarmSwitch.visibility = View.GONE + val time = detail.timeRemaining + val id = detail.id + setSwitchState(time, id) + } + else -> { + if (mMachineType == context.getString(R.string.washer)) { + // holder.machineView!!.setImageResource(R.drawable.ic_washer_in_use) + val animated = AnimatedVectorDrawableCompat.create(context, R.drawable.ic_washer_in_use) + animated?.registerAnimationCallback( + object : Animatable2Compat.AnimationCallback() { + override fun onAnimationEnd(drawable: Drawable?) { + animated.start() + } + }, + ) + machineView!!.setImageDrawable(animated) + animated?.start() + } else { + machineView!!.setImageResource(R.drawable.ic_dryer_in_use) + } + timeTextView!!.setTextColor(ContextCompat.getColor(context, R.color.secondary_text_color)) + timeTextView!!.text = timeRemaining.toString() + val time = detail.timeRemaining + val id = detail.id + setSwitchState(time, id) + machineView?.setOnClickListener { + itemView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP) + alarmSwitch.performClick() + } + } + } + } } - holder.alarmSwitch.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> - val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager - - if (isChecked) { - holder.notificationBell.visibility = View.VISIBLE - holder.notificationBell.playAnimation() - - val alarmIntent1 = - PendingIntent.getBroadcast( - context, - id, - intent, - PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE, - ) - // for testing 10 second notification - // alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 10000, alarmIntent); - alarmManager[AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + time * 60000] = alarmIntent1 - - val message = context.resources.getQuantityString(R.plurals.laundry_alarm_on, time, time) - ( - ((context as Activity).window?.decorView as ViewGroup).showSneakerToast( - message, - null, - R.color.sneakerBlurColorOverlay, - ) + + fun setSwitchState( + time: Int, + machineId: Int, + ) { + val id = (mRoomName + mMachineType).hashCode() + machineId + val intent = Intent(context, LaundryBroadcastReceiver::class.java) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + intent.putExtra(context.resources.getString(R.string.laundry_room_name), mRoomName) + intent.putExtra(context.resources.getString(R.string.laundry_machine_type), mMachineType) + intent.putExtra(context.resources.getString(R.string.laundry_machine_id), id) + val alarmIntent: PendingIntent? = + PendingIntent.getBroadcast( + context, + id, + intent, + PendingIntent.FLAG_NO_CREATE or PendingIntent.FLAG_IMMUTABLE, ) + + // switch is off if no alarm + if (alarmIntent != null) { + alarmSwitch.isChecked = true + notificationBell.visibility = View.VISIBLE + notificationBell.playAnimation() } else { - holder.notificationBell.visibility = View.INVISIBLE - // cancel alarm if exists - val alarmIntent1 = - PendingIntent.getBroadcast( - context, - id, - intent, - PendingIntent.FLAG_NO_CREATE or PendingIntent.FLAG_IMMUTABLE, + alarmSwitch.isChecked = false + } + alarmSwitch.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> + val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager + + if (isChecked) { + notificationBell.visibility = View.VISIBLE + notificationBell.playAnimation() + + val alarmIntent1 = + PendingIntent.getBroadcast( + context, + id, + intent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE, + ) + // for testing 10 second notification + // alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 10000, alarmIntent); + alarmManager[AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + time * 60000] = alarmIntent1 + + val message = context.resources.getQuantityString(R.plurals.laundry_alarm_on, time, time) + ( + ((context as Activity).window?.decorView as ViewGroup).showSneakerToast( + message, + null, + R.color.sneakerBlurColorOverlay, + ) ) - if (alarmIntent1 != null) { - alarmManager.cancel(alarmIntent1) - alarmIntent1.cancel() - } - if (buttonView.context == null) { - return@setOnCheckedChangeListener - } + } else { + notificationBell.visibility = View.INVISIBLE + // cancel alarm if exists + val alarmIntent1 = + PendingIntent.getBroadcast( + context, + id, + intent, + PendingIntent.FLAG_NO_CREATE or PendingIntent.FLAG_IMMUTABLE, + ) + if (alarmIntent1 != null) { + alarmManager.cancel(alarmIntent1) + alarmIntent1.cancel() + } + if (buttonView.context == null) { + return@setOnCheckedChangeListener + } - val message = context.resources.getString(R.string.laundry_alarm_off) - ( - ((context as Activity).window?.decorView as ViewGroup).showSneakerToast( - message, - null, - R.color.sneakerBlurColorOverlay, + val message = context.resources.getString(R.string.laundry_alarm_off) + ( + ((context as Activity).window?.decorView as ViewGroup).showSneakerToast( + message, + null, + R.color.sneakerBlurColorOverlay, + ) ) - ) + } } } } + // adds alarm to machine + companion object { // labels for ordering const val OPEN_LABEL = 400 diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/PreferenceFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/PreferenceFragment.kt index 1880b88d..6b45b664 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/PreferenceFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/PreferenceFragment.kt @@ -10,6 +10,7 @@ import android.view.View import android.view.ViewGroup import android.webkit.CookieManager import android.widget.TextView +import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentTransaction import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat @@ -22,7 +23,6 @@ import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.SupportFragment import com.pennapps.labs.pennmobile.components.dialog.CustomAlertDialogue import com.pennapps.labs.pennmobile.showSneakerToast -import kotlinx.android.synthetic.main.include_main.toolbar /** * Created by Davies Lumumba Spring 2021 @@ -30,6 +30,7 @@ import kotlinx.android.synthetic.main.include_main.toolbar class PreferenceFragment : PreferenceFragmentCompat() { private lateinit var mContext: Context private lateinit var mActivity: MainActivity + private lateinit var toolbar: Toolbar override fun onAttach(context: Context) { super.onAttach(context) @@ -43,7 +44,8 @@ class PreferenceFragment : PreferenceFragmentCompat() { super.onViewCreated(view, savedInstanceState) listView.isVerticalScrollBarEnabled = false mActivity = mContext as MainActivity - mActivity.toolbar.visibility = View.GONE + toolbar = mActivity.findViewById(R.id.toolbar) + toolbar.visibility = View.GONE val sp = PreferenceManager.getDefaultSharedPreferences(mActivity) val editor = sp.edit() diff --git a/PennMobile/src/main/res/layout/laundry_dryer_item.xml b/PennMobile/src/main/res/layout/laundry_dryer_item.xml index 8f1177a5..9c82d460 100644 --- a/PennMobile/src/main/res/layout/laundry_dryer_item.xml +++ b/PennMobile/src/main/res/layout/laundry_dryer_item.xml @@ -17,7 +17,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> - - Date: Tue, 1 Oct 2024 15:37:30 -0400 Subject: [PATCH 20/34] Created ViewModels Folder (So it won't be too chaotic when I migrate homeAdapter to viewBinding) and GsrBuildingAdapter viewBinding implementation --- .../labs/pennmobile/GsrBuildingHolder.kt | 19 ------------------- .../pennmobile/adapters/GsrBuildingAdapter.kt | 11 ++++------- .../pennmobile/adapters/GsrRoomAdapter.kt | 2 +- .../viewholders/GsrBuildingHolder.kt | 12 ++++++++++++ .../{ => viewholders}/GsrRoomHolder.kt | 2 +- 5 files changed, 18 insertions(+), 28 deletions(-) delete mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrBuildingHolder.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/GsrBuildingHolder.kt rename PennMobile/src/main/java/com/pennapps/labs/pennmobile/{ => viewholders}/GsrRoomHolder.kt (92%) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrBuildingHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrBuildingHolder.kt deleted file mode 100644 index 72a89f5d..00000000 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrBuildingHolder.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.pennapps.labs.pennmobile - -import android.view.View -import android.widget.TextView -import androidx.recyclerview.widget.RecyclerView -import kotlinx.android.synthetic.main.gsr_building.view.gsr_availability_in_building -import kotlinx.android.synthetic.main.gsr_building.view.gsr_building_name - -class GsrBuildingHolder( - itemView: View, -) : RecyclerView.ViewHolder(itemView) { - internal var gsrBuildingName: TextView? = null - internal var recyclerView: RecyclerView? = null - - init { - recyclerView = itemView.gsr_availability_in_building - gsrBuildingName = itemView.gsr_building_name - } -} diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrBuildingAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrBuildingAdapter.kt index 5f6a07ec..7ca4adf0 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrBuildingAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrBuildingAdapter.kt @@ -5,9 +5,9 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import com.pennapps.labs.pennmobile.GsrBuildingHolder -import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.classes.GSRContainer +import com.pennapps.labs.pennmobile.databinding.GsrBuildingBinding +import com.pennapps.labs.pennmobile.viewholders.GsrBuildingHolder import org.joda.time.DateTime class GsrBuildingAdapter( @@ -21,11 +21,8 @@ class GsrBuildingAdapter( parent: ViewGroup, viewType: Int, ): GsrBuildingHolder { - val view = - LayoutInflater - .from(parent.context) - .inflate(R.layout.gsr_building, parent, false) - return GsrBuildingHolder(view) + val itemBinding = GsrBuildingBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return GsrBuildingHolder(itemBinding) } override fun onBindViewHolder( diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrRoomAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrRoomAdapter.kt index b7643234..02f80417 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrRoomAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrRoomAdapter.kt @@ -6,10 +6,10 @@ import android.view.ViewGroup import androidx.fragment.app.FragmentTransaction import androidx.recyclerview.widget.RecyclerView import com.pennapps.labs.pennmobile.BookGsrFragment -import com.pennapps.labs.pennmobile.GsrRoomHolder import com.pennapps.labs.pennmobile.MainActivity import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.databinding.GsrRoomBinding +import com.pennapps.labs.pennmobile.viewholders.GsrRoomHolder import org.joda.time.DateTime class GsrRoomAdapter( diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/GsrBuildingHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/GsrBuildingHolder.kt new file mode 100644 index 00000000..482b4847 --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/GsrBuildingHolder.kt @@ -0,0 +1,12 @@ +package com.pennapps.labs.pennmobile.viewholders + +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.pennapps.labs.pennmobile.databinding.GsrBuildingBinding + +class GsrBuildingHolder( + itemBinding: GsrBuildingBinding, +) : RecyclerView.ViewHolder(itemBinding.root) { + internal var gsrBuildingName: TextView = itemBinding.gsrBuildingName + internal var recyclerView: RecyclerView? = itemBinding.gsrAvailabilityInBuilding +} diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrRoomHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/GsrRoomHolder.kt similarity index 92% rename from PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrRoomHolder.kt rename to PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/GsrRoomHolder.kt index 64ae4603..95d9c5e7 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrRoomHolder.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/GsrRoomHolder.kt @@ -1,4 +1,4 @@ -package com.pennapps.labs.pennmobile +package com.pennapps.labs.pennmobile.viewholders import android.widget.LinearLayout import android.widget.TextView From bf5e3397933fad505cbf5dd5e33027d7f9830913 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Wed, 2 Oct 2024 01:38:22 -0400 Subject: [PATCH 21/34] HomeAdapter Viewbinding implementation and ViewHolder creation (actual crash out worthy debug session) --- .../labs/pennmobile/adapters/HomeAdapter.kt | 584 +++++++++--------- .../pennmobile/viewholders/HomeBaseHolder.kt | 13 + .../pennmobile/viewholders/HomeGSRHolder.kt | 13 + .../viewholders/HomeNewsCardHolder.kt | 19 + .../pennmobile/viewholders/HomePollHolder.kt | 14 + .../pennmobile/viewholders/HomePostHolder.kt | 17 + 6 files changed, 357 insertions(+), 303 deletions(-) create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeBaseHolder.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeGSRHolder.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeNewsCardHolder.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomePollHolder.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomePostHolder.kt diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeAdapter.kt index 1ed8bbe6..54d966a1 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeAdapter.kt @@ -53,36 +53,18 @@ import com.pennapps.labs.pennmobile.classes.PollCell import com.pennapps.labs.pennmobile.classes.Post import com.pennapps.labs.pennmobile.classes.PostCell import com.pennapps.labs.pennmobile.components.sneaker.Utils.convertToDp +import com.pennapps.labs.pennmobile.databinding.HomeBaseCardBinding +import com.pennapps.labs.pennmobile.databinding.HomeGsrCardBinding +import com.pennapps.labs.pennmobile.databinding.HomeNewsCardBinding +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.HomeGSRHolder +import com.pennapps.labs.pennmobile.viewholders.HomeNewsCardHolder +import com.pennapps.labs.pennmobile.viewholders.HomePollHolder +import com.pennapps.labs.pennmobile.viewholders.HomePostHolder import eightbitlab.com.blurview.RenderScriptBlur -import kotlinx.android.synthetic.main.home_base_card.view.dining_prefs_btn -import kotlinx.android.synthetic.main.home_base_card.view.home_card_rv -import kotlinx.android.synthetic.main.home_base_card.view.home_card_subtitle -import kotlinx.android.synthetic.main.home_base_card.view.home_card_title -import kotlinx.android.synthetic.main.home_gsr_card.view.home_gsr_button -import kotlinx.android.synthetic.main.home_gsr_card.view.home_gsr_rv -import kotlinx.android.synthetic.main.home_gsr_card.view.home_gsr_subtitle -import kotlinx.android.synthetic.main.home_gsr_card.view.home_gsr_title -import kotlinx.android.synthetic.main.home_news_card.view.blurView -import kotlinx.android.synthetic.main.home_news_card.view.button -import kotlinx.android.synthetic.main.home_news_card.view.dot_divider -import kotlinx.android.synthetic.main.home_news_card.view.home_news_iv -import kotlinx.android.synthetic.main.home_news_card.view.home_news_subtitle -import kotlinx.android.synthetic.main.home_news_card.view.home_news_timestamp -import kotlinx.android.synthetic.main.home_news_card.view.home_news_title -import kotlinx.android.synthetic.main.home_news_card.view.news_card_container -import kotlinx.android.synthetic.main.home_news_card.view.news_card_logo -import kotlinx.android.synthetic.main.home_news_card.view.news_info_icon -import kotlinx.android.synthetic.main.home_post_card.view.home_post_card -import kotlinx.android.synthetic.main.home_post_card.view.home_post_iv -import kotlinx.android.synthetic.main.home_post_card.view.home_post_source -import kotlinx.android.synthetic.main.home_post_card.view.home_post_subtitle -import kotlinx.android.synthetic.main.home_post_card.view.home_post_timestamp -import kotlinx.android.synthetic.main.home_post_card.view.home_post_title -import kotlinx.android.synthetic.main.home_post_card.view.postBlurView -import kotlinx.android.synthetic.main.home_post_card.view.post_card_container -import kotlinx.android.synthetic.main.poll_card.view.home_card_subtitle_2 -import kotlinx.android.synthetic.main.poll_card.view.vote_btn import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import retrofit.ResponseCallback @@ -92,7 +74,7 @@ import rx.Observable class HomeAdapter( private val dataModel: HomepageDataModel, -) : RecyclerView.Adapter() { +) : RecyclerView.Adapter() { private lateinit var mContext: Context private lateinit var mActivity: MainActivity private lateinit var mStudentLife: StudentLife @@ -123,38 +105,35 @@ class HomeAdapter( override fun onCreateViewHolder( parent: ViewGroup, viewType: Int, - ): ViewHolder { + ): RecyclerView.ViewHolder { mContext = parent.context mStudentLife = MainActivity.studentLifeInstance mActivity = mContext as MainActivity return when (viewType) { NEWS -> { - ViewHolder( - LayoutInflater.from(mContext).inflate(R.layout.home_news_card, parent, false), - ) + val itemBinding = HomeNewsCardBinding.inflate(LayoutInflater.from(mContext), parent, false) + return HomeNewsCardHolder(itemBinding) } POST -> { - ViewHolder( - LayoutInflater.from(mContext).inflate(R.layout.home_post_card, parent, false), - ) + val itemBinding = HomePostCardBinding.inflate(LayoutInflater.from(mContext), parent, false) + return HomePostHolder(itemBinding) } FEATURE -> { - ViewHolder( - LayoutInflater.from(mContext).inflate(R.layout.home_post_card, parent, false), - ) + val itemBinding = HomePostCardBinding.inflate(LayoutInflater.from(mContext), parent, false) + return HomePostHolder(itemBinding) } POLL -> { - ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.poll_card, parent, false)) + val itemBinding = PollCardBinding.inflate(LayoutInflater.from(mContext), parent, false) + return HomePollHolder(itemBinding) } GSR_BOOKING -> { - ViewHolder( - LayoutInflater.from(mContext).inflate(R.layout.home_gsr_card, parent, false), - ) + val itemBinding = HomeGsrCardBinding.inflate(LayoutInflater.from(mContext), parent, false) + return HomeGSRHolder(itemBinding) } NOT_SUPPORTED -> { @@ -164,26 +143,25 @@ class HomeAdapter( } else -> { - ViewHolder( - LayoutInflater.from(mContext).inflate(R.layout.home_base_card, parent, false), - ) + val itemBinding = HomeBaseCardBinding.inflate(LayoutInflater.from(mContext), parent, false) + return HomeBaseHolder(itemBinding) } } } override fun onBindViewHolder( - holder: ViewHolder, + holder: RecyclerView.ViewHolder, position: Int, ) { val cell = dataModel.getCell(position) when (cell.type) { - "dining" -> bindDiningCell(holder, cell as DiningCell) - "calendar" -> bindCalendarCell(holder, cell as CalendarCell) - "news" -> bindNewsCell(holder, cell as NewsCell) - "laundry" -> bindLaundryCell(holder, cell as LaundryCell) - "post" -> bindPostCell(holder, cell as PostCell) - "poll" -> bindPollCell(holder, cell as PollCell, position) - "gsr_booking" -> bindGSRCell(holder, cell as GSRCell) + "dining" -> bindDiningCell(holder as HomeBaseHolder, cell as DiningCell) + "calendar" -> bindCalendarCell(holder as HomeBaseHolder, cell as CalendarCell) + "news" -> bindNewsCard(holder as HomeNewsCardHolder, cell as NewsCell) + "laundry" -> bindLaundryCell(holder as HomeBaseHolder, 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) "none" -> Log.i("HomeAdapter", "Empty cell at position $position") else -> Log.i("HomeAdapter", "Unsupported type of data at position $position") } @@ -191,12 +169,6 @@ class HomeAdapter( override fun getItemCount(): Int = dataModel.getSize() - inner class ViewHolder( - itemView: View, - ) : RecyclerView.ViewHolder(itemView) { - val view = itemView - } - override fun getItemViewType(position: Int): Int { val cell = dataModel.getCell(position) return when (cell.type) { @@ -213,14 +185,74 @@ class HomeAdapter( } } + /** Checks if the chrome tab is supported on the current device. */ + private fun Context.isChromeCustomTabsSupported(): Boolean { + val serviceIntent = Intent("android.support.customtabs.action.CustomTabsService") + serviceIntent.setPackage("com.android.chrome") + val resolveInfos = this.packageManager.queryIntentServices(serviceIntent, 0) + return resolveInfos.isNotEmpty() + } + + // Chrome custom tabs to launch news site + internal inner class NewsCustomTabsServiceConnection : CustomTabsServiceConnection() { + override fun onCustomTabsServiceConnected( + name: ComponentName, + client: CustomTabsClient, + ) { + mCustomTabsClient = client + mCustomTabsClient?.warmup(0) + session = mCustomTabsClient?.newSession(null) + } + + override fun onServiceDisconnected(name: ComponentName) { + mCustomTabsClient = null + session = null + customTabsIntent = null + } + } + + private fun bindLaundryCell( + holder: HomeBaseHolder, + cell: LaundryCell, + ) { + val roomID = cell.roomId + holder.homeSubtitle.text = "LAUNDRY" + holder.homeRv.layoutManager = + LinearLayoutManager( + mContext, + LinearLayoutManager.VERTICAL, + false, + ) + + val params: ConstraintLayout.LayoutParams = + holder.homeRv.layoutParams as ConstraintLayout.LayoutParams + params.setMargins(0, 0, 0, 0) + params.marginStart = 0 + + holder.homeRv.layoutParams = params + + try { + mStudentLife.room(roomID).subscribe({ room -> + mActivity.runOnUiThread { + holder.homeTitle.text = room.name + val rooms = arrayListOf(room) + holder.homeRv.adapter = + LaundryRoomAdapter(mContext, rooms, null, true) + } + }, { throwable -> mActivity.runOnUiThread { throwable.printStackTrace() } }) + } catch (e: Exception) { + e.printStackTrace() + } + } + private fun bindDiningCell( - holder: ViewHolder, + holder: HomeBaseHolder, cell: DiningCell, ) { - holder.itemView.home_card_title.text = "Favorites" - holder.itemView.home_card_subtitle.text = "DINING HALLS" - holder.itemView.dining_prefs_btn.visibility = View.VISIBLE - holder.itemView.dining_prefs_btn.setOnClickListener { + holder.homeTitle.text = "Favorites" + holder.homeSubtitle.text = "DINING HALLS" + holder.diningPrefsBtn.visibility = View.VISIBLE + holder.diningPrefsBtn.setOnClickListener { mActivity.supportFragmentManager .beginTransaction() .replace(R.id.content_frame, DiningSettingsFragment(dataModel)) @@ -246,13 +278,13 @@ class HomeAdapter( } } getMenus(favorites) - holder.itemView.home_card_rv.layoutManager = + holder.homeRv.layoutManager = LinearLayoutManager( mContext, LinearLayoutManager.VERTICAL, false, ) - holder.itemView.home_card_rv.adapter = DiningCardAdapter(favorites) + holder.homeRv.adapter = DiningCardAdapter(favorites) } } } catch (e: Exception) { @@ -260,149 +292,11 @@ class HomeAdapter( } } - private fun bindNewsCell( - holder: ViewHolder, - cell: NewsCell, - ) { - val article = cell.article - holder.itemView.home_news_title.text = article?.title - holder.itemView.home_news_subtitle.text = article?.subtitle - holder.itemView.home_news_timestamp.text = article?.timestamp?.trim() - - Glide - .with(mContext) - .load(article?.imageUrl) - .fitCenter() - .centerCrop() - .into(holder.itemView.home_news_iv) - - /** Adds dynamically generated accent color from the fetched image to the news card */ - var accentColor: Int = getColor(mContext, R.color.black) - mActivity.lifecycleScope.launch(Dispatchers.Default) { - val bitmap = - Glide - .with(mContext) - .load(article?.imageUrl) - .submit() - .get() - .toBitmap() - - // Create palette from bitmap - fun createPaletteSync(bitmap: Bitmap): Palette = Palette.from(bitmap).generate() - val vibrantSwatch: Palette.Swatch? = createPaletteSync(bitmap).darkVibrantSwatch - vibrantSwatch?.rgb?.let { accentColor = it } - - mActivity.runOnUiThread { - // Change all the components to match the accent color palette - vibrantSwatch?.titleTextColor?.let { - DrawableCompat.setTint( - DrawableCompat.wrap(holder.itemView.news_card_logo.drawable), - ColorUtils.setAlphaComponent(it, 150), - ) - DrawableCompat.setTint( - DrawableCompat.wrap(holder.itemView.news_info_icon.drawable), - it, - ) - DrawableCompat.setTint( - DrawableCompat.wrap(holder.itemView.dot_divider.drawable), - it, - ) - holder.itemView.button.setTextColor(ColorUtils.setAlphaComponent(it, 150)) - DrawableCompat.setTint( - DrawableCompat.wrap(holder.itemView.button.background), - it, - ) - holder.itemView.home_news_title.setTextColor( - ColorUtils.setAlphaComponent( - it, - 150, - ), - ) - holder.itemView.home_news_subtitle.setTextColor(it) - holder.itemView.home_news_timestamp.setTextColor(it) - } - holder.itemView.news_card_container.background = - BitmapDrawable( - holder.view.resources, - bitmap, - ) - holder.itemView.blurView - .setOverlayColor(ColorUtils.setAlphaComponent(accentColor, 150)) - - // tell model that the news blur view has been loaded - dataModel.notifyNewsBlurLoaded() - } - } - - /** Logic for the more info button on the news card */ - holder.itemView.news_info_icon.setOnClickListener { - when (holder.itemView.home_news_subtitle.visibility) { - View.GONE -> { - holder.itemView.home_news_subtitle.visibility = View.VISIBLE - holder.itemView.home_news_title.setPadding(0, 0, 0, 0) - holder.itemView.blurView - .setOverlayColor(ColorUtils.setAlphaComponent(accentColor, 250)) - } - - View.VISIBLE -> { - holder.itemView.home_news_subtitle.visibility = View.GONE - holder.itemView.home_news_title.setPadding(0, 0, 0, convertToDp(mContext, 8f)) - holder.itemView.blurView - .setOverlayColor(ColorUtils.setAlphaComponent(accentColor, 150)) - } - } - } - - /** Sets up blur view on news card */ - holder.itemView.blurView - .setupWith(holder.itemView.news_card_container, RenderScriptBlur(mContext)) - .setFrameClearDrawable(ColorDrawable(getColor(mContext, R.color.white))) - .setBlurRadius(25f) - - holder.itemView.button.setOnClickListener { - val url = article?.articleUrl - - val connection = NewsCustomTabsServiceConnection() - builder = CustomTabsIntent.Builder() - share = Intent(Intent.ACTION_SEND) - share?.type = "text/plain" - builder?.setToolbarColor(0x3E50B4) - builder?.setStartAnimations( - mContext, - androidx.appcompat.R.anim.abc_popup_enter, - androidx.appcompat.R.anim.abc_popup_exit, - ) - CustomTabsClient.bindCustomTabsService( - mContext, - NewsFragment.CUSTOM_TAB_PACKAGE_NAME, - connection, - ) - - if (mContext.isChromeCustomTabsSupported()) { - share?.putExtra(Intent.EXTRA_TEXT, url) - builder?.addMenuItem( - "Share", - PendingIntent.getActivity( - mContext, - 0, - share, - PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE, - ), - ) - customTabsIntent = builder?.build() - customTabsIntent?.launchUrl(mActivity, Uri.parse(url)) - } else { - val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) - startActivity(mContext, browserIntent, null) - } - } - } - private fun bindCalendarCell( - holder: ViewHolder, + holder: HomeBaseHolder, cell: CalendarCell, ) { - val events = cell.events ?: ArrayList() + val events = cell.events var i = events.size - 1 val eventList: ArrayList = ArrayList() @@ -414,83 +308,49 @@ class HomeAdapter( } eventList.reverse() - holder.itemView.home_card_title.text = "Upcoming Events" - holder.itemView.home_card_subtitle.text = "UNIVERSITY NOTIFICATIONS" + holder.homeTitle.text = "Upcoming Events" + holder.homeSubtitle.text = "UNIVERSITY NOTIFICATIONS" - holder.itemView.home_card_rv.layoutManager = - LinearLayoutManager( - mContext, - LinearLayoutManager.VERTICAL, - false, - ) - - holder.itemView.home_card_rv.adapter = UniversityEventAdapter(eventList) - } - - private fun bindLaundryCell( - holder: ViewHolder, - cell: LaundryCell, - ) { - val roomID = cell.roomId - holder.itemView.home_card_subtitle.text = "LAUNDRY" - holder.itemView.home_card_rv.layoutManager = + holder.homeRv.layoutManager = LinearLayoutManager( mContext, LinearLayoutManager.VERTICAL, false, ) - val params: ConstraintLayout.LayoutParams = - holder.itemView.home_card_rv.layoutParams as ConstraintLayout.LayoutParams - params.setMargins(0, 0, 0, 0) - params.marginStart = 0 - - holder.itemView.home_card_rv.layoutParams = params - - try { - mStudentLife.room(roomID).subscribe({ room -> - mActivity.runOnUiThread { - holder.itemView.home_card_title.text = room.name - val rooms = arrayListOf(room) - holder.itemView.home_card_rv.adapter = - LaundryRoomAdapter(mContext, rooms, null, true) - } - }, { throwable -> mActivity.runOnUiThread { throwable.printStackTrace() } }) - } catch (e: Exception) { - e.printStackTrace() - } + holder.homeRv.adapter = UniversityEventAdapter(eventList) } private fun bindPostCell( - holder: ViewHolder, + holder: HomePostHolder, cell: PostCell, ) { val post = cell.post // if the post is a draft, then change the color and add a note if (cell.post.status == Post.DRAFT) { - holder.itemView.home_post_title.setTextColor(Color.parseColor(DRAFT_COLOR)) + holder.homePostTitle.setTextColor(Color.parseColor(DRAFT_COLOR)) val draftSubtitle = post.subtitle + DRAFT_NOTE - holder.itemView.home_post_subtitle.text = draftSubtitle + holder.homePostSubtitle.text = draftSubtitle } else { - holder.itemView.home_post_subtitle.text = post.subtitle + holder.homePostSubtitle.text = post.subtitle } - holder.itemView.home_post_title.text = post.title - holder.itemView.home_post_source.text = "Penn Labs" // post?.clubCode?.capitalize() + holder.homePostTitle.text = post.title + holder.homePostSource.text = "Penn Labs" // post?.clubCode?.capitalize() val time = post.startDate?.substring(5, 7) + " / " + post.startDate?.substring(8, 10) + " - " + post.expireDate?.substring(5, 7) + " / " + post.expireDate?.substring(8, 10) - holder.itemView.home_post_timestamp.text = time + holder.homePostTimestamp.text = time Glide .with(mContext) .load(post.imageUrl) .fitCenter() .centerCrop() - .into(holder.itemView.home_post_iv) + .into(holder.homePostIv) /** Adds dynamically generated accent color from the fetched image to the news card */ var accentColor: Int = getColor(mContext, R.color.black) mActivity.lifecycleScope.launch(Dispatchers.Default) { @@ -510,25 +370,25 @@ class HomeAdapter( // Change all the components to match the accent color palette vibrantSwatch?.titleTextColor?.let { if (cell.post.status != Post.DRAFT) { - holder.itemView.home_post_title.setTextColor( + holder.homePostTitle.setTextColor( ColorUtils.setAlphaComponent( it, 150, ), ) } - holder.itemView.home_post_subtitle.setTextColor(it) - holder.itemView.home_post_timestamp.setTextColor(it) - holder.itemView.home_post_source.setTextColor(it) + holder.homePostSubtitle.setTextColor(it) + holder.homePostTimestamp.setTextColor(it) + holder.homePostSource.setTextColor(it) } val bitmapDrawable = BitmapDrawable( - holder.view.resources, + holder.itemBinding.root.resources, bitmap, ) - holder.itemView.post_card_container.background = bitmapDrawable - holder.itemView.postBlurView + holder.homePostContainer.background = bitmapDrawable + holder.postBlurView .setOverlayColor(ColorUtils.setAlphaComponent(accentColor, 150)) // tell dataModel that hte post blur view is done loading @@ -536,13 +396,13 @@ class HomeAdapter( } } /** Sets up blur view on post card */ - holder.itemView.postBlurView - .setupWith(holder.itemView.post_card_container, RenderScriptBlur(mContext)) + holder.postBlurView + .setupWith(holder.homePostContainer, RenderScriptBlur(mContext)) .setFrameClearDrawable(ColorDrawable(getColor(mContext, R.color.white))) .setBlurRadius(25f) /** Post clicking logic if there exists a URL **/ val url = post?.postUrl ?: return - holder.itemView.home_post_card.setOnClickListener { + holder.homePostCard.setOnClickListener { val connection = NewsCustomTabsServiceConnection() builder = CustomTabsIntent.Builder() share = Intent(Intent.ACTION_SEND) @@ -580,29 +440,29 @@ class HomeAdapter( } private fun bindPollCell( - holder: ViewHolder, - cell: PollCell, + holder: HomePollHolder, position: Int, + cell: PollCell, ) { val poll = cell.poll // if the post is a draft, then change the color and add a note if (poll.status == Poll.DRAFT) { - holder.itemView.home_card_title.setTextColor(Color.parseColor(DRAFT_COLOR)) + holder.pollTitle.setTextColor(Color.parseColor(DRAFT_COLOR)) val draftQuestion = poll.question + DRAFT_NOTE - holder.itemView.home_card_title?.text = draftQuestion + holder.pollTitle.text = draftQuestion } else { - holder.itemView.home_card_title?.text = poll.question + holder.pollTitle.text = poll.question } - holder.itemView.home_card_subtitle_2?.text = "${poll.totalVotes} Votes" + holder.pollSubtitle2.text = "${poll.totalVotes} Votes" if (poll.clubCode != null) { - holder.itemView.home_card_subtitle?.text = "POLL FROM ${poll.clubCode}" + holder.pollSubtitle.text = "POLL FROM ${poll.clubCode}" } - holder.itemView.home_card_rv?.layoutManager = LinearLayoutManager(mContext) - holder.itemView.home_card_rv?.adapter = PollOptionAdapter(ArrayList(poll.options), poll) + holder.homeCardRv.layoutManager = LinearLayoutManager(mContext) + holder.homeCardRv.adapter = PollOptionAdapter(ArrayList(poll.options), poll) if (!poll.isVisible) { - holder.itemView.vote_btn?.setOnClickListener { + holder.voteBtn.setOnClickListener { var isSelected = false poll.options.forEach { isSelected = isSelected || it.selected } if (!isSelected) { @@ -615,8 +475,8 @@ class HomeAdapter( return@setOnClickListener } poll.isVisible = true - (holder.itemView.home_card_rv?.adapter as PollOptionAdapter).notifyDataSetChanged() - holder.itemView.vote_btn?.isClickable = false + (holder.homeCardRv.adapter as PollOptionAdapter).notifyDataSetChanged() + holder.voteBtn.isClickable = false notifyItemChanged(position) val selectedOptions = ArrayList() poll.options.forEach { @@ -652,26 +512,26 @@ class HomeAdapter( } } } else { - holder.itemView.vote_btn?.setTextColor(mContext.resources.getColor(R.color.gray)) - holder.itemView.vote_btn?.setOnClickListener {} + holder.voteBtn.setTextColor(mContext.resources.getColor(R.color.gray)) + holder.voteBtn.setOnClickListener {} } } private fun bindGSRCell( - holder: ViewHolder, + holder: HomeGSRHolder, cell: GSRCell, ) { - holder.itemView.home_gsr_title?.text = "Reservations" - holder.itemView.home_gsr_subtitle?.text = "Group Study Rooms" + holder.homeGSRTitle.text = "Reservations" + holder.homeGSRSubtitle.text = "Group Study Rooms" val reservations = cell.reservations - holder.itemView.home_gsr_rv?.layoutManager = + holder.homeGSRRv.layoutManager = LinearLayoutManager( mContext, LinearLayoutManager.VERTICAL, false, ) - holder.itemView.home_gsr_button?.text = "Book a Room" - holder.itemView.home_gsr_button?.setOnClickListener { + holder.homeGSRButton.text = "Book a Room" + holder.homeGSRButton.setOnClickListener { mActivity.setTab(MainActivity.GSR_ID) for (fragment in mActivity.supportFragmentManager.fragments) { if (fragment is GsrTabbedFragment) { @@ -679,32 +539,150 @@ class HomeAdapter( } } } - holder.itemView.home_gsr_rv?.adapter = HomeGsrReservationAdapter(reservations) + holder.homeGSRRv.adapter = HomeGsrReservationAdapter(reservations) } - // Chrome custom tabs to launch news site - internal inner class NewsCustomTabsServiceConnection : CustomTabsServiceConnection() { - override fun onCustomTabsServiceConnected( - name: ComponentName, - client: CustomTabsClient, - ) { - mCustomTabsClient = client - mCustomTabsClient?.warmup(0) - session = mCustomTabsClient?.newSession(null) + private fun bindNewsCard( + holder: HomeNewsCardHolder, + cell: NewsCell, + ) { + val article = cell.article + holder.homeNewsTitle.text = article.title + holder.homeNewsSubtitle.text = article.subtitle + holder.homeNewsTimestamp.text = article.timestamp?.trim() + + Glide + .with(mContext) + .load(article?.imageUrl) + .fitCenter() + .centerCrop() + .into(holder.homeNewsImageView) + + /** Adds dynamically generated accent color from the fetched image to the news card */ + var accentColor: Int = getColor(mContext, R.color.black) + mActivity.lifecycleScope.launch(Dispatchers.Default) { + val bitmap = + Glide + .with(mContext) + .load(article?.imageUrl) + .submit() + .get() + .toBitmap() + + // Create palette from bitmap + fun createPaletteSync(bitmap: Bitmap): Palette = Palette.from(bitmap).generate() + val vibrantSwatch: Palette.Swatch? = createPaletteSync(bitmap).darkVibrantSwatch + vibrantSwatch?.rgb?.let { accentColor = it } + + mActivity.runOnUiThread { + // Change all the components to match the accent color palette + vibrantSwatch?.titleTextColor?.let { + DrawableCompat.setTint( + DrawableCompat.wrap(holder.newsCardLogo.drawable), + ColorUtils.setAlphaComponent(it, 150), + ) + DrawableCompat.setTint( + DrawableCompat.wrap(holder.newsInfoIcon.drawable), + it, + ) + DrawableCompat.setTint( + DrawableCompat.wrap(holder.dotDivider.drawable), + it, + ) + holder.newsButton.setTextColor(ColorUtils.setAlphaComponent(it, 150)) + DrawableCompat.setTint( + DrawableCompat.wrap(holder.newsButton.background), + it, + ) + holder.homeNewsTitle.setTextColor( + ColorUtils.setAlphaComponent( + it, + 150, + ), + ) + holder.homeNewsSubtitle.setTextColor(it) + holder.homeNewsTimestamp.setTextColor(it) + } + holder.newsCardContainer.background = + BitmapDrawable( + holder.itemBinding.root.resources, + bitmap, + ) + holder.newsBlurView + .setOverlayColor(ColorUtils.setAlphaComponent(accentColor, 150)) + + // tell model that the news blur view has been loaded + dataModel.notifyNewsBlurLoaded() + } } - override fun onServiceDisconnected(name: ComponentName) { - mCustomTabsClient = null - session = null - customTabsIntent = null + /** Logic for the more info button on the news card */ + holder.newsInfoIcon.setOnClickListener { + when (holder.homeNewsSubtitle.visibility) { + View.GONE -> { + holder.homeNewsSubtitle.visibility = View.VISIBLE + holder.homeNewsTitle.setPadding(0, 0, 0, 0) + holder.newsBlurView + .setOverlayColor(ColorUtils.setAlphaComponent(accentColor, 250)) + } + + View.VISIBLE -> { + holder.homeNewsSubtitle.visibility = View.GONE + holder.homeNewsTitle.setPadding(0, 0, 0, convertToDp(mContext, 8f)) + holder.newsBlurView + .setOverlayColor(ColorUtils.setAlphaComponent(accentColor, 150)) + } + } + } + + /** Sets up blur view on news card */ + holder.newsBlurView + .setupWith(holder.newsCardContainer, RenderScriptBlur(mContext)) + .setFrameClearDrawable(ColorDrawable(getColor(mContext, R.color.white))) + .setBlurRadius(25f) + + holder.newsButton.setOnClickListener { + val url = article?.articleUrl + + val connection = NewsCustomTabsServiceConnection() + builder = CustomTabsIntent.Builder() + share = Intent(Intent.ACTION_SEND) + share?.type = "text/plain" + builder?.setToolbarColor(0x3E50B4) + builder?.setStartAnimations( + mContext, + androidx.appcompat.R.anim.abc_popup_enter, + androidx.appcompat.R.anim.abc_popup_exit, + ) + CustomTabsClient.bindCustomTabsService( + mContext, + NewsFragment.CUSTOM_TAB_PACKAGE_NAME, + connection, + ) + + if (mContext.isChromeCustomTabsSupported()) { + share?.putExtra(Intent.EXTRA_TEXT, url) + builder?.addMenuItem( + "Share", + PendingIntent.getActivity( + mContext, + 0, + share, + PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE, + ), + ) + customTabsIntent = builder?.build() + customTabsIntent?.launchUrl(mActivity, Uri.parse(url)) + } else { + val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + startActivity(mContext, browserIntent, null) + } } } - /** Checks if the chrome tab is supported on the current device. */ - private fun Context.isChromeCustomTabsSupported(): Boolean { - val serviceIntent = Intent("android.support.customtabs.action.CustomTabsService") - serviceIntent.setPackage("com.android.chrome") - val resolveInfos = this.packageManager.queryIntentServices(serviceIntent, 0) - return resolveInfos.isNotEmpty() + inner class ViewHolder( + itemView: View, + ) : RecyclerView.ViewHolder(itemView) { + val view = itemView } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeBaseHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeBaseHolder.kt new file mode 100644 index 00000000..3ef2ff4d --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeBaseHolder.kt @@ -0,0 +1,13 @@ +package com.pennapps.labs.pennmobile.viewholders + +import androidx.recyclerview.widget.RecyclerView +import com.pennapps.labs.pennmobile.databinding.HomeBaseCardBinding + +class HomeBaseHolder( + val itemBinding: HomeBaseCardBinding, +) : RecyclerView.ViewHolder(itemBinding.root) { + var homeTitle = itemBinding.homeCardTitle + var homeSubtitle = itemBinding.homeCardSubtitle + var homeRv = itemBinding.homeCardRv + var diningPrefsBtn = itemBinding.diningPrefsBtn +} diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeGSRHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeGSRHolder.kt new file mode 100644 index 00000000..b749a334 --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeGSRHolder.kt @@ -0,0 +1,13 @@ +package com.pennapps.labs.pennmobile.viewholders + +import androidx.recyclerview.widget.RecyclerView +import com.pennapps.labs.pennmobile.databinding.HomeGsrCardBinding + +class HomeGSRHolder( + val itemBinding: HomeGsrCardBinding, +) : RecyclerView.ViewHolder(itemBinding.root) { + var homeGSRTitle = itemBinding.homeGsrTitle + var homeGSRSubtitle = itemBinding.homeGsrSubtitle + var homeGSRRv = itemBinding.homeGsrRv + var homeGSRButton = itemBinding.homeGsrButton +} diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeNewsCardHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeNewsCardHolder.kt new file mode 100644 index 00000000..91284f69 --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeNewsCardHolder.kt @@ -0,0 +1,19 @@ +package com.pennapps.labs.pennmobile.viewholders + +import androidx.recyclerview.widget.RecyclerView +import com.pennapps.labs.pennmobile.databinding.HomeNewsCardBinding + +class HomeNewsCardHolder( + val itemBinding: HomeNewsCardBinding, +) : RecyclerView.ViewHolder(itemBinding.root) { + var homeNewsTitle = itemBinding.homeNewsTitle + var homeNewsSubtitle = itemBinding.homeNewsSubtitle + var homeNewsTimestamp = itemBinding.homeNewsTimestamp + var homeNewsImageView = itemBinding.homeNewsIv + var newsCardLogo = itemBinding.newsCardLogo + var newsInfoIcon = itemBinding.newsInfoIcon + var newsBlurView = itemBinding.blurView + var newsCardContainer = itemBinding.newsCardContainer + var newsButton = itemBinding.button + var dotDivider = itemBinding.dotDivider +} diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomePollHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomePollHolder.kt new file mode 100644 index 00000000..4bd1d735 --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomePollHolder.kt @@ -0,0 +1,14 @@ +package com.pennapps.labs.pennmobile.viewholders + +import androidx.recyclerview.widget.RecyclerView +import com.pennapps.labs.pennmobile.databinding.PollCardBinding + +class HomePollHolder( + val itemBinding: PollCardBinding, +) : RecyclerView.ViewHolder(itemBinding.root) { + var pollTitle = itemBinding.homeCardTitle + var pollSubtitle = itemBinding.homeCardSubtitle + var pollSubtitle2 = itemBinding.homeCardSubtitle2 + var homeCardRv = itemBinding.homeCardRv + var voteBtn = itemBinding.voteBtn +} diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomePostHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomePostHolder.kt new file mode 100644 index 00000000..b248b82f --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomePostHolder.kt @@ -0,0 +1,17 @@ +package com.pennapps.labs.pennmobile.viewholders + +import androidx.recyclerview.widget.RecyclerView +import com.pennapps.labs.pennmobile.databinding.HomePostCardBinding + +class HomePostHolder( + val itemBinding: HomePostCardBinding, +) : RecyclerView.ViewHolder(itemBinding.root) { + var homePostTitle = itemBinding.homePostTitle + var homePostSubtitle = itemBinding.homePostSubtitle + var homePostTimestamp = itemBinding.homePostTimestamp + var homePostContainer = itemBinding.postCardContainer + var homePostSource = itemBinding.homePostSource + var homePostIv = itemBinding.homePostIv + var homePostCard = itemBinding.homePostCard + var postBlurView = itemBinding.postBlurView +} From 104f3bd7cb044a972fed693893102807932c515d Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Wed, 2 Oct 2024 02:54:24 -0400 Subject: [PATCH 22/34] DiningSettingsAdapter and SupportAdapter viewBinding implementation (why does diningsettings use views from laundry lmao) --- .../adapters/DiningSettingsAdapter.kt | 20 ++++++------- .../pennmobile/adapters/SupportAdapter.kt | 28 +++++++++---------- .../layout/laundry_settings_child_item.xml | 2 +- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningSettingsAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningSettingsAdapter.kt index 84df0b3b..4f50603e 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningSettingsAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningSettingsAdapter.kt @@ -4,14 +4,11 @@ import android.content.Context import android.content.SharedPreferences import android.util.Log import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import androidx.preference.PreferenceManager import androidx.recyclerview.widget.RecyclerView -import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.classes.DiningHall -import kotlinx.android.synthetic.main.laundry_settings_child_item.view.laundry_favorite_switch -import kotlinx.android.synthetic.main.laundry_settings_child_item.view.laundry_room_name +import com.pennapps.labs.pennmobile.databinding.LaundrySettingsChildItemBinding class DiningSettingsAdapter( private var diningHalls: List, @@ -24,9 +21,9 @@ class DiningSettingsAdapter( viewType: Int, ): DiningSettingsViewHolder { mContext = parent.context - val view = LayoutInflater.from(mContext).inflate(R.layout.laundry_settings_child_item, parent, false) + val itemBinding = LaundrySettingsChildItemBinding.inflate(LayoutInflater.from(mContext), parent, false) sp = PreferenceManager.getDefaultSharedPreferences(mContext) - return DiningSettingsViewHolder(view) + return DiningSettingsViewHolder(itemBinding) } override fun getItemCount(): Int = diningHalls.count() @@ -36,8 +33,8 @@ class DiningSettingsAdapter( position: Int, ) { val hall = diningHalls[position] - holder.view.laundry_room_name?.text = hall.name - val switch = holder.view.laundry_favorite_switch + holder.laundryRoomName.text = hall.name + val switch = holder.laundryFavoriteSwitch // set the switch to the correct on or off switch.isChecked = sp.getBoolean(hall.name, false) @@ -51,8 +48,9 @@ class DiningSettingsAdapter( } inner class DiningSettingsViewHolder( - itemView: View, - ) : RecyclerView.ViewHolder(itemView) { - val view = itemView + itemBinding: LaundrySettingsChildItemBinding, + ) : RecyclerView.ViewHolder(itemBinding.root) { + val laundryRoomName = itemBinding.laundryRoomName + val laundryFavoriteSwitch = itemBinding.laundryFavoriteSwitch } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/SupportAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/SupportAdapter.kt index 6a3015bc..70465507 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/SupportAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/SupportAdapter.kt @@ -9,38 +9,38 @@ import android.view.ViewGroup import android.widget.ArrayAdapter import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.classes.Contact -import kotlinx.android.synthetic.main.support_list_item.view.support_name -import kotlinx.android.synthetic.main.support_list_item.view.support_phone -import kotlinx.android.synthetic.main.support_list_item.view.support_phone_icon +import com.pennapps.labs.pennmobile.databinding.SupportListItemBinding class SupportAdapter( context: Context, contacts: List, ) : ArrayAdapter(context, R.layout.support_list_item, contacts) { - private val inflater: LayoutInflater = LayoutInflater.from(context) - override fun getView( position: Int, convertView: View?, parent: ViewGroup, ): View { val currentPerson = getItem(position) + val itemBinding: SupportListItemBinding = + if (convertView != null) { + SupportListItemBinding.bind(convertView) + } else { + SupportListItemBinding.inflate(LayoutInflater.from(context), parent, false) + } - val view = convertView ?: inflater.inflate(R.layout.support_list_item, parent, false) - - view.support_name?.text = currentPerson?.name + itemBinding.supportName.text = currentPerson?.name if (currentPerson?.phoneWords == "") { - view.support_phone?.text = currentPerson.phone + itemBinding.supportPhone.text = currentPerson.phone } else { - view.support_phone?.text = currentPerson?.phoneWords + " (" + currentPerson?.phone + ")" + itemBinding.supportPhone.text = currentPerson?.phoneWords + " (" + currentPerson?.phone + ")" } if (currentPerson?.isURL == true) { - view.support_phone_icon?.visibility = View.GONE + itemBinding.supportPhoneIcon.visibility = View.GONE } else { - view.support_phone_icon?.visibility = View.GONE + itemBinding.supportPhoneIcon.visibility = View.GONE } - view.setOnClickListener { v -> + itemBinding.root.setOnClickListener { v -> val intent: Intent if (currentPerson?.isURL == true) { intent = Intent(Intent.ACTION_VIEW) @@ -53,6 +53,6 @@ class SupportAdapter( intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) v.context.startActivity(intent) } - return view + return itemBinding.root } } diff --git a/PennMobile/src/main/res/layout/laundry_settings_child_item.xml b/PennMobile/src/main/res/layout/laundry_settings_child_item.xml index 0d3dc53b..01d31e6b 100644 --- a/PennMobile/src/main/res/layout/laundry_settings_child_item.xml +++ b/PennMobile/src/main/res/layout/laundry_settings_child_item.xml @@ -4,7 +4,7 @@ android:layout_height="wrap_content" android:background="@color/white"> - Date: Wed, 2 Oct 2024 03:19:32 -0400 Subject: [PATCH 23/34] ViewBinding and toolBar tweaks (Where do we even access this savecontacts fragment?) --- .../labs/pennmobile/SaveContactsFragment.kt | 15 ++++++++-- .../pennmobile/adapters/PhoneSaveAdapter.kt | 30 ++++++++++--------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SaveContactsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SaveContactsFragment.kt index 7d13daaa..d8ee65d9 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SaveContactsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SaveContactsFragment.kt @@ -14,15 +14,16 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.widget.Toast +import androidx.appcompat.widget.Toolbar import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.fragment.app.ListFragment import com.pennapps.labs.pennmobile.adapters.PhoneSaveAdapter import com.pennapps.labs.pennmobile.classes.Contact -import kotlinx.android.synthetic.main.include_main.toolbar class SaveContactsFragment : ListFragment() { private lateinit var mActivity: MainActivity + private lateinit var toolbar: Toolbar private var contactsList: MutableList = ArrayList() private var selected: MutableList = ArrayList() private var currentNumbers: MutableSet = HashSet() @@ -58,11 +59,19 @@ class SaveContactsFragment : ListFragment() { val view = inflater.inflate(R.layout.fragment_save_contacts, container, false) setHasOptionsMenu(true) mActivity = activity as MainActivity - mActivity.toolbar.visibility = View.VISIBLE - mActivity.toolbar.setNavigationIcon(R.drawable.ic_back_navigation) return view } + override fun onViewCreated( + view: View, + savedInstanceState: Bundle?, + ) { + super.onViewCreated(view, savedInstanceState) + toolbar = mActivity.findViewById(R.id.toolbar) + toolbar.visibility = View.VISIBLE + toolbar.setNavigationIcon(R.drawable.ic_back_navigation) + } + override fun onCreateOptionsMenu( menu: Menu, inflater: MenuInflater, diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PhoneSaveAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PhoneSaveAdapter.kt index b34c9ec3..91ffe623 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PhoneSaveAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PhoneSaveAdapter.kt @@ -7,10 +7,7 @@ import android.view.ViewGroup import android.widget.ArrayAdapter import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.classes.Contact -import kotlinx.android.synthetic.main.phone_save_list_item.view.phone_save_checkbox -import kotlinx.android.synthetic.main.phone_save_list_item.view.support_name -import kotlinx.android.synthetic.main.phone_save_list_item.view.support_phone -import kotlinx.android.synthetic.main.phone_save_list_item.view.support_phone_icon +import com.pennapps.labs.pennmobile.databinding.PhoneSaveListItemBinding class PhoneSaveAdapter( context: Context, @@ -32,14 +29,19 @@ class PhoneSaveAdapter( parent: ViewGroup, ): View { val currentPerson = getItem(pos) - val view = view ?: inflater.inflate(R.layout.phone_save_list_item, parent, false) + val itemBinding: PhoneSaveListItemBinding = + if (view != null) { + PhoneSaveListItemBinding.bind(view) + } else { + PhoneSaveListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) + } - val nameTv = view.support_name - val supportPhoneTv = view.support_phone - val checkbox = view.phone_save_checkbox - nameTv?.text = currentPerson?.name - supportPhoneTv?.text = currentPerson?.phone - view.support_phone_icon?.visibility = if (currentPerson?.isURL == true) View.GONE else View.VISIBLE + val nameTv = itemBinding.supportName + val supportPhoneTv = itemBinding.supportPhone + val checkbox = itemBinding.phoneSaveCheckbox + nameTv.text = currentPerson?.name + supportPhoneTv.text = currentPerson?.phone + itemBinding.supportPhoneIcon.visibility = if (currentPerson?.isURL == true) View.GONE else View.VISIBLE checkbox?.setOnCheckedChangeListener(null) checkbox?.isChecked = state[pos] checkbox?.setOnCheckedChangeListener { buttonView, isChecked -> @@ -48,7 +50,7 @@ class PhoneSaveAdapter( selections.add(Contact(nameTv?.text.toString(), supportPhoneTv.text.toString())) state[pos] = true } else { - view.phone_save_checkbox?.isChecked = false + itemBinding.phoneSaveCheckbox.isChecked = false for (p in selections) { if (p.name == nameTv?.text.toString()) { selections.remove(p) @@ -58,8 +60,8 @@ class PhoneSaveAdapter( state[pos] = false } } - view.setOnClickListener { checkbox.isChecked = !checkbox.isChecked } - return view + itemBinding.root.setOnClickListener { checkbox.isChecked = !checkbox.isChecked } + return itemBinding.root } init { From 9c4db65b9b79090ccebb2509f1d7ad8fa2327e17 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Wed, 2 Oct 2024 03:41:59 -0400 Subject: [PATCH 24/34] DiningSettings ToolBar fix --- .../labs/pennmobile/DiningSettingsFragment.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningSettingsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningSettingsFragment.kt index 9e154db0..104506be 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningSettingsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningSettingsFragment.kt @@ -9,6 +9,7 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.widget.Toast +import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment import androidx.preference.PreferenceManager import androidx.recyclerview.widget.LinearLayoutManager @@ -19,7 +20,6 @@ import com.pennapps.labs.pennmobile.classes.DiningHall import com.pennapps.labs.pennmobile.classes.DiningRequest import com.pennapps.labs.pennmobile.classes.HomepageDataModel import com.pennapps.labs.pennmobile.databinding.FragmentDiningPreferencesBinding -import kotlinx.android.synthetic.main.include_main.toolbar import retrofit.ResponseCallback import retrofit.RetrofitError import retrofit.client.Response @@ -31,6 +31,7 @@ class DiningSettingsFragment( private lateinit var mActivity: MainActivity private lateinit var mStudentLife: StudentLife private lateinit var halls: List + private lateinit var toolbar: Toolbar private val dataModel: HomepageDataModel = dataModel private var _binding: FragmentDiningPreferencesBinding? = null @@ -43,8 +44,6 @@ class DiningSettingsFragment( super.onCreate(savedInstanceState) setHasOptionsMenu(true) mActivity = activity as MainActivity - mActivity.toolbar.visibility = View.VISIBLE - mActivity.title = "Select Favorites" mStudentLife = MainActivity.studentLifeInstance mStudentLife = MainActivity.studentLifeInstance } @@ -68,6 +67,16 @@ class DiningSettingsFragment( return v } + override fun onViewCreated( + view: View, + savedInstanceState: Bundle?, + ) { + super.onViewCreated(view, savedInstanceState) + toolbar = mActivity.findViewById(R.id.toolbar) + toolbar.visibility = View.VISIBLE + mActivity.title = "Select Favorites" + } + override fun onCreateOptionsMenu( menu: Menu, inflater: MenuInflater, @@ -76,7 +85,7 @@ class DiningSettingsFragment( } override fun onOptionsItemSelected(item: MenuItem): Boolean { - mActivity.toolbar.visibility = View.GONE + toolbar.visibility = View.GONE when (item.itemId) { android.R.id.home -> { mActivity.onBackPressed() @@ -120,7 +129,7 @@ class DiningSettingsFragment( } override fun onDestroyView() { - mActivity.toolbar.visibility = View.GONE + toolbar.visibility = View.GONE if (!savedNewPrefs) restoreOriginal() _binding = null super.onDestroyView() From a956a6c5553c2ab59eb67b8e5c9faf4f527387ba Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:28:29 -0400 Subject: [PATCH 25/34] DiningFragment and LaundrySettingsFragment toolbar, no_results, and loadingpanel fixes --- .../labs/pennmobile/DiningFragment.kt | 8 +++-- .../pennmobile/LaundrySettingsFragment.kt | 31 ++++++++++--------- .../src/main/res/layout/fragment_dining.xml | 2 ++ .../res/layout/fragment_laundry_settings.xml | 8 +++-- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt index b1c98c9d..cf9df2dd 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt @@ -20,8 +20,6 @@ import com.pennapps.labs.pennmobile.api.StudentLife import com.pennapps.labs.pennmobile.classes.DiningHall import com.pennapps.labs.pennmobile.classes.Venue import com.pennapps.labs.pennmobile.databinding.FragmentDiningBinding -import kotlinx.android.synthetic.main.loading_panel.loadingPanel -import kotlinx.android.synthetic.main.no_results.no_results import rx.Observable import java.time.LocalDateTime import java.time.format.DateTimeFormatter @@ -29,6 +27,8 @@ import java.time.format.DateTimeFormatter class DiningFragment : Fragment() { private lateinit var mActivity: MainActivity private lateinit var mStudentLife: StudentLife + private lateinit var loadingPanel: View + private lateinit var noResults: View private var _binding: FragmentDiningBinding? = null val binding get() = _binding!! @@ -74,6 +74,8 @@ class DiningFragment : Fragment() { savedInstanceState: Bundle?, ) { super.onViewCreated(view, savedInstanceState) + loadingPanel = view.findViewById(R.id.loadingPanel) + noResults = view.findViewById(R.id.no_results) getDiningHalls() } @@ -167,7 +169,7 @@ class DiningFragment : Fragment() { val adapter = DiningAdapter(diningHalls) loadingPanel?.visibility = View.GONE if (diningHalls.size > 0) { - no_results?.visibility = View.GONE + noResults?.visibility = View.GONE } // Log non-fatal error to crashyltics if null diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundrySettingsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundrySettingsFragment.kt index 7bcf49df..feedcadc 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundrySettingsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundrySettingsFragment.kt @@ -7,6 +7,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.preference.PreferenceManager @@ -14,14 +15,12 @@ import com.google.firebase.crashlytics.FirebaseCrashlytics import com.pennapps.labs.pennmobile.adapters.LaundrySettingsAdapter import com.pennapps.labs.pennmobile.databinding.FragmentLaundrySettingsBinding import com.pennapps.labs.pennmobile.viewmodels.LaundryViewModel -import kotlinx.android.synthetic.main.include_main.toolbar -import kotlinx.android.synthetic.main.loading_panel.loadingPanel -import kotlinx.android.synthetic.main.no_results.no_results class LaundrySettingsFragment : Fragment() { private lateinit var mActivity: MainActivity private lateinit var mStudentLife: StudentLifeRf2 private lateinit var mContext: Context + private lateinit var toolbar: Toolbar private var _binding: FragmentLaundrySettingsBinding? = null val binding get() = _binding!! @@ -37,9 +36,6 @@ class LaundrySettingsFragment : Fragment() { sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mActivity) mContext = mActivity - mActivity.closeKeyboard() - mActivity.toolbar.visibility = View.VISIBLE - mActivity.hideBottomBar() } override fun onCreateView( @@ -50,9 +46,6 @@ class LaundrySettingsFragment : Fragment() { _binding = FragmentLaundrySettingsBinding.inflate(inflater, container, false) val view = binding.root - // set up back button - mActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true) - return view } @@ -70,20 +63,28 @@ class LaundrySettingsFragment : Fragment() { savedInstanceState: Bundle?, ) { super.onViewCreated(view, savedInstanceState) - loadingPanel?.visibility = View.VISIBLE + + toolbar = mActivity.findViewById(R.id.toolbar) + toolbar.visibility = View.VISIBLE + + mActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true) + mActivity.closeKeyboard() + mActivity.hideBottomBar() + + binding.loadingPanel.root.visibility = View.VISIBLE // if this value is already true, then simply attach adapter if (laundryViewModel.loadedRooms.value != null && laundryViewModel.loadedRooms.value!!) { attachAdapter() - loadingPanel?.visibility = View.GONE - no_results?.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE + binding.noResults.root.visibility = View.GONE } else { // otherwise, wait until the network request is done laundryViewModel.loadedRooms.observe(viewLifecycleOwner) { loaded -> if (loaded) { attachAdapter() - loadingPanel?.visibility = View.GONE - no_results?.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE + binding.noResults.root.visibility = View.GONE } } laundryViewModel.getHalls(mStudentLife) @@ -110,7 +111,7 @@ class LaundrySettingsFragment : Fragment() { } } mActivity.supportActionBar?.setDisplayHomeAsUpEnabled(false) - mActivity.toolbar.visibility = View.GONE + toolbar.visibility = View.GONE _binding = null } } diff --git a/PennMobile/src/main/res/layout/fragment_dining.xml b/PennMobile/src/main/res/layout/fragment_dining.xml index 159bb9d0..79baf3ea 100644 --- a/PennMobile/src/main/res/layout/fragment_dining.xml +++ b/PennMobile/src/main/res/layout/fragment_dining.xml @@ -30,6 +30,8 @@ + + - + - + Date: Fri, 4 Oct 2024 01:56:07 -0400 Subject: [PATCH 26/34] HomeFragment viewbinding and toolbar/loadingpanel reimplementation --- .../pennapps/labs/pennmobile/HomeFragment.kt | 62 +++++++++---------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt index 4e3c753e..6df5bb2f 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt @@ -6,6 +6,7 @@ import android.os.Handler import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.appcompat.widget.Toolbar import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels @@ -20,13 +21,6 @@ import com.pennapps.labs.pennmobile.classes.HomepageViewModel import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior import com.pennapps.labs.pennmobile.databinding.FragmentHomeBinding import com.pennapps.labs.pennmobile.utils.Utils -import kotlinx.android.synthetic.main.fragment_home.view.appbar_home -import kotlinx.android.synthetic.main.fragment_home.view.date_view -import kotlinx.android.synthetic.main.fragment_home.view.home_cells_rv -import kotlinx.android.synthetic.main.fragment_home.view.home_refresh_layout -import kotlinx.android.synthetic.main.fragment_home.view.profile -import kotlinx.android.synthetic.main.include_main.toolbar -import kotlinx.android.synthetic.main.loading_panel.loadingPanel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -35,6 +29,8 @@ import java.util.Locale class HomeFragment : Fragment() { private lateinit var mActivity: MainActivity private lateinit var sharedPreferences: SharedPreferences + private lateinit var loadingPanel: View + private lateinit var toolbar: Toolbar private var _binding: FragmentHomeBinding? = null val binding get() = _binding!! @@ -55,30 +51,10 @@ class HomeFragment : Fragment() { ): View { _binding = FragmentHomeBinding.inflate(inflater, container, false) val view = binding.root - - view.home_cells_rv.layoutManager = - LinearLayoutManager( - context, - LinearLayoutManager.VERTICAL, - false, - ) - - view.home_refresh_layout - .setColorSchemeResources(R.color.color_accent, R.color.color_primary) - view.home_refresh_layout - .setOnRefreshListener { - getHomePage() - } - initAppBar(view) return view } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - override fun onViewCreated( view: View, savedInstanceState: Bundle?, @@ -107,6 +83,21 @@ class HomeFragment : Fragment() { below and change getHomePage() so that when HomeAdapter is set, homeCellsRv.visibility is set to View.VISIBLE instead of View.INVISIBLE and hide loadingPanel */ + toolbar = mActivity.findViewById(R.id.toolbar) + loadingPanel = view.findViewById(R.id.loadingPanel) + binding.homeCellsRv.layoutManager = + LinearLayoutManager( + context, + LinearLayoutManager.VERTICAL, + false, + ) + + binding.homeRefreshLayout + .setColorSchemeResources(R.color.color_accent, R.color.color_primary) + binding.homeRefreshLayout + .setOnRefreshListener { + getHomePage() + } homepageViewModel.resetBlurViews() homepageViewModel.blurViewsLoaded.observe(viewLifecycleOwner) { loaded -> if (loaded) { @@ -198,7 +189,7 @@ class HomeFragment : Fragment() { super.onResume() mActivity.removeTabs() this.setTitle(getString(R.string.home)) - mActivity.toolbar.visibility = View.GONE + toolbar.visibility = View.GONE val initials = sharedPreferences.getString(getString(R.string.initials), null) if (!initials.isNullOrEmpty()) { binding.initials.text = initials @@ -219,22 +210,27 @@ class HomeFragment : Fragment() { private fun initAppBar(view: View) { val firstName = sharedPreferences.getString(getString(R.string.first_name), null) firstName?.let { - view.date_view.text = "Welcome, $it!".toUpperCase(Locale.getDefault()) + binding.dateView.text = "Welcome, $it!".toUpperCase(Locale.getDefault()) Handler().postDelayed( { - view.date_view.text = Utils.getCurrentSystemTime() + binding.dateView.text = Utils.getCurrentSystemTime() }, 4000, ) } ?: run { - view.date_view.text = Utils.getCurrentSystemTime() + binding.dateView.text = Utils.getCurrentSystemTime() } ( - view.appbar_home.layoutParams + binding.appbarHome.layoutParams as CoordinatorLayout.LayoutParams ).behavior = ToolbarBehavior() - view.profile.setOnClickListener { + binding.profile.setOnClickListener { // TODO: Account Settings } } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } } From b28891e532acda6012eb26eda9c77f19c63bbf00 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Fri, 4 Oct 2024 19:33:14 -0400 Subject: [PATCH 27/34] MainActivity ViewBinding Implementation --- .../pennapps/labs/pennmobile/MainActivity.kt | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt index e7b1ca4f..9d05d7ee 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt @@ -50,12 +50,9 @@ import com.pennapps.labs.pennmobile.classes.LaundryRoom import com.pennapps.labs.pennmobile.classes.Post import com.pennapps.labs.pennmobile.classes.Venue import com.pennapps.labs.pennmobile.components.sneaker.Sneaker +import com.pennapps.labs.pennmobile.databinding.ActivityMainBinding import com.pennapps.labs.pennmobile.utils.Utils -import kotlinx.android.synthetic.main.custom_sneaker_view.view.blurView -import kotlinx.android.synthetic.main.include_main.appbar -import kotlinx.android.synthetic.main.include_main.content_frame -import kotlinx.android.synthetic.main.include_main.expandable_bottom_bar -import kotlinx.android.synthetic.main.include_main.main_view_pager +import eightbitlab.com.blurview.BlurView import kotlinx.coroutines.sync.Mutex import okhttp3.OkHttpClient import retrofit.RestAdapter @@ -73,26 +70,28 @@ class MainActivity : AppCompatActivity() { private var tabShowed = false private lateinit var fragmentManager: FragmentManager private lateinit var mSharedPrefs: SharedPreferences + private lateinit var binding: ActivityMainBinding val tokenMutex = Mutex() private lateinit var mFirebaseAnalytics: FirebaseAnalytics val mNetworkManager by lazy { OAuth2NetworkManager(this) } override fun onCreate(savedInstanceState: Bundle?) { - setTheme(R.style.AppTheme) if (Build.VERSION.SDK_INT > 28) { setTheme(R.style.DarkModeApi29) } super.onCreate(savedInstanceState) + setTheme(R.style.AppTheme) + binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) if (applicationContext.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES ) { setTheme(R.style.DarkBackground) } - setContentView(R.layout.activity_main) Utils.getCurrentSystemTime() - setSupportActionBar(appbar.findViewById(R.id.toolbar)) + setSupportActionBar(binding.include.toolbar) fragmentManager = supportFragmentManager supportActionBar?.setDisplayHomeAsUpEnabled(false) supportActionBar?.setHomeButtonEnabled(false) @@ -133,7 +132,7 @@ class MainActivity : AppCompatActivity() { } private fun onExpandableBottomNavigationItemSelected() { - expandable_bottom_bar.setOnNavigationItemSelectedListener { item -> + binding.include.expandableBottomBar.setOnNavigationItemSelectedListener { item -> val position = when (item.itemId) { R.id.nav_home -> MainPagerAdapter.HOME_POSITION @@ -143,13 +142,13 @@ class MainActivity : AppCompatActivity() { R.id.nav_more -> MainPagerAdapter.MORE_POSITION else -> MainPagerAdapter.HOME_POSITION } - main_view_pager.setCurrentItem(position, false) + binding.include.mainViewPager.setCurrentItem(position, false) true } } fun setTab(id: Int) { - expandable_bottom_bar.selectedItemId = id + binding.include.expandableBottomBar.selectedItemId = id } fun setSelectedTab(id: Int) {} @@ -169,12 +168,12 @@ class MainActivity : AppCompatActivity() { } } val mainPagerAdapter = MainPagerAdapter(fragmentManager, lifecycle) - main_view_pager.isSaveEnabled = false - main_view_pager?.adapter = mainPagerAdapter - main_view_pager.isUserInputEnabled = false - main_view_pager.offscreenPageLimit = 5 - main_view_pager.visibility = View.VISIBLE - expandable_bottom_bar.visibility = View.VISIBLE + binding.include.mainViewPager.isSaveEnabled = false + binding.include.mainViewPager.adapter = mainPagerAdapter + binding.include.mainViewPager.isUserInputEnabled = false + binding.include.mainViewPager.offscreenPageLimit = 5 + binding.include.mainViewPager.visibility = View.VISIBLE + binding.include.expandableBottomBar.visibility = View.VISIBLE setTab(HOME_ID) } @@ -203,8 +202,8 @@ class MainActivity : AppCompatActivity() { .replace(R.id.content_frame, fragment) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .commit() - main_view_pager.visibility = View.GONE - expandable_bottom_bar.visibility = View.GONE + binding.include.mainViewPager.visibility = View.GONE + binding.include.expandableBottomBar.visibility = View.GONE } } @@ -278,7 +277,7 @@ class MainActivity : AppCompatActivity() { } override fun setTitle(title: CharSequence) { - appbar + binding.include.appbar .findViewById(R.id.toolbar) .findViewById(R.id.toolbar_title) .text = title @@ -290,17 +289,17 @@ class MainActivity : AppCompatActivity() { } fun hideBottomBar() { - expandable_bottom_bar.visibility = View.GONE - val layoutParams = this.content_frame.layoutParams as CoordinatorLayout.LayoutParams + binding.include.expandableBottomBar.visibility = View.GONE + val layoutParams = binding.include.contentFrame.layoutParams as CoordinatorLayout.LayoutParams layoutParams.setMargins(0, 0, 0, 0) - this.content_frame.layoutParams = layoutParams + binding.include.contentFrame.layoutParams = layoutParams } fun showBottomBar() { - expandable_bottom_bar.visibility = View.VISIBLE - val layoutParams = this.content_frame.layoutParams as CoordinatorLayout.LayoutParams + binding.include.expandableBottomBar.visibility = View.VISIBLE + val layoutParams = binding.include.contentFrame.layoutParams as CoordinatorLayout.LayoutParams layoutParams.setMargins(0, 0, 0, Utils.dpToPixel(this, 16f)) - this.content_frame.layoutParams = layoutParams + binding.include.contentFrame.layoutParams = layoutParams } companion object { @@ -489,7 +488,9 @@ fun ViewGroup.showSneakerToast( .from(this.context) .inflate(R.layout.custom_sneaker_view, sneaker.getView(), false) - view.blurView + val blurView: BlurView = view.findViewById(R.id.blurView) + + blurView .setupWith(this) .setFrameClearDrawable(ColorDrawable(Color.TRANSPARENT)) .setBlurRadius(10f) From b852b201a684308ae5cb53234818a6ee0db18c2c Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sun, 6 Oct 2024 02:50:23 -0400 Subject: [PATCH 28/34] DiningHolder Redundant Internet Connectivity fix and HomeFragment auto-refresh implmentation in onResume so we don't need to manually hide the no internet view on PottruckFragment --- .../labs/pennmobile/DiningHolderFragment.kt | 17 ----------------- .../pennapps/labs/pennmobile/HomeFragment.kt | 1 + .../labs/pennmobile/PottruckFragment.kt | 2 -- .../res/layout/fragment_dining_holder.xml | 19 +------------------ 4 files changed, 2 insertions(+), 37 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt index a263b569..7197b7c4 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt @@ -11,7 +11,6 @@ import com.pennapps.labs.pennmobile.adapters.DiningPagerAdapter import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior import com.pennapps.labs.pennmobile.databinding.FragmentDiningHolderBinding import com.pennapps.labs.pennmobile.utils.Utils -import kotlinx.android.synthetic.main.fragment_dining.view.dining_swiperefresh class DiningHolderFragment : Fragment() { lateinit var pagerAdapter: DiningPagerAdapter @@ -33,9 +32,6 @@ class DiningHolderFragment : Fragment() { ): View { _binding = FragmentDiningHolderBinding.inflate(inflater, container, false) val view = binding.root - view.dining_swiperefresh?.setOnRefreshListener { getConnected() } - view.dining_swiperefresh?.setColorSchemeResources(R.color.color_accent, R.color.color_primary) - getConnected() initAppBar() // Inflate the layout for this fragment return view @@ -64,21 +60,8 @@ class DiningHolderFragment : Fragment() { setTitle("Dining") } - private fun getConnected() { - // displays banner if not connected - if (!isOnline(context)) { - binding.internetConnectionDiningHolder.setBackgroundColor(resources.getColor(R.color.darkRedBackground)) - binding.internetConnectionMessageDiningHolder.text = getString(R.string.internet_error) - binding.internetConnectionDiningHolder.visibility = View.VISIBLE - // loadingPanel?.visibility = View.GONE - } else { - binding.internetConnectionDiningHolder.visibility = View.GONE - } - } - override fun onResume() { super.onResume() - getConnected() mActivity.removeTabs() mActivity.setTitle(R.string.dining) mActivity.setSelectedTab(MainActivity.DINING) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt index 6df5bb2f..0edca9c5 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt @@ -187,6 +187,7 @@ class HomeFragment : Fragment() { override fun onResume() { super.onResume() + getOnline() mActivity.removeTabs() this.setTitle(getString(R.string.home)) toolbar.visibility = View.GONE diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt index 39257746..648cf040 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt @@ -24,7 +24,6 @@ import com.pennapps.labs.pennmobile.classes.FitnessPreferenceViewModel import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior import com.pennapps.labs.pennmobile.databinding.FragmentPottruckBinding import com.pennapps.labs.pennmobile.utils.Utils -import kotlinx.android.synthetic.main.fragment_home.internetConnectionHome class PottruckFragment : Fragment() { private lateinit var mActivity: MainActivity @@ -203,7 +202,6 @@ class PottruckFragment : Fragment() { swipeRefresh.isRefreshing = false return false } - internetConnectionHome?.visibility = View.GONE connectionToolbar.visibility = View.GONE return true } diff --git a/PennMobile/src/main/res/layout/fragment_dining_holder.xml b/PennMobile/src/main/res/layout/fragment_dining_holder.xml index 8601906d..8a6cffdb 100644 --- a/PennMobile/src/main/res/layout/fragment_dining_holder.xml +++ b/PennMobile/src/main/res/layout/fragment_dining_holder.xml @@ -54,34 +54,17 @@ - - - - - - - - - Date: Sun, 6 Oct 2024 03:15:16 -0400 Subject: [PATCH 29/34] Tweaked PennCourseAlertManageAlertsFragment so we don't directly call the switches as the fragment has no access to the layout anymore (and also how do we even access PennCourseAlerts?) --- .../labs/pennmobile/PennCourseAlertManageAlertsFragment.kt | 7 +++---- .../labs/pennmobile/adapters/RegistrationsAdapter.kt | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertManageAlertsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertManageAlertsFragment.kt index 296c788c..af71510d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertManageAlertsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertManageAlertsFragment.kt @@ -21,8 +21,6 @@ import androidx.recyclerview.widget.RecyclerView import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import com.pennapps.labs.pennmobile.adapters.RegistrationsAdapter import com.pennapps.labs.pennmobile.viewmodels.PennCourseAlertViewModel -import kotlinx.android.synthetic.main.pca_registration_list_item.notify_closed_switch -import kotlinx.android.synthetic.main.pca_registration_list_item.subscribed_switch class PennCourseAlertManageAlertsFragment : Fragment(), @@ -161,6 +159,7 @@ class PennCourseAlertManageAlertsFragment : override fun onClosedNotificationsSwitchClick( position: Int, onClosedNotifications: Boolean, + isSubscribed: Boolean, ) { val id = adapter.currentList[position].id.toString() Log.i( @@ -168,10 +167,10 @@ class PennCourseAlertManageAlertsFragment : "Item $position closedNoti" + " clicked with closed noti set to $onClosedNotifications", ) - if (subscribed_switch.isChecked) { + if (isSubscribed) { viewModel.switchOnClosedNotifications(id, onClosedNotifications) } else { - notify_closed_switch.isChecked = false + adapter.notifyItemChanged(position) Toast .makeText( context, diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/RegistrationsAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/RegistrationsAdapter.kt index bf4a1ac8..22f27a5d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/RegistrationsAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/RegistrationsAdapter.kt @@ -97,9 +97,11 @@ class RegistrationsAdapter( } if (v?.id?.equals(R.id.notify_closed_switch) == true) { Log.i("PCA_RV", "Notify switch clicked") + val isSubscribed = subscribedSwitch.isChecked listener.onClosedNotificationsSwitchClick( position, notifyClosedSwitch.isChecked, + isSubscribed, ) } listener.onItemClick(position) @@ -118,6 +120,7 @@ class RegistrationsAdapter( fun onClosedNotificationsSwitchClick( position: Int, onClosedNotifications: Boolean, + isSubscribed: Boolean, ) } From e1978651e0579ae7eb505b9de4982b22bef24d16 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sun, 6 Oct 2024 03:15:36 -0400 Subject: [PATCH 30/34] ViewBinding immigration Complete! --- PennMobile/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PennMobile/build.gradle b/PennMobile/build.gradle index b0d2cecc..d8c5dc18 100644 --- a/PennMobile/build.gradle +++ b/PennMobile/build.gradle @@ -4,9 +4,9 @@ plugins { id 'com.google.gms.google-services' id("com.google.firebase.crashlytics") id 'jacoco' + id 'kotlin-parcelize' } -apply plugin: 'kotlin-android-extensions' apply plugin: "kotlin-android" android { From 80523334b4cd09383d0237bb57cc26b7a44bcdfa Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sun, 6 Oct 2024 03:19:15 -0400 Subject: [PATCH 31/34] Small Tweaks on SavedState (so it uses the non-deprecated parcelize library) --- .../pennmobile/components/floatingbottombar/state/SavedState.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/state/SavedState.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/state/SavedState.kt index 774efe0b..14d86888 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/state/SavedState.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/state/SavedState.kt @@ -1,7 +1,7 @@ package com.pennapps.labs.pennmobile.components.floatingbottombar.state import android.os.Parcelable -import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parcelize @Parcelize internal data class SavedState( From c7bce3ba4d85d22a3a1a29b44e42819fd520d44e Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sun, 6 Oct 2024 14:06:45 -0400 Subject: [PATCH 32/34] loadingPanel and noResults fixes s.t they can be accessed directly by binding instead of findviewbyid --- .../com/pennapps/labs/pennmobile/DiningFragment.kt | 10 +++------- .../labs/pennmobile/GsrReservationsFragment.kt | 10 ++++------ .../java/com/pennapps/labs/pennmobile/HomeFragment.kt | 6 ++---- .../com/pennapps/labs/pennmobile/LaundryFragment.kt | 9 +++------ .../com/pennapps/labs/pennmobile/PottruckFragment.kt | 8 +++----- PennMobile/src/main/res/layout/fragment_dining.xml | 8 ++++++-- .../src/main/res/layout/fragment_gsr_reservations.xml | 4 +++- PennMobile/src/main/res/layout/fragment_home.xml | 4 +++- PennMobile/src/main/res/layout/fragment_laundry.xml | 4 +++- PennMobile/src/main/res/layout/fragment_pottruck.xml | 4 +++- 10 files changed, 33 insertions(+), 34 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt index cf9df2dd..06fd4a0e 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt @@ -27,8 +27,6 @@ import java.time.format.DateTimeFormatter class DiningFragment : Fragment() { private lateinit var mActivity: MainActivity private lateinit var mStudentLife: StudentLife - private lateinit var loadingPanel: View - private lateinit var noResults: View private var _binding: FragmentDiningBinding? = null val binding get() = _binding!! @@ -74,8 +72,6 @@ class DiningFragment : Fragment() { savedInstanceState: Bundle?, ) { super.onViewCreated(view, savedInstanceState) - loadingPanel = view.findViewById(R.id.loadingPanel) - noResults = view.findViewById(R.id.no_results) getDiningHalls() } @@ -167,9 +163,9 @@ class DiningFragment : Fragment() { mActivity.runOnUiThread { getMenus(diningHalls) val adapter = DiningAdapter(diningHalls) - loadingPanel?.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE if (diningHalls.size > 0) { - noResults?.visibility = View.GONE + binding.noResults.root.visibility = View.GONE } // Log non-fatal error to crashyltics if null @@ -188,7 +184,7 @@ class DiningFragment : Fragment() { Log.e("DiningFragment", "Error getting dining halls", it) mActivity.runOnUiThread { Log.e("Dining", "Could not load Dining page", it) - loadingPanel?.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE binding.diningSwiperefresh.isRefreshing = false } }) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt index b0ac756f..a0736ce7 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt @@ -19,7 +19,6 @@ import com.pennapps.labs.pennmobile.databinding.FragmentGsrReservationsBinding class GsrReservationsFragment : Fragment() { private lateinit var mActivity: MainActivity - private lateinit var loadingPanel: View private var _binding: FragmentGsrReservationsBinding? = null val binding get() = _binding!! @@ -65,13 +64,12 @@ class GsrReservationsFragment : Fragment() { savedInstanceState: Bundle?, ) { super.onViewCreated(view, savedInstanceState) - loadingPanel = view.findViewById(R.id.loadingPanel) if (!isOnline(context)) { binding.internetConnectionGSRReservations.setBackgroundColor(resources.getColor(R.color.darkRedBackground)) binding.internetConnectionMessageGsrReservations.text = "Not Connected to Internet" binding.internetConnectionGSRReservations.visibility = View.VISIBLE binding.gsrReservationsRefreshLayout.isRefreshing = false - loadingPanel?.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE binding.gsrNoReservations.visibility = View.VISIBLE } else { binding.internetConnectionGSRReservations.visibility = View.GONE @@ -85,7 +83,7 @@ class GsrReservationsFragment : Fragment() { binding.internetConnectionGSRReservations.visibility = View.VISIBLE binding.gsrReservationsRefreshLayout.isRefreshing = false binding.gsrReservationsRv.adapter = GsrReservationsAdapter(ArrayList()) - loadingPanel?.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE binding.gsrNoReservations.visibility = View.VISIBLE } else { binding.internetConnectionGSRReservations.visibility = View.GONE @@ -102,7 +100,7 @@ class GsrReservationsFragment : Fragment() { try { labs.getGsrReservations("Bearer $token").subscribe({ reservations -> mActivity.runOnUiThread { - loadingPanel?.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE try { binding.gsrReservationsRv.adapter = GsrReservationsAdapter(ArrayList(reservations)) @@ -121,7 +119,7 @@ class GsrReservationsFragment : Fragment() { mActivity.runOnUiThread { Log.e("GsrReservationsFragment", "Error getting reservations", throwable) throwable.printStackTrace() - loadingPanel?.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE try { binding.gsrReservationsRv.adapter = GsrReservationsAdapter(ArrayList()) binding.gsrNoReservations.visibility = View.VISIBLE diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt index 0edca9c5..9638ff0b 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt @@ -29,7 +29,6 @@ import java.util.Locale class HomeFragment : Fragment() { private lateinit var mActivity: MainActivity private lateinit var sharedPreferences: SharedPreferences - private lateinit var loadingPanel: View private lateinit var toolbar: Toolbar private var _binding: FragmentHomeBinding? = null @@ -84,7 +83,6 @@ class HomeFragment : Fragment() { set to View.VISIBLE instead of View.INVISIBLE and hide loadingPanel */ toolbar = mActivity.findViewById(R.id.toolbar) - loadingPanel = view.findViewById(R.id.loadingPanel) binding.homeCellsRv.layoutManager = LinearLayoutManager( context, @@ -102,7 +100,7 @@ class HomeFragment : Fragment() { homepageViewModel.blurViewsLoaded.observe(viewLifecycleOwner) { loaded -> if (loaded) { binding.homeCellsRv.visibility = View.VISIBLE - loadingPanel?.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE } } @@ -132,7 +130,7 @@ class HomeFragment : Fragment() { binding.homeCellsRv.setPadding(0, 90, 0, 0) binding.internetConnectionHome.visibility = View.VISIBLE binding.homeRefreshLayout.isRefreshing = false - loadingPanel?.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE return false } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt index e8bf1e36..be27fb20 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt @@ -26,7 +26,6 @@ class LaundryFragment : Fragment() { private lateinit var mStudentLife: StudentLifeRf2 private lateinit var mContext: Context - private lateinit var loadingPanel: View private lateinit var sharedPreferences: SharedPreferences @@ -84,12 +83,10 @@ class LaundryFragment : Fragment() { mActivity.removeTabs() mActivity.setTitle(R.string.laundry) - loadingPanel = view.findViewById(R.id.loadingPanel) - mAdapter = LaundryRoomAdapter(mContext, laundryRooms, roomsData, false) binding.favoriteLaundryList.adapter = mAdapter - loadingPanel.visibility = View.VISIBLE + binding.loadingPanel.root.visibility = View.VISIBLE laundryViewModel.favoriteRooms.observe(viewLifecycleOwner) { favorites -> binding.laundryMachineRefresh.isRefreshing = false @@ -108,7 +105,7 @@ class LaundryFragment : Fragment() { mAdapter!!.notifyItemChanged(pos) } - loadingPanel.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE binding.laundryHelpText.visibility = View.INVISIBLE } @@ -123,7 +120,7 @@ class LaundryFragment : Fragment() { binding.internetConnectionLaundry.visibility = View.VISIBLE binding.laundryHelpText.visibility = View.INVISIBLE binding.laundryMachineRefresh.isRefreshing = false - loadingPanel?.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE return false } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt index 648cf040..44180931 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt @@ -32,7 +32,6 @@ class PottruckFragment : Fragment() { private lateinit var mView: View private lateinit var swipeRefresh: SwipeRefreshLayout private lateinit var recyclerView: RecyclerView - private lateinit var loadingPanel: View private lateinit var dataModel: FitnessPreferenceViewModel private lateinit var favoritesAdapter: FitnessAdapter @@ -73,7 +72,6 @@ class PottruckFragment : Fragment() { swipeRefresh = binding.swiperefreshFitness recyclerView = binding.recyclerViewFitnessRooms - loadingPanel = view.findViewById(R.id.loadingPanel) swipeRefresh.setColorSchemeResources(R.color.color_accent, R.color.color_primary) recyclerView.layoutManager = @@ -134,7 +132,7 @@ class PottruckFragment : Fragment() { Log.e("PottruckFragment", "Error getting fitness rooms", it) mActivity.runOnUiThread { Log.e("Fitness", "Could not load Pottruck page", it) - loadingPanel.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE swipeRefresh.isRefreshing = false } }) @@ -159,7 +157,7 @@ class PottruckFragment : Fragment() { ) recyclerView.adapter = concatAdapter - loadingPanel.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE swipeRefresh.isRefreshing = false // set click listener for favorites button @@ -198,7 +196,7 @@ class PottruckFragment : Fragment() { ) connectionMessage.text = getString(R.string.internet_error) connectionToolbar.visibility = View.VISIBLE - loadingPanel.visibility = View.GONE + binding.loadingPanel.root.visibility = View.GONE swipeRefresh.isRefreshing = false return false } diff --git a/PennMobile/src/main/res/layout/fragment_dining.xml b/PennMobile/src/main/res/layout/fragment_dining.xml index 79baf3ea..163228c3 100644 --- a/PennMobile/src/main/res/layout/fragment_dining.xml +++ b/PennMobile/src/main/res/layout/fragment_dining.xml @@ -28,9 +28,13 @@ - + - + - + \ No newline at end of file diff --git a/PennMobile/src/main/res/layout/fragment_home.xml b/PennMobile/src/main/res/layout/fragment_home.xml index 9c731517..da74ac79 100644 --- a/PennMobile/src/main/res/layout/fragment_home.xml +++ b/PennMobile/src/main/res/layout/fragment_home.xml @@ -135,7 +135,9 @@ - + - + - + From 3647511e855033687acc0062d695076673bb5663 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sun, 6 Oct 2024 14:29:37 -0400 Subject: [PATCH 33/34] HomeAdapter modifications such that Calendar, Dining, and Laundry cells can have their own viewholders --- .../labs/pennmobile/adapters/HomeAdapter.kt | 30 +++++++++++++++---- .../pennmobile/viewholders/HomeBaseHolder.kt | 2 +- .../viewholders/HomeCalendarHolder.kt | 7 +++++ .../viewholders/HomeDiningHolder.kt | 7 +++++ .../viewholders/HomeLaundryHolder.kt | 7 +++++ 5 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeCalendarHolder.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeDiningHolder.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeLaundryHolder.kt diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeAdapter.kt index 54d966a1..0f1da876 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeAdapter.kt @@ -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 @@ -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) @@ -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) @@ -212,7 +230,7 @@ class HomeAdapter( } private fun bindLaundryCell( - holder: HomeBaseHolder, + holder: HomeLaundryHolder, cell: LaundryCell, ) { val roomID = cell.roomId @@ -246,7 +264,7 @@ class HomeAdapter( } private fun bindDiningCell( - holder: HomeBaseHolder, + holder: HomeDiningHolder, cell: DiningCell, ) { holder.homeTitle.text = "Favorites" @@ -293,7 +311,7 @@ class HomeAdapter( } private fun bindCalendarCell( - holder: HomeBaseHolder, + holder: HomeCalendarHolder, cell: CalendarCell, ) { val events = cell.events diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeBaseHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeBaseHolder.kt index 3ef2ff4d..4b1a594c 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeBaseHolder.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeBaseHolder.kt @@ -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 diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeCalendarHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeCalendarHolder.kt new file mode 100644 index 00000000..9b710da4 --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeCalendarHolder.kt @@ -0,0 +1,7 @@ +package com.pennapps.labs.pennmobile.viewholders + +import com.pennapps.labs.pennmobile.databinding.HomeBaseCardBinding + +class HomeCalendarHolder( + itemBinding: HomeBaseCardBinding, +) : HomeBaseHolder(itemBinding) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeDiningHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeDiningHolder.kt new file mode 100644 index 00000000..857011d6 --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeDiningHolder.kt @@ -0,0 +1,7 @@ +package com.pennapps.labs.pennmobile.viewholders + +import com.pennapps.labs.pennmobile.databinding.HomeBaseCardBinding + +class HomeDiningHolder( + itemBinding: HomeBaseCardBinding, +) : HomeBaseHolder(itemBinding) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeLaundryHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeLaundryHolder.kt new file mode 100644 index 00000000..259a1097 --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewholders/HomeLaundryHolder.kt @@ -0,0 +1,7 @@ +package com.pennapps.labs.pennmobile.viewholders + +import com.pennapps.labs.pennmobile.databinding.HomeBaseCardBinding + +class HomeLaundryHolder( + itemBinding: HomeBaseCardBinding, +) : HomeBaseHolder(itemBinding) From 1a368dd472b8183a84b7eeed21ed76fb2b570328 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Sun, 6 Oct 2024 14:52:32 -0400 Subject: [PATCH 34/34] Small Menu Fragment tweak after merge --- .../src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt index ebdcdef3..c0026a7c 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt @@ -105,7 +105,6 @@ class MenuFragment : Fragment() { pager.adapter = pageAdapter v.setBackgroundColor(Color.WHITE) mActivity.addTabs(pageAdapter as TabAdapter, pager, true) - mActivity.hideBottomBar() return v }