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
2 changes: 2 additions & 0 deletions README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ avec sa propre clé. Une copie installée depuis F-Droid reçoit la 3.0.0 par F-
élément vide la termine.
- Épingler, favoris, couleurs, archives, corbeille (30 jours), ordre de tri, thème clair / sombre / système ;
la liste à l'ouverture, **Toutes les notes** ou la **Boîte de réception** (3.5.0).
- **Recherche** : celle de l'accueil parcourt les notes qui ne sont pas archivées ; les **Archives** ont la
leur, dans leurs seules notes (3.5.0, [#72](https://github.com/gitubpatrice/notes_tech/issues/72)).

### Coffres par dossier
- **Mode phrase secrète** — Argon2id (64 Mio, t = 3) et AES-256-GCM. La clé du coffre (32 octets
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ A copy installed from F-Droid receives the 3.0.0 through F-Droid.
Enter continues any list — a box, a bullet, the next number —; Enter on an empty item ends it.
- Pin, favourites, colours, archive, trash (30-day retention), sort order, light / dark / system theme;
the list the app opens on, **All notes** or the **Inbox** (3.5.0).
- **Search**: the home screen's looks through the notes that are not archived; the **Archive** has its own,
through its notes alone (3.5.0, [#72](https://github.com/gitubpatrice/notes_tech/issues/72)).

### Per-folder vaults
- **Passphrase mode** — Argon2id (64 MiB, t = 3) and AES-256-GCM. The vault key (32 random bytes) is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,26 @@ class LegacyDatabaseOpeningTest {
assertThat(db.noteSearchDao().search("reunion").first()).isEmpty()
}

/**
* D-051 (3.5.0, issue #72) : la recherche de la vue Archives trouve les notes archivées, et elles
* seules — le jumeau du test au-dessus. Et la garde du coffre y tient de même.
*/
@Test
fun la_recherche_des_archives_ne_trouve_que_les_notes_archivees(): Unit = runBlocking {
val db = openDatabase()
// Le témoin : pas encore archivée, la note est celle de l'accueil, pas des archives.
assertThat(db.noteSearchDao().search("reunion", archived = true).first()).isEmpty()

listOf(LegacyDatabaseFixture.Fixtures.NOTE_PLAIN, LegacyDatabaseFixture.Fixtures.NOTE_LOCKED).forEach {
db.noteWriteDao().updateFlags(id = it, updatedAt = 9_999L, archived = true)
}

assertThat(db.noteSearchDao().search("reunion", archived = true).first().map(NoteEntity::id))
.containsExactly(LegacyDatabaseFixture.Fixtures.NOTE_PLAIN)
assertThat(db.noteSearchDao().search(LegacyDatabaseFixture.Fixtures.LOCKED_TITLE, archived = true).first())
.isEmpty()
}

// ── 6. Refus sans destruction ────────────────────────────────────────────

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import java.time.ZoneOffset
* The rule itself — which of saved state and setting wins — is `DossierAuDemarrageTest`, on the JVM. This
* class checks that the view model applies it, and the control (the default) that it applies nothing
* else.
*
* Also D-051 (3.5.0, issue #72), on the same real view model and database: the archive's own search.
*/
@RunWith(AndroidJUnit4::class)
class AccueilAuDemarrageTest {
Expand Down Expand Up @@ -161,6 +163,56 @@ class AccueilAuDemarrageTest {
assertThat(sauvegarde.get<String>(HomeViewModel.CLE_DOSSIER)).isNull()
}

// ── D-051 (3.5.0, issue #72): the archive's own search ──────────────────────────────────────────────

/**
* In the archive, the search looks through the archived notes alone; on the home screen, through the
* others alone. Leaving the archive clears its search, rather than going on through the other notes.
*/
@Test
fun the_archive_searches_its_own_notes_and_leaving_it_clears_the_search(): Unit = runBlocking {
val plain = LegacyDatabaseFixture.Fixtures.NOTE_PLAIN
notes.setArchived(plain, true)
// A second archived note WITHOUT the word: the whole archive is two notes, its search one — so a list
// that ignored the search could not pass for it.
val autreArchivee = notes.create(folderId = Folder.INBOX_ID, title = "Liste de courses", content = "")
notes.setArchived(autreArchivee.id, true)
// And a note that is NOT archived, holding the word: what a search outside the archive would find.
val ordinaire = notes.create(folderId = Folder.INBOX_ID, title = "Réunion de rentrée", content = "")
val accueil = accueil(SavedStateHandle())

withContext(Dispatchers.Main) {
accueil.onArchiveSelected()
accueil.onQueryChange("reunion")
}
// Times out if the archive ignores the search (two notes) or searches outside it (the other note).
etatCharge(accueil) { it.archive && it.notes.map { n -> n.id } == listOf(plain) }

withContext(Dispatchers.Main) { accueil.onFolderSelected(null) }
assertThat(etatCharge(accueil) { !it.archive }.query).isEmpty()

withContext(Dispatchers.Main) { accueil.onQueryChange("reunion") }
etatCharge(accueil) { !it.archive && it.notes.map { n -> n.id } == listOf(ordinaire.id) }
}

/**
* Back from the archive returns to the list shown before it — here a folder (3.5.0; until then, Back left
* the app from the archive). All notes would be the wrong list: the test fails on it.
*/
@Test
fun back_from_the_archive_returns_to_the_folder_shown_before_it(): Unit = runBlocking {
val travail = LegacyDatabaseFixture.Fixtures.FOLDER_WORK
val accueil = accueil(SavedStateHandle())
withContext(Dispatchers.Main) { accueil.onFolderSelected(travail) }
etatCharge(accueil) { it.currentFolder?.id == travail }

withContext(Dispatchers.Main) { accueil.onArchiveSelected() }
etatCharge(accueil) { it.archive }
withContext(Dispatchers.Main) { accueil.quitterLArchive() }

etatCharge(accueil) { !it.archive && it.currentFolder?.id == travail }
}

private suspend fun accueil(sauvegarde: SavedStateHandle): HomeViewModel = withContext(Dispatchers.Main) {
HomeViewModel(
notes = notes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performSemanticsAction
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.performTouchInput
import androidx.test.espresso.Espresso
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.filestech.notes_tech.R
import com.filestech.notes_tech.domain.model.Folder
Expand Down Expand Up @@ -73,6 +74,7 @@ class AccueilTest {
private val trisChoisis = mutableListOf<NoteSortMode>()
private val requetes = mutableListOf<String>()
private val tiroirsOuverts = mutableListOf<Unit>()
private val sortiesDeLArchive = mutableListOf<Unit>()
private val recherchesOuvertes = mutableListOf<Unit>()
private val reglagesOuverts = mutableListOf<Unit>()

Expand Down Expand Up @@ -123,6 +125,7 @@ class AccueilTest {
),
onNewNote = { nouvellesNotesDemandees += Unit },
onOpenDrawer = { tiroirsOuverts += Unit },
onQuitterLArchive = { sortiesDeLArchive += Unit },
onOpenSearch = { recherchesOuvertes += Unit },
onOpenSettings = { reglagesOuverts += Unit },
onOpenAbout = {},
Expand Down Expand Up @@ -459,12 +462,16 @@ class AccueilTest {
assertThat(regle.actionnablesSansNom()).isEmpty()
}

/** In the archive's view (3.3.0): its title, no search field, no "New note", "Unarchive" in the bar. */
/**
* In the archive's view (3.3.0): its title, no "New note", "Unarchive" in the bar — and its OWN search
* field (D-051, 3.5.0, issue #72), which says it searches the archive, not the home screen's.
*/
@Test
fun the_archive_has_its_title_no_search_no_new_note_and_unarchives() {
fun the_archive_has_its_title_its_own_search_no_new_note_and_unarchives() {
poser(HomeUiState(notes = listOf(note("a", "Vieille")), loading = false, archive = true))

regle.onNode(hasText(texte(R.string.archive_title)) and isHeading()).assertExists()
regle.onNodeWithText(texte(R.string.home_search_archive_hint)).assertExists()
regle.onNodeWithText(texte(R.string.home_search_hint)).assertDoesNotExist()
regle.onNodeWithContentDescription(texte(R.string.home_new_note)).assertDoesNotExist()

Expand Down Expand Up @@ -506,6 +513,55 @@ class AccueilTest {
),
)
regle.onNodeWithText(enTete(11)).assertDoesNotExist()

// D-051: nor does a search of the archive — its results come by relevance, not by month.
poser(
HomeUiState(
notes = listOf(novembre, octobre),
loading = false,
archive = true,
sort = NoteSortMode.UPDATED_DESC,
query = "vieille",
),
)
regle.onNodeWithText(enTete(11)).assertDoesNotExist()
regle.onNodeWithText("Vieille").assertExists()
}

/**
* 🔴 Back in the archive goes back to the list shown before it (3.5.0, Patrice on the S9: the app
* closed). A selection goes first. The control: on an ordinary list nothing of the screen takes Back —
* it still leaves the app, as on any app's first screen.
*/
@Test
fun back_in_the_archive_goes_back_to_the_list_and_a_selection_goes_first() {
poser(HomeUiState(notes = listOf(note("a", "Vieille")), loading = false, archive = true))
Espresso.pressBack()
assertThat(sortiesDeLArchive).hasSize(1)

poser(
HomeUiState(notes = listOf(note("a", "Vieille")), loading = false, archive = true, selection = setOf("a")),
)
Espresso.pressBack()
assertThat(gestesDeSelection).containsExactly("fermer")
assertThat(sortiesDeLArchive).hasSize(1)

poser(HomeUiState(notes = listOf(note("a", "Vieille")), loading = false))
assertThat(regle.runOnIdle { regle.activity.onBackPressedDispatcher.hasEnabledCallbacks() }).isFalse()
}

/**
* D-051: a search of the archive that finds nothing says so — not "the archive is empty", which would
* read as if the notes were gone. The control: an empty archive with no search still says it is empty.
*/
@Test
fun a_search_of_the_archive_that_finds_nothing_says_so() {
poser(HomeUiState(notes = emptyList(), loading = false, archive = true, query = "introuvable"))
regle.onNodeWithText(texte(R.string.search_empty)).assertIsDisplayed()
regle.onNodeWithText(texte(R.string.archive_empty_title)).assertDoesNotExist()

poser(HomeUiState(notes = emptyList(), loading = false, archive = true))
regle.onNodeWithText(texte(R.string.archive_empty_title)).assertIsDisplayed()
}

/** Ouvrir une note rend **la** note, pas un identifiant reconstruit ailleurs. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ abstract class NoteSearchDao {
* dans l'index pour toute note dont `encrypted_content` n'est pas nul. La garde est donc dans
* les données, pas dans cette requête — c'est plus solide, mais ça veut dire qu'un futur
* changement de trigger casserait la promesse sans toucher à ce fichier.
*
* @param archived `false` : les notes ordinaires, comme la recherche de la 2.0.9 (D-036) ; `true` : les
* seules notes archivées — la recherche de la vue Archives (D-051, 3.5.0, issue #72). Jamais les deux.
*/
fun search(rawInput: String, limit: Int = DEFAULT_LIMIT): Flow<List<NoteEntity>> {
fun search(rawInput: String, archived: Boolean = false, limit: Int = DEFAULT_LIMIT): Flow<List<NoteEntity>> {
val match = FtsMatchExpression.from(rawInput) ?: return flowOf(emptyList())
return searchRaw(SimpleSQLiteQuery(SEARCH_SQL, arrayOf<Any?>(match, limit)))
return searchRaw(SimpleSQLiteQuery(SEARCH_SQL, arrayOf<Any?>(match, if (archived) 1 else 0, limit)))
}

private companion object {
Expand Down Expand Up @@ -81,7 +84,7 @@ abstract class NoteSearchDao {
JOIN notes n ON n.rowid = f.rowid
WHERE notes_fts MATCH ?
AND n.trashed_at IS NULL
AND n.archived = 0
AND n.archived = ?
AND n.encrypted_content IS NULL
ORDER BY bm25(notes_fts), n.updated_at DESC
LIMIT ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class SearchRepository @Inject constructor(private val databases: DatabaseProvid
*
* Rend un flux vide — jamais une erreur — si la saisie ne contient aucun terme exploitable :
* taper trois espaces n'est pas une faute de l'utilisateur.
*
* @param archived dans les seules notes archivées (la vue Archives, D-051) plutôt que dans les autres.
*/
fun observe(query: String): Flow<List<Note>> =
flow { emitAll(databases.get().noteSearchDao().search(query)) }.map { it.toDomain() }
fun observe(query: String, archived: Boolean = false): Flow<List<Note>> =
flow { emitAll(databases.get().noteSearchDao().search(query, archived)) }.map { it.toDomain() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ fun HomeRoute(
// that comes while the creation runs is dropped by the ViewModel.
onNewNote = dropUnlessResumed { homeViewModel.createNote() },
onOpenDrawer = { portee.launch { drawerState.open() } },
onQuitterLArchive = homeViewModel::quitterLArchive,
onOpenSearch = onOpenSearch,
onOpenSettings = onOpenSettings,
onOpenAbout = onOpenAbout,
Expand Down
65 changes: 37 additions & 28 deletions app/src/main/java/com/filestech/notes_tech/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ fun HomeScreen(
actionsDeSelection: ActionsDeSelection,
onNewNote: () -> Unit,
onOpenDrawer: () -> Unit,
/** Back in the archive: the list shown before it (3.5.0 — until then, Back left the app). */
onQuitterLArchive: () -> Unit,
onOpenSearch: () -> Unit,
onOpenSettings: () -> Unit,
onOpenAbout: () -> Unit,
Expand All @@ -111,9 +113,11 @@ fun HomeScreen(
// here, at display time, in the language the user chose (notes_tech 2.0.9 parity).
val nomDuDossier = rememberFolderDisplayName()

// The archive's months, recomputed only when the list or its order changes.
val lignesDeLArchive = remember(state.notes, state.sort, state.archive) {
if (state.archive) lignesDeLArchive(state.notes, state.sort, ZoneId.systemDefault()) else emptyList()
// The archive's months, recomputed only when the list or its order changes. Not while searching the
// archive (D-051): the results come by relevance, and months over them would repeat and jumble.
val enMois = state.archive && state.query.isBlank()
val lignesDeLArchive = remember(state.notes, state.sort, enMois) {
if (enMois) lignesDeLArchive(state.notes, state.sort, ZoneId.systemDefault()) else emptyList()
}
val nomDuMois = rememberFormateurDeMois()
val carte: @Composable (Note) -> Unit = { note ->
Expand All @@ -134,6 +138,10 @@ fun HomeScreen(

// Back leaves the selection first, as in every app that selects — not the app.
BackHandler(enabled = state.enSelection, onBack = actionsDeSelection.onFermer)
// 🔴 Then the archive, back to the list shown before it (3.5.0, Patrice on the S9: "dès que je fais retour
// l'appli se ferme"). The archive reads as a screen of its own; Back left the app from it since 3.3.0.
// Not while selecting: the selection goes first. The open drawer goes before both (`HomeRoute`).
BackHandler(enabled = state.archive && !state.enSelection, onBack = onQuitterLArchive)

Scaffold(
modifier = modifier.fillMaxSize(),
Expand Down Expand Up @@ -195,29 +203,29 @@ fun HomeScreen(
if (state.vaultLostCount > 0) {
BanniereBrouillonsPerdus(state.vaultLostCount, onDismissVaultLostBanner)
}
// Not in the archive: the search leaves archived notes out (D-036).
if (!state.archive) {
OutlinedTextField(
value = state.query,
onValueChange = onQueryChange,
label = { Text(stringResource(R.string.home_search_hint)) },
singleLine = true,
leadingIcon = { Icon(Icons.Filled.Search, contentDescription = null) },
trailingIcon = {
if (state.query.isNotEmpty()) {
IconButton(onClick = { onQueryChange("") }) {
Icon(
imageVector = Icons.Filled.Close,
contentDescription = stringResource(R.string.search_clear),
)
}
// Each list searches what it shows: here the notes that are not archived (D-036), in the archive
// the archived ones alone (D-051, 3.5.0, issue #72) — and the field says which.
val indication = if (state.archive) R.string.home_search_archive_hint else R.string.home_search_hint
OutlinedTextField(
value = state.query,
onValueChange = onQueryChange,
label = { Text(stringResource(indication)) },
singleLine = true,
leadingIcon = { Icon(Icons.Filled.Search, contentDescription = null) },
trailingIcon = {
if (state.query.isNotEmpty()) {
IconButton(onClick = { onQueryChange("") }) {
Icon(
imageVector = Icons.Filled.Close,
contentDescription = stringResource(R.string.search_clear),
)
}
},
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, top = 8.dp, end = 16.dp, bottom = 4.dp),
)
}
}
},
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, top = 8.dp, end = 16.dp, bottom = 4.dp),
)

when {
state.loading -> Box(Modifier.fillMaxSize(), Alignment.Center) { CircularProgressIndicator() }
Expand Down Expand Up @@ -246,8 +254,8 @@ fun HomeScreen(
// `key = { it.id }` stabilise l'identité des éléments entre recompositions.
// Sans clé, un changement de filtre réassocie les états par position, et les
// cartes se réutilisent pour la mauvaise note.
// The archive is cut into months (3.3.0); the other lists are not.
if (state.archive) {
// The archive is cut into months (3.3.0); the other lists, and its search, are not.
if (enMois) {
items(lignesDeLArchive, key = { it.cle }) { ligne ->
when (ligne) {
is LigneDeLArchive.Mois -> IntertitreDeMois(nomDuMois(ligne.mois))
Expand All @@ -266,7 +274,8 @@ fun HomeScreen(
@Composable
private fun ListeVide(state: HomeUiState, onNewNote: () -> Unit) {
val enRecherche = state.query.isNotEmpty()
if (state.archive) {
// A search with no result says so, in the archive too (D-051): not "the archive is empty".
if (state.archive && !enRecherche) {
EmptyState(
icon = Icons.Outlined.Archive,
title = stringResource(R.string.archive_empty_title),
Expand Down
Loading
Loading