From 191858121b0f3b30c1a9a7e154aba8effea94a44 Mon Sep 17 00:00:00 2001 From: chaneylc Date: Thu, 12 Sep 2024 11:57:27 -0500 Subject: [PATCH 1/3] cloud import fixes cloud files couldn't be imported when clicking the arrow next to the cloud provider in the google file chooser fix for cloud names showing as UUID --- .../activities/FieldEditorActivityOld.java | 11 ++++++++++- .../tracker/objects/FieldFileObject.java | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/fieldbook/tracker/activities/FieldEditorActivityOld.java b/app/src/main/java/com/fieldbook/tracker/activities/FieldEditorActivityOld.java index 3abdd2321..933392aa2 100644 --- a/app/src/main/java/com/fieldbook/tracker/activities/FieldEditorActivityOld.java +++ b/app/src/main/java/com/fieldbook/tracker/activities/FieldEditorActivityOld.java @@ -598,7 +598,7 @@ private void showFieldFileDialog(final String chosenFile, Boolean isCloud) { DocumentFile importDoc = DocumentFile.fromSingleUri(this, docUri); - if (importDoc != null && importDoc.exists()) { + if (importDoc != null) { ContentResolver resolver = getContentResolver(); if (resolver != null) { @@ -606,6 +606,8 @@ private void showFieldFileDialog(final String chosenFile, Boolean isCloud) { String cloudName = null; if (isCloud != null && isCloud) { cloudName = getFileName(Uri.parse(chosenFile)); + } else { + if (!importDoc.exists()) return; } try (InputStream is = resolver.openInputStream(docUri)) { @@ -613,6 +615,13 @@ private void showFieldFileDialog(final String chosenFile, Boolean isCloud) { fieldFile = FieldFileObject.create(this, docUri, is, cloudName); String fieldFileName = fieldFile.getStem(); + if (isCloud != null && isCloud) { + int index = cloudName.lastIndexOf("."); + if (index > -1) { + cloudName = cloudName.substring(0, index); + } + fieldFile.setName(cloudName); + } Editor e = preferences.edit(); e.putString(GeneralKeys.FIELD_FILE, fieldFileName); diff --git a/app/src/main/java/com/fieldbook/tracker/objects/FieldFileObject.java b/app/src/main/java/com/fieldbook/tracker/objects/FieldFileObject.java index 8848fb831..bf6bd70c9 100644 --- a/app/src/main/java/com/fieldbook/tracker/objects/FieldFileObject.java +++ b/app/src/main/java/com/fieldbook/tracker/objects/FieldFileObject.java @@ -67,6 +67,8 @@ public abstract static class FieldFileBase { private final Uri path_; private final Context ctx; + private String name; + FieldFileBase(final Context ctx, final Uri path) { this.ctx = ctx; path_ = path; @@ -146,8 +148,13 @@ public final boolean hasSpecialCharacters() { public FieldObject createFieldObject() { FieldObject f = new FieldObject(); - f.setExp_name(this.getStem()); - f.setExp_alias(this.getStem()); + if (name == null) { + f.setExp_name(this.getStem()); + f.setExp_alias(this.getStem()); + } else { + f.setExp_name(name); + f.setExp_alias(name); + } f.setExp_source(this.getFileStem()); f.setImport_format(ImportFormat.fromString(getExtension(this.getFileStem()))); return f; @@ -157,6 +164,10 @@ public boolean getOpenFailed() { return openFail; } + public void setName(String name) { this.name = name; } + + public String getName() { return name; } + abstract public boolean isCSV(); abstract public boolean isExcel(); From 07e4946d29d5a1d6f4f6231274f059b093a64025 Mon Sep 17 00:00:00 2001 From: chaneylc Date: Thu, 12 Sep 2024 12:22:05 -0500 Subject: [PATCH 2/3] fixed source and import format columns for cloud files --- .../tracker/objects/FieldFileObject.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/fieldbook/tracker/objects/FieldFileObject.java b/app/src/main/java/com/fieldbook/tracker/objects/FieldFileObject.java index bf6bd70c9..eca7981d6 100644 --- a/app/src/main/java/com/fieldbook/tracker/objects/FieldFileObject.java +++ b/app/src/main/java/com/fieldbook/tracker/objects/FieldFileObject.java @@ -61,6 +61,19 @@ public static String getExtension(final String path) { return path.substring(first).toLowerCase(); } + public static String getExtensionFromClass(FieldFileBase fieldFile) { + + if (fieldFile instanceof FieldFileCSV) { + return "csv"; + } else if (fieldFile instanceof FieldFileExcel) { + return "xls"; + } else if (fieldFile instanceof FieldFileXlsx) { + return "xlsx"; + } else { + return ""; + } + } + public abstract static class FieldFileBase { boolean openFail; boolean specialCharactersFail; @@ -151,12 +164,14 @@ public FieldObject createFieldObject() { if (name == null) { f.setExp_name(this.getStem()); f.setExp_alias(this.getStem()); + f.setExp_source(this.getFileStem()); + f.setImport_format(ImportFormat.fromString(getExtension(this.getFileStem()))); } else { f.setExp_name(name); f.setExp_alias(name); + f.setExp_source(name + "." + getExtensionFromClass(this)); + f.setImport_format(ImportFormat.fromString(getExtensionFromClass(this))); } - f.setExp_source(this.getFileStem()); - f.setImport_format(ImportFormat.fromString(getExtension(this.getFileStem()))); return f; } From bd7d9aff67e5322b710906f71244e981013ccb91 Mon Sep 17 00:00:00 2001 From: trife Date: Fri, 13 Sep 2024 13:08:04 -0400 Subject: [PATCH 3/3] apply fix to new field editor activity --- .../tracker/activities/FieldEditorActivity.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/fieldbook/tracker/activities/FieldEditorActivity.java b/app/src/main/java/com/fieldbook/tracker/activities/FieldEditorActivity.java index 6470e5da1..01a0dd699 100644 --- a/app/src/main/java/com/fieldbook/tracker/activities/FieldEditorActivity.java +++ b/app/src/main/java/com/fieldbook/tracker/activities/FieldEditorActivity.java @@ -767,7 +767,7 @@ private void showFieldFileDialog(final String chosenFile, Boolean isCloud) { DocumentFile importDoc = DocumentFile.fromSingleUri(this, docUri); - if (importDoc != null && importDoc.exists()) { + if (importDoc != null) { ContentResolver resolver = getContentResolver(); if (resolver != null) { @@ -775,6 +775,8 @@ private void showFieldFileDialog(final String chosenFile, Boolean isCloud) { String cloudName = null; if (isCloud != null && isCloud) { cloudName = getFileName(Uri.parse(chosenFile)); + } else { + if (!importDoc.exists()) return; } try (InputStream is = resolver.openInputStream(docUri)) { @@ -782,10 +784,16 @@ private void showFieldFileDialog(final String chosenFile, Boolean isCloud) { fieldFile = FieldFileObject.create(this, docUri, is, cloudName); String fieldFileName = fieldFile.getStem(); + if (isCloud != null && isCloud) { + int index = cloudName.lastIndexOf("."); + if (index > -1) { + cloudName = cloudName.substring(0, index); + } + fieldFile.setName(cloudName); + } Editor e = preferences.edit(); e.putString(GeneralKeys.FIELD_FILE, fieldFileName); - e.putString(GeneralKeys.FIELD_ALIAS, fieldFileName); e.apply(); if (database.checkFieldName(fieldFileName) >= 0) {