Search in sources :

Example 16 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 17 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project J2ME-Loader by nikita36078.

the class InstallerDialog method onAttach.

@Override
public void onAttach(@NonNull Context context) {
    super.onAttach(context);
    AppListModel appListModel = new ViewModelProvider(requireActivity()).get(AppListModel.class);
    appRepository = appListModel.getAppRepository();
}
Also used : AppListModel(ru.playsoftware.j2meloader.applist.AppListModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 18 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project bitcoin-wallet by bitcoin-wallet.

the class EncryptKeysDialogFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    log.info("opening dialog {}", getClass().getName());
    activityViewModel = new ViewModelProvider(activity).get(WalletActivityViewModel.class);
    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 19 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project bitcoin-wallet by bitcoin-wallet.

the class EditAddressBookEntryFragment method maybeSelectAddress.

private void maybeSelectAddress(final Address address) {
    // in the address book.
    if (activity instanceof AddressBookActivity) {
        final AddressBookViewModel activityViewModel = new ViewModelProvider(activity).get(AddressBookViewModel.class);
        new Handler().postDelayed(() -> activityViewModel.selectedAddress.setValue(address), 250);
    }
}
Also used : Handler(android.os.Handler) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 20 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project bitcoin-wallet by bitcoin-wallet.

the class RequestCoinsFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.fragmentManager = getChildFragmentManager();
    setHasOptionsMenu(true);
    viewModel = new ViewModelProvider(this).get(RequestCoinsViewModel.class);
    final Intent intent = activity.getIntent();
    if (intent.hasExtra(RequestCoinsActivity.INTENT_EXTRA_OUTPUT_SCRIPT_TYPE))
        viewModel.freshReceiveAddress.overrideOutputScriptType((Script.ScriptType) intent.getSerializableExtra(RequestCoinsActivity.INTENT_EXTRA_OUTPUT_SCRIPT_TYPE));
    viewModel.freshReceiveAddress.observe(this, address -> log.info("request coins address: {}", address));
    viewModel.qrCode.observe(this, qrCode -> {
        final BitmapDrawable qrDrawable = new BitmapDrawable(getResources(), qrCode);
        qrDrawable.setFilterBitmap(false);
        qrView.setImageDrawable(qrDrawable);
        qrCardView.setOnClickListener(v -> viewModel.showBitmapDialog.setValue(new Event<>(viewModel.qrCode.getValue())));
    });
    viewModel.paymentRequest.observe(this, paymentRequest -> {
        final NfcAdapter nfcAdapter = RequestCoinsFragment.this.nfcAdapter;
        final SpannableStringBuilder initiateText = new SpannableStringBuilder(getString(R.string.request_coins_fragment_initiate_request_qr));
        if (nfcAdapter != null && nfcAdapter.isEnabled()) {
            initiateText.append(' ').append(getString(R.string.request_coins_fragment_initiate_request_nfc));
            nfcAdapter.setNdefPushMessage(createNdefMessage(paymentRequest), activity);
        }
        initiateRequestView.setText(initiateText);
    });
    viewModel.bitcoinUri.observe(this, bitcoinUri -> activity.invalidateOptionsMenu());
    if (config.isEnableExchangeRates()) {
        viewModel.exchangeRate.observe(this, exchangeRate -> amountCalculatorLink.setExchangeRate(exchangeRate != null ? exchangeRate.exchangeRate() : null));
    }
    viewModel.showBitmapDialog.observe(this, new Event.Observer<Bitmap>() {

        @Override
        protected void onEvent(final Bitmap bitmap) {
            BitmapFragment.show(fragmentManager, bitmap);
        }
    });
    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    }
}
Also used : Bitmap(android.graphics.Bitmap) Intent(android.content.Intent) NfcAdapter(android.nfc.NfcAdapter) BitmapDrawable(android.graphics.drawable.BitmapDrawable) SpannableStringBuilder(android.text.SpannableStringBuilder) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

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