-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBL-1167: New Login/Sign up Screen with Chrome Tabs (Phase 2) (#1941)
* - ChromeTabIntent with CustomTabSession + CustomTabClient to be able to detect when the X button has been pressed, pre-render the url to reduce loading times, reload when no connectivity working * - Documentation and some improvements --------- Co-authored-by: mtgriego <matthew.t.griego@gmail.com>
- Loading branch information
Showing
5 changed files
with
133 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 35 additions & 7 deletions
42
app/src/main/java/com/kickstarter/ui/activities/OAuthActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,52 @@ | ||
package com.kickstarter.ui.activities | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import androidx.activity.addCallback | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.setValue | ||
import com.kickstarter.ui.extensions.finishWithAnimation | ||
import androidx.browser.customtabs.CustomTabsIntent | ||
import androidx.lifecycle.lifecycleScope | ||
import com.kickstarter.libs.utils.TransitionUtils | ||
import com.kickstarter.models.chrome.ChromeTabsHelperActivity | ||
import com.kickstarter.ui.IntentKey | ||
import com.kickstarter.ui.extensions.setUpConnectivityStatusCheck | ||
import kotlinx.coroutines.launch | ||
|
||
class OAuthActivity : AppCompatActivity() { | ||
|
||
private lateinit var helper: ChromeTabsHelperActivity.CustomTabSessionAndClientHelper | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setUpConnectivityStatusCheck(lifecycle) | ||
|
||
this.onBackPressedDispatcher.addCallback { | ||
finishWithAnimation() | ||
// TODO MBL-1168 the url will be retrieved from the VM,on MBL-1168 alongside PKCE paramenters | ||
val uri = Uri.parse("https://www.kickstarter.com/oauth/authorizations") | ||
|
||
// BindCustomTabsService, obtain CustomTabsClient and Client, listens to navigation events | ||
helper = ChromeTabsHelperActivity.CustomTabSessionAndClientHelper(this, uri) { | ||
finish() | ||
} | ||
|
||
// - Fallback in case Chrome is not installed, open WebViewActivity | ||
val fallback = object : ChromeTabsHelperActivity.CustomTabFallback { | ||
override fun openUri(activity: Activity, uri: Uri) { | ||
val intent: Intent = Intent(activity, WebViewActivity::class.java) | ||
.putExtra(IntentKey.URL, uri.toString()) | ||
|
||
activity.startActivity(intent) | ||
TransitionUtils.slideInFromRight() | ||
} | ||
} | ||
|
||
// TODO: Will continue work on https://kickstarter.atlassian.net/browse/MBL-1167 | ||
lifecycleScope.launch { | ||
// - Once the session is ready and client warmed-up load the url | ||
helper.isSessionReady().collect { | ||
val tabIntent = CustomTabsIntent.Builder(helper.getSession()).build() | ||
ChromeTabsHelperActivity.openCustomTab(this@OAuthActivity, tabIntent, uri, fallback) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters