Search in sources :

Example 26 with ViewModelProvider

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

the class RaiseFeeDialogFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    log.info("opening dialog {}", getClass().getName());
    walletActivityViewModel = new ViewModelProvider(activity).get(AbstractWalletActivityViewModel.class);
    walletActivityViewModel.wallet.observe(this, wallet -> {
        final Bundle args = getArguments();
        transaction = checkNotNull(wallet.getTransaction(Sha256Hash.wrap(args.getByteArray(KEY_TRANSACTION))));
        updateView();
        viewModel.getDynamicFees().observe(this, dynamicFees -> {
            // We basically have to pay fee for two transactions:
            // The transaction to raise the fee of and the CPFP transaction we're about to create.
            final int size = transaction.getMessageSize() + 192;
            feeRaise = dynamicFees.get(FeeCategory.PRIORITY).multiply(size).divide(1000);
            updateView();
        });
    });
    viewModel = new ViewModelProvider(this).get(RaiseFeeViewModel.class);
    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());
}
Also used : HandlerThread(android.os.HandlerThread) Bundle(android.os.Bundle) AbstractWalletActivityViewModel(de.schildbach.wallet.ui.AbstractWalletActivityViewModel) Handler(android.os.Handler) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 27 with ViewModelProvider

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

the class FormHierarchyActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hierarchy_layout);
    Collect.getInstance().getComponent().inject(this);
    recyclerView = findViewById(R.id.list);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    TextView emptyView = findViewById(android.R.id.empty);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    FormController formController = Collect.getInstance().getFormController();
    // https://github.com/getodk/collect/issues/998
    if (formController == null) {
        finish();
        Timber.w("FormController is null");
        return;
    }
    formEntryViewModel = new ViewModelProvider(this, formEntryViewModelFactory).get(FormEntryViewModel.class);
    formEntryViewModel.formLoaded(Collect.getInstance().getFormController());
    startIndex = formController.getFormIndex();
    setTitle(formController.getFormTitle());
    groupPathTextView = findViewById(R.id.pathtext);
    jumpBeginningButton = findViewById(R.id.jumpBeginningButton);
    jumpEndButton = findViewById(R.id.jumpEndButton);
    configureButtons(formController);
    restoreInstanceState(savedInstanceState);
    refreshView();
    // TODO: avoid another iteration through all displayed elements
    if (recyclerView != null && recyclerView.getAdapter() != null && recyclerView.getAdapter().getItemCount() > 0) {
        emptyView.setVisibility(View.GONE);
        recyclerView.post(() -> {
            int position = 0;
            // startIndex which can either represent a question or a field list.
            for (HierarchyElement hierarchyElement : elementsToDisplay) {
                FormIndex indexToCheck = hierarchyElement.getFormIndex();
                if (startIndex.equals(indexToCheck) || (formController.indexIsInFieldList(startIndex) && indexToCheck.toString().startsWith(startIndex.toString()))) {
                    position = elementsToDisplay.indexOf(hierarchyElement);
                    break;
                }
            }
            ((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(position, 0);
        });
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) HierarchyElement(org.odk.collect.android.logic.HierarchyElement) FormIndex(org.javarosa.core.model.FormIndex) TextView(android.widget.TextView) FormEntryViewModel(org.odk.collect.android.formentry.FormEntryViewModel) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Toolbar(androidx.appcompat.widget.Toolbar) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 28 with ViewModelProvider

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

the class MainMenuActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    new ThemeUtils(this).setDarkModeForCurrentProject();
    super.onCreate(savedInstanceState);
    DaggerUtils.getComponent(this).inject(this);
    setContentView(R.layout.main_menu);
    settingsProvider.getMetaSettings().save(MetaKeys.FIRST_LAUNCH, false);
    mainMenuViewModel = new ViewModelProvider(this, viewModelFactory).get(MainMenuViewModel.class);
    currentProjectViewModel = new ViewModelProvider(this, currentProjectViewModelFactory).get(CurrentProjectViewModel.class);
    currentProjectViewModel.getCurrentProject().observe(this, project -> {
        invalidateOptionsMenu();
        setTitle(project.getName());
    });
    initToolbar();
    // enter data button. expects a result.
    Button enterDataButton = findViewById(R.id.enter_data);
    enterDataButton.setText(getString(R.string.enter_data_button));
    enterDataButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), FillBlankFormActivity.class);
            startActivity(i);
        }
    });
    // review data button. expects a result.
    reviewDataButton = findViewById(R.id.review_data);
    reviewDataButton.setText(getString(R.string.review_data_button));
    reviewDataButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), InstanceChooserList.class);
            i.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.EDIT_SAVED);
            startActivity(i);
        }
    });
    // send data button. expects a result.
    sendDataButton = findViewById(R.id.send_data);
    sendDataButton.setText(getString(R.string.send_data_button));
    sendDataButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), InstanceUploaderListActivity.class);
            startActivity(i);
        }
    });
    // View sent forms
    viewSentFormsButton = findViewById(R.id.view_sent_forms);
    viewSentFormsButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), InstanceChooserList.class);
            i.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.VIEW_SENT);
            startActivity(i);
        }
    });
    // manage forms button. no result expected.
    getFormsButton = findViewById(R.id.get_forms);
    getFormsButton.setText(getString(R.string.get_forms));
    getFormsButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String protocol = settingsProvider.getUnprotectedSettings().getString(ProjectKeys.KEY_PROTOCOL);
            Intent i;
            if (protocol.equalsIgnoreCase(ProjectKeys.PROTOCOL_GOOGLE_SHEETS)) {
                if (new PlayServicesChecker().isGooglePlayServicesAvailable(MainMenuActivity.this)) {
                    i = new Intent(getApplicationContext(), GoogleDriveActivity.class);
                } else {
                    new PlayServicesChecker().showGooglePlayServicesAvailabilityErrorDialog(MainMenuActivity.this);
                    return;
                }
            } else {
                i = new Intent(getApplicationContext(), FormDownloadListActivity.class);
            }
            startActivity(i);
        }
    });
    // manage forms button. no result expected.
    manageFilesButton = findViewById(R.id.manage_forms);
    manageFilesButton.setText(getString(R.string.manage_files));
    manageFilesButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), DeleteSavedFormActivity.class);
            startActivity(i);
        }
    });
    TextView appName = findViewById(R.id.app_name);
    appName.setText(String.format("%s %s", getString(R.string.collect_app_name), mainMenuViewModel.getVersion()));
    TextView versionSHAView = findViewById(R.id.version_sha);
    String versionSHA = mainMenuViewModel.getVersionCommitDescription();
    if (versionSHA != null) {
        versionSHAView.setText(versionSHA);
    } else {
        versionSHAView.setVisibility(View.GONE);
    }
    mainMenuViewModel.getSendableInstancesCount().observe(this, finalized -> {
        if (finalized > 0) {
            sendDataButton.setText(getString(R.string.send_data_button, String.valueOf(finalized)));
        } else {
            sendDataButton.setText(getString(R.string.send_data));
        }
    });
    mainMenuViewModel.getEditableInstancesCount().observe(this, unsent -> {
        if (unsent > 0) {
            reviewDataButton.setText(getString(R.string.review_data_button, String.valueOf(unsent)));
        } else {
            reviewDataButton.setText(getString(R.string.review_data));
        }
    });
    mainMenuViewModel.getSentInstancesCount().observe(this, sent -> {
        if (sent > 0) {
            viewSentFormsButton.setText(getString(R.string.view_sent_forms_button, String.valueOf(sent)));
        } else {
            viewSentFormsButton.setText(getString(R.string.view_sent_forms));
        }
    });
}
Also used : MainMenuViewModel(org.odk.collect.android.activities.viewmodels.MainMenuViewModel) ThemeUtils(org.odk.collect.android.utilities.ThemeUtils) PlayServicesChecker(org.odk.collect.android.utilities.PlayServicesChecker) Intent(android.content.Intent) View(android.view.View) ProjectIconView(org.odk.collect.android.projects.ProjectIconView) TextView(android.widget.TextView) Button(android.widget.Button) CurrentProjectViewModel(org.odk.collect.android.activities.viewmodels.CurrentProjectViewModel) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 29 with ViewModelProvider

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

the class AndroidShortcutsActivity method onCreate.

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    DaggerUtils.getComponent(this).inject(this);
    BlankFormsListViewModel blankFormsListViewModel = new ViewModelProvider(this, blankFormsListViewModelFactory).get(BlankFormsListViewModel.class);
    List<BlankForm> forms = blankFormsListViewModel.getForms();
    showFormListDialog(forms);
}
Also used : BlankForm(org.odk.collect.android.formmanagement.BlankFormsListViewModel.BlankForm) BlankFormsListViewModel(org.odk.collect.android.formmanagement.BlankFormsListViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 30 with ViewModelProvider

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

the class FixedDatePickerDialog method onAttach.

@Override
public void onAttach(@NonNull Context context) {
    super.onAttach(context);
    themeUtils = new ThemeUtils(context);
    if (context instanceof CustomDatePickerDialog.DateChangeListener) {
        dateChangeListener = (CustomDatePickerDialog.DateChangeListener) context;
    }
    viewModel = new ViewModelProvider(this).get(DateTimeViewModel.class);
    viewModel.setDialogTheme(getArguments().getInt(DateTimeWidgetUtils.DIALOG_THEME));
    viewModel.setLocalDateTime((LocalDateTime) getArguments().getSerializable(DateTimeWidgetUtils.DATE));
    viewModel.setDatePickerDetails((DatePickerDetails) getArguments().getSerializable(DateTimeWidgetUtils.DATE_PICKER_DETAILS));
    viewModel.getSelectedDate().observe(this, localDateTime -> {
        if (localDateTime != null) {
            dateChangeListener.onDateChanged(localDateTime);
        }
    });
}
Also used : ThemeUtils(org.odk.collect.android.utilities.ThemeUtils) DateTimeViewModel(org.odk.collect.android.widgets.viewmodels.DateTimeViewModel) 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