Skip to content

Commit df4ad24

Browse files
K2GO-383 refactor(ui): feed the Details log from the progress tick (review)
The service already polls /rebuild/log each tick for progress; carry the log tail on the same ACTION_PROGRESS broadcast and render the Details panel from it, dropping the fragment's second /rebuild/log poll loop. Also fix two stale comments (status columns are centered; percentAndEta is the notification caption, the card builds two columns from of()).
1 parent 47b62f5 commit df4ad24

3 files changed

Lines changed: 18 additions & 33 deletions

File tree

‎controller/app/src/main/java/org/appdevforall/k2go/install/presentation/EtaText.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ public static String of(Context ctx, long etaSeconds) {
2424
}
2525
}
2626

27-
/** K2GO-383: the shared progress caption, "NN%" or "NN% ~N min left" (the eta is appended only when
28-
* known). {@code percent} must be >= 0; the caller owns the indeterminate (percent < 0) case. One
29-
* place so the rebuild notification and the card caption never drift. */
27+
/** K2GO-383: the one-line progress caption, "NN%" or "NN% ~N min left" (the eta is appended only when
28+
* known). {@code percent} must be >= 0; the caller owns the indeterminate (percent < 0) case. Used
29+
* by the rebuild notification, which needs the percent and eta in a single string; the in-app card
30+
* renders them as two columns instead, built from {@link #of} plus its own "NN%". */
3031
public static String percentAndEta(Context ctx, int percent, long etaSeconds) {
3132
String eta = of(ctx, etaSeconds);
3233
return eta.isEmpty() ? percent + "%" : percent + "% " + eta;

‎controller/app/src/main/java/org/appdevforall/k2go/redesign/DashboardDetailFragment.java‎

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,14 @@ public class DashboardDetailFragment extends Fragment {
5454
// ADFA-5339 / K2GO-374: expandable Details — the live rebuild log via the shared LiveLogPanel. The
5555
// toggle stays hidden until there are lines (an older box without /rebuild/log shows no Details).
5656
private org.appdevforall.k2go.widget.LiveLogPanel logPanel;
57-
private static final long LOG_POLL_MS = 1500L;
58-
private final Runnable logPoll = this::pollLog;
5957
// K2GO-95 / K2GO-383: the determinate in-progress bar + its "NN% ~N min left" caption. The values
6058
// come from DashboardRebuildService (the persistent owner, which outlives this card's recreation) via
6159
// its ACTION_PROGRESS broadcast, so the bar resumes where the rebuild actually is after minimize /
6260
// restore instead of restarting from 0.
6361
private LinearProgressIndicator progressBar;
64-
// K2GO-383: the status line under the label is two fixed columns: the percent anchored left, the ETA
65-
// anchored right (space-between). Each has its own anchor, so a width change in one never shifts the
66-
// other. Style matches the content updaters' status line (BodySmall, muted, single line).
62+
// K2GO-383: the status line under the label is two equal-weight columns, the percent and the ETA each
63+
// centered in its own half. Separate columns, so a width change in one never reaches the other. Style
64+
// matches the content updaters' status line (BodySmall, muted, single line).
6765
private TextView updatingPercent;
6866
private TextView updatingEta;
6967

@@ -77,6 +75,10 @@ public class DashboardDetailFragment extends Fragment {
7775
if (DashboardRebuildService.ACTION_PROGRESS.equals(i.getAction())) {
7876
onProgress(i.getIntExtra(DashboardRebuildService.EXTRA_PERCENT, -1),
7977
i.getLongExtra(DashboardRebuildService.EXTRA_ETA_SECONDS, -1L));
78+
// K2GO-383: the same tick carries the log tail; feed the Details panel from it instead of
79+
// a second /rebuild/log poll. reveal + auto-scroll are handled inside setContent.
80+
String log = i.getStringExtra(DashboardRebuildService.EXTRA_LOG);
81+
if (updating && logPanel != null && log != null) logPanel.setContent(log);
8082
return;
8183
}
8284
String state = i.getStringExtra(DashboardRebuildService.EXTRA_STATE);
@@ -388,39 +390,17 @@ private void setUpdating(boolean on) {
388390
if (updatingCancel != null) updatingCancel.setEnabled(on); // re-enable when a new update shows
389391
if (rebuild != null) { rebuild.setEnabled(!on); rebuild.setAlpha(on ? 0.5f : 1f); }
390392
if (on && rebuildHint != null) rebuildHint.setVisibility(View.GONE);
391-
// ADFA-5339: the Details log only exists while a rebuild runs. Poll it on, tear it down on off.
392-
main.removeCallbacks(logPoll);
393393
if (on) {
394394
// K2GO-383: start indeterminate with the plain label; the service's ACTION_PROGRESS then
395-
// drives the bar + the "NN% ~N min left" caption. pollLog only feeds the Details panel now.
395+
// drives the bar, the "NN% ~N min left" caption, and (same tick) the Details panel.
396396
if (progressBar != null) progressBar.setIndeterminate(true);
397397
if (updatingPercent != null) updatingPercent.setText(""); // filled by the first progress tick
398398
if (updatingEta != null) updatingEta.setText("");
399399
if (logPanel != null) logPanel.reset(); // K2GO-374: start clean; toggle hidden until lines
400-
main.post(logPoll);
401400
}
402401
// On "off" the whole updatingRow is hidden above, which takes the panel with it.
403402
}
404403

405-
/** ADFA-5339: poll the rebuild log tail while updating. Fork B — the toggle appears only once there
406-
* are lines, so an older box without the endpoint (empty) shows no Details affordance. Reschedules
407-
* itself while {@code updating}; setUpdating(false) and onDestroyView remove the callback. */
408-
private void pollLog() {
409-
if (!isAdded() || !updating) return;
410-
DashboardClient.rebuildLog(new DashboardClient.RebuildLogCb() {
411-
@Override public void onLines(java.util.List<String> lines) {
412-
if (!isAdded() || !updating) return;
413-
String log = android.text.TextUtils.join("\n", lines);
414-
if (logPanel != null) logPanel.setContent(log); // K2GO-374: reveal + auto-scroll handled here
415-
main.postDelayed(logPoll, LOG_POLL_MS);
416-
}
417-
@Override public void onErr(String message) {
418-
// No endpoint / transient: keep the panel as-is (toggle hidden if never populated) and retry.
419-
if (isAdded() && updating) main.postDelayed(logPoll, LOG_POLL_MS);
420-
}
421-
});
422-
}
423-
424404
/** K2GO-383: apply a progress tick from DashboardRebuildService (the persistent owner, so the value
425405
* survives this card's recreation). A negative percent means "no phase marker yet" -> indeterminate;
426406
* otherwise set the determinate bar and the two status columns: "NN%" left, the ETA right (eta via
@@ -440,7 +420,7 @@ private void onProgress(int percent, long etaSeconds) {
440420
}
441421

442422
@Override public void onDestroyView() {
443-
main.removeCallbacks(logPoll); // ADFA-5339: never poll past the view's life
423+
main.removeCallbacksAndMessages(null); // ADFA-5339: drop any pending posts past the view's life
444424
super.onDestroyView();
445425
}
446426

‎controller/app/src/main/java/org/appdevforall/k2go/redesign/DashboardRebuildService.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public final class DashboardRebuildService extends Service {
7373
public static final String ACTION_PROGRESS = "org.iiab.controller.DASHBOARD_UPDATE_PROGRESS";
7474
public static final String EXTRA_PERCENT = "percent";
7575
public static final String EXTRA_ETA_SECONDS = "eta_seconds";
76+
/** K2GO-383: the rebuild log tail, carried on the same tick so a visible card feeds its Details panel
77+
* from this one poll instead of running a second /rebuild/log loop of its own. */
78+
public static final String EXTRA_LOG = "log";
7679

7780
private static final long POLL_MS = 2500L;
7881
/**
@@ -241,7 +244,8 @@ private void publishProgress(String log) {
241244
NotificationManager m = getSystemService(NotificationManager.class);
242245
if (m != null) m.notify(NOTIFICATION_ID, buildOngoing());
243246
sendBroadcast(new Intent(ACTION_PROGRESS).setPackage(getPackageName())
244-
.putExtra(EXTRA_PERCENT, lastPercent).putExtra(EXTRA_ETA_SECONDS, lastEtaSeconds));
247+
.putExtra(EXTRA_PERCENT, lastPercent).putExtra(EXTRA_ETA_SECONDS, lastEtaSeconds)
248+
.putExtra(EXTRA_LOG, log)); // same poll feeds the card's Details panel
245249
}
246250

247251
private void schedule() {

0 commit comments

Comments
 (0)