From 28d820482fc37f45ec75b57b6b747e505b8eb1cf Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Thu, 1 Jul 2021 13:59:23 +0200 Subject: [PATCH 01/22] fix for amazon app store --- app/build.gradle | 5 +++-- app/src/main/AndroidManifest.xml | 4 ++-- .../reader/ui/activity/MainActivity.java | 18 ++++++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 199b093193d9..cb1733238fb4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -88,16 +88,17 @@ android { } dependencies { - implementation platform('com.google.firebase:firebase-bom:27.1.0') + implementation platform('com.google.firebase:firebase-bom:28.1.0') implementation 'com.google.firebase:firebase-storage' implementation 'com.google.firebase:firebase-auth' - implementation 'com.google.firebase:firebase-ads' implementation 'com.google.firebase:firebase-perf' implementation 'com.google.firebase:firebase-crashlytics-ndk' implementation 'com.google.firebase:firebase-inappmessaging-display' implementation 'com.google.firebase:firebase-analytics' implementation 'com.google.firebase:firebase-config' + implementation 'com.google.android.gms:play-services-ads:20.2.0' + implementation 'com.android.billingclient:billing:4.0.0' implementation 'com.google.android.play:core:1.10.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 48cf78bc950e..4b799545fda9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@ diff --git a/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java b/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java index 06622b864fd4..29bc6248fe1b 100644 --- a/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java +++ b/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java @@ -215,10 +215,8 @@ private void initializeCatchAllSwitch() { toggleComponent(strictCatchComponent, !isCatchAllEnabled); SwitchCompat catchAllSwitch = findViewById(R.id.landing_catch_all); - if (!IS_GOOGLE_ECOSYSTEM) { - LinearLayout parent = (LinearLayout) catchAllSwitch.getParent(); - parent.setVisibility(View.GONE); - } + LinearLayout parent = (LinearLayout) catchAllSwitch.getParent(); + parent.setVisibility(View.GONE); catchAllSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override @@ -312,19 +310,19 @@ private void initializeProprietaryLibraries() { } crashManager = new CrashManager(); - crashManager.setEnabled(useProprietaryLibraries); + crashManager.setEnabled(useProprietaryLibraries && IS_GOOGLE_ECOSYSTEM); crashManager.initialize(); analyticsManager = new AnalyticsManager(); - analyticsManager.setEnabled(useProprietaryLibraries); + analyticsManager.setEnabled(useProprietaryLibraries && IS_GOOGLE_ECOSYSTEM); analyticsManager.initialize(this); configManager = new ConfigManager(); - configManager.setEnabled(useProprietaryLibraries); + configManager.setEnabled(useProprietaryLibraries && IS_GOOGLE_ECOSYSTEM); configManager.initialize(); adManager = new AdManager(); - adManager.setEnabled(!IS_TESTING && useProprietaryLibraries); + adManager.setEnabled(!IS_TESTING && useProprietaryLibraries && IS_GOOGLE_ECOSYSTEM); adManager.setAdContainer(adContainer); adManager.initialize(this, analyticsManager, crashManager); @@ -333,7 +331,7 @@ private void initializeProprietaryLibraries() { billingManager.initialize(this, analyticsManager, adManager, crashManager); helpManager = new HelpManager(); - helpManager.setEnabled(useProprietaryLibraries); + helpManager.setEnabled(true); helpManager.initialize(this); } @@ -356,7 +354,7 @@ public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); - if (billingManager.hasPurchased()) { + if (!billingManager.isEnabled() || billingManager.hasPurchased()) { menu.findItem(R.id.menu_remove_ads).setVisible(false); } From 683a4b87ebedd6494336ddeb91915b5df28c33b2 Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Fri, 8 Oct 2021 18:47:23 +0200 Subject: [PATCH 02/22] tmp --- OpenDocument.core | 2 +- app/src/main/cpp/CoreWrapper.cpp | 151 +++++++++++-------------------- gradle.properties | 17 +++- 3 files changed, 69 insertions(+), 101 deletions(-) diff --git a/OpenDocument.core b/OpenDocument.core index cd2fd3568a0f..9a8c9a1197fe 160000 --- a/OpenDocument.core +++ b/OpenDocument.core @@ -1 +1 @@ -Subproject commit cd2fd3568a0fcf6e5f8df1931a23f00217d2da17 +Subproject commit 9a8c9a1197fec640309a9acc265ca5a6bf07174a diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp index 5ca3e3934a34..c95fad4836ec 100644 --- a/app/src/main/cpp/CoreWrapper.cpp +++ b/app/src/main/cpp/CoreWrapper.cpp @@ -1,10 +1,11 @@ #include "CoreWrapper.h" +#include +#include +#include +#include -#include -#include -#include - -std::optional document; +std::optional documentFile; +std::optional document; JNIEXPORT jobject JNICALL Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject instance, jobject options) @@ -26,34 +27,35 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject env->ReleaseStringUTFChars(inputPath, inputPathC); try { - document = odr::DocumentNoExcept::open(inputPathCpp); if (!document.has_value()) { env->SetIntField(result, errorField, -1); return result; } - auto meta = document->meta(); + odr::DecodedFile file(inputPathCpp); + // TODO this throws if it is not a document file! + documentFile = file.document_file(); jfieldID passwordField = env->GetFieldID(optionsClass, "password", "Ljava/lang/String;"); jstring password = (jstring) env->GetObjectField(options, passwordField); - bool decrypted = !meta.encrypted; - if (password != NULL) { + bool decrypted = !documentFile->password_encrypted(); + if (password != nullptr) { const auto passwordC = env->GetStringUTFChars(password, &isCopy); const auto passwordCpp = std::string(passwordC, env->GetStringUTFLength(password)); env->ReleaseStringUTFChars(password, passwordC); - decrypted = document->decrypt(passwordCpp); - - meta = document->meta(); + decrypted = documentFile->decrypt(passwordCpp); } + document = documentFile->document(); + if (!decrypted) { env->SetIntField(result, errorField, -2); return result; } - const auto extensionCpp = meta.typeAsString(); + const auto extensionCpp = documentFile->file_meta().type_as_string(); const auto extensionC = extensionCpp.c_str(); jstring extension = env->NewStringUTF(extensionC); @@ -63,10 +65,10 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject jfieldID editableField = env->GetFieldID(optionsClass, "editable", "Z"); jboolean editable = env->GetBooleanField(options, editableField); - odr::Config config = {}; + odr::HtmlConfig config; config.editable = editable; - config.entryCount = 1; - config.tableLimitRows = 10000; + config.entry_count = 1; + config.table_limit = {10000, 500}; jfieldID outputPathField = env->GetFieldID(optionsClass, "outputPath", "Ljava/lang/String;"); jstring outputPath = (jstring) env->GetObjectField(options, outputPathField); @@ -83,76 +85,37 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject jfieldID ooxmlField = env->GetFieldID(optionsClass, "ooxml", "Z"); jboolean ooxml = env->GetBooleanField(options, ooxmlField); - if (!ooxml) { - if (meta.type == odr::FileType::OPENDOCUMENT_TEXT) { - jstring pageName = env->NewStringUTF("Document"); - env->CallBooleanMethod(pageNames, addMethod, pageName); - - outputPathCpp = outputPathCpp + "0.html"; - - bool translated = document->translate(outputPathCpp, config); - if (!translated) { - env->SetIntField(result, errorField, -4); - return result; - } - } else if (meta.type == odr::FileType::OPENDOCUMENT_SPREADSHEET || meta.type == odr::FileType::OPENDOCUMENT_PRESENTATION || meta.type == odr::FileType::OPENDOCUMENT_GRAPHICS) { - int i = 0; - // TODO: this could fail for HUGE documents with hundreds of pages - // https://stackoverflow.com/a/24292867/198996 - for (auto page = meta.entries.begin(); page != meta.entries.end(); page++) { - jstring pageName = env->NewStringUTF(page->name.c_str()); - env->CallBooleanMethod(pageNames, addMethod, pageName); - - const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; - config.entryOffset = i; - - bool translated = document->translate(entryOutputPath, config); - if (!translated) { - env->SetIntField(result, errorField, -4); - return result; - } - - i++; - } - } else { - env->SetIntField(result, errorField, -5); - return result; - } + if (!ooxml && documentFile->file_type() == odr::FileType::office_open_xml_document) { + // TODO fail fast if ooxml file is given but disabled + env->SetIntField(result, errorField, -5); + return result; + } + + if (document->document_type() == odr::DocumentType::text) { + jstring pageName = env->NewStringUTF("Document"); + env->CallBooleanMethod(pageNames, addMethod, pageName); + + outputPathCpp = outputPathCpp + "0.html"; + + odr::html::translate(*document, outputPathCpp, config); + } else if (document->document_type() == odr::DocumentType::spreadsheet) { + auto cursor = document->root_element(); + + cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { + auto sheet = cursor.element().sheet(); + + jstring sheetName = env->NewStringUTF(sheet.name().c_str()); + env->CallBooleanMethod(pageNames, addMethod, sheetName); + + const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; + config.entry_offset = i; + + // TODO: trycatch, return -4 + odr::html::translate(*document, entryOutputPath, config); + }); } else { - if (meta.type == odr::FileType::OFFICE_OPEN_XML_DOCUMENT) { - jstring pageName = env->NewStringUTF("Text document"); - env->CallBooleanMethod(pageNames, addMethod, pageName); - - outputPathCpp = outputPathCpp + "0.html"; - - bool translated = document->translate(outputPathCpp, config); - if (!translated) { - env->SetIntField(result, errorField, -4); - return result; - } - } else if (meta.type == odr::FileType::OFFICE_OPEN_XML_WORKBOOK || meta.type == odr::FileType::OFFICE_OPEN_XML_PRESENTATION) { - int i = 0; - // TODO: this could fail for HUGE documents with hundreds of pages - // https://stackoverflow.com/a/24292867/198996 - for (auto page = meta.entries.begin(); page != meta.entries.end(); page++) { - jstring pageName = env->NewStringUTF(page->name.c_str()); - env->CallBooleanMethod(pageNames, addMethod, pageName); - - const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; - config.entryOffset = i; - - bool translated = document->translate(entryOutputPath, config); - if (!translated) { - env->SetIntField(result, errorField, -4); - return result; - } - - i++; - } - } else { - env->SetIntField(result, errorField, -5); - return result; - } + env->SetIntField(result, errorField, -5); + return result; } } catch (...) { env->SetIntField(result, errorField, -3); @@ -188,9 +151,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, auto htmlDiffCpp = std::string(htmlDiffC, env->GetStringUTFLength(htmlDiff)); env->ReleaseStringUTFChars(htmlDiff, htmlDiffC); - const auto meta = document->meta(); - - const auto extension = meta.typeAsString(); + const auto extension = documentFile->file_meta().type_as_string(); const auto outputPathCpp = outputPathPrefixCpp + "." + extension; const char *outputPathC = outputPathCpp.c_str(); jstring outputPath = env->NewStringUTF(outputPathC); @@ -198,17 +159,11 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, jfieldID outputPathField = env->GetFieldID(resultClass, "outputPath", "Ljava/lang/String;"); env->SetObjectField(result, outputPathField, outputPath); - bool success = document->edit(htmlDiffCpp); - if (!success) { - env->SetIntField(result, errorField, -6); - return result; - } + // TODO: trycatch, return -6 + odr::html::edit(*document, htmlDiffCpp); - success = document->save(outputPathCpp); - if (!success) { - env->SetIntField(result, errorField, -7); - return result; - } + // TODO: trycatch, return -7 + document->save(outputPathCpp); } catch (...) { env->SetIntField(result, errorField, -3); return result; diff --git a/gradle.properties b/gradle.properties index b84c2ed13799..ad202697730e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,17 @@ +## For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx1024m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +#Fri Oct 08 18:22:20 CEST 2021 +android.bundle.enableUncompressedNativeLibs=false +org.gradle.jvmargs=-Xmx1536M -Dkotlin.daemon.jvm.options\="-Xmx1536M" android.enableJetifier=true android.useAndroidX=true -org.gradle.jvmargs=-Xmx1024m -android.bundle.enableUncompressedNativeLibs=false \ No newline at end of file From 7a351499f636addd6606bceea1596b6373b0440c Mon Sep 17 00:00:00 2001 From: andiwand Date: Fri, 8 Oct 2021 19:39:41 +0200 Subject: [PATCH 03/22] tmp --- app/src/main/cpp/CoreWrapper.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp index c95fad4836ec..2676a434f990 100644 --- a/app/src/main/cpp/CoreWrapper.cpp +++ b/app/src/main/cpp/CoreWrapper.cpp @@ -1,5 +1,6 @@ #include "CoreWrapper.h" #include +#include #include #include #include @@ -27,11 +28,6 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject env->ReleaseStringUTFChars(inputPath, inputPathC); try { - if (!document.has_value()) { - env->SetIntField(result, errorField, -1); - return result; - } - odr::DecodedFile file(inputPathCpp); // TODO this throws if it is not a document file! documentFile = file.document_file(); From 59bdde8c787093b0d02c020b085231215bf87237 Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Fri, 8 Oct 2021 22:36:24 +0200 Subject: [PATCH 04/22] tmp --- app/src/main/cpp/CoreWrapper.cpp | 42 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp index c95fad4836ec..6af1adddca64 100644 --- a/app/src/main/cpp/CoreWrapper.cpp +++ b/app/src/main/cpp/CoreWrapper.cpp @@ -27,15 +27,14 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject env->ReleaseStringUTFChars(inputPath, inputPathC); try { - if (!document.has_value()) { + odr::DecodedFile file(inputPathCpp); + try { + documentFile = file.document_file(); + } catch (...) { env->SetIntField(result, errorField, -1); return result; } - odr::DecodedFile file(inputPathCpp); - // TODO this throws if it is not a document file! - documentFile = file.document_file(); - jfieldID passwordField = env->GetFieldID(optionsClass, "password", "Ljava/lang/String;"); jstring password = (jstring) env->GetObjectField(options, passwordField); @@ -48,8 +47,6 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject decrypted = documentFile->decrypt(passwordCpp); } - document = documentFile->document(); - if (!decrypted) { env->SetIntField(result, errorField, -2); return result; @@ -85,12 +82,14 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject jfieldID ooxmlField = env->GetFieldID(optionsClass, "ooxml", "Z"); jboolean ooxml = env->GetBooleanField(options, ooxmlField); - if (!ooxml && documentFile->file_type() == odr::FileType::office_open_xml_document) { - // TODO fail fast if ooxml file is given but disabled + if (!ooxml && + (documentFile->file_type() == odr::FileType::office_open_xml_document || documentFile->file_type() == odr::FileType::office_open_xml_workbook || documentFile->file_type() == odr::FileType::office_open_xml_presentation || )) { env->SetIntField(result, errorField, -5); return result; } + document = documentFile->document(); + if (document->document_type() == odr::DocumentType::text) { jstring pageName = env->NewStringUTF("Document"); env->CallBooleanMethod(pageNames, addMethod, pageName); @@ -110,8 +109,12 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; config.entry_offset = i; - // TODO: trycatch, return -4 - odr::html::translate(*document, entryOutputPath, config); + try { + odr::html::translate(*document, entryOutputPath, config); + } catch (...) { + env->SetIntField(result, errorField, -4); + return result; + } }); } else { env->SetIntField(result, errorField, -5); @@ -159,11 +162,19 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, jfieldID outputPathField = env->GetFieldID(resultClass, "outputPath", "Ljava/lang/String;"); env->SetObjectField(result, outputPathField, outputPath); - // TODO: trycatch, return -6 - odr::html::edit(*document, htmlDiffCpp); + try { + odr::html::edit(*document, htmlDiffCpp); + } catch (...) { + env->SetIntField(result, errorField, -6); + return result; + } - // TODO: trycatch, return -7 - document->save(outputPathCpp); + try { + document->save(outputPathCpp); + } catch (...) { + env->SetIntField(result, errorField, -7); + return result; + } } catch (...) { env->SetIntField(result, errorField, -3); return result; @@ -177,4 +188,5 @@ JNIEXPORT void JNICALL Java_at_tomtasche_reader_background_CoreWrapper_closeNative(JNIEnv *env, jobject instance, jobject options) { document.reset(); + documentFile.reset(); } \ No newline at end of file From f48bb537c74c2a7ae79f0f156f4b3a5d02179ad6 Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Fri, 8 Oct 2021 22:50:06 +0200 Subject: [PATCH 05/22] finish CoreWrapper for latest core --- app/src/main/cpp/CoreWrapper.cpp | 40 +++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp index 23a9d9f1b261..964b593c42cb 100644 --- a/app/src/main/cpp/CoreWrapper.cpp +++ b/app/src/main/cpp/CoreWrapper.cpp @@ -84,7 +84,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject jfieldID ooxmlField = env->GetFieldID(optionsClass, "ooxml", "Z"); jboolean ooxml = env->GetBooleanField(options, ooxmlField); if (!ooxml && - (documentFile->file_type() == odr::FileType::office_open_xml_document || documentFile->file_type() == odr::FileType::office_open_xml_workbook || documentFile->file_type() == odr::FileType::office_open_xml_presentation || )) { + (documentFile->file_type() == odr::FileType::office_open_xml_document || documentFile->file_type() == odr::FileType::office_open_xml_workbook || documentFile->file_type() == odr::FileType::office_open_xml_presentation)) { env->SetIntField(result, errorField, -5); return result; } @@ -110,6 +110,44 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; config.entry_offset = i; + try { + odr::html::translate(*document, entryOutputPath, config); + } catch (...) { + env->SetIntField(result, errorField, -4); + return result; + } + }); + } else if (document->document_type() == odr::DocumentType::presentation) { + auto cursor = document->root_element(); + + cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { + auto slide = cursor.element().slide(); + + jstring sheetName = env->NewStringUTF(slide.name().c_str()); + env->CallBooleanMethod(pageNames, addMethod, sheetName); + + const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; + config.entry_offset = i; + + try { + odr::html::translate(*document, entryOutputPath, config); + } catch (...) { + env->SetIntField(result, errorField, -4); + return result; + } + }); + } else if (document->document_type() == odr::DocumentType::drawing) { + auto cursor = document->root_element(); + + cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { + auto page = cursor.element().page(); + + jstring sheetName = env->NewStringUTF(std::to_string(i).c_str()); + env->CallBooleanMethod(pageNames, addMethod, sheetName); + + const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; + config.entry_offset = i; + try { odr::html::translate(*document, entryOutputPath, config); } catch (...) { From dab0864612388e796ad3708180c8143c7c37ad7b Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Fri, 8 Oct 2021 22:59:36 +0200 Subject: [PATCH 06/22] fix "remove ads" shown in Pro --- .../tomtasche/reader/nonfree/BillingManager.java | 4 ++++ .../at/tomtasche/reader/nonfree/HelpManager.java | 16 ---------------- .../reader/ui/activity/MainActivity.java | 1 + 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/at/tomtasche/reader/nonfree/BillingManager.java b/app/src/main/java/at/tomtasche/reader/nonfree/BillingManager.java index ecd4582c7375..d8af1e47c51d 100644 --- a/app/src/main/java/at/tomtasche/reader/nonfree/BillingManager.java +++ b/app/src/main/java/at/tomtasche/reader/nonfree/BillingManager.java @@ -216,6 +216,10 @@ public void onAcknowledgePurchaseResponse(BillingResult billingResult) { } public boolean hasPurchased() { + if (!enabled) { + return true; + } + if (billingPreferences == null) { return false; } diff --git a/app/src/main/java/at/tomtasche/reader/nonfree/HelpManager.java b/app/src/main/java/at/tomtasche/reader/nonfree/HelpManager.java index 815b0bd427a2..d55fdadfb9dc 100644 --- a/app/src/main/java/at/tomtasche/reader/nonfree/HelpManager.java +++ b/app/src/main/java/at/tomtasche/reader/nonfree/HelpManager.java @@ -15,17 +15,6 @@ public void initialize(Context context) { if (!enabled) { return; } - - /*HelpCrunchOptions options = new HelpCrunchOptions() - .setRequestName(false).setNotificationsChannelTitle("Support"); - - HelpCrunch.initializeWithOptions( - context, - "opendocumentreader", - 1, - "Fs5HNI5XBRXjgr4dfc7fFd7aVGElLznF3p9hLUAD/2DPpLefIQ5+IZgQlBYgCfQ8bG/xBUx8nQsaAQCqOy3wuA==", - options - );*/ } public void setEnabled(boolean enabled) { @@ -33,13 +22,8 @@ public void setEnabled(boolean enabled) { } public void show() { - if (!enabled) { - return; - } - context.startActivity(new Intent( Intent.ACTION_VIEW, Uri.parse("https://opendocument.app/"))); - //HelpCrunch.showChatScreen(context); } } diff --git a/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java b/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java index 06622b864fd4..454c0b360e07 100644 --- a/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java +++ b/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java @@ -299,6 +299,7 @@ public boolean requestSave() { } } + private void initializeProprietaryLibraries() { boolean useProprietaryLibraries = !getResources().getBoolean(R.bool.DISABLE_TRACKING); From 8bf3c22a97cf815a8e9874fbbc5666d7064ff91d Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Fri, 8 Oct 2021 23:38:52 +0200 Subject: [PATCH 07/22] fix zip files not working --- .../main/java/at/tomtasche/reader/ui/widget/PageView.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/at/tomtasche/reader/ui/widget/PageView.java b/app/src/main/java/at/tomtasche/reader/ui/widget/PageView.java index 64302c3ba9a0..3f3dfed6812c 100644 --- a/app/src/main/java/at/tomtasche/reader/ui/widget/PageView.java +++ b/app/src/main/java/at/tomtasche/reader/ui/widget/PageView.java @@ -202,7 +202,12 @@ public void sendFile(String base64) { inputStream.close(); } - documentFragment.loadUri(AndroidFileCache.getCacheFileUri(getContext(), tmpFile), false); + post(new Runnable() { + @Override + public void run() { + documentFragment.loadUri(AndroidFileCache.getCacheFileUri(getContext(), tmpFile), false); + } + }); } catch (IOException e) { crashManager.log(e); } From 59d7ce554379b303566269eeafc3633acbda3f65 Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Mon, 11 Oct 2021 17:43:08 +0200 Subject: [PATCH 08/22] tmp --- CMakeLists.txt | 4 +- OpenDocument.core | 2 +- app/build.gradle | 14 +++---- app/src/main/cpp/CoreWrapper.cpp | 40 +++++++++++++++++++ .../reader/ui/activity/DocumentFragment.java | 12 ++++++ build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 7 files changed, 65 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91f783edbd3a..15911f7c68d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,5 +14,7 @@ add_library(odr-core SHARED ${SRC}) option (ODR_TEST "" OFF) set(ODR_TEST OFF) +find_library(LOG log) + add_subdirectory(OpenDocument.core) -target_link_libraries(odr-core odr-shared) +target_link_libraries(odr-core odr-shared ${LOG}) diff --git a/OpenDocument.core b/OpenDocument.core index 9a8c9a1197fe..7c5ee06694cc 160000 --- a/OpenDocument.core +++ b/OpenDocument.core @@ -1 +1 @@ -Subproject commit 9a8c9a1197fec640309a9acc265ca5a6bf07174a +Subproject commit 7c5ee06694cc12494ba306203d16e5bbc6bdd5c1 diff --git a/app/build.gradle b/app/build.gradle index 199b093193d9..7993af096d30 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -100,12 +100,12 @@ dependencies { implementation 'com.android.billingclient:billing:4.0.0' - implementation 'com.google.android.play:core:1.10.0' + implementation 'com.google.android.play:core:1.10.2' implementation 'androidx.multidex:multidex:2.0.1' - implementation 'androidx.appcompat:appcompat:1.3.0' - implementation 'androidx.core:core:1.5.0' - implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'androidx.core:core:1.6.0' + implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.webkit:webkit:1.4.0' implementation 'com.github.AppIntro:AppIntro:5.1.0' @@ -118,9 +118,9 @@ dependencies { implementation 'com.viliussutkus89:wvware-android:1.2.4' implementation 'com.github.huzongyao:AndroidMagic:v1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' - androidTestImplementation 'androidx.test:rules:1.3.0' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'androidx.test:rules:1.4.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' } apply plugin: 'com.google.gms.google-services' diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp index 964b593c42cb..45cbe3ff4785 100644 --- a/app/src/main/cpp/CoreWrapper.cpp +++ b/app/src/main/cpp/CoreWrapper.cpp @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include std::optional documentFile; std::optional document; @@ -19,6 +22,8 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject jfieldID errorField = env->GetFieldID(resultClass, "errorCode", "I"); + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "1"); + jclass optionsClass = env->GetObjectClass(options); jfieldID inputPathField = env->GetFieldID(optionsClass, "inputPath", "Ljava/lang/String;"); jstring inputPath = (jstring) env->GetObjectField(options, inputPathField); @@ -27,6 +32,8 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject auto inputPathCpp = std::string(inputPathC, env->GetStringUTFLength(inputPath)); env->ReleaseStringUTFChars(inputPath, inputPathC); + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "2"); + try { odr::DecodedFile file(inputPathCpp); try { @@ -36,6 +43,8 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject return result; } + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "3"); + jfieldID passwordField = env->GetFieldID(optionsClass, "password", "Ljava/lang/String;"); jstring password = (jstring) env->GetObjectField(options, passwordField); @@ -48,6 +57,8 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject decrypted = documentFile->decrypt(passwordCpp); } + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "4"); + if (!decrypted) { env->SetIntField(result, errorField, -2); return result; @@ -57,6 +68,8 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject const auto extensionC = extensionCpp.c_str(); jstring extension = env->NewStringUTF(extensionC); + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "5"); + jfieldID extensionField = env->GetFieldID(resultClass, "extension", "Ljava/lang/String;"); env->SetObjectField(result, extensionField, extension); @@ -68,6 +81,8 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject config.entry_count = 1; config.table_limit = {10000, 500}; + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "6"); + jfieldID outputPathField = env->GetFieldID(optionsClass, "outputPath", "Ljava/lang/String;"); jstring outputPath = (jstring) env->GetObjectField(options, outputPathField); @@ -89,21 +104,39 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject return result; } + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "7"); + document = documentFile->document(); + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "7.1"); + if (document->document_type() == odr::DocumentType::text) { + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "7.2t"); + jstring pageName = env->NewStringUTF("Document"); env->CallBooleanMethod(pageNames, addMethod, pageName); outputPathCpp = outputPathCpp + "0.html"; + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "7.3"); + odr::html::translate(*document, outputPathCpp, config); + + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "7.4"); } else if (document->document_type() == odr::DocumentType::spreadsheet) { + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "7.2"); + auto cursor = document->root_element(); + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "8"); + cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "8.1"); + auto sheet = cursor.element().sheet(); + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "9"); + jstring sheetName = env->NewStringUTF(sheet.name().c_str()); env->CallBooleanMethod(pageNames, addMethod, sheetName); @@ -111,7 +144,11 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject config.entry_offset = i; try { + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "10"); + odr::html::translate(*document, entryOutputPath, config); + + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "11"); } catch (...) { env->SetIntField(result, errorField, -4); return result; @@ -165,6 +202,9 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject } env->SetIntField(result, errorField, 0); + + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "12"); + return result; } diff --git a/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java b/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java index 23e6d6d6e1e0..5c379a4f2cf9 100644 --- a/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java +++ b/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java @@ -95,6 +95,8 @@ public class DocumentFragment extends Fragment implements FileLoader.FileLoaderL private FileLoader.Result resultOnStart; private Throwable errorOnStart; + private int lastSelectedTab = -1; + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -791,8 +793,18 @@ private void dismissProgress() { @Override public void onTabSelected(ActionBar.Tab tab, androidx.fragment.app.FragmentTransaction ft) { + if (lastResult.options.translatable) { + if (lastSelectedTab > 0) { + getActivity().getActionBar().setSelectedNavigationItem(lastSelectedTab); + } + + return; + } + Uri uri = lastResult.partUris.get(tab.getPosition()); loadData(uri.toString()); + + lastSelectedTab = tab.getPosition(); } @Override diff --git a/build.gradle b/build.gradle index 301817f0a6d9..b55a6ab315a1 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.2.1' + classpath 'com.android.tools.build:gradle:7.0.2' classpath 'com.google.gms:google-services:4.3.8' classpath 'com.google.firebase:perf-plugin:1.4.0' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.6.1' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bcd180f65fe5..ce890375bdbf 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip From d898bc234207709207a4f0ee591ccf9272ee4510 Mon Sep 17 00:00:00 2001 From: andiwand Date: Mon, 11 Oct 2021 18:03:32 +0200 Subject: [PATCH 09/22] fix --- CMakeLists.txt | 4 +- OpenDocument.core | 2 +- app/src/main/cpp/CoreWrapper.cpp | 123 +++++++++++-------------------- 3 files changed, 47 insertions(+), 82 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 15911f7c68d9..91f783edbd3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,5 @@ add_library(odr-core SHARED ${SRC}) option (ODR_TEST "" OFF) set(ODR_TEST OFF) -find_library(LOG log) - add_subdirectory(OpenDocument.core) -target_link_libraries(odr-core odr-shared ${LOG}) +target_link_libraries(odr-core odr-shared) diff --git a/OpenDocument.core b/OpenDocument.core index 7c5ee06694cc..80c7d21f8bb2 160000 --- a/OpenDocument.core +++ b/OpenDocument.core @@ -1 +1 @@ -Subproject commit 7c5ee06694cc12494ba306203d16e5bbc6bdd5c1 +Subproject commit 80c7d21f8bb24a7ed86311bd28163df0d6296561 diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp index 45cbe3ff4785..37540281b58a 100644 --- a/app/src/main/cpp/CoreWrapper.cpp +++ b/app/src/main/cpp/CoreWrapper.cpp @@ -2,11 +2,10 @@ #include #include #include -#include -#include -#include #include #include +#include +#include std::optional documentFile; std::optional document; @@ -22,8 +21,6 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject jfieldID errorField = env->GetFieldID(resultClass, "errorCode", "I"); - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "1"); - jclass optionsClass = env->GetObjectClass(options); jfieldID inputPathField = env->GetFieldID(optionsClass, "inputPath", "Ljava/lang/String;"); jstring inputPath = (jstring) env->GetObjectField(options, inputPathField); @@ -32,8 +29,6 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject auto inputPathCpp = std::string(inputPathC, env->GetStringUTFLength(inputPath)); env->ReleaseStringUTFChars(inputPath, inputPathC); - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "2"); - try { odr::DecodedFile file(inputPathCpp); try { @@ -43,8 +38,6 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject return result; } - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "3"); - jfieldID passwordField = env->GetFieldID(optionsClass, "password", "Ljava/lang/String;"); jstring password = (jstring) env->GetObjectField(options, passwordField); @@ -57,8 +50,6 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject decrypted = documentFile->decrypt(passwordCpp); } - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "4"); - if (!decrypted) { env->SetIntField(result, errorField, -2); return result; @@ -68,8 +59,6 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject const auto extensionC = extensionCpp.c_str(); jstring extension = env->NewStringUTF(extensionC); - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "5"); - jfieldID extensionField = env->GetFieldID(resultClass, "extension", "Ljava/lang/String;"); env->SetObjectField(result, extensionField, extension); @@ -81,8 +70,6 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject config.entry_count = 1; config.table_limit = {10000, 500}; - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "6"); - jfieldID outputPathField = env->GetFieldID(optionsClass, "outputPath", "Ljava/lang/String;"); jstring outputPath = (jstring) env->GetObjectField(options, outputPathField); @@ -104,94 +91,77 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject return result; } - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "7"); - document = documentFile->document(); - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "7.1"); - if (document->document_type() == odr::DocumentType::text) { - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "7.2t"); - jstring pageName = env->NewStringUTF("Document"); env->CallBooleanMethod(pageNames, addMethod, pageName); outputPathCpp = outputPathCpp + "0.html"; - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "7.3"); - - odr::html::translate(*document, outputPathCpp, config); - - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "7.4"); + try { + odr::html::translate(*document, outputPathCpp, config); + } catch (...) { + env->SetIntField(result, errorField, -4); + return result; + } } else if (document->document_type() == odr::DocumentType::spreadsheet) { - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "7.2"); - auto cursor = document->root_element(); - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "8"); - - cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "8.1"); - - auto sheet = cursor.element().sheet(); + try { + cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { + auto sheet = cursor.element().sheet(); - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "9"); + jstring sheetName = env->NewStringUTF(sheet.name().c_str()); + env->CallBooleanMethod(pageNames, addMethod, sheetName); - jstring sheetName = env->NewStringUTF(sheet.name().c_str()); - env->CallBooleanMethod(pageNames, addMethod, sheetName); - - const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; - config.entry_offset = i; - - try { - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "10"); + const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; + config.entry_offset = i; odr::html::translate(*document, entryOutputPath, config); - - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "11"); - } catch (...) { - env->SetIntField(result, errorField, -4); - return result; - } - }); + }); + } catch (...) { + env->SetIntField(result, errorField, -4); + return result; + } } else if (document->document_type() == odr::DocumentType::presentation) { auto cursor = document->root_element(); - cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { - auto slide = cursor.element().slide(); + try { + cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { + auto slide = cursor.element().slide(); - jstring sheetName = env->NewStringUTF(slide.name().c_str()); - env->CallBooleanMethod(pageNames, addMethod, sheetName); + jstring sheetName = env->NewStringUTF(slide.name().c_str()); + env->CallBooleanMethod(pageNames, addMethod, sheetName); - const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; - config.entry_offset = i; + const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; + config.entry_offset = i; - try { - odr::html::translate(*document, entryOutputPath, config); - } catch (...) { - env->SetIntField(result, errorField, -4); - return result; - } - }); + odr::html::translate(*document, entryOutputPath, config); + }); + } catch (...) { + env->SetIntField(result, errorField, -4); + return result; + } } else if (document->document_type() == odr::DocumentType::drawing) { auto cursor = document->root_element(); - cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { - auto page = cursor.element().page(); + try { + cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { + auto page = cursor.element().page(); - jstring sheetName = env->NewStringUTF(std::to_string(i).c_str()); - env->CallBooleanMethod(pageNames, addMethod, sheetName); + jstring sheetName = env->NewStringUTF(std::to_string(i).c_str()); + env->CallBooleanMethod(pageNames, addMethod, sheetName); - const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; - config.entry_offset = i; + const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; + config.entry_offset = i; - try { odr::html::translate(*document, entryOutputPath, config); - } catch (...) { - env->SetIntField(result, errorField, -4); - return result; - } - }); + }); + } catch (...) { + env->SetIntField(result, errorField, -4); + return result; + } } else { env->SetIntField(result, errorField, -5); return result; @@ -202,9 +172,6 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject } env->SetIntField(result, errorField, 0); - - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "12"); - return result; } From 45812099f549b666d917b34aaa1f4572d2f11c6c Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Mon, 18 Oct 2021 22:05:01 +0200 Subject: [PATCH 10/22] lock pageswitch during edit --- OpenDocument.core | 2 +- app/src/main/cpp/CoreWrapper.cpp | 10 ++++++---- .../tomtasche/reader/ui/activity/DocumentFragment.java | 10 ++++++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/OpenDocument.core b/OpenDocument.core index 80c7d21f8bb2..2c74ceb30776 160000 --- a/OpenDocument.core +++ b/OpenDocument.core @@ -1 +1 @@ -Subproject commit 80c7d21f8bb24a7ed86311bd28163df0d6296561 +Subproject commit 2c74ceb30776781d10840cedd29761f6c3e97a3a diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp index 37540281b58a..24279ef67a23 100644 --- a/app/src/main/cpp/CoreWrapper.cpp +++ b/app/src/main/cpp/CoreWrapper.cpp @@ -137,7 +137,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; config.entry_offset = i; - odr::html::translate(*document, entryOutputPath, config); + odr::html::translate(*document, entryOutputPath, config); }); } catch (...) { env->SetIntField(result, errorField, -4); @@ -197,8 +197,6 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, env->ReleaseStringUTFChars(outputPathPrefix, outputPathPrefixC); const auto htmlDiffC = env->GetStringUTFChars(htmlDiff, &isCopy); - auto htmlDiffCpp = std::string(htmlDiffC, env->GetStringUTFLength(htmlDiff)); - env->ReleaseStringUTFChars(htmlDiff, htmlDiffC); const auto extension = documentFile->file_meta().type_as_string(); const auto outputPathCpp = outputPathPrefixCpp + "." + extension; @@ -209,8 +207,12 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, env->SetObjectField(result, outputPathField, outputPath); try { - odr::html::edit(*document, htmlDiffCpp); + odr::html::edit(*document, htmlDiffC); + + env->ReleaseStringUTFChars(htmlDiff, htmlDiffC); } catch (...) { + env->ReleaseStringUTFChars(htmlDiff, htmlDiffC); + env->SetIntField(result, errorField, -6); return result; } diff --git a/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java b/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java index 5c379a4f2cf9..6379c67f31a6 100644 --- a/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java +++ b/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java @@ -794,8 +794,14 @@ private void dismissProgress() { @Override public void onTabSelected(ActionBar.Tab tab, androidx.fragment.app.FragmentTransaction ft) { if (lastResult.options.translatable) { - if (lastSelectedTab > 0) { - getActivity().getActionBar().setSelectedNavigationItem(lastSelectedTab); + if (lastSelectedTab >= 0) { + mainHandler.postDelayed(new Runnable() { + @Override + public void run() { + ActionBar bar = ((AppCompatActivity) getActivity()).getSupportActionBar(); + bar.setSelectedNavigationItem(lastSelectedTab); + } + }, 1); } return; From 9e12c031ae2368add03774c7475356afd0f4085d Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Thu, 21 Oct 2021 11:54:13 +0200 Subject: [PATCH 11/22] tmp --- CMakeLists.txt | 4 +- OpenDocument.core | 2 +- app/src/main/cpp/CoreWrapper.cpp | 144 ++++++++++--------------------- 3 files changed, 49 insertions(+), 101 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91f783edbd3a..ef782f41c1b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,5 +14,7 @@ add_library(odr-core SHARED ${SRC}) option (ODR_TEST "" OFF) set(ODR_TEST OFF) +find_library(LOG log) + add_subdirectory(OpenDocument.core) -target_link_libraries(odr-core odr-shared) +target_link_libraries(odr-core odr-shared ${LOG}) \ No newline at end of file diff --git a/OpenDocument.core b/OpenDocument.core index 2c74ceb30776..5058a82ed77b 160000 --- a/OpenDocument.core +++ b/OpenDocument.core @@ -1 +1 @@ -Subproject commit 2c74ceb30776781d10840cedd29761f6c3e97a3a +Subproject commit 5058a82ed77b77ac24889a08e6d736127f9d54c7 diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp index 24279ef67a23..c785281948ba 100644 --- a/app/src/main/cpp/CoreWrapper.cpp +++ b/app/src/main/cpp/CoreWrapper.cpp @@ -6,9 +6,11 @@ #include #include #include +#include +#include +#include -std::optional documentFile; -std::optional document; +std::optional html; JNIEXPORT jobject JNICALL Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject instance, jobject options) @@ -30,46 +32,18 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject env->ReleaseStringUTFChars(inputPath, inputPathC); try { - odr::DecodedFile file(inputPathCpp); - try { - documentFile = file.document_file(); - } catch (...) { - env->SetIntField(result, errorField, -1); - return result; - } - + std::optional passwordCpp; jfieldID passwordField = env->GetFieldID(optionsClass, "password", "Ljava/lang/String;"); jstring password = (jstring) env->GetObjectField(options, passwordField); - - bool decrypted = !documentFile->password_encrypted(); if (password != nullptr) { const auto passwordC = env->GetStringUTFChars(password, &isCopy); - const auto passwordCpp = std::string(passwordC, env->GetStringUTFLength(password)); + passwordCpp = std::string(passwordC, env->GetStringUTFLength(password)); env->ReleaseStringUTFChars(password, passwordC); - - decrypted = documentFile->decrypt(passwordCpp); } - if (!decrypted) { - env->SetIntField(result, errorField, -2); - return result; - } - - const auto extensionCpp = documentFile->file_meta().type_as_string(); - const auto extensionC = extensionCpp.c_str(); - jstring extension = env->NewStringUTF(extensionC); - - jfieldID extensionField = env->GetFieldID(resultClass, "extension", "Ljava/lang/String;"); - env->SetObjectField(result, extensionField, extension); - jfieldID editableField = env->GetFieldID(optionsClass, "editable", "Z"); jboolean editable = env->GetBooleanField(options, editableField); - odr::HtmlConfig config; - config.editable = editable; - config.entry_count = 1; - config.table_limit = {10000, 500}; - jfieldID outputPathField = env->GetFieldID(optionsClass, "outputPath", "Ljava/lang/String;"); jstring outputPath = (jstring) env->GetObjectField(options, outputPathField); @@ -85,86 +59,59 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject jfieldID ooxmlField = env->GetFieldID(optionsClass, "ooxml", "Z"); jboolean ooxml = env->GetBooleanField(options, ooxmlField); - if (!ooxml && - (documentFile->file_type() == odr::FileType::office_open_xml_document || documentFile->file_type() == odr::FileType::office_open_xml_workbook || documentFile->file_type() == odr::FileType::office_open_xml_presentation)) { - env->SetIntField(result, errorField, -5); - return result; - } - document = documentFile->document(); - - if (document->document_type() == odr::DocumentType::text) { - jstring pageName = env->NewStringUTF("Document"); - env->CallBooleanMethod(pageNames, addMethod, pageName); + try { + odr::HtmlConfig config; + config.editable = editable; - outputPathCpp = outputPathCpp + "0.html"; + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "1"); - try { - odr::html::translate(*document, outputPathCpp, config); - } catch (...) { - env->SetIntField(result, errorField, -4); - return result; + const char* passwordC = nullptr; + if (passwordCpp.has_value()) { + passwordC = passwordCpp.value().c_str(); } - } else if (document->document_type() == odr::DocumentType::spreadsheet) { - auto cursor = document->root_element(); - - try { - cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { - auto sheet = cursor.element().sheet(); - jstring sheetName = env->NewStringUTF(sheet.name().c_str()); - env->CallBooleanMethod(pageNames, addMethod, sheetName); + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "2"); + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "%s", inputPathCpp.c_str()); + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "%s", outputPathCpp.c_str()); - const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; - config.entry_offset = i; + html = odr::OpenDocumentReader::html(inputPathCpp, passwordC, outputPathCpp, config); - odr::html::translate(*document, entryOutputPath, config); - }); - } catch (...) { - env->SetIntField(result, errorField, -4); - return result; - } - } else if (document->document_type() == odr::DocumentType::presentation) { - auto cursor = document->root_element(); + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "3"); - try { - cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { - auto slide = cursor.element().slide(); + //const auto extensionCpp = html->file_type().type_as_string(); + //const auto extensionC = extensionCpp.c_str(); + //jstring extension = env->NewStringUTF(extensionC); - jstring sheetName = env->NewStringUTF(slide.name().c_str()); - env->CallBooleanMethod(pageNames, addMethod, sheetName); + //jfieldID extensionField = env->GetFieldID(resultClass, "extension", "Ljava/lang/String;"); + //env->SetObjectField(result, extensionField, extension); - const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; - config.entry_offset = i; + if (!ooxml && + (html->file_type() == odr::FileType::office_open_xml_document || html->file_type() == odr::FileType::office_open_xml_workbook || html->file_type() == odr::FileType::office_open_xml_presentation)) { + // TODO: this is stupid and should happen BEFORE translation - odr::html::translate(*document, entryOutputPath, config); - }); - } catch (...) { - env->SetIntField(result, errorField, -4); + env->SetIntField(result, errorField, -5); return result; } - } else if (document->document_type() == odr::DocumentType::drawing) { - auto cursor = document->root_element(); - try { - cursor.for_each_child([&](odr::DocumentCursor &cursor, std::uint32_t i) { - auto page = cursor.element().page(); + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "4"); - jstring sheetName = env->NewStringUTF(std::to_string(i).c_str()); - env->CallBooleanMethod(pageNames, addMethod, sheetName); + for (auto &&page : html->pages()) { + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "5"); + jstring pageName = env->NewStringUTF(page.name.c_str()); + env->CallBooleanMethod(pageNames, addMethod, pageName); - const auto entryOutputPath = outputPathCpp + std::to_string(i) + ".html"; - config.entry_offset = i; - - odr::html::translate(*document, entryOutputPath, config); - }); - } catch (...) { - env->SetIntField(result, errorField, -4); - return result; + __android_log_print(ANDROID_LOG_VERBOSE, "smn", "6"); } - } else { + } catch (odr::UnknownFileType) { env->SetIntField(result, errorField, -5); return result; + } catch (odr::WrongPassword) { + env->SetIntField(result, errorField, -2); + return result; + } catch (...) { + env->SetIntField(result, errorField, -4); + return result; } } catch (...) { env->SetIntField(result, errorField, -3); @@ -198,7 +145,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, const auto htmlDiffC = env->GetStringUTFChars(htmlDiff, &isCopy); - const auto extension = documentFile->file_meta().type_as_string(); + /*const auto extension = documentFile->file_meta().type_as_string(); const auto outputPathCpp = outputPathPrefixCpp + "." + extension; const char *outputPathC = outputPathCpp.c_str(); jstring outputPath = env->NewStringUTF(outputPathC); @@ -207,7 +154,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, env->SetObjectField(result, outputPathField, outputPath); try { - odr::html::edit(*document, htmlDiffC); + html->edit(htmlDiffC); env->ReleaseStringUTFChars(htmlDiff, htmlDiffC); } catch (...) { @@ -218,11 +165,11 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, } try { - document->save(outputPathCpp); + html->save(outputPathCpp); } catch (...) { env->SetIntField(result, errorField, -7); return result; - } + }*/ } catch (...) { env->SetIntField(result, errorField, -3); return result; @@ -235,6 +182,5 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, JNIEXPORT void JNICALL Java_at_tomtasche_reader_background_CoreWrapper_closeNative(JNIEnv *env, jobject instance, jobject options) { - document.reset(); - documentFile.reset(); + html.reset(); } \ No newline at end of file From b03648eaaf5678f3d7f57507d30d865fdc169288 Mon Sep 17 00:00:00 2001 From: andiwand Date: Thu, 21 Oct 2021 12:16:51 +0200 Subject: [PATCH 12/22] update core --- OpenDocument.core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenDocument.core b/OpenDocument.core index 5058a82ed77b..81486084659e 160000 --- a/OpenDocument.core +++ b/OpenDocument.core @@ -1 +1 @@ -Subproject commit 5058a82ed77b77ac24889a08e6d736127f9d54c7 +Subproject commit 81486084659e6ee0a0d53e44c56e282a1d33b06a From f45532b925a25268b264a9cc2d89b9232bc0263f Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Sun, 24 Oct 2021 11:29:56 +0200 Subject: [PATCH 13/22] tmp --- OpenDocument.core | 2 +- app/src/main/cpp/CoreWrapper.cpp | 31 ++--- .../reader/background/AndroidFileCache.java | 7 +- .../reader/background/CoreWrapper.java | 1 + .../reader/background/OdfLoader.java | 6 +- .../reader/background/OoxmlLoader.java | 4 +- .../reader/ui/activity/DocumentFragment.java | 13 +- app/src/main/res/menu/menu_main.xml | 125 ++++++++++-------- 8 files changed, 102 insertions(+), 87 deletions(-) diff --git a/OpenDocument.core b/OpenDocument.core index 81486084659e..37c273ff3ab8 160000 --- a/OpenDocument.core +++ b/OpenDocument.core @@ -1 +1 @@ -Subproject commit 81486084659e6ee0a0d53e44c56e282a1d33b06a +Subproject commit 37c273ff3ab83eefe8dbdc198111c1336d29dd58 diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp index c785281948ba..28e865982ca2 100644 --- a/app/src/main/cpp/CoreWrapper.cpp +++ b/app/src/main/cpp/CoreWrapper.cpp @@ -57,6 +57,9 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject jfieldID pageNamesField = env->GetFieldID(resultClass, "pageNames", "Ljava/util/List;"); jobject pageNames = (jobject) env->GetObjectField(result, pageNamesField); + jfieldID pagePathsField = env->GetFieldID(resultClass, "pagePaths", "Ljava/util/List;"); + jobject pagePaths = (jobject) env->GetObjectField(result, pagePathsField); + jfieldID ooxmlField = env->GetFieldID(optionsClass, "ooxml", "Z"); jboolean ooxml = env->GetBooleanField(options, ooxmlField); @@ -64,27 +67,21 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject odr::HtmlConfig config; config.editable = editable; - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "1"); - const char* passwordC = nullptr; if (passwordCpp.has_value()) { passwordC = passwordCpp.value().c_str(); } - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "2"); - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "%s", inputPathCpp.c_str()); - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "%s", outputPathCpp.c_str()); + // __android_log_print(ANDROID_LOG_VERBOSE, "smn", "%s", outputPathCpp.c_str()); html = odr::OpenDocumentReader::html(inputPathCpp, passwordC, outputPathCpp, config); - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "3"); - - //const auto extensionCpp = html->file_type().type_as_string(); - //const auto extensionC = extensionCpp.c_str(); - //jstring extension = env->NewStringUTF(extensionC); + const auto extensionCpp = odr::OpenDocumentReader::type_to_string(html->file_type()); + const auto extensionC = extensionCpp.c_str(); + jstring extension = env->NewStringUTF(extensionC); - //jfieldID extensionField = env->GetFieldID(resultClass, "extension", "Ljava/lang/String;"); - //env->SetObjectField(result, extensionField, extension); + jfieldID extensionField = env->GetFieldID(resultClass, "extension", "Ljava/lang/String;"); + env->SetObjectField(result, extensionField, extension); if (!ooxml && (html->file_type() == odr::FileType::office_open_xml_document || html->file_type() == odr::FileType::office_open_xml_workbook || html->file_type() == odr::FileType::office_open_xml_presentation)) { @@ -94,14 +91,12 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject return result; } - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "4"); - for (auto &&page : html->pages()) { - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "5"); jstring pageName = env->NewStringUTF(page.name.c_str()); env->CallBooleanMethod(pageNames, addMethod, pageName); - __android_log_print(ANDROID_LOG_VERBOSE, "smn", "6"); + jstring pagePath = env->NewStringUTF(page.path.c_str()); + env->CallBooleanMethod(pagePaths, addMethod, pagePath); } } catch (odr::UnknownFileType) { env->SetIntField(result, errorField, -5); @@ -145,7 +140,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, const auto htmlDiffC = env->GetStringUTFChars(htmlDiff, &isCopy); - /*const auto extension = documentFile->file_meta().type_as_string(); + const auto extension = odr::OpenDocumentReader::type_to_string(html->file_type()); const auto outputPathCpp = outputPathPrefixCpp + "." + extension; const char *outputPathC = outputPathCpp.c_str(); jstring outputPath = env->NewStringUTF(outputPathC); @@ -169,7 +164,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, } catch (...) { env->SetIntField(result, errorField, -7); return result; - }*/ + } } catch (...) { env->SetIntField(result, errorField, -3); return result; diff --git a/app/src/main/java/at/tomtasche/reader/background/AndroidFileCache.java b/app/src/main/java/at/tomtasche/reader/background/AndroidFileCache.java index 0b0c20271950..26743a6dfc86 100644 --- a/app/src/main/java/at/tomtasche/reader/background/AndroidFileCache.java +++ b/app/src/main/java/at/tomtasche/reader/background/AndroidFileCache.java @@ -97,7 +97,12 @@ private static void cleanup(File directory) { for (String s : files) { try { - new File(directory, s).delete(); + File file = new File(directory, s); + if (file.isDirectory()) { + cleanup(file); + } else { + file.delete(); + } } catch (Exception e) { e.printStackTrace(); } diff --git a/app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java b/app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java index 2501bbb586bc..50dd58f28407 100644 --- a/app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java +++ b/app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java @@ -97,6 +97,7 @@ public static class CoreResult { public Exception exception; public List pageNames = new LinkedList<>(); + public List pagePaths = new LinkedList<>(); public String outputPath; diff --git a/app/src/main/java/at/tomtasche/reader/background/OdfLoader.java b/app/src/main/java/at/tomtasche/reader/background/OdfLoader.java index 78b0091074dc..242f76a836f1 100644 --- a/app/src/main/java/at/tomtasche/reader/background/OdfLoader.java +++ b/app/src/main/java/at/tomtasche/reader/background/OdfLoader.java @@ -17,7 +17,7 @@ public OdfLoader(Context context) { @Override public boolean isSupported(Options options) { - return options.fileType.startsWith("application/vnd.oasis.opendocument") || options.fileType.startsWith("application/x-vnd.oasis.opendocument"); + return options.fileType.startsWith("application/vnd.oasis.opendocument") || options.fileType.startsWith("application/x-vnd.oasis.opendocument") || options.fileType.startsWith("application/vnd.oasis.opendocument.text-master"); } @Override @@ -84,8 +84,8 @@ private void translate(Options options, Result result) throws Exception { throw coreResult.exception; } - for (int i = 0; i < coreResult.pageNames.size(); i++) { - File entryFile = new File(fakeHtmlFile.getPath() + i + ".html"); + for (int i = 0; i < coreResult.pagePaths.size(); i++) { + File entryFile = new File(coreResult.pagePaths.get(i)); result.partTitles.add(coreResult.pageNames.get(i)); result.partUris.add(Uri.fromFile(entryFile)); diff --git a/app/src/main/java/at/tomtasche/reader/background/OoxmlLoader.java b/app/src/main/java/at/tomtasche/reader/background/OoxmlLoader.java index 2ac6a6bf9fdb..e329d0603194 100644 --- a/app/src/main/java/at/tomtasche/reader/background/OoxmlLoader.java +++ b/app/src/main/java/at/tomtasche/reader/background/OoxmlLoader.java @@ -89,8 +89,8 @@ private void translate(Options options, Result result) throws Exception { // (not reported as DOCX prior) options.fileType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(coreResult.extension); - for (int i = 0; i < coreResult.pageNames.size(); i++) { - File entryFile = new File(fakeHtmlFile.getPath() + i + ".html"); + for (int i = 0; i < coreResult.pagePaths.size(); i++) { + File entryFile = new File(coreResult.pagePaths.get(i)); result.partTitles.add(coreResult.pageNames.get(i)); result.partUris.add(Uri.fromFile(entryFile)); diff --git a/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java b/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java index 6379c67f31a6..c6e54862124d 100644 --- a/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java +++ b/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java @@ -207,7 +207,11 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { this.menu = menu; - menu.setGroupVisible(R.id.menu_document_group, true); + menu.findItem(R.id.menu_fullscreen).setVisible(true); + menu.findItem(R.id.menu_open_with).setVisible(true); + menu.findItem(R.id.menu_share).setVisible(true); + menu.findItem(R.id.menu_print).setVisible(true); + // the other menu items are dynamically enabled on document load } @Override @@ -418,6 +422,7 @@ public void onSuccess(FileLoader.Result result) { errorOnStart = null; } + lastSelectedTab = -1; lastResult = result; analyticsManager.setCurrentScreen(activity, "screen_" + result.loaderType.toString() + "_" + result.options.fileType); @@ -802,15 +807,15 @@ public void run() { bar.setSelectedNavigationItem(lastSelectedTab); } }, 1); + + return; } - return; + lastSelectedTab = tab.getPosition(); } Uri uri = lastResult.partUris.get(tab.getPosition()); loadData(uri.toString()); - - lastSelectedTab = tab.getPosition(); } @Override diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index dd163530ef44..2d0390d8d328 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -1,60 +1,69 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + From 3ea5b2f44d5adf209f2f80a17fc5ddaef5acde0e Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Sun, 24 Oct 2021 11:35:49 +0200 Subject: [PATCH 14/22] fix build --- .github/workflows/android_main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/android_main.yml b/.github/workflows/android_main.yml index 6eb442351ccd..3694eb868a1f 100644 --- a/.github/workflows/android_main.yml +++ b/.github/workflows/android_main.yml @@ -18,7 +18,7 @@ jobs: - name: java uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 11 - name: build run: ./gradlew clean assembleDebug --stacktrace From 2fffdf3131fce2b8d84e6cef6f593fdfffdcf9ea Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Tue, 26 Oct 2021 20:47:16 +0200 Subject: [PATCH 15/22] update dependencies --- .github/workflows/android_main.yml | 4 ++-- app/build.gradle | 7 ++++--- app/src/main/AndroidManifest.xml | 8 ++------ build.gradle | 6 +++--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.github/workflows/android_main.yml b/.github/workflows/android_main.yml index 3694eb868a1f..b231d83f752b 100644 --- a/.github/workflows/android_main.yml +++ b/.github/workflows/android_main.yml @@ -4,7 +4,7 @@ on: [push] jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: checkout @@ -24,7 +24,7 @@ jobs: run: ./gradlew clean assembleDebug --stacktrace test: - runs-on: macos-latest + runs-on: macos-11 steps: - name: checkout diff --git a/app/build.gradle b/app/build.gradle index 7993af096d30..f7458c69bc62 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' -apply plugin: 'com.google.firebase.firebase-perf' +apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' +apply plugin: 'com.google.firebase.firebase-perf' android { compileSdkVersion 30 @@ -88,10 +89,9 @@ android { } dependencies { - implementation platform('com.google.firebase:firebase-bom:27.1.0') + implementation platform('com.google.firebase:firebase-bom:28.4.2') implementation 'com.google.firebase:firebase-storage' implementation 'com.google.firebase:firebase-auth' - implementation 'com.google.firebase:firebase-ads' implementation 'com.google.firebase:firebase-perf' implementation 'com.google.firebase:firebase-crashlytics-ndk' implementation 'com.google.firebase:firebase-inappmessaging-display' @@ -100,6 +100,7 @@ dependencies { implementation 'com.android.billingclient:billing:4.0.0' + implementation 'com.google.android.gms:play-services-ads:20.4.0' implementation 'com.google.android.play:core:1.10.2' implementation 'androidx.multidex:multidex:2.0.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 48cf78bc950e..977d16c980c6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,15 +2,11 @@ - - diff --git a/build.gradle b/build.gradle index b55a6ab315a1..aeebe0830268 100644 --- a/build.gradle +++ b/build.gradle @@ -6,10 +6,10 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.0.2' - classpath 'com.google.gms:google-services:4.3.8' + classpath 'com.android.tools.build:gradle:7.0.3' + classpath 'com.google.gms:google-services:4.3.10' classpath 'com.google.firebase:perf-plugin:1.4.0' - classpath 'com.google.firebase:firebase-crashlytics-gradle:2.6.1' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1' } } From 52c75803c9ed76aab84a43e2ebbfc4c9e553e860 Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Tue, 26 Oct 2021 20:49:08 +0200 Subject: [PATCH 16/22] update gems --- Gemfile.lock | 115 +++++++++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 53 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 88829d84b501..675a40754b14 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,26 +1,27 @@ GEM remote: https://rubygems.org/ specs: - CFPropertyList (3.0.3) - addressable (2.7.0) + CFPropertyList (3.0.4) + rexml + addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) artifactory (3.0.15) atomos (0.1.3) - aws-eventstream (1.1.1) - aws-partitions (1.461.0) - aws-sdk-core (3.114.0) + aws-eventstream (1.2.0) + aws-partitions (1.519.0) + aws-sdk-core (3.121.3) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.239.0) aws-sigv4 (~> 1.1) jmespath (~> 1.0) - aws-sdk-kms (1.43.0) - aws-sdk-core (~> 3, >= 3.112.0) + aws-sdk-kms (1.50.0) + aws-sdk-core (~> 3, >= 3.121.2) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.95.0) - aws-sdk-core (~> 3, >= 3.112.0) + aws-sdk-s3 (1.104.0) + aws-sdk-core (~> 3, >= 3.121.2) aws-sdk-kms (~> 1) - aws-sigv4 (~> 1.1) - aws-sigv4 (1.2.3) + aws-sigv4 (~> 1.4) + aws-sigv4 (1.4.0) aws-eventstream (~> 1, >= 1.0.2) babosa (1.0.4) claide (1.0.3) @@ -29,19 +30,22 @@ GEM commander (4.6.0) highline (~> 2.0.0) declarative (0.0.20) - digest-crc (0.6.3) + digest-crc (0.6.4) rake (>= 12.0.0, < 14.0.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) dotenv (2.7.6) - emoji_regex (3.2.2) - excon (0.81.0) - faraday (1.4.2) + emoji_regex (3.2.3) + excon (0.87.0) + faraday (1.8.0) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0.1) faraday-net_http (~> 1.0) faraday-net_http_persistent (~> 1.1) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) multipart-post (>= 1.2, < 3) ruby2_keywords (>= 0.0.4) faraday-cookie_jar (0.0.7) @@ -50,14 +54,17 @@ GEM faraday-em_http (1.0.0) faraday-em_synchrony (1.0.0) faraday-excon (1.1.0) + faraday-httpclient (1.0.1) faraday-net_http (1.0.1) - faraday-net_http_persistent (1.1.0) - faraday_middleware (1.0.0) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday_middleware (1.2.0) faraday (~> 1.0) - fastimage (2.2.3) - fastlane (2.184.0) + fastimage (2.2.5) + fastlane (2.197.0) CFPropertyList (>= 2.3, < 4.0.0) - addressable (>= 2.3, < 3.0.0) + addressable (>= 2.8, < 3.0.0) artifactory (~> 3.0) aws-sdk-s3 (~> 1.0) babosa (>= 1.0.3, < 2.0.0) @@ -72,7 +79,7 @@ GEM faraday_middleware (~> 1.0) fastimage (>= 2.1.0, < 3.0.0) gh_inspector (>= 1.1.2, < 2.0.0) - google-apis-androidpublisher_v3 (~> 0.1) + google-apis-androidpublisher_v3 (~> 0.3) google-apis-playcustomapp_v1 (~> 0.1) google-cloud-storage (~> 1.31) highline (~> 2.0) @@ -81,6 +88,7 @@ GEM mini_magick (>= 4.9.4, < 5.0.0) multipart-post (~> 2.0.0) naturally (~> 2.2) + optparse (~> 0.1.1) plist (>= 3.1.0, < 4.0.0) rubyzip (>= 2.0.0, < 3.0.0) security (= 0.1.3) @@ -94,63 +102,63 @@ GEM xcpretty (~> 0.3.0) xcpretty-travis-formatter (>= 0.0.3) gh_inspector (1.1.3) - google-apis-androidpublisher_v3 (0.3.0) - google-apis-core (~> 0.1) - google-apis-core (0.3.0) + google-apis-androidpublisher_v3 (0.12.0) + google-apis-core (>= 0.4, < 2.a) + google-apis-core (0.4.1) addressable (~> 2.5, >= 2.5.1) - googleauth (~> 0.14) - httpclient (>= 2.8.1, < 3.0) + googleauth (>= 0.16.2, < 2.a) + httpclient (>= 2.8.1, < 3.a) mini_mime (~> 1.0) representable (~> 3.0) - retriable (>= 2.0, < 4.0) + retriable (>= 2.0, < 4.a) rexml - signet (~> 0.14) webrick - google-apis-iamcredentials_v1 (0.3.0) - google-apis-core (~> 0.1) - google-apis-playcustomapp_v1 (0.2.0) - google-apis-core (~> 0.1) - google-apis-storage_v1 (0.3.0) - google-apis-core (~> 0.1) + google-apis-iamcredentials_v1 (0.7.0) + google-apis-core (>= 0.4, < 2.a) + google-apis-playcustomapp_v1 (0.5.0) + google-apis-core (>= 0.4, < 2.a) + google-apis-storage_v1 (0.8.0) + google-apis-core (>= 0.4, < 2.a) google-cloud-core (1.6.0) google-cloud-env (~> 1.0) google-cloud-errors (~> 1.0) google-cloud-env (1.5.0) faraday (>= 0.17.3, < 2.0) - google-cloud-errors (1.1.0) - google-cloud-storage (1.31.1) + google-cloud-errors (1.2.0) + google-cloud-storage (1.34.1) addressable (~> 2.5) digest-crc (~> 0.4) google-apis-iamcredentials_v1 (~> 0.1) google-apis-storage_v1 (~> 0.1) - google-cloud-core (~> 1.2) - googleauth (~> 0.9) + google-cloud-core (~> 1.6) + googleauth (>= 0.16.2, < 2.a) mini_mime (~> 1.0) - googleauth (0.16.2) + googleauth (1.1.0) faraday (>= 0.17.3, < 2.0) jwt (>= 1.4, < 3.0) memoist (~> 0.16) multi_json (~> 1.11) os (>= 0.9, < 2.0) - signet (~> 0.14) + signet (>= 0.16, < 2.a) highline (2.0.3) - http-cookie (1.0.3) + http-cookie (1.0.4) domain_name (~> 0.5) httpclient (2.8.3) jmespath (1.4.0) - json (2.5.1) - jwt (2.2.3) + json (2.6.1) + jwt (2.3.0) memoist (0.16.2) mini_magick (4.11.0) - mini_mime (1.1.0) + mini_mime (1.1.2) multi_json (1.15.0) multipart-post (2.0.0) nanaimo (0.3.0) naturally (2.2.1) + optparse (0.1.1) os (1.1.1) plist (3.6.0) public_suffix (4.0.6) - rake (13.0.3) + rake (13.0.6) representable (3.1.1) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) @@ -158,11 +166,11 @@ GEM retriable (3.1.2) rexml (3.2.5) rouge (2.0.7) - ruby2_keywords (0.0.4) - rubyzip (2.3.0) + ruby2_keywords (0.0.5) + rubyzip (2.3.2) security (0.1.3) - signet (0.15.0) - addressable (~> 2.3) + signet (0.16.0) + addressable (~> 2.8) faraday (>= 0.17.3, < 2.0) jwt (>= 1.5, < 3.0) multi_json (~> 1.10) @@ -180,16 +188,17 @@ GEM uber (0.1.0) unf (0.1.4) unf_ext - unf_ext (0.0.7.7) - unicode-display_width (1.7.0) + unf_ext (0.0.8) + unicode-display_width (1.8.0) webrick (1.7.0) word_wrap (1.0.0) - xcodeproj (1.19.0) + xcodeproj (1.21.0) CFPropertyList (>= 2.3.3, < 4.0) atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0) colored2 (~> 3.1) nanaimo (~> 0.3.0) + rexml (~> 3.2.4) xcpretty (0.3.0) rouge (~> 2.0.7) xcpretty-travis-formatter (1.0.1) @@ -202,4 +211,4 @@ DEPENDENCIES fastlane BUNDLED WITH - 1.17.3 + 2.2.5 From f83451a2800f6fb106b714bb35d62c3f4a64e2a5 Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Sat, 30 Oct 2021 08:32:26 +0200 Subject: [PATCH 17/22] fix integration of new core --- .github/workflows/android_main.yml | 2 +- CMakeLists.txt | 2 ++ OpenDocument.core | 2 +- app/src/main/AndroidManifest.xml | 4 ++-- .../main/java/at/tomtasche/reader/background/OdfLoader.java | 4 +--- .../main/java/at/tomtasche/reader/background/OoxmlLoader.java | 4 +--- build.gradle | 2 +- fastlane/README.md | 2 +- 8 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/workflows/android_main.yml b/.github/workflows/android_main.yml index b231d83f752b..771a0ac344d4 100644 --- a/.github/workflows/android_main.yml +++ b/.github/workflows/android_main.yml @@ -4,7 +4,7 @@ on: [push] jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-18.04 steps: - name: checkout diff --git a/CMakeLists.txt b/CMakeLists.txt index ef782f41c1b9..5ad04165e781 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.12.4) +project(odr-droid) + set(CMAKE_CXX_STANDARD 17) FILE(GLOB SRC diff --git a/OpenDocument.core b/OpenDocument.core index 37c273ff3ab8..0f56966ab7a3 160000 --- a/OpenDocument.core +++ b/OpenDocument.core @@ -1 +1 @@ -Subproject commit 37c273ff3ab83eefe8dbdc198111c1336d29dd58 +Subproject commit 0f56966ab7a36644e8b8d2b4953ef8187f649072 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3bbc83f822ac..f0a7156b8fc1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@ diff --git a/app/src/main/java/at/tomtasche/reader/background/OdfLoader.java b/app/src/main/java/at/tomtasche/reader/background/OdfLoader.java index 242f76a836f1..c08adb2718b5 100644 --- a/app/src/main/java/at/tomtasche/reader/background/OdfLoader.java +++ b/app/src/main/java/at/tomtasche/reader/background/OdfLoader.java @@ -58,11 +58,9 @@ private void translate(Options options, Result result) throws Exception { File cacheDirectory = AndroidFileCache.getCacheDirectory(cachedFile); - File fakeHtmlFile = new File(cacheDirectory, "odf"); - CoreWrapper.CoreOptions coreOptions = new CoreWrapper.CoreOptions(); coreOptions.inputPath = cachedFile.getPath(); - coreOptions.outputPath = fakeHtmlFile.getPath(); + coreOptions.outputPath = cacheDirectory.getPath(); coreOptions.password = options.password; coreOptions.editable = options.translatable; coreOptions.ooxml = false; diff --git a/app/src/main/java/at/tomtasche/reader/background/OoxmlLoader.java b/app/src/main/java/at/tomtasche/reader/background/OoxmlLoader.java index e329d0603194..f592f536d0ee 100644 --- a/app/src/main/java/at/tomtasche/reader/background/OoxmlLoader.java +++ b/app/src/main/java/at/tomtasche/reader/background/OoxmlLoader.java @@ -69,11 +69,9 @@ private void translate(Options options, Result result) throws Exception { File cacheDirectory = AndroidFileCache.getCacheDirectory(cacheFile); - File fakeHtmlFile = new File(cacheDirectory, "ooxml"); - CoreWrapper.CoreOptions coreOptions = new CoreWrapper.CoreOptions(); coreOptions.inputPath = cacheFile.getPath(); - coreOptions.outputPath = fakeHtmlFile.getPath(); + coreOptions.outputPath = cacheDirectory.getPath(); coreOptions.password = options.password; coreOptions.editable = options.translatable; coreOptions.ooxml = true; diff --git a/build.gradle b/build.gradle index aeebe0830268..e523cb2235ec 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.0.3' + classpath 'com.android.tools.build:gradle:7.0.2' classpath 'com.google.gms:google-services:4.3.10' classpath 'com.google.firebase:perf-plugin:1.4.0' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1' diff --git a/fastlane/README.md b/fastlane/README.md index 827060737259..b25d96c66c32 100644 --- a/fastlane/README.md +++ b/fastlane/README.md @@ -34,6 +34,6 @@ fastlane android tests ---- -This README.md is auto-generated and will be re-generated every time [fastlane](https://fastlane.tools) is run. +This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run. More information about fastlane can be found on [fastlane.tools](https://fastlane.tools). The documentation of fastlane can be found on [docs.fastlane.tools](https://docs.fastlane.tools). From c4e8b153734bd35dc6d7cd4e5104fcea0b30115e Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Thu, 4 Nov 2021 00:00:05 +0100 Subject: [PATCH 18/22] update core --- OpenDocument.core | 2 +- app/src/main/AndroidManifest.xml | 4 ++-- app/src/main/cpp/CoreWrapper.cpp | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/OpenDocument.core b/OpenDocument.core index 0f56966ab7a3..9c694e21dd84 160000 --- a/OpenDocument.core +++ b/OpenDocument.core @@ -1 +1 @@ -Subproject commit 0f56966ab7a36644e8b8d2b4953ef8187f649072 +Subproject commit 9c694e21dd840b3b00cdfc6f7fc163deba9529e9 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f0a7156b8fc1..ba1436176d0e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@ diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp index 28e865982ca2..f5fb8231fa80 100644 --- a/app/src/main/cpp/CoreWrapper.cpp +++ b/app/src/main/cpp/CoreWrapper.cpp @@ -104,6 +104,9 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject } catch (odr::WrongPassword) { env->SetIntField(result, errorField, -2); return result; + } catch (odr::UnsupportedFileType) { + env->SetIntField(result, errorField, -5); + return result; } catch (...) { env->SetIntField(result, errorField, -4); return result; From c272c2d08bd962974de00df2687aa387e7c4fe95 Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Thu, 9 Dec 2021 19:52:32 +0100 Subject: [PATCH 19/22] make catchAll-setting visible again, not sure why it went missing --- .../main/java/at/tomtasche/reader/ui/activity/MainActivity.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java b/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java index a863e1e61ff5..c3eee1241c29 100644 --- a/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java +++ b/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java @@ -215,8 +215,6 @@ private void initializeCatchAllSwitch() { toggleComponent(strictCatchComponent, !isCatchAllEnabled); SwitchCompat catchAllSwitch = findViewById(R.id.landing_catch_all); - LinearLayout parent = (LinearLayout) catchAllSwitch.getParent(); - parent.setVisibility(View.GONE); catchAllSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override From 9369636099f13ca5cedf127e5c64154aed545ab2 Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Sun, 12 Dec 2021 20:06:25 +0100 Subject: [PATCH 20/22] prepare AB test for intro --- OpenDocument.core | 2 +- app/build.gradle | 14 ++++---- app/src/main/AndroidManifest.xml | 4 +-- .../reader/nonfree/ConfigManager.java | 19 +++++++++- .../tomtasche/reader/nonfree/HelpManager.java | 7 ++-- .../reader/ui/EditActionModeCallback.java | 4 +-- .../reader/ui/activity/DocumentFragment.java | 8 ++--- .../reader/ui/activity/MainActivity.java | 36 ++++++++++++++----- app/src/main/res/menu/edit.xml | 2 +- app/src/main/res/menu/menu_main.xml | 13 ++++--- build.gradle | 6 ++-- 11 files changed, 75 insertions(+), 40 deletions(-) diff --git a/OpenDocument.core b/OpenDocument.core index 37c273ff3ab8..7f64196b1b70 160000 --- a/OpenDocument.core +++ b/OpenDocument.core @@ -1 +1 @@ -Subproject commit 37c273ff3ab83eefe8dbdc198111c1336d29dd58 +Subproject commit 7f64196b1b701c4b91fd33cd903ce79eb6a06443 diff --git a/app/build.gradle b/app/build.gradle index ea53d412bd8f..f41ea9601a62 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,13 +3,13 @@ apply plugin: 'com.google.firebase.firebase-perf' apply plugin: 'com.google.firebase.crashlytics' android { - compileSdkVersion 30 - ndkVersion "22.0.7026061" + compileSdkVersion 31 + ndkVersion "23.1.7779620" defaultConfig { applicationId "at.tomtasche.reader" minSdkVersion 19 - targetSdkVersion 30 + targetSdkVersion 31 testApplicationId "at.tomtasche.reader.test" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -88,7 +88,7 @@ android { } dependencies { - implementation platform('com.google.firebase:firebase-bom:28.1.0') + implementation platform('com.google.firebase:firebase-bom:29.0.2') implementation 'com.google.firebase:firebase-storage' implementation 'com.google.firebase:firebase-auth' implementation 'com.google.firebase:firebase-perf' @@ -97,15 +97,15 @@ dependencies { implementation 'com.google.firebase:firebase-analytics' implementation 'com.google.firebase:firebase-config' - implementation 'com.google.android.gms:play-services-ads:20.2.0' + implementation 'com.google.android.gms:play-services-ads:20.5.0' implementation 'com.android.billingclient:billing:4.0.0' implementation 'com.google.android.play:core:1.10.2' implementation 'androidx.multidex:multidex:2.0.1' - implementation 'androidx.appcompat:appcompat:1.3.1' - implementation 'androidx.core:core:1.6.0' + implementation 'androidx.appcompat:appcompat:1.4.0' + implementation 'androidx.core:core:1.7.0' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.webkit:webkit:1.4.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4b799545fda9..23e444130fd4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@ diff --git a/app/src/main/java/at/tomtasche/reader/nonfree/ConfigManager.java b/app/src/main/java/at/tomtasche/reader/nonfree/ConfigManager.java index 1ec384b81eb2..4f8a405c18ab 100644 --- a/app/src/main/java/at/tomtasche/reader/nonfree/ConfigManager.java +++ b/app/src/main/java/at/tomtasche/reader/nonfree/ConfigManager.java @@ -47,11 +47,24 @@ public void onComplete(@NonNull Task task) { }); } + public boolean isLoaded() { + if (!enabled) { + return true; + } + + return loaded; + } + public void setEnabled(boolean enabled) { this.enabled = enabled; } public void getBooleanConfig(String key, ConfigListener configListener) { + if (!enabled) { + configListener.onConfig(key, null); + return; + } + synchronized (callbacks) { if (!loaded) { callbacks.add(new Runnable() { @@ -69,7 +82,11 @@ public void run() { configListener.onConfig(key, value); } - public boolean getBooleanConfig(String key) { + public Boolean getBooleanConfig(String key) { + if (!enabled) { + return null; + } + return remoteConfig.getBoolean(key); } diff --git a/app/src/main/java/at/tomtasche/reader/nonfree/HelpManager.java b/app/src/main/java/at/tomtasche/reader/nonfree/HelpManager.java index d55fdadfb9dc..371250eb9d4b 100644 --- a/app/src/main/java/at/tomtasche/reader/nonfree/HelpManager.java +++ b/app/src/main/java/at/tomtasche/reader/nonfree/HelpManager.java @@ -4,6 +4,8 @@ import android.content.Intent; import android.net.Uri; +import at.tomtasche.reader.ui.activity.IntroActivity; + public class HelpManager { private boolean enabled; @@ -22,8 +24,7 @@ public void setEnabled(boolean enabled) { } public void show() { - context.startActivity(new Intent( - Intent.ACTION_VIEW, - Uri.parse("https://opendocument.app/"))); + Intent intent = new Intent(context, IntroActivity.class); + context.startActivity(intent); } } diff --git a/app/src/main/java/at/tomtasche/reader/ui/EditActionModeCallback.java b/app/src/main/java/at/tomtasche/reader/ui/EditActionModeCallback.java index 88708c02c9ef..d33ed266a698 100644 --- a/app/src/main/java/at/tomtasche/reader/ui/EditActionModeCallback.java +++ b/app/src/main/java/at/tomtasche/reader/ui/EditActionModeCallback.java @@ -19,11 +19,9 @@ import androidx.appcompat.view.ActionMode; import at.tomtasche.reader.R; -import at.tomtasche.reader.nonfree.AdManager; import at.tomtasche.reader.nonfree.HelpManager; import at.tomtasche.reader.ui.activity.DocumentFragment; import at.tomtasche.reader.ui.activity.MainActivity; -import at.tomtasche.reader.ui.widget.PageView; public class EditActionModeCallback implements ActionMode.Callback { @@ -65,7 +63,7 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu) { @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { - case R.id.edit_help: { + case R.id.menu_help: { helpManager.show(); break; diff --git a/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java b/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java index c6e54862124d..49b83c04985f 100644 --- a/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java +++ b/app/src/main/java/at/tomtasche/reader/ui/activity/DocumentFragment.java @@ -13,20 +13,16 @@ import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.TextView; import android.widget.Toast; -import com.google.android.gms.tasks.OnCompleteListener; -import com.google.android.gms.tasks.Task; import com.google.android.play.core.review.ReviewInfo; import com.google.android.play.core.review.ReviewManager; import com.google.android.play.core.review.ReviewManagerFactory; import com.google.firebase.analytics.FirebaseAnalytics; -import com.google.firebase.remoteconfig.FirebaseRemoteConfig; import java.io.File; import java.io.FileNotFoundException; @@ -409,6 +405,8 @@ public void run() { menu.findItem(R.id.menu_search).setVisible(enabled); menu.findItem(R.id.menu_tts).setVisible(enabled); + + menu.findItem(R.id.menu_help).setShowAsAction(enabled ? MenuItem.SHOW_AS_ACTION_NEVER : MenuItem.SHOW_AS_ACTION_ALWAYS); } @Override diff --git a/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java b/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java index c3eee1241c29..a61c85c12edf 100644 --- a/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java +++ b/app/src/main/java/at/tomtasche/reader/ui/activity/MainActivity.java @@ -21,6 +21,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.ViewTreeObserver; import android.view.WindowManager; import android.widget.CompoundButton; import android.widget.LinearLayout; @@ -142,10 +143,6 @@ public void onClick(View view) { printingManager = new PrintingManager(); initializeProprietaryLibraries(); - if (!IS_TESTING) { - showIntroActivity(); - } - initializeCatchAllSwitch(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { @@ -182,6 +179,29 @@ public void onClick(View view) { analyticsManager.setCurrentScreen(this, "screen_main"); } + + final View content = findViewById(android.R.id.content); + content.getViewTreeObserver().addOnPreDrawListener( + new ViewTreeObserver.OnPreDrawListener() { + @Override + public boolean onPreDraw() { + if (configManager.isLoaded()) { + if (IS_TESTING) { + return true; + } + + Boolean isShowIntro = configManager.getBooleanConfig("show_intro"); + if (isShowIntro == null || isShowIntro) { + showIntroActivityOnFirstStart(); + } + + content.getViewTreeObserver().removeOnPreDrawListener(this); + return true; + } else { + return false; + } + } + }); } @Override @@ -248,13 +268,12 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) { adManager.showGoogleAds(); } - private void showIntroActivity() { + private void showIntroActivityOnFirstStart() { SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(this); boolean wasIntroShown = getPrefs.getBoolean("introShown", false); if (!wasIntroShown) { - Intent intent = new Intent(MainActivity.this, IntroActivity.class); - startActivity(intent); + helpManager.show(); SharedPreferences.Editor editor = getPrefs.edit(); editor.putBoolean("introShown", true); @@ -295,7 +314,6 @@ public boolean requestSave() { } } - private void initializeProprietaryLibraries() { boolean useProprietaryLibraries = !getResources().getBoolean(R.bool.DISABLE_TRACKING); @@ -532,7 +550,7 @@ public void run() { break; } - case R.id.edit_help: { + case R.id.menu_help: { helpManager.show(); break; diff --git a/app/src/main/res/menu/edit.xml b/app/src/main/res/menu/edit.xml index 8c591ffda579..ae845abd398c 100644 --- a/app/src/main/res/menu/edit.xml +++ b/app/src/main/res/menu/edit.xml @@ -8,7 +8,7 @@ app:showAsAction="always" android:title="@string/action_edit_save" /> diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 2d0390d8d328..47306f04c32c 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -10,6 +10,14 @@ app:showAsAction="always" tools:ignore="AlwaysShowAction" /> + + - - diff --git a/build.gradle b/build.gradle index 0bc22906d4f0..0765180d7618 100644 --- a/build.gradle +++ b/build.gradle @@ -6,10 +6,10 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.1.2' - classpath 'com.google.gms:google-services:4.3.8' + classpath 'com.android.tools.build:gradle:4.1.3' + classpath 'com.google.gms:google-services:4.3.10' classpath 'com.google.firebase:perf-plugin:1.4.0' - classpath 'com.google.firebase:firebase-crashlytics-gradle:2.6.1' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1' } } From f28df7403faa08a8cf870a4def838e1ba1047c3e Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Sun, 12 Dec 2021 21:51:03 +0100 Subject: [PATCH 21/22] raise version --- app/src/main/AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ba1436176d0e..9ab57700aa67 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@ From 4e1c491cb46944e4a6da2dfe56521c77c4c6b7c4 Mon Sep 17 00:00:00 2001 From: Thomas Taschauer Date: Wed, 15 Dec 2021 19:44:57 +0100 Subject: [PATCH 22/22] raise version, fix Android 12 --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0992186b18be..e0c0114112a5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -102,7 +102,7 @@ dependencies { implementation 'com.android.billingclient:billing:4.0.0' - implementation 'com.google.android.gms:play-services-ads:20.4.0' + implementation 'com.google.android.gms:play-services-ads:20.5.0' implementation 'com.google.android.play:core:1.10.2' implementation 'androidx.multidex:multidex:2.0.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9ab57700aa67..49665f9e871c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@