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 #452 from fieldsight/451-hotfix/enabled-auto-send-…
Browse files Browse the repository at this point in the history
…check

enables auto send check (#451)
  • Loading branch information
konishon authored Nov 2, 2019
2 parents cae9b0b + ff765c5 commit 296fcd9
Showing 1 changed file with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
import androidx.work.WorkInfo;
import androidx.work.WorkManager;

import org.bcss.collect.android.R;
import org.odk.collect.android.adapters.InstanceUploaderAdapter;
Expand All @@ -52,10 +55,13 @@
import org.odk.collect.android.tasks.sms.SmsService;
import org.odk.collect.android.tasks.sms.contracts.SmsSubmissionManagerContract;
import org.odk.collect.android.tasks.sms.models.SmsSubmission;
import org.odk.collect.android.upload.AutoSendWorker;
import org.odk.collect.android.utilities.PermissionUtils;
import org.odk.collect.android.utilities.PlayServicesUtil;
import org.odk.collect.android.utilities.ToastUtils;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
Expand Down Expand Up @@ -246,35 +252,35 @@ void init() {
instanceSyncTask.setDiskSyncListener(this);
instanceSyncTask.execute();

sortingOptions = new int[] {
sortingOptions = new int[]{
R.string.sort_by_name_asc, R.string.sort_by_name_desc,
R.string.sort_by_date_asc, R.string.sort_by_date_desc
};

getSupportLoaderManager().initLoader(LOADER_ID, null, this);

// Start observer that sets autoSendOngoing field based on AutoSendWorker status
// updateAutoSendStatus();
// Start observer that sets autoSendOngoing field based on AutoSendWorker status
updateAutoSendStatus();
}

// /**
// * Updates whether an auto-send job is ongoing.
// */
// private void updateAutoSendStatus() {
// LiveData<List<WorkInfo>> statuses = WorkManager.getInstance().getWorkInfosForUniqueWorkLiveData(AutoSendWorker.class.getName());
//
// statuses.observe(this, workStatuses -> {
// if (workStatuses != null) {
// for (WorkInfo status : workStatuses) {
// if (status.getState().equals(WorkInfo.State.RUNNING)) {
// autoSendOngoing = true;
// return;
// }
// }
// autoSendOngoing = false;
// }
// });
// }
/**
* Updates whether an auto-send job is ongoing.
*/
private void updateAutoSendStatus() {
LiveData<List<WorkInfo>> statuses = WorkManager.getInstance().getWorkInfosForUniqueWorkLiveData(AutoSendWorker.class.getName());

statuses.observe(this, workStatuses -> {
if (workStatuses != null) {
for (WorkInfo status : workStatuses) {
if (status.getState().equals(WorkInfo.State.RUNNING)) {
autoSendOngoing = true;
return;
}
}
autoSendOngoing = false;
}
});
}

@Override
protected void onResume() {
Expand Down

0 comments on commit 296fcd9

Please sign in to comment.