|
|
@ -21,6 +21,7 @@ package eu.faircode.email;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.ResolveInfo;
|
|
|
|
import android.content.pm.ResolveInfo;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
@ -59,6 +60,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
|
|
|
private Context context;
|
|
|
|
private Context context;
|
|
|
|
private LifecycleOwner owner;
|
|
|
|
private LifecycleOwner owner;
|
|
|
|
private boolean readonly;
|
|
|
|
private boolean readonly;
|
|
|
|
|
|
|
|
private boolean confirm;
|
|
|
|
private boolean debug;
|
|
|
|
private boolean debug;
|
|
|
|
|
|
|
|
|
|
|
|
private List<EntityAttachment> all = new ArrayList<>();
|
|
|
|
private List<EntityAttachment> all = new ArrayList<>();
|
|
|
@ -181,6 +183,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
|
|
|
List<ResolveInfo> ris = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
|
|
|
List<ResolveInfo> ris = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
|
|
|
for (ResolveInfo ri : ris) {
|
|
|
|
for (ResolveInfo ri : ris) {
|
|
|
|
Log.i(Helper.TAG, "Target=" + ri);
|
|
|
|
Log.i(Helper.TAG, "Target=" + ri);
|
|
|
|
|
|
|
|
context.grantUriPermission(ri.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
targets.add(new NameResolveInfo(
|
|
|
|
targets.add(new NameResolveInfo(
|
|
|
|
pm.getApplicationIcon(ri.activityInfo.applicationInfo),
|
|
|
|
pm.getApplicationIcon(ri.activityInfo.applicationInfo),
|
|
|
|
pm.getApplicationLabel(ri.activityInfo.applicationInfo).toString(),
|
|
|
|
pm.getApplicationLabel(ri.activityInfo.applicationInfo).toString(),
|
|
|
@ -193,32 +196,34 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_attachment, null);
|
|
|
|
if (confirm) {
|
|
|
|
final AlertDialog dialog = new DialogBuilderLifecycle(context, owner)
|
|
|
|
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_attachment, null);
|
|
|
|
.setView(dview)
|
|
|
|
final AlertDialog dialog = new DialogBuilderLifecycle(context, owner)
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setView(dview)
|
|
|
|
.create();
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
|
|
|
|
.create();
|
|
|
|
TextView tvName = dview.findViewById(R.id.tvName);
|
|
|
|
|
|
|
|
TextView tvType = dview.findViewById(R.id.tvType);
|
|
|
|
TextView tvName = dview.findViewById(R.id.tvName);
|
|
|
|
ListView lvApp = dview.findViewById(R.id.lvApp);
|
|
|
|
TextView tvType = dview.findViewById(R.id.tvType);
|
|
|
|
|
|
|
|
ListView lvApp = dview.findViewById(R.id.lvApp);
|
|
|
|
tvName.setText(attachment.name);
|
|
|
|
|
|
|
|
tvType.setText(attachment.type);
|
|
|
|
tvName.setText(attachment.name);
|
|
|
|
|
|
|
|
tvType.setText(attachment.type);
|
|
|
|
lvApp.setAdapter(new TargetAdapter(context, R.layout.item_target, targets));
|
|
|
|
|
|
|
|
lvApp.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
lvApp.setAdapter(new TargetAdapter(context, R.layout.item_target, targets));
|
|
|
|
@Override
|
|
|
|
lvApp.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
@Override
|
|
|
|
NameResolveInfo selected = (NameResolveInfo) parent.getItemAtPosition(position);
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
context.grantUriPermission(selected.info.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
NameResolveInfo selected = (NameResolveInfo) parent.getItemAtPosition(position);
|
|
|
|
intent.setPackage(selected.info.activityInfo.packageName);
|
|
|
|
intent.setPackage(selected.info.activityInfo.packageName);
|
|
|
|
context.startActivity(intent);
|
|
|
|
context.startActivity(intent);
|
|
|
|
dialog.dismiss();
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (attachment.progress == null) {
|
|
|
|
if (attachment.progress == null) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Bundle args = new Bundle();
|
|
|
@ -293,10 +298,12 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AdapterAttachment(Context context, LifecycleOwner owner, boolean readonly) {
|
|
|
|
AdapterAttachment(Context context, LifecycleOwner owner, boolean readonly) {
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
this.context = context;
|
|
|
|
this.context = context;
|
|
|
|
this.owner = owner;
|
|
|
|
this.owner = owner;
|
|
|
|
this.readonly = readonly;
|
|
|
|
this.readonly = readonly;
|
|
|
|
this.debug = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("debug", false);
|
|
|
|
this.confirm = prefs.getBoolean("confirm", false);
|
|
|
|
|
|
|
|
this.debug = prefs.getBoolean("debug", false);
|
|
|
|
setHasStableIds(true);
|
|
|
|
setHasStableIds(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|