androidx.databinding.ViewDataBinding Java Examples

The following examples show how to use androidx.databinding.ViewDataBinding. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DateTimeHolder.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
DateTimeHolder(ViewDataBinding binding, FlowableProcessor<RowAction> processor, boolean isSearchMode, MutableLiveData<String> currentSelection) {
    super(binding);
    this.processor = processor;
    this.isSearchMode = isSearchMode;
    this.currentUid = currentSelection;

    if (binding instanceof FormTimeTextBinding) {
        ((FormTimeTextBinding) binding).timeView.setDateListener(this);
        ((FormTimeTextBinding) binding).timeView.setActivationListener(() ->
                setSelectedBackground(isSearchMode));
    }

    if (binding instanceof FormDateTextBinding) {
        ((FormDateTextBinding) binding).dateView.setDateListener(this);
        ((FormDateTextBinding) binding).dateView.setActivationListener(() ->
                setSelectedBackground(isSearchMode));
    }

    if (binding instanceof FormDateTimeTextBinding) {
        ((FormDateTimeTextBinding) binding).dateTimeView.setDateListener(this);
        ((FormDateTimeTextBinding) binding).dateTimeView.setActivationListener(() ->
                setSelectedBackground(isSearchMode));
    }
}
 
Example #2
Source File: FormViewHolder.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public FormViewHolder(ViewDataBinding binding) {
    super(binding.getRoot());
    this.binding = binding;
    this.description = binding.getRoot().findViewById(R.id.descriptionLabel);
    if (description != null) {
        description.setOnClickListener(v ->
                new CustomDialog(
                        itemView.getContext(),
                        label.toString(),
                        descriptionText != null ? descriptionText : itemView.getContext().getString(R.string.empty_description),
                        itemView.getContext().getString(R.string.action_close),
                        null,
                        Constants.DESCRIPTION_DIALOG,
                        null
                ).show());
    }
}
 
Example #3
Source File: DateTimeRow.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NonNull
@Override
public DateTimeHolder onCreate(@NonNull ViewGroup parent) {

    ViewDataBinding binding;

    switch (viewType) {
        case TIME:
            binding = DataBindingUtil.inflate(inflater,
                    R.layout.table_time_text, parent, false);
            ((TableTimeTextBinding) binding).timeView.setCellLayout(tableScale);
            break;
        case DATE:
            binding = DataBindingUtil.inflate(inflater,
                    R.layout.table_date_text, parent, false);
            ((TableDateTextBinding) binding).dateView.setCellLayout(tableScale);
            break;
        default:
            binding = DataBindingUtil.inflate(inflater,
                    R.layout.table_date_time_text, parent, false);
            ((TableDateTimeTextBinding) binding).dateTimeView.setCellLayout(tableScale);
            break;
    }

    return new DateTimeHolder(binding, processor);
}
 
Example #4
Source File: DateTimeHolder.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
DateTimeHolder(ViewDataBinding binding, FlowableProcessor<RowAction> processor) {
    super(binding);
    this.disposable = new CompositeDisposable();
    this.processor = processor;

    if (binding instanceof TableTimeTextBinding) {
        ((TableTimeTextBinding) binding).timeView.setDateListener(this);
    }

    if (binding instanceof TableDateTextBinding) {
        ((TableDateTextBinding) binding).dateView.setDateListener(this);
    }

    if (binding instanceof TableDateTimeTextBinding) {
        ((TableDateTimeTextBinding) binding).dateTimeView.setDateListener(this);
    }

}
 
Example #5
Source File: FormViewHolder.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public FormViewHolder(ViewDataBinding binding) {
    super(binding.getRoot());
    label = new StringBuilder();
    this.binding = binding;
    this.description = binding.getRoot().findViewById(R.id.descriptionLabel);
    if (description != null) {
        description.setOnClickListener(v ->
                new CustomDialog(
                        itemView.getContext(),
                        label.toString(),
                        descriptionText != null ? descriptionText : itemView.getContext().getString(R.string.empty_description),
                        itemView.getContext().getString(R.string.action_close),
                        null,
                        Constants.DESCRIPTION_DIALOG,
                        null
                ).show());
    }
}
 
Example #6
Source File: DataBindingModelWithAllFieldTypesNoValidation_.java    From epoxy with Apache License 2.0 6 votes vote down vote up
@Override
protected void setDataBindingVariables(ViewDataBinding binding) {
  binding.setVariable(BR.valueInt, valueInt);
  binding.setVariable(BR.valueInteger, valueInteger);
  binding.setVariable(BR.valueShort, valueShort);
  binding.setVariable(BR.valueShortWrapper, valueShortWrapper);
  binding.setVariable(BR.valueChar, valueChar);
  binding.setVariable(BR.valueCharacter, valueCharacter);
  binding.setVariable(BR.valuebByte, valuebByte);
  binding.setVariable(BR.valueByteWrapper, valueByteWrapper);
  binding.setVariable(BR.valueLong, valueLong);
  binding.setVariable(BR.valueLongWrapper, valueLongWrapper);
  binding.setVariable(BR.valueDouble, valueDouble);
  binding.setVariable(BR.valueDoubleWrapper, valueDoubleWrapper);
  binding.setVariable(BR.valueFloat, valueFloat);
  binding.setVariable(BR.valueFloatWrapper, valueFloatWrapper);
  binding.setVariable(BR.valueBoolean, valueBoolean);
  binding.setVariable(BR.valueBooleanWrapper, valueBooleanWrapper);
  binding.setVariable(BR.valueIntArray, valueIntArray);
  binding.setVariable(BR.valueObjectArray, valueObjectArray);
  binding.setVariable(BR.valueString, valueString);
  binding.setVariable(BR.valueObject, valueObject);
  binding.setVariable(BR.valueList, valueList);
}
 
Example #7
Source File: OrgUnitHolder.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
OrgUnitHolder(FragmentManager fm, ViewDataBinding binding, FlowableProcessor<RowAction> processor) {
    super(binding);
    compositeDisposable = new CompositeDisposable();
    this.editText = binding.getRoot().findViewById(R.id.input_editText);
    this.inputLayout = binding.getRoot().findViewById(R.id.input_layout);
    this.description = binding.getRoot().findViewById(R.id.descriptionLabel);

    this.editText.setOnClickListener(view -> {
        editText.setEnabled(false);
        orgUnitDialog = new OrgUnitDialog()
                .setTitle(model.label())
                .setMultiSelection(false)
                .setPossitiveListener(data -> {
                    processor.onNext(RowAction.create(model.uid(), orgUnitDialog.getSelectedOrgUnit(), model.dataElement(), model.categoryOptionCombo(),model.catCombo(), model.row(), model.column()));
                    this.editText.setText(orgUnitDialog.getSelectedOrgUnitName());
                    orgUnitDialog.dismiss();
                    editText.setEnabled(true);
                })
                .setNegativeListener(data -> {
                    orgUnitDialog.dismiss();
                    editText.setEnabled(true);
                });
        if (!orgUnitDialog.isAdded())
            orgUnitDialog.show(fm, model.label());
    });
}
 
Example #8
Source File: GroupedRecyclerViewAdapter.java    From GroupedRecyclerViewAdapter with Apache License 2.0 6 votes vote down vote up
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    if (viewType == TYPE_EMPTY){
        return new BaseViewHolder(getEmptyView(parent));
    } else {
        if (mUseBinding) {
            ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mContext),
                    getLayoutId(mTempPosition, viewType), parent, false);
            return new BaseViewHolder(binding.getRoot());
        } else {
            View view = LayoutInflater.from(mContext).inflate(
                    getLayoutId(mTempPosition, viewType), parent, false);
            return new BaseViewHolder(view);
        }
    }
}
 
Example #9
Source File: OrgUnitRow.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NonNull
@Override
public OrgUnitHolder onCreate(@NonNull ViewGroup parent) {
    ViewDataBinding binding = DataBindingUtil.inflate(
            inflater,
            isBgTransparent ? R.layout.custom_text_view : R.layout.custom_text_view_accent,
            parent,
            false
    );
    binding.setVariable(BR.renderType, renderType);
    binding.executePendingBindings();

    binding.getRoot().findViewById(R.id.input_editText).setFocusable(false); //Makes editText
    binding.getRoot().findViewById(R.id.input_editText).setClickable(true);//  but clickable

    return new OrgUnitHolder(fm, binding, processor);
}
 
Example #10
Source File: FieldViewFactory.java    From ground-android with Apache License 2.0 5 votes vote down vote up
/**
 * Inflates the view, generates a new view model and binds to the {@link ViewDataBinding}.
 *
 * @param fieldType Type of the field
 * @param root Parent layout
 * @return {@link ViewDataBinding}
 */
ViewDataBinding addFieldView(Field.Type fieldType, LinearLayout root) {
  ViewDataBinding binding =
      DataBindingUtil.inflate(fragment.getLayoutInflater(), getLayoutId(fieldType), root, true);
  binding.setLifecycleOwner(fragment);
  binding.setVariable(BR.viewModel, viewModelFactory.create(getViewModelClass(fieldType)));
  assignGeneratedId(binding.getRoot());
  return binding;
}
 
Example #11
Source File: DateTimeRow.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NonNull
@Override
public DateTimeHolder onCreate(@NonNull ViewGroup parent) {

    ViewDataBinding binding;

    switch (viewType) {
        case TIME:
            binding = DataBindingUtil.inflate(inflater,
                    R.layout.form_time_text, parent, false);
            ((FormTimeTextBinding) binding).timeView.setIsBgTransparent(isBgTransparent);
            break;
        case DATE:
            binding = DataBindingUtil.inflate(inflater,
                    R.layout.form_date_text, parent, false);
            ((FormDateTextBinding) binding).dateView.setIsBgTransparent(isBgTransparent);
            break;
        case DATETIME:
        default:
            binding = DataBindingUtil.inflate(inflater,
                    R.layout.form_date_time_text, parent, false);
            ((FormDateTimeTextBinding) binding).dateTimeView.setIsBgTransparent(isBgTransparent);
            break;
    }

    return new DateTimeHolder(binding, processor, isSearchMode, currentSelection);
}
 
Example #12
Source File: FilterHolder.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
FilterHolder(@NonNull ViewDataBinding binding, ObservableField<Filters> openedFilter) {
    super(binding.getRoot());
    this.binding = binding;
    this.openFilter = openedFilter;
    this.filterArrow = binding.getRoot().findViewById(R.id.filterArrow);
    this.filterIcon = binding.getRoot().findViewById(R.id.filterIcon);
    this.filterTitle = binding.getRoot().findViewById(R.id.filterTitle);
    this.filterValues = binding.getRoot().findViewById(R.id.filterValues);
}
 
Example #13
Source File: EditObservationFragment.java    From ground-android with Apache License 2.0 5 votes vote down vote up
private static AbstractFieldViewModel getViewModel(ViewDataBinding binding) {
  if (binding == null) {
    return null;
  } else if (binding instanceof TextInputFieldBinding) {
    return ((TextInputFieldBinding) binding).getViewModel();
  } else if (binding instanceof MultipleChoiceInputFieldBinding) {
    return ((MultipleChoiceInputFieldBinding) binding).getViewModel();
  } else if (binding instanceof PhotoInputFieldBinding) {
    return ((PhotoInputFieldBinding) binding).getViewModel();
  } else {
    throw new IllegalArgumentException("Unknown binding type: " + binding.getClass());
  }
}
 
Example #14
Source File: EditObservationFragment.java    From ground-android with Apache License 2.0 5 votes vote down vote up
private void rebuildForm(Form form) {
  formLayout.removeAllViews();
  fieldViewModelList.clear();
  for (Element element : form.getElements()) {
    if (element.getType() == Type.FIELD) {
      Field field = element.getField();
      ViewDataBinding binding = fieldViewFactory.addFieldView(field.getType(), formLayout);
      addFieldViewModel(field, getViewModel(binding));
    } else {
      throw new IllegalArgumentException(element.getType() + " elements not yet supported");
    }
  }
}
 
Example #15
Source File: ViewModelBaseBindingFragment.java    From AndroidViewModel with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    getViewModelHelper().performBinding(this);
    final ViewDataBinding binding = getViewModelHelper().getBinding();
    if (binding != null) {
        return binding.getRoot();
    } else {
        throw new IllegalStateException("Binding cannot be null. Perform binding before calling getBinding()");
    }
}
 
Example #16
Source File: ViewModelHelper.java    From AndroidViewModel with Apache License 2.0 5 votes vote down vote up
public void performBinding(@NonNull final IView bindingView) {
    // skip if already create
    if (mBinding != null) {
        return;
    }

    // get ViewModelBinding config
    final ViewModelBindingConfig viewModelConfig = bindingView.getViewModelBindingConfig();
    // if fragment not providing ViewModelBindingConfig, do not perform binding operations
    if (viewModelConfig == null) {
        return;
    }

    // perform Data Binding initialization
    final ViewDataBinding viewDataBinding;
    if (bindingView instanceof Activity) {
        viewDataBinding = DataBindingUtil.setContentView(((Activity) bindingView), viewModelConfig.getLayoutResource());
    } else if (bindingView instanceof Fragment) {
        viewDataBinding = DataBindingUtil.inflate(LayoutInflater.from(viewModelConfig.getContext()), viewModelConfig.getLayoutResource(), null, false);
    } else {
        throw new IllegalArgumentException("View must be an instance of Activity or Fragment (support-v4).");
    }

    // bind all together
    if (!viewDataBinding.setVariable(viewModelConfig.getViewModelVariableName(), getViewModel())) {
        throw new IllegalArgumentException("Binding variable wasn't set successfully. Probably viewModelVariableName of your " +
                "ViewModelBindingConfig of " + bindingView.getClass().getSimpleName() + " doesn't match any variable in "
                + viewDataBinding.getClass().getSimpleName());
    }

    mBinding = viewDataBinding;
}
 
Example #17
Source File: ModelWithDataBindingWithoutDonothashBindingModel_.java    From epoxy with Apache License 2.0 5 votes vote down vote up
@Override
protected void setDataBindingVariables(ViewDataBinding binding) {
  if (!binding.setVariable(BR.stringValue, stringValue)) {
    throw new IllegalStateException("The attribute stringValue was defined in your data binding model (com.airbnb.epoxy.DataBindingEpoxyModel) but a data variable of that name was not found in the layout.");
  }
  if (!binding.setVariable(BR.clickListener, clickListener)) {
    throw new IllegalStateException("The attribute clickListener was defined in your data binding model (com.airbnb.epoxy.DataBindingEpoxyModel) but a data variable of that name was not found in the layout.");
  }
}
 
Example #18
Source File: ModelWithDataBindingWithoutDonothashBindingModel_.java    From epoxy with Apache License 2.0 5 votes vote down vote up
@Override
protected void setDataBindingVariables(ViewDataBinding binding, EpoxyModel previousModel) {
  if (!(previousModel instanceof ModelWithDataBindingWithoutDonothashBindingModel_)) {
    setDataBindingVariables(binding);
    return;
  }
  ModelWithDataBindingWithoutDonothashBindingModel_ that = (ModelWithDataBindingWithoutDonothashBindingModel_) previousModel;
  if ((stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null)) {
    binding.setVariable(BR.stringValue, stringValue);
  }
  if ((clickListener != null ? !clickListener.equals(that.clickListener) : that.clickListener != null)) {
    binding.setVariable(BR.clickListener, clickListener);
  }
}
 
Example #19
Source File: ModelWithDataBindingBindingModel_.java    From epoxy with Apache License 2.0 5 votes vote down vote up
@Override
protected void setDataBindingVariables(ViewDataBinding binding, EpoxyModel previousModel) {
  if (!(previousModel instanceof ModelWithDataBindingBindingModel_)) {
    setDataBindingVariables(binding);
    return;
  }
  ModelWithDataBindingBindingModel_ that = (ModelWithDataBindingBindingModel_) previousModel;
  if ((stringValue != null ? !stringValue.equals(that.stringValue) : that.stringValue != null)) {
    binding.setVariable(BR.stringValue, stringValue);
  }
}
 
Example #20
Source File: DataBindingEpoxyModel.java    From epoxy with Apache License 2.0 5 votes vote down vote up
@Override
protected View buildView(@NonNull ViewGroup parent) {
  LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
  ViewDataBinding binding = DataBindingUtil.inflate(layoutInflater, getViewType(), parent, false);
  View view = binding.getRoot();
  view.setTag(binding);
  return view;
}
 
Example #21
Source File: BindingFactory.java    From Aria with Apache License 2.0 5 votes vote down vote up
/**
 * 从其它组件中加载binding
 *
 * @param obj Module寄主
 * @param clazz 具体的Binding
 * @param <VB> ViewDataBinding
 */
private <VB extends ViewDataBinding> VB loadBind(Object obj, Class<VB> clazz) {
  VB vb = null;
  if (obj instanceof AbsActivity) {
    vb = (VB) ((AbsActivity) obj).getBinding();
  } else if (obj instanceof AbsFragment) {
    vb = (VB) ((AbsFragment) obj).getBinding();
  } else if (obj instanceof AbsDialogFragment) {
    vb = (VB) ((AbsDialogFragment) obj).getBinding();
  }
  mBindings.put(clazz.hashCode(), vb);
  return vb;
}
 
Example #22
Source File: BindingFactory.java    From Aria with Apache License 2.0 5 votes vote down vote up
/**
 * 获取Binding
 *
 * @param obj Module寄主
 */
public <VB extends ViewDataBinding> VB getBinding(Object obj, Class<VB> clazz) {
  VB vb = (VB) mBindings.get(clazz.hashCode());
  if (vb == null) {
    vb = loadBind(obj, clazz);
  }
  return vb;
}
 
Example #23
Source File: BaseDataBoundAdapter.java    From views-widgets-samples with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreBind(ViewDataBinding binding) {
    if (mRecyclerView == null || mRecyclerView.isComputingLayout()) {
        return true;
    }
    int childAdapterPosition = mRecyclerView.getChildAdapterPosition(binding.getRoot());
    if (childAdapterPosition == RecyclerView.NO_POSITION) {
        return true;
    }
    notifyItemChanged(childAdapterPosition, DB_PAYLOAD);
    return false;
}
 
Example #24
Source File: TeiProgramListAdapter.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NonNull
@Override
public TeiProgramListEnrollmentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    ViewDataBinding binding;

    switch (viewType) {
        case TeiProgramListItem.TeiProgramListItemViewType.ALL_PROGRAMS_DASHBOARD:
            binding = DataBindingUtil.inflate(inflater, R.layout.item_tei_all_programs_dashboard_title, parent, false);
            break;
        case TeiProgramListItem.TeiProgramListItemViewType.FIRST_TITLE:
            binding = DataBindingUtil.inflate(inflater, R.layout.item_tei_programs_active_title, parent, false);
            break;
        case TeiProgramListItem.TeiProgramListItemViewType.ACTIVE_ENROLLMENT:
            binding = DataBindingUtil.inflate(inflater, R.layout.item_tei_programs_enrollment, parent, false);
            break;
        case TeiProgramListItem.TeiProgramListItemViewType.PROGRAM:
            binding = DataBindingUtil.inflate(inflater, R.layout.item_tei_programs_programs, parent, false);
            break;
        case TeiProgramListItem.TeiProgramListItemViewType.SECOND_TITLE:
            binding = DataBindingUtil.inflate(inflater, R.layout.item_tei_programs_inactive_title, parent, false);
            break;
        case TeiProgramListItem.TeiProgramListItemViewType.INACTIVE_ENROLLMENT:
            binding = DataBindingUtil.inflate(inflater, R.layout.item_tei_programs_enrollment_inactive, parent, false);
            break;
        case TeiProgramListItem.TeiProgramListItemViewType.THIRD_TITLE:
            binding = DataBindingUtil.inflate(inflater, R.layout.item_tei_programs_to_enroll_title, parent, false);
            break;
        case TeiProgramListItem.TeiProgramListItemViewType.PROGRAMS_TO_ENROLL:
            binding = DataBindingUtil.inflate(inflater, R.layout.item_tei_programs_programs, parent, false);
            break;
        default:
            binding = DataBindingUtil.inflate(inflater, R.layout.item_tei_programs_enrollment, parent, false);
            break;
    }

    return new TeiProgramListEnrollmentViewHolder(binding);
}
 
Example #25
Source File: FragmentNovelSeries.java    From Pixiv-Shaft with MIT License 4 votes vote down vote up
@Override
public BaseAdapter<?, ? extends ViewDataBinding> adapter() {
    return new NAdapter(allItems, mContext, true);
}
 
Example #26
Source File: BaseMixtureDBAdapter.java    From RvHelper with Apache License 2.0 4 votes vote down vote up
@Override
public BaseBindViewHolder createCustomViewHolder(ViewGroup parent, int viewType) {
    ViewDataBinding viewDataBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), getLayoutRes(viewType),
            parent, false);
    return new BaseBindViewHolder<ViewDataBinding, T>(viewDataBinding);
}
 
Example #27
Source File: BaseDBAdapter.java    From RvHelper with Apache License 2.0 4 votes vote down vote up
@Override
public BaseBindViewHolder createCustomViewHolder(ViewGroup parent, int viewType) {
    ViewDataBinding viewDataBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), mLayoutRes, parent, false);
    return new BaseBindViewHolder<ViewDataBinding, T>(viewDataBinding);
}
 
Example #28
Source File: DataBindingEpoxyModel.java    From epoxy with Apache License 2.0 4 votes vote down vote up
@Override
protected void bindView(@NonNull View itemView) {
  dataBinding = (ViewDataBinding) itemView.getTag();
}
 
Example #29
Source File: DataBindingEpoxyModel.java    From epoxy with Apache License 2.0 4 votes vote down vote up
public ViewDataBinding getDataBinding() {
  return dataBinding;
}
 
Example #30
Source File: DataBindingEpoxyModel.java    From epoxy with Apache License 2.0 4 votes vote down vote up
protected void setDataBindingVariables(ViewDataBinding dataBinding, List<Object> payloads) {
  setDataBindingVariables(dataBinding);
}