Skip to content

Instantly share code, notes, and snippets.

View brady-aiello's full-sized avatar

Brady Aiello brady-aiello

View GitHub Profile
@brady-aiello
brady-aiello / UiState.kt
Last active November 14, 2023 22:20
A data state sealed class that treats Loading as a member of every state, rather than an exclusive state itself.
/*
This UiState model addresses the problems associated with treating Loading as its own state.
Loading in general is not an exclusive state.
You may be showing data, and fetching (Success + Loading).
You might show an error, and try to fetch the data again (Error + Loading)
The only time Loading is kind of its own thing is when the screen is first opened, and nothing is displayed yet.
So that case, InitialBlankLoading should be a separate state.
Here's what a flow in this would look like, fetching a list of messages:
@brady-aiello
brady-aiello / GoogleAuth.kt
Last active March 15, 2024 02:11
Google Auth: One Tap with Legacy Auth backup using Coroutines
package com.nbcuni.idm.sdk.debug.ui
import android.annotation.SuppressLint
import android.app.PendingIntent
import android.text.method.LinkMovementMethod
import android.util.Log
import android.view.View
import android.widget.TextView
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.IntentSenderRequest
@brady-aiello
brady-aiello / FacebookAuth.kt
Last active September 3, 2021 20:50
Facebook Login with Coroutines
@ExperimentalCoroutinesApi
private fun setupFacebookContinueButton() {
binding?.buttonContinueFacebook?.setOnClickListener {
beginLoginToFacebook()
finishFacebookLogin { loginResult ->
loginViewModel.loginFacebook(loginResult.accessToken.token)
}
}
}
@brady-aiello
brady-aiello / GoogleOneTapAuth.kt
Last active March 10, 2022 15:13
Setup Google One Tap with Coroutines and Activity Result Contract API
// InvalidFragmentVersionForActivityResult: https://issuetracker.google.com/issues/182388985
@SuppressLint("InvalidFragmentVersionForActivityResult")
@ExperimentalCoroutinesApi
private fun setupGoogleContinueButton() {
activity?.let { fragmentActivity ->
oneTapClient = Identity.getSignInClient(fragmentActivity)
signInRequest = createBeginSignInRequest(fragmentActivity)
val intentSender: ActivityResultLauncher<IntentSenderRequest> =
getGoogleActivityResultLauncher()