Skip to content

Instantly share code, notes, and snippets.

Avatar
🧉

Paweł Gajda pawegio

🧉
View GitHub Profile
View sample_2_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
View sample1Optimized.kt
private fun generateItems(): List<Item> {
val now = LocalDateTime.now()
return List(1_000) { Item(now, it + 1) }
}
private fun bindItem(holder: ViewHolderBinder<Item>, item: Item) = with(holder.itemView) {
val date = item.now.plusDays(item.offset.toLong()).toLocalDate().atStartOfDay()
val remainingTime = getRemainingTime(item.now, date)
dateView.text = date.format(DateTimeFormatter.ISO_LOCAL_DATE)
remainingTimeView.text = resources.getString(R.string.remaining, remainingTime)
View Item.kt
data class Item(val now: LocalDateTime, val offset: Int)
View methods.csv
class method total time (in ms) percentage of recorded duration
Sample1Activity refreshData 3027 89.28
Sample1Activity generateItems 3025 89.22
Sample1Activity getRemainingTime 1723 50.83
LocalDateTime format 1003 29.59
View simple_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical">
<TextView
android:id="@+id/dateView"
View sample_1_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
View Sample1Activity.kt
class Sample1Activity : AppCompatActivity() {
private val items = mutableListOf<Item>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.sample_1_activity)
recyclerView.adapter = basicAdapterWithLayoutAndBinder(
items, R.layout.simple_list_item, ::bindItem
View keybase.md

Keybase proof

I hereby claim:

  • I am pawegio on github.
  • I am pawegio (https://keybase.io/pawegio) on keybase.
  • I have a public key ASDbR3fTMPvOcu2OoWUw4QLLKArGlLJeeqZIclv3KwjAEgo

To claim this, I am signing this object:

View inlining3.kt
inline val <reified T> T.tag
get() = T::class.simpleName
fun Any.log(msg: String) = Log.d(tag, msg)