Skip to content

Commit

Permalink
loadingPanel and noResults fixes s.t they can be accessed directly by…
Browse files Browse the repository at this point in the history
… binding instead of findviewbyid
  • Loading branch information
baronhsieh2005 committed Oct 6, 2024
1 parent 8052333 commit c7bce3b
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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!!
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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
Expand All @@ -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
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!!
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
}

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

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

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

Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
}
})
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 6 additions & 2 deletions PennMobile/src/main/res/layout/fragment_dining.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@

</androidx.appcompat.widget.Toolbar>

<include layout="@layout/loading_panel" />
<include
android:id="@+id/loading_panel"
layout="@layout/loading_panel" />

<include layout="@layout/no_results" />
<include
android:id="@+id/no_results"
layout="@layout/no_results" />

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/dining_swiperefresh"
Expand Down
4 changes: 3 additions & 1 deletion PennMobile/src/main/res/layout/fragment_gsr_reservations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

<include layout="@layout/loading_panel" />
<include
android:id="@+id/loading_panel"
layout="@layout/loading_panel" />

</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 3 additions & 1 deletion PennMobile/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

<include layout="@layout/loading_panel" />
<include
android:id="@+id/loading_panel"
layout="@layout/loading_panel" />

<!-- Coordinator Layout used to position the SnackBar -->
<androidx.coordinatorlayout.widget.CoordinatorLayout
Expand Down
4 changes: 3 additions & 1 deletion PennMobile/src/main/res/layout/fragment_laundry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<include layout="@layout/loading_panel" />
<include
android:id="@+id/loading_panel"
layout="@layout/loading_panel" />

<androidx.appcompat.widget.Toolbar
android:id="@+id/internetConnectionLaundry"
Expand Down
4 changes: 3 additions & 1 deletion PennMobile/src/main/res/layout/fragment_pottruck.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@

</androidx.appcompat.widget.Toolbar>

<include layout="@layout/loading_panel" />
<include
android:id="@+id/loading_panel"
layout="@layout/loading_panel" />



Expand Down

0 comments on commit c7bce3b

Please sign in to comment.