Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,27 @@ private void render(KolibriTopicsUiState s) {
}
list.addView(nodeRow(rows.get(i), childAncestors));
}
// ADFA-5094: the offline bundle folds a folder's own loose resources into an
// aggregate rather than listing them, so show that as one informational line —
// this is also what keeps a loose-only level from rendering blank. The live
// sources list those leaves individually, so looseResourceCount is 0 and this
// is skipped.
TopicNode here = s.node();
if (here != null && here.looseResourceCount() > 0) {
if (!rows.isEmpty()) {
list.addView(hairline());
}
list.addView(looseRow(here));
}
}

count.setText(getString(R.string.k2go_zc_count_items, s.children().size()));
// ADFA-5094: count the rows the level actually shows — the child folders plus the one
// loose-aggregate line when present — so a loose-only level does not read "0 items".
int shown = s.children().size();
if (s.node() != null && s.node().looseResourceCount() > 0) {
shown++;
}
count.setText(getString(R.string.k2go_zc_count_items, shown));
updateStorage();
}

Expand Down Expand Up @@ -424,6 +442,26 @@ private String sizeLabel(TopicNode node) {
return "";
}

/**
* ADFA-5094: the offline summary of a folder's direct loose resources — the leaves the
* bundle folds away. Informational only: they have no ids to pick individually (picking
* the folder brings them), so no checkbox or chevron. Reuses the resource-count string so
* no new translation is needed; the size is language-neutral.
*/
private View looseRow(TopicNode node) {
String text = getString(R.string.k2go_kolibri_resources_fmt, node.looseResourceCount());
if (node.looseResourceBytes() > 0) {
text = text + " · " + ByteFormatter.toHuman(node.looseResourceBytes());
}
TextView t = new TextView(requireContext());
t.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodyMedium);
t.setText(text);
t.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_muted));
t.setPadding(px(12), px(10), px(12), px(10));
t.setMinimumHeight(px(36));
return t;
}

private View note(String text, int colorRes) {
TextView t = new TextView(requireContext());
t.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodySmall);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,14 @@ public List<TopicNode> children() {
return node == null ? Collections.<TopicNode>emptyList() : node.children();
}

/** True when the level arrived and genuinely has nothing under it. */
/**
* True when the level arrived and genuinely has nothing under it — no child folders and
* no loose resources folded in by the offline bundle (ADFA-5094). A level with only loose
* content is not empty: it renders the aggregate line, not the "empty" status.
*/
public boolean isEmpty() {
return !loading && !unavailable && (node == null || !node.hasChildren());
return !loading && !unavailable
&& (node == null || (!node.hasChildren() && node.looseResourceCount() == 0));
}

/** What to show as the screen's heading: the channel, or the topic drilled into. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.iiab.controller.kolibri.presentation;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.iiab.controller.kolibri.domain.TopicNode;
import org.junit.Test;

import java.util.Collections;

/**
* Unit tests for {@link KolibriTopicsUiState#isEmpty()} — the call that decides whether a
* level renders content or the "empty" status. The offline bundle folds a folder's loose
* leaves into an aggregate, so "no child folders" no longer means "nothing here" (ADFA-5094).
* Pure JVM, no Android.
*/
public class KolibriTopicsUiStateTest {

private static final String ROOT = "c150ea1d69495d37b5b0ac6f017e9bfb";
private static final String CHILD = "23a7dc9c73635cd2abbd3e8aab13c3ca";

private static KolibriTopicsUiState levelOf(TopicNode node) {
return KolibriTopicsUiState.level(node, "Folder",
Collections.<String>emptyList(), Collections.singletonList("Folder"));
}

@Test
public void aLevelWithOnlyLooseResourcesIsNotEmpty() {
// No sub-folders, but loose resources: must render the aggregate line, not "empty".
TopicNode loose = TopicNode.fromBundle(ROOT, "Folder", "topic", 100L, 3, 3, 100L, null);
assertFalse(levelOf(loose).isEmpty());
}

@Test
public void aLevelWithNeitherChildrenNorLooseIsEmpty() {
TopicNode bare = TopicNode.fromBundle(ROOT, "Folder", "topic", 0L, 0, 0, 0L, null);
assertTrue(levelOf(bare).isEmpty());
}

@Test
public void aLevelWithChildFoldersIsNotEmpty() {
TopicNode child = TopicNode.fromBundle(CHILD, "Sub", "topic", 0L, 0, 0, 0L, null);
TopicNode parent = TopicNode.fromBundle(ROOT, "Folder", "topic", 0L, 1, 0, 0L,
Collections.singletonList(child));
assertFalse(levelOf(parent).isEmpty());
}
}
Loading