Skip to content

Commit

Permalink
Add synchronous calls for accessing bearer token
Browse files Browse the repository at this point in the history
  • Loading branch information
JSnipes29 committed Oct 1, 2023
1 parent 3d405bc commit 98d96e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "") {
Expand All @@ -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 != "") {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 98d96e7

Please sign in to comment.