From 2f70495070a1d11f87b725790e289ba2121274a3 Mon Sep 17 00:00:00 2001 From: deviant Date: Sat, 21 Oct 2017 00:14:38 +0300 Subject: [PATCH] docs fixes --- README.md | 19 +++++++++++++++++-- .../java/ds/bindingtools/demo/MainActivity.kt | 12 ++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index af41fb5..a28e125 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ println("the name is ${prefs.userName}") ``` ### Bundle arguments tricks -The args bundle have never been such simple before. Let's declare another one activity: +Dealing with args bundle has never been such simple before. Let's declare another one activity: ```kotlin class SecondActivity : AppCompatActivity() { @@ -136,10 +136,25 @@ class SecondActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_second) - println("$userName $age $country") + println("$userName $age $country") // that's it. just read the properties } } +``` +Start activity with convenient bundle builder: +```kotlin +startActivity { + SecondActivity::userName to "Ivo Bobul" + SecondActivity::age to 99 + SecondActivity::code to 65536 +} +``` +or build the bundle separately: +```kotlin +val args = bundle { + SecondActivity::userName to "Slavko Vakarchuk" + SecondActivity::code to 100500 +} ``` ### Resources diff --git a/app/src/main/java/ds/bindingtools/demo/MainActivity.kt b/app/src/main/java/ds/bindingtools/demo/MainActivity.kt index f060ae0..4bc6066 100644 --- a/app/src/main/java/ds/bindingtools/demo/MainActivity.kt +++ b/app/src/main/java/ds/bindingtools/demo/MainActivity.kt @@ -5,7 +5,9 @@ import android.support.v7.app.AppCompatActivity import android.widget.Button import android.widget.TextView import ds.bindingtools.bind +import ds.bindingtools.bundle import ds.bindingtools.startActivity +import ds.bindingtools.unbindAll class MainActivity : AppCompatActivity() { @@ -29,6 +31,12 @@ class MainActivity : AppCompatActivity() { } + override fun onDestroy() { + super.onDestroy() + // need in case your viewmodel life duration is greater than activity (e.g. Arch Components ViewModel) + viewModel.unbindAll() + } + private fun bindViews() = with(viewModel) { bind(::text, textLabel::setText, textLabel::getText) } @@ -47,5 +55,9 @@ class MainActivity : AppCompatActivity() { SecondActivity::age to 99 SecondActivity::code to 65536 } + val args = bundle { + SecondActivity::userName to "Slavko Vakarchuk" + SecondActivity::code to 100500 + } } }