Skip to content

Instantly share code, notes, and snippets.

@dshen6
dshen6 / ViewState.kt
Created March 12, 2018 05:18
Android ViewState
sealed class ViewState<T> {
class Init<T>: ViewState<T>()
class Error<T>: ViewState<T>()
class Empty<T>: ViewState<T>()
class Loading<T>: ViewState<T>()
class DataReady<T>(val data : T): ViewState<T>()
}
@dshen6
dshen6 / ViewModelProviderHelper.kt
Created March 12, 2018 05:17
Android Arch-ViewModelProviderHelper
import android.arch.lifecycle.ViewModelProvider
import android.arch.lifecycle.ViewModelStores
import android.support.v4.app.Fragment
/**
* Created by Shen on 2/4/2018.
*/
object ViewModelProviderHelper {
fun forFragmentInActivity(fragment: Fragment): ViewModelProvider {
@dshen6
dshen6 / TransitionHelper.kt
Created March 12, 2018 05:11
Android TransitionManagerUtil
import android.annotation.TargetApi
import android.support.v4.view.animation.FastOutSlowInInterpolator
import android.support.v7.widget.RecyclerView
import android.transition.ChangeBounds
import android.transition.Fade
import android.transition.Transition
import android.transition.TransitionManager
import android.transition.TransitionSet
import android.view.View
import android.view.ViewGroup

Now you have all the tools to make a game!

But let's just practice using them for now.

  1. What variable do you change to make the ball fall faster? Try it!
  2. What variable can you change to make the ball fall further?
  3. Let's give our ball horizontal motion!
  • Create a global var horizontalSpeed, assign it the value 1.
  • Within the move function body, make another variable called previousLeft, assign it ball.offset().left.
  • Then use offset() to change the ball's left offset.
@dshen6
dshen6 / README.md
Last active October 24, 2017 05:42
Exported from Popcode. Click to import: https://popcode.org/?gist=d9cdd70e652a6831d67ff35d89480e89

Create a mosaic with different colors by adding ID attributes and selecting individual elements. Use the background-color attribute.