Skip to content

Commit

Permalink
docs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-dev committed Oct 20, 2017
1 parent 58c8169 commit 2f70495
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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> {
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
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/ds/bindingtools/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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)
}
Expand All @@ -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
}
}
}

0 comments on commit 2f70495

Please sign in to comment.