/*
 * Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.gnd.ui.editobservation;

import com.google.android.gnd.ui.common.AbstractViewModel;

public class AbstractFieldViewModel extends AbstractViewModel {}

@@ -641,16 +641,282 @@
 ation;%0A%0A
+import android.content.res.Resources;%0Aimport androidx.lifecycle.MutableLiveData;%0Aimport com.google.android.gnd.GndApplication;%0Aimport com.google.android.gnd.R;%0Aimport com.google.android.gnd.model.form.Field;%0Aimport com.google.android.gnd.model.observation.Response;%0A
 import c
@@ -965,16 +965,44 @@
 ewModel;
+%0Aimport java8.util.Optional;
 %0A%0Apublic
@@ -1058,10 +1058,1154 @@
 wModel %7B
+%0A%0A  private final Resources resources;%0A  private final MutableLiveData%3CString%3E error = new MutableLiveData%3C%3E();%0A  private final MutableLiveData%3CString%3E responseValue = new MutableLiveData%3C%3E();%0A%0A  private Field field;%0A  private Optional%3CResponse%3E response;%0A%0A  public AbstractFieldViewModel(GndApplication application) %7B%0A    resources = application.getResources();%0A  %7D%0A%0A  public Field getField() %7B%0A    return field;%0A  %7D%0A%0A  public void setField(Field field) %7B%0A    this.field = field;%0A  %7D%0A%0A  public MutableLiveData%3CString%3E getResponseValue() %7B%0A    return responseValue;%0A  %7D%0A%0A  public Optional%3CResponse%3E getResponse() %7B%0A    return response;%0A  %7D%0A%0A  public void setResponse(Optional%3CResponse%3E response) %7B%0A    this.response = response;%0A    responseValue.setValue(response.map(r -%3E r.getDetailsText(field)).orElse(%22%22));%0A  %7D%0A%0A  public MutableLiveData%3CString%3E getError() %7B%0A    return error;%0A  %7D%0A%0A  public void setError(String error) %7B%0A    this.error.setValue(error);%0A  %7D%0A%0A  public void refreshError() %7B%0A    if (field.isRequired() && (response == null %7C%7C response.isEmpty())) %7B%0A      error.setValue(resources.getString(R.string.required_field));%0A    %7D%0A  %7D%0A
 %7D%0A

Add fields to AbstractFieldViewModel