Skip to content

Instantly share code, notes, and snippets.

View adrianhall's full-sized avatar

Adrian Hall adrianhall

View GitHub Profile
@adrianhall
adrianhall / activity_authenticator.xml
Created April 18, 2018 19:39
Layout for the Sign-in process
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_background"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<TextView
@adrianhall
adrianhall / AuthenticatorActivity.kt
Created April 18, 2018 19:47
Partial AuthenticatorActivity for a custom UI
class AuthenticatorActivity : Activity(), AuthenticationHandler {
companion object {
private val TAG: String = this::class.java.simpleName
}
/**
* The identityManager for this application
*/
private val identityManager: IdentityManager by inject()
@adrianhall
adrianhall / AuthenticatorActivity.kt
Created April 18, 2018 19:51
The handleLogin() method
/**
* Handles the login event
*/
private fun handleLogin() {
val username = loginform_username.getContent()
val password = loginform_password.getContent()
Log.d(TAG, "handleLogin - username = $username, password = $password")
/**
@adrianhall
adrianhall / AuthenticatorActivity.kt
Created April 18, 2018 19:56
AuthenticationHandler implementation
/**
* Part of the AuthenticationHandler interface
*
* Called when the Amazon Cognito service returns a valid set of tokens, when the tokens
* are available (cached) or after successful completion of the authentication process.
*
* @param userSession Contains the valid user tokens
* @param newDevice If this is a new device, then contains the device information
*/
override fun onSuccess(userSession: CognitoUserSession?, newDevice: CognitoDevice?) {
@adrianhall
adrianhall / AuthenticatorActivity.kt
Created April 18, 2018 19:58
getMFACode callback
@Suppress("InflateParams")
override fun getMFACode(continuation: MultiFactorAuthenticationContinuation?) {
runOnUiThread {
val mfaPromptDialog = layoutInflater.inflate(R.layout.dialog_mfa_prompt, null)
val mfaInput = mfaPromptDialog.find(R.id.mfapromptdialog_code) as MFAEditText
continuation?.let {
val mfaInstructions = mfaPromptDialog.find(R.id.mfapromptdialog_instructions) as TextView
mfaInstructions.text = "Enter the code we just sent to ${it.parameters.deliveryMedium}:${it.parameters.destination}"
}
alert {
@adrianhall
adrianhall / IdentityManager.kt
Last active April 18, 2018 21:34
The definition for a custom UI IdentityManager
package com.shellmonger.apps.familyphotos.services.interfaces
import android.arch.lifecycle.LiveData
import com.shellmonger.apps.familyphotos.models.User
enum class IdentityRequest {
NEED_CREDENTIALS,
NEED_NEWPASSWORD,
NEED_MULTIFACTORCODE,
SUCCESS,
@adrianhall
adrianhall / MockIdentityManager.kt
Created April 18, 2018 22:32
A mock identity manager
package com.shellmonger.apps.familyphotos.services.mock
import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
import android.util.Log
import com.amazonaws.mobile.auth.core.internal.util.ThreadUtils.runOnUiThread
import com.shellmonger.apps.familyphotos.models.User
import com.shellmonger.apps.familyphotos.services.interfaces.IdentityHandler
import com.shellmonger.apps.familyphotos.services.interfaces.IdentityManager
import com.shellmonger.apps.familyphotos.services.interfaces.IdentityRequest
@adrianhall
adrianhall / AuthenticatorActivity.kt
Created April 18, 2018 22:34
The refactored handleLogin() method
@SuppressLint("InflateParams")
private fun handleLogin() {
identityManager.initiateSignin {
request, params, callback -> when(request) {
IdentityRequest.NEED_CREDENTIALS -> {
Log.d(TAG, "NEED_CREDENTIALS")
callback(mapOf("username" to loginform_username.getContent(), "password" to loginform_password.getContent()))
}
IdentityRequest.NEED_NEWPASSWORD -> {
@adrianhall
adrianhall / wpconvert.sh
Created May 4, 2018 23:07
Convert an exported wordpress.com post to Jekyll
#!/usr/bin/env bash
echo "Processing $1"
base=${1//.html/}
# split .html into an empty file, a .yaml and an .htm
csplit "$base.html" '/---/'
mv xx00 tmp/$base.yaml
mv xx01 tmp/$base.html
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.NoteDetailActivity">
<EditText
android:id="@+id/detail_title_editor"