Skip to content

Commit

Permalink
fix: Keep at top of pings (#31)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
sdsantos authored Apr 5, 2021
1 parent bc4c288 commit 2f4034a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/src/main/java/tech/relaycorp/ping/ui/common/DummyItemView.kt
Original file line number Diff line number Diff line change
@@ -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)
)
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/tech/relaycorp/ping/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,6 +66,10 @@ class MainActivity : BaseActivity() {

private fun updateList(pings: List<Ping>) {
list.withModels {
dummyItemView {
id("top")
}

pings.forEach { ping ->
pingItemView {
id(ping.pingId)
Expand Down

0 comments on commit 2f4034a

Please sign in to comment.