This file contains 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
data class Report(val uuid: String, val name: String, val date: Long) | |
fun loadReport(uuid: String) { | |
api.getReport(uuid) { (_, name, date) -> | |
reportView.text = name | |
dateView.text = formatDate(date) | |
} | |
} |
This file contains 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 doSthWithReport(report: Report) = when (report) { | |
is HourlyReport -> view.showHours(report.hours) | |
is DailyReport -> view.showDate(report.date) | |
//else -> throw IllegalArgumentException() <- NOT NEEDED! | |
} |
This file contains 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
sealed class Report { | |
abstract val uuid: String | |
abstract val date: String | |
} | |
data class HourlyReport( | |
override val uuid: String, | |
override val date: String, | |
val hours: Int) : Report() |
This file contains 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
package inheritance | |
sealed class S // no { here | |
class A : S() | |
class B : S() { | |
// ... | |
} |
This file contains 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
val Context.alarmManager | |
inline get() = getSystemService(Context.ALARM_SERVICE) as AlarmManager? |
This file contains 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 val Context.alarmManager | |
get() = getSystemService(Context.ALARM_SERVICE) as AlarmManager? |
This file contains 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
typealias ItemAction = (Item, Int, Boolean) -> Unit | |
open class ViewHolder(view: View, val action: ItemAction? = null) : RecyclerView.ViewHolder(view) { | |
// ... | |
} | |
class AViewHolder(view: View, action: ItemAction? = null) : ViewHolder(view, action) { | |
// ... | |
} |
This file contains 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
open class ViewHolder(view: View, val action: ((Item) -> Unit)? = null) : RecyclerView.ViewHolder(view) { | |
// ... | |
} | |
class AViewHolder(view: View, action: ((Item) -> Unit)? = null) : ViewHolder(view, action) { | |
// ... | |
} | |
class BViewHolder(view: View, action: ((Item) -> Unit)? = null) : ViewHolder(view, action) { | |
// ... |
This file contains 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 ViewHolder(view: View, val action: ((Item) -> Unit)? = null) : RecyclerView.ViewHolder(view) { | |
fun bind(item: Item) { | |
itemView.setOnClickListener { action?.invoke(item) } | |
} | |
} |
This file contains 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 loadUser(id: Int) = async { | |
val user = api.getUser(id).await() // not blocking main thread | |
textView.text = "User: ${user.name}" | |
} |
NewerOlder