Search in sources :

Example 1 with ViewModelProvider

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);
        }
    });
}
Also used : ItemManager(io.github.hidroh.materialistic.data.ItemManager) AlgoliaClient(io.github.hidroh.materialistic.data.AlgoliaClient) Snackbar(com.google.android.material.snackbar.Snackbar) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 2 with ViewModelProvider

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();
}
Also used : MainActivityViewModel(com.google.firebase.example.fireeats.java.viewmodel.MainActivityViewModel) FirebaseFirestoreException(com.google.firebase.firestore.FirebaseFirestoreException) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RestaurantAdapter(com.google.firebase.example.fireeats.java.adapter.RestaurantAdapter) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 3 with ViewModelProvider

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);
}
Also used : AppCompatActivity(androidx.appcompat.app.AppCompatActivity) RegistrationNumberInputController(org.thoughtcrime.securesms.registration.util.RegistrationNumberInputController) ViewModelProvider(androidx.lifecycle.ViewModelProvider) RegistrationViewModel(org.thoughtcrime.securesms.registration.viewmodel.RegistrationViewModel) Toolbar(androidx.appcompat.widget.Toolbar)

Example 4 with ViewModelProvider

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);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Intent(android.content.Intent) MultiDeviceProfileKeyUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob) ProfileUploadJob(org.thoughtcrime.securesms.jobs.ProfileUploadJob) MultiDeviceProfileContentUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob) RegistrationViewModel(org.thoughtcrime.securesms.registration.viewmodel.RegistrationViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) PinRestoreActivity(org.thoughtcrime.securesms.pin.PinRestoreActivity)

Example 5 with ViewModelProvider

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);
}
Also used : View(android.view.View) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Toolbar(androidx.appcompat.widget.Toolbar)

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