@@ -536,68 +536,68 @@ else if (cursor.getCount() > 0 && cursor.moveToFirst()) {
536
536
}
537
537
538
538
private @ Nullable List <LayoutElementParcelable > listRecentFiles () {
539
- final Context context = this .context .get ();
540
- final MainFragment mainFragment = this .mainFragmentReference .get ();
539
+ final Context c = context .get ();
541
540
542
- if (context == null ) {
541
+ if (c == null ) {
543
542
cancel (true );
544
543
return null ;
545
544
}
546
- MainFragmentViewModel viewModel = mainFragment . getMainFragmentViewModel ();
545
+
547
546
List <LayoutElementParcelable > recentFiles = new ArrayList <>(40 );
548
547
549
- Cursor cursor = getCursor ( context );
548
+ Cursor cursor = getRecentFilesCursor ( c );
550
549
if (cursor == null ) return recentFiles ;
551
550
if (cursor .getCount () > 0 && cursor .moveToFirst ()) {
552
551
do {
553
- String path = cursor .getString (cursor .getColumnIndex (MediaStore .Files . FileColumns .DATA ));
554
- File f = new File (path );
552
+ String filePath = cursor .getString (cursor .getColumnIndex (MediaStore .MediaColumns .DATA ));
553
+ File f = new File (filePath );
555
554
if (f .isDirectory ()) {
556
555
List <File > files = getFilesFromDirectory (f );
557
- for (File file : files ) {
558
- compareFileAndAddToList (viewModel , recentFiles , file );
559
- }
560
- }
556
+ for (File file : files )
557
+ compareFileAndAddToList (recentFiles , file );
558
+ } else compareFileAndAddToList (recentFiles , f );
561
559
} while (cursor .moveToNext ());
562
560
}
563
561
cursor .close ();
564
562
return recentFiles ;
565
563
}
566
564
567
565
@ Nullable
568
- private Cursor getCursor (Context context ) {
566
+ private Cursor getRecentFilesCursor (Context c ) {
569
567
final String [] projection = {
570
- MediaStore .Files . FileColumns . DATA , MediaStore .Files . FileColumns .DATE_MODIFIED
568
+ MediaStore .MediaColumns . DATA , MediaStore .MediaColumns .DATE_MODIFIED
571
569
};
572
570
Cursor cursor ;
573
571
if (SDK_INT >= Q ) {
574
572
Bundle queryArgs = new Bundle ();
575
573
queryArgs .putStringArray (
576
574
ContentResolver .QUERY_ARG_SORT_COLUMNS ,
577
- new String [] {MediaStore .Files . FileColumns .DATE_MODIFIED });
575
+ new String [] {MediaStore .MediaColumns .DATE_MODIFIED });
578
576
queryArgs .putInt (
579
577
ContentResolver .QUERY_ARG_SORT_DIRECTION ,
580
578
ContentResolver .QUERY_SORT_DIRECTION_DESCENDING );
579
+ queryArgs .putInt (
580
+ ContentResolver .QUERY_ARG_LIMIT ,
581
+ 100 );
581
582
cursor =
582
- context
583
+ c
583
584
.getContentResolver ()
584
585
.query (MediaStore .Files .getContentUri ("external" ), projection , queryArgs , null );
585
586
} else {
586
587
cursor =
587
- context
588
+ c
588
589
.getContentResolver ()
589
590
.query (
590
591
MediaStore .Files .getContentUri ("external" ),
591
592
projection ,
592
593
null ,
593
594
null ,
594
- MediaStore .Files . FileColumns . DATE_MODIFIED + " DESC LIMIT 20 " );
595
+ MediaStore .MediaColumns . DATE_MODIFIED + " DESC LIMIT 100 " );
595
596
}
596
597
return cursor ;
597
598
}
598
599
599
- private void compareFileAndAddToList (
600
- MainFragmentViewModel viewModel , List <LayoutElementParcelable > recentFiles , File file ) {
600
+ private void compareFileAndAddToList (List <LayoutElementParcelable > recentFiles , File file ) {
601
601
Calendar c = Calendar .getInstance ();
602
602
c .set (Calendar .DAY_OF_YEAR , c .get (Calendar .DAY_OF_YEAR ) - 2 );
603
603
Date d = c .getTime ();
@@ -608,7 +608,6 @@ private void compareFileAndAddToList(
608
608
LayoutElementParcelable parcelable = createListParcelables (strings );
609
609
if (parcelable != null ) {
610
610
recentFiles .add (parcelable );
611
- viewModel .incrementFileCount ();
612
611
}
613
612
}
614
613
}
0 commit comments