forked from mirrors/Fedilab
Fix issue #665 - Adding description failed when sharing
This commit is contained in:
parent
c1814aa5e9
commit
e919e98b68
6 changed files with 47 additions and 34 deletions
|
@ -1076,8 +1076,12 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
if (imageUri != null) {
|
||||
Bundle b = new Bundle();
|
||||
b.putParcelable(Helper.ARG_SHARE_URI, imageUri);
|
||||
CrossActionHelper.doCrossShare(BaseMainActivity.this, b);
|
||||
List<Uri> uris = new ArrayList<>();
|
||||
uris.add(imageUri);
|
||||
Helper.createAttachmentFromUri(BaseMainActivity.this, uris, attachments -> {
|
||||
b.putSerializable(Helper.ARG_MEDIA_ATTACHMENTS, new ArrayList<>(attachments));
|
||||
CrossActionHelper.doCrossShare(BaseMainActivity.this, b);
|
||||
});
|
||||
} else {
|
||||
Toasty.warning(BaseMainActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
@ -1087,7 +1091,10 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
ArrayList<Uri> imageList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||
if (imageList != null) {
|
||||
Bundle b = new Bundle();
|
||||
b.putParcelableArrayList(Helper.ARG_SHARE_URI_LIST, imageList);
|
||||
Helper.createAttachmentFromUri(BaseMainActivity.this, imageList, attachments -> {
|
||||
b.putSerializable(Helper.ARG_MEDIA_ATTACHMENTS, new ArrayList<>(attachments));
|
||||
CrossActionHelper.doCrossShare(BaseMainActivity.this, b);
|
||||
});
|
||||
CrossActionHelper.doCrossShare(BaseMainActivity.this, b);
|
||||
} else {
|
||||
Toasty.warning(BaseMainActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
|
|
|
@ -109,6 +109,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
|||
private ComposeAdapter composeAdapter;
|
||||
private boolean promptSaveDraft;
|
||||
private boolean restoredDraft;
|
||||
private List<Attachment> sharedAttachments;
|
||||
|
||||
|
||||
private final BroadcastReceiver imageReceiver = new BroadcastReceiver() {
|
||||
|
@ -147,8 +148,6 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
|||
private app.fedilab.android.client.entities.api.Account accountMention;
|
||||
private String statusReplyId;
|
||||
private app.fedilab.android.client.entities.api.Account mentionBooster;
|
||||
private ArrayList<Uri> sharedUriList = new ArrayList<>();
|
||||
private Uri sharedUri;
|
||||
private String sharedSubject, sharedContent, sharedTitle, sharedDescription, shareURL, sharedUrlMedia;
|
||||
private String editMessageId;
|
||||
|
||||
|
@ -483,8 +482,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
|||
mentionBooster = (app.fedilab.android.client.entities.api.Account) b.getSerializable(Helper.ARG_MENTION_BOOSTER);
|
||||
accountMention = (app.fedilab.android.client.entities.api.Account) b.getSerializable(Helper.ARG_ACCOUNT_MENTION);
|
||||
//Shared elements
|
||||
sharedUriList = b.getParcelableArrayList(Helper.ARG_SHARE_URI_LIST);
|
||||
sharedUri = b.getParcelable(Helper.ARG_SHARE_URI);
|
||||
sharedAttachments = (ArrayList<Attachment>) b.getSerializable(Helper.ARG_MEDIA_ATTACHMENTS);
|
||||
sharedUrlMedia = b.getString(Helper.ARG_SHARE_URL_MEDIA);
|
||||
sharedSubject = b.getString(Helper.ARG_SHARE_SUBJECT, null);
|
||||
sharedContent = b.getString(Helper.ARG_SHARE_CONTENT, null);
|
||||
|
@ -678,18 +676,19 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
|||
}, 0, 10000);
|
||||
}
|
||||
|
||||
if (sharedUriList != null && sharedUriList.size() > 0) {
|
||||
List<Uri> uris = new ArrayList<>(sharedUriList);
|
||||
Helper.createAttachmentFromUri(ComposeActivity.this, uris, attachment -> {
|
||||
if (sharedAttachments != null && sharedAttachments.size() > 0) {
|
||||
for (Attachment attachment : sharedAttachments) {
|
||||
composeAdapter.addAttachment(-1, attachment);
|
||||
});
|
||||
} else if (sharedUri != null && !sharedUri.toString().startsWith("http")) {
|
||||
}
|
||||
} /*else if (sharedUri != null && !sharedUri.toString().startsWith("http")) {
|
||||
List<Uri> uris = new ArrayList<>();
|
||||
uris.add(sharedUri);
|
||||
Helper.createAttachmentFromUri(ComposeActivity.this, uris, attachment -> {
|
||||
composeAdapter.addAttachment(-1, attachment);
|
||||
Helper.createAttachmentFromUri(ComposeActivity.this, uris, attachments -> {
|
||||
for(Attachment attachment: attachments) {
|
||||
composeAdapter.addAttachment(-1, attachment);
|
||||
}
|
||||
});
|
||||
} else if (shareURL != null) {
|
||||
} */ else if (shareURL != null) {
|
||||
|
||||
Helper.download(ComposeActivity.this, sharedUrlMedia, new OnDownloadInterface() {
|
||||
@Override
|
||||
|
|
|
@ -96,7 +96,7 @@ public class CacheHelper {
|
|||
String[] children = dir.list();
|
||||
assert children != null;
|
||||
for (String aChildren : children) {
|
||||
if (!aChildren.equals("databases") && !aChildren.equals("shared_prefs")) {
|
||||
if (!aChildren.equals("databases") && !aChildren.equals("shared_prefs") && !aChildren.equals(Helper.TEMP_MEDIA_DIRECTORY)) {
|
||||
boolean success = deleteDir(new File(dir, aChildren));
|
||||
if (!success) {
|
||||
return false;
|
||||
|
|
|
@ -235,10 +235,8 @@ public class Helper {
|
|||
public static final String ARG_MINIFIED = "ARG_MINIFIED";
|
||||
public static final String ARG_STATUS_REPORT = "ARG_STATUS_REPORT";
|
||||
public static final String ARG_STATUS_MENTION = "ARG_STATUS_MENTION";
|
||||
public static final String ARG_SHARE_URI = "ARG_SHARE_URI";
|
||||
public static final String ARG_SHARE_URL_MEDIA = "ARG_SHARE_URL_MEDIA";
|
||||
public static final String ARG_SHARE_URL = "ARG_SHARE_URL";
|
||||
public static final String ARG_SHARE_URI_LIST = "ARG_SHARE_URI_LIST";
|
||||
public static final String ARG_SHARE_TITLE = "ARG_SHARE_TITLE";
|
||||
public static final String ARG_SHARE_SUBJECT = "ARG_SHARE_SUBJECT";
|
||||
public static final String ARG_SHARE_DESCRIPTION = "ARG_SHARE_DESCRIPTION";
|
||||
|
@ -258,6 +256,7 @@ public class Helper {
|
|||
public static final String ARG_TAG_TIMELINE = "ARG_TAG_TIMELINE";
|
||||
public static final String ARG_MEDIA_POSITION = "ARG_MEDIA_POSITION";
|
||||
public static final String ARG_MEDIA_ATTACHMENT = "ARG_MEDIA_ATTACHMENT";
|
||||
public static final String ARG_MEDIA_ATTACHMENTS = "ARG_MEDIA_ATTACHMENTS";
|
||||
public static final String ARG_SHOW_REPLIES = "ARG_SHOW_REPLIES";
|
||||
public static final String ARG_SHOW_REBLOGS = "ARG_SHOW_REBLOGS";
|
||||
public static final String ARG_INITIALIZE_VIEW = "ARG_INITIALIZE_VIEW";
|
||||
|
@ -1220,6 +1219,7 @@ public class Helper {
|
|||
|
||||
public static void createAttachmentFromUri(Context context, List<Uri> uris, OnAttachmentCopied callBack) {
|
||||
new Thread(() -> {
|
||||
List<Attachment> attachments = new ArrayList<>();
|
||||
for (Uri uri : uris) {
|
||||
Attachment attachment = new Attachment();
|
||||
attachment.filename = Helper.getFileName(context, uri);
|
||||
|
@ -1274,11 +1274,11 @@ public class Helper {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> callBack.onAttachmentCopied(attachment);
|
||||
mainHandler.post(myRunnable);
|
||||
attachments.add(attachment);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> callBack.onAttachmentCopied(attachments);
|
||||
mainHandler.post(myRunnable);
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
@ -1328,6 +1328,7 @@ public class Helper {
|
|||
|
||||
public static void createAttachmentFromPAth(String path, OnAttachmentCopied callBack) {
|
||||
new Thread(() -> {
|
||||
List<Attachment> attachmentList = new ArrayList<>();
|
||||
Attachment attachment = new Attachment();
|
||||
attachment.mimeType = "image/*";
|
||||
String extension = "jpg";
|
||||
|
@ -1336,7 +1337,8 @@ public class Helper {
|
|||
Date now = new Date();
|
||||
attachment.filename = formatter.format(now) + "." + extension;
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> callBack.onAttachmentCopied(attachment);
|
||||
attachmentList.add(attachment);
|
||||
Runnable myRunnable = () -> callBack.onAttachmentCopied(attachmentList);
|
||||
mainHandler.post(myRunnable);
|
||||
}).start();
|
||||
}
|
||||
|
@ -1733,7 +1735,11 @@ public class Helper {
|
|||
fileName = FileNameCleaner.cleanFileName(fileName);
|
||||
// opens input stream from the HTTP connection
|
||||
InputStream inputStream = httpURLConnection.getInputStream();
|
||||
File saveDir = context.getCacheDir();
|
||||
final File saveDir = new File(context.getCacheDir(), TEMP_MEDIA_DIRECTORY);
|
||||
boolean isCertCacheDirExists = saveDir.exists();
|
||||
if (!isCertCacheDirExists) {
|
||||
saveDir.mkdirs();
|
||||
}
|
||||
final String saveFilePath = saveDir + File.separator + fileName;
|
||||
// opens an output stream to save into file
|
||||
FileOutputStream outputStream = new FileOutputStream(saveFilePath);
|
||||
|
@ -1979,7 +1985,7 @@ public class Helper {
|
|||
}
|
||||
|
||||
public interface OnAttachmentCopied {
|
||||
void onAttachmentCopied(Attachment attachment);
|
||||
void onAttachmentCopied(List<Attachment> attachments);
|
||||
}
|
||||
|
||||
public interface OnFileCopied {
|
||||
|
|
|
@ -10,7 +10,6 @@ import android.graphics.Typeface;
|
|||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.animation.AnticipateOvershootInterpolator;
|
||||
|
@ -179,8 +178,6 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
|
|||
}
|
||||
uri = resultUri;
|
||||
}
|
||||
} else {
|
||||
Log.e(Helper.TAG, "onActivityResult...Error CropImage: " + result.getError());
|
||||
}
|
||||
});
|
||||
mPhotoEditor.setFilterEffect(PhotoFilter.NONE);
|
||||
|
@ -299,7 +296,7 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
|
|||
int imgHeightInEditor;
|
||||
int imgWidthInEditor;
|
||||
//If the original image has its height greater than width => heights are equals
|
||||
float focusX = -2, focusY = -2;
|
||||
float focusX, focusY;
|
||||
if (imageHeight > imageWidth) {
|
||||
imgHeightInEditor = pHeight;
|
||||
float ratio = (float) pHeight / (float) imageHeight;
|
||||
|
@ -325,7 +322,6 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
|
|||
intentImage.putExtra("focusY", focusY);
|
||||
|
||||
}
|
||||
|
||||
LocalBroadcastManager.getInstance(EditImageActivity.this).sendBroadcast(intentImage);
|
||||
finish();
|
||||
}
|
||||
|
@ -415,8 +411,6 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
|
|||
}
|
||||
uri = resultUri;
|
||||
}
|
||||
} else {
|
||||
Log.e(Helper.TAG, "onActivityResult...Error CropImage: " + result.getError());
|
||||
}
|
||||
});
|
||||
cropImageContractOptionsActivityResultLauncher.launch(cropImageContractOptions);
|
||||
|
|
|
@ -221,8 +221,10 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||
promptDraftListener.promptDraft();
|
||||
}
|
||||
int finalPosition = position;
|
||||
Helper.createAttachmentFromUri(context, uris, attachment -> {
|
||||
statusList.get(finalPosition).media_attachments.add(attachment);
|
||||
Helper.createAttachmentFromUri(context, uris, attachments -> {
|
||||
for (Attachment attachment : attachments) {
|
||||
statusList.get(finalPosition).media_attachments.add(attachment);
|
||||
}
|
||||
notifyItemChanged(finalPosition);
|
||||
});
|
||||
}
|
||||
|
@ -1098,6 +1100,11 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
||||
super.onLoadFailed(errorDrawable);
|
||||
}
|
||||
});
|
||||
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||
if (attachment.description != null) {
|
||||
|
|
Loading…
Reference in a new issue