diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2021-04-09 10:08:24 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2021-04-12 07:20:36 +0200 |
commit | d8fea0b8cc92c3416df1e98d7f472e534eae38e8 (patch) | |
tree | 394adaeb378430fcdcae727d88476219c2c68e16 | |
parent | d3f8f4b1663214ebe29e49e109b1ae704b680b9e (diff) |
android: Always create a temporary local copy of the doc
Always create a local copy of the original document
to work with, rather than doing a different handling
depending on the type of the URI used to specify the
file to load.
This will also simplify adding support for "Save As"
in upcoming commits, where the temporary
file can remain the same and only the URI for the
actual document will need to be changed.
Change-Id: I2587611fa56b76d8a5384ac25c57335e8d12e987
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113882
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
-rw-r--r-- | android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index 0048bad50fd7..950a063e8d94 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -80,7 +80,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin private List<DocumentPartView> mDocumentPartView = new ArrayList<DocumentPartView>(); private DocumentPartViewListAdapter mDocumentPartViewListAdapter; private int partIndex=-1; - private File mInputFile; private DocumentOverlay mDocumentOverlay; /** URI of the actual document. */ private Uri mDocumentUri; @@ -183,38 +182,37 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin String newDocumentType = getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY); // create a temporary local file, will be copied to the actual URI when saving loadNewDocument(newDocumentType); - mInputFile = mTempFile; isReadOnlyDoc = false; - } else if (copyFileToTemp() && mTempFile != null) { - mInputFile = mTempFile; - isReadOnlyDoc = (getIntent().getFlags() & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) == 0; } else { - // TODO: can't open the file - Log.e(LOGTAG, "couldn't create temporary file from " + mDocumentUri); - return; + isReadOnlyDoc = (getIntent().getFlags() & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) == 0; } mbISReadOnlyMode = !isExperimentalMode() || isReadOnlyDoc; Log.d(LOGTAG, "SCHEME_CONTENT: getPath(): " + mDocumentUri.getPath()); String displayName = FileUtilities.retrieveDisplayNameForDocumentUri(getContentResolver(), mDocumentUri); - if (displayName.isEmpty()) { - // fall back to using temp file name - displayName = mInputFile.getName(); - } toolbarTop.setTitle(displayName); } else if (mDocumentUri.getScheme().equals(ContentResolver.SCHEME_FILE)) { - mInputFile = new File(mDocumentUri.getPath()); mbISReadOnlyMode = true; Log.d(LOGTAG, "SCHEME_FILE: getPath(): " + mDocumentUri.getPath()); - toolbarTop.setTitle(mInputFile.getName()); + toolbarTop.setTitle(mDocumentUri.getLastPathSegment()); } } else { Log.e(LOGTAG, "No document specified. This should never happen."); return; } + if (!isNewDocument) { + // create a temporary local copy to work with + boolean copyOK = copyFileToTemp() && mTempFile != null; + if (!copyOK) { + // TODO: can't open the file + Log.e(LOGTAG, "couldn't create temporary file from " + mDocumentUri); + return; + } + } + mDrawerLayout = findViewById(R.id.drawer_layout); if (mDocumentPartViewListAdapter == null) { @@ -345,12 +343,12 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin } public void saveFileToOriginalSource() { - if (isReadOnlyMode() || mInputFile == null || mDocumentUri == null || !mDocumentUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) + if (isReadOnlyMode() || mTempFile == null || mDocumentUri == null || !mDocumentUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) return; boolean copyOK = false; try { - final FileInputStream inputStream = new FileInputStream(mInputFile); + final FileInputStream inputStream = new FileInputStream(mTempFile); final OutputStream outputStream = getContentResolver().openOutputStream(mDocumentUri); copyOK = copyStream(inputStream, outputStream); } catch (FileNotFoundException e) { @@ -401,9 +399,9 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin super.onStart(); if (!isNewDocument){ if (partIndex == -1) - LOKitShell.sendLoadEvent(mInputFile.getPath()); + LOKitShell.sendLoadEvent(mTempFile.getPath()); else - LOKitShell.sendResumeEvent(mInputFile.getPath(), partIndex); + LOKitShell.sendResumeEvent(mTempFile.getPath(), partIndex); } } @@ -785,7 +783,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin // this function can only be called in InvalidationHandler.java public void setPassword() { - mTileProvider.setDocumentPassword("file://"+mInputFile.getPath(), mPassword); + mTileProvider.setDocumentPassword("file://" + mTempFile.getPath(), mPassword); } // setTileProvider is meant to let main activity have a handle of LOKit when dealing with password @@ -943,7 +941,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin public void preparePresentation() { if (getExternalCacheDir() != null) { - String tempPath = getExternalCacheDir().getPath() + "/" + mInputFile.getName() + ".svg"; + String tempPath = getExternalCacheDir().getPath() + "/" + mTempFile.getName() + ".svg"; mTempSlideShowFile = new File(tempPath); if (mTempSlideShowFile.exists() && !isDocumentChanged) { startPresentation("file://" + tempPath); |