Skip to content

Commit 4bac75c

Browse files
committed
fix app loader
1 parent 6cb1a89 commit 4bac75c

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

PowerFileExplorer/src/main/java/net/gnu/explorer/AppsFragment.java

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,8 @@ public void onItemSelected(
376376
AdapterView<?> parent, View view, int position, long id) {
377377
Log.i(TAG, "onItemSelected view " + view + ", position " + position + ", id " + id);
378378
//showToast("Spinner1: position=" + position + " id=" + id);
379-
AsyncTask.Status status;
380379
synchronized (searchTask) {
381-
if ((status = searchTask.getStatus()) == AsyncTask.Status.RUNNING
382-
|| status == AsyncTask.Status.PENDING) {
383-
searchTask.cancel(true);
384-
}
380+
searchTask.cancel(true);
385381
searchTask = new SearchFileNameTask();
386382
searchTask.execute(position);
387383
}
@@ -398,12 +394,8 @@ public void afterTextChanged(final Editable text) {
398394
final String filesearch = text.toString();
399395
Log.d("quicksearch", "filesearch " + filesearch);
400396
if (filesearch.length() > 0) {
401-
AsyncTask.Status status;
402397
synchronized (searchTask) {
403-
if (((status = searchTask.getStatus()) == AsyncTask.Status.RUNNING
404-
|| status == AsyncTask.Status.PENDING)) {
405-
searchTask.cancel(true);
406-
}
398+
searchTask.cancel(true);
407399
searchTask = new SearchFileNameTask();
408400
searchTask.execute(filesearch);
409401
}
@@ -459,9 +451,7 @@ protected ArrayList<AppInfo> doInBackground(Object... params) {
459451

460452
@Override
461453
protected void onPostExecute(ArrayList<AppInfo> tempAppList) {
462-
if (isCancelled()) {
463-
return;
464-
}
454+
465455
Collections.sort(tempAppList, appListSorter);
466456
appList.clear();
467457
appList.addAll(tempAppList);
@@ -681,11 +671,14 @@ public void loadlist(final boolean save) {
681671
appLoadTask.execute();
682672
}
683673

684-
class LoadAppListTask extends AsyncTask<Void, Void, ArrayList<AppInfo>> {
674+
class LoadAppListTask extends AsyncTask<Void, ArrayList<AppInfo>, Void> {
685675

686676
private final int index, top;
687677
private final boolean save;
688678

679+
public long prevUpdate = 0;
680+
public boolean busyNoti = false;
681+
689682
public LoadAppListTask(final boolean save, final int top, final int index) {
690683
this.save = save;
691684
this.index = index;
@@ -694,11 +687,14 @@ public LoadAppListTask(final boolean save, final int top, final int index) {
694687

695688
@Override
696689
protected void onPreExecute() {
690+
appList.clear();
691+
selectedInList1.clear();
692+
appAdapter.notifyDataSetChanged();
697693
mSwipeRefreshLayout.setRefreshing(true);
698694
}
699695

700-
protected ArrayList<AppInfo> doInBackground(Void[] p1) {
701-
final ArrayList<AppInfo> tempAppList = new ArrayList<AppInfo>();
696+
protected Void doInBackground(Void[] p1) {
697+
ArrayList<AppInfo> tempAppList = new ArrayList<AppInfo>(64);
702698
try {
703699
final PackageManager packageManager = activity.getPackageManager();
704700
final List<PackageInfo> all_apps = packageManager.getInstalledPackages(PackageManager.GET_META_DATA);
@@ -709,31 +705,42 @@ protected ArrayList<AppInfo> doInBackground(Void[] p1) {
709705

710706
tempAppList.add(new AppInfo(packageManager, pinfo));
711707

708+
final long present = System.currentTimeMillis();
709+
if (present - prevUpdate > 1000 && !busyNoti) {
710+
prevUpdate = present;
711+
publishProgress(tempAppList);
712+
tempAppList = new ArrayList<>(64);
713+
}
712714
//packageInfos.add(pinfo);
713715
//System.out.println( new ObjectDumper(pinfo).dump());
714716
}
717+
publishProgress(tempAppList);
715718
//Collections.sort(layoutElems, new FileListSorter(0, sortby, asc, false));
716719
} catch (Throwable e) {
717720
e.printStackTrace();
718721
//Toast.makeText(getActivity(), "" + e, Toast.LENGTH_LONG).show();
719722
}
720-
Collections.sort(tempAppList, appListSorter);
721-
return tempAppList;
723+
return null;//tempAppList;
722724
}
723725

726+
@Override
727+
protected void onProgressUpdate(ArrayList<AppInfo>... values) {
728+
super.onProgressUpdate(values);
729+
busyNoti = true;
730+
appList.addAll(values[0]);
731+
appAdapter.notifyDataSetChanged();
732+
busyNoti = false;
733+
selectionStatusTV.setText(selectedInList1.size() + "/" + appList.size());
734+
}
735+
724736
@Override
725737
// Once the image is downloaded, associates it to the imageView
726-
protected void onPostExecute(ArrayList<AppInfo> tempAppList) {
727-
if (isCancelled()) {
728-
return;
729-
}
738+
protected void onPostExecute(Void v) {
730739
try {
731-
appList.clear();
732-
selectedInList1.clear();
733-
appList.addAll(tempAppList);
740+
Collections.sort(appList, appListSorter);
734741
synchronized (tempOriDataSourceL1) {
735742
tempOriDataSourceL1.clear();
736-
tempOriDataSourceL1.addAll(tempAppList);
743+
tempOriDataSourceL1.addAll(appList);
737744
}
738745

739746
appAdapter.notifyDataSetChanged();

PowerFileExplorer/src/main/java/net/gnu/explorer/FileFrag.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ public void onViewCreated(View v, Bundle savedInstanceState) {
226226
mSwipeRefreshLayout.setColorSchemeResources(
227227
android.R.color.holo_blue_bright,
228228
android.R.color.holo_red_light);
229-
mSwipeRefreshLayout.setProgressViewOffset(false, 0,
230-
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, res.getDisplayMetrics()));
229+
//mSwipeRefreshLayout.setProgressViewOffset(false, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, res.getDisplayMetrics()));
231230

232231
horizontalDivider0 = v.findViewById(R.id.horizontalDivider0);
233232
horizontalDivider12 = v.findViewById(R.id.horizontalDivider12);

0 commit comments

Comments
 (0)