From 2f4034a902c96f022c722ba8b1d687093b131e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Santos?= Date: Mon, 5 Apr 2021 22:05:36 +0100 Subject: [PATCH] fix: Keep at top of pings (#31) Fixes #25 If already at the top of the list of pings, when a new ping is added, it keeps being at the top of the list, to ensure the new ping is visible. But it won't show it if you were not at the top (this is usually the expected behaviour). --- .../relaycorp/ping/ui/common/DummyItemView.kt | 24 +++++++++++++++++++ .../relaycorp/ping/ui/main/MainActivity.kt | 5 ++++ 2 files changed, 29 insertions(+) create mode 100644 app/src/main/java/tech/relaycorp/ping/ui/common/DummyItemView.kt diff --git a/app/src/main/java/tech/relaycorp/ping/ui/common/DummyItemView.kt b/app/src/main/java/tech/relaycorp/ping/ui/common/DummyItemView.kt new file mode 100644 index 00000000..f7d9b2fd --- /dev/null +++ b/app/src/main/java/tech/relaycorp/ping/ui/common/DummyItemView.kt @@ -0,0 +1,24 @@ +package tech.relaycorp.ping.ui.common + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import com.airbnb.epoxy.ModelView + +@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT, fullSpan = true) +class DummyItemView +@JvmOverloads +constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : View(context, attrs, defStyleAttr) { + + // 1 invisible px square + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + super.onMeasure( + MeasureSpec.makeMeasureSpec(1, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(1, MeasureSpec.EXACTLY) + ) + } +} diff --git a/app/src/main/java/tech/relaycorp/ping/ui/main/MainActivity.kt b/app/src/main/java/tech/relaycorp/ping/ui/main/MainActivity.kt index a48c014e..47651e55 100644 --- a/app/src/main/java/tech/relaycorp/ping/ui/main/MainActivity.kt +++ b/app/src/main/java/tech/relaycorp/ping/ui/main/MainActivity.kt @@ -14,6 +14,7 @@ import tech.relaycorp.ping.R import tech.relaycorp.ping.common.di.ViewModelFactory import tech.relaycorp.ping.domain.model.Ping import tech.relaycorp.ping.ui.BaseActivity +import tech.relaycorp.ping.ui.common.dummyItemView import tech.relaycorp.ping.ui.peers.PeersActivity import tech.relaycorp.ping.ui.ping.SendPingActivity import javax.inject.Inject @@ -65,6 +66,10 @@ class MainActivity : BaseActivity() { private fun updateList(pings: List) { list.withModels { + dummyItemView { + id("top") + } + pings.forEach { ping -> pingItemView { id(ping.pingId)