Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #470 from fieldsight/466/feature-open-form-with-no…
Browse files Browse the repository at this point in the history
…-version

466/feature open form with no version
  • Loading branch information
yubarajpoudel authored Nov 6, 2019
2 parents 739a6e9 + 6835c07 commit e74fae7
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 63 deletions.
2 changes: 1 addition & 1 deletion collect_app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def mapboxToken = secrets.getProperty('MAPBOX_ACCESS_TOKEN', getProps("mapbox"))

def versionMajor = 3
def versionMinor = 2
def versionPatch = 10
def versionPatch = 11

android {
compileSdkVersion(28)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
Expand All @@ -26,7 +25,7 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.bcss.collect.android.R;;
import org.bcss.collect.android.R;
import org.fieldsight.naxa.BaseActivity;
import org.fieldsight.naxa.common.Constant;
import org.fieldsight.naxa.common.DialogFactory;
Expand All @@ -48,6 +47,7 @@
import org.fieldsight.naxa.site.db.SiteLocalSource;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.dao.FormsDao;
import org.odk.collect.android.dto.Instance;
import org.odk.collect.android.listeners.DownloadFormsTaskListener;
import org.odk.collect.android.logic.FormDetails;
import org.odk.collect.android.provider.FormsProviderAPI;
Expand All @@ -63,14 +63,15 @@

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Function;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;

;


public class FlaggedInstanceActivity extends BaseActivity implements View.OnClickListener, NotificationImageAdapter.OnItemClickListener {

Expand Down Expand Up @@ -298,7 +299,7 @@ protected long getFormId(String jrFormId) throws CursorIndexOutOfBoundsException
}


protected void fillODKForm(String idString) {
protected void createNewSubmission(String idString) {
try {
long formId = getFormId(idString);
Uri formUri = ContentUris.withAppendedId(FormsProviderAPI.FormsColumns.CONTENT_URI, formId);
Expand Down Expand Up @@ -404,7 +405,7 @@ private void showAskNewSubmissionConsentDialog(String message) {
.setNegativeButton(R.string.dialog_action_make_new_submission, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
fillODKForm(loadedFieldSightNotification.getIdString());
createNewSubmission(loadedFieldSightNotification.getIdString());
}
})
.setNeutralButton(R.string.dialog_action_dismiss, null)
Expand Down Expand Up @@ -580,25 +581,20 @@ public ObservableSource<String> apply(Map.Entry<String, String> filenameFilePath
});


Observable<Uri> instanceObservable = InstanceRemoteSource.getInstanceRemoteSource()
Observable<Instance> instanceObservable = InstanceRemoteSource.getInstanceRemoteSource()
.downloadInstances(notification, nameAndPath);

Observable.concat(attachedMediaObservable, instanceObservable)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Comparable<? extends Comparable<?>>>() {
@Override
public void onSubscribe(Disposable d) {
changeDialogMsg("Downloading filled form");
}

.subscribe(new DisposableObserver<Object>() {
@Override
public void onNext(Comparable<? extends Comparable<?>> comparable) {
if (comparable instanceof Uri) {
public void onNext(Object comparable) {
if (comparable instanceof Instance) {
hideDialog();
Uri instanceUri = (Uri) comparable;
loadInstance(instanceUri);
finish();
Instance instance = (Instance) comparable;
loadSavedInstance(instance.getFieldSightInstanceId(), instance.getJrFormId());

}
}

Expand All @@ -623,7 +619,6 @@ public void onComplete() {
hideDialog();
}
});

}

private void showErrorDialog(String errorMessage) {
Expand All @@ -634,8 +629,6 @@ public void run() {
errorDialog.show();
}
});


}


Expand All @@ -649,8 +642,6 @@ private void initrecyclerViewImages(List<NotificationImage> framelist) {
RecyclerView.VERTICAL, false));

notificationImageAdapter.setOnItemClickListener(this);
// recyclerViewImages.addItemDecoration(new LinePagerIndicatorDecoration());

recyclerViewImages.setNestedScrollingEnabled(false);
}

Expand Down Expand Up @@ -710,10 +701,26 @@ private void loadSavedInstance(String fsInstanceId, String jrFormId) {
selectionArgs, null);

int count = cursorInstanceForm.getCount();
List<Instance> instances = instancesDao.getInstancesFromCursor(cursorInstanceForm);

if (count == 1) {
openSavedForm(cursorInstanceForm);
Instance instance = instances.get(0);
boolean doesVersionMatch = hasFormVersion();
if (doesVersionMatch) {
openSavedForm(instance);
} else {
hideDialog();
DialogFactory.createActionDialog(FlaggedInstanceActivity.this,
getString(R.string.msg_matching_form_verion_not_found),
getString(R.string.msg_missing_form_version))
.setPositiveButton(R.string.msg_yes_open_missing_version, (dialogInterface, i)
-> openSavedForm(instance))
.setNegativeButton(R.string.msg_no_open_missing_version, (dialogInterface, i)
-> createNewSubmission(loadedFieldSightNotification.getIdString()))
.show();
}
} else {
fillODKForm(jrFormId);
createNewSubmission(jrFormId);
}
} catch (NullPointerException | CursorIndexOutOfBoundsException e) {
ToastUtils.showLongToast(getString(R.string.dialog_unexpected_error_title));
Expand All @@ -724,17 +731,13 @@ private void loadSavedInstance(String fsInstanceId, String jrFormId) {
}
}

private void openSavedForm(Cursor cursorInstanceForm) {
private void openSavedForm(Instance cursorInstanceForm) {

Toast.makeText(context, "Opening saved form.", Toast.LENGTH_LONG).show();

cursorInstanceForm.moveToLast();
long idFormsTable = Long.parseLong(cursorInstanceForm.getString(cursorInstanceForm.getColumnIndex(InstanceProviderAPI.InstanceColumns._ID)));
Log.d(TAG, "Opening saved form with _ID" + idFormsTable);

Uri instanceUri =
ContentUris.withAppendedId(InstanceProviderAPI.InstanceColumns.CONTENT_URI,
idFormsTable);
cursorInstanceForm.getDatabaseId());


String action = getIntent().getAction();
Expand All @@ -745,9 +748,9 @@ private void openSavedForm(Cursor cursorInstanceForm) {
// the form can be edited if it is incomplete or if, when it was
// marked as complete, it was determined that it could be edited
// later.
String status = cursorInstanceForm.getString(cursorInstanceForm.getColumnIndex(InstanceProviderAPI.InstanceColumns.STATUS));
String status = cursorInstanceForm.getStatus();
String strCanEditWhenComplete =
cursorInstanceForm.getString(cursorInstanceForm.getColumnIndex(InstanceProviderAPI.InstanceColumns.CAN_EDIT_WHEN_COMPLETE));
cursorInstanceForm.getCanEditWhenComplete();

boolean canEdit = status.equals(InstanceProviderAPI.STATUS_INCOMPLETE)
|| Boolean.parseBoolean(strCanEditWhenComplete);
Expand All @@ -756,13 +759,8 @@ private void openSavedForm(Cursor cursorInstanceForm) {
return;
}

// caller wants to view/edit a form, so launch FormEntryActivity
//send the slected id to the upload button
//Susan

Long selectedFormId = cursorInstanceForm.getLong(cursorInstanceForm.getColumnIndex(InstanceProviderAPI.InstanceColumns._ID));
Intent toEdit = new Intent(Intent.ACTION_EDIT, instanceUri);
toEdit.putExtra("EditedFormID", selectedFormId);
toEdit.putExtra("EditedFormID", cursorInstanceForm.getDatabaseId());
startActivity(toEdit);
}
finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static synchronized InstanceRemoteSource getInstanceRemoteSource() {
}


Observable<Uri> downloadInstances(FieldSightNotification fieldSightNotification, String[] nameAndPath) {
Observable<Instance> downloadInstances(FieldSightNotification fieldSightNotification, String[] nameAndPath) {
String downloadUrl = String.format(FieldSightUserSession.getServerUrl(Collect.getInstance()) + APIEndpoint.GET_INSTANCE_XML + "/%s", fieldSightNotification.getFormSubmissionId());
return downloadInstance(mapNotificationToInstance(fieldSightNotification), downloadUrl, nameAndPath);
}
Expand All @@ -61,11 +61,11 @@ String[] getNameAndPath(String instanceName) {
return new String[]{formattedInstanceName.concat(".xml"), pathToDownload};
}

private Observable<Uri> downloadInstance(Instance.Builder instance, String downloadUrl, String[] nameAndPath) {
private Observable<Instance> downloadInstance(Instance.Builder instance, String downloadUrl, String[] nameAndPath) {
Timber.i("Downloading filled form from %s for %s", downloadUrl, nameAndPath[0]);

return Observable.just(instance)
.flatMap((Function<Instance.Builder, ObservableSource<Uri>>) instance1 -> {
.flatMap((Function<Instance.Builder, ObservableSource<Instance>>) instance1 -> {

String instanceName = nameAndPath[0];
String pathToDownload = nameAndPath[1];
Expand All @@ -84,10 +84,15 @@ public void accept(Throwable throwable) throws Exception {

}
})
.map(path -> {
path = path.replace("file://", "");
instance.instanceFilePath(path);
return saveInstance(instance.build());
.map(new Function<String, Instance>() {
@Override
public Instance apply(String path) throws Exception {
path = path.replace("file://", "");
instance.instanceFilePath(path);
saveInstance(instance.build());
return instance.build();
}

});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ public static void startWithSurveyForm(Context context, Project project) {
context.startActivity(intent);
}

public static void startFlaggedForm(Context context, String type) {
public static void startFlaggedForm(Context context, String type, Project project) {
Intent intent = new Intent(context, FragmentHostActivity.class);
intent.putExtra(EXTRA_MESSAGE, type);
intent.putExtra(EXTRA_PROJECT, project);
context.startActivity(intent);
}

Expand Down Expand Up @@ -110,7 +111,7 @@ protected void onCreate(Bundle savedInstanceState) {


if (openSubmissionScreen) {
fragment = FormsStateFragment.newInstance(extraMessage);
fragment = FormsStateFragment.newInstance(extraMessage, project);
} else if (openSurveyForm) {

fragment = FieldSightFormListFragment.newInstance(Constant.FormType.SURVEY, null, project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ private void handleNavDrawerClicks(int id) {
startActivity(new Intent(this, org.fieldsight.naxa.preferences.SettingsActivity.class));
break;
case R.id.nav_flagged_form:
FragmentHostActivity.startFlaggedForm(this, "Flagged");
FragmentHostActivity.startFlaggedForm(this, "Flagged",loadedProject);
break;
case R.id.nav_rejected_form:
FragmentHostActivity.startFlaggedForm(this, "Rejected");
FragmentHostActivity.startFlaggedForm(this, "Rejected",loadedProject);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import org.bcss.collect.android.R;;
import org.bcss.collect.android.R;
import org.fieldsight.naxa.login.model.Project;

import butterknife.BindView;
import butterknife.ButterKnife;
import timber.log.Timber;

;

class ProjectViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.primary_text)
TextView primaryText;
Expand Down Expand Up @@ -48,12 +50,12 @@ public ProjectViewHolder(@NonNull View itemView) {

void bindView(Project project, boolean allTrue) {
primaryText.setText(project.getName());
textView.setText(String.format("A PROJECT by %s", project.getOrganizationName()));
textView.setText(String.format("A project by %s", project.getOrganizationName()));
tvSyncedDate.setText(project.getStatusMessage());
chkbxSync.setChecked(project.isChecked());
chkbxSync.setVisibility(allTrue ? View.VISIBLE : View.GONE);
// imageView.setImageResource(PROJECT.isSynced() ? R.drawable.ic_action_check : android.R.drawable.stat_sys_download_done);
Timber.i("PROJECT image = %s", project.getUrl());
Timber.i("project image = %s", project.getUrl());
Glide.with(itemView.getContext()).load(project.getUrl()).apply(RequestOptions.circleCropTransform()).into(ivThumbnail);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.fieldsight.naxa.data.FieldSightNotification;
import org.fieldsight.naxa.data.FieldSightNotificationBuilder;
import org.fieldsight.naxa.flagform.FlaggedInstanceActivity;
import org.fieldsight.naxa.login.model.Project;
import org.fieldsight.naxa.network.APIEndpoint;
import org.fieldsight.naxa.network.ServiceGenerator;
import org.fieldsight.naxa.v3.FormState;
Expand All @@ -40,8 +41,10 @@
import io.reactivex.functions.Predicate;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import timber.log.Timber;

import static org.fieldsight.naxa.common.Constant.EXTRA_MESSAGE;
import static org.fieldsight.naxa.common.Constant.EXTRA_OBJECT;
import static org.fieldsight.naxa.common.Constant.FormStatus.FLAGGED;

public class FormsStateFragment extends Fragment {
Expand All @@ -52,12 +55,14 @@ public class FormsStateFragment extends Fragment {
private View emptyLayout;
private BaseRecyclerViewAdapter<FormState, FieldSightFormStateVH> adapter;
private String submissionStatus;
private Project project;
private String url = APIEndpoint.V3.GET_MY_FLAGGED_SUBMISSIONS;

public static FormsStateFragment newInstance(String type) {
public static FormsStateFragment newInstance(String type, Project project) {
FormsStateFragment fragment = new FormsStateFragment();
Bundle bundle = new Bundle();
bundle.putString(EXTRA_MESSAGE, type);
bundle.putParcelable(EXTRA_OBJECT, project);
fragment.setArguments(bundle);
return fragment;
}
Expand All @@ -69,6 +74,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
savedInstanceState) {
View rootView = inflater.inflate(R.layout.fieldsight_list_fragment, container, false);
submissionStatus = getArguments().getString(EXTRA_MESSAGE);
project = getArguments().getParcelable(EXTRA_OBJECT);
bindUI(rootView);

return rootView;
Expand Down Expand Up @@ -149,17 +155,23 @@ private Single<List<FormState>> getFormUsingProjectId(String url) {
})
.map(new Function<JSONObject, FormState>() {
@Override
public FormState apply(JSONObject jsonObject) throws Exception {
public FormState apply(JSONObject jsonObject) {
return GSONInstance.getInstance().fromJson(jsonObject.toString(), FormState.class);
}
})
.filter(new Predicate<FormState>() {
@Override
public boolean test(FormState formState) throws Exception {
public boolean test(FormState formState) {
return TextUtils.equals(formState.getStatusDisplay().toLowerCase(Locale.getDefault()),
submissionStatus.toLowerCase(Locale.getDefault()));
}
})
.filter(new Predicate<FormState>() {
@Override
public boolean test(FormState formState) {
return formState.getProject().equals(project.getId());
}
})
.toList();
}

Expand Down
Loading

0 comments on commit e74fae7

Please sign in to comment.