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