android: Deduplicate LOKitThread#load{,New}Document

After Change-Id I15ecc2eba6c5ee441f6e14f8229594cab05dbba7
"tdf#148556 android: Don't delay refresh when loading doc",
the only thing that `LOKitThread#loadNewDocument` does
in addition to `LOKithThread#loadDocument` is to save the
newly created document (to a temp file) if loading was
successful.

So, have `loadDocument` return a boolean saying whether
loading was successful and call that method from
`loadNewDocument` to reduce duplication.

Change-Id: I9b99e011b3f5105bb60f95174de393462ff08271
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132966
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn
2022-04-13 13:52:40 +02:00
parent 4476fd51a3
commit d2572dc9d6

View File

@@ -204,8 +204,9 @@ class LOKitThread extends Thread {
/**
* Handle load document event.
* @param filePath - filePath to where the document is located
* @return Whether the document has been loaded successfully.
*/
private void loadDocument(String filePath) {
private boolean loadDocument(String filePath) {
mLayerClient = mContext.getLayerClient();
mInvalidationHandler = new InvalidationHandler(mContext);
@@ -216,8 +217,10 @@ class LOKitThread extends Thread {
updateZoomConstraints();
refresh(true);
LOKitShell.hideProgressSpinner(mContext);
return true;
} else {
closeDocument();
return false;
}
}
@@ -227,20 +230,9 @@ class LOKitThread extends Thread {
* @param fileType - fileType what type of new document is to be loaded
*/
private void loadNewDocument(String filePath, String fileType) {
mLayerClient = mContext.getLayerClient();
mInvalidationHandler = new InvalidationHandler(mContext);
mTileProvider = TileProviderFactory.create(mContext, mInvalidationHandler, fileType);
if (mTileProvider.isReady()) {
LOKitShell.showProgressSpinner(mContext);
updateZoomConstraints();
refresh(true);
LOKitShell.hideProgressSpinner(mContext);
boolean ok = loadDocument(fileType);
if (ok) {
mTileProvider.saveDocumentAs(filePath, true);
} else {
closeDocument();
}
}