Preserve open positions carousel scroll
This commit is contained in:
@@ -10,7 +10,7 @@ android {
|
||||
applicationId = "xyz.kusoft.tradebotmonitor"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 15
|
||||
versionName = "0.2.12"
|
||||
versionCode = 16
|
||||
versionName = "0.2.13"
|
||||
}
|
||||
}
|
||||
|
||||
+9
-3
@@ -59,6 +59,7 @@ class MainActivity : Activity() {
|
||||
var exposure: TextView? = null,
|
||||
var positionCount: TextView? = null,
|
||||
var positionsContainer: LinearLayout? = null,
|
||||
var positionsScroller: HorizontalScrollView? = null,
|
||||
var positionsList: LinearLayout? = null,
|
||||
var closedTradesContainer: LinearLayout? = null,
|
||||
val positions: MutableMap<String, PositionBinding> = linkedMapOf(),
|
||||
@@ -258,7 +259,7 @@ class MainActivity : Activity() {
|
||||
val positionSignature = positionsSignature(data.positions)
|
||||
if (binding.positionSignature != positionSignature) {
|
||||
binding.positionsContainer?.let { container ->
|
||||
rebuildPositionsContent(container, data.positions)
|
||||
rebuildPositionsContent(container, data.positions, binding.positionsScroller?.scrollX ?: 0)
|
||||
binding.positionSignature = positionSignature
|
||||
} ?: return false
|
||||
}
|
||||
@@ -833,9 +834,10 @@ class MainActivity : Activity() {
|
||||
return section(null, body)
|
||||
}
|
||||
|
||||
private fun rebuildPositionsContent(container: LinearLayout, positions: List<PositionData>) {
|
||||
private fun rebuildPositionsContent(container: LinearLayout, positions: List<PositionData>, preserveScrollX: Int = 0) {
|
||||
container.removeAllViews()
|
||||
assetsBindings?.positions?.clear()
|
||||
assetsBindings?.positionsScroller = null
|
||||
assetsBindings?.positionsList = null
|
||||
if (positions.isEmpty()) {
|
||||
container.addView(text("Открытых позиций нет", 13f, Typeface.NORMAL, palette.muted))
|
||||
@@ -852,7 +854,11 @@ class MainActivity : Activity() {
|
||||
isHorizontalScrollBarEnabled = false
|
||||
overScrollMode = View.OVER_SCROLL_NEVER
|
||||
addView(list, ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
if (preserveScrollX > 0) {
|
||||
post { scrollTo(preserveScrollX, 0) }
|
||||
}
|
||||
}
|
||||
assetsBindings?.positionsScroller = scroller
|
||||
container.addView(scroller)
|
||||
}
|
||||
|
||||
@@ -1533,7 +1539,7 @@ class MainActivity : Activity() {
|
||||
}
|
||||
|
||||
private fun positionsSignature(positions: List<PositionData>): String =
|
||||
positions.joinToString("|") { positionKey(it) }
|
||||
positions.map { positionKey(it) }.sorted().joinToString("|")
|
||||
|
||||
private fun positionKey(position: PositionData): String =
|
||||
when {
|
||||
|
||||
Reference in New Issue
Block a user