From b0b1ab9a0cb9870df502c6908f5d92fdaebb5aac Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:17:12 -0400 Subject: [PATCH 1/5] Version Bump --- .../pennapps/labs/pennmobile/GsrFragment.kt | 48 +++++++++++-------- .../pennapps/labs/pennmobile/MenuFragment.kt | 4 +- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt index 38fe7a43..2c2c0bbb 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt @@ -2,6 +2,7 @@ package com.pennapps.labs.pennmobile import android.app.DatePickerDialog import android.app.TimePickerDialog +import android.content.Context import android.content.SharedPreferences import android.os.Bundle import android.util.Log @@ -242,27 +243,29 @@ class GsrFragment : Fragment() { private fun updateStatus() { mActivity.mNetworkManager.getAccessToken { - val bearerToken = - sharedPreferences.getString(getString(R.string.access_token), "").toString() + checkIfFragmentAttached { + val bearerToken = + sharedPreferences.getString(getString(R.string.access_token), "").toString() - if (bearerToken.isEmpty()) { - Toast.makeText(activity, "You are not logged in!", Toast.LENGTH_LONG).show() - } else { - try { - mStudentLife - .isWharton( - "Bearer $bearerToken", - )?.subscribe( - { status -> - isWharton = status.isWharton - }, - { - Log.e("GsrFragment", "Error getting Wharton status", it) - isWharton = false - }, - ) - } catch (e: Exception) { - e.printStackTrace() + if (bearerToken.isEmpty()) { + Toast.makeText(activity, "You are not logged in!", Toast.LENGTH_LONG).show() + } else { + try { + mStudentLife + .isWharton( + "Bearer $bearerToken", + )?.subscribe( + { status -> + isWharton = status.isWharton + }, + { + Log.e("GsrFragment", "Error getting Wharton status", it) + isWharton = false + }, + ) + } catch (e: Exception) { + e.printStackTrace() + } } } } @@ -681,4 +684,9 @@ class GsrFragment : Fragment() { mGSRS.add(newGSRObject) } } + fun checkIfFragmentAttached(operation: Context.() -> Unit) { + if (isAdded && context != null) { + operation(requireContext()) + } + } } 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..0830d48a 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt @@ -88,9 +88,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( @@ -105,6 +103,8 @@ class MenuFragment : Fragment() { pager.adapter = pageAdapter v.setBackgroundColor(Color.WHITE) mActivity.addTabs(pageAdapter as TabAdapter, pager, true) + mActivity.toolbar.visibility = View.VISIBLE + mActivity.hideBottomBar() return v } From 22a37615db96e9e79dd74c4f752f14a225de5989 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:13:09 -0400 Subject: [PATCH 2/5] Linting --- .../src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt index 2c2c0bbb..a447a054 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt @@ -684,6 +684,7 @@ class GsrFragment : Fragment() { mGSRS.add(newGSRObject) } } + fun checkIfFragmentAttached(operation: Context.() -> Unit) { if (isAdded && context != null) { operation(requireContext()) From 8e3a567fad15ca92c54969e269b9b71033c8b096 Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:33:41 -0400 Subject: [PATCH 3/5] Change to OnViewCreated --- .../main/java/com/pennapps/labs/pennmobile/MenuFragment.kt | 6 +++++- 1 file changed, 5 insertions(+), 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 0830d48a..04a00680 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt @@ -103,11 +103,15 @@ class MenuFragment : Fragment() { pager.adapter = pageAdapter v.setBackgroundColor(Color.WHITE) mActivity.addTabs(pageAdapter as TabAdapter, pager, true) - mActivity.toolbar.visibility = View.VISIBLE mActivity.hideBottomBar() return v } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + mActivity.toolbar.visibility = View.VISIBLE + } + override fun onCreateOptionsMenu( menu: Menu, inflater: MenuInflater, From 109e35e331cf1e2416b3737c0b63392a8a78db6e Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:39:26 -0400 Subject: [PATCH 4/5] Linting (I'm trolling) --- .../main/java/com/pennapps/labs/pennmobile/MenuFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 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 04a00680..289e556f 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt @@ -107,7 +107,10 @@ class MenuFragment : Fragment() { return v } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + override fun onViewCreated( + view: View, + savedInstanceState: Bundle? + ) { super.onViewCreated(view, savedInstanceState) mActivity.toolbar.visibility = View.VISIBLE } From 63cedc057e9581b1e76b9a3a48bc46e2ac60c18c Mon Sep 17 00:00:00 2001 From: Skeletrobro <67814129+baronhsieh2005@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:51:15 -0400 Subject: [PATCH 5/5] Final Lint (bruh) --- .../src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt | 2 +- 1 file changed, 1 insertion(+), 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 289e556f..4d3bc3c4 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt @@ -109,7 +109,7 @@ class MenuFragment : Fragment() { override fun onViewCreated( view: View, - savedInstanceState: Bundle? + savedInstanceState: Bundle?, ) { super.onViewCreated(view, savedInstanceState) mActivity.toolbar.visibility = View.VISIBLE