@@ -376,12 +376,8 @@ public void onItemSelected(
376
376
AdapterView <?> parent , View view , int position , long id ) {
377
377
Log .i (TAG , "onItemSelected view " + view + ", position " + position + ", id " + id );
378
378
//showToast("Spinner1: position=" + position + " id=" + id);
379
- AsyncTask .Status status ;
380
379
synchronized (searchTask ) {
381
- if ((status = searchTask .getStatus ()) == AsyncTask .Status .RUNNING
382
- || status == AsyncTask .Status .PENDING ) {
383
- searchTask .cancel (true );
384
- }
380
+ searchTask .cancel (true );
385
381
searchTask = new SearchFileNameTask ();
386
382
searchTask .execute (position );
387
383
}
@@ -398,12 +394,8 @@ public void afterTextChanged(final Editable text) {
398
394
final String filesearch = text .toString ();
399
395
Log .d ("quicksearch" , "filesearch " + filesearch );
400
396
if (filesearch .length () > 0 ) {
401
- AsyncTask .Status status ;
402
397
synchronized (searchTask ) {
403
- if (((status = searchTask .getStatus ()) == AsyncTask .Status .RUNNING
404
- || status == AsyncTask .Status .PENDING )) {
405
- searchTask .cancel (true );
406
- }
398
+ searchTask .cancel (true );
407
399
searchTask = new SearchFileNameTask ();
408
400
searchTask .execute (filesearch );
409
401
}
@@ -459,9 +451,7 @@ protected ArrayList<AppInfo> doInBackground(Object... params) {
459
451
460
452
@ Override
461
453
protected void onPostExecute (ArrayList <AppInfo > tempAppList ) {
462
- if (isCancelled ()) {
463
- return ;
464
- }
454
+
465
455
Collections .sort (tempAppList , appListSorter );
466
456
appList .clear ();
467
457
appList .addAll (tempAppList );
@@ -681,11 +671,14 @@ public void loadlist(final boolean save) {
681
671
appLoadTask .execute ();
682
672
}
683
673
684
- class LoadAppListTask extends AsyncTask <Void , Void , ArrayList <AppInfo >> {
674
+ class LoadAppListTask extends AsyncTask <Void , ArrayList <AppInfo >, Void > {
685
675
686
676
private final int index , top ;
687
677
private final boolean save ;
688
678
679
+ public long prevUpdate = 0 ;
680
+ public boolean busyNoti = false ;
681
+
689
682
public LoadAppListTask (final boolean save , final int top , final int index ) {
690
683
this .save = save ;
691
684
this .index = index ;
@@ -694,11 +687,14 @@ public LoadAppListTask(final boolean save, final int top, final int index) {
694
687
695
688
@ Override
696
689
protected void onPreExecute () {
690
+ appList .clear ();
691
+ selectedInList1 .clear ();
692
+ appAdapter .notifyDataSetChanged ();
697
693
mSwipeRefreshLayout .setRefreshing (true );
698
694
}
699
695
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 );
702
698
try {
703
699
final PackageManager packageManager = activity .getPackageManager ();
704
700
final List <PackageInfo > all_apps = packageManager .getInstalledPackages (PackageManager .GET_META_DATA );
@@ -709,31 +705,42 @@ protected ArrayList<AppInfo> doInBackground(Void[] p1) {
709
705
710
706
tempAppList .add (new AppInfo (packageManager , pinfo ));
711
707
708
+ final long present = System .currentTimeMillis ();
709
+ if (present - prevUpdate > 1000 && !busyNoti ) {
710
+ prevUpdate = present ;
711
+ publishProgress (tempAppList );
712
+ tempAppList = new ArrayList <>(64 );
713
+ }
712
714
//packageInfos.add(pinfo);
713
715
//System.out.println( new ObjectDumper(pinfo).dump());
714
716
}
717
+ publishProgress (tempAppList );
715
718
//Collections.sort(layoutElems, new FileListSorter(0, sortby, asc, false));
716
719
} catch (Throwable e ) {
717
720
e .printStackTrace ();
718
721
//Toast.makeText(getActivity(), "" + e, Toast.LENGTH_LONG).show();
719
722
}
720
- Collections .sort (tempAppList , appListSorter );
721
- return tempAppList ;
723
+ return null ;//tempAppList;
722
724
}
723
725
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
+
724
736
@ Override
725
737
// 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 ) {
730
739
try {
731
- appList .clear ();
732
- selectedInList1 .clear ();
733
- appList .addAll (tempAppList );
740
+ Collections .sort (appList , appListSorter );
734
741
synchronized (tempOriDataSourceL1 ) {
735
742
tempOriDataSourceL1 .clear ();
736
- tempOriDataSourceL1 .addAll (tempAppList );
743
+ tempOriDataSourceL1 .addAll (appList );
737
744
}
738
745
739
746
appAdapter .notifyDataSetChanged ();
0 commit comments