Skip to content

Commit

Permalink
Merge pull request #174 from opendocument-app/development
Browse files Browse the repository at this point in the history
3.2.9
  • Loading branch information
TomTasche authored Apr 13, 2020
2 parents 176780b + d7f5138 commit f3c6daa
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ option (ODR_TEST "" OFF)
set(ODR_TEST OFF)

add_subdirectory(OpenDocument.core)
target_link_libraries(odr-core odr)
target_link_libraries(odr-core odr-shared)
2 changes: 1 addition & 1 deletion OpenDocument.core
9 changes: 4 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ android {
targets "odr-core"
}
}

}

dexOptions {
Expand Down Expand Up @@ -89,10 +88,10 @@ dependencies {
implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.google.firebase:firebase-auth:19.3.0'
implementation 'com.google.firebase:firebase-ads:19.0.1'
implementation 'com.google.firebase:firebase-core:17.2.3'
implementation 'com.google.firebase:firebase-perf:19.0.5'
implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta02'
implementation 'com.google.firebase:firebase-crashlytics-ndk:17.0.0-beta01'
implementation 'com.google.firebase:firebase-core:17.3.0'
implementation 'com.google.firebase:firebase-perf:19.0.6'
implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta04'
implementation 'com.google.firebase:firebase-crashlytics-ndk:17.0.0-beta04'

implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.appcompat:appcompat:1.1.0'
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
package="at.tomtasche.reader"
android:installLocation="auto"
android:versionCode="126"
android:versionName="3.2.8"
android:versionCode="127"
android:versionName="3.2.9"
tools:ignore="GoogleAppIndexingWarning">

<!-- added by HelpCrunch SDK otherwise -->
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/cpp/CoreWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,17 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env,
jfieldID outputPathField = env->GetFieldID(resultClass, "outputPath", "Ljava/lang/String;");
env->SetObjectField(result, outputPathField, outputPath);

bool translated = translator->backTranslate(htmlDiffCpp, outputPathCpp);
if (!translated) {
bool success = translator->edit(htmlDiffCpp);
if (!success) {
env->SetIntField(result, errorField, -4);
return result;
}

success = translator->save(outputPathCpp);
if (!success) {
env->SetIntField(result, errorField, -5);
return result;
}
} catch (...) {
env->SetIntField(result, errorField, -3);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class OnlineLoader extends FileLoader {
};
private static final String[] MIME_BLACKLIST = {"image/x-tga", "image/vnd.djvu", "image/g3fax", "audio/amr", "text/calendar", "text/vcard", "video/3gpp"};

public static final String GOOGLE_VIEWER_URL = "https://docs.google.com/viewer?embedded=true&url=";
public static final String MICROSOFT_VIEWER_URL = "https://view.officeapps.live.com/op/view.aspx?src=";

private StorageReference storage;
private FirebaseAuth auth;

Expand Down Expand Up @@ -136,8 +139,16 @@ public void loadSync(Options options) {
Task<Uri> urlTask = reference.getDownloadUrl();
Tasks.await(urlTask);

String viewerUrl;
if (options.fileType.contains("vnd.oasis.opendocument")) {
viewerUrl = MICROSOFT_VIEWER_URL;
} else {
// ODF does not seem to be supported by google docs viewer
viewerUrl = GOOGLE_VIEWER_URL;
}

String downloadUrl = urlTask.getResult().toString();
Uri viewerUri = Uri.parse("https://docs.google.com/viewer?embedded=true&url="
Uri viewerUri = Uri.parse(viewerUrl
+ URLEncoder.encode(downloadUrl, StreamUtil.ENCODING));

result.partTitles.add(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ public OoxmlLoader(Context context) {

@Override
public boolean isSupported(Options options) {
if (true) {
// TODO: not stable enough yet
return false;
}

// TODO: enable xlsx and pptx too
return options.fileType.startsWith("application/vnd.openxmlformats-officedocument.wordprocessingml.document") /*|| options.fileType.startsWith("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") || options.fileType.startsWith("application/vnd.openxmlformats-officedocument.spreadsheetml.presentation")*/;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public void onClick(DialogInterface dialog,
}

return;
} else if (result.loaderType == FileLoader.LoaderType.PDF) {
} else if (result.loaderType == FileLoader.LoaderType.PDF || result.loaderType == FileLoader.LoaderType.OOXML || result.loaderType == FileLoader.LoaderType.DOC) {
crashManager.log(error, options.originalUri);

offerUpload(activity, options, true);
Expand Down Expand Up @@ -549,12 +549,20 @@ private void offerReopen(Activity activity, FileLoader.Options options, int desc
SnackbarHelper.show(activity, description, new Runnable() {
@Override
public void run() {
loadReopen(options, activity, true);
doReopen(options, activity, true, false);
}
}, isIndefinite, false);
}

private void loadReopen(FileLoader.Options options, Activity activity, boolean grantPermission) {
public void openWith(Activity activity) {
doReopen(lastResult.options, activity, true, false);
}

public void share(Activity activity) {
doReopen(lastResult.options, activity, true, true);
}

private void doReopen(FileLoader.Options options, Activity activity, boolean grantPermission, boolean share) {
Uri reopenUri = null;
Uri cacheUri = options.cacheUri;
String fileType = options.fileType;
Expand All @@ -579,13 +587,23 @@ private void loadReopen(FileLoader.Options options, Activity activity, boolean g
}

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);

String action = share ? Intent.ACTION_SEND : Intent.ACTION_VIEW;
intent.setAction(action);

Uri streamUri;
if (!"N/A".equals(fileType)) {
intent.setDataAndType(reopenUri, fileType);
} else if (reopenUri != null) {
intent.setData(reopenUri);

streamUri = reopenUri;
} else {
intent.setData(options.originalUri);
if (reopenUri != null) {
streamUri = reopenUri;
} else {
streamUri = options.originalUri;
}

intent.setData(streamUri);
}

// taken from: https://stackoverflow.com/a/23268821/198996
Expand All @@ -602,6 +620,10 @@ private void loadReopen(FileLoader.Options options, Activity activity, boolean g
targetIntent.setPackage(packageName);
targetIntent.setComponent(new ComponentName(packageName, currentInfo.activityInfo.name));

if (share) {
targetIntent.putExtra(Intent.EXTRA_STREAM, streamUri);
}

if (grantPermission) {
targetIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
Expand All @@ -610,13 +632,15 @@ private void loadReopen(FileLoader.Options options, Activity activity, boolean g
}
}

String logPrefix = share ? "share" : "reopen";

Intent initialIntent;
if (targetIntents.size() > 0) {
initialIntent = targetIntents.remove(0);
analyticsManager.report("reopen_success", FirebaseAnalytics.Param.CONTENT_TYPE, fileType);
analyticsManager.report(logPrefix + "_success", FirebaseAnalytics.Param.CONTENT_TYPE, fileType);
} else {
initialIntent = intent;
analyticsManager.report("reopen_failed_noapp", FirebaseAnalytics.Param.CONTENT_TYPE, fileType);
analyticsManager.report(logPrefix + "_failed_noapp", FirebaseAnalytics.Param.CONTENT_TYPE, fileType);
}

Intent chooserIntent = Intent.createChooser(initialIntent, activity.getString(R.string.reopen_chooser_title));
Expand All @@ -628,7 +652,8 @@ private void loadReopen(FileLoader.Options options, Activity activity, boolean g
crashManager.log(e);

if (grantPermission) {
loadReopen(options, activity, false);
// if we're trying to reopen the originalUri, the provider might decline the request
doReopen(options, activity, false, share);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,20 @@ public boolean onOptionsItemSelected(MenuItem item) {

break;
}
case R.id.menu_open_with: {
documentFragment.openWith(this);

analyticsManager.report("menu_open_with");

break;
}
case R.id.menu_share: {
documentFragment.share(this);

analyticsManager.report("menu_share");

break;
}
case R.id.menu_remove_ads: {
analyticsManager.report("menu_remove_ads");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import androidx.annotation.Keep;
import at.tomtasche.reader.background.AndroidFileCache;
import at.tomtasche.reader.background.OnlineLoader;
import at.tomtasche.reader.background.StreamUtil;
import at.tomtasche.reader.nonfree.CrashManager;
import at.tomtasche.reader.ui.ParagraphListener;
Expand Down Expand Up @@ -99,7 +100,7 @@ public void onPageCommitVisible(WebView view, String url) {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("https://docs.google.com/viewer?embedded=true")) {
if (url.startsWith(OnlineLoader.GOOGLE_VIEWER_URL) || url.startsWith(OnlineLoader.MICROSOFT_VIEWER_URL) || url.contains("officeapps.live.com/")) {
return false;
} else {
try {
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
android:icon="@drawable/ic_fullscreen"
android:title="@string/menu_fullscreen"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_open_with"
android:title="@string/menu_open_with"
app:showAsAction="never" />
<item
android:id="@+id/menu_share"
android:title="@string/menu_share"
app:showAsAction="never" />
<item
android:id="@+id/menu_print"
android:title="@string/menu_cloud_print"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<string name="menu_recent">Recently opened documents</string>
<string name="menu_search">Search in document</string>
<string name="menu_open">Open document</string>
<string name="menu_open_with">Open with...</string>
<string name="menu_share">Share document</string>
<string name="menu_edit">Edit document</string>
<string name="menu_remove_ads">Remove advertisements</string>
<string name="menu_fullscreen">Open fullscreen mode</string>
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ buildscript {
jcenter()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'com.google.firebase:perf-plugin:1.3.1'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta03'
Expand Down

0 comments on commit f3c6daa

Please sign in to comment.