Skip to content

Instantly share code, notes, and snippets.

View delacrixmorgan's full-sized avatar
💭
🙉🙈🙊

Morgan Koh delacrixmorgan

💭
🙉🙈🙊
View GitHub Profile
@delacrixmorgan
delacrixmorgan / CubeTransformer.md
Last active November 21, 2021 09:45
Cube ViewPager Transformer

Cube ViewPager Transformer

class CubeTransformer : ViewPager.PageTransformer {
    override fun transformPage(view: View, position: Float) {
        val deltaY = 0.5F

        view.pivotX = if (position < 0F) view.width.toFloat() else 0F
        view.pivotY = view.height * deltaY
 view.rotationY = 45F * position
@delacrixmorgan
delacrixmorgan / ShrinkAnimation.md
Last active February 13, 2019 08:38
Shrink Layout Animation

Shrink Layout Animation

enum class ScaleType{
  SHRINK,
  GROW
}

fun View.startScaleAnimation(scaleType: ScaleType, durationInMilliseconds: Long) {
 val scaleAnimation = when (scaleType) {
@delacrixmorgan
delacrixmorgan / InvokeInterface.md
Last active February 13, 2019 08:39
Invoke Completion with FirebaseUser and Exception Listener

Invoke Completion with FirebaseUser and Exception Listener

fun sendCurrentUserEmailVerification(completion: ((user: FirebaseUser?, error: Exception?) -> Unit)) {
        val currentUser = this.authFireBase.currentUser
        
        if (currentUser != null) {
            currentUser.sendEmailVerification()
                .addOnCompleteListener { task ->
                    if (task.isSuccessful) {
@delacrixmorgan
delacrixmorgan / HelloCoroutines.md
Last active February 13, 2019 08:39
Kotlin Coroutines Callback

Kotlin Coroutines Callback

interface CallbackListener<T> {
  fun onComplete(result: T)
  fun onException(e: Exception?)
}

suspend fun <T> awaitCallback(block: (CallbackListener<T>) -> Unit): T =
 suspendCancellableCoroutine { cont -&gt;
@delacrixmorgan
delacrixmorgan / FetchGalleryImages.md
Last active February 13, 2019 08:39
Fetch Gallery Images and Returning URLs

Fetch Gallery Images and Returning URLs

open class Photo(val url: String)

fun Activity.getGalleryImages(): ArrayList<Photo> {
    val galleryImageUrls: ArrayList<GalleryPickerFragment.Photo> = ArrayList()
    val columns = arrayOf(MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID)
    val orderBy = MediaStore.Images.Media.DATE_TAKEN
@delacrixmorgan
delacrixmorgan / AuthFiniteStateMachine.md
Last active February 14, 2019 08:57
Finite State Machine Authentication Flow

Finite State Machine Authentication Flow

class AuthRegistrationTest {
    sealed class AuthRegistrationState: FSMState {
        object Presenting : AuthRegistrationState()
        object Registering : AuthRegistrationState()
        class Failed(var error: Error) : AuthRegistrationState()
        class Completed(var user: User?) : AuthRegistrationState()
    }
@delacrixmorgan
delacrixmorgan / KotlinSerialization.md
Last active April 27, 2020 08:25
Kotlin JSON Processor using native Kotlin Serializable

Kotlin JSON Processor using native Kotlin Serializable

Date Serializer

@Serializer(forClass = DateSerializer::class)
object DateSerializer : KSerializer<Date> {
    override val descriptor: SerialDescriptor =
        PrimitiveDescriptor(DateSerializer.javaClass.simpleName, PrimitiveKind.STRING)

    override fun serialize(encoder: Encoder, value: Date) {
@delacrixmorgan
delacrixmorgan / AndroidFastlane.md
Last active February 13, 2019 08:37
Fastlane Android Bundle and APK Deployment

Fastlane Android Bundle and APK Deployment

default_platform(:android)

platform :android do
  desc "Runs all the tests"
  lane :test do
    gradle(task: "test")
  end
@delacrixmorgan
delacrixmorgan / JsonApiKotlin.md
Last active February 4, 2019 01:58
Kotlin Flattening Json API

Kotlin Flattening Json API

JSON that conform to the structure of https://jsonapi.org/. Flattening the JSON to able to deserialize into Kotlin objects later on.

data_post.json

{
  "data": [
    {
@delacrixmorgan
delacrixmorgan / PrimaryButtonStyles.md
Last active February 13, 2019 08:42
Default Button Style in Theme

Default Button Style in Theme

<resources> 
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="buttonStyle">@style/primaryButton</item>
    </style>