This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FragmentDelegateTest : Fragment() { | |
companion object { | |
fun newInstance(someId: String) : FragmentDelegateTest { | |
return FragmentDelegateTest().apply { this.someId = someId } | |
} | |
} | |
private var someId: String? by fragmentArgument() | |
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object About : MdlContent { | |
override val content = content("About") { | |
setAttribute("style", " background: url('images/whoiam.jpg') center / cover; filter: alpha(opacity=60); padding: 10px;") | |
grid { | |
cell(3) {} | |
cellCard(6) { | |
title = "About me" | |
supportingText = "Completely self-taught, I began my love for writing code when I was you kid and found out about QBasic on the family computer. In my day to day life, I enjoy keeping up with new developments within the technology and android community. I am very passionate about clean thought out architecture in the code I write. And believe strongly in testing as much as possible. Even on Android where it's not the easiest to accomplish." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun content(title: String, cssClassId: String = "", body: Element.() -> Unit) = Content(title, cssClassId, body) | |
class Content(val title: String, cssClassId: String = "", body: Element.() -> Unit) : MdlComponent("div", "mdl-layout__content", cssClassId) { | |
init { | |
mainElement.body() | |
} | |
} | |
interface MdlContent { | |
val content: Content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
val mdlApp = mdlApp { | |
navigationLayout(About, "layout") { | |
header {} | |
drawer("drawer") { | |
mainElement.header("drawer-header ${MdlColor.Background.blueGrey(Shade.s300)}") { | |
img("avatar") { src = "images/roundprofile.png" } | |
b { textContent = "Lewis Rhine" } | |
append(document.createTextNode("Android Developer")) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Img(cssClassId: String = "") : MdlComponent("img", cssClassId) { | |
var src: String by htmlPram() | |
var width: Int by htmlPram() | |
var height: Int by htmlPram() | |
var border:Int by htmlPram() | |
var alt: String by htmlPram() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class MdlComponent(tag: String, classType: String, cssClassId: String = "") { | |
val mainElement = document.createElement(tag).apply { this classType "$cssClassId $classType" } | |
var backgroundColor: MdlColor.Background? = null | |
set(value) { | |
value?.let { mainElement.setAttribute("class", mainElement.getAttribute("class")?.plus(" $it")!!) } | |
} | |
var textColor: MdlColor.Text? = null | |
set(value) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun mdlApp(init: MdlApp.() -> Unit): MdlApp { | |
val app = MdlApp() | |
app.init() | |
return app | |
} | |
class MdlApp() { | |
private val app = document.getElementById("MdlApp") | |
init { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
when (restaurantNearby) { | |
is RestaurantNearby.Loading -> // Tell user the data is loading | |
is RestaurantNearby.Loading.Done -> { | |
restaurantNearby.reloadData() // Attach this function to some user feedback. | |
when (restaurantNearby) { | |
is RestaurantNearby.Loading.Done.Ready -> restaurantNearby.restaurants // Do something with this list. | |
is RestaurantNearby.Loading.Done.Empty -> // Tell the user there was no data found. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class RestaurantNearby() { | |
sealed class Loading() : RestaurantNearby() { | |
//Code for getting Location, and API call | |
sealed class Done() : Loading() { | |
fun reloadData() {} | |
class Ready(val restaurants: List<Restaurant>) : Done() | |
class Empty() : Done() | |
class Error(val message: String, val throwable: Throwable?) : Done() | |
} | |
} |