Skip to content

Commit

Permalink
#113: In Filter Find api (IGalleryFilter.InAnyField) allow to search …
Browse files Browse the repository at this point in the history
…for subexpressions seperated by " "
  • Loading branch information
k3b committed Mar 19, 2018
1 parent ffadaf1 commit a981468
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public class GalleryCursorFragment extends Fragment implements Queryable, Direc
private static final String INSTANCE_STATE_SEL_ONLY = "selectedOnly";
private static final String INSTANCE_STATE_LOADER_ID = "loaderID";

private static final int MODE_VIEW = 0;
private static final int MODE_PICK_SINGLE = 1;
private static final int MODE_PICK_MULTIBLE = 2;
private static final int MODE_VIEW_PICKER_NONE = 0;
private static final int MODE_VIEW_PICK_SINGLE = 1;
private static final int MODE_VIEW_PICK_MULTIBLE = 2;

private static int nextLoaderID = 100;
private int loaderID = -1;
Expand Down Expand Up @@ -153,7 +153,8 @@ public class GalleryCursorFragment extends Fragment implements Queryable, Direc
/** true pick geo; false pick image */
private boolean mGetGeo = false;

private int mMode = MODE_VIEW;
/** one of the MODE_VIEW_PICKER_XXXX */
private int mMode = MODE_VIEW_PICKER_NONE;

private MoveOrCopyDestDirPicker mDestDirPicker = null;
/**************** construction ******************/
Expand Down Expand Up @@ -366,7 +367,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
String action = (intent != null) ? intent.getAction() : null;

if ((action != null) && ((Intent.ACTION_PICK.compareTo(action) == 0) || (Intent.ACTION_GET_CONTENT.compareTo(action) == 0))) {
this.mMode = (intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE,false)) ? MODE_PICK_MULTIBLE : MODE_PICK_SINGLE;
this.mMode = (intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE,false)) ? MODE_VIEW_PICK_MULTIBLE : MODE_VIEW_PICK_SINGLE;
mMustReplaceMenue = true;
String schema = intent.getScheme();
mGetGeo = ((schema != null) && ("geo".compareTo(schema) == 0));
Expand Down Expand Up @@ -758,6 +759,27 @@ private void startMultiSelectionMode() {
getActivity().invalidateOptionsMenu();
}

/**
* Different menu modes
* * normal name searchbar-icon folder map (tags) (filter) menu
* * R.menu.menu_gallery_non_selected_only R.menu.menu_gallery_non_multiselect
* * selected selected cancel seleted-only share (save) menu
* * (Filter not available; this.isMultiSelectionActive();
* * R.menu.menu_gallery_multiselect_mode_all R.menu.menu_image_commands
* * locked name lock folder map menu
* * (no multiselection, no base-filters)
* * (this.locked; R.menu.menu_gallery_locked)
* * searchbar bar cancel-searc-bar (folder) (map) (tags) (filter) menu
* * picker-locked
* * R.menu.menu_gallery_pick R.menu.menu_gallery_locked
* * picker-non-locked selected ok cancel filter settings
* * R.menu.menu_gallery_pick R.menu.menu_gallery_non_multiselect
*
* (xxxx) with "IFROOM" (in wide screen only)
* searchbarmode is like "normal" where there is no "IFROOM" on no-searchbar items
*
* @param menu
*/
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
Expand All @@ -769,12 +791,13 @@ public void onPrepareOptionsMenu(Menu menu) {
mMustReplaceMenue = false;
menu.clear();
mMenuRemoveAllSelected = null;
if (mMode == MODE_VIEW) {
if (mMode == MODE_VIEW_PICKER_NONE) {
//
if (locked) { // view-locked
mSelectedItems.clear();
inflater.inflate(R.menu.menu_gallery_locked, menu);
LockScreen.fixMenu(menu);
} else if (isMultiSelectionActive()) { // view-multiselect
} else if (this.isMultiSelectionActive()) { // view-multiselect
inflater.inflate(R.menu.menu_gallery_multiselect_mode_all, menu);

mShareOnlyToggle = menu.findItem(R.id.cmd_selected_only);
Expand All @@ -796,7 +819,7 @@ public void onPrepareOptionsMenu(Menu menu) {
}


} else {
} else { // picker mode
inflater.inflate(R.menu.menu_gallery_pick, menu);
if (locked) { // pick-locked
mSelectedItems.clear();
Expand Down Expand Up @@ -1316,7 +1339,7 @@ private void onDuplicatesFound(SelectedItems selectedItems, StringBuffer debugMe
}

private boolean isMultiSelectionActive() {
if (mMode != MODE_VIEW) return true;
if (mMode != MODE_VIEW_PICKER_NONE) return true;
return !mSelectedItems.isEmpty();
}

Expand Down Expand Up @@ -1344,7 +1367,7 @@ private void fix() {
/** return true if included; false if excluded */
private boolean toggleSelection(long imageID) {
boolean contains = mSelectedItems.contains(imageID);
if (mMode == MODE_PICK_SINGLE) {
if (mMode == MODE_VIEW_PICK_SINGLE) {
clearSelections();
}
if (contains) {
Expand Down
26 changes: 19 additions & 7 deletions app/src/main/java/de/k3b/android/androFotoFinder/tagDB/TagSql.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,16 @@ public static IGalleryFilter parseQueryEx(QueryParameter query, boolean remove)

// from more complex to less complex
String[] params;
if ((params = getParams(query, FILTER_EXPR_ANY_LIKE, remove)) != null) {
resultFilter.setInAnyField(params[0]);
StringBuilder any = null;
while ((params = getParams(query, FILTER_EXPR_ANY_LIKE, remove)) != null) {
if (any == null) {
any = new StringBuilder().append(params[0]);
} else {
any.append(" ").append(params[0]);

}
}
if (any != null) resultFilter.setInAnyField(any.toString());

parseTagsFromQuery(query, remove, resultFilter);

Expand Down Expand Up @@ -156,12 +163,17 @@ public static void filter2QueryEx(QueryParameter resultQuery, IGalleryFilter fil
if ((resultQuery != null) && (!GalleryFilterParameter.isEmpty(filter))) {
filter2Query(resultQuery, filter, clearWhereBefore);
if (Global.Media.enableIptcMediaScanner) {
String any = filter.getInAnyField();
if ((any != null) && (any.length() > 0)) {
if (!any.contains("%")) {
any = "%" + any + "%";
String allAny = filter.getInAnyField();

if (allAny != null) {
for (String any : allAny.split(" ")) {
if ((any != null) && (any.length() > 0)) {
if (!any.contains("%")) {
any = "%" + any + "%";
}
resultQuery.addWhere(FILTER_EXPR_ANY_LIKE, any, any, any, any);
}
}
resultQuery.addWhere(FILTER_EXPR_ANY_LIKE, any, any, any, any);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public void shouldParsePublic() throws Exception {
assertFilterQueryFilter(VISIBILITY.PUBLIC);
}

@Test
public void shouldFilterFind() throws Exception {
assertFilterFind("hello world", "shouldFilterFind");
}

// assert that input-string==output-string in input-string -> filter -> query -> filter -> output-string
private QueryParameter assertFilterQueryFilter(VISIBILITY visibility) {
String FILTER_STRING = ";;;;;;;;;" + visibility.value;
Expand All @@ -79,29 +84,48 @@ private QueryParameter assertFilterQueryFilter(String filterString) {
}

// assert that input-string==output-string in input-string -> filter -> query -> filter -> output-string
private QueryParameter assertFilterQueryFilter(String filterString, String printSql) {
GalleryFilterParameter initialFilter = GalleryFilterParameter.parse(filterString, new GalleryFilterParameter());
private QueryParameter assertFilterQueryFilter(String expectedFilterString, String printSql) {
GalleryFilterParameter initialFilter = GalleryFilterParameter.parse(expectedFilterString, new GalleryFilterParameter());

QueryParameter query = new QueryParameter();
TagSql.filter2QueryEx(query, initialFilter, true);
GalleryFilterParameter parsedFilter = getParsedGalleryFilterParameter(query, initialFilter, printSql);

if (printSql != null) {
String sql = query.toSqlString();
assertEquals(expectedFilterString, parsedFilter.toString());
return query;
}

// assert that input-string==output-string in input-string -> filter -> query -> filter -> output-string
private QueryParameter assertFilterFind(String expectedFilterFindValue, String debugPrefixPrintSql) {
GalleryFilterParameter initialFilter = new GalleryFilterParameter().setInAnyField(expectedFilterFindValue);

QueryParameter query = new QueryParameter();
GalleryFilterParameter parsedFilter = getParsedGalleryFilterParameter(query, initialFilter, debugPrefixPrintSql);

assertEquals(query.toSqlString(), expectedFilterFindValue, parsedFilter.getInAnyField().replaceAll("%",""));
return query;
}

private GalleryFilterParameter getParsedGalleryFilterParameter(QueryParameter resultQuery, GalleryFilterParameter initialFilter, String debugPrefixPrintSql) {
TagSql.filter2QueryEx(resultQuery, initialFilter, true);

if (debugPrefixPrintSql != null) {
String sql = resultQuery.toSqlString();
int start = sql.indexOf("WHERE");
System.out.println(printSql + ": " + sql.substring(start));
System.out.println(debugPrefixPrintSql + ": " + sql.substring(start));
}

GalleryFilterParameter parsedFilter = (GalleryFilterParameter) TagSql.parseQueryEx(query, true);
// query is destroyed by parse so use a clone
QueryParameter queryToParse = new QueryParameter(resultQuery);
GalleryFilterParameter parsedFilter = (GalleryFilterParameter) TagSql.parseQueryEx(queryToParse, true);
parsedFilter.setSort(initialFilter.getSortID(), initialFilter.isSortAscending());

// compensate that query might automatically add visibility
if (initialFilter.getVisibility() == VISIBILITY.DEFAULT) {
parsedFilter.setVisibility(VISIBILITY.DEFAULT);
}

assertEquals(filterString, parsedFilter.toString());
return query;
return parsedFilter;
}

//################ tag filter support
@Test
public void shouldTagsNoneOnly() throws Exception {
Expand Down
7 changes: 5 additions & 2 deletions fotolib2/src/main/java/de/k3b/io/GalleryFilterParameter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017 by k3b.
* Copyright (c) 2015-2018 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down Expand Up @@ -39,6 +39,8 @@ public class GalleryFilterParameter extends GeoRectangle implements IGalleryFilt

private List<String> tagsAllIncluded;
private List<String> tagsAllExcluded;

/** match if the text is in path, filename, title, description, tags. Wildcard "%" is allowed. Sub-expressions are seperated by " " */
private String inAnyField;

private long dateMin = 0;
Expand Down Expand Up @@ -152,12 +154,13 @@ public GalleryFilterParameter setTagsAllExcluded(List<String> tagsAllExcluded) {
return this;
}

/** match if the text is in path, filename, title, description, tags */
/** match if the text is in path, filename, title, description, tags. Wildcard "%" is allowed. Sub-expressions are seperated by " " */
@Override
public String getInAnyField() {
return inAnyField;
}

/** match if the text is in path, filename, title, description, tags. Wildcard "%" is allowed. Sub-expressions are seperated by " " */
public GalleryFilterParameter setInAnyField(String inAnyField) {
this.inAnyField = inAnyField;
return this;
Expand Down
4 changes: 2 additions & 2 deletions fotolib2/src/main/java/de/k3b/io/IGalleryFilter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017 by k3b.
* Copyright (c) 2015-2018 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down Expand Up @@ -57,7 +57,7 @@ public interface IGalleryFilter extends IGeoRectangle {
/** None of the Tags/Keywords/Categories/VirtualAlbum that the image must NOT contain. ("AND NOT") */
List<String> getTagsAllExcluded();

/** match if the text is in path, filename, title, description, tags */
/** match if the text is in path, filename, title, description, tags. Wildcard "%" is allowed. Sub-expressions are seperated by " " */
String getInAnyField();

/** one of the VISIBILITY_XXXX values for public/private images */
Expand Down
52 changes: 0 additions & 52 deletions wiki/table-of-content.md

This file was deleted.

0 comments on commit a981468

Please sign in to comment.