ObservableArray<T> { val size: Int operator fun get(index: Int): T fun updates(): Observable<Event> sealed class Event { class DataSetChanged : Event() class ItemChanged(val position: Int) : Event() class ItemInserted(val position: Int) : Event() class ItemRemoved(val position: Int) : Event() } }
ObservableArray<T> { val size: Int operator fun get(index: Int): T fun updates(): Observable<Event> sealed class Event { class DataSetChanged : Event() class ItemChanged(val position: Int) : Event() class ItemInserted(val position: Int) : Event() class ItemRemoved(val position: Int) : Event() } }
ObservableArray<T> { val size: Int operator fun get(index: Int): T fun updates(): Observable<Event> sealed class Event { class DataSetChanged : Event() class ItemChanged(val position: Int) : Event() class ItemInserted(val position: Int) : Event() class ItemRemoved(val position: Int) : Event() } } operator overloadで array[0] という形のアクセスが可能
ObservableArray<T> { val size: Int operator fun get(index: Int): T fun updates(): Observable<Event> sealed class Event { class DataSetChanged : Event() class ItemChanged(val position: Int) : Event() class ItemInserted(val position: Int) : Event() class ItemRemoved(val position: Int) : Event() } } 変更の通知を受け取ることが可能
ObservableArray<T> { val size: Int operator fun get(index: Int): T fun updates(): Observable<Event> sealed class Event { class DataSetChanged : Event() class ItemChanged(val position: Int) : Event() class ItemInserted(val position: Int) : Event() class ItemRemoved(val position: Int) : Event() } } sealed classで複数のEventを定義
ObservableArray<T> { val size: Int operator fun get(index: Int): T fun updates(): Observable<Event> sealed class Event { class DataSetChanged : Event() class ItemChanged(val position: Int) : Event() class ItemInserted(val position: Int) : Event() class ItemRemoved(val position: Int) : Event() } }
ExampleActivity extends Activity { @State String username; // This will be automatically saved and restored @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Icepick.restoreInstanceState(this, savedInstanceState); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Icepick.saveInstanceState(this, outState); } // You can put the calls to Icepick into a BaseActivity // All Activities extending BaseActivity automatically have state saved/restored } ͜ΕΛKotlinͷػೳΛ͔࣮ͭͬͯͯ͠Έͨ
MainActivity : Activity(), Pikkel by PikkelDelegate() { var data by state<String?>(null) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) restoreInstanceState(savedInstanceState) } override fun onSaveInstanceState(outState: Bundle?) { super.onSaveInstanceState(outState) saveInstanceState(outState) } } ͓·͡ͳ͍
Activity(), Pikkel by PikkelDelegate() { var data by state<String?>(null) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) restoreInstanceState(savedInstanceState) } override fun onSaveInstanceState(outState: Bundle?) { super.onSaveInstanceState(outState) saveInstanceState(outState) } } อଘ͍ͨ͠ϓϩύςΟΛ by state<T>() ͷ delegated propertyͰࢦఆ
Activity(), Pikkel by PikkelDelegate() { var data by state<String?>(null) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) restoreInstanceState(savedInstanceState) } override fun onSaveInstanceState(outState: Bundle?) { super.onSaveInstanceState(outState) saveInstanceState(outState) } } onSaveInstanceState() Ͱstate()ࢦఆ͍ͯͨ͠ϓϩύ ςΟ͕ࣗಈతʹอଘ͞ΕΔ
Activity(), Pikkel by PikkelDelegate() { var data by state<String?>(null) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) restoreInstanceState(savedInstanceState) } override fun onSaveInstanceState(outState: Bundle?) { super.onSaveInstanceState(outState) saveInstanceState(outState) } } ʢ͠อଘͯ͋͠Εʣ onCreate()ͷ savedInstanceState͔ΒΛ ෮ݩ