diff options
Diffstat (limited to 'src/main/java/de/pixart')
3 files changed, 48 insertions, 4 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index 1cd1b4e12..53f3b0a14 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -39,6 +39,7 @@ import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.databinding.DataBindingUtil; import android.graphics.Typeface; import android.net.Uri; @@ -97,6 +98,7 @@ public class ConversationActivity extends XmppActivity implements OnConversation public static final String EXTRA_NICK = "nick"; public static final String EXTRA_IS_PRIVATE_MESSAGE = "pm"; public static final String ACTION_DESTROY_MUC = "de.pixart.messenger.DESTROY_MUC"; + public static final int REQUEST_OPEN_MESSAGE = 0x9876; private boolean showLastSeen = false; @@ -341,6 +343,16 @@ public class ConversationActivity extends XmppActivity implements OnConversation @Override public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults); + if (grantResults.length > 0) { + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + switch (requestCode) { + case REQUEST_OPEN_MESSAGE: + refreshUiReal(); + ConversationFragment.openPendingMessage(this); + break; + } + } + } } @Override diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 568b0db11..ef2910ab3 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -464,16 +464,41 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke private int lastCompletionCursor; private boolean firstWord = false; private Message mPendingDownloadableMessage; + private final PendingItem<Message> pendingMessage = new PendingItem<>(); - public static void downloadFile(Activity activity, Message message) { + private static ConversationFragment findConversationFragment(Activity activity) { Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment); if (fragment != null && fragment instanceof ConversationFragment) { - ((ConversationFragment) fragment).startDownloadable(message); - return; + return (ConversationFragment) fragment; } fragment = activity.getFragmentManager().findFragmentById(R.id.secondary_fragment); if (fragment != null && fragment instanceof ConversationFragment) { - ((ConversationFragment) fragment).startDownloadable(message); + return (ConversationFragment) fragment; + } + return null; + } + + public static void downloadFile(Activity activity, Message message) { + ConversationFragment fragment = findConversationFragment(activity); + if (fragment != null) { + fragment.startDownloadable(message); + } + } + + public static void registerPendingMessage(Activity activity, Message message) { + ConversationFragment fragment = findConversationFragment(activity); + if (fragment != null) { + fragment.pendingMessage.push(message); + } + } + + public static void openPendingMessage(Activity activity) { + ConversationFragment fragment = findConversationFragment(activity); + if (fragment != null) { + Message message = fragment.pendingMessage.pop(); + if (message != null) { + fragment.messageListAdapter.openDownloadable(message); + } } } diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index 436f0f219..37dd32b4c 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -1,5 +1,6 @@ package de.pixart.messenger.ui.adapter; +import android.Manifest; import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.SharedPreferences; @@ -15,6 +16,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.preference.PreferenceManager; import android.support.annotation.ColorInt; +import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.text.Spannable; import android.text.SpannableString; @@ -1057,6 +1059,11 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } public void openDownloadable(Message message) { + if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + ConversationFragment.registerPendingMessage(activity, message); + ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, ConversationActivity.REQUEST_OPEN_MESSAGE); + return; + } DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); if (!file.exists()) { Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show(); |