Skip to content

Commit

Permalink
#169: Fixed media scanner: visibility ==> SQL_COL_EXT_MEDIA_TYPE
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed Feb 7, 2021
1 parent becfdec commit 8e1f533
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,18 @@ public static QueryParameter setWhereVisibility(QueryParameter parameters, VISIB
return parameters;
}

public static void setVisibility(ContentValues contentValues, VISIBILITY visibility) {
contentValues.put(SQL_COL_EXT_MEDIA_TYPE, getImageMediaType(visibility));
}

private static int getImageMediaType(VISIBILITY visibility) {
switch (visibility) {
case PRIVATE: return MEDIA_TYPE_IMAGE_PRIVATE;
case HIDDEN: return MEDIA_TYPE_IMAGE_HIDDEN;
default: return MEDIA_TYPE_IMAGE; // assume PUBLIC for the others
}
}

public static List<String> getAlbumFiles(String path, int subDirLevels) {
SelectedFiles databaseFiles = FotoSql.getSelectedfiles(
SQL_COL_PATH +" like '" + path + "/%" + AlbumFile.SUFFIX_VALBUM + "' OR " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,22 @@ public MergedMediaRepository(IMediaRepositoryApi database, IMediaRepositoryApi c
@Override
public int execUpdate(String dbgContext, long id, ContentValues values) {
int result = super.execUpdate(dbgContext, id, values);
database.execUpdate(dbgContext, id, values);
return result;
if (result == 0) {
dbgContext += " " + id + " not found or no change in contentprovider.";

String path = values.getAsString(FotoSql.SQL_COL_PATH);
Long changedId = FotoSql.getId(dbgContext, getWriteChild(), path);
if (changedId != null && id != changedId.longValue()) {
// pk in contentprovidser has changed
dbgContext += " unsing " + path + "(" + changedId + ") instead";
result = super.execUpdate(dbgContext, changedId, values);
if (result > 0) {
// also correcting pk in local db
values.put(FotoSql.SQL_COL_PK, changedId);
}
}
}
return database.execUpdate(dbgContext, id, values);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2020 by k3b.
* Copyright (c) 2016-2021 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down Expand Up @@ -64,9 +64,15 @@ public class TagSql extends FotoSql {
* <P>Type: INTEGER (long) as milliseconds since jan 1, 1970</P> */
public static final String SQL_COL_EXT_XMP_LAST_MODIFIED_DATE = MediaStore.Video.Media.DURATION;

// pseudo date values for SQL_COL_EXT_XMP_LAST_MODIFIED_DATE
public static final int EXT_LAST_EXT_SCAN_UNKNOWN = 0;
public static final int EXT_LAST_EXT_SCAN_NO_XMP_IN_CSV = 5;
public static final int EXT_LAST_EXT_SCAN_NO_XMP = 10;
public static final int EXT_LAST_EXT_SCAN_PSEUDO_LAST = 30;

public static boolean isPseudoXmpFileDateVauel(long xmpFileDate) {
return xmpFileDate >= EXT_LAST_EXT_SCAN_UNKNOWN && xmpFileDate <= EXT_LAST_EXT_SCAN_PSEUDO_LAST;
}

protected static final String FILTER_EXPR_PATH_AND_XMP_DATE_LESS_THAN = FILTER_EXPR_PATH_LIKE
+ " and ("
Expand Down Expand Up @@ -377,7 +383,7 @@ public static int updateDB(String dbgContext, String oldFullJpgFilePath,


public static int execUpdate(String dbgContext, String path, long xmpFileDate, ContentValues values, VISIBILITY visibility) {
if ((!Global.Media.enableXmpNone) || (xmpFileDate == EXT_LAST_EXT_SCAN_UNKNOWN)) {
if (!Global.Media.enableXmpNone || isPseudoXmpFileDateVauel(xmpFileDate)) {
return getMediaDBApi().execUpdate(dbgContext, path, values, visibility);
}
return getMediaDBApi().exexUpdateImpl(dbgContext, values, FILTER_EXPR_PATH_AND_XMP_DATE_LESS_THAN, new String[]{path, Long.toString(xmpFileDate)});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ protected PhotoPropertiesMediaDBContentValues getExifFromFile(ContentValues valu
getExifValues(dest, src);

updateTagRepository(src.getTags());

VISIBILITY visibility = src.getVisibility();
if (visibility == null) {
visibility = VISIBILITY.getVisibility(src);
}
FotoSql.setVisibility(values, visibility);
}

String absoluteJpgPath = jpgFile.getCanonicalPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,6 @@ private static void notifyIfThereAreChanges(Integer modifyCount, Context context
}
}

/** do not wait for result. */
public static void updateMediaDBInBackground(
PhotoPropertiesMediaFilesScanner scanner, Context context, String why,
IFile[] oldPathNames, IFile[] newPathNames) {
if (isGuiThread()) {
// update_Android42 scanner in seperate background task
PhotoPropertiesMediaFilesScannerAsyncTask scanTask = new PhotoPropertiesMediaFilesScannerAsyncTask(scanner, context.getApplicationContext(), why + " from completed new AsycTask");
scanTask.execute(oldPathNames, newPathNames);
} else {
// Continute in background task
int modifyCount = scanner.updateMediaDatabaseAndroid42(context.getApplicationContext(), oldPathNames, newPathNames);
notifyIfThereAreChanges(modifyCount, context, why + " within current non-gui-task");
}
}

@Override
protected void onPostExecute(Integer modifyCount) {
super.onPostExecute(modifyCount);
Expand Down
30 changes: 29 additions & 1 deletion fotolib2/src/main/java/de/k3b/io/VISIBILITY.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2020 by k3b.
* Copyright (c) 2017-2021 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand All @@ -26,6 +26,8 @@
import java.util.List;

import de.k3b.LibGlobal;
import de.k3b.media.IPhotoProperties;
import de.k3b.media.PhotoPropertiesUtil;

public enum VISIBILITY {
/**
Expand Down Expand Up @@ -113,10 +115,36 @@ public static boolean hasPrivate(List<String> tags) {
return (existing >= 0);
}

/** infers visibility from tags */
public static VISIBILITY getVisibility(List<String> tags) {
return hasPrivate(tags) ? PRIVATE : PUBLIC;
}

/** infers visibility from path */
public static VISIBILITY getVisibility(String filePath) {
if (filePath == null) return null;
return PhotoPropertiesUtil.isPrivateImage(filePath) ? PRIVATE : PUBLIC;
}

/** infers visibility from tags and path */
public static VISIBILITY getVisibility(IPhotoProperties photoProperties) {
VISIBILITY result = null;
if (photoProperties != null) {
List<String> tags = photoProperties.getTags();
if (tags != null) {
result = VISIBILITY.getVisibility(tags);
}

if (result == null) {
String path = photoProperties.getPath();
if (path != null) {
result = VISIBILITY.getVisibility(path);
}
}
}
return result;
}

public static List<String> setPrivate(List<String> tags, VISIBILITY visibility) {
boolean hasPrivate = VISIBILITY.hasPrivate(tags);
if (visibility == VISIBILITY.PRIVATE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2020 by k3b.
* Copyright (c) 2016-2021 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down Expand Up @@ -184,8 +184,10 @@ public IPhotoProperties setRating(Integer value) {
@Override
public VISIBILITY getVisibility() {
String sValue = getString("getVisibility", colVisibility);
if (sValue == null) return null;
return VISIBILITY.valueOf(sValue);
if (sValue != null) {
return VISIBILITY.valueOf(sValue);
}
return VISIBILITY.getVisibility(this);
}

@Override
Expand Down
8 changes: 6 additions & 2 deletions fotolib2/src/main/java/de/k3b/media/PhotoPropertiesUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2020 by k3b.
* Copyright (c) 2016-2021 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down Expand Up @@ -317,10 +317,14 @@ public static boolean isImage(String path, int imageTypeFlags) {
}

return (IMG_TYPE_PRIVATE == (imageTypeFlags & IMG_TYPE_PRIVATE)) &&
(lcPath.endsWith(EXT_JPG_PRIVATE));
isPrivateImage(lcPath);

}

public static boolean isPrivateImage(String filePath) {
return filePath != null && filePath.endsWith(EXT_JPG_PRIVATE);
}

/** returns the full path that item should get or null if path is already ok */
public static String getModifiedPath(IPhotoProperties item) {
if (item != null) {
Expand Down

0 comments on commit 8e1f533

Please sign in to comment.