aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-03-31 00:35:16 +0200
committerChristian Schneppe <christian@pix-art.de>2018-03-31 00:35:16 +0200
commit362eddae27568674e78aa4968b1a4165cd67f517 (patch)
treef2a8390e246df239eded72ee7f9fb1be91209f5d /src/main/java/de/pixart/messenger
parent506b1488d3ff013e232f222db0037303a29ed8a5 (diff)
fixed take photo + do not reint twice
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java89
1 files changed, 64 insertions, 25 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 1f6540a79..e310ed089 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -139,6 +139,7 @@ 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";
final protected List<Message> messageList = new ArrayList<>();
final private List<Uri> mPendingImageUris = new ArrayList<>();
@@ -146,6 +147,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
private final PendingItem<String> pendingConversationsUuid = new PendingItem<>();
private final PendingItem<Bundle> pendingExtras = new PendingItem<>();
+ private final PendingItem<Uri> pendingTakePhotoUri = new PendingItem<>();
protected MessageAdapter messageListAdapter;
private Conversation conversation;
public FragmentConversationBinding binding;
@@ -153,6 +155,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, dd. MMM yyyy", Locale.getDefault());
private Toast messageLoaderToast;
private ConversationActivity activity;
+
+ private boolean reInitRequiredOnStart = true;
+
protected OnClickListener clickToVerify = new OnClickListener() {
@Override
public void onClick(View v) {
@@ -750,6 +755,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private void sendImage(Conversation conversation, Uri uri) {
final Toast prepareFileToast = Toast.makeText(getActivity(), getText(R.string.preparing_image), Toast.LENGTH_LONG);
prepareFileToast.show();
+ activity.delegateUriPermissionsToService(uri);
activity.xmppConnectionService.attachImageToConversation(conversation, uri,
new UiCallback<Message>() {
@@ -767,14 +773,14 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
@Override
public void error(final int error, Message message) {
hidePrepareFileToast(prepareFileToast);
- getActivity().runOnUiThread(() -> activity.replaceToast(getString(error)));
+ activity.runOnUiThread(() -> activity.replaceToast(getString(error)));
}
});
}
private void hidePrepareFileToast(final Toast prepareFileToast) {
if (prepareFileToast != null) {
- getActivity().runOnUiThread(prepareFileToast::cancel);
+ activity.runOnUiThread(prepareFileToast::cancel);
}
}
@@ -907,18 +913,28 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
break;
case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
List<Uri> imageUris = AttachmentTool.extractUriFromIntent(data);
- for (Iterator<Uri> i = imageUris.iterator(); i.hasNext(); i.remove()) {
- Log.d(Config.LOGTAG, "ConversationsActivity.onActivityResult() - attaching image to conversations. CHOOSE_IMAGE");
- attachImageToConversation(conversation, i.next(), false);
+ int ImageUrisCount = imageUris.size();
+ if (activity.xmppConnectionServiceBound) {
+ if (ImageUrisCount == 1) {
+ Uri uri = imageUris.get(0);
+ Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching image to conversations. CHOOSE_IMAGE");
+ attachImageToConversation(conversation, uri, false);
+ } else {
+ for (Iterator<Uri> i = imageUris.iterator(); i.hasNext(); i.remove()) {
+ Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching images to conversations. CHOOSE_IMAGES");
+ attachImagesToConversation(conversation, i.next());
+ }
+ }
}
break;
case ATTACHMENT_CHOICE_TAKE_FROM_CAMERA:
- //TODO save photo uri
- final List<Uri> PhotoUris = AttachmentTool.extractUriFromIntent(data);
- for (Iterator<Uri> i = PhotoUris.iterator(); i.hasNext(); i.remove()) {
- Log.d(Config.LOGTAG, "ConversationsActivity.onActivityResult() - attaching image to conversations. TAKE_FROM_CAMERA");
- attachPhotoToConversation(conversation, i.next());
+ Uri takePhotoUri = pendingTakePhotoUri.pop();
+ if (takePhotoUri != null) {
+ attachImageToConversation(conversation, takePhotoUri, false);
+ } else {
+ Log.d(Config.LOGTAG, "lost take photo uri. unable to to attach");
}
+ break;
case ATTACHMENT_CHOICE_CHOOSE_FILE:
case ATTACHMENT_CHOICE_RECORD_VOICE:
final List<Uri> fileUris = AttachmentTool.extractUriFromIntent(data);
@@ -1525,6 +1541,14 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
boolean chooser = false;
String fallbackPackageId = null;
switch (attachmentChoice) {
+ case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
+ intent.setAction(Intent.ACTION_GET_CONTENT);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
+ }
+ intent.setType("image/*");
+ chooser = true;
+ break;
case ATTACHMENT_CHOICE_CHOOSE_VIDEO:
chooser = true;
intent.setType("video/*");
@@ -1536,10 +1560,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
builder.setTitle(getString(R.string.attach_take_from_camera));
builder.setNegativeButton(getString(R.string.action_take_photo),
(dialog, which) -> {
- Uri uri = activity.xmppConnectionService.getFileBackend().getTakePhotoUri();
+ final Uri uri = activity.xmppConnectionService.getFileBackend().getTakePhotoUri();
+ pendingTakePhotoUri.push(uri);
+ intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
- intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, attachmentChoice);
});
builder.setPositiveButton(getString(R.string.action_take_video),
@@ -1794,6 +1820,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
super.onSaveInstanceState(outState);
if (conversation != null) {
outState.putString(STATE_CONVERSATION_UUID, conversation.getUuid());
+ Uri uri = pendingTakePhotoUri.pop();
+ if (uri != null) {
+ outState.putString(STATE_PHOTO_URI, uri.toString());
+ }
}
}
@@ -1806,16 +1836,24 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
String uuid = savedInstanceState.getString(STATE_CONVERSATION_UUID);
if (uuid != null) {
this.pendingConversationsUuid.push(uuid);
+ String takePhotoUri = savedInstanceState.getString(STATE_PHOTO_URI);
+ if (takePhotoUri != null) {
+ pendingTakePhotoUri.push(Uri.parse(takePhotoUri));
+ }
}
}
@Override
public void onStart() {
super.onStart();
- reInit(conversation);
- final Bundle extras = pendingExtras.pop();
- if (extras != null) {
- processExtras(extras);
+ if (this.reInitRequiredOnStart) {
+ reInit(conversation);
+ final Bundle extras = pendingExtras.pop();
+ if (extras != null) {
+ processExtras(extras);
+ }
+ } else {
+ Log.d(Config.LOGTAG, "skipped reinit on start");
}
}
@@ -1860,29 +1898,29 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public void reInit(Conversation conversation, Bundle extras) {
this.saveMessageDraftStopAudioPlayer();
- this.reInit(conversation);
- if (extras != null) {
- //if binding or activity does not exist we will retry in onStart()
- if (this.activity != null && this.binding != null) {
+ if (this.reInit(conversation)) {
+ if (extras != null) {
processExtras(extras);
+ this.reInitRequiredOnStart = false;
} else {
+ this.reInitRequiredOnStart = true;
pendingExtras.push(extras);
}
}
}
- private void reInit(Conversation conversation) {
- reInit(conversation, false);
+ private boolean reInit(Conversation conversation) {
+ return reInit(conversation, false);
}
- private void reInit(Conversation conversation, boolean restore) {
+ private boolean reInit(Conversation conversation, boolean restore) {
if (conversation == null) {
- return;
+ return false;
}
this.conversation = conversation;
//once we set the conversation all is good and it will automatically do the right thing in onStart()
if (this.activity == null || this.binding == null) {
- return;
+ return false;
}
Log.d(Config.LOGTAG, "reInit(restore=" + Boolean.toString(restore) + ")");
setupIme();
@@ -1925,6 +1963,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
activity.onConversationRead(this.conversation);
//TODO if we only do this when this fragment is running on main it won't *bing* in tablet layout which might be unnecessary since we can *see* it
activity.xmppConnectionService.getNotificationService().setOpenConversation(this.conversation);
+ return true;
}
private void processExtras(Bundle extras) {