Skip to content

Commit bed2832

Browse files
Merge pull request #618 from appdevforall/feat/K2GO-441-addons-incremental-refresh
K2GO-441 feat(addons): catalog-driven incremental refresh with an "up to date" report
2 parents 0671494 + e4e0241 commit bed2832

43 files changed

Lines changed: 294 additions & 78 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎controller/app/src/main/java/org/appdevforall/k2go/addons/data/AddonsRefreshClient.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Contract:
1515
* POST /k2go-api/addons/refresh -> 202 { state:"running" }
16-
* GET /k2go-api/addons/refresh/status -> { state, lines, downloaded, failed }
16+
* GET /k2go-api/addons/refresh/status -> { state, lines, downloaded, reused, failed, upToDate }
1717
* POST /k2go-api/addons/refresh/cancel -> { state:"cancelled" }
1818
* ============================================================================
1919
*/
@@ -58,12 +58,17 @@ public interface Listener {
5858

5959
/** The last status-tail line handed to the listener, so a poll that did not advance stays quiet. */
6060
private String lastEmitted;
61-
private int lastDownloaded = -1, lastFailed = -1;
61+
private int lastDownloaded = -1, lastReused = -1, lastFailed = -1;
62+
private boolean lastUpToDate = false;
6263

6364
/** Files downloaded in the last refresh; -1 if the box did not report it. */
6465
public int lastDownloaded() { return lastDownloaded; }
66+
/** Files reused unchanged in the last refresh; -1 if the box did not report it (K2GO-441). */
67+
public int lastReused() { return lastReused; }
6568
/** Files the last refresh could not fetch or verify; -1 if the box did not report it. */
6669
public int lastFailed() { return lastFailed; }
70+
/** K2GO-441: true when the published set was unchanged, so the refresh downloaded nothing. */
71+
public boolean lastUpToDate() { return lastUpToDate; }
6772

6873
/**
6974
* Start the refresh if it is not already running, then poll to a terminal state. Each refresh is
@@ -127,7 +132,9 @@ private String readState(@Nullable Listener l) {
127132
if (!ok) return null;
128133
JSONObject j = new JSONObject(text.isEmpty() ? "{}" : text);
129134
if (j.has("downloaded")) lastDownloaded = j.optInt("downloaded", lastDownloaded);
135+
if (j.has("reused")) lastReused = j.optInt("reused", lastReused);
130136
if (j.has("failed")) lastFailed = j.optInt("failed", lastFailed);
137+
if (j.has("upToDate")) lastUpToDate = j.optBoolean("upToDate", lastUpToDate);
131138
if (l != null) {
132139
JSONArray lines = j.optJSONArray("lines");
133140
if (lines != null && lines.length() > 0) {

‎controller/app/src/main/java/org/appdevforall/k2go/addons/presentation/AddonsRefresh.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,24 @@ private static void run(@NonNull View trigger) {
128128
main.post(() -> { if (liveLine.isAttachedToWindow()) liveLine.setText(shown); });
129129
});
130130
final int failed = client.lastFailed();
131+
final boolean upToDate = client.lastUpToDate();
131132
main.post(() -> {
132133
if (!trigger.isAttachedToWindow()) return;
133134
parent.removeView(progress);
134135
trigger.setEnabled(true);
135-
Snackbars.make(trigger, ctx.getString(messageFor(r, failed))).show();
136+
Snackbars.make(trigger, ctx.getString(messageFor(r, failed, upToDate))).show();
136137
});
137138
});
138139
}
139140

140141
/** Map the refresh outcome to a user message covering every state. */
141-
private static int messageFor(AddonsRefreshClient.Result r, int failed) {
142+
private static int messageFor(AddonsRefreshClient.Result r, int failed, boolean upToDate) {
142143
if (r == AddonsRefreshClient.Result.CANCELLED) return R.string.k2go_code_addons_update_cancelled;
143144
if (r != AddonsRefreshClient.Result.DONE) return R.string.k2go_code_addons_update_failed; // box unreachable
144145
if (failed > 0) return R.string.k2go_code_addons_update_some_failed; // some files could not be fetched
146+
// K2GO-441: the box is the single source for "nothing changed" (result: up-to-date). A box that
147+
// does not report it (pre-1.3.9) ran the old full mirror, so "updated" is the correct default.
148+
if (upToDate) return R.string.k2go_code_addons_update_none;
145149
return R.string.k2go_code_addons_update_done;
146150
}
147151
}

‎controller/app/src/main/res/values-ar/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,7 @@
13831383
<string name="k2go_code_addons_update_cancelling">جارٍ الإلغاء...</string>
13841384
<string name="k2go_code_addons_update_cancelled">تم إلغاء تحديث الإضافات</string>
13851385
<string name="k2go_code_addons_update_done">تم تحديث الإضافات</string>
1386+
<string name="k2go_code_addons_update_none">الإضافات محدَّثة بالفعل</string>
13861387
<string name="k2go_code_addons_update_failed">تعذّر تحديث الإضافات</string>
13871388
<string name="k2go_code_addons_update_some_failed">تعذّر تحديث بعض الإضافات</string>
13881389
</resources>

‎controller/app/src/main/res/values-az/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,7 @@
14031403
<string name="k2go_code_addons_update_cancelling">Ləğv edilir...</string>
14041404
<string name="k2go_code_addons_update_cancelled">Əlavələrin yenilənməsi ləğv edildi</string>
14051405
<string name="k2go_code_addons_update_done">Əlavələr yeniləndi</string>
1406+
<string name="k2go_code_addons_update_none">Əlavələr artıq günceldir</string>
14061407
<string name="k2go_code_addons_update_failed">Əlavələri yeniləmək mümkün olmadı</string>
14071408
<string name="k2go_code_addons_update_some_failed">Bəzi əlavələri yeniləmək mümkün olmadı</string>
14081409
</resources>

‎controller/app/src/main/res/values-bg/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,7 @@
13901390
<string name="k2go_code_addons_update_cancelling">Отказване...</string>
13911391
<string name="k2go_code_addons_update_cancelled">Актуализирането на добавките е отменено</string>
13921392
<string name="k2go_code_addons_update_done">Добавките са актуализирани</string>
1393+
<string name="k2go_code_addons_update_none">Добавките вече са актуални</string>
13931394
<string name="k2go_code_addons_update_failed">Добавките не могат да бъдат актуализирани</string>
13941395
<string name="k2go_code_addons_update_some_failed">Някои добавки не можаха да бъдат актуализирани</string>
13951396
</resources>

‎controller/app/src/main/res/values-bn/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,7 @@
13961396
<string name="k2go_code_addons_update_cancelling">বাতিল করা হচ্ছে...</string>
13971397
<string name="k2go_code_addons_update_cancelled">অ্যাড-অন আপডেট বাতিল করা হয়েছে</string>
13981398
<string name="k2go_code_addons_update_done">অ্যাড-অন আপডেট করা হয়েছে</string>
1399+
<string name="k2go_code_addons_update_none">অ্যাড-অনগুলি ইতিমধ্যে হালনাগাদ</string>
13991400
<string name="k2go_code_addons_update_failed">অ্যাড-অন আপডেট করা যায়নি</string>
14001401
<string name="k2go_code_addons_update_some_failed">কিছু অ্যাড-অন আপডেট করা যায়নি</string>
14011402
</resources>

‎controller/app/src/main/res/values-cs/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,7 @@
13901390
<string name="k2go_code_addons_update_cancelling">Rušení...</string>
13911391
<string name="k2go_code_addons_update_cancelled">Aktualizace doplňků zrušena</string>
13921392
<string name="k2go_code_addons_update_done">Doplňky aktualizovány</string>
1393+
<string name="k2go_code_addons_update_none">Doplňky jsou již aktuální</string>
13931394
<string name="k2go_code_addons_update_failed">Doplňky se nepodařilo aktualizovat</string>
13941395
<string name="k2go_code_addons_update_some_failed">Některé doplňky se nepodařilo aktualizovat</string>
13951396
</resources>

‎controller/app/src/main/res/values-de/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,7 @@
13831383
<string name="k2go_code_addons_update_cancelling">Wird abgebrochen...</string>
13841384
<string name="k2go_code_addons_update_cancelled">Add-on-Aktualisierung abgebrochen</string>
13851385
<string name="k2go_code_addons_update_done">Add-ons aktualisiert</string>
1386+
<string name="k2go_code_addons_update_none">Add-ons sind bereits aktuell</string>
13861387
<string name="k2go_code_addons_update_failed">Add-ons konnten nicht aktualisiert werden</string>
13871388
<string name="k2go_code_addons_update_some_failed">Einige Add-ons konnten nicht aktualisiert werden</string>
13881389
</resources>

‎controller/app/src/main/res/values-el/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,7 @@
13901390
<string name="k2go_code_addons_update_cancelling">Ακύρωση...</string>
13911391
<string name="k2go_code_addons_update_cancelled">Η ενημέρωση προσθέτων ακυρώθηκε</string>
13921392
<string name="k2go_code_addons_update_done">Τα πρόσθετα ενημερώθηκαν</string>
1393+
<string name="k2go_code_addons_update_none">Τα πρόσθετα είναι ήδη ενημερωμένα</string>
13931394
<string name="k2go_code_addons_update_failed">Δεν ήταν δυνατή η ενημέρωση των προσθέτων</string>
13941395
<string name="k2go_code_addons_update_some_failed">Ορισμένα πρόσθετα δεν ήταν δυνατό να ενημερωθούν</string>
13951396
</resources>

‎controller/app/src/main/res/values-es/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,7 @@
14591459
<string name="k2go_code_addons_update_cancelling">Cancelando...</string>
14601460
<string name="k2go_code_addons_update_cancelled">Actualización de complementos cancelada</string>
14611461
<string name="k2go_code_addons_update_done">Complementos actualizados</string>
1462+
<string name="k2go_code_addons_update_none">Complementos ya actualizados</string>
14621463
<string name="k2go_code_addons_update_failed">No se pudieron actualizar los complementos</string>
14631464
<string name="k2go_code_addons_update_some_failed">Algunos complementos no se pudieron actualizar</string>
14641465
</resources>

0 commit comments

Comments
 (0)