@@ -37,8 +37,8 @@ public object VkAuth {
3737 public const val VK_API_VERSION_DEFAULT : String = " 5.113"
3838 public const val VK_REDIRECT_URI_DEFAULT : String = " https://oauth.vk.com/blank.html"
3939
40- private const val INFO_RESPONSE_TYPE_NOT_SUPPORTED =
41- " Specifying the response_type is not available with the official VK App, so it can not be used"
40+ private const val INFO_RESPONSE_TYPE_NOT_SUPPORTED = " Specifying the response_type is not available " +
41+ " with the official VK App, so it can not be used"
4242
4343 private const val VK_EXTRA_CLIENT_ID = " client_id"
4444 private const val VK_EXTRA_REVOKE = " revoke"
@@ -73,8 +73,6 @@ public object VkAuth {
7373 }
7474
7575 activity.addOnNewIntentListener { intent ->
76- resultLaunchers.remove(activity)
77-
7876 try {
7977 listener(
8078 Result .success(VkResultParser .parseCustomTabs(intent = intent))
@@ -99,8 +97,6 @@ public object VkAuth {
9997 } catch (e: Throwable ) {
10098 listener(Result .failure(e))
10199 null
102- } finally {
103- resultLaunchers.remove(activity)
104100 }
105101
106102 if (vkResult != null ) {
@@ -112,6 +108,21 @@ public object VkAuth {
112108 resultLaunchers[activity] = resultLauncher
113109 }
114110
111+ /* *
112+ * Unregister the activity result listeners.
113+ *
114+ * @param activity An activity for which to unregister the listeners.
115+ * If null, all listeners will be unregistered.
116+ */
117+ @JvmStatic
118+ public fun unregister (activity : ComponentActivity ? = null) {
119+ if (activity != null ) {
120+ resultLaunchers.remove(activity)
121+ } else {
122+ resultLaunchers.clear()
123+ }
124+ }
125+
115126 /* *
116127 * Checks is the official VK app installed
117128 * to be able to authorize through the app without the WebView
@@ -179,7 +190,6 @@ public object VkAuth {
179190 AuthMode .RequireWeb -> {
180191 when {
181192 activity.customTabsSupported() -> {
182- resultLaunchers.remove(activity)
183193 activity.startActivity(loadCustomTabsAuthUrlIntent(authParams.asQuery()))
184194 null
185195 }
@@ -201,7 +211,6 @@ public object VkAuth {
201211 }
202212
203213 activity.customTabsSupported() -> {
204- resultLaunchers.remove(activity)
205214 activity.startActivity(loadCustomTabsAuthUrlIntent(authParams.asQuery()))
206215 null
207216 }
@@ -226,7 +235,6 @@ public object VkAuth {
226235
227236 when {
228237 activity.customTabsSupported() -> {
229- resultLaunchers.remove(activity)
230238 activity.startActivity(loadCustomTabsAuthUrlIntent(authParams.asQuery()))
231239 }
232240
0 commit comments