aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java97
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MediaPreviewAdapter.java4
-rw-r--r--src/main/java/de/pixart/messenger/ui/util/Attachment.java34
3 files changed, 89 insertions, 46 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 451ac6bde..137fca339 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -146,41 +146,40 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public static final String RECENTLY_USED_QUICK_ACTION = "recently_used_quick_action";
public static final String STATE_CONVERSATION_UUID = ConversationFragment.class.getName() + ".uuid";
public static final String STATE_SCROLL_POSITION = ConversationFragment.class.getName() + ".scroll_position";
- public static final String STATE_PHOTO_URI = ConversationFragment.class.getName() + ".take_photo_uri";
- public static final String STATE_VIDEO_URI = ConversationFragment.class.getName() + ".take_video_uri";
+ public static final String STATE_PHOTO_URI = ConversationFragment.class.getName() + ".media_previews";
+ public static final String STATE_VIDEO_URI = ConversationFragment.class.getName() + ".media_previews";
+ public static final String STATE_MEDIA_PREVIEWS = ConversationFragment.class.getName() + ".take_photo_uri";
private static final String STATE_LAST_MESSAGE_UUID = "state_last_message_uuid";
private final List<Message> messageList = new ArrayList<>();
- final private List<Uri> mPendingImageUris = new ArrayList<>();
- private String lastMessageUuid = null;
- public Uri mPendingEditorContent = null;
private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
private final PendingItem<String> pendingConversationsUuid = new PendingItem<>();
+ private final PendingItem<ArrayList<Attachment>> pendingMediaPreviews = new PendingItem<>();
private final PendingItem<Bundle> pendingExtras = new PendingItem<>();
private final PendingItem<Uri> pendingTakePhotoUri = new PendingItem<>();
private final PendingItem<Uri> pendingTakeVideoUri = new PendingItem<>();
private final PendingItem<ScrollState> pendingScrollState = new PendingItem<>();
private final PendingItem<String> pendingLastMessageUuid = new PendingItem<>();
private final PendingItem<Message> pendingMessage = new PendingItem<>();
- protected MessageAdapter messageListAdapter;
- private Conversation conversation;
+ public Uri mPendingEditorContent = null;
public FragmentConversationBinding binding;
+ protected MessageAdapter messageListAdapter;
protected Message lastHistoryMessage = null;
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, dd. MMM yyyy", Locale.getDefault());
+ private String lastMessageUuid = null;
+ private Conversation conversation;
private Toast messageLoaderToast;
private ConversationsActivity activity;
- private boolean reInitRequiredOnStart = true;
- private MediaPreviewAdapter mediaPreviewAdapter;
-
- private SimpleFingerGestures gesturesDetector = new SimpleFingerGestures();
-
protected OnClickListener clickToVerify = new OnClickListener() {
@Override
public void onClick(View v) {
activity.verifyOtrSessionDialog(conversation, v);
}
};
+ private boolean reInitRequiredOnStart = true;
+ private MediaPreviewAdapter mediaPreviewAdapter;
+ private SimpleFingerGestures gesturesDetector = new SimpleFingerGestures();
private OnClickListener clickToMuc = new OnClickListener() {
@Override
@@ -487,32 +486,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
}
};
-
- @SuppressLint("RestrictedApi")
- private void choose_attachment(View v) {
- SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity);
- final boolean hideVoice = p.getBoolean("show_record_voice_btn", activity.getResources().getBoolean(R.bool.show_record_voice_btn));
- PopupMenu popup = new PopupMenu(activity, v);
- popup.inflate(R.menu.choose_attachment);
- Menu menu = popup.getMenu();
- ConversationMenuConfigurator.configureQuickShareAttachmentMenu(conversation, menu, hideVoice);
- popup.setOnMenuItemClickListener(attachmentItem -> {
- switch (attachmentItem.getItemId()) {
- case R.id.attach_choose_picture:
- case R.id.attach_take_picture:
- case R.id.attach_choose_file:
- case R.id.attach_record_voice:
- case R.id.attach_location:
- handleAttachmentSelection(attachmentItem);
- default:
- return false;
- }
- });
- MenuPopupHelper menuHelper = new MenuPopupHelper(getActivity(), (MenuBuilder) menu, v);
- menuHelper.setForceShowIcon(true);
- menuHelper.show();
- }
-
private View.OnLongClickListener mSendButtonLongListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
@@ -644,6 +617,31 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
}
+ @SuppressLint("RestrictedApi")
+ private void choose_attachment(View v) {
+ SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity);
+ final boolean hideVoice = p.getBoolean("show_record_voice_btn", activity.getResources().getBoolean(R.bool.show_record_voice_btn));
+ PopupMenu popup = new PopupMenu(activity, v);
+ popup.inflate(R.menu.choose_attachment);
+ Menu menu = popup.getMenu();
+ ConversationMenuConfigurator.configureQuickShareAttachmentMenu(conversation, menu, hideVoice);
+ popup.setOnMenuItemClickListener(attachmentItem -> {
+ switch (attachmentItem.getItemId()) {
+ case R.id.attach_choose_picture:
+ case R.id.attach_take_picture:
+ case R.id.attach_choose_file:
+ case R.id.attach_record_voice:
+ case R.id.attach_location:
+ handleAttachmentSelection(attachmentItem);
+ default:
+ return false;
+ }
+ });
+ MenuPopupHelper menuHelper = new MenuPopupHelper(getActivity(), (MenuBuilder) menu, v);
+ menuHelper.setForceShowIcon(true);
+ menuHelper.show();
+ }
+
private void toggleScrollDownButton() {
toggleScrollDownButton(binding.messagesView);
}
@@ -1470,10 +1468,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
clearHistoryDialog(conversation);
break;
case R.id.action_group_details:
- Intent intent = new Intent(activity, ConferenceDetailsActivity.class);
- intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
- intent.putExtra("uuid", conversation.getUuid());
- startActivity(intent);
+ Intent intent = new Intent(activity, ConferenceDetailsActivity.class);
+ intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
+ intent.putExtra("uuid", conversation.getUuid());
+ startActivity(intent);
break;
case R.id.action_contact_details:
activity.switchToContactDetails(conversation.getContact());
@@ -2034,6 +2032,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (scrollState != null) {
outState.putParcelable(STATE_SCROLL_POSITION, scrollState);
}
+ final ArrayList<Attachment> attachments = mediaPreviewAdapter.getAttachments();
+ if (attachments.size() > 0) {
+ outState.putParcelableArrayList(STATE_MEDIA_PREVIEWS, attachments);
+ }
}
}
@@ -2044,10 +2046,14 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return;
}
String uuid = savedInstanceState.getString(STATE_CONVERSATION_UUID);
+ ArrayList<Attachment> attachments = savedInstanceState.getParcelableArrayList(STATE_MEDIA_PREVIEWS);
pendingLastMessageUuid.push(savedInstanceState.getString(STATE_LAST_MESSAGE_UUID, null));
if (uuid != null) {
QuickLoader.set(uuid);
this.pendingConversationsUuid.push(uuid);
+ if (attachments != null && attachments.size() > 0) {
+ this.pendingMediaPreviews.push(attachments);
+ }
String takePhotoUri = savedInstanceState.getString(STATE_PHOTO_URI);
if (takePhotoUri != null) {
pendingTakePhotoUri.push(Uri.parse(takePhotoUri));
@@ -3044,9 +3050,15 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
reInit(conversation);
ScrollState scrollState = pendingScrollState.pop();
String lastMessageUuid = pendingLastMessageUuid.pop();
+ List<Attachment> attachments = pendingMediaPreviews.pop();
if (scrollState != null) {
setScrollPosition(scrollState, lastMessageUuid);
}
+ if (attachments != null && attachments.size() > 0) {
+ Log.d(Config.LOGTAG, "had attachments on restore");
+ mediaPreviewAdapter.addMediaPreviews(attachments);
+ toggleInputMethod();
+ }
return true;
}
@@ -3061,7 +3073,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
-
public Conversation getConversation() {
return conversation;
}
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MediaPreviewAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MediaPreviewAdapter.java
index bbcaa5dc6..c89ce6216 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MediaPreviewAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MediaPreviewAdapter.java
@@ -29,7 +29,7 @@ import de.pixart.messenger.ui.util.StyledAttributes;
public class MediaPreviewAdapter extends RecyclerView.Adapter<MediaPreviewAdapter.MediaPreviewViewHolder> {
- private final List<Attachment> mediaPreviews = new ArrayList<>();
+ private final ArrayList<Attachment> mediaPreviews = new ArrayList<>();
private final ConversationFragment conversationFragment;
@@ -150,7 +150,7 @@ public class MediaPreviewAdapter extends RecyclerView.Adapter<MediaPreviewAdapte
return mediaPreviews.size() > 0;
}
- public List<Attachment> getAttachments() {
+ public ArrayList<Attachment> getAttachments() {
return mediaPreviews;
}
diff --git a/src/main/java/de/pixart/messenger/ui/util/Attachment.java b/src/main/java/de/pixart/messenger/ui/util/Attachment.java
index 8c1d0c75e..f11efd0d1 100644
--- a/src/main/java/de/pixart/messenger/ui/util/Attachment.java
+++ b/src/main/java/de/pixart/messenger/ui/util/Attachment.java
@@ -33,6 +33,8 @@ import android.content.ClipData;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
+import android.os.Parcel;
+import android.os.Parcelable;
import android.util.Log;
import java.util.ArrayList;
@@ -43,11 +45,28 @@ import java.util.UUID;
import de.pixart.messenger.Config;
import de.pixart.messenger.utils.MimeUtils;
-public class Attachment {
+public class Attachment implements Parcelable {
+ public static final Creator<Attachment> CREATOR = new Parcelable.Creator<Attachment>() {
+ @Override
+ public Attachment createFromParcel(Parcel in) {
+ return new Attachment(in);
+ }
+
+ @Override
+ public Attachment[] newArray(int size) {
+ return new Attachment[size];
+ }
+ };
private final Uri uri;
private final Type type;
private final UUID uuid;
private final String mime;
+ Attachment(Parcel in) {
+ uri = in.readParcelable(Uri.class.getClassLoader());
+ mime = in.readString();
+ uuid = UUID.fromString(in.readString());
+ type = Type.valueOf(in.readString());
+ }
private Attachment(Uri uri, Type type, String mime) {
this.uri = uri;
this.type = type;
@@ -94,6 +113,19 @@ public class Attachment {
return uris;
}
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeParcelable(uri, flags);
+ dest.writeString(mime);
+ dest.writeString(uuid.toString());
+ dest.writeString(type.toString());
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
public String getMime() {
return mime;
}