<commit_before># IceKick
[Icepick][1]-esque Android Instance State for Kotlin, inspired by [Kotter Knife][2].

```kotlin
class MyActivity : Activity() {
  // A state that can't be null, needs a default value
  private var nonNullState: Int by state(0)

  // A state that can be null
  private var nullableState: Int? by nullableState(Int::class.java)
  
  // A state that behaves as if the variable had `lateinit` modifier
  private var lateinitState: String by lateState(String::class.java)

  // Lazier developers can even shorten them
  private var nonNullState by state(0) // Type inferred by the default value
  private var nullableState by nullableState(Int::class.java) // Needs the type information
  private var lateinitState by lateState(String::class.java)  // Same
}
```

These methods work for `Serializable` and `Parcelable` objects and are available on subclasses of `Activity`, `Fragment`,
the support library `Fragment`, and `View`.

If you need to save/restore an object that can't be made `Serializable` or `Parcelable`, a custom `Bundler` can be specified:

```kotlin
class MyFragment : Fragment() {
  // Your custom object
  class MyData(var value: Int)

  // Your Bundler
  class MyDataBundler : Bundler {
    override fun save(bundle: Bundle, key: String, value: Any?) {
      val myData = value as? MyData ?: return
      bundle.putInt(key, myData.value)
    }

    override fun load(bundle: Bundle, key: String): Any? {
      return MyData(bundle.getInt(key))
    }
  }

  // Usage
  private var myData by state(MyData(100), MyDataBundler())
  private var nullableMyData by nullableState(MyDataBundler())
  private var lateinitMyData by lateState(MyDataBundler())
}
```

Download
-------

Currently available via [JitPack][3].

To use it, add the jitpack maven repository to your build.gradle file:
```gradle
repositories {
  ...
  maven { url "https://jitpack.io" }
  ...
}
```
and add the dependency:
```gradle
dependencies {
  ...
  compile 'com.github.tinsukE:icekick:0.1'
  ...
}
```


Setup
-------

To enable it, add these to your classes:

```kotlin
class MyActivity : Activity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    unfreezeInstanceState(savedInstanceState)
  }
  
  override fun onSaveInstanceState(outState: Bundle) {
    super.onSaveInstanceState(outState)
    freezeInstanceState(outState)
  }
}
```

```kotlin
class MyFragment : Fragment() {
  override fun onSaveInstanceState(outState: Bundle) {<commit_msg>Updated the README for the new API<commit_after># IceKick
[Icepick][1]-esque Android Instance State for Kotlin, inspired by [Kotter Knife][2].

```kotlin
class MyActivity : Activity() {
  // There out-of-the-box support for Serializable
  // A state that can't be null, needs a default value
  private var nonNullState: Int by serialState(0)

  // A state that can be null
  private var nullableState: Int? by serialState()

  // A state that behaves as if the variable had the 'lateinit' modifier
  private var lateinitState: String by serialLateState()

  // And for Parcelable too
  private var resourceUri: Uri by parcelState(MY_DEFAULT_URI)
  private var nullableIntentState: Intent? by parcelState()
  private val lateinitPacelState: Intent by parcelLateState()
}
```

These methods are available on subclasses of `Activity`, `Fragment`, the support library `Fragment`, and `View`.

If you need to save/restore an object that can't be made `Serializable` or `Parcelable`, a custom `Bundler` can be specified:

```kotlin
class MyFragment : Fragment() {
  // Your custom object
  class MyData(var value: Int)

  // Your Bundler
  class MyDataBundler : Bundler<MyData> {
    override fun save(bundle: Bundle, key: String, value: MyData?) {
      val myData = value as? MyData ?: return
      bundle.putInt(key, myData.value)
    }

    override fun load(bundle: Bundle, key: String): MyData? {
      return if (bundle.containsKey(key)) MyData(bundle.getInt(key)) ?: null
    }
  }

  // Usage
  private var myData: MyData by state(MyData(100), MyDataBundler())
  private var nullableMyData: MyData? by state(MyDataBundler())
  private var lateinitMyData: MyData by lateState(MyDataBundler())
}
```

Download
-------

Currently available via [JitPack][3].

To use it, add the jitpack maven repository to your build.gradle file:
```gradle
repositories {
  ...
  maven { url "https://jitpack.io" }
  ...
}
```
and add the dependency:
```gradle
dependencies {
  ...
  compile 'com.github.tinsukE:icekick:0.2'
  ...
}
```


Setup
-------

To enable it, add these to your classes:

```kotlin
class MyActivity : Activity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    unfreezeInstanceState(savedInstanceState)
  }
  
  override fun onSaveInstanceState(outState: Bundle) {
    super.onSaveInstanceState(outState)
    freezeInstanceState(outState)
  }
}
```

```kotlin
class MyFragment : Fragment() {
  override fun onSaveInstanceState(outState: Bundle) {
{'fraction_non_alphanumeric': 0.11168727562824092, 'fraction_numerical': 0.003789389708815317, 'mean_word_length': 3.955533596837945, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1103440', 'n_tokens_mistral': 1622, 'n_tokens_neox': 1507, 'n_words': 513}