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

Crash hotfix #625

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading