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());
}
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();
}
});
}
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());
});
}
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());
});
}
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;
}
Aggregations