use of androidx.lifecycle.ViewModelProvider in project materialistic by hidroh.
the class ListFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
MaterialisticDatabase.getInstance(getContext()).getLiveData().observe(getViewLifecycleOwner(), mObserver);
String managerClassName = getArguments().getString(EXTRA_ITEM_MANAGER);
ItemManager itemManager;
if (TextUtils.equals(managerClassName, AlgoliaClient.class.getName())) {
itemManager = mAlgoliaItemManager;
} else if (TextUtils.equals(managerClassName, AlgoliaPopularClient.class.getName())) {
itemManager = mPopularItemManager;
} else {
itemManager = mHnItemManager;
}
getAdapter().setHotThresHold(AppUtils.HOT_THRESHOLD_NORMAL);
if (itemManager == mHnItemManager && mFilter != null) {
switch(mFilter) {
case ItemManager.BEST_FETCH_MODE:
getAdapter().setHotThresHold(AppUtils.HOT_THRESHOLD_HIGH);
break;
case ItemManager.NEW_FETCH_MODE:
getAdapter().setHotThresHold(AppUtils.HOT_THRESHOLD_LOW);
break;
}
} else if (itemManager == mPopularItemManager) {
getAdapter().setHotThresHold(AppUtils.HOT_THRESHOLD_HIGH);
}
getAdapter().initDisplayOptions(mRecyclerView);
getAdapter().setCacheMode(mCacheMode);
getAdapter().setUpdateListener((showAll, itemCount, actionClickListener) -> {
if (showAll) {
Snackbar.make(mRecyclerView, getResources().getQuantityString(R.plurals.new_stories_count, itemCount, itemCount), Snackbar.LENGTH_LONG).setAction(R.string.show_me, actionClickListener).show();
} else {
final Snackbar snackbar = Snackbar.make(mRecyclerView, getResources().getQuantityString(R.plurals.showing_new_stories, itemCount, itemCount), Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.show_all, actionClickListener).show();
}
});
mStoryListViewModel = new ViewModelProvider(this).get(StoryListViewModel.class);
mStoryListViewModel.inject(itemManager, mIoThreadScheduler);
mStoryListViewModel.getStories(mFilter, mCacheMode).observe(getViewLifecycleOwner(), itemLists -> {
if (itemLists == null) {
return;
}
if (itemLists.first != null) {
onItemsLoaded(itemLists.first);
}
if (itemLists.second != null) {
onItemsLoaded(itemLists.second);
}
});
}
use of androidx.lifecycle.ViewModelProvider in project quickstart-android by firebase.
the class MainFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mBinding.filterBar.setOnClickListener(this);
mBinding.buttonClearFilter.setOnClickListener(this);
// View model
mViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
// Enable Firestore logging
FirebaseFirestore.setLoggingEnabled(true);
// Firestore
mFirestore = FirebaseFirestore.getInstance();
// Get ${LIMIT} restaurants
mQuery = mFirestore.collection("restaurants").orderBy("avgRating", Query.Direction.DESCENDING).limit(LIMIT);
// RecyclerView
mAdapter = new RestaurantAdapter(mQuery, this) {
@Override
protected void onDataChanged() {
// Show/hide content if the query returns empty.
if (getItemCount() == 0) {
mBinding.recyclerRestaurants.setVisibility(View.GONE);
mBinding.viewEmpty.setVisibility(View.VISIBLE);
} else {
mBinding.recyclerRestaurants.setVisibility(View.VISIBLE);
mBinding.viewEmpty.setVisibility(View.GONE);
}
}
@Override
protected void onError(FirebaseFirestoreException e) {
// Show a snackbar on errors
Snackbar.make(mBinding.getRoot(), "Error: check logs for info.", Snackbar.LENGTH_LONG).show();
}
};
mBinding.recyclerRestaurants.setLayoutManager(new LinearLayoutManager(requireContext()));
mBinding.recyclerRestaurants.setAdapter(mAdapter);
// Filter Dialog
mFilterDialog = new FilterDialogFragment();
}
use of androidx.lifecycle.ViewModelProvider in project Signal-Android by WhisperSystems.
the class EnterPhoneNumberFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setDebugLogSubmitMultiTapView(view.findViewById(R.id.verify_header));
countryCode = view.findViewById(R.id.country_code);
number = view.findViewById(R.id.number);
countrySpinner = view.findViewById(R.id.country_spinner);
cancel = view.findViewById(R.id.cancel_button);
scrollView = view.findViewById(R.id.scroll_view);
register = view.findViewById(R.id.registerButton);
RegistrationNumberInputController controller = new RegistrationNumberInputController(requireContext(), countryCode, number, countrySpinner, true, this);
register.setOnClickListener(v -> handleRegister(requireContext()));
disposables.bindTo(getViewLifecycleOwner().getLifecycle());
viewModel = new ViewModelProvider(requireActivity()).get(RegistrationViewModel.class);
if (viewModel.isReregister()) {
cancel.setVisibility(View.VISIBLE);
cancel.setOnClickListener(v -> Navigation.findNavController(v).navigateUp());
} else {
cancel.setVisibility(View.GONE);
}
viewModel.getLiveNumber().observe(getViewLifecycleOwner(), controller::updateNumber);
if (viewModel.hasCaptchaToken()) {
ThreadUtil.runOnMainDelayed(() -> handleRegister(requireContext()), 250);
}
Toolbar toolbar = view.findViewById(R.id.toolbar);
((AppCompatActivity) requireActivity()).setSupportActionBar(toolbar);
((AppCompatActivity) requireActivity()).getSupportActionBar().setTitle(null);
}
use of androidx.lifecycle.ViewModelProvider in project Signal-Android by WhisperSystems.
the class RegistrationCompleteFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
FragmentActivity activity = requireActivity();
RegistrationViewModel viewModel = new ViewModelProvider(activity).get(RegistrationViewModel.class);
if (SignalStore.storageService().needsAccountRestore()) {
Log.i(TAG, "Performing pin restore");
activity.startActivity(new Intent(activity, PinRestoreActivity.class));
} else if (!viewModel.isReregister()) {
boolean needsProfile = Recipient.self().getProfileName().isEmpty() || !AvatarHelper.hasAvatar(activity, Recipient.self().getId());
boolean needsPin = !SignalStore.kbsValues().hasPin();
Log.i(TAG, "Pin restore flow not required." + " profile name: " + Recipient.self().getProfileName().isEmpty() + " profile avatar: " + !AvatarHelper.hasAvatar(activity, Recipient.self().getId()) + " needsPin:" + needsPin);
Intent startIntent = MainActivity.clearTop(activity);
if (needsPin) {
startIntent = chainIntents(CreateKbsPinActivity.getIntentForPinCreate(requireContext()), startIntent);
}
if (needsProfile) {
startIntent = chainIntents(EditProfileActivity.getIntentForUserProfile(activity), startIntent);
}
if (!needsProfile && !needsPin) {
ApplicationDependencies.getJobManager().startChain(new ProfileUploadJob()).then(Arrays.asList(new MultiDeviceProfileKeyUpdateJob(), new MultiDeviceProfileContentUpdateJob())).enqueue();
RegistrationUtil.maybeMarkRegistrationComplete(requireContext());
}
activity.startActivity(startIntent);
}
activity.finish();
ActivityNavigator.applyPopAnimationsToPendingTransition(activity);
}
use of androidx.lifecycle.ViewModelProvider in project Signal-Android by WhisperSystems.
the class EditNoteFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
viewModel = new ViewModelProvider(Navigation.findNavController(view).getViewModelStoreOwner(R.id.payments_create)).get(CreatePaymentViewModel.class);
Toolbar toolbar = view.findViewById(R.id.edit_note_fragment_toolbar);
toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(v).popBackStack());
noteEditText = view.findViewById(R.id.edit_note_fragment_edit_text);
viewModel.getNote().observe(getViewLifecycleOwner(), note -> {
noteEditText.setText(note);
if (!TextUtils.isEmpty(note)) {
noteEditText.setSelection(note.length());
}
});
noteEditText.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_DONE) {
saveNote();
return true;
}
return false;
});
View fab = view.findViewById(R.id.edit_note_fragment_fab);
fab.setOnClickListener(v -> saveNote());
ViewUtil.focusAndMoveCursorToEndAndOpenKeyboard(noteEditText);
}
Aggregations