This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .map { | |
| with(createRequest(Type.NEXT, it, data)) { | |
| val keywords = // ... | |
| copy(keywords = keywords) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun returnsUnit() { | |
| methodReturningBoolean() | |
| } | |
| fun returnsAnImplicitBoolean() = methodReturningBoolean() | |
| private fun methodReturningBoolean() = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun alwaysReturnsNull(position: Int): String? { | |
| if ((position % 10) == 0) { | |
| when (position) { | |
| 10 -> "one" | |
| 20, 30 -> "two" | |
| else -> "three" | |
| } | |
| } | |
| return null | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Repository { | |
| init{ | |
| } | |
| companion object { | |
| private val CACHE = TimeUnit.HOURS.toSeconds(4) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun requireNotNulls(vararg any: Any?) { | |
| any.forEach { | |
| requireNotNull(value = it) | |
| } | |
| } | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| requireNotNulls(id1, id2) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const val ID = "id" | |
| class MyActivity : Activity() { | |
| private val id1 by extra<String>(ID) // String? | |
| private val id2 by extraNotNull<String>(ID) // String | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| requireNotNull(id1, id2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inline fun <reified T: Any> Fragment.extra(key: String, default: T? = null) = lazy { | |
| val value = arguments?.get(key) | |
| if (value is T) value else default | |
| } | |
| inline fun <reified T: Any> Fragment.extraNotNull(key: String, default: T? = null) = lazy { | |
| val value = arguments?.get(key) | |
| requireNotNull(if (value is T) value else default) { key } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inline fun <reified T: Any> Activity.extra(key: String, default: T? = null) = lazy { | |
| val value = intent?.extras?.get(key) | |
| if (value is T) value else default | |
| } | |
| inline fun <reified T: Any> Activity.extraNotNull(key: String, default: T? = null) = lazy { | |
| val value = intent?.extras?.get(key) | |
| requireNotNull(if (value is T) value else default) { key } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @UiThread | |
| fun getUsers(context: Context): LiveData<List<User>> { | |
| if (!::users.isInitialized) { | |
| users = MutableLiveData() | |
| Coroutines.ioThenMain({ | |
| DataManager.getUsers(context) | |
| }) { | |
| users.value = it | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object DataManager { | |
| @WorkerThread | |
| fun dummy(context: Context) { | |
| with(MyDatabase.get(context)) { | |
| users().insert(User(login = "user.name")) | |
| projects().insert(Project(name = "project.name")) | |
| notifications().insert(Notification(msg = "created")) | |
| } | |
| } |