ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - andre-artus/AnvilKotlin: A simple Kotlin wrapper around Anvil.
A simple Kotlin wrapper around Anvil. Contribute to andre-artus/AnvilKotlin development by creating an account on GitHub.
Visit Site

GitHub - andre-artus/AnvilKotlin: A simple Kotlin wrapper around Anvil.

GitHub - andre-artus/AnvilKotlin: A simple Kotlin wrapper around Anvil.

AnvilKotlin

A simple Kotlin wrapper around Anvil.

The only purpose of this library is to provide type safety to Anvil through Kotlin. Nothing more, nothing less. Enjoy! :)

Get it

Add the JitPack repo to your root build.gradle file:

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

The possible library strings are:

dependencies {
	// Remember, you still need to set up the equivalent Anvil ones!
	
	// SDK libraries
	compile 'com.github.graknol.AnvilKotlin:anvil:0.4.0:sdk15Release@aar'
	compile 'com.github.graknol.AnvilKotlin:anvil:0.4.0:sdk19Release@aar'
	compile 'com.github.graknol.AnvilKotlin:anvil:0.4.0:sdk21Release@aar'
	
	// Support libraries
	compile 'com.github.graknol.AnvilKotlin:cardview:0.4.0@aar'
	compile 'com.github.graknol.AnvilKotlin:gridlayout:0.4.0@aar'
	compile 'com.github.graknol.AnvilKotlin:recyclerview:0.4.0@aar'
	compile 'com.github.graknol.AnvilKotlin:support:0.4.0@aar'
	compile 'com.github.graknol.AnvilKotlin:design:0.4.0@aar'
	compile 'com.github.graknol.AnvilKotlin:appcompat:0.4.0@aar'
}

How to use it

Use the functions from each library (these are found in graknol.anvil.kotlin) to create views and then use the functions on this, for instance:

val fooContent: Anvil.Renderable.() -> Unit = {
	coordinatorLayout {
		appBarLayout {
			size(MATCH, WRAP)
			toolbar {
				size(MATCH, dip(48))
			}
		}
	}
}

// Just to demonstrate that you can indeed style views by a lambda (think, theme classes with functions like this in it).
val styleNavDrawer: AppCompatDSLListViewCompat.() -> Unit = {
	choiceMode(ListView.CHOICE_MODE_SINGLE)
	divider(resources.getDrawable(android.R.color.transparent))
	dividerHeight(0)
	backgroundColor(hex("#111111"))
}

class ExampleView(c: Context) : RenderableView(c) {
	fun view() {
		linearLayout {
			backgroundColor(someIntColorValue)
			appCompatButton {
				text("click me!")
				onClick(View.OnClickListener {
					doSomethingCool()
				})
			}
			
			drawerLayout {
				// Look at the top of this snippet
				fooContent()
				
				listViewCompat {
					size(dip(240), MATCH)
					// Look at the top of this snippet
					styleNavDrawer() 
				}.lparams {
					gravity = START
					weight = 1f
				}
			}
			
			// If there are functions missing in the DSL, do this little trick:
			with(Anvil.currentView<LinearLayout>()) {
				// Magic!
				whicheverFunctionIsMissing()
				andAllOthers()
			}
		}
	}
}

The reason for the "seemingly redundant" typing of OnClickListener above, is simply that Kotlin does not automatically convert Kotlin parameters to SAMs (Single abstract method), and there are too many functions in the different library for me to patch every single one of them. PS: Some listeners have multiple functions, so you'll end up writing those like this anyway ;)

Splitting the code is ~~ugly not that ugly anymore, YAY :)

Most issues are not present anymore. If there's something bothering you on this area, DO NOT hesitate to open an issue (we really need all the input we can get).

License

Code is distributed under the MIT license, feel free to use it in your proprietary projects as well.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory