Skip to content

Commit

Permalink
#169: lib-test
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed Apr 25, 2020
1 parent 2c5f509 commit af35237
Show file tree
Hide file tree
Showing 23 changed files with 688 additions and 307 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.tagDB.TagSql;
import de.k3b.database.QueryParameter;
import de.k3b.io.FileFacade;
import de.k3b.io.IFile;
import de.k3b.io.IItemSaver;
import de.k3b.io.IProgessListener;
import de.k3b.io.StringUtils;
Expand Down Expand Up @@ -126,10 +128,10 @@ public IZipConfig execute() {
boolean addPhotos = BackupOptions.allOf(jobOptions, BackupOptions.PHOTOS_WITH_EXISTING_XMP);
if (addPhotos) {
// pipline for (IPhotoProperties item: query(filter)) : Zip+=File(item)
final IItemSaver<File> file2ZipSaver = new IItemSaver<File>() {
final IItemSaver<IFile> file2ZipSaver = new IItemSaver<IFile>() {
@Override
public boolean save(File item) {
CompressItem compressItem = job.addToCompressQue("", item);
public boolean save(IFile item) {
CompressItem compressItem = addCompressItem((FileFacade) item);
/*
if (PhotoPropertiesUtil.isImage(item.getName(), PhotoPropertiesUtil.IMG_TYPE_COMPRESSED)) {
// performance improvement: jpg-s should not be compressed
Expand Down Expand Up @@ -171,6 +173,12 @@ public boolean save(File item) {
return null;
}

// TODO add IFile to job
@Deprecated
public CompressItem addCompressItem(FileFacade item) {
return job.addToCompressQue("", item.getFile());
}

/**
* @return get query without filte-DateModified-min/max and with added zipConfig.getDateModifiedFrom
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@
import de.k3b.database.QueryParameter;
import de.k3b.geo.api.GeoPointDto;
import de.k3b.geo.io.GeoUri;
import de.k3b.io.FileFacade;
import de.k3b.io.FileProcessor;
import de.k3b.io.FileUtils;
import de.k3b.io.GalleryFilterParameter;
import de.k3b.io.IDirectory;
import de.k3b.io.IFile;
import de.k3b.io.StringUtils;
import de.k3b.io.collections.SelectedFiles;
import de.k3b.media.PhotoPropertiesUtil;
Expand Down Expand Up @@ -121,6 +123,7 @@ public class ImageDetailActivityViewPager extends BaseActivity implements Common
/** if smaller that these millisecs then the actionbar autohide is disabled */
private static final int DISABLE_HIDE_ACTIONBAR = 700;
private static final int NOMEDIA_GALLERY = 8227;
private static final String MIME = "*/*";

// how many changes have been made. if != 0 parent activity must invalidate cached data
private static int mModifyCount = 0;
Expand Down Expand Up @@ -667,28 +670,28 @@ private boolean checkForIncompleteMediaDatabase(String jpgFullFilePath, String w

private void onRenameFileAnswer(final CharSequence title, final SelectedFiles currentFoto, final long fotoId,
final String fotoSourcePath, final String newFileName) {
File src = new File(fotoSourcePath);
File dest = new File(src.getParentFile(), newFileName);
IFile src = FileFacade.convert(new File(fotoSourcePath));
IFile dest = src.getParentFile().create(newFileName, src.getMime());

File srcXmpShort = FileProcessor.getSidecar(src, false);
IFile srcXmpShort = FileProcessor.getSidecar(src, false);
boolean hasSideCarShort = ((srcXmpShort != null) && (mFileCommands.osFileExists(srcXmpShort)));
File srcXmpLong = FileProcessor.getSidecar(src, true);
IFile srcXmpLong = FileProcessor.getSidecar(src, true);
boolean hasSideCarLong = ((srcXmpLong != null) && (mFileCommands.osFileExists(srcXmpLong)));

File destXmpShort = FileProcessor.getSidecar(dest, false);
File destXmpLong = FileProcessor.getSidecar(dest, true);
IFile destXmpShort = FileProcessor.getSidecar(dest, false);
IFile destXmpLong = FileProcessor.getSidecar(dest, true);

if (src.equals(dest)) return; // new name == old name ==> nothing to do

String errorMessage = null;
if (hasSideCarShort && mFileCommands.osFileExists(destXmpShort)) {
errorMessage = getString(R.string.image_err_file_exists_format, destXmpShort.getAbsoluteFile());
errorMessage = getString(R.string.image_err_file_exists_format, destXmpShort.getAbsolutePath());
}
if (hasSideCarLong && mFileCommands.osFileExists(destXmpLong)) {
errorMessage = getString(R.string.image_err_file_exists_format, destXmpLong.getAbsoluteFile());
errorMessage = getString(R.string.image_err_file_exists_format, destXmpLong.getAbsolutePath());
}
if (mFileCommands.osFileExists(dest)) {
errorMessage = getString(R.string.image_err_file_exists_format, dest.getAbsoluteFile());
errorMessage = getString(R.string.image_err_file_exists_format, dest.getAbsolutePath());
}

PhotoChangeNotifyer.setPhotoChangedListener(this);
Expand All @@ -700,16 +703,16 @@ private void onRenameFileAnswer(final CharSequence title, final SelectedFiles cu
mModifyCount++;
} else {
// rename failed
errorMessage = getString(R.string.image_err_file_rename_format, src.getAbsoluteFile());
errorMessage = getString(R.string.image_err_file_rename_format, src.getAbsolutePath());
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
}
}

private boolean osRenameTo(final CharSequence title, final File dest, final SelectedFiles currentFoto) {
private boolean osRenameTo(final CharSequence title, final IFile dest, final SelectedFiles currentFoto) {
// close rename dialog to allow messagebox that prepares to ask
closeDialogIfNeeded();
File missingRoot = getMissingRootDirFileOrNull(
"ImageDetailActivityViewPager.osRenameTo", currentFoto.getFiles());
IFile missingRoot = getMissingRootDirFileOrNull(
"ImageDetailActivityViewPager.osRenameTo", currentFoto.getIFiles());
if (missingRoot != null) {
// ask for needed permissions
requestRootUriDialog(missingRoot, title,
Expand Down Expand Up @@ -1090,22 +1093,22 @@ private void onRenameSubDirAnswer(final CharSequence title, SelectedFiles curren
File src = new File(fotoSourcePath);
File dest = new File(src.getParentFile(), newFileName);

File srcXmpShort = FileProcessor.getSidecar(src, false);
IFile srcXmpShort = FileProcessor.getSidecar(src, false);
boolean hasSideCarShort = ((srcXmpShort != null) && (mFileCommands.osFileExists(srcXmpShort)));
File srcXmpLong = FileProcessor.getSidecar(src, true);
IFile srcXmpLong = FileProcessor.getSidecar(src, true);
boolean hasSideCarLong = ((srcXmpLong != null) && (mFileCommands.osFileExists(srcXmpLong)));

File destXmpShort = FileProcessor.getSidecar(dest, false);
File destXmpLong = FileProcessor.getSidecar(dest, true);
IFile destXmpShort = FileProcessor.getSidecar(dest, false);
IFile destXmpLong = FileProcessor.getSidecar(dest, true);

if (src.equals(dest)) return; // new name == old name ==> nothing to do

String errorMessage = null;
if (hasSideCarShort && mFileCommands.osFileExists(destXmpShort)) {
errorMessage = getString(R.string.image_err_file_exists_format, destXmpShort.getAbsoluteFile());
errorMessage = getString(R.string.image_err_file_exists_format, destXmpShort.getAbsolutePath());
}
if (hasSideCarLong && mFileCommands.osFileExists(destXmpLong)) {
errorMessage = getString(R.string.image_err_file_exists_format, destXmpLong.getAbsoluteFile());
errorMessage = getString(R.string.image_err_file_exists_format, destXmpLong.getAbsolutePath());
}
if (mFileCommands.osFileExists(dest)) {
errorMessage = getString(R.string.image_err_file_exists_format, dest.getAbsoluteFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import de.k3b.android.androFotoFinder.queries.IMediaRepositoryApi;
import de.k3b.android.io.AndroidFileCommands;
import de.k3b.io.FileCommands;
import de.k3b.io.IFile;
import de.k3b.io.IProgessListener;
import de.k3b.io.collections.SelectedFiles;
import de.k3b.media.MediaFormatter;
Expand Down Expand Up @@ -65,7 +66,7 @@ public TagWorflow init(Activity context, SelectedFiles selectedItems, List<Tag>
this.items = loadTagWorflowItems(context, (selectedItems == null) ? null : selectedItems.toIdString(), anyOfTags);
for (TagSql.TagWorflowItem item : items) {
List<String> tags = item.tags;
File xmpFile = FileCommands.getExistingSidecarOrNull(item.path);
IFile xmpFile = FileCommands.getExistingSidecarOrNull(item.path);
if ((xmpFile != null) && xmpFile.exists() && (item.xmpLastModifiedDate < xmpFile.lastModified())){ // || (tags == null) || (tags.size() == 0)) {
// xmp has been updated since last db update.
tags = loadTags(xmpFile);
Expand Down Expand Up @@ -170,13 +171,13 @@ public boolean onProgress(int itemCount, int total, String message) {
return true;
}

private List<String> loadTags(File xmpFile) {
private List<String> loadTags(IFile xmpFile) {
PhotoPropertiesXmpSegment xmp = loadXmp(xmpFile);
return (xmp == null) ? null : xmp.getTags();
}

@NonNull
private PhotoPropertiesXmpSegment loadXmp(File xmpFile) {
private PhotoPropertiesXmpSegment loadXmp(IFile xmpFile) {
if ((xmpFile != null) && (xmpFile.exists())) {
try {
PhotoPropertiesXmpSegment xmp = new PhotoPropertiesXmpSegment();
Expand Down
11 changes: 1 addition & 10 deletions app/src/main/java/de/k3b/android/io/AndroidFileFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ public static void setContext(DocumentFileTranslator documentFileTranslator) {
AndroidFileFacade.documentFileTranslator = documentFileTranslator;
}

public static AndroidFileFacade[] get(File[] files) {
AndroidFileFacade f[] = new AndroidFileFacade[files.length];
for (int i = 0; i < files.length; i++) {
f[i] = new AndroidFileFacade(files[i]);
}

return f;
}

@Override
public boolean renameTo(IFile newName) {
if (exists() && !newName.exists()) {
Expand All @@ -71,7 +62,7 @@ public boolean renameTo(IFile newName) {
}

if (copyImpl((AndroidFileFacade) newName, true)) {
setFile(((AndroidFileFacade) newName).getFile());
setFile(newName.getFile());
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
import de.k3b.android.androFotoFinder.Global;
import de.k3b.android.androFotoFinder.R;
import de.k3b.android.io.DocumentFileTranslator;
import de.k3b.io.FileFacade;
import de.k3b.io.FileNameUtil;
import de.k3b.io.IFile;

/**
* Manage permission
Expand Down Expand Up @@ -132,19 +134,23 @@ private static void execRequestRootUri(
parent.startActivityForResult(intent, REQUEST_ROOT_DIR);
}

@Deprecated
public File getMissingRootDirFileOrNull(String dbgContext, File... dirs) {
return getMissingRootDirFileOrNull(dbgContext, FileFacade.get(dirs)).getFile();
}
/**
*
* @param dbgContext
* @param dirs where the permissions are needed.
* @return null if all permissions are granted or
* the root file that has not permissions yet.
*/
public File getMissingRootDirFileOrNull(String dbgContext, File... dirs) {
public IFile getMissingRootDirFileOrNull(String dbgContext, IFile... dirs) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
for (int i = dirs.length - 1; i >= 0; i--) {
final File dir = dirs[i];
final IFile dir = dirs[i];
if (!getDocumentFileTranslator().isKnownRoot(dir)) {
final File anddroidRootDir = FileNameUtil.getAnddroidRootDir(dir);
final IFile anddroidRootDir = FileNameUtil.getAnddroidRootDir(dir);
if (DocumentFileTranslator.debugDocFile) {
Log.i(TAG, dbgContext + ":" + this.documentFileTranslator
+ ":getMissingRootDirFileOrNull(" + dir
Expand Down
22 changes: 14 additions & 8 deletions fastlane/fd2fastlane.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@


def save_to_wiki_homepage(title, short_description, full_description, android_locale):
if ((len(WIKI_OUT_ROOT) > 0) and (len(android_locale) > 0)):
if ((mylen(WIKI_OUT_ROOT) > 0) and (mylen(android_locale) > 0)):
label = f'<!--!!generated from .../values{android_locale}/fdroid.xml!!-->';
homepate_locale = translate_locale(android_locale, LANG_ANDROID_TO_WIKI)
filename = homepate_locale + '-home.md'
Expand All @@ -90,7 +90,7 @@ def save_to_wiki_homepage(title, short_description, full_description, android_lo
# does not exist or was autogenerated: overwrite

md = generate_wiki_homepage(label, title, short_description, full_description)
# print(f'\t{full_md_path[-10:]}\t{oldContent[:10]}\t{len(oldContent)} {label}')
# print(f'\t{full_md_path[-10:]}\t{oldContent[:10]}\t{mylen(oldContent)} {label}')
save_to_file(md, WIKI_OUT_ROOT, filename)


Expand All @@ -111,7 +111,7 @@ def generate_wiki_homepage(label, title, short_description, full_description):


def save_to_app_about(title, short_description, full_description, android_locale):
if (len(APP_OUT_RES_ROOT) > 0) and (len(android_locale) > 0):
if (mylen(APP_OUT_RES_ROOT) > 0) and (mylen(android_locale) > 0):
label = f'<!--!!generated from .../values{android_locale}/fdroid.xml!!-->';
dir = os.path.join(APP_OUT_RES_ROOT, "values" + android_locale)
filename = "html-pages.xml"
Expand All @@ -127,7 +127,7 @@ def save_to_app_about(title, short_description, full_description, android_locale
# does not exist or was autogenerated: overwrite
md = generate_app_about(label, title, short_description,
full_description.replace("\"", "\\\""))
# print(f'\t{full_md_path[-10:]}\t{oldContent[:10]}\t{len(oldContent)} {label}')
# print(f'\t{full_md_path[-10:]}\t{oldContent[:10]}\t{mylen(oldContent)} {label}')
save_to_file(md, dir, filename)


Expand Down Expand Up @@ -165,7 +165,7 @@ def process_translation(fdroid_xml, android_locale):
# print(android_locale + '\t' + fastlane_locale + '\t' + fdroid_xml)
root = ElementTree.parse(fdroid_xml).getroot()
title = getElementText(root, './/string[@name="title"]', 50, fdroid_xml)
if len(DEFAULT_APP_TITLE) > 0 and len(title) > 0 and title.find(DEFAULT_APP_TITLE) < 0:
if mylen(DEFAULT_APP_TITLE) > 0 and mylen(title) > 0 and title.find(DEFAULT_APP_TITLE) < 0:
title = DEFAULT_APP_TITLE + " (" + title + ")"

short_description = getElementText(root, './/string[@name="short_description"]', 80,
Expand All @@ -179,7 +179,7 @@ def process_translation(fdroid_xml, android_locale):
save_to_file(short_description, cur_fastlane_out_dir, 'short_description.txt')

if (full_description is not None):
if len(title) == 0:
if mylen(title) == 0:
title = DEFAULT_APP_TITLE

html = markdown.markdown(full_description)
Expand All @@ -192,7 +192,7 @@ def translate_locale(android_locale, locale_map):
result_locale = ""
if android_locale in locale_map.keys():
result_locale = locale_map[android_locale]
elif (len(android_locale) == 3):
elif (mylen(android_locale) == 3):
# if not found: translate '-de' to 'de'
result_locale = android_locale[1:]
return result_locale
Expand All @@ -219,12 +219,18 @@ def save_to_file(content, directory_path, filename):
def clean_text(text, limit=0, context=''):
# remove leading/trailing blanks and string delimiter, unescape String delimiter
text = text.strip("\s\"'").replace('\\\'', '\'').replace('\\\"', '\"')
if limit != 0 and len(text) > limit:
if limit != 0 and mylen(text) > limit:
print(context + " Warning: Text longer than %d characters, ignoring..." % limit)
# text = text[:limit]
return text


def mylen(item):
if item is None:
return 0
return len(item)


def main():
path = os.path.join(PATH, FD_SRC_PATH_ROOT, 'values*/fdroid.xml')

Expand Down
Loading

0 comments on commit af35237

Please sign in to comment.