Skip to content

Commit

Permalink
Merge pull request #625 from pennlabs/crash-hotfix
Browse files Browse the repository at this point in the history
Crash hotfix
  • Loading branch information
baronhsieh2005 authored Sep 10, 2024
2 parents 8469628 + 63cedc0 commit e46ae16
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
}
}
Expand Down Expand Up @@ -681,4 +684,10 @@ class GsrFragment : Fragment() {
mGSRS.add(newGSRObject)
}
}

fun checkIfFragmentAttached(operation: Context.() -> Unit) {
if (isAdded && context != null) {
operation(requireContext())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -105,9 +103,18 @@ class MenuFragment : Fragment() {
pager.adapter = pageAdapter
v.setBackgroundColor(Color.WHITE)
mActivity.addTabs(pageAdapter as TabAdapter, pager, true)
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,
Expand Down

0 comments on commit e46ae16

Please sign in to comment.