Skip to content

Commit

Permalink
Work on adapt-it#539
Browse files Browse the repository at this point in the history
- Use chooser plugin to select project files (same work done for adapt-it#538).
- Allow project import from clipboard (not a huge use case, but the work was already done for basic file import)
- Add .aic filetype to Android supported file type lists
Work still in progress.
  • Loading branch information
eb1 committed Dec 21, 2023
1 parent 40972a9 commit b08c46c
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 58 deletions.
6 changes: 5 additions & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,36 @@
<data android:scheme="content" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<!-- our mimeType is really broad; limit to our 6 supported filetypes
<!-- our mimeType is really broad; limit to our 7 supported filetypes
(and work around Android's ugly path pattern matching system) -->
<data android:pathPattern=".*\\.xml" />
<data android:pathPattern=".*\\.tmx" />
<data android:pathPattern=".*\\.txt" />
<data android:pathPattern=".*\\.usfm" />
<data android:pathPattern=".*\\.sfm" />
<data android:pathPattern=".*\\.usx" />
<data android:pathPattern=".*\\.aic" />
<data android:pathPattern=".*\\..*\\.xml" />
<data android:pathPattern=".*\\..*\\.tmx" />
<data android:pathPattern=".*\\..*\\.txt" />
<data android:pathPattern=".*\\..*\\.usfm" />
<data android:pathPattern=".*\\..*\\.sfm" />
<data android:pathPattern=".*\\..*\\.usx" />
<data android:pathPattern=".*\\..*\\.aic" />
<data android:pathPattern=".*\\..*\\..*\\.xml" />
<data android:pathPattern=".*\\..*\\..*\\.tmx" />
<data android:pathPattern=".*\\..*\\..*\\.txt" />
<data android:pathPattern=".*\\..*\\..*\\.usfm" />
<data android:pathPattern=".*\\..*\\..*\\.sfm" />
<data android:pathPattern=".*\\..*\\..*\\.usx" />
<data android:pathPattern=".*\\..*\\..*\\.aic" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.xml" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.tmx" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.txt" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.usfm" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.sfm" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.usx" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.aic" />
</intent-filter>
</config-file>
<icon density="ldpi" src="www/res/icon/android/ldpi.png" />
Expand Down
28 changes: 8 additions & 20 deletions www/js/views/DocumentViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define(function (require) {
Backbone = require('backbone'),
Marionette = require('marionette'),
i18n = require('i18n'),
ProjectViews = require('app/views/ProjectViews'),
tplLoadingPleaseWait = require('text!tpl/LoadingPleaseWait.html'),
tplImportDoc = require('text!tpl/CopyOrImport.html'),
tplExportDoc = require('text!tpl/Export.html'),
Expand All @@ -30,9 +31,7 @@ define(function (require) {
scrIDs = require('utils/scrIDs'),
USFM = require('utils/usfm'),
kblist = null, // populated in onShow
isPortion = false, // Scripture portion support
bookName = "",
cbData = "", // clipboard text (so we call it once)
scrID = "",
fileName = "",
versionSpec = "", // file type specification version (2.5, 3.0, etc.)
Expand Down Expand Up @@ -3081,18 +3080,6 @@ define(function (require) {
var tmpMk = "";
var num = /\d/;

// // set the lastDocument / lastAdapted<xxx> values if not already set
// if (project.get('lastDocument') === "") {
// project.set('lastDocument', bookName);
// }
// if (project.get('lastAdaptedBookID') === 0) {
// project.set('lastAdaptedBookID', bookID);
// project.set('lastAdaptedChapterID', chapterID);
// }
// if (project.get('lastAdaptedName') === "") {
// project.set('lastAdaptedName', chapterName);
// }

// build SourcePhrases
arr = contents.replace(/\\/gi, " \\").split(spaceRE); // add space to make sure markers get put in a separate token
arrSP = contents.replace(/\\/gi, " \\").split(nonSpaceRE); // add space to make sure markers get put in a separate token
Expand Down Expand Up @@ -3873,6 +3860,9 @@ define(function (require) {
result = readTextDoc(contents);
}
}
} else if (fileName.toLowerCase().indexOf(".aic") > 0) {
// project settings file reader is held in ProjectViews - call it
result = ProjectViews.importSettingsFile({model: proj});
} else {
if (isClipboard === true) {
// this came from the clipboard -- we'll need to do some tests to try to identify the content type.
Expand Down Expand Up @@ -6308,17 +6298,14 @@ define(function (require) {
function (error) {
console.log("resolveLocalFileSystemURL error: " + error.code);
});
// importFile(file, model);
}
}, function (error) {
// error in clipboard retrieval -- skip entry
// (seen this when there's data on the clipboard that isn't text/plain)
console.log("Error retrieving clipboard data:" + error);
DirsRemaining--;
// Log the error
console.log("CopyProjectView::onBtnBrowse getFile() error: " + error);
});
},
// Handler for when the user clicks the "clipboard text" option;
// copy the clipboard contents, and if they're not empty, import the contents as a file
// copy the clipboard contents, and if they're not empty, try to import the contents as a file
onBtnClipboard: function () {
var model = this.model;
// Are we in the browser or on a mobile device?
Expand Down Expand Up @@ -6365,6 +6352,7 @@ define(function (require) {
navigator.clipboard.readText().then(
(clipText) => {
if (clipText.length > 0) {
var clipboardFile = new Blob([clipText], {type: "text/plain"});
isClipboard = true;
console.log("Non-empty clipboard selected. Creating ad hoc file from text.");
// replace the selection UI with the import UI
Expand Down
Loading

0 comments on commit b08c46c

Please sign in to comment.