Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ViewBinding Migration #629

Merged
merged 35 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
845de03
Dining Adapter Binding Implementation
baronhsieh2005 Sep 28, 2024
9bb12c3
UniversityEventAdapter Binding Implementation
baronhsieh2005 Sep 28, 2024
a25d77a
GSRReservationAdapter Change to ViewBinding
baronhsieh2005 Sep 28, 2024
12c958b
AboutAdapter ViewBinding Implementation
baronhsieh2005 Sep 28, 2024
4c875a3
Fling Adapter ViewBinding Implementation
baronhsieh2005 Sep 28, 2024
9c32fcf
HomeGsrBuildingAdapter ViewBinding Implementation (but seems to be ne…
baronhsieh2005 Sep 28, 2024
a48af7b
Warning Cleaning
baronhsieh2005 Sep 28, 2024
2027003
GsrRoomAdapter ViewBinding Implementation
baronhsieh2005 Sep 28, 2024
1aaa409
GSRRservationsFragement LoadingPanel Redefine
baronhsieh2005 Sep 28, 2024
267ed8e
GSRRservationsFragement LoadingPanel Redefine
baronhsieh2005 Sep 28, 2024
9cdd415
GSRRservationsAdapter transition to ViewBinding
baronhsieh2005 Sep 28, 2024
7b627ac
Implement ViewBinding in MoreFragment
baronhsieh2005 Sep 28, 2024
9197ca1
initAppBar modifications
baronhsieh2005 Sep 28, 2024
1a8b9c6
linting
baronhsieh2005 Sep 29, 2024
72eb287
LaundryFragment loadingPanel fix
baronhsieh2005 Sep 29, 2024
fa9f315
DiningCardAdapter ViewBinding Implementation
baronhsieh2005 Sep 29, 2024
2a94c82
SupportFragment ToolBar Reimplementation (finally figured this jawn out)
baronhsieh2005 Sep 29, 2024
ada39e3
MenuFragment toolbar fix
baronhsieh2005 Sep 30, 2024
8d317d6
LaundrtMachine Adapter viewBinding + Switch to SwitchCompat for alarm…
baronhsieh2005 Sep 30, 2024
2728e00
Created ViewModels Folder (So it won't be too chaotic when I migrate …
baronhsieh2005 Oct 1, 2024
bf5e339
HomeAdapter Viewbinding implementation and ViewHolder creation (actua…
baronhsieh2005 Oct 2, 2024
104f3bd
DiningSettingsAdapter and SupportAdapter viewBinding implementation (…
baronhsieh2005 Oct 2, 2024
d85df72
ViewBinding and toolBar tweaks (Where do we even access this savecont…
baronhsieh2005 Oct 2, 2024
9c4db65
DiningSettings ToolBar fix
baronhsieh2005 Oct 2, 2024
a956a6c
DiningFragment and LaundrySettingsFragment toolbar, no_results, and l…
baronhsieh2005 Oct 2, 2024
faea174
HomeFragment viewbinding and toolbar/loadingpanel reimplementation
baronhsieh2005 Oct 4, 2024
b28891e
MainActivity ViewBinding Implementation
baronhsieh2005 Oct 4, 2024
b852b20
DiningHolder Redundant Internet Connectivity fix and HomeFragment aut…
baronhsieh2005 Oct 6, 2024
4f0fefe
Tweaked PennCourseAlertManageAlertsFragment so we don't directly call…
baronhsieh2005 Oct 6, 2024
e197865
ViewBinding immigration Complete!
baronhsieh2005 Oct 6, 2024
8052333
Small Tweaks on SavedState (so it uses the non-deprecated parcelize l…
baronhsieh2005 Oct 6, 2024
c7bce3b
loadingPanel and noResults fixes s.t they can be accessed directly by…
baronhsieh2005 Oct 6, 2024
3647511
HomeAdapter modifications such that Calendar, Dining, and Laundry cel…
baronhsieh2005 Oct 6, 2024
f5686b1
Merge branch 'main' into kotlin-extension-removal
baronhsieh2005 Oct 6, 2024
1a368dd
Small Menu Fragment tweak after merge
baronhsieh2005 Oct 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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!!
Expand Down Expand Up @@ -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"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -106,7 +108,7 @@ class LaundryFragment : Fragment() {
mAdapter!!.notifyItemChanged(pos)
}

loadingPanel?.visibility = View.GONE
loadingPanel.visibility = View.GONE
binding.laundryHelpText.visibility = View.INVISIBLE
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -81,7 +90,7 @@ class SupportFragment : ListFragment() {

override fun onPause() {
super.onPause()
mActivity.toolbar.visibility = View.GONE
toolbar.visibility = View.GONE
}

override fun onResume() {
Expand All @@ -93,7 +102,7 @@ class SupportFragment : ListFragment() {
}

override fun onDestroyView() {
mActivity.toolbar.setNavigationOnClickListener(null)
toolbar.setNavigationOnClickListener(null)
super.onDestroyView()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ 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<String>,
Expand All @@ -18,9 +18,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()
Expand All @@ -29,7 +29,7 @@ class AboutAdapter(
holder: TeamViewHolder,
position: Int,
) {
holder.view.name_tv?.text = members[position]
holder.nameTv.text = members[position]
val imageId =
when (members[position]) {
"Marta García Ferreiro" -> R.drawable.marta
Expand All @@ -51,12 +51,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.personIv.setImageResource(imageId)
}

inner class TeamViewHolder(
itemView: View,
) : RecyclerView.ViewHolder(itemView) {
val view = itemView
itemBinding: TeamMemberBinding,
) : RecyclerView.ViewHolder(itemBinding.root) {
val personIv: ImageView = itemBinding.personIv
val nameTv: TextView = itemBinding.nameTv
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -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
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
}
}
Loading
Loading