From 98d96e70610dcf5512175248a2a78a3fa26befe2 Mon Sep 17 00:00:00 2001 From: Julius Snipes Date: Sun, 1 Oct 2023 12:05:14 -0400 Subject: [PATCH] Add synchronous calls for accessing bearer token --- .../main/java/com/pennapps/labs/pennmobile/GsrFragment.kt | 5 +++-- .../com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt | 4 ++++ 2 files changed, 7 insertions(+), 2 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 1dcdacbe..037c13a2 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt @@ -101,7 +101,9 @@ class GsrFragment : Fragment() { huntsmanDurationAdapter = ArrayAdapter(mActivity, R.layout.gsr_spinner_item, arrayOf("30m", "60m", "90m")) // update user status by getting the bearer token and checking wharton status - updateStatus() + OAuth2NetworkManager(mActivity).getAccessToken { + updateStatus() + } // populate the list of gsrs populateDropDownGSR() @@ -194,7 +196,6 @@ class GsrFragment : Fragment() { } private fun updateStatus() { - OAuth2NetworkManager(mActivity).getAccessToken() val sp = PreferenceManager.getDefaultSharedPreferences(activity) bearerToken = sp.getString(getString(R.string.access_token), "").toString(); diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt index 3ef4bb92..ae35e6ed 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt @@ -23,6 +23,7 @@ class OAuth2NetworkManager(private var mActivity: MainActivity) { return deviceID } + @Synchronized fun getAccessToken() { val expiresIn = sp.getString(mActivity.getString(R.string.expires_in), "") if (expiresIn != "") { @@ -39,6 +40,7 @@ class OAuth2NetworkManager(private var mActivity: MainActivity) { } } + @Synchronized fun getAccessToken(function: () -> Unit) { val expiresIn = sp.getString(mActivity.getString(R.string.expires_in), "") if (expiresIn != "") { @@ -56,6 +58,7 @@ class OAuth2NetworkManager(private var mActivity: MainActivity) { } } + @Synchronized private fun refreshAccessToken() { val refreshToken = sp.getString(mActivity.getString(R.string.refresh_token), "") val clientID = BuildConfig.PLATFORM_CLIENT_ID @@ -85,6 +88,7 @@ class OAuth2NetworkManager(private var mActivity: MainActivity) { }) } + @Synchronized private fun refreshAccessToken(function: () -> Unit) { val refreshToken = sp.getString(mActivity.getString(R.string.refresh_token), "") val clientID = BuildConfig.PLATFORM_CLIENT_ID