From aac2c236f638e6d9d2bc578ec25a9189b3af12c7 Mon Sep 17 00:00:00 2001 From: meiron03 Date: Fri, 2 Feb 2024 17:11:13 -0500 Subject: [PATCH] finish adding try/catches for firebase logging. --- .../pennmobile/GsrReservationsFragment.kt | 28 ++++++++++++------- .../labs/pennmobile/LaundryFragment.kt | 28 +++++++++++++------ 2 files changed, 38 insertions(+), 18 deletions(-) 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 0db3f054..fb49cfd0 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt @@ -13,7 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import com.google.firebase.analytics.FirebaseAnalytics +import com.google.firebase.crashlytics.FirebaseCrashlytics import com.pennapps.labs.pennmobile.adapters.GsrReservationsAdapter import com.pennapps.labs.pennmobile.databinding.FragmentGsrReservationsBinding @@ -96,22 +96,30 @@ class GsrReservationsFragment : Fragment() { binding.gsrReservationsRv.adapter = GsrReservationsAdapter(ArrayList(reservations)) loadingPanel?.visibility = View.GONE - if (reservations.size > 0) { - binding.gsrNoReservations.visibility = View.GONE - } else { - binding.gsrNoReservations.visibility = View.VISIBLE + try { + if (reservations.size > 0) { + binding.gsrNoReservations.visibility = View.GONE + } else { + binding.gsrNoReservations.visibility = View.VISIBLE + } + // stop refreshing + binding.gsrReservationsRefreshLayout.isRefreshing = false + } catch (e: Exception) { + FirebaseCrashlytics.getInstance().recordException(e) } - // stop refreshing - binding.gsrReservationsRefreshLayout.isRefreshing = false } }, { throwable -> mActivity.runOnUiThread { Log.e("GsrReservationsFragment", "Error getting reservations", throwable) - binding.gsrReservationsRv.adapter = GsrReservationsAdapter(ArrayList()) throwable.printStackTrace() loadingPanel?.visibility = View.GONE - binding.gsrNoReservations.visibility = View.VISIBLE - binding.gsrReservationsRefreshLayout.isRefreshing = false + try { + binding.gsrReservationsRv.adapter = GsrReservationsAdapter(ArrayList()) + binding.gsrNoReservations.visibility = View.VISIBLE + binding.gsrReservationsRefreshLayout.isRefreshing = false + } catch (e: Exception) { + FirebaseCrashlytics.getInstance().recordException(e) + } } }) } 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 af8191a1..26de7e3f 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt @@ -10,6 +10,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentTransaction import androidx.recyclerview.widget.LinearLayoutManager +import com.google.firebase.crashlytics.FirebaseCrashlytics import com.pennapps.labs.pennmobile.adapters.LaundryRoomAdapter import com.pennapps.labs.pennmobile.api.StudentLife import com.pennapps.labs.pennmobile.classes.LaundryRoom @@ -190,20 +191,27 @@ class LaundryFragment : Fragment() { roomsData = roomsDataResult laundryRooms = laundryRoomsResult mAdapter = LaundryRoomAdapter(mContext, laundryRooms, roomsData, false) - binding.favoriteLaundryList.adapter = mAdapter + try { + binding.favoriteLaundryList.adapter = mAdapter + binding.laundryHelpText.visibility = View.INVISIBLE + binding.laundryMachineRefresh.isRefreshing = false + } catch (e: Exception) { + FirebaseCrashlytics.getInstance().recordException(e) + } no_results?.visibility = View.GONE loadingPanel?.visibility = View.GONE - binding.laundryHelpText.visibility = View.INVISIBLE - binding.laundryMachineRefresh.isRefreshing = false - } } }, { mActivity.runOnUiThread { + try { + binding.laundryHelpText.visibility = View.GONE + binding.laundryMachineRefresh.isRefreshing = false + } catch (e: Exception) { + FirebaseCrashlytics.getInstance().recordException(e) + } loadingPanel?.visibility = View.GONE no_results?.visibility = View.VISIBLE - binding.laundryHelpText.visibility = View.GONE - binding.laundryMachineRefresh.isRefreshing = false Log.e("Laundry", "Error getting laundry data: " + it.stackTrace) } }) @@ -224,8 +232,12 @@ class LaundryFragment : Fragment() { mActivity.runOnUiThread { loadingPanel?.visibility = View.GONE no_results?.visibility = View.VISIBLE - binding.laundryHelpText.visibility = View.GONE - binding.laundryMachineRefresh.isRefreshing = false + try { + binding.laundryHelpText.visibility = View.GONE + binding.laundryMachineRefresh.isRefreshing = false + } catch (e: Exception) { + FirebaseCrashlytics.getInstance().recordException(e) + } } }) }