Commit d03bb2de authored by rahadi's avatar rahadi

Moved hierarchy to RecyclerView, added save mechanism

parent 349ed645
......@@ -423,10 +423,21 @@ public class CapiFormFragment extends Fragment implements FormListDownloaderList
ArrayList<HashMap<String, String>> downloadedFilteredFormList = new ArrayList<>();
ArrayList<HashMap<String, String>> unDownloadedFilteredFormList = new ArrayList<>();
FormsDao formsDao = new FormsDao();
for (int idx = 0; idx < mFilteredFormList.size(); idx++) {
HashMap<String, String> item = mFilteredFormList.get(idx);
Cursor c = formsDao.getFormsCursor(FormsProviderAPI.FormsColumns.JR_FORM_ID + "=?",
new String[]{item.get(FORM_ID_KEY)});
c.moveToFirst();
if (item.get(HAS_BEEN_DOWNLOADED) != null && item.get(HAS_BEEN_DOWNLOADED).equals("true")) {
if (isFormInActiveSurvey(item)) downloadedFilteredFormList.add(item);
if (isFormInActiveSurvey(item)) {
item.put(FORM_TYPE_KEY, c.getString(c.getColumnIndex(FormsProviderAPI.FormsColumns.FORM_TYPE)));
downloadedFilteredFormList.add(item);
}
} else {
if (isLocalFormSuperseded(item.get(FORM_ID_KEY), item.get(FORM_VERSION_KEY))) {
//need to downloaded
......@@ -435,9 +446,13 @@ public class CapiFormFragment extends Fragment implements FormListDownloaderList
} else {
//has been downloaded
item.put(HAS_BEEN_DOWNLOADED, "true");
item.put(FORM_TYPE_KEY, c.getString(c.getColumnIndex(FormsProviderAPI.FormsColumns.FORM_TYPE)));
if (isFormInActiveSurvey(item)) downloadedFilteredFormList.add(item);
}
}
c.close();
}
downloadedFilteredFormList.addAll(unDownloadedFilteredFormList);
......@@ -497,10 +512,10 @@ public class CapiFormFragment extends Fragment implements FormListDownloaderList
item.put(FORM_ID_KEY, details.formID);
item.put(FORM_VERSION_KEY, details.formVersion);
FormsDao formsDao = new FormsDao();
Cursor c = formsDao.getFormsCursor(FormsProviderAPI.FormsColumns.JR_FORM_ID + "=?",
new String[]{details.formID});
item.put(FORM_TYPE_KEY, c.getString(c.getColumnIndex(FormsProviderAPI.FormsColumns.FORM_TYPE)));
// FormsDao formsDao = new FormsDao();
// Cursor c = formsDao.getFormsCursor(FormsProviderAPI.FormsColumns.JR_FORM_ID + "=?",
// new String[]{details.formID});
// item.put(FORM_TYPE_KEY, c.getString(c.getColumnIndex(FormsProviderAPI.FormsColumns.FORM_TYPE)));
if (!mFormListContain(details.formName)) {
// Insert the new form in alphabetical order.
......
......@@ -17,7 +17,6 @@ import java.util.List;
import id.ac.stis.capi.R;
import id.ac.stis.capi.collectiva.preferences.Constants;
import id.ac.stis.capi.lessthink.fragments.FormEntryDialogFragment;
import id.ac.stis.capi.lessthink.fragments.FormEntryRVDialogFragment;
import id.ac.stis.capi.lessthink.listeners.OnTableAddButtonClickListener;
import id.ac.stis.capi.lessthink.models.FormLabels;
import id.ac.stis.capi.lessthink.models.InstanceValues;
......@@ -44,7 +43,7 @@ public class ListingInstanceActivity extends AppCompatActivity {
private TableFooterView tableFooterView;
private String formId, formName;
// private FormEntryDialogFragment entryDialogFragment;
private FormEntryRVDialogFragment entryDialogFragment;
private FormEntryDialogFragment entryDialogFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -96,7 +95,7 @@ public class ListingInstanceActivity extends AppCompatActivity {
String instanceUuid = view.getTag().toString();
// entryDialogFragment = FormEntryDialogFragment.newInstance(instanceUuid,
// FormEntryDialogFragment.MODE_EDIT, false);
entryDialogFragment = FormEntryRVDialogFragment.newInstance(instanceUuid,
entryDialogFragment = FormEntryDialogFragment.newInstance(instanceUuid,
FormEntryDialogFragment.MODE_EDIT, false);
entryDialogFragment.show(getSupportFragmentManager(), instanceUuid);
//
......
package id.ac.stis.capi.lessthink.adapters;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import org.javarosa.core.model.FormIndex;
import java.util.List;
import java.io.InvalidObjectException;
import java.util.ArrayList;
import id.ac.stis.capi.lessthink.listeners.OnChangeListener;
import id.ac.stis.capi.lessthink.models.BaseHierarchy;
import id.ac.stis.capi.lessthink.models.PromptHierarchy;
import id.ac.stis.capi.lessthink.utils.ViewUtils;
import id.ac.stis.capi.odk.widgets.QuestionWidget;
import timber.log.Timber;
/**
......@@ -21,72 +16,70 @@ import timber.log.Timber;
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class HierarchyAdapter extends BaseAdapter implements OnChangeListener {
public class HierarchyAdapter extends RecyclerView.Adapter<HierarchyAdapter.ViewHolder> {
private ArrayList<BaseHierarchy> hierarchies;
private OnChangeListener onChangeListener;
private List<BaseHierarchy> hierarchies;
public HierarchyAdapter(ArrayList<BaseHierarchy> hierarchies) {
public HierarchyAdapter(List<BaseHierarchy> hierarchies) {
this.hierarchies = hierarchies;
}
public void setOnChangeListener(OnChangeListener onChangeListener) {
this.onChangeListener = onChangeListener;
public void setHierarchies(List<BaseHierarchy> hierarchies) {
this.hierarchies = hierarchies;
}
@Override
public int getCount() {
return hierarchies.size();
public BaseHierarchy getItem(int position) {
return hierarchies.get(position);
}
@Override
public Object getItem(int position) {
return hierarchies.get(position);
public int getItemViewType(int position) {
return position;
}
@NonNull
@Override
public long getItemId(int position) {
return 0;
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Timber.d("Creating with type %s", viewType);
// BaseHierarchy hierarchy = hierarchies.get(viewType);
// if (hierarchy instanceof PromptHierarchy) {
// ((PromptHierarchy) hierarchy).setOnChangeListener(onChangeListener);
// return new PromptViewHolder(hierarchy.getView());
// } else if (hierarchy instanceof CaptionHierarchy) {
// return new CaptionViewHolder(hierarchy.getView());
// } else {
// // Should not be happening
// return new ViewHolder(hierarchy.getView());
// }
return new ViewHolder(new LinearLayout(parent.getContext()));
}
@Override
public boolean isEnabled(int position) {
return false;
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
// if (holder instanceof PromptViewHolder) {
// PromptHierarchy hierarchy = (PromptHierarchy) hierarchies.get(position);
// }
holder.bind(hierarchies.get(position));
}
@Override
public View getView(final int position, View view, final ViewGroup parent) {
BaseHierarchy hierarchy = hierarchies.get(position);
View v = hierarchy.getView();
if (hierarchy instanceof PromptHierarchy) {
final QuestionWidget widget = ((PromptHierarchy) hierarchy).getWidget();
// widget.setOnFocusChangeListener(new View.OnFocusChangeListener() {
// @Override
// public void onFocusChange(View v, boolean hasFocus) {
// if (hasFocus) {
// widget.setFocus(parent.getContext());
// }
// }
// });
try {
ViewUtils.setChangeListener(widget, ((PromptHierarchy) hierarchy).getPrompt().getIndex(),
this);
} catch (InvalidObjectException e) {
Timber.e(e);
}
public int getItemCount() {
return hierarchies.size();
}
}
class ViewHolder extends RecyclerView.ViewHolder {
return v;
}
public ViewHolder(View itemView) {
super(itemView);
}
@Override
public void onChange(QuestionWidget questionWidget, FormIndex formIndex) {
if (onChangeListener != null) {
onChangeListener.onChange(questionWidget, formIndex);
void bind(BaseHierarchy hierarchy) {
ViewGroup parent = (ViewGroup) itemView;
if (parent != null) {
parent.removeAllViews();
parent.addView(hierarchy.getView());
}
}
}
}
\ No newline at end of file
}
package id.ac.stis.capi.lessthink.adapters;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import java.util.List;
import id.ac.stis.capi.lessthink.models.BaseHierarchy;
import timber.log.Timber;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class HierarchyRVAdapter extends RecyclerView.Adapter<HierarchyRVAdapter.ViewHolder> {
private List<BaseHierarchy> hierarchies;
public HierarchyRVAdapter(List<BaseHierarchy> hierarchies) {
this.hierarchies = hierarchies;
}
public void setHierarchies(List<BaseHierarchy> hierarchies) {
this.hierarchies = hierarchies;
}
public BaseHierarchy getItem(int position) {
return hierarchies.get(position);
}
@Override
public int getItemViewType(int position) {
return position;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Timber.d("Creating with type %s", viewType);
// BaseHierarchy hierarchy = hierarchies.get(viewType);
// if (hierarchy instanceof PromptHierarchy) {
// ((PromptHierarchy) hierarchy).setOnChangeListener(onChangeListener);
// return new PromptViewHolder(hierarchy.getView());
// } else if (hierarchy instanceof CaptionHierarchy) {
// return new CaptionViewHolder(hierarchy.getView());
// } else {
// // Should not be happening
// return new ViewHolder(hierarchy.getView());
// }
return new ViewHolder(new LinearLayout(parent.getContext()));
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
// if (holder instanceof PromptViewHolder) {
// PromptHierarchy hierarchy = (PromptHierarchy) hierarchies.get(position);
// }
holder.bind(hierarchies.get(position));
}
@Override
public int getItemCount() {
return hierarchies.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View itemView) {
super(itemView);
}
void bind(BaseHierarchy hierarchy) {
ViewGroup parent = (ViewGroup) itemView;
if (parent != null) {
parent.removeAllViews();
parent.addView(hierarchy.getView());
}
}
}
}
......@@ -2,29 +2,42 @@ package id.ac.stis.capi.lessthink.fragments;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ContentUris;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import org.javarosa.core.model.Constants;
import org.javarosa.core.model.FormIndex;
import org.javarosa.core.model.data.IAnswerData;
import org.javarosa.core.model.instance.TreeReference;
import org.javarosa.form.api.FormEntryController;
import org.javarosa.form.api.FormEntryPrompt;
import java.io.File;
import java.io.InvalidObjectException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
......@@ -34,33 +47,73 @@ import java.util.Set;
import id.ac.stis.capi.R;
import id.ac.stis.capi.lessthink.adapters.HierarchyAdapter;
import id.ac.stis.capi.lessthink.listeners.OnChangeListener;
import id.ac.stis.capi.lessthink.listeners.OnButtonHierarchyClickListener;
import id.ac.stis.capi.lessthink.listeners.OnAnswerChangedListener;
import id.ac.stis.capi.lessthink.listeners.OnEditRutaSavedListener;
import id.ac.stis.capi.lessthink.models.BaseHierarchy;
import id.ac.stis.capi.lessthink.models.ButtonHierarchy;
import id.ac.stis.capi.lessthink.models.PromptHierarchy;
import id.ac.stis.capi.lessthink.utils.ViewUtils;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.odk.dao.FormsDao;
import id.ac.stis.capi.odk.dao.InstancesDao;
import id.ac.stis.capi.odk.dto.Form;
import id.ac.stis.capi.odk.dto.Instance;
import id.ac.stis.capi.odk.exception.GDriveConnectionException;
import id.ac.stis.capi.odk.exception.JavaRosaException;
import id.ac.stis.capi.odk.external.ExternalAppsUtils;
import id.ac.stis.capi.odk.listeners.FormLoaderListener;
import id.ac.stis.capi.odk.listeners.FormSavedListener;
import id.ac.stis.capi.odk.logic.FailedConstraint;
import id.ac.stis.capi.odk.logic.FormController;
import id.ac.stis.capi.odk.provider.FormsProviderAPI;
import id.ac.stis.capi.odk.provider.InstanceProviderAPI;
import id.ac.stis.capi.odk.tasks.FormLoaderTask;
import id.ac.stis.capi.odk.tasks.SaveResult;
import id.ac.stis.capi.odk.tasks.SaveToDiskTask;
import id.ac.stis.capi.odk.utilities.FileUtils;
import id.ac.stis.capi.odk.utilities.MediaUtils;
import id.ac.stis.capi.odk.utilities.TimerLogger;
import id.ac.stis.capi.odk.utilities.ToastUtils;
import id.ac.stis.capi.odk.widgets.IBinaryWidget;
import id.ac.stis.capi.odk.widgets.QuestionWidget;
import timber.log.Timber;
import static android.app.Activity.RESULT_CANCELED;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.ALIGNED_IMAGE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.ANNOTATE_IMAGE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.AUDIO_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.AUDIO_CHOOSER;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.BARCODE_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.BEARING_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.BEARING_RESULT;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.DRAW_IMAGE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.EX_DECIMAL_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.EX_GROUP_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.EX_INT_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.EX_STRING_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.GEOSHAPE_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.GEOSHAPE_RESULTS;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.GEOTRACE_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.GEOTRACE_RESULTS;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.HIERARCHY_ACTIVITY;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.IMAGE_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.IMAGE_CHOOSER;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.LOCATION_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.LOCATION_RESULT;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.LOKASI_ASLI;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.OSM_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.SIGNATURE_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.VIDEO_CAPTURE;
import static id.ac.stis.capi.odk.activities.FormEntryActivity.VIDEO_CHOOSER;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class FormEntryDialogFragment extends DialogFragment implements FormLoaderListener, OnChangeListener {
public class FormEntryDialogFragment extends DialogFragment implements FormLoaderListener, OnAnswerChangedListener,
OnButtonHierarchyClickListener, FormSavedListener {
public static final int MODE_EDIT = 0;
public static final int MODE_INSERT = 1;
......@@ -69,10 +122,18 @@ public class FormEntryDialogFragment extends DialogFragment implements FormLoade
private static final int DO_NOT_EVALUATE_CONSTRAINTS = 2;
private static final int EVALUATE_CONSTRAINTS_BUT_CAN_SKIP = 3;
private static final int PROGRESS_DIALOG = 1;
private static final int SAVING_DIALOG = 2;
private static final int SAVING_IMAGE_DIALOG = 3;
private static final String INSTANCE_UUID = "instance_uuid";
private static final String FLAG_FROM_DETAIL = "from_detail";
private static final String VIEW_MODE = "viewMode";
private final Object saveDialogLock = new Object();
private Uri instanceUri;
private SaveToDiskTask saveToDiskTask;
private boolean fromDetail;
private int viewMode, locationState;
private String instanceUuid, formPath;
......@@ -82,9 +143,10 @@ public class FormEntryDialogFragment extends DialogFragment implements FormLoade
private InstancesDao instancesDao;
// private LinearLayout questionContainer;
private TimerLogger timerLogger;
private ListView mainContent;
private RecyclerView mainContent;
private HierarchyAdapter adapter;
private ArrayList<BaseHierarchy> hierarchies, newHierarchies;
private ArrayList<BaseHierarchy> hierarchies;
private ProgressDialog progressDialog;
public FormEntryDialogFragment() {
// Required empty public constructor
......@@ -124,6 +186,9 @@ public class FormEntryDialogFragment extends DialogFragment implements FormLoade
String instancePath = instance.getInstanceFilePath();
String formId = instance.getJrFormId();
instanceUri = ContentUris.withAppendedId(InstanceProviderAPI.InstanceColumns.CONTENT_URI,
instance.getIdInstance());
formsDao = new FormsDao();
Cursor c1 = formsDao.getFormsCursorForFormId(formId);
......@@ -162,12 +227,22 @@ public class FormEntryDialogFragment extends DialogFragment implements FormLoade
// questionContainer = v.findViewById(R.id.question_container);
mainContent = v.findViewById(R.id.question_container);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
mainContent.setLayoutManager(layoutManager);
hierarchies = new ArrayList<>();
adapter = new HierarchyAdapter(hierarchies);
mainContent.setAdapter(adapter);
builder.setView(v).setPositiveButton(getString(R.string.save_all_answers), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (null != onEditRutaSavedListener) {
onEditRutaSavedListener.onEditRutaSaved();
}
saveDataToDisk();
}
});
......@@ -185,130 +260,34 @@ public class FormEntryDialogFragment extends DialogFragment implements FormLoade
}
private void initializeView() {
// questionWidgets = new HashMap<>();
FormController controller = Collect.getInstance().getFormController();
hierarchies = controller.getAllQuestions(getContext());
adapter = new HierarchyAdapter(hierarchies);
mainContent.setAdapter(adapter);
mainContent.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == SCROLL_STATE_IDLE) {
view.setFocusable(true);
} else {
view.setFocusable(false);
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
adapter.setOnChangeListener(this);
setPositiveButtonState(saveAnswers(false));
// adapter.notifyDataSetChanged();
// populateQuestionWidgets(hierarchies, questionContainer);
refreshView();
setPositiveButtonState(validateAnswers(false));
}
private void refreshView() {
FormController controller = Collect.getInstance().getFormController();
newHierarchies = controller.getAllQuestions(getContext());
hierarchies = controller.getAllQuestions(getActivity());
setupChangeListener();
hierarchies.clear();
hierarchies.addAll(newHierarchies);
adapter.setHierarchies(hierarchies);
adapter.notifyDataSetChanged();
}
// private void refreshView(FormIndex index) {
// FormController controller = Collect.getInstance().getFormController();
// newHierarchies = controller.getQuestionsAfter(index);
//
// boolean hit = false;
// Iterator<Map.Entry<String, QuestionWidget>> iter = questionWidgets.entrySet().iterator();
// while (iter.hasNext()) {
// Map.Entry<String, QuestionWidget> entry = iter.next();
// if (!hit) {
// hit = entry.getKey().equals(index.getReference().toString());
// } else {
//// questionContainer.removeView(getTextView().findViewWithTag(entry.getKey()));
// ViewGroup parent = (ViewGroup) entry.getValue().getParent();
// while (parent != questionContainer) {
// parent.removeView(parent.findViewWithTag(entry.getKey()));
// parent = (ViewGroup) parent.getParent();
// }
// iter.remove();
// }
// }
// populateQuestionWidgetsAfter(prompts, questionContainer);
// }
// private void populateQuestionWidgets(ArrayList<PromptDepHierarchy> prompts, LinearLayout container) {
//
// for (PromptDepHierarchy prompt : prompts) {
// FormEntryPrompt entryPrompt = prompt.getPrompt();
// if (prompt.getPrompt() != null) {
// QuestionWidget widget = WidgetFactory.createWidgetFromPrompt(entryPrompt, getContext(), false);
// widget.setTag(entryPrompt.getIndex().getReference().toString());
//
// container.addView(widget);
// questionWidgets.put(entryPrompt.getIndex().getReference().toString(), widget);
//
// try {
// ViewUtils.setChangeListener(widget, entryPrompt.getIndex(), this);
// } catch (InvalidObjectException e) {
// Timber.e(e);
// }
// } else {
// LinearLayout linearLayout = new LinearLayout(getContext());
// linearLayout.setOrientation(LinearLayout.VERTICAL);
// linearLayout.setPadding(32, 32, 32, 32);
//
// TextView textView = new TextView(getContext());
// textView.setText(prompt.getCaption().getLongText());
// linearLayout.addView(textView);
//
// populateQuestionWidgets(prompt.getChildren(), linearLayout);
// container.addView(linearLayout);
// }
// }
// }
//
// private void populateQuestionWidgetsAfter(ArrayList<PromptDepHierarchy> prompts, LinearLayout container) {
// for (PromptDepHierarchy prompt : prompts) {
// FormEntryPrompt entryPrompt = prompt.getPrompt();
// if (prompt.getPrompt() != null) {
// QuestionWidget widget = WidgetFactory.createWidgetFromPrompt(entryPrompt, getContext(), false);
// widget.setTag(entryPrompt.getIndex());
//
// container.addView(widget);
// questionWidgets.put(entryPrompt.getIndex().getReference().toString(), widget);
//
// try {
// ViewUtils.setChangeListener(widget, entryPrompt.getIndex(), this);
// } catch (InvalidObjectException e) {
// Timber.e(e);
// }
// } else {
// LinearLayout linearLayout = new LinearLayout(getContext());
// linearLayout.setOrientation(LinearLayout.VERTICAL);
// linearLayout.setPadding(16, 16, 16, 16);
//
// TextView textView = new TextView(getContext());
// textView.setText(prompt.getCaption().getLongText());
// linearLayout.addView(textView);
//
// populateQuestionWidgetsAfter(prompt.getChildren(), linearLayout);
// container.addView(linearLayout);
// }
// }
// }
void setupChangeListener() {
for (BaseHierarchy hierarchy : hierarchies) {
if (hierarchy instanceof PromptHierarchy) {
try {
ViewUtils.setChangeListener(((PromptHierarchy) hierarchy).getWidget(),
((PromptHierarchy) hierarchy).getPrompt().getIndex(), this);
} catch (InvalidObjectException e) {
e.printStackTrace();
}
} else if (hierarchy instanceof ButtonHierarchy) {
((ButtonHierarchy) hierarchy).setOnButtonHierarchyClickListener(this);
}
}
}
private void setTimerLogger(FormController formController) {
......@@ -318,9 +297,39 @@ public class FormEntryDialogFragment extends DialogFragment implements FormLoade
formController);
}
private boolean saveDataToDisk() {
// save current answer
if (!validateAnswers(true)) {
ToastUtils.showShortToast(R.string.data_saved_error);
return false;
}
synchronized (saveDialogLock) {
saveToDiskTask = new SaveToDiskTask(instanceUri, false, true, null);
saveToDiskTask.setFormSavedListener(this);
showProgressDialog(SAVING_DIALOG);
// show dialog before we execute...
saveToDiskTask.execute();
}
return true;
}
private void cancelSaveToDiskTask() {
synchronized (saveDialogLock) {
if (saveToDiskTask != null) {
saveToDiskTask.setFormSavedListener(null);
boolean cancelled = saveToDiskTask.cancel(true);
Timber.w("Cancelled SaveToDiskTask! (%s)", cancelled);
saveToDiskTask = null;
}
}
}
private void setPositiveButtonState(boolean enabled) {