aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-03-30 22:23:15 +0200
committerChristian Schneppe <christian@pix-art.de>2018-03-30 22:23:15 +0200
commit4ebea503479848c318f606e7a398b33f41ef17e8 (patch)
tree6f3dddcec21a5fe849c1a6a556b3f1b7fe81a89a /src/main/java/de/pixart/messenger/ui/ConversationFragment.java
parenta9546bab57ee46a7dacc4f1646514728ce5f6234 (diff)
fix permission handling
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui/ConversationFragment.java')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java82
1 files changed, 47 insertions, 35 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 93b8146dc..1f6540a79 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -1,5 +1,6 @@
package de.pixart.messenger.ui;
+import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
@@ -288,7 +289,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return false;
}
}
- if (activity.hasStoragePermission(REQUEST_ADD_EDITOR_CONTENT)) {
+ if (hasStoragePermission(REQUEST_ADD_EDITOR_CONTENT)) {
attachImageToConversation(inputContentInfo.getContentUri());
} else {
mPendingEditorContent = inputContentInfo.getContentUri();
@@ -1226,7 +1227,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
copyUrl(selectedMessage);
return true;
case R.id.download_file:
- downloadFile(selectedMessage);
+ startDownloadable(selectedMessage);
return true;
case R.id.cancel_transmission:
cancelTransmission(selectedMessage);
@@ -1367,7 +1368,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public void attachFile(final int attachmentChoice) {
if (attachmentChoice != ATTACHMENT_CHOICE_LOCATION) {
- if (!Config.ONLY_INTERNAL_STORAGE && !activity.hasStoragePermission(attachmentChoice)) {
+ if (!Config.ONLY_INTERNAL_STORAGE && !hasStoragePermission(attachmentChoice)) {
return;
}
}
@@ -1464,7 +1465,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
public void startDownloadable(Message message) {
- if (!Config.ONLY_INTERNAL_STORAGE && !activity.hasStoragePermission(REQUEST_START_DOWNLOAD)) {
+ if (!Config.ONLY_INTERNAL_STORAGE && !hasStoragePermission(REQUEST_START_DOWNLOAD)) {
this.mPendingDownloadableMessage = message;
return;
}
@@ -1503,6 +1504,19 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
builder.create().show();
}
+ private boolean hasStoragePermission(int requestCode) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode);
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+ return true;
+ }
+ }
+
protected void selectPresenceToAttachFile(final int attachmentChoice) {
final int encryption = conversation.getNextEncryption();
final Account account = conversation.getAccount();
@@ -1698,19 +1712,15 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
}
- private void downloadFile(Message message) {
- activity.xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message, true);
- }
-
public static void downloadFile(Activity activity, Message message) {
Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment);
if (fragment != null && fragment instanceof ConversationFragment) {
- ((ConversationFragment) fragment).downloadFile(message);
+ ((ConversationFragment) fragment).startDownloadable(message);
return;
}
fragment = activity.getFragmentManager().findFragmentById(R.id.secondary_fragment);
if (fragment != null && fragment instanceof ConversationFragment) {
- ((ConversationFragment) fragment).downloadFile(message);
+ ((ConversationFragment) fragment).startDownloadable(message);
}
}
@@ -1834,10 +1844,26 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
}
+ private void saveMessageDraftStopAudioPlayer() {
+ final Conversation previousConversation = this.conversation;
+ if (this.activity == null || this.binding == null || previousConversation == null) {
+ return;
+ }
+ Log.d(Config.LOGTAG, "ConversationFragment.saveMessageDraftStopAudioPlayer()");
+ final String msg = this.binding.textinput.getText().toString();
+ if (previousConversation.setNextMessage(msg)) {
+ activity.xmppConnectionService.updateConversation(previousConversation);
+ }
+ updateChatState(this.conversation, msg);
+ messageListAdapter.stopAudioPlayer();
+ }
+
public void reInit(Conversation conversation, Bundle extras) {
+ this.saveMessageDraftStopAudioPlayer();
this.reInit(conversation);
if (extras != null) {
- if (activity != null) {
+ //if binding or activity does not exist we will retry in onStart()
+ if (this.activity != null && this.binding != null) {
processExtras(extras);
} else {
pendingExtras.push(extras);
@@ -1853,31 +1879,18 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (conversation == null) {
return;
}
- if (this.activity == null) {
- this.conversation = conversation;
+ 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;
}
Log.d(Config.LOGTAG, "reInit(restore=" + Boolean.toString(restore) + ")");
setupIme();
- if (this.conversation != null) {
- final String msg = this.binding.textinput.getText().toString();
- if (this.conversation.setNextMessage(msg)) {
- activity.xmppConnectionService.updateConversation(conversation);
- }
- if (this.conversation != conversation && !restore) {
- updateChatState(this.conversation, msg);
- messageListAdapter.stopAudioPlayer();
- }
- if (!restore) {
- this.conversation.trim();
- }
+ if (!restore) {
+ this.conversation.trim();
}
- if (activity != null) {
- this.binding.textSendButton.setContentDescription(activity.getString(R.string.send_message_to_x, conversation.getName()));
- }
-
- this.conversation = conversation;
+ this.binding.textSendButton.setContentDescription(activity.getString(R.string.send_message_to_x, conversation.getName()));
this.binding.textinput.setKeyboardListener(null);
this.binding.textinput.setText("");
this.binding.textinput.append(this.conversation.getNextMessage());
@@ -1908,11 +1921,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
this.binding.messagesView.setSelection(pos);
isAtBottom = pos == bottom;
}
- if (activity != null) {
- 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);
- }
+
+ 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);
}
private void processExtras(Bundle extras) {