Search in sources :

Example 11 with Media

use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by signalapp.

the class MediaPreviewViewModel method setActiveAlbumRailItem.

public void setActiveAlbumRailItem(@NonNull Context context, int activePosition) {
    if (cursor == null) {
        previewData.postValue(new PreviewData(Collections.emptyList(), null, 0));
        return;
    }
    activePosition = getCursorPosition(activePosition);
    cursor.moveToPosition(activePosition);
    MediaRecord activeRecord = MediaRecord.from(context, cursor);
    LinkedList<Media> rail = new LinkedList<>();
    Media activeMedia = toMedia(activeRecord);
    if (activeMedia != null)
        rail.add(activeMedia);
    while (cursor.moveToPrevious()) {
        MediaRecord record = MediaRecord.from(context, cursor);
        if (record.getAttachment().getMmsId() == activeRecord.getAttachment().getMmsId()) {
            Media media = toMedia(record);
            if (media != null)
                rail.addFirst(media);
        } else {
            break;
        }
    }
    cursor.moveToPosition(activePosition);
    while (cursor.moveToNext()) {
        MediaRecord record = MediaRecord.from(context, cursor);
        if (record.getAttachment().getMmsId() == activeRecord.getAttachment().getMmsId()) {
            Media media = toMedia(record);
            if (media != null)
                rail.addLast(media);
        } else {
            break;
        }
    }
    if (!leftIsRecent) {
        Collections.reverse(rail);
    }
    previewData.postValue(new PreviewData(rail.size() > 1 ? rail : Collections.emptyList(), activeRecord.getAttachment().getCaption(), rail.indexOf(activeMedia)));
}
Also used : MediaRecord(org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord) Media(org.thoughtcrime.securesms.mediasend.Media) LinkedList(java.util.LinkedList)

Example 12 with Media

use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by WhisperSystems.

the class MediaPreviewViewModel method setActiveAlbumRailItem.

public void setActiveAlbumRailItem(@NonNull Context context, int activePosition) {
    if (cursor == null) {
        previewData.postValue(new PreviewData(Collections.emptyList(), null, 0));
        return;
    }
    activePosition = getCursorPosition(activePosition);
    cursor.moveToPosition(activePosition);
    MediaRecord activeRecord = MediaRecord.from(context, cursor);
    LinkedList<Media> rail = new LinkedList<>();
    Media activeMedia = toMedia(activeRecord);
    if (activeMedia != null)
        rail.add(activeMedia);
    while (cursor.moveToPrevious()) {
        MediaRecord record = MediaRecord.from(context, cursor);
        if (record.getAttachment().getMmsId() == activeRecord.getAttachment().getMmsId()) {
            Media media = toMedia(record);
            if (media != null)
                rail.addFirst(media);
        } else {
            break;
        }
    }
    cursor.moveToPosition(activePosition);
    while (cursor.moveToNext()) {
        MediaRecord record = MediaRecord.from(context, cursor);
        if (record.getAttachment().getMmsId() == activeRecord.getAttachment().getMmsId()) {
            Media media = toMedia(record);
            if (media != null)
                rail.addLast(media);
        } else {
            break;
        }
    }
    if (!leftIsRecent) {
        Collections.reverse(rail);
    }
    previewData.postValue(new PreviewData(rail.size() > 1 ? rail : Collections.emptyList(), activeRecord.getAttachment().getCaption(), rail.indexOf(activeMedia)));
}
Also used : MediaRecord(org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord) Media(org.thoughtcrime.securesms.mediasend.Media) LinkedList(java.util.LinkedList)

Example 13 with Media

use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by WhisperSystems.

the class EditProfileFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    GroupId groupId = GroupId.parseNullableOrThrow(requireArguments().getString(GROUP_ID, null));
    initializeViewModel(requireArguments().getBoolean(EXCLUDE_SYSTEM, false), groupId, savedInstanceState != null);
    initializeResources(view, groupId);
    initializeProfileAvatar();
    initializeProfileName();
    getParentFragmentManager().setFragmentResultListener(AvatarPickerFragment.REQUEST_KEY_SELECT_AVATAR, getViewLifecycleOwner(), (key, bundle) -> {
        if (bundle.getBoolean(AvatarPickerFragment.SELECT_AVATAR_CLEAR)) {
            viewModel.setAvatarMedia(null);
            viewModel.setAvatar(null);
            avatar.setImageDrawable(null);
        } else {
            Media media = bundle.getParcelable(AvatarPickerFragment.SELECT_AVATAR_MEDIA);
            handleMediaFromResult(media);
        }
    });
}
Also used : Media(org.thoughtcrime.securesms.mediasend.Media) ParcelableGroupId(org.thoughtcrime.securesms.groups.ParcelableGroupId) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 14 with Media

use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by WhisperSystems.

the class ManageProfileFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    this.toolbar = view.findViewById(R.id.toolbar);
    this.avatarView = view.findViewById(R.id.manage_profile_avatar);
    this.avatarPlaceholderView = view.findViewById(R.id.manage_profile_avatar_placeholder);
    this.profileNameView = view.findViewById(R.id.manage_profile_name);
    this.profileNameContainer = view.findViewById(R.id.manage_profile_name_container);
    this.usernameView = view.findViewById(R.id.manage_profile_username);
    this.usernameContainer = view.findViewById(R.id.manage_profile_username_container);
    this.aboutView = view.findViewById(R.id.manage_profile_about);
    this.aboutContainer = view.findViewById(R.id.manage_profile_about_container);
    this.aboutEmojiView = view.findViewById(R.id.manage_profile_about_icon);
    this.avatarInitials = view.findViewById(R.id.manage_profile_avatar_initials);
    this.avatarBackground = view.findViewById(R.id.manage_profile_avatar_background);
    this.badgesContainer = view.findViewById(R.id.manage_profile_badges_container);
    this.badgeView = view.findViewById(R.id.manage_profile_badge);
    initializeViewModel();
    this.toolbar.setNavigationOnClickListener(v -> requireActivity().finish());
    View editAvatar = view.findViewById(R.id.manage_profile_edit_photo);
    editAvatar.setOnClickListener(v -> onEditAvatarClicked());
    this.profileNameContainer.setOnClickListener(v -> {
        SafeNavigation.safeNavigate(Navigation.findNavController(v), ManageProfileFragmentDirections.actionManageProfileName());
    });
    this.usernameContainer.setOnClickListener(v -> {
        SafeNavigation.safeNavigate(Navigation.findNavController(v), ManageProfileFragmentDirections.actionManageUsername());
    });
    this.aboutContainer.setOnClickListener(v -> {
        SafeNavigation.safeNavigate(Navigation.findNavController(v), ManageProfileFragmentDirections.actionManageAbout());
    });
    getParentFragmentManager().setFragmentResultListener(AvatarPickerFragment.REQUEST_KEY_SELECT_AVATAR, getViewLifecycleOwner(), (key, bundle) -> {
        if (bundle.getBoolean(AvatarPickerFragment.SELECT_AVATAR_CLEAR)) {
            viewModel.onAvatarSelected(requireContext(), null);
        } else {
            Media result = bundle.getParcelable(AvatarPickerFragment.SELECT_AVATAR_MEDIA);
            viewModel.onAvatarSelected(requireContext(), result);
        }
    });
    avatarInitials.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
        if (avatarInitials.length() > 0) {
            updateInitials(avatarInitials.getText().toString());
        }
    });
    if (FeatureFlags.donorBadges()) {
        badgesContainer.setOnClickListener(v -> {
            if (Recipient.self().getBadges().isEmpty()) {
                BecomeASustainerFragment.show(getParentFragmentManager());
            } else {
                SafeNavigation.safeNavigate(Navigation.findNavController(v), ManageProfileFragmentDirections.actionManageProfileFragmentToBadgeManageFragment());
            }
        });
    } else {
        badgesContainer.setVisibility(View.GONE);
    }
}
Also used : Media(org.thoughtcrime.securesms.mediasend.Media) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView)

Example 15 with Media

use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by WhisperSystems.

the class AttachmentKeyboard method init.

private void init(@NonNull Context context) {
    inflate(context, R.layout.attachment_keyboard, this);
    this.container = findViewById(R.id.attachment_keyboard_container);
    this.mediaList = findViewById(R.id.attachment_keyboard_media_list);
    this.permissionText = findViewById(R.id.attachment_keyboard_permission_text);
    this.permissionButton = findViewById(R.id.attachment_keyboard_permission_button);
    RecyclerView buttonList = findViewById(R.id.attachment_keyboard_button_list);
    mediaAdapter = new AttachmentKeyboardMediaAdapter(GlideApp.with(this), media -> {
        if (callback != null) {
            callback.onAttachmentMediaClicked(media);
        }
    });
    buttonAdapter = new AttachmentKeyboardButtonAdapter(button -> {
        if (callback != null) {
            callback.onAttachmentSelectorClicked(button);
        }
    });
    mediaList.setAdapter(mediaAdapter);
    buttonList.setAdapter(buttonAdapter);
    mediaList.setLayoutManager(new GridLayoutManager(context, 1, GridLayoutManager.HORIZONTAL, false));
    buttonList.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
    buttonAdapter.setButtons(DEFAULT_BUTTONS);
}
Also used : Context(android.content.Context) Arrays(java.util.Arrays) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) FrameLayout(android.widget.FrameLayout) R(org.thoughtcrime.securesms.R) ViewGroup(android.view.ViewGroup) StorageUtil(org.thoughtcrime.securesms.util.StorageUtil) List(java.util.List) Nullable(androidx.annotation.Nullable) AttributeSet(android.util.AttributeSet) Media(org.thoughtcrime.securesms.mediasend.Media) View(android.view.View) InputAwareLayout(org.thoughtcrime.securesms.components.InputAwareLayout) Predicate(com.annimon.stream.function.Predicate) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

Media (org.thoughtcrime.securesms.mediasend.Media)22 Intent (android.content.Intent)8 PendingIntent (android.app.PendingIntent)6 Context (android.content.Context)6 Uri (android.net.Uri)6 View (android.view.View)6 NonNull (androidx.annotation.NonNull)6 Nullable (androidx.annotation.Nullable)6 Stream (com.annimon.stream.Stream)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 TransportOption (org.thoughtcrime.securesms.TransportOption)6 Manifest (android.Manifest)4 SuppressLint (android.annotation.SuppressLint)4 Bitmap (android.graphics.Bitmap)4 Drawable (android.graphics.drawable.Drawable)4 SpannableString (android.text.SpannableString)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 WorkerThread (androidx.annotation.WorkerThread)4