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