Skip to content

Commit 45ac397

Browse files
author
NexDrop Agent
committed
feat(android): v1.4 slice B — truthful transfer notifications, live speed graph, premium completion card
Phase 3 — TransferService: progress notification with real percentage, transferred/total, current speed, ETA; PAUSE/RESUME + CANCEL actions bound to the LIVE engine via engineControl (registered only for the in-flight transfer); SHA-verified completion and real-failure notifications on separate auto-cancel IDs; POST_NOTIFICATIONS denied => transfer unaffected. Phase 4 — SpeedGraphView: live graph fed ONLY by real delta-bytes/delta-time samples from onProgress; <=4 Hz graph, <=1 Hz notification so UI never competes with the NDT1 transport; paused shows zero, never synthetic data. Phase 5 — completion card: peak (sustained) + real route (discovery names, honest fallback), SHARE SUMMARY (real values from this transfer) and VIEW HISTORY actions; DONE/OPEN FILE unchanged. Fix: NEARBY DEVICES section moved below the primary CONTINUE action — it had pushed CONTINUE off-screen on small devices (smoke caught it); Send layout above CONTINUE is byte-identical to v1.3.0.
1 parent fd990af commit 45ac397

3 files changed

Lines changed: 364 additions & 95 deletions

File tree

‎android/app/src/main/java/com/nexdrop/ndt1/MainActivity.kt‎

Lines changed: 173 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import com.nexdrop.ndt1.ui.GradientTextView
4545
import com.nexdrop.ndt1.ui.HeroView
4646
import com.nexdrop.ndt1.ui.PulseDotView
4747
import com.nexdrop.ndt1.ui.RingView
48+
import com.nexdrop.ndt1.ui.SpeedGraphView
4849
import com.nexdrop.ndt1.ui.UiSpeed
4950
import com.nexdrop.ndt1.ui.bigText
5051
import com.nexdrop.ndt1.ui.body
@@ -373,6 +374,12 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
373374
private var etaView: TextView? = null
374375
private var overallView: TextView? = null
375376
private var pauseBtn: View? = null
377+
private var speedGraph: SpeedGraphView? = null
378+
// real-sample throttle: graph <=4 Hz, notification <=1 Hz (never competes
379+
// with the NDT1 transport for CPU; values stay REAL, just cadence-limited)
380+
private var lastGraphSampleMs = 0L
381+
private var lastGraphDurable = -1L
382+
private var lastNotifMs = 0L
376383

377384
// ---- activity result contracts (unchanged engine flow) ----
378385
private val scanQr = registerForActivityResult(ScanContract()) { result ->
@@ -474,7 +481,7 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
474481

475482
private fun render() {
476483
ticker?.let { ui.removeCallbacks(it); ticker = null }
477-
qrView = null; ring = null; ringPct = null; ringBytes = null; speedView = null; speedUnitView = null; etaView = null; pauseBtn = null
484+
qrView = null; ring = null; ringPct = null; ringBytes = null; speedView = null; speedUnitView = null; etaView = null; pauseBtn = null; speedGraph = null
478485
pendingNav = null
479486
root = FrameLayout(this)
480487
root.addView(BgView(this), FrameLayout.LayoutParams(
@@ -855,48 +862,6 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
855862
}
856863
content.addView(chips)
857864

858-
// NEARBY DEVICES (v1.4): real NDD1 discovery — receivers running on this
859-
// network appear here automatically. No peers = honest empty state, and
860-
// QR pairing always remains. No radar rings: Android exposes no honest
861-
// distance for arbitrary peers, so none is implied.
862-
content.addView(sm("NEARBY DEVICES").apply {
863-
setTextColor(D.MUTED); letterSpacing = 0.10f
864-
layoutParams = (layoutParams as LinearLayout.LayoutParams).apply { topMargin = dp(16); bottomMargin = dp(6) }
865-
})
866-
val nearby = pairablePeers()
867-
content.addView(glassCard(pad = 12f).apply {
868-
if (nearby.isEmpty()) {
869-
if (beaconIdentity == null && beaconSession == null) {
870-
addView(textView("Discovery unavailable", 13f, D.TEXT, 700).apply { setPadding(0, 0, 0, dp(2)) })
871-
addView(sm("Another local socket holds the discovery port, or multicast is blocked. Scan the receiver's QR instead — pairing is identical."))
872-
} else {
873-
addView(textView("No NexDrop receivers found", 13f, D.TEXT, 700).apply { setPadding(0, 0, 0, dp(2)) })
874-
addView(sm("A device on this network shows up here when it opens the Receive screen. QR pairing always works too."))
875-
}
876-
} else {
877-
nearby.forEach { p ->
878-
val dev = p.dev
879-
val r = row().apply { setOnClickListener { pairFromDiscovery(p) } }
880-
r.addView(icBox(R.drawable.ic_dev).apply {
881-
background = android.graphics.drawable.GradientDrawable().apply {
882-
cornerRadius = dp(13).toFloat(); setColor(D.argb(31, D.PRIMARY)); setStroke(dp(1), D.argb(51, D.PRIMARY))
883-
}
884-
})
885-
r.addView(Space(this@MainActivity).apply { layoutParams = LinearLayout.LayoutParams(dp(10), 1) })
886-
val t = col().apply { layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT).apply { weight = 1f } }
887-
t.addView(textView(if (isTrusted(dev.deviceId)) "${dev.deviceName} · trusted" else dev.deviceName, 13f, D.TEXT, 700))
888-
t.addView(sm("${dev.address} · ready to receive"))
889-
r.addView(t)
890-
r.addView(pill(if (isTrusted(dev.deviceId)) "TRUSTED" else "LOCAL"))
891-
addView(r)
892-
addView(Space(this@MainActivity).apply { layoutParams = LinearLayout.LayoutParams(1, dp(6)) })
893-
}
894-
addView(sm("Tap a device to send the ${if (sendQueue.isEmpty()) "queue" else "whole queue"} without scanning a QR.").apply {
895-
setPadding(0, dp(2), 0, 0)
896-
})
897-
}
898-
})
899-
900865
// SEND QUEUE (PRIORITY 1): real totals, per-item states, add/remove/reorder
901866
val queued = sendQueue.toList()
902867
content.addView(sm(if (queued.isEmpty()) "No files selected"
@@ -945,6 +910,48 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
945910

946911
// fill + SEND ALL
947912
content.addView(Space(this).apply { layoutParams = LinearLayout.LayoutParams(1, 0).apply { weight = 1f } })
913+
// NEARBY DEVICES (v1.4): real NDD1 discovery — receivers running on this
914+
// network appear here automatically. No peers = honest empty state, and
915+
// QR pairing always remains. No radar rings: Android exposes no honest
916+
// distance for arbitrary peers, so none is implied.
917+
content.addView(sm("NEARBY DEVICES").apply {
918+
setTextColor(D.MUTED); letterSpacing = 0.10f
919+
layoutParams = (layoutParams as LinearLayout.LayoutParams).apply { topMargin = dp(16); bottomMargin = dp(6) }
920+
})
921+
val nearby = pairablePeers()
922+
content.addView(glassCard(pad = 12f).apply {
923+
if (nearby.isEmpty()) {
924+
if (beaconIdentity == null && beaconSession == null) {
925+
addView(textView("Discovery unavailable", 13f, D.TEXT, 700).apply { setPadding(0, 0, 0, dp(2)) })
926+
addView(sm("Another local socket holds the discovery port, or multicast is blocked. Scan the receiver's QR instead — pairing is identical."))
927+
} else {
928+
addView(textView("No NexDrop receivers found", 13f, D.TEXT, 700).apply { setPadding(0, 0, 0, dp(2)) })
929+
addView(sm("A device on this network shows up here when it opens the Receive screen. QR pairing always works too."))
930+
}
931+
} else {
932+
nearby.forEach { p ->
933+
val dev = p.dev
934+
val r = row().apply { setOnClickListener { pairFromDiscovery(p) } }
935+
r.addView(icBox(R.drawable.ic_dev).apply {
936+
background = android.graphics.drawable.GradientDrawable().apply {
937+
cornerRadius = dp(13).toFloat(); setColor(D.argb(31, D.PRIMARY)); setStroke(dp(1), D.argb(51, D.PRIMARY))
938+
}
939+
})
940+
r.addView(Space(this@MainActivity).apply { layoutParams = LinearLayout.LayoutParams(dp(10), 1) })
941+
val t = col().apply { layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT).apply { weight = 1f } }
942+
t.addView(textView(if (isTrusted(dev.deviceId)) "${dev.deviceName} · trusted" else dev.deviceName, 13f, D.TEXT, 700))
943+
t.addView(sm("${dev.address} · ready to receive"))
944+
r.addView(t)
945+
r.addView(pill(if (isTrusted(dev.deviceId)) "TRUSTED" else "LOCAL"))
946+
addView(r)
947+
addView(Space(this@MainActivity).apply { layoutParams = LinearLayout.LayoutParams(1, dp(6)) })
948+
}
949+
addView(sm("Tap a device to send the ${if (sendQueue.isEmpty()) "queue" else "whole queue"} without scanning a QR.").apply {
950+
setPadding(0, dp(2), 0, 0)
951+
})
952+
}
953+
})
954+
948955
content.addView(btn(if (sendQueue.size > 1) "SEND ALL (${sendQueue.size})" else "CONTINUE", "primary") {
949956
if (sendQueue.isEmpty()) { toast("Select a file first"); return@btn }
950957
if (!hasPermission(Manifest.permission.CAMERA)) { askPermission(Manifest.permission.CAMERA, REQ_CAMERA); return@btn }
@@ -1282,6 +1289,19 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
12821289
speedCol.addView(etaView)
12831290
content.addView(speedCol)
12841291

1292+
// LIVE SPEED GRAPH (Phase 4): real measured samples only, <=4 Hz,
1293+
// drawn off the transfer path (postInvalidate + animation cadence).
1294+
content.addView(glassCard(pad = 10f).apply {
1295+
layoutParams = (layoutParams as LinearLayout.LayoutParams).apply { topMargin = dp(12) }
1296+
addView(sm("SPEED — LIVE SAMPLES").apply {
1297+
setTextColor(D.MUTED); letterSpacing = 0.10f
1298+
})
1299+
addView(SpeedGraphView(this@MainActivity).apply {
1300+
layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, dp(72))
1301+
contentDescription = "Live transfer speed graph from real measured samples"
1302+
}.also { speedGraph = it })
1303+
})
1304+
12851305
// device-to-device dashed link
12861306
content.addView(glassCard(pad = 10f).apply {
12871307
layoutParams = (layoutParams as LinearLayout.LayoutParams).apply {
@@ -1343,20 +1363,7 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
13431363
render() // relabel PAUSE/RESUME from real state; ring refs rebind, engine untouched
13441364
}.also { pauseBtn = it })
13451365
controls.addView(Space(this).apply { layoutParams = LinearLayout.LayoutParams(dp(10), 1) })
1346-
controls.addView(btn("CANCEL", "outline", icon = R.drawable.ic_x, tintText = D.DANGER) {
1347-
receiver?.cancel(); sender?.cancel()
1348-
// Queue: only the in-flight file is cancelled; Done stays done, the
1349-
// rest stay Ready — the user returns to the queue, not a dead end.
1350-
if (role == Role.SEND) {
1351-
sendQueue.getOrNull(queueIndex)?.let { if (it.state == "Sending") it.state = "Ready" }
1352-
activePairing = null
1353-
}
1354-
hideTransferUi()
1355-
TransferService.stop(this)
1356-
toast("Transfer cancelled")
1357-
if (role == Role.SEND && sendQueue.isNotEmpty()) { screen = Screen.SEND; render() }
1358-
else { screen = Screen.HOME; render() }
1359-
})
1366+
controls.addView(btn("CANCEL", "outline", icon = R.drawable.ic_x, tintText = D.DANGER) { cancelTransfer() })
13601367
content.addView(controls)
13611368
}
13621369

@@ -1404,6 +1411,27 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
14041411
})
14051412
content.addView(statRow)
14061413

1414+
// PEAK (Phase 5): the engine's measured sustained peak — never a burst.
1415+
val peakRow = row().apply { bottomMargin = dp(8) }
1416+
peakRow.addView(glassCard(pad = 14f).apply {
1417+
layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT).apply { weight = 1f }
1418+
addView(sm("Peak (sustained)"))
1419+
addView(bigText(UiSpeed.speedText(stats?.peakSustainedBps), 18f).apply { setPadding(0, dp(3), 0, 0) })
1420+
})
1421+
// Real device names where discovery provided them; honest fallback.
1422+
val peerName = peerIdentity()?.deviceName
1423+
val route = when {
1424+
role == Role.SEND && !peerName.isNullOrEmpty() -> "This device → $peerName"
1425+
role == Role.RECEIVE && !peerName.isNullOrEmpty() -> "$peerName → This device"
1426+
else -> "Android → Android"
1427+
}
1428+
peakRow.addView(glassCard(pad = 14f).apply {
1429+
layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT).apply { weight = 1f; marginStart = dp(5) }
1430+
addView(sm("Route"))
1431+
addView(bigText(route, 13f).apply { setPadding(0, dp(5), 0, 0) })
1432+
})
1433+
content.addView(peakRow)
1434+
14071435
// verified card — real transport + verification facts
14081436
content.addView(glassCard(pad = 12f).apply {
14091437
fun infoRow(icon: Int, main: TextView, subView: TextView): View {
@@ -1431,7 +1459,7 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
14311459
textView("LOCAL DIRECT · Native NDT1 TCP", 12.5f, D.MUTED, 600), sm("")))
14321460
})
14331461

1434-
// buttons
1462+
// buttons — Open/Done stay; Share summary + View history added (Phase 5)
14351463
content.addView(Space(this).apply { layoutParams = LinearLayout.LayoutParams(1, 0).apply { weight = 1f } })
14361464
val btns = row()
14371465
val f = currentFile
@@ -1440,6 +1468,16 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
14401468
btns.addView(Space(this).apply { layoutParams = LinearLayout.LayoutParams(dp(10), 1) })
14411469
btns.addView(btn("DONE", "primary") { goRoot(Screen.HOME) })
14421470
content.addView(btns)
1471+
content.addView(row().apply {
1472+
setPadding(0, dp(8), 0, 0)
1473+
addView(btn("SHARE SUMMARY", "outline", height = 44, weight = 1f) { shareSummary() }.apply {
1474+
layoutParams = LinearLayout.LayoutParams(0, dp(44)).apply { weight = 1f }
1475+
})
1476+
addView(Space(this@MainActivity).apply { layoutParams = LinearLayout.LayoutParams(dp(10), 1) })
1477+
addView(btn("VIEW HISTORY", "outline", height = 44, weight = 1f) { go(Screen.HISTORY) }.apply {
1478+
layoutParams = LinearLayout.LayoutParams(0, dp(44)).apply { weight = 1f }
1479+
})
1480+
})
14431481
content.addView(btn(if (role == Role.SEND) "KEEP SENDING" else "KEEP RECEIVING", "text", height = 36) {
14441482
screen = if (role == Role.SEND) Screen.SEND else { startReceiving(); return@btn }
14451483
render()
@@ -1888,8 +1926,14 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
18881926
if (idx < 0) { // whole queue verified-complete
18891927
runOnUiThread {
18901928
hideTransferUi()
1891-
TransferService.stop(this)
1929+
val done = sendQueue.filter { it.state == "Done" }
1930+
val bytes = done.sumOf { it.size }
1931+
val summary = if (done.size == 1)
1932+
"${done.first().name} · ${SpeedFormat.bytesText(bytes)}\n${UiSpeed.speedText(completedStats?.averageBps)} · ${UiSpeed.durationText(completedStats?.durationMs ?: 0)} · SHA-256 VERIFIED"
1933+
else
1934+
"${done.size} files · ${SpeedFormat.bytesText(bytes)}\nAll SHA-256 VERIFIED"
18921935
backStack.clear(); screen = Screen.RESULT; render()
1936+
TransferService.complete(this, summary)
18931937
}
18941938
return
18951939
}
@@ -1980,12 +2024,29 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
19802024
failedMessage = message
19812025
backStack.clear(); screen = Screen.FAILED
19822026
render()
1983-
TransferService.stop(this)
2027+
TransferService.fail(this, currentName?.let { "$it — ${message.lineSequence().firstOrNull()?.take(100) ?: "failed"}" }
2028+
?: (message.lineSequence().firstOrNull()?.take(120) ?: "failed"))
19842029
}
19852030

19862031
@Volatile private var failedMessage: String? = null
19872032

1988-
private fun hideTransferUi() { sender = null; receiver = null; setTransferActive(false) }
2033+
private fun hideTransferUi() { sender = null; receiver = null; TransferService.engineControl = null; setTransferActive(false) }
2034+
2035+
/** ONE cancel path: on-screen button and notification action both land here. */
2036+
private fun cancelTransfer() {
2037+
receiver?.cancel(); sender?.cancel()
2038+
// Queue: only the in-flight file is cancelled; Done stays done, the
2039+
// rest stay Ready — the user returns to the queue, not a dead end.
2040+
if (role == Role.SEND) {
2041+
sendQueue.getOrNull(queueIndex)?.let { if (it.state == "Sending") it.state = "Ready" }
2042+
activePairing = null
2043+
}
2044+
hideTransferUi()
2045+
TransferService.stop(this)
2046+
toast("Transfer cancelled")
2047+
if (role == Role.SEND && sendQueue.isNotEmpty()) { screen = Screen.SEND; render() }
2048+
else { screen = Screen.HOME; render() }
2049+
}
19892050

19902051
private fun setTransferActive(on: Boolean) {
19912052
transferActive = on
@@ -1997,6 +2058,17 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
19972058
transferStartNanos = System.nanoTime()
19982059
paused = false
19992060
transferGotFirstProgress = false
2061+
lastGraphSampleMs = 0; lastGraphDurable = -1; lastNotifMs = 0
2062+
// Notification actions control the LIVE engine only (Phase 3). The same
2063+
// semantics as the on-screen buttons: toggle pause, hard cancel.
2064+
TransferService.engineControl = { cmd ->
2065+
runOnUiThread {
2066+
when (cmd) {
2067+
"pause" -> { paused = !paused; if (paused) { receiver?.pause(); sender?.pause() } else { receiver?.resume(); sender?.resume() } }
2068+
"cancel" -> cancelTransfer()
2069+
}
2070+
}
2071+
}
20002072
backStack.clear(); screen = Screen.TRANSFER
20012073
render()
20022074
}
@@ -2028,8 +2100,22 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
20282100
val pos = maxOf(sendQueue.indexOfFirst { it.state == "Sending" }, 0)
20292101
overallView?.text = "File ${pos + 1} of ${sendQueue.size} — overall $opct%"
20302102
}
2031-
// Truthful foreground notification (same math as the JSON export)
2032-
currentName?.let { TransferService.notifyProgress(this, it, durable, total, bps) }
2103+
// LIVE GRAPH + NOTIFICATION (Phases 3/4): real delta-bytes/delta-time
2104+
// samples; graph <=4 Hz, notification <=1 Hz so UI never competes with
2105+
// the NDT1 transport. Nothing synthetic — paused time shows as zero.
2106+
val nowMs = System.currentTimeMillis()
2107+
if (nowMs - lastGraphSampleMs >= 250) {
2108+
if (lastGraphDurable >= 0 && lastGraphSampleMs > 0) {
2109+
val dtS = (nowMs - lastGraphSampleMs) / 1000.0
2110+
val sample = if (paused) 0.0 else (durable - lastGraphDurable) / dtS
2111+
if (sample >= 0) speedGraph?.add(sample)
2112+
}
2113+
lastGraphSampleMs = nowMs; lastGraphDurable = durable
2114+
}
2115+
if (nowMs - lastNotifMs >= 1000) {
2116+
lastNotifMs = nowMs
2117+
currentName?.let { TransferService.notifyProgress(this, it, durable, total, bps, paused, canControl = true) }
2118+
}
20332119
}
20342120
}
20352121

@@ -2096,7 +2182,9 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
20962182
recordHistory(file.name, stats.averageBps, stats.durationMs, sha256, verified = true)
20972183
backStack.clear(); screen = Screen.RESULT
20982184
render()
2099-
TransferService.stop(this)
2185+
TransferService.complete(this,
2186+
"${file.name} · ${SpeedFormat.bytesText(file.length())}\n" +
2187+
"${UiSpeed.speedText(stats.averageBps)} · ${UiSpeed.durationText(stats.durationMs)} · SHA-256 VERIFIED")
21002188
}
21012189
}
21022190

@@ -2190,6 +2278,27 @@ class MainActivity : AppCompatActivity(), TurboReceiver.Listener {
21902278
} catch (_: Exception) { toast("No app can share this file type") }
21912279
}
21922280

2281+
/** Shareable completion summary (Phase 5) — every value from THIS transfer. */
2282+
private fun shareSummary() {
2283+
val stats = completedStats
2284+
val text = buildString {
2285+
append("NexDrop — Transfer complete\n\n")
2286+
append(currentName ?: "file").append('\n')
2287+
append(SpeedFormat.bytesText(currentFile?.length() ?: currentSize)).append('\n')
2288+
append("Duration: ").append(UiSpeed.durationText(stats?.durationMs ?: 0)).append('\n')
2289+
append("Average: ").append(UiSpeed.speedText(stats?.averageBps)).append('\n')
2290+
append("Peak (sustained): ").append(UiSpeed.speedText(stats?.peakSustainedBps)).append('\n')
2291+
if (completedSha != null) append("SHA-256: VERIFIED\n")
2292+
append("Transport: LOCAL DIRECT · Native NDT1 TCP\n")
2293+
append("\nPRIVATE · DIRECT · FAST — no cloud, no accounts.")
2294+
}
2295+
try {
2296+
startActivity(Intent.createChooser(Intent(Intent.ACTION_SEND).apply {
2297+
type = "text/plain"; putExtra(Intent.EXTRA_TEXT, text)
2298+
}, "Share transfer summary"))
2299+
} catch (_: Exception) { toast("Sharing unavailable") }
2300+
}
2301+
21932302
private fun openFile(f: File) {
21942303
try {
21952304
val uri = FileProvider.getUriForFile(this, "$packageName.fileprovider", f)

0 commit comments

Comments
 (0)