Skip to content

Commit bd72cf8

Browse files
committed
deploy core; cleanup odf loader
1 parent b233734 commit bd72cf8

6 files changed

Lines changed: 36 additions & 20 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ tasks.register('conanProfile', Copy) {
2222
profile.set('build/conanprofile.txt')
2323
deployer.set('conandeployer.py')
2424
deployerFolder.set(outputDirectory.get().asFile.toString() + "/assets")
25-
conanExecutable.set('/Users/andreas/odr/venv/bin/conan')
2625
dependsOn(tasks.named('conanProfile'))
2726
}
2827
}
@@ -151,6 +150,7 @@ dependencies {
151150
implementation 'app.opendocument:pdf2htmlex-android:0.18.26'
152151
implementation 'app.opendocument:wvware-android:1.2.11'
153152
implementation 'com.github.huzongyao:AndroidMagic:v1.1.2'
153+
implementation 'com.viliussutkus89:assetextractor-android:1.3.3'
154154

155155
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
156156
androidTestImplementation 'androidx.test:rules:1.6.1'

app/conandeployer.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ def deploy(graph, output_folder: str, **kwargs):
1515

1616
print(f"Dependencies: {list(deps.keys())}")
1717

18+
copytree_kwargs = {"symlinks": symlinks, "dirs_exist_ok": True}
19+
1820
if "odrcore" in deps:
1921
dep = deps["odrcore"]
2022
conanfile.output.info(f"Deploying odrcore to {output_folder}")
21-
# nothing to deploy so far
22-
23-
copytree_kwargs = {"symlinks": symlinks, "dirs_exist_ok": True}
23+
shutil.copytree(
24+
f"{dep.package_folder}/share",
25+
f"{output_folder}/odrcore",
26+
**copytree_kwargs,
27+
)
2428

2529
if "pdf2htmlex" in deps:
2630
dep = deps["pdf2htmlex"]

app/src/main/java/at/tomtasche/reader/background/CoreHttpLoader.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import android.content.Context;
44
import android.net.Uri;
55

6+
import com.viliussutkus89.android.assetextractor.AssetExtractor;
7+
68
import java.io.File;
79

810
import at.tomtasche.reader.nonfree.ConfigManager;
@@ -17,6 +19,10 @@ public CoreHttpLoader(Context context, ConfigManager configManager) {
1719
super(context, LoaderType.CORE);
1820

1921
this.configManager = configManager;
22+
23+
AssetExtractor ae = new AssetExtractor(context.getAssets());
24+
ae.setNoOverwrite();
25+
ae.extract(new File(context.getFilesDir(), "assets"), ".");
2026
}
2127

2228
@Override

app/src/main/java/at/tomtasche/reader/background/OdrCoreLoader.java renamed to app/src/main/java/at/tomtasche/reader/background/CoreLoader.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import android.net.Uri;
55
import android.webkit.MimeTypeMap;
66

7+
import com.viliussutkus89.android.assetextractor.AssetExtractor;
8+
79
import java.io.File;
810

911
import at.tomtasche.reader.nonfree.ConfigManager;
1012

11-
public class OdrCoreLoader extends FileLoader {
13+
public class CoreLoader extends FileLoader {
1214

1315
private final ConfigManager configManager;
1416

@@ -17,11 +19,15 @@ public class OdrCoreLoader extends FileLoader {
1719

1820
private final boolean doOoxml;
1921

20-
public OdrCoreLoader(Context context, ConfigManager configManager, boolean doOOXML) {
22+
public CoreLoader(Context context, ConfigManager configManager, boolean doOOXML) {
2123
super(context, LoaderType.CORE);
2224

2325
this.configManager = configManager;
2426
this.doOoxml = doOOXML;
27+
28+
AssetExtractor ae = new AssetExtractor(context.getAssets());
29+
ae.setNoOverwrite();
30+
ae.extract(new File(context.getFilesDir(), "assets"), ".");
2531
}
2632

2733
@Override

app/src/main/java/at/tomtasche/reader/background/LoaderService.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class LoaderService extends Service implements FileLoader.FileLoaderListe
3434
private AnalyticsManager analyticsManager;
3535

3636
private MetadataLoader metadataLoader;
37-
private OdrCoreLoader odrCoreLoader;
37+
private CoreLoader coreLoader;
3838
private Pdf2htmlExLoader pdf2htmlExLoader;
3939
private WvwareDocLoader wvwareDocLoader;
4040
private RawLoader rawLoader;
@@ -63,8 +63,8 @@ public synchronized void onCreate() {
6363
metadataLoader = new MetadataLoader(context);
6464
metadataLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
6565

66-
odrCoreLoader = new OdrCoreLoader(context, configManager, true);
67-
odrCoreLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
66+
coreLoader = new CoreLoader(context, configManager, true);
67+
coreLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
6868

6969
pdf2htmlExLoader = new Pdf2htmlExLoader(context);
7070
pdf2htmlExLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
@@ -75,7 +75,7 @@ public synchronized void onCreate() {
7575
rawLoader = new RawLoader(context);
7676
rawLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
7777

78-
onlineLoader = new OnlineLoader(context, odrCoreLoader);
78+
onlineLoader = new OnlineLoader(context, coreLoader);
7979
onlineLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
8080

8181
coreHttpLoader = new CoreHttpLoader(context, configManager);
@@ -135,7 +135,7 @@ public synchronized void loadWithType(FileLoader.LoaderType loaderType, FileLoad
135135
FileLoader loader;
136136
switch (loaderType) {
137137
case CORE:
138-
loader = odrCoreLoader;
138+
loader = coreLoader;
139139
break;
140140
case WVWARE:
141141
loader = wvwareDocLoader;
@@ -163,7 +163,7 @@ public synchronized void loadWithType(FileLoader.LoaderType loaderType, FileLoad
163163
public void onSuccess(FileLoader.Result result) {
164164
FileLoader.Options options = result.options;
165165
if (result.loaderType == FileLoader.LoaderType.METADATA) {
166-
if (!odrCoreLoader.isSupported(options)) {
166+
if (!coreLoader.isSupported(options)) {
167167
crashManager.log("we do not expect this file to be an ODF: " + options.originalUri.toString());
168168
analyticsManager.report("load_odf_error_expected", FirebaseAnalytics.Param.CONTENT_TYPE, options.fileType);
169169
}
@@ -248,7 +248,7 @@ private void saveSync(FileLoader.Result lastResult, Uri outFile, String htmlDiff
248248
try {
249249
File fileToSave;
250250
if (htmlDiff != null) {
251-
fileToSave = odrCoreLoader.retranslate(lastResult.options, htmlDiff);
251+
fileToSave = coreLoader.retranslate(lastResult.options, htmlDiff);
252252
if (fileToSave == null) {
253253
throw new RuntimeException("retranslate failed");
254254
}
@@ -290,8 +290,8 @@ public void onDestroy() {
290290
metadataLoader.close();
291291
}
292292

293-
if (odrCoreLoader != null) {
294-
odrCoreLoader.close();
293+
if (coreLoader != null) {
294+
coreLoader.close();
295295
}
296296

297297
if (pdf2htmlExLoader != null) {

app/src/main/java/at/tomtasche/reader/background/OnlineLoader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ public class OnlineLoader extends FileLoader {
7474
public static final String GOOGLE_VIEWER_URL = "https://docs.google.com/viewer?embedded=true&url=";
7575
public static final String MICROSOFT_VIEWER_URL = "https://view.officeapps.live.com/op/view.aspx?src=";
7676

77-
private final OdrCoreLoader odrCoreLoader;
77+
private final CoreLoader coreLoader;
7878

7979
private StorageReference storage;
8080
private FirebaseAuth auth;
8181

82-
public OnlineLoader(Context context, OdrCoreLoader odrCoreLoader) {
82+
public OnlineLoader(Context context, CoreLoader coreLoader) {
8383
super(context, LoaderType.ONLINE);
84-
this.odrCoreLoader = odrCoreLoader;
84+
this.coreLoader = coreLoader;
8585
}
8686

8787
@Override
@@ -126,7 +126,7 @@ public void loadSync(Options options) {
126126
try {
127127
Uri viewerUri;
128128
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
129-
("text/rtf".equals(options.fileType) || "application/vnd.wordperfect".equals(options.fileType) || odrCoreLoader.isSupported(options) || "application/vnd.ms-excel".equals(options.fileType) || "application/msword".equals(options.fileType) || "application/vnd.ms-powerpoint".equals(options.fileType) || options.fileType.startsWith("application/vnd.openxmlformats-officedocument.") || options.fileType.equals("application/pdf"))) {
129+
("text/rtf".equals(options.fileType) || "application/vnd.wordperfect".equals(options.fileType) || coreLoader.isSupported(options) || "application/vnd.ms-excel".equals(options.fileType) || "application/msword".equals(options.fileType) || "application/vnd.ms-powerpoint".equals(options.fileType) || options.fileType.startsWith("application/vnd.openxmlformats-officedocument.") || options.fileType.equals("application/pdf"))) {
130130
viewerUri = doOnlineConvert(options);
131131
} else {
132132
viewerUri = doFirebaseConvert(options);
@@ -206,7 +206,7 @@ private Uri doFirebaseConvert(Options options) throws ExecutionException, Interr
206206

207207
if (uploadTask.isSuccessful()) {
208208
Uri viewerUri;
209-
if (odrCoreLoader.isSupported(options)) {
209+
if (coreLoader.isSupported(options)) {
210210
// ODF does not seem to be supported by google docs viewer
211211
String downloadUrl = "https://us-central1-admob-app-id-9025061963.cloudfunctions.net/download?filePath=" + filePath;
212212

0 commit comments

Comments
 (0)