Skip to content

Instantly share code, notes, and snippets.

View yogacp's full-sized avatar
:octocat:
Exploring

Yoga C. Pranata yogacp

:octocat:
Exploring
View GitHub Profile
@yogacp
yogacp / MainDslActivity.kt
Last active June 28, 2018 09:06
final result of simple DSL example
val movieData = movies {
title = "Avengers: Infinity War"
genres = "Action, Adventure, Fantasy, Sci-Fi"
release_date = "27 April 2018 (USA)"
detailMovies {
country = "USA"
language = "English"
directed_by = " Anthony Russo, Joe Russo"
produced_by = "Kevin Feige"
overview = "As the Avengers and their allies have continued to protect the world from threats too large for any one hero to handle, a new danger has emerged from the cosmic shadows: Thanos. A despot of intergalactic infamy, his goal is to collect all six Infinity Stones, artifacts of unimaginable power, and use them to inflict his twisted will on all of reality. Everything the Avengers have fought for has led up to this moment - the fate of Earth and existence itself has never been more uncertain."
@yogacp
yogacp / Movies.kt
Created June 28, 2018 09:03
Models for movie data
data class Movies(
var genres: String? = null,
var title: String? = null,
var release_date: String? = null,
var detailMovies: DetailMovies? = null
)
@yogacp
yogacp / DetailMovies.kt
Created June 28, 2018 09:05
Models for detail movies data
data class DetailMovies(
var country: String? = null,
var language: String? = null,
var directed_by: String? = null,
var produced_by: String? = null,
var overview: String? = null
)
@yogacp
yogacp / final_movie_dsl.kt
Last active June 28, 2018 11:32
Final DSL function
/**
* Create function to store movies data
*/
fun movies(inputs: Movies.() -> Unit): Movies = Movies().apply(inputs)
/**
* Create function to store detail movies data
*/
fun Movies.detailMovies(inputs: DetailMovies.() -> Unit) {
detailMovies = DetailMovies().apply(inputs)
@yogacp
yogacp / Implementation_1.kt
Last active June 28, 2018 11:30
Implementation #1
val movieData = movies {
it.title = "Avengers: Infinity War"
it.genres = "Action, Adventure, Fantasy, Sci-Fi"
it.release_date = "27 April 2018 (USA)"
}
@yogacp
yogacp / final_implementation.kt
Created June 28, 2018 11:31
Final Implementation
val movieData = movies {
title = "Avengers: Infinity War"
genres = "Action, Adventure, Fantasy, Sci-Fi"
release_date = "27 April 2018 (USA)"
detailMovies {
country = "USA"
language = "English"
directed_by = " Anthony Russo, Joe Russo"
produced_by = "Kevin Feige"
overview = "As the Avengers and their allies have continued to protect the world from threats too large for any one hero to handle, a new danger has emerged from the cosmic shadows: Thanos. A despot of intergalactic infamy, his goal is to collect all six Infinity Stones, artifacts of unimaginable power, and use them to inflict his twisted will on all of reality. Everything the Avengers have fought for has led up to this moment - the fate of Earth and existence itself has never been more uncertain."
@yogacp
yogacp / movie_dsl_1.kt
Created June 28, 2018 11:34
First Movie Dsl
/**
* Create function to store movies data
*/
fun movies(inputs: (Movies) -> Unit): Movies {
val movie = Movies()
inputs(movie)
return movie
}
@yogacp
yogacp / movie_dsl_2.kt
Created June 28, 2018 11:36
Movie DSL 2
/**
* Create function to store movies data
*/
fun movies(inputs: Movies.() -> Unit): Movies = Movies().apply(inputs)
@yogacp
yogacp / Implementation_2.kt
Created June 28, 2018 11:38
Implementation_2
val movieData = movies {
title = "Avengers: Infinity War"
genres = "Action, Adventure, Fantasy, Sci-Fi"
release_date = "27 April 2018 (USA)"
}
@yogacp
yogacp / LoginContract.kt
Last active July 16, 2018 09:07
User Login example 1
class LoginContract {
interface View {
fun goToOtpPage(userId: String)
fun showError(message: String)
fun onLoginButtonClicked()
}
interface Presenter {
fun onLoginBtnPressed(username: String, password: String)
fun onLoginSuccess(userid: String)