|
| 1 | +package com.bkase.cyklic.example.app |
| 2 | + |
| 3 | +import android.os.Bundle |
| 4 | +import android.support.v7.app.AppCompatActivity |
| 5 | +import android.support.v7.widget.Toolbar |
| 6 | +import android.view.Menu |
| 7 | +import android.view.MenuItem |
| 8 | +import android.widget.Button |
| 9 | +import android.widget.TextView |
| 10 | +import com.bkase.cyklic.example.SimpleCounter |
| 11 | +import com.bkase.cyklic.example.app.R |
| 12 | +import com.jakewharton.rxbinding.view.clicks |
| 13 | + |
| 14 | +class MainActivity : AppCompatActivity() { |
| 15 | + |
| 16 | + val incButton by lazy { |
| 17 | + findViewById(R.id.increment) as Button |
| 18 | + } |
| 19 | + |
| 20 | + val decButton by lazy { |
| 21 | + findViewById(R.id.decrement) as Button |
| 22 | + } |
| 23 | + |
| 24 | + val countView by lazy { |
| 25 | + findViewById(R.id.count) as TextView |
| 26 | + } |
| 27 | + |
| 28 | + val component by lazy { |
| 29 | + val viewish = object: SimpleCounter.Viewish { |
| 30 | + override fun setCount(count: Int) { |
| 31 | + countView.text = count.toString() |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + SimpleCounter.SimpleCounterComponent( |
| 36 | + SimpleCounter.ViewIntentions( |
| 37 | + incButton.clicks(), |
| 38 | + decButton.clicks() |
| 39 | + ), viewish |
| 40 | + ) |
| 41 | + } |
| 42 | + |
| 43 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 44 | + super.onCreate(savedInstanceState) |
| 45 | + setContentView(R.layout.activity_main) |
| 46 | + val toolbar = findViewById(R.id.toolbar) as Toolbar? |
| 47 | + setSupportActionBar(toolbar) |
| 48 | + } |
| 49 | + |
| 50 | + override fun onResume() { |
| 51 | + super.onResume() |
| 52 | + |
| 53 | + component.start() |
| 54 | + } |
| 55 | + |
| 56 | + override fun onPause() { |
| 57 | + component.stop() |
| 58 | + |
| 59 | + super.onPause() |
| 60 | + } |
| 61 | + |
| 62 | + override fun onCreateOptionsMenu(menu: Menu): Boolean { |
| 63 | + // Inflate the menu; this adds items to the action bar if it is present. |
| 64 | + menuInflater.inflate(R.menu.menu_main, menu) |
| 65 | + return true |
| 66 | + } |
| 67 | + |
| 68 | + override fun onOptionsItemSelected(item: MenuItem): Boolean { |
| 69 | + // Handle action bar item clicks here. The action bar will |
| 70 | + // automatically handle clicks on the Home/Up button, so long |
| 71 | + // as you specify a parent activity in AndroidManifest.xml. |
| 72 | + val id = item.itemId |
| 73 | + |
| 74 | + //noinspection SimplifiableIfStatement |
| 75 | + if (id == R.id.action_settings) { |
| 76 | + return true |
| 77 | + } |
| 78 | + |
| 79 | + return super.onOptionsItemSelected(item) |
| 80 | + } |
| 81 | +} |
0 commit comments