Search in sources :

Example 6 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project Signal-Android by WhisperSystems.

the class PaymentsTransferQrScanFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    overlay = view.findViewById(R.id.overlay);
    scannerView = view.findViewById(R.id.scanner);
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        overlay.setOrientation(LinearLayout.HORIZONTAL);
    } else {
        overlay.setOrientation(LinearLayout.VERTICAL);
    }
    viewModel = new ViewModelProvider(Navigation.findNavController(view).getViewModelStoreOwner(R.id.payments_transfer), new PaymentsTransferViewModel.Factory()).get(PaymentsTransferViewModel.class);
    Toolbar toolbar = view.findViewById(R.id.payments_transfer_scan_qr);
    toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(v).popBackStack());
}
Also used : ViewModelProvider(androidx.lifecycle.ViewModelProvider) Toolbar(androidx.appcompat.widget.Toolbar)

Example 7 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method initializeStickerObserver.

private void initializeStickerObserver() {
    StickerSearchRepository repository = new StickerSearchRepository(requireContext());
    stickerViewModel = new ViewModelProvider(this, new ConversationStickerViewModel.Factory(requireActivity().getApplication(), repository)).get(ConversationStickerViewModel.class);
    stickerViewModel.getStickerResults().observe(getViewLifecycleOwner(), stickers -> {
        if (stickers == null)
            return;
        inputPanel.setStickerSuggestions(stickers);
    });
    stickerViewModel.getStickersAvailability().observe(getViewLifecycleOwner(), stickersAvailable -> {
        if (stickersAvailable == null)
            return;
        boolean isSystemEmojiPreferred = SignalStore.settings().isPreferSystemEmoji();
        MediaKeyboardMode keyboardMode = TextSecurePreferences.getMediaKeyboardMode(requireContext());
        boolean stickerIntro = !TextSecurePreferences.hasSeenStickerIntroTooltip(requireContext());
        if (stickersAvailable) {
            inputPanel.showMediaKeyboardToggle(true);
            switch(keyboardMode) {
                case EMOJI:
                    inputPanel.setMediaKeyboardToggleMode(isSystemEmojiPreferred ? KeyboardPage.STICKER : KeyboardPage.EMOJI);
                    break;
                case STICKER:
                    inputPanel.setMediaKeyboardToggleMode(KeyboardPage.STICKER);
                    break;
                case GIF:
                    inputPanel.setMediaKeyboardToggleMode(KeyboardPage.GIF);
                    break;
            }
            if (stickerIntro)
                showStickerIntroductionTooltip();
        }
        if (emojiDrawerStub.resolved()) {
            initializeMediaKeyboardProviders();
        }
    });
}
Also used : StickerSearchRepository(org.thoughtcrime.securesms.stickers.StickerSearchRepository) MediaKeyboardMode(org.thoughtcrime.securesms.util.TextSecurePreferences.MediaKeyboardMode) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 8 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method initializeSearchObserver.

private void initializeSearchObserver() {
    ConversationSearchViewModel.Factory viewModelFactory = new ConversationSearchViewModel.Factory(getString(R.string.note_to_self));
    searchViewModel = new ViewModelProvider(this, viewModelFactory).get(ConversationSearchViewModel.class);
    searchViewModel.getSearchResults().observe(getViewLifecycleOwner(), result -> {
        if (result == null)
            return;
        if (!result.getResults().isEmpty()) {
            MessageResult messageResult = result.getResults().get(result.getPosition());
            fragment.jumpToMessage(messageResult.getMessageRecipient().getId(), messageResult.getReceivedTimestampMs(), searchViewModel::onMissingResult);
        }
        searchNav.setData(result.getPosition(), result.getResults().size());
    });
}
Also used : ConversationMessageFactory(org.thoughtcrime.securesms.conversation.ConversationMessage.ConversationMessageFactory) MessageResult(org.thoughtcrime.securesms.search.MessageResult) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 9 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project Signal-Android by WhisperSystems.

the class LongMessageFragment method initViewModel.

private void initViewModel(long messageId, boolean isMms) {
    viewModel = new ViewModelProvider(this, new LongMessageViewModel.Factory(requireActivity().getApplication(), new LongMessageRepository(), messageId, isMms)).get(LongMessageViewModel.class);
    viewModel.getMessage().observe(this, message -> {
        if (message == null)
            return;
        if (!message.isPresent()) {
            Toast.makeText(requireContext(), R.string.LongMessageActivity_unable_to_find_message, Toast.LENGTH_SHORT).show();
            dismissAllowingStateLoss();
            return;
        }
        if (message.get().getMessageRecord().isOutgoing()) {
            toolbar.setTitle(getString(R.string.LongMessageActivity_your_message));
        } else {
            Recipient recipient = message.get().getMessageRecord().getRecipient();
            String name = recipient.getDisplayName(requireContext());
            toolbar.setTitle(getString(R.string.LongMessageActivity_message_from_s, name));
        }
        ViewGroup bubble;
        if (message.get().getMessageRecord().isOutgoing()) {
            bubble = sentBubble.get();
            colorizerView.setVisibility(View.VISIBLE);
            colorizerView.setBackground(message.get().getMessageRecord().getRecipient().getChatColors().getChatBubbleMask());
            bubble.getBackground().setColorFilter(message.get().getMessageRecord().getRecipient().getChatColors().getChatBubbleColorFilter());
            bubble.addOnLayoutChangeListener(bubbleLayoutListener);
            bubbleLayoutListener.onLayoutChange(bubble, 0, 0, 0, 0, 0, 0, 0, 0);
        } else {
            bubble = receivedBubble.get();
            bubble.getBackground().setColorFilter(ContextCompat.getColor(requireContext(), R.color.signal_background_secondary), PorterDuff.Mode.MULTIPLY);
        }
        EmojiTextView text = bubble.findViewById(R.id.longmessage_text);
        ConversationItemFooter footer = bubble.findViewById(R.id.longmessage_footer);
        CharSequence trimmedBody = getTrimmedBody(message.get().getFullBody(requireContext()));
        SpannableString styledBody = linkifyMessageBody(new SpannableString(trimmedBody));
        bubble.setVisibility(View.VISIBLE);
        text.setText(styledBody);
        text.setMovementMethod(LinkMovementMethod.getInstance());
        text.setTextSize(TypedValue.COMPLEX_UNIT_SP, SignalStore.settings().getMessageFontSize());
        if (!message.get().getMessageRecord().isOutgoing()) {
            text.setMentionBackgroundTint(ContextCompat.getColor(requireContext(), ThemeUtil.isDarkTheme(requireActivity()) ? R.color.core_grey_60 : R.color.core_grey_20));
        } else {
            text.setMentionBackgroundTint(ContextCompat.getColor(requireContext(), R.color.transparent_black_40));
        }
        footer.setMessageRecord(message.get().getMessageRecord(), Locale.getDefault());
    });
}
Also used : SpannableString(android.text.SpannableString) ConversationItemFooter(org.thoughtcrime.securesms.components.ConversationItemFooter) ViewGroup(android.view.ViewGroup) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SpannableString(android.text.SpannableString) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 10 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project SeriesGuide by UweTrottmann.

the class MoviesNowFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_now, container, false);
    unbinder = ButterKnife.bind(this, view);
    swipeRefreshLayout.setSwipeableChildren(R.id.scrollViewNow, R.id.recyclerViewNow);
    swipeRefreshLayout.setOnRefreshListener(this::refreshStream);
    swipeRefreshLayout.setProgressViewOffset(false, getResources().getDimensionPixelSize(R.dimen.swipe_refresh_progress_bar_start_margin), getResources().getDimensionPixelSize(R.dimen.swipe_refresh_progress_bar_end_margin));
    emptyView.setText(R.string.now_movies_empty);
    showError(null);
    snackbarButton.setText(R.string.refresh);
    snackbarButton.setOnClickListener(v -> refreshStream());
    // recycler view layout manager
    final int spanCount = getResources().getInteger(R.integer.grid_column_count);
    final GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), spanCount);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            if (adapter == null) {
                return 1;
            }
            if (position >= adapter.getItemCount()) {
                return 1;
            }
            // make headers and more links span all columns
            int type = adapter.getItem(position).type;
            return (type == NowAdapter.ItemType.HEADER || type == NowAdapter.ItemType.MORE_LINK) ? spanCount : 1;
        }
    });
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    new ViewModelProvider(requireActivity()).get(MoviesActivityViewModel.class).getScrollTabToTopLiveData().observe(getViewLifecycleOwner(), event -> {
        if (event != null && event.getTabPosition() == MoviesActivity.TAB_POSITION_NOW) {
            recyclerView.smoothScrollToPosition(0);
        }
    });
    return view;
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Nullable(androidx.annotation.Nullable)

Aggregations

ViewModelProvider (androidx.lifecycle.ViewModelProvider)56 TextView (android.widget.TextView)13 Intent (android.content.Intent)12 View (android.view.View)11 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)8 IdpResponse (com.firebase.ui.auth.IdpResponse)8 Bundle (android.os.Bundle)7 Toolbar (androidx.appcompat.widget.Toolbar)7 FirebaseAuthAnonymousUpgradeException (com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException)7 Handler (android.os.Handler)6 HandlerThread (android.os.HandlerThread)5 SpannableStringBuilder (android.text.SpannableStringBuilder)5 Nullable (androidx.annotation.Nullable)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)4 Animator (android.animation.Animator)3 Bitmap (android.graphics.Bitmap)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 Uri (android.net.Uri)3 FragmentManager (androidx.fragment.app.FragmentManager)3