@@ -49,6 +49,12 @@ public abstract class AbstractSpotifyPkceLoginActivity : AppCompatActivity() {
4949 public open val state: String = Random .nextLong().toString()
5050 public open val options: ((SpotifyApiOptions ).() -> Unit )? = null
5151
52+ /* *
53+ * Custom logic to invoke when loading begins ([isLoading] is true) or ends ([isLoading] is false).
54+ * You can update the view here.
55+ */
56+ public open fun setLoadingContent (isLoading : Boolean ) = {}
57+
5258 private lateinit var authorizationIntent: Intent
5359 private lateinit var credentialStore: SpotifyDefaultCredentialStore
5460
@@ -144,7 +150,7 @@ public abstract class AbstractSpotifyPkceLoginActivity : AppCompatActivity() {
144150 } else {
145151 try {
146152 logToConsole(" Building client PKCE api..." )
147- setProgressBarVisible( )
153+ setLoadingContent( true )
148154 val api = spotifyClientPkceApi(
149155 clientId = clientId,
150156 redirectUri = redirectUri,
@@ -158,33 +164,25 @@ public abstract class AbstractSpotifyPkceLoginActivity : AppCompatActivity() {
158164 logToConsole(" Successfully built client PKCE api" )
159165 if (api.token.accessToken.isNotBlank()) {
160166 credentialStore.spotifyToken = api.token
161- setProgressBarInvisible( )
167+ setLoadingContent( false )
162168 logToConsole(" Successful PKCE auth. Executing success handler.." )
163169 onSuccess(api)
164170 } else {
165- setProgressBarInvisible( )
171+ setLoadingContent( false )
166172 logToConsole(" Failed PKCE auth - API token was blank. Executing success handler.." )
167173 onFailure(
168174 IllegalArgumentException (" API token was blank" )
169175 )
170176 }
171177 } catch (exception: Exception ) {
172- setProgressBarInvisible( )
178+ setLoadingContent( false )
173179 logToConsole(" Got error in authorization... executing error handler" )
174180 onFailure(exception)
175181 }
176182 }
177183
178- setProgressBarInvisible( )
184+ setLoadingContent( false )
179185 finish()
180186 }
181187 }
182-
183- private fun setProgressBarInvisible () {
184- findViewById<FrameLayout >(R .id.progress_overlay).visibility = View .INVISIBLE
185- }
186-
187- private fun setProgressBarVisible () {
188- findViewById<FrameLayout >(R .id.progress_overlay).visibility = View .VISIBLE
189- }
190188}
0 commit comments