Skip to content

Commit

Permalink
#169: Introduced visibility "hidden"
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed Jan 19, 2021
1 parent f5b66e7 commit dded376
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,15 @@ public IPhotoProperties setRating(Integer value) {
public VISIBILITY getVisibility() {
Integer ty = mData.getAsInteger(TagSql.SQL_COL_EXT_MEDIA_TYPE);
if (ty != null) {
if (ty.intValue() == FotoSql.MEDIA_TYPE_IMAGE_PRIVATE)
return VISIBILITY.PRIVATE;

return VISIBILITY.PUBLIC;
return FotoSql.mediaType2Visibility(ty.intValue());
}
return null;
}

@Override
public IPhotoProperties setVisibility(VISIBILITY value) {
if (VISIBILITY.isChangingValue(value)) {
int iValue = (value.equals(VISIBILITY.PRIVATE))
? FotoSql.MEDIA_TYPE_IMAGE_PRIVATE
: FotoSql.MEDIA_TYPE_IMAGE;
mData.put(TagSql.SQL_COL_EXT_MEDIA_TYPE, iValue);
mData.put(TagSql.SQL_COL_EXT_MEDIA_TYPE, FotoSql.mediaTypeFromVisibility(value));
setLastXmpFileModifyDate();
}
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ public VISIBILITY getVisibility() {
if (colType == -1) return null;
Integer ty = cursor.getInt(colType);
if (ty != null) {
if (ty.intValue() == FotoSql.MEDIA_TYPE_IMAGE_PRIVATE)
return VISIBILITY.PRIVATE;

return VISIBILITY.PUBLIC;
return FotoSql.mediaType2Visibility(ty.intValue());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,16 @@ public class FotoSql extends FotoSqlBase {
private static final int LAST_MODIFIED_FACTOR = 1000;

public static final int MEDIA_TYPE_IMAGE_PRIVATE = 1000 + MEDIA_TYPE_IMAGE; // 1001 APhoto manager specific
public static final int MEDIA_TYPE_ALBUM_FILE = 0;
public static final int MEDIA_TYPE_IMAGE_HIDDEN = 1100 + MEDIA_TYPE_IMAGE; // 1101 APhoto manager specific
public static final int MEDIA_TYPE_ALBUM_FILE = 0;

protected static final String FILTER_EXPR_PRIVATE
= "(" + SQL_COL_EXT_MEDIA_TYPE + " = " + MEDIA_TYPE_IMAGE_PRIVATE + ")";
protected static final String FILTER_EXPR_HIDDEN
= "(" + SQL_COL_EXT_MEDIA_TYPE + " = " + MEDIA_TYPE_IMAGE_HIDDEN + ")";

public static final String FILTER_EXPR_PRIVATE_PUBLIC
= "(" + SQL_COL_EXT_MEDIA_TYPE + " in (" + MEDIA_TYPE_IMAGE_PRIVATE + "," + MEDIA_TYPE_IMAGE +"))";
= "(" + SQL_COL_EXT_MEDIA_TYPE + " in (" + MEDIA_TYPE_IMAGE_PRIVATE + "," + MEDIA_TYPE_IMAGE + "))";
protected static final String FILTER_EXPR_PUBLIC
= "(" + SQL_COL_EXT_MEDIA_TYPE + " = " + MEDIA_TYPE_IMAGE + ")";

Expand Down Expand Up @@ -1329,6 +1333,31 @@ private static List<String> getFileNamesImpl(QueryParameter parameters, List<Lon
return result;
}

public static VISIBILITY mediaType2Visibility(final int mediaTypeId) {
switch (mediaTypeId) {
case FotoSql.MEDIA_TYPE_IMAGE_PRIVATE:
return VISIBILITY.PRIVATE;
case FotoSql.MEDIA_TYPE_IMAGE_HIDDEN:
return VISIBILITY.PRIVATE;
default:
return VISIBILITY.PUBLIC;
}


}

public static int mediaTypeFromVisibility(VISIBILITY value) {
switch (value) {
case HIDDEN:
return FotoSql.MEDIA_TYPE_IMAGE_HIDDEN;
case PRIVATE:
return FotoSql.MEDIA_TYPE_IMAGE_PRIVATE;
case PUBLIC:
default:
return FotoSql.MEDIA_TYPE_IMAGE;
}
}

protected static String getFilterExpressionVisibility(VISIBILITY _visibility) {
VISIBILITY visibility = _visibility;
// add visibility column only if not included yet
Expand All @@ -1343,6 +1372,8 @@ protected static String getFilterExpressionVisibility(VISIBILITY _visibility) {
return FILTER_EXPR_PRIVATE;
case PRIVATE_PUBLIC:
return FILTER_EXPR_PRIVATE_PUBLIC;
case HIDDEN:
return FILTER_EXPR_HIDDEN;
case PUBLIC:
default:
return FILTER_EXPR_PUBLIC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public static IGalleryFilter parseQueryEx(QueryParameter query, boolean remove)
if (getParams(query, FILTER_EXPR_PRIVATE, remove) != null) {
resultFilter.setVisibility(VISIBILITY.PRIVATE);
}
if (getParams(query, FILTER_EXPR_HIDDEN, remove) != null) {
resultFilter.setVisibility(VISIBILITY.HIDDEN);
}
if (getParams(query, FILTER_EXPR_PUBLIC, remove) != null) {
resultFilter.setVisibility(VISIBILITY.PUBLIC);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public void shouldParsePublic() {
assertFilterQueryFilter(VISIBILITY.PUBLIC);
}

@Test
public void shouldParseHidden() {
assertFilterQueryFilter(VISIBILITY.HIDDEN);
}

@Test
public void shouldFilterFind() {
assertFilterFind("hello world", "shouldFilterFind");
Expand Down
27 changes: 20 additions & 7 deletions fotolib2/src/main/java/de/k3b/io/VISIBILITY.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,26 @@
import de.k3b.LibGlobal;

public enum VISIBILITY {
/** take from current settings */
/**
* take from current settings
*/
DEFAULT(0),
/** private only */
/**
* private only
*/
PRIVATE(1),
/** public only */
/**
* public only
*/
PUBLIC(2),
/** private and public images but not other files like album-files */
PRIVATE_PUBLIC(3);

/**
* Used as Filter: private and public images but not other files like album-files
*/
PRIVATE_PUBLIC(3),

/* Hidden Photo (inside directoryname starting with "." or Directory miwth ".nomedia" file */
HIDDEN(4);

// #100: if photo has this tag it has visibility PRIVATE
public static final String TAG_PRIVATE = "PRIVATE";
Expand All @@ -44,7 +56,7 @@ public enum VISIBILITY {
// causes "SLF4J: Class path contains multiple SLF4J bindings." in unittests :-(
// private static final Logger logger = LoggerFactory.getLogger(LibGlobal.LOG_TAG);

public static final VISIBILITY MAX = PRIVATE_PUBLIC;
public static final VISIBILITY MAX = HIDDEN;
public final int value;

private VISIBILITY(int value) {
Expand All @@ -71,6 +83,7 @@ public static VISIBILITY fromString(String value) {
if (lower.startsWith("private_p")) return PRIVATE_PUBLIC;
if (lower.startsWith("pr")) return PRIVATE;
if (lower.startsWith("pu")) return PUBLIC;
if (lower.startsWith("hi")) return HIDDEN;
switch (lower.charAt(0)) {
case 'd' :
return DEFAULT;
Expand All @@ -92,7 +105,7 @@ public static VISIBILITY fromString(String value) {
}

public static boolean isChangingValue(VISIBILITY value) {
return ((value == PRIVATE) || (value == PUBLIC));
return ((value == PRIVATE) || (value == PUBLIC) || (value == HIDDEN));
}

public static boolean hasPrivate(List<String> tags) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void addChanges(IPhotoProperties newData, EnumSet<FieldID> changes, List<

final VISIBILITY visibility = newData.getVisibility();
if (changes.contains(FieldID.visibility) && VISIBILITY.isChangingValue(visibility)) {
addChanges(MediaTransactionLogEntryType.VISIBILITY, ((VISIBILITY.PRIVATE.equals(visibility)) ? "1": "0") + " " + visibility, false);
addChanges(MediaTransactionLogEntryType.VISIBILITY, ((!VISIBILITY.PUBLIC.equals(visibility)) ? "1" : "0") + " " + visibility, false);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ public void shouldNotCalculateModifiedPath() {
check(null, "/path/to/file.jpg-p", VISIBILITY.PRIVATE);
check(null, "/path/to/file.jpg", VISIBILITY.PRIVATE_PUBLIC);
check(null, "/path/to/file.jpg", VISIBILITY.DEFAULT);
check(null, "/path/to/file.jpg", VISIBILITY.HIDDEN);
check(null, "/path/to/file.jpg-p", VISIBILITY.HIDDEN);
check(null, "/path/to/file.jpg", null);
check(null, "/path/to/file.jpg-p", null);
}


Expand Down

0 comments on commit dded376

Please sign in to comment.