Search in sources :

Example 46 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project FirebaseUI-Android by firebase.

the class PhoneActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fui_activity_register_phone);
    final PhoneProviderResponseHandler handler = new ViewModelProvider(this).get(PhoneProviderResponseHandler.class);
    handler.init(getFlowParams());
    handler.getOperation().observe(this, new ResourceObserver<IdpResponse>(this, R.string.fui_progress_dialog_signing_in) {

        @Override
        protected void onSuccess(@NonNull IdpResponse response) {
            startSaveCredentials(handler.getCurrentUser(), response, null);
        }

        @Override
        protected void onFailure(@NonNull Exception e) {
            handleError(e);
        }
    });
    mPhoneVerifier = new ViewModelProvider(this).get(PhoneNumberVerificationHandler.class);
    mPhoneVerifier.init(getFlowParams());
    mPhoneVerifier.onRestoreInstanceState(savedInstanceState);
    mPhoneVerifier.getOperation().observe(this, new ResourceObserver<PhoneVerification>(this, R.string.fui_verifying) {

        @Override
        protected void onSuccess(@NonNull PhoneVerification verification) {
            if (verification.isAutoVerified()) {
                Toast.makeText(PhoneActivity.this, R.string.fui_auto_verified, Toast.LENGTH_LONG).show();
                FragmentManager manager = getSupportFragmentManager();
                if (manager.findFragmentByTag(SubmitConfirmationCodeFragment.TAG) != null) {
                    // Ensure the submit code screen isn't visible if there's no code to submit.
                    // It's possible to get into this state when an SMS is sent, but then
                    // automatically retrieved.
                    manager.popBackStack();
                }
            }
            handler.startSignIn(verification.getCredential(), new IdpResponse.Builder(new User.Builder(PhoneAuthProvider.PROVIDER_ID, null).setPhoneNumber(verification.getNumber()).build()).build());
        }

        @Override
        protected void onFailure(@NonNull Exception e) {
            if (e instanceof PhoneNumberVerificationRequiredException) {
                // already be visible so we have nothing to do.
                if (getSupportFragmentManager().findFragmentByTag(SubmitConfirmationCodeFragment.TAG) == null) {
                    showSubmitCodeFragment(((PhoneNumberVerificationRequiredException) e).getPhoneNumber());
                }
                // Clear existing errors
                handleError(null);
            } else {
                handleError(e);
            }
        }
    });
    if (savedInstanceState != null) {
        return;
    }
    Bundle params = getIntent().getExtras().getBundle(ExtraConstants.PARAMS);
    CheckPhoneNumberFragment fragment = CheckPhoneNumberFragment.newInstance(params);
    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_phone, fragment, CheckPhoneNumberFragment.TAG).disallowAddToBackStack().commit();
}
Also used : Bundle(android.os.Bundle) PhoneNumberVerificationRequiredException(com.firebase.ui.auth.data.model.PhoneNumberVerificationRequiredException) PhoneNumberVerificationRequiredException(com.firebase.ui.auth.data.model.PhoneNumberVerificationRequiredException) FirebaseAuthAnonymousUpgradeException(com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) FirebaseAuthException(com.google.firebase.auth.FirebaseAuthException) FragmentManager(androidx.fragment.app.FragmentManager) PhoneProviderResponseHandler(com.firebase.ui.auth.viewmodel.phone.PhoneProviderResponseHandler) ViewModelProvider(androidx.lifecycle.ViewModelProvider) IdpResponse(com.firebase.ui.auth.IdpResponse)

Example 47 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project android-mvvm-architecture by MindorksOpenSource.

the class ActivityModule method provideFeedViewModel.

@Provides
FeedViewModel provideFeedViewModel(DataManager dataManager, SchedulerProvider schedulerProvider) {
    Supplier<FeedViewModel> supplier = () -> new FeedViewModel(dataManager, schedulerProvider);
    ViewModelProviderFactory<FeedViewModel> factory = new ViewModelProviderFactory<>(FeedViewModel.class, supplier);
    return new ViewModelProvider(activity, factory).get(FeedViewModel.class);
}
Also used : FeedViewModel(com.mindorks.framework.mvvm.ui.feed.FeedViewModel) ViewModelProviderFactory(com.mindorks.framework.mvvm.ViewModelProviderFactory) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Provides(dagger.Provides)

Example 48 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project android-mvvm-architecture by MindorksOpenSource.

the class FragmentModule method provideBlogViewModel.

@Provides
BlogViewModel provideBlogViewModel(DataManager dataManager, SchedulerProvider schedulerProvider) {
    Supplier<BlogViewModel> supplier = () -> new BlogViewModel(dataManager, schedulerProvider);
    ViewModelProviderFactory<BlogViewModel> factory = new ViewModelProviderFactory<>(BlogViewModel.class, supplier);
    return new ViewModelProvider(fragment, factory).get(BlogViewModel.class);
}
Also used : ViewModelProviderFactory(com.mindorks.framework.mvvm.ViewModelProviderFactory) BlogViewModel(com.mindorks.framework.mvvm.ui.feed.blogs.BlogViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Provides(dagger.Provides)

Example 49 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project android-mvvm-architecture by MindorksOpenSource.

the class FragmentModule method provideAboutViewModel.

@Provides
AboutViewModel provideAboutViewModel(DataManager dataManager, SchedulerProvider schedulerProvider) {
    Supplier<AboutViewModel> supplier = () -> new AboutViewModel(dataManager, schedulerProvider);
    ViewModelProviderFactory<AboutViewModel> factory = new ViewModelProviderFactory<>(AboutViewModel.class, supplier);
    return new ViewModelProvider(fragment, factory).get(AboutViewModel.class);
}
Also used : ViewModelProviderFactory(com.mindorks.framework.mvvm.ViewModelProviderFactory) AboutViewModel(com.mindorks.framework.mvvm.ui.about.AboutViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Provides(dagger.Provides)

Example 50 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project AudioVideo by JimSeker.

the class CameraFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    myViewModel = new ViewModelProvider(requireActivity()).get(videoViewModel.class);
    View myView = inflater.inflate(R.layout.fragment_camera, container, false);
    context = getContext();
    preview = myView.findViewById(R.id.camera2_preview);
    // Install a SurfaceHolder.Callback so we get notified when the
    // underlying surface is created and destroyed.
    mHolder = preview.getHolder();
    mHolder.addCallback(this);
    btn_takevideo = myView.findViewById(R.id.btn_takevideo);
    btn_takevideo.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!mIsRecordingVideo) {
                // about to take a video
                mIsRecordingVideo = true;
                btn_takevideo.setText("Stop Recording");
                startRecordingVideo();
            } else {
                stopRecordingVideo();
                mIsRecordingVideo = false;
                btn_takevideo.setText("Start Recording");
            }
        }
    });
    return myView;
}
Also used : SurfaceView(android.view.SurfaceView) View(android.view.View) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

ViewModelProvider (androidx.lifecycle.ViewModelProvider)159 View (android.view.View)38 TextView (android.widget.TextView)28 BottomSheetEvent (xyz.zedler.patrick.grocy.model.BottomSheetEvent)25 Intent (android.content.Intent)24 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)24 InfoFullscreenHelper (xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper)23 Nullable (androidx.annotation.Nullable)21 Snackbar (com.google.android.material.snackbar.Snackbar)20 ClickUtil (xyz.zedler.patrick.grocy.util.ClickUtil)20 Bundle (android.os.Bundle)18 RecyclerView (androidx.recyclerview.widget.RecyclerView)18 Toolbar (androidx.appcompat.widget.Toolbar)16 SnackbarMessage (xyz.zedler.patrick.grocy.model.SnackbarMessage)16 Uri (android.net.Uri)10 ViewGroup (android.view.ViewGroup)10 NonNull (androidx.annotation.NonNull)10 Handler (android.os.Handler)9 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)8 IdpResponse (com.firebase.ui.auth.IdpResponse)8