Skip to content

Commit

Permalink
Merge pull request #482 from PhenoApps/hotfix/cloud_import/480
Browse files Browse the repository at this point in the history
Cloud Import Fix #480
  • Loading branch information
trife authored Aug 3, 2022
2 parents 2d28c4c + b4d6fa3 commit c11c839
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ android {
applicationId "com.fieldbook.tracker"
minSdkVersion 21
targetSdkVersion 31
versionCode = 524
versionName = '5.2.0'
versionCode = 525
versionName = '5.2.5'
multiDexEnabled true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 2) {
if (resultCode == RESULT_OK) {
final String chosenFile = data.getStringExtra("result");
showFieldFileDialog(chosenFile);
showFieldFileDialog(chosenFile, null);
}
}

if (requestCode == REQUEST_FILE_EXPLORER_CODE) {
if (resultCode == RESULT_OK) {
final String chosenFile = data.getStringExtra(FileExploreActivity.EXTRA_RESULT_KEY);
showFieldFileDialog(chosenFile);
showFieldFileDialog(chosenFile, null);
}
}

Expand Down Expand Up @@ -569,12 +569,12 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
return;
}

showFieldFileDialog(content_describer.toString());
showFieldFileDialog(content_describer.toString(), true);
}
}
}

private void showFieldFileDialog(final String chosenFile) {
private void showFieldFileDialog(final String chosenFile, Boolean isCloud) {

try {

Expand All @@ -587,33 +587,42 @@ private void showFieldFileDialog(final String chosenFile) {
ContentResolver resolver = getContentResolver();
if (resolver != null) {

InputStream inputStream = resolver.openInputStream(docUri);
String cloudName = null;
if (isCloud != null && isCloud) {
cloudName = getFileName(Uri.parse(chosenFile));
}

fieldFile = FieldFileObject.create(this, docUri, inputStream);
try(InputStream is = resolver.openInputStream(docUri)) {

String fieldFileName = fieldFile.getStem();
fieldFile = FieldFileObject.create(this, docUri, is, cloudName);

Editor e = ep.edit();
e.putString(GeneralKeys.FIELD_FILE, fieldFileName);
e.apply();
String fieldFileName = fieldFile.getStem();

if (ConfigActivity.dt.checkFieldName(fieldFileName) >= 0) {
Utils.makeToast(getApplicationContext(),getString(R.string.fields_study_exists_message));
SharedPreferences.Editor ed = ep.edit();
ed.putString(GeneralKeys.FIELD_FILE, null);
ed.putBoolean(GeneralKeys.IMPORT_FIELD_FINISHED, false);
ed.apply();
return;
}
Editor e = ep.edit();
e.putString(GeneralKeys.FIELD_FILE, fieldFileName);
e.apply();

if (fieldFile.isOther()) {
Utils.makeToast(getApplicationContext(),getString(R.string.import_error_unsupported));
}
if (ConfigActivity.dt.checkFieldName(fieldFileName) >= 0) {
Utils.makeToast(getApplicationContext(),getString(R.string.fields_study_exists_message));
SharedPreferences.Editor ed = ep.edit();
ed.putString(GeneralKeys.FIELD_FILE, null);
ed.putBoolean(GeneralKeys.IMPORT_FIELD_FINISHED, false);
ed.apply();
return;
}

//utility call creates photos, audio and thumbnails folders under a new field folder
DocumentTreeUtil.Companion.createFieldDir(this, fieldFileName);
if (fieldFile.isOther()) {
Utils.makeToast(getApplicationContext(),getString(R.string.import_error_unsupported));
}

//utility call creates photos, audio and thumbnails folders under a new field folder
DocumentTreeUtil.Companion.createFieldDir(this, fieldFileName);

loadFile(fieldFile);
loadFile(fieldFile);

} catch (Exception e) {
e.printStackTrace();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.net.Uri;
import android.provider.OpenableColumns;

import androidx.annotation.Nullable;

import com.fieldbook.tracker.utilities.CSVReader;

import org.apache.poi.ss.usermodel.Cell;
Expand All @@ -27,8 +29,15 @@

//TODO when merged with xlsx edit getColumnSet
public class FieldFileObject {
public static FieldFileBase create(final Context ctx, final Uri path, final InputStream inputStream) {
switch (getExtension(path.toString())) {
public static FieldFileBase create(final Context ctx, final Uri path,
final InputStream inputStream, @Nullable String cloudName) {

String ext = getExtension(path.toString());
if (cloudName != null) {
ext = getExtension(cloudName);
}

switch (ext) {
case "csv":
return new FieldFileCSV(ctx, path);
case "xls":
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/raw/changelog.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<changelog>

<release
date="2022-08-03"
versionCode="525"
versionName="v5.2.5">
<bugfix>Fixed an issue with cloud imports</bugfix>
</release>

<release
date="2022-07-11"
versionCode="523"
versionCode="524"
versionName="v5.2">
<new>Datagrid focuses on current entry/trait</new>
<new>Database export now exports to single zipped file</new>
Expand Down

0 comments on commit c11c839

Please sign in to comment.