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:
@@ -204,8 +204,9 @@ class LOKitThread extends Thread {
|
|||||||
/**
|
/**
|
||||||
* Handle load document event.
|
* Handle load document event.
|
||||||
* @param filePath - filePath to where the document is located
|
* @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();
|
mLayerClient = mContext.getLayerClient();
|
||||||
|
|
||||||
mInvalidationHandler = new InvalidationHandler(mContext);
|
mInvalidationHandler = new InvalidationHandler(mContext);
|
||||||
@@ -216,8 +217,10 @@ class LOKitThread extends Thread {
|
|||||||
updateZoomConstraints();
|
updateZoomConstraints();
|
||||||
refresh(true);
|
refresh(true);
|
||||||
LOKitShell.hideProgressSpinner(mContext);
|
LOKitShell.hideProgressSpinner(mContext);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
closeDocument();
|
closeDocument();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,20 +230,9 @@ class LOKitThread extends Thread {
|
|||||||
* @param fileType - fileType what type of new document is to be loaded
|
* @param fileType - fileType what type of new document is to be loaded
|
||||||
*/
|
*/
|
||||||
private void loadNewDocument(String filePath, String fileType) {
|
private void loadNewDocument(String filePath, String fileType) {
|
||||||
mLayerClient = mContext.getLayerClient();
|
boolean ok = loadDocument(fileType);
|
||||||
|
if (ok) {
|
||||||
mInvalidationHandler = new InvalidationHandler(mContext);
|
|
||||||
mTileProvider = TileProviderFactory.create(mContext, mInvalidationHandler, fileType);
|
|
||||||
|
|
||||||
if (mTileProvider.isReady()) {
|
|
||||||
LOKitShell.showProgressSpinner(mContext);
|
|
||||||
updateZoomConstraints();
|
|
||||||
refresh(true);
|
|
||||||
LOKitShell.hideProgressSpinner(mContext);
|
|
||||||
|
|
||||||
mTileProvider.saveDocumentAs(filePath, true);
|
mTileProvider.saveDocumentAs(filePath, true);
|
||||||
} else {
|
|
||||||
closeDocument();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user