Search in sources :

Example 96 with ViewModelProvider

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

the class WalletAddressFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.fragmentManager = getChildFragmentManager();
    activityViewModel = new ViewModelProvider(activity).get(WalletActivityViewModel.class);
    viewModel = new ViewModelProvider(this).get(WalletAddressViewModel.class);
    viewModel.qrCode.observe(this, qrCode -> {
        final BitmapDrawable qrDrawable = new BitmapDrawable(getResources(), qrCode);
        qrDrawable.setFilterBitmap(false);
        currentAddressQrView.setImageDrawable(qrDrawable);
        currentAddressQrCardView.setOnClickListener(v -> viewModel.showWalletAddressDialog.setValue(Event.simple()));
    });
    viewModel.bitcoinUri.observe(this, bitcoinUri -> {
        final NfcAdapter nfcAdapter = WalletAddressFragment.this.nfcAdapter;
        if (nfcAdapter != null)
            nfcAdapter.setNdefPushMessage(createNdefMessage(bitcoinUri.toString()), activity);
        activityViewModel.addressLoadingFinished();
    });
    viewModel.showWalletAddressDialog.observe(this, new Event.Observer<Void>() {

        @Override
        protected void onEvent(final Void v) {
            final Address address = viewModel.currentAddress.getValue();
            WalletAddressDialogFragment.show(fragmentManager);
            log.info("Current address enlarged: {}", address);
        }
    });
}
Also used : Address(org.bitcoinj.core.Address) NfcAdapter(android.nfc.NfcAdapter) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 97 with ViewModelProvider

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

the class RestoreWalletDialogFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    log.info("opening dialog {}", getClass().getName());
    viewModel = new ViewModelProvider(this).get(RestoreWalletViewModel.class);
    viewModel.showSuccessDialog.observe(this, new Event.Observer<Boolean>() {

        @Override
        protected void onEvent(final Boolean showEncryptedMessage) {
            SuccessDialogFragment.showDialog(fragmentManager, showEncryptedMessage);
        }
    });
    viewModel.showFailureDialog.observe(this, new Event.Observer<String>() {

        @Override
        protected void onEvent(final String message) {
            FailureDialogFragment.showDialog(fragmentManager, message, viewModel.backupUri.getValue());
        }
    });
    viewModel.backupUri.observe(this, uri -> {
        final String backupProvider = WalletUtils.uriToProvider(uri);
        log.info("picked '{}'{}", uri, backupProvider != null ? " (" + backupProvider + ")" : "");
        final Cursor cursor = contentResolver.query(uri, null, null, null, null, null);
        if (cursor != null) {
            try {
                if (cursor.moveToFirst())
                    viewModel.displayName.setValue(cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)));
            } finally {
                cursor.close();
            }
        }
    });
    viewModel.displayName.observe(this, name -> messageView.setText(name));
    final Bundle args = getArguments();
    if (args != null) {
        viewModel.backupUri.setValue((Uri) args.getParcelable(KEY_BACKUP_URI));
    } else {
        final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
        try {
            startActivityForResult(intent, REQUEST_CODE_OPEN_DOCUMENT);
        } catch (final ActivityNotFoundException x) {
            log.warn("Cannot open document selector: {}", intent);
            new Toast(activity).longToast(R.string.toast_start_storage_provider_selector_failed);
        }
    }
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) Cursor(android.database.Cursor) Toast(de.schildbach.wallet.util.Toast) ActivityNotFoundException(android.content.ActivityNotFoundException) Event(de.schildbach.wallet.ui.Event) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 98 with ViewModelProvider

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

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (FileUtils.isExternalStorageLegacy()) {
        permissionsLauncher.launch(STORAGE_PERMISSIONS);
    }
    appListModel = new ViewModelProvider(this).get(AppListModel.class);
    if (savedInstanceState == null) {
        Intent intent = getIntent();
        Uri uri = null;
        if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
            uri = intent.getData();
        }
        AppsListFragment fragment = AppsListFragment.newInstance(uri);
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
    }
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    if (!preferences.contains(PREF_TOOLBAR)) {
        boolean enable = !ViewConfiguration.get(this).hasPermanentMenuKey();
        preferences.edit().putBoolean(PREF_TOOLBAR, enable).apply();
    }
    boolean warningShown = preferences.getBoolean(PREF_STORAGE_WARNING_SHOWN, false);
    if (!FileUtils.isExternalStorageLegacy() && !warningShown) {
        showScopedStorageDialog();
        preferences.edit().putBoolean(PREF_STORAGE_WARNING_SHOWN, true).apply();
    }
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
Also used : AppsListFragment(ru.playsoftware.j2meloader.applist.AppsListFragment) Intent(android.content.Intent) AppListModel(ru.playsoftware.j2meloader.applist.AppListModel) Uri(android.net.Uri) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 99 with ViewModelProvider

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

the class AppsListFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle args = requireArguments();
    appUri = args.getParcelable(KEY_APP_URI);
    args.remove(KEY_APP_URI);
    preferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
    AppListModel appListModel = new ViewModelProvider(requireActivity()).get(AppListModel.class);
    appRepository = appListModel.getAppRepository();
    appRepository.observeErrors(this, this::alertDbError);
    appRepository.observeApps(this, this::onDbUpdated);
}
Also used : Bundle(android.os.Bundle) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 100 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project collect by opendatakit.

the class FormEntryActivity method setupViewModels.

private void setupViewModels() {
    backgroundLocationViewModel = ViewModelProviders.of(this, new BackgroundLocationViewModel.Factory(permissionsProvider, settingsProvider.getUnprotectedSettings())).get(BackgroundLocationViewModel.class);
    backgroundAudioViewModel = new ViewModelProvider(this, backgroundAudioViewModelFactory).get(BackgroundAudioViewModel.class);
    backgroundAudioViewModel.isPermissionRequired().observe(this, isPermissionRequired -> {
        if (isPermissionRequired) {
            showIfNotShowing(BackgroundAudioPermissionDialogFragment.class, getSupportFragmentManager());
        }
    });
    identityPromptViewModel = ViewModelProviders.of(this).get(IdentityPromptViewModel.class);
    identityPromptViewModel.requiresIdentityToContinue().observe(this, requiresIdentity -> {
        if (requiresIdentity) {
            showIfNotShowing(IdentifyUserPromptDialogFragment.class, getSupportFragmentManager());
        }
    });
    identityPromptViewModel.isFormEntryCancelled().observe(this, isFormEntryCancelled -> {
        if (isFormEntryCancelled) {
            finish();
        }
    });
    formEntryViewModel = ViewModelProviders.of(this, formEntryViewModelFactory).get(FormEntryViewModel.class);
    formEntryViewModel.getError().observe(this, error -> {
        if (error instanceof FormEntryViewModel.NonFatal) {
            createErrorDialog(((FormEntryViewModel.NonFatal) error).getMessage(), false);
            formEntryViewModel.errorDisplayed();
        }
    });
    formSaveViewModel = new ViewModelProvider(this, formSaveViewModelFactoryFactory.create(this, null)).get(FormSaveViewModel.class);
    formSaveViewModel.getSaveResult().observe(this, this::handleSaveResult);
    formSaveViewModel.isSavingAnswerFile().observe(this, isSavingAnswerFile -> {
        if (isSavingAnswerFile) {
            DialogFragmentUtils.showIfNotShowing(SaveAnswerFileProgressDialogFragment.class, getSupportFragmentManager());
        } else {
            DialogFragmentUtils.dismissDialog(SaveAnswerFileProgressDialogFragment.class, getSupportFragmentManager());
        }
    });
    formSaveViewModel.getAnswerFileError().observe(this, file -> {
        if (file != null) {
            DialogFragmentUtils.showIfNotShowing(SaveAnswerFileErrorDialogFragment.class, getSupportFragmentManager());
        }
    });
    internalRecordingRequester = new InternalRecordingRequester(this, audioRecorder, permissionsProvider, formEntryViewModel);
    waitingForDataRegistry = new FormControllerWaitingForDataRegistry();
    externalAppRecordingRequester = new ExternalAppRecordingRequester(this, intentLauncher, waitingForDataRegistry, permissionsProvider, formEntryViewModel);
    RecordingHandler recordingHandler = new RecordingHandler(formSaveViewModel, this, audioRecorder, new AMRAppender(), new M4AAppender());
    audioRecorder.getCurrentSession().observe(this, session -> {
        if (session != null && session.getFile() != null) {
            recordingHandler.handle(getFormController(), session, success -> {
                if (success) {
                    onScreenRefresh();
                    formSaveViewModel.resumeSave();
                } else {
                    String path = session.getFile().getAbsolutePath();
                    String message = getString(R.string.answer_file_copy_failed_message, path);
                    Toast.makeText(this, message, Toast.LENGTH_LONG).show();
                }
            });
        }
    });
}
Also used : BackgroundLocationViewModel(org.odk.collect.android.formentry.backgroundlocation.BackgroundLocationViewModel) IdentityPromptViewModel(org.odk.collect.android.formentry.audit.IdentityPromptViewModel) ExternalAppRecordingRequester(org.odk.collect.android.widgets.utilities.ExternalAppRecordingRequester) FormEntryViewModel(org.odk.collect.android.formentry.FormEntryViewModel) RecordingHandler(org.odk.collect.android.formentry.RecordingHandler) AMRAppender(org.odk.collect.android.audio.AMRAppender) FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) BackgroundAudioViewModel(org.odk.collect.android.formentry.BackgroundAudioViewModel) InternalRecordingRequester(org.odk.collect.android.widgets.utilities.InternalRecordingRequester) FormControllerWaitingForDataRegistry(org.odk.collect.android.widgets.utilities.FormControllerWaitingForDataRegistry) M4AAppender(org.odk.collect.android.audio.M4AAppender) 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