Skip to content

Commit

Permalink
♻️ Remove AsyncTasks in SecuredNativeSmartRegister
Browse files Browse the repository at this point in the history
  • Loading branch information
allan-on committed Sep 6, 2022
1 parent c726a64 commit 9b385bf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.smartregister.view.activity;

import static android.os.AsyncTask.THREAD_POOL_EXECUTOR;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static org.apache.commons.lang3.StringUtils.isEmpty;
Expand All @@ -21,7 +20,6 @@
import android.content.SharedPreferences;
import android.database.DataSetObserver;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
Expand All @@ -46,6 +44,7 @@
import org.smartregister.domain.ReportMonth;
import org.smartregister.domain.form.FormSubmission;
import org.smartregister.provider.SmartRegisterClientsProvider;
import org.smartregister.util.AppExecutorService;
import org.smartregister.util.PaginationHolder;
import org.smartregister.util.ViewHelper;
import org.smartregister.view.contract.SmartRegisterClient;
Expand Down Expand Up @@ -76,6 +75,7 @@ public abstract class SecuredNativeSmartRegisterActivity extends SecuredActivity
private final PaginationViewHandler paginationViewHandler = new PaginationViewHandler();
private final NavBarActionsHandler navBarActionsHandler = new NavBarActionsHandler();
private final SearchCancelHandler searchCancelHandler = new SearchCancelHandler();
private final AppExecutorService appExecutorService = new AppExecutorService();
private ListView clientsView;
private ProgressBar clientsProgressView;
private TextView serviceModeView;
Expand Down Expand Up @@ -145,30 +145,19 @@ protected void onCreation() {

@Override
protected void onResumption() {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
publishProgress();
setupAdapter();
return null;
}

@Override
protected void onPreExecute() {
super.onPreExecute();
clientsProgressView.setVisibility(VISIBLE);
clientsView.setVisibility(INVISIBLE);
}

@Override
protected void onPostExecute(Void result) {
// On Pre-Execute
clientsProgressView.setVisibility(VISIBLE);
clientsView.setVisibility(INVISIBLE);
appExecutorService.executorService().execute(() -> {
// publishProgress();
setupAdapter();
appExecutorService.mainThread().execute(() -> {
clientsView.setAdapter(clientsAdapter);
paginationViewHandler.refresh();
clientsProgressView.setVisibility(View.GONE);
clientsView.setVisibility(VISIBLE);

}
}.executeOnExecutor(THREAD_POOL_EXECUTOR);
});
});
}

protected void setupViews() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package org.smartregister.view.fragment;

import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.smartregister.AllConstants.SHORT_DATE_FORMAT;
import static java.text.MessageFormat.format;
import static java.util.Arrays.asList;

import android.content.pm.ActivityInfo;
import android.database.DataSetObserver;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
Expand All @@ -26,6 +32,7 @@
import org.smartregister.adapter.SmartRegisterPaginatedAdapter;
import org.smartregister.domain.ReportMonth;
import org.smartregister.provider.SmartRegisterClientsProvider;
import org.smartregister.util.AppExecutorService;
import org.smartregister.util.PaginationHolder;
import org.smartregister.util.ViewHelper;
import org.smartregister.view.activity.SecuredNativeSmartRegisterActivity;
Expand All @@ -43,14 +50,6 @@

import java.util.List;

import static android.os.AsyncTask.THREAD_POOL_EXECUTOR;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static java.text.MessageFormat.format;
import static java.util.Arrays.asList;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.smartregister.AllConstants.SHORT_DATE_FORMAT;

/**
* Created by koros on 10/12/15.
*/
Expand All @@ -62,6 +61,7 @@ public abstract class SecuredNativeSmartRegisterFragment extends SecuredFragment
private final PaginationViewHandler paginationViewHandler = new PaginationViewHandler();
private final NavBarActionsHandler navBarActionsHandler = new NavBarActionsHandler();
private final SearchCancelHandler searchCancelHandler = new SearchCancelHandler();
private final AppExecutorService appExecutorService = new AppExecutorService();
public ListView clientsView;
public ProgressBar clientsProgressView;
public TextView serviceModeView;
Expand Down Expand Up @@ -152,32 +152,21 @@ public void refreshListView() {

@Override
protected void onResumption() {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
publishProgress();
setupAdapter();
return null;
}

@Override
protected void onPreExecute() {
super.onPreExecute();
clientsProgressView.setVisibility(VISIBLE);
clientsView.setVisibility(INVISIBLE);
}

@Override
protected void onPostExecute(Void result) {
// On Pre-Execute
clientsProgressView.setVisibility(VISIBLE);
clientsView.setVisibility(INVISIBLE);
appExecutorService.executorService().execute(() -> {
// publishProgress();
setupAdapter();
appExecutorService.mainThread().execute(() -> {
clientsView.setAdapter(clientsAdapter);
if (isAdded()) {
paginationViewHandler.refresh();
clientsProgressView.setVisibility(View.GONE);
clientsView.setVisibility(VISIBLE);
}

}
}.executeOnExecutor(THREAD_POOL_EXECUTOR);
});
});
}

private void setupStatusBarViews(View view) {
Expand Down

0 comments on commit 9b385bf

Please sign in to comment.