Skip to content

Commit

Permalink
Protected notes are no more searchable nor their tags (from content) …
Browse files Browse the repository at this point in the history
…will appear anywhere (closes #956)
  • Loading branch information
federicoiosue committed Jan 1, 2024
1 parent 3c36042 commit ed07df4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ public void testGetNotesByTag() {
assertEquals(1, dbHelper.getNotesByTag("#tagged").size());
}

@Test
public void testGetNotesByTag_excludeLocked() {
var titleTag = "#titleTag";
var contentTag = "#tag";

var note1 = new Note();
note1.setTitle("simple note with " + titleTag);
note1.setContent("content with " + contentTag);
dbHelper.updateNote(note1, true);
var note2 = new Note();
note2.setTitle("protected note with " + titleTag);
note2.setContent("content with same tag " + contentTag);
note2.setLocked(true);
dbHelper.updateNote(note2, true);

var result = dbHelper.getNotesByTag(contentTag);
assertEquals(1, result.size());
assertEquals(note1.getTitle(), result.get(0).getTitle());
assertEquals(2, dbHelper.getNotesByTag(titleTag).size());
}

@Test
public void getNotesByPatternEscaped() {
Note note1 = new Note();
Expand All @@ -65,4 +86,40 @@ public void getNotesByPatternEscaped() {
assertEquals(1, dbHelper.getNotesByPattern("%").size());
}

@Test
public void getNotesByPattern_excludeLocked() {
var note1 = new Note();
note1.setTitle("title one");
note1.setContent("This note is clear");
dbHelper.updateNote(note1, true);
var note2 = new Note();
note2.setTitle("title two");
note2.setContent("This note is protected");
note2.setLocked(true);
dbHelper.updateNote(note2, true);

var result = dbHelper.getNotesByPattern("This note is ");

assertEquals(1, result.size());
assertEquals(note1.getTitle(), result.get(0).getTitle());
}

@Test
public void getTags() {
var note1 = new Note();
note1.setTitle("title1");
note1.setContent("#tag1");
dbHelper.updateNote(note1, true);
var note2 = new Note();
note2.setTitle("title2#");
note2.setContent("#tag2");
note2.setLocked(true);
dbHelper.updateNote(note2, true);

var tags = dbHelper.getTags();

assertEquals(1, tags.size());
assertEquals(note1.getContent(), tags.get(0).getText());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,8 @@ public boolean onQueryTextSubmit(String arg0) {

@Override
public boolean onQueryTextChange(String pattern) {

if (Prefs.getBoolean("settings_instant_search", false)
&& binding.searchLayout != null &&
searchPerformed && mFragment.isAdded()) {
&& searchPerformed && mFragment.isAdded()) {
searchTags = null;
searchQuery = pattern;
NoteLoaderTask.getInstance().execute("getNotesByPattern", pattern);
Expand All @@ -738,15 +736,12 @@ public boolean onQueryTextChange(String pattern) {


private void setActionItemsVisibility(Menu menu, boolean searchViewHasFocus) {

boolean drawerOpen =
mainActivity.getDrawerLayout() != null && mainActivity.getDrawerLayout().isDrawerOpen
(GravityCompat.START);
boolean drawerOpen = mainActivity.getDrawerLayout() != null
&& mainActivity.getDrawerLayout().isDrawerOpen(GravityCompat.START);
boolean expandedView = Prefs.getBoolean(PREF_EXPANDED_VIEW, true);

int navigation = Navigation.getNavigation();
boolean navigationReminders = navigation == Navigation.REMINDERS;
boolean navigationArchive = navigation == Navigation.ARCHIVE;
boolean navigationTrash = navigation == Navigation.TRASH;
boolean navigationCategory = navigation == Navigation.CATEGORY;

Expand All @@ -771,8 +766,7 @@ private void setActionItemsVisibility(Menu menu, boolean searchViewHasFocus) {
menu.findItem(R.id.menu_filter_category).setVisible(!drawerOpen && !filterArchivedInCategory &&
navigationCategory && !searchViewHasFocus);
menu.findItem(R.id.menu_filter_category_remove)
.setVisible(!drawerOpen && filterArchivedInCategory &&
navigationCategory && !searchViewHasFocus);
.setVisible(!drawerOpen && filterArchivedInCategory && navigationCategory && !searchViewHasFocus);
menu.findItem(R.id.menu_sort)
.setVisible(!drawerOpen && !navigationReminders && !searchViewHasFocus);
menu.findItem(R.id.menu_expanded_view)
Expand Down Expand Up @@ -805,7 +799,6 @@ public boolean onOptionsItemSelected(final MenuItem item) {
* Performs one of the ActionBar button's actions after checked notes protection
*/
public void performAction(MenuItem item, ActionMode actionMode) {

if (isOptionsItemFastClick()) {
return;
}
Expand Down
30 changes: 13 additions & 17 deletions omniNotes/src/main/java/it/feio/android/omninotes/db/DbHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static it.feio.android.omninotes.utils.ConstantsBase.PREF_PASSWORD;
import static it.feio.android.omninotes.utils.ConstantsBase.PREF_SORTING_COLUMN;
import static it.feio.android.omninotes.utils.ConstantsBase.TIMESTAMP_UNIX_EPOCH;
import static it.feio.android.omninotes.utils.Navigation.checkNavigation;

import android.content.ContentValues;
import android.content.Context;
Expand Down Expand Up @@ -399,7 +400,7 @@ public List<Note> getNotes(String whereCondition, boolean order) {
String sortOrder = "";

// Getting sorting criteria from preferences. Reminder screen forces sorting.
if (Navigation.checkNavigation(Navigation.REMINDERS)) {
if (checkNavigation(Navigation.REMINDERS)) {
sortColumn = KEY_REMINDER;
} else {
sortColumn = Prefs.getString(PREF_SORTING_COLUMN, KEY_TITLE);
Expand Down Expand Up @@ -569,7 +570,7 @@ public List<Note> getNotesByPattern(String pattern) {
+ (navigation == Navigation.UNCATEGORIZED ? " AND (" + KEY_CATEGORY + " IS NULL OR "
+ KEY_CATEGORY_ID
+ " == 0) " : "")
+ (Navigation.checkNavigation(Navigation.REMINDERS) ? " AND " + KEY_REMINDER
+ (checkNavigation(Navigation.REMINDERS) ? " AND " + KEY_REMINDER
+ " IS NOT NULL" : "")
+ " AND ("
+ " ( " + KEY_LOCKED + " IS NOT 1 AND (" + KEY_TITLE + " LIKE '%" + escapedPattern
Expand Down Expand Up @@ -702,8 +703,8 @@ public List<Tag> getTags(Note note) {
String whereCondition = " WHERE "
+ (note != null ? KEY_ID + " = " + note.get_id() + " AND " : "")
+ "(" + KEY_CONTENT + " LIKE '%#%' OR " + KEY_TITLE + " LIKE '%#%' " + ")"
+ " AND " + KEY_TRASHED + " IS " + (Navigation.checkNavigation(Navigation.TRASH) ? ""
: " NOT ") + " 1";
+ " AND " + KEY_TRASHED + " IS " + (checkNavigation(Navigation.TRASH) ? "1" : " NOT 1")
+ " AND " + KEY_LOCKED + " IS NOT 1";
List<Note> notesRetrieved = getNotes(whereCondition, true);

for (Note noteRetrieved : notesRetrieved) {
Expand All @@ -728,33 +729,28 @@ public List<Tag> getTags(Note note) {
* Retrieves all notes related to category it passed as parameter
*/
public List<Note> getNotesByTag(String tag) {
if (tag.contains(",")) {
return getNotesByTag(tag.split(","));
} else {
return getNotesByTag(new String[]{tag});
}
return tag.contains(",")
? getNotesByTag(tag.split(","))
: getNotesByTag(new String[]{tag});
}


/**
* Retrieves all notes with specified tags
*/
public List<Note> getNotesByTag(String[] tags) {
StringBuilder whereCondition = new StringBuilder();
var whereCondition = new StringBuilder();
whereCondition.append(" WHERE ");
for (int i = 0; i < tags.length; i++) {
if (i != 0) {
whereCondition.append(" AND ");
}
whereCondition.append("(" + KEY_CONTENT + " LIKE '%").append(tags[i]).append("%' OR ")
.append(KEY_TITLE)
.append(" LIKE '%").append(tags[i]).append("%')");
whereCondition.append(String.format("((%s IS 1 AND %s LIKE '%%%s%%') OR (%s is NOT 1 AND (%s LIKE '%%%s%%' OR %s LIKE '%%%s%%')))"
, KEY_LOCKED, KEY_TITLE, tags[i], KEY_LOCKED, KEY_CONTENT, tags[i], KEY_TITLE, tags[i]));
}
// Trashed notes must be included in search results only if search if performed from trash
whereCondition.append(" AND " + KEY_TRASHED + " IS ")
.append(Navigation.checkNavigation(Navigation.TRASH) ?
"" : "" +
" NOT ").append(" 1");
.append(checkNavigation(Navigation.TRASH) ? "" : "NOT ").append("1");

return rx.Observable.from(getNotes(whereCondition.toString(), true))
.map(note -> {
Expand All @@ -777,7 +773,7 @@ public List<Note> getNotesByTag(String[] tags) {
public List<Note> getNotesByUncompleteChecklist() {
String whereCondition =
" WHERE " + KEY_CHECKLIST + " = 1 AND " + KEY_CONTENT + " LIKE '%" + UNCHECKED_SYM + "%' AND "
+ KEY_TRASHED + (Navigation.checkNavigation(Navigation.TRASH) ? " IS 1" : " IS NOT 1");
+ KEY_TRASHED + (checkNavigation(Navigation.TRASH) ? " IS 1" : " IS NOT 1");
return getNotes(whereCondition, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Note extends BaseNote implements Parcelable {
* Parcelable interface must also have a static field called CREATOR, which is an object implementing the
* Parcelable.Creator interface. Used to un-marshal or de-serialize object from Parcel.
*/
public static final Parcelable.Creator<Note> CREATOR = new Parcelable.Creator<Note>() {
public static final Parcelable.Creator<Note> CREATOR = new Parcelable.Creator<>() {

public Note createFromParcel(Parcel in) {
return new Note(in);
Expand Down
8 changes: 6 additions & 2 deletions omniNotes/src/main/res/raw/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
-->
<changelog bulletedList="true">

<changelogversion
changeDate="Jan 2, 2024"
versionName="6.3.2">
<changelogtext>[u]Fix[/u] Protected notes are no more searchable nor their tags (from content) will appear anywhere content's secrecy (thanks to [a href='https://github.com/XYIheng']Yiheng Xiong[/a])</changelogtext>
</changelogversion>

<changelogversion
changeDate="Dec 16, 2023"
versionName="6.3.1">
<changelogtext>[i]Improved![/i] Updated F-Droid resources and translations</changelogtext>
<changelogtext>[u]Fix[/u] Dynamic left menu items counting fixed (thanks to [a href='https://github.com/XYIheng']Yiheng Xiong[/a])</changelogtext>
<changelogtext>[u]Fix[/u] Dynamic left menu items counting fixed (thanks to [a href='https://github.com/XYIheng']Yiheng Xiong[/a])</changelogtext>
<changelogtext>[u]Fix[/u] Correct dialog text shown on category deletion (thanks to [a href='https://github.com/XYIheng']Yiheng Xiong[/a])</changelogtext>
<changelogtext>[u]Fix[/u] Notes updated state correctly reflected into the notes list in real time (thanks to [a href='https://github.com/XYIheng']Yiheng Xiong[/a])</changelogtext>
<changelogtext>[u]Fix[/u] Notes updated state correctly reflected into the notes list in real time (thanks to [a href='https://github.com/XYIheng']Yiheng Xiong[/a])</changelogtext>
</changelogversion>

<changelogversion
Expand Down

0 comments on commit ed07df4

Please sign in to comment.