Search in sources :

Example 1 with SaveAttachmentTask

use of org.thoughtcrime.securesms.util.SaveAttachmentTask in project Signal-Android by WhisperSystems.

the class MediaOverviewActivity method saveToDisk.

private void saveToDisk() {
    final Context c = this;
    SaveAttachmentTask.showWarningDialog(this, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            new ProgressDialogAsyncTask<Void, Void, List<SaveAttachmentTask.Attachment>>(c, R.string.ConversationFragment_collecting_attahments, R.string.please_wait) {

                @Override
                protected List<SaveAttachmentTask.Attachment> doInBackground(Void... params) {
                    Cursor cursor = DatabaseFactory.getMediaDatabase(c).getMediaForThread(threadId);
                    List<SaveAttachmentTask.Attachment> attachments = new ArrayList<>(cursor.getCount());
                    while (cursor != null && cursor.moveToNext()) {
                        MediaRecord record = MediaRecord.from(cursor);
                        attachments.add(new SaveAttachmentTask.Attachment(record.getAttachment().getDataUri(), record.getContentType(), record.getDate()));
                    }
                    return attachments;
                }

                @Override
                protected void onPostExecute(List<SaveAttachmentTask.Attachment> attachments) {
                    super.onPostExecute(attachments);
                    SaveAttachmentTask saveTask = new SaveAttachmentTask(c, masterSecret, attachments.size());
                    saveTask.execute(attachments.toArray(new SaveAttachmentTask.Attachment[attachments.size()]));
                }
            }.execute();
        }
    }, gridView.getAdapter().getItemCount());
}
Also used : Context(android.content.Context) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) SaveAttachmentTask(org.thoughtcrime.securesms.util.SaveAttachmentTask) MediaRecord(org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord) ProgressDialogAsyncTask(org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with SaveAttachmentTask

use of org.thoughtcrime.securesms.util.SaveAttachmentTask in project Signal-Android by WhisperSystems.

the class ConversationFragment method performSave.

private void performSave(final MediaMmsMessageRecord message) {
    List<SaveAttachmentTask.Attachment> attachments = Stream.of(message.getSlideDeck().getSlides()).filter(s -> s.getUri() != null && (s.hasImage() || s.hasVideo() || s.hasAudio() || s.hasDocument())).map(s -> new SaveAttachmentTask.Attachment(s.getUri(), s.getContentType(), message.getDateReceived(), s.getFileName().orNull())).toList();
    if (!Util.isEmpty(attachments)) {
        SaveAttachmentTask saveTask = new SaveAttachmentTask(getActivity());
        saveTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, attachments.toArray(new SaveAttachmentTask.Attachment[0]));
        return;
    }
    Log.w(TAG, "No slide with attachable media found, failing nicely.");
    Toast.makeText(getActivity(), getResources().getQuantityString(R.plurals.ConversationFragment_error_while_saving_attachments_to_sd_card, 1), Toast.LENGTH_LONG).show();
}
Also used : TypingStatusRepository(org.thoughtcrime.securesms.components.TypingStatusRepository) Bundle(android.os.Bundle) GroupMigrationMembershipChange(org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange) RecaptchaProofBottomSheetFragment(org.thoughtcrime.securesms.ratelimit.RecaptchaProofBottomSheetFragment) GiphyMp4ItemDecoration(org.thoughtcrime.securesms.giph.mp4.GiphyMp4ItemDecoration) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) RecyclerViewColorizer(org.thoughtcrime.securesms.conversation.colors.RecyclerViewColorizer) ProgressDialogAsyncTask(org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask) Manifest(android.Manifest) LayoutTransition(android.animation.LayoutTransition) ActivityOptionsCompat(androidx.core.app.ActivityOptionsCompat) MultiselectForwardFragmentArgs(org.thoughtcrime.securesms.conversation.mutiselect.forward.MultiselectForwardFragmentArgs) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) SnapToTopDataObserver(org.thoughtcrime.securesms.util.SnapToTopDataObserver) HtmlUtil(org.thoughtcrime.securesms.util.HtmlUtil) PartAuthority(org.thoughtcrime.securesms.mms.PartAuthority) MultiDeviceViewOnceOpenJob(org.thoughtcrime.securesms.jobs.MultiDeviceViewOnceOpenJob) OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) ViewCompat(androidx.core.view.ViewCompat) StickyHeaderViewHolder(org.thoughtcrime.securesms.conversation.ConversationAdapter.StickyHeaderViewHolder) MultiselectForwardFragment(org.thoughtcrime.securesms.conversation.mutiselect.forward.MultiselectForwardFragment) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) DimensionUnit(org.signal.core.util.DimensionUnit) SmoothScrollingLinearLayoutManager(org.thoughtcrime.securesms.components.recyclerview.SmoothScrollingLinearLayoutManager) MessageRecordUtil(org.thoughtcrime.securesms.util.MessageRecordUtil) Unit(kotlin.Unit) Nullable(androidx.annotation.Nullable) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StickyHeaderDecoration(org.thoughtcrime.securesms.util.StickyHeaderDecoration) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) ViewKt(androidx.core.view.ViewKt) Util(org.thoughtcrime.securesms.util.Util) ArrayList(java.util.ArrayList) MessageRequestState(org.thoughtcrime.securesms.messagerequests.MessageRequestState) SpannableStringBuilder(android.text.SpannableStringBuilder) SignalProxyUtil(org.thoughtcrime.securesms.util.SignalProxyUtil) Toast(android.widget.Toast) Menu(android.view.Menu) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) GiphyMp4ProjectionRecycler(org.thoughtcrime.securesms.giph.mp4.GiphyMp4ProjectionRecycler) LiveData(androidx.lifecycle.LiveData) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob) Collectors(com.annimon.stream.Collectors) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Contact(org.thoughtcrime.securesms.contactshare.Contact) RecipientBottomSheetDialogFragment(org.thoughtcrime.securesms.recipients.ui.bottomsheet.RecipientBottomSheetDialogFragment) Permissions(org.thoughtcrime.securesms.permissions.Permissions) TextUtils(android.text.TextUtils) SafetyNumberChangeDialog(org.thoughtcrime.securesms.conversation.ui.error.SafetyNumberChangeDialog) IOException(java.io.IOException) Optional(org.whispersystems.libsignal.util.guava.Optional) ExecutionException(java.util.concurrent.ExecutionException) ItemClickListener(org.thoughtcrime.securesms.conversation.ConversationAdapter.ItemClickListener) StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator) Configuration(android.content.res.Configuration) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) RecipientExporter(org.thoughtcrime.securesms.recipients.RecipientExporter) LoggingFragment(org.thoughtcrime.securesms.LoggingFragment) PhoneNumberFormatter(org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter) ValueAnimator(android.animation.ValueAnimator) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Rect(android.graphics.Rect) ConversationTypingView(org.thoughtcrime.securesms.components.ConversationTypingView) SignalBottomActionBar(org.thoughtcrime.securesms.components.menu.SignalBottomActionBar) MessageSender(org.thoughtcrime.securesms.sms.MessageSender) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) GroupLinkInviteFriendsBottomSheetDialogFragment(org.thoughtcrime.securesms.groups.ui.invitesandrequests.invite.GroupLinkInviteFriendsBottomSheetDialogFragment) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Animator(android.animation.Animator) R(org.thoughtcrime.securesms.R) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) GiphyMp4ProjectionPlayerHolder(org.thoughtcrime.securesms.giph.mp4.GiphyMp4ProjectionPlayerHolder) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Locale(java.util.Locale) View(android.view.View) ViewOnceUtil(org.thoughtcrime.securesms.revealable.ViewOnceUtil) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Animation(android.view.animation.Animation) RecyclerView(androidx.recyclerview.widget.RecyclerView) VoiceNotePlaybackState(org.thoughtcrime.securesms.components.voice.VoiceNotePlaybackState) NavHostFragment(androidx.navigation.fragment.NavHostFragment) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) ViewSwitcher(android.widget.ViewSwitcher) AppSettingsActivity(org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity) AsyncTask(android.os.AsyncTask) ContactUtil(org.thoughtcrime.securesms.contactshare.ContactUtil) MessageRequestViewModel(org.thoughtcrime.securesms.messagerequests.MessageRequestViewModel) HtmlCompat(androidx.core.text.HtmlCompat) LongMessageFragment(org.thoughtcrime.securesms.longmessage.LongMessageFragment) NotificationProfile(org.thoughtcrime.securesms.notifications.profiles.NotificationProfile) ViewGroup(android.view.ViewGroup) VoiceNoteMediaControllerOwner(org.thoughtcrime.securesms.components.voice.VoiceNoteMediaControllerOwner) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) List(java.util.List) TextView(android.widget.TextView) Slide(org.thoughtcrime.securesms.mms.Slide) ConversationItemAnimator(org.thoughtcrime.securesms.conversation.mutiselect.ConversationItemAnimator) GroupId(org.thoughtcrime.securesms.groups.GroupId) Toolbar(androidx.appcompat.widget.Toolbar) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) GiphyMp4PlaybackPolicy(org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackPolicy) OnScrollListener(androidx.recyclerview.widget.RecyclerView.OnScrollListener) SaveAttachmentTask(org.thoughtcrime.securesms.util.SaveAttachmentTask) Snackbar(com.google.android.material.snackbar.Snackbar) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) SharedContactDetailsActivity(org.thoughtcrime.securesms.contactshare.SharedContactDetailsActivity) TopToastPopup(org.thoughtcrime.securesms.util.TopToastPopup) MultiselectPart(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectPart) ReactionsBottomSheetDialogFragment(org.thoughtcrime.securesms.reactions.ReactionsBottomSheetDialogFragment) SignalLocalMetrics(org.thoughtcrime.securesms.util.SignalLocalMetrics) Intent(android.content.Intent) MenuItem(android.view.MenuItem) AnimationUtils(android.view.animation.AnimationUtils) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) StickerPackPreviewActivity(org.thoughtcrime.securesms.stickers.StickerPackPreviewActivity) ActionItem(org.thoughtcrime.securesms.components.menu.ActionItem) GroupsV1MigrationInfoBottomSheetDialogFragment(org.thoughtcrime.securesms.groups.ui.migration.GroupsV1MigrationInfoBottomSheetDialogFragment) Colorizer(org.thoughtcrime.securesms.conversation.colors.Colorizer) ConversationScrollToView(org.thoughtcrime.securesms.components.ConversationScrollToView) ViewOnceMessageActivity(org.thoughtcrime.securesms.revealable.ViewOnceMessageActivity) GiphyMp4PlaybackController(org.thoughtcrime.securesms.giph.mp4.GiphyMp4PlaybackController) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) VerifyIdentityActivity(org.thoughtcrime.securesms.verify.VerifyIdentityActivity) MultiselectItemDecoration(org.thoughtcrime.securesms.conversation.mutiselect.MultiselectItemDecoration) GroupDescriptionDialog(org.thoughtcrime.securesms.groups.ui.managegroup.dialogs.GroupDescriptionDialog) GroupDescriptionUtil(org.thoughtcrime.securesms.groups.v2.GroupDescriptionUtil) LayoutInflater(android.view.LayoutInflater) ActivityCompat(androidx.core.app.ActivityCompat) MessageDetailsFragment(org.thoughtcrime.securesms.messagedetails.MessageDetailsFragment) RemoteDeleteUtil(org.thoughtcrime.securesms.util.RemoteDeleteUtil) BlobProvider(org.thoughtcrime.securesms.providers.BlobProvider) CommunicationActions(org.thoughtcrime.securesms.util.CommunicationActions) CachedInflater(org.thoughtcrime.securesms.util.CachedInflater) InMemoryMessageRecord(org.thoughtcrime.securesms.database.model.InMemoryMessageRecord) ActionMode(androidx.appcompat.view.ActionMode) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Color(android.graphics.Color) Observer(androidx.lifecycle.Observer) StorageUtil(org.thoughtcrime.securesms.util.StorageUtil) Bitmap(android.graphics.Bitmap) EnableCallNotificationSettingsDialog(org.thoughtcrime.securesms.conversation.ui.error.EnableCallNotificationSettingsDialog) ViewTreeObserver(android.view.ViewTreeObserver) Collections(java.util.Collections) InputStream(java.io.InputStream) SaveAttachmentTask(org.thoughtcrime.securesms.util.SaveAttachmentTask)

Example 3 with SaveAttachmentTask

use of org.thoughtcrime.securesms.util.SaveAttachmentTask in project Signal-Android by WhisperSystems.

the class MediaPreviewActivity method performSavetoDisk.

private void performSavetoDisk(@NonNull MediaItem mediaItem) {
    SaveAttachmentTask saveTask = new SaveAttachmentTask(MediaPreviewActivity.this);
    long saveDate = (mediaItem.date > 0) ? mediaItem.date : System.currentTimeMillis();
    saveTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Attachment(mediaItem.uri, mediaItem.type, saveDate, null));
}
Also used : SaveAttachmentTask(org.thoughtcrime.securesms.util.SaveAttachmentTask) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) Attachment(org.thoughtcrime.securesms.util.SaveAttachmentTask.Attachment)

Example 4 with SaveAttachmentTask

use of org.thoughtcrime.securesms.util.SaveAttachmentTask in project Signal-Android by WhisperSystems.

the class ImageEditorFragment method performSaveToDisk.

private void performSaveToDisk() {
    SimpleTask.run(this::renderToSingleUseBlob, uri -> {
        SaveAttachmentTask saveTask = new SaveAttachmentTask(requireContext());
        SaveAttachmentTask.Attachment attachment = new SaveAttachmentTask.Attachment(uri, MediaUtil.IMAGE_JPEG, System.currentTimeMillis(), null);
        saveTask.executeOnExecutor(SignalExecutors.BOUNDED, attachment);
    });
}
Also used : SaveAttachmentTask(org.thoughtcrime.securesms.util.SaveAttachmentTask)

Aggregations

SaveAttachmentTask (org.thoughtcrime.securesms.util.SaveAttachmentTask)4 Context (android.content.Context)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ProgressDialogAsyncTask (org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask)2 Manifest (android.Manifest)1 Animator (android.animation.Animator)1 LayoutTransition (android.animation.LayoutTransition)1 ValueAnimator (android.animation.ValueAnimator)1 SuppressLint (android.annotation.SuppressLint)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Configuration (android.content.res.Configuration)1 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 Color (android.graphics.Color)1 Rect (android.graphics.Rect)1 Uri (android.net.Uri)1 AsyncTask (android.os.AsyncTask)1 Bundle (android.os.Bundle)1