Refactoring

pull/184/head
M66B 5 years ago
parent aae2808f5c
commit 2665774d66

@ -137,29 +137,6 @@
<action android:name="${applicationId}.REFRESH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="mailto" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="mailto" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
<activity
@ -223,9 +200,32 @@
<activity
android:name=".ActivityCompose"
android:exported="false"
android:exported="true"
android:launchMode="singleTask"
android:parentActivityName=".ActivityView" />
android:parentActivityName=".ActivityView">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="mailto" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="mailto" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
<activity
android:name=".ActivityEML"

@ -23,20 +23,13 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import androidx.core.content.FileProvider;
import androidx.documentfile.provider.DocumentFile;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.PreferenceManager;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -95,23 +88,6 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
@Override
protected void onExecuted(Bundle args, Boolean hasAccounts) {
if (hasAccounts) {
Intent intent = getIntent();
String action = intent.getAction();
Uri uri = intent.getData();
boolean mailto = (uri != null && "mailto".equals(uri.getScheme()));
if ((Intent.ACTION_VIEW.equals(action) && mailto) ||
(Intent.ACTION_SENDTO.equals(action) && mailto) ||
Intent.ACTION_SEND.equals(action) ||
Intent.ACTION_SEND_MULTIPLE.equals(action)) {
processStreams(intent);
intent.setClass(ActivityMain.this, ActivityCompose.class);
startActivity(intent);
finish();
return;
}
Log.logBundle(args);
Intent view = new Intent(ActivityMain.this, ActivityView.class);
view.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@ -146,63 +122,6 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getSupportFragmentManager(), ex);
}
// Copy content local to prevent security exceptions
private void processStreams(Intent intent) {
intent.setClipData(null);
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
if (Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) {
ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (uris == null)
intent.removeExtra(Intent.EXTRA_STREAM);
else {
ArrayList<Uri> processed = new ArrayList<>();
for (Uri uri : uris)
processed.add(processUri(uri));
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, processed);
}
} else {
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri == null)
intent.removeExtra(Intent.EXTRA_STREAM);
else
intent.putExtra(Intent.EXTRA_STREAM, processUri(uri));
}
}
}
private Uri processUri(Uri uri) {
try {
String fname = null;
try {
DocumentFile dfile = DocumentFile.fromSingleUri(ActivityMain.this, uri);
if (dfile != null)
fname = dfile.getName();
} catch (SecurityException ex) {
Log.e(ex);
}
if (TextUtils.isEmpty(fname))
fname = uri.getLastPathSegment();
if (TextUtils.isEmpty(fname))
return uri;
File dir = new File(getCacheDir(), "shared");
if (!dir.exists())
dir.mkdir();
File file = new File(dir, fname);
Log.i("Copying shared file to " + file);
Helper.copy(getContentResolver().openInputStream(uri), new FileOutputStream(file));
return FileProvider.getUriForFile(ActivityMain.this, BuildConfig.APPLICATION_ID, file);
} catch (Throwable ex) {
Log.w(ex);
return uri;
}
}
};
if (Helper.shouldAuthenticate(this))

@ -170,7 +170,7 @@ class Shortcuts {
boolean identicons = prefs.getBoolean("identicons", false);
boolean circular = prefs.getBoolean("circular", true);
Intent intent = new Intent(context, ActivityMain.class);
Intent intent = new Intent(context, ActivityCompose.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setAction(Intent.ACTION_SEND);
intent.addCategory(Intent.CATEGORY_DEFAULT);

@ -12,9 +12,6 @@
<cache-path
name="calendar"
path="calendar" />
<cache-path
name="shared"
path="shared" />
<cache-path
name="images"
path="images" />

Loading…
Cancel
Save