diff --git a/app/src/main/java/com/CodeBoy/MediaFacer_Examples/fragments/videoPlayerFragment.java b/app/src/main/java/com/CodeBoy/MediaFacer_Examples/fragments/videoPlayerFragment.java index 070c725..cc80950 100644 --- a/app/src/main/java/com/CodeBoy/MediaFacer_Examples/fragments/videoPlayerFragment.java +++ b/app/src/main/java/com/CodeBoy/MediaFacer_Examples/fragments/videoPlayerFragment.java @@ -267,6 +267,4 @@ private void updateProgressCallbackTask() { } } - - } diff --git a/app/src/main/java/com/CodeBoy/MediaFacer_Examples/pictureActivity.java b/app/src/main/java/com/CodeBoy/MediaFacer_Examples/pictureActivity.java index c16fc2c..13876b6 100644 --- a/app/src/main/java/com/CodeBoy/MediaFacer_Examples/pictureActivity.java +++ b/app/src/main/java/com/CodeBoy/MediaFacer_Examples/pictureActivity.java @@ -106,7 +106,7 @@ private void setUpFolderSelector(){ final ArrayList pictureFolders = new ArrayList<>(); pictureFolders.add(new pictureFolderContent("all","*All*")); - pictureFolders.addAll(MediaFacer.withPictureContex(this).getPictureFolders()); + pictureFolders.addAll(MediaFacer.withPictureContex(this).getAbsolutePictureFolders()); final ArrayList folders = new ArrayList<>(); for(int i = 0;i < pictureFolders.size();i++){ @@ -126,9 +126,10 @@ public void onItemSelected(AdapterView parent, View view, int position, long Toast.makeText(pictureActivity.this,String.valueOf(allPhotos.size()),Toast.LENGTH_LONG).show(); setUpAndDisplayPictures(); }else { - allPhotos = MediaFacer + allPhotos = pictureFolders.get(position).getPhotos(); + /* allPhotos = MediaFacer .withPictureContex(pictureActivity.this) - .getAllPictureContentByBucket_id(pictureFolders.get(position).getBucket_id()); + .getAllPictureContentByBucket_id(pictureFolders.get(position).getBucket_id());*/ Toast.makeText(pictureActivity.this,String.valueOf(allPhotos.size()),Toast.LENGTH_LONG).show(); setUpAndDisplayPictures(); } diff --git a/app/src/main/java/com/CodeBoy/MediaFacer_Examples/videoActivity.java b/app/src/main/java/com/CodeBoy/MediaFacer_Examples/videoActivity.java index 9d8e233..96a2052 100644 --- a/app/src/main/java/com/CodeBoy/MediaFacer_Examples/videoActivity.java +++ b/app/src/main/java/com/CodeBoy/MediaFacer_Examples/videoActivity.java @@ -61,7 +61,7 @@ private void setupFolderSelector(){ final ArrayList videoFolders = new ArrayList<>(); videoFolders.add(new videoFolderContent("all","*All*")); - videoFolders.addAll(MediaFacer.withVideoContex(this).getVideoFolders(VideoGet.externalContentUri)); + videoFolders.addAll(MediaFacer.withVideoContex(this).getAbsoluteVideoFolders(VideoGet.externalContentUri)); final ArrayList folders = new ArrayList<>(); for(int i = 0;i < videoFolders.size();i++){ @@ -81,9 +81,10 @@ public void onItemSelected(AdapterView parent, View view, int position, long Toast.makeText(videoActivity.this,String.valueOf(allVideos.size()),Toast.LENGTH_LONG).show(); setuUpAndDisplayVideos(); }else { - allVideos = MediaFacer + allVideos = videoFolders.get(position).getVideoFiles(); + /* allVideos = MediaFacer .withVideoContex(videoActivity.this) - .getAllVideoContentByBucket_id(videoFolders.get(position).getBucket_id()); + .getAllVideoContentByBucket_id(videoFolders.get(position).getBucket_id());*/ Toast.makeText(videoActivity.this,String.valueOf(allVideos.size()),Toast.LENGTH_LONG).show(); setuUpAndDisplayVideos(); } @@ -117,7 +118,6 @@ public void onVideoItemLongClicked(int position) { } - private void playVideo(int position){ videoPlayerFragment playerFragment = new videoPlayerFragment(); diff --git a/mediafacer/src/main/java/com/CodeBoy/MediaFacer/AudioGet.java b/mediafacer/src/main/java/com/CodeBoy/MediaFacer/AudioGet.java index 92479f6..5e48b38 100644 --- a/mediafacer/src/main/java/com/CodeBoy/MediaFacer/AudioGet.java +++ b/mediafacer/src/main/java/com/CodeBoy/MediaFacer/AudioGet.java @@ -13,7 +13,6 @@ import java.io.File; import java.util.ArrayList; - public class AudioGet { private static AudioGet audioGet; diff --git a/mediafacer/src/main/java/com/CodeBoy/MediaFacer/PictureGet.java b/mediafacer/src/main/java/com/CodeBoy/MediaFacer/PictureGet.java index 99f5313..4d73e93 100644 --- a/mediafacer/src/main/java/com/CodeBoy/MediaFacer/PictureGet.java +++ b/mediafacer/src/main/java/com/CodeBoy/MediaFacer/PictureGet.java @@ -36,12 +36,15 @@ static PictureGet getInstance(Context contx){ /**Returns an ArrayList of {@link pictureContent} */ public ArrayList getAllPictureContents(Uri contentLocation){ ArrayList images = new ArrayList<>(); - String[] projection = { MediaStore.Images.Media.DATA ,MediaStore.Images.Media.DISPLAY_NAME, - MediaStore.Images.Media.SIZE, MediaStore.Images.Media.DATE_ADDED,MediaStore.Images.Media._ID, + String[] projection = { + MediaStore.Images.Media.DATA, + MediaStore.Images.Media.DISPLAY_NAME, + MediaStore.Images.Media.SIZE, + MediaStore.Images.Media.DATE_ADDED, + MediaStore.Images.Media._ID, MediaStore.Images.Media.DATE_MODIFIED}; cursor = pictureContex.getContentResolver().query( contentLocation, projection, null, null, "LOWER ("+MediaStore.Images.Media.DATE_TAKEN+") DESC"); - try { cursor.moveToFirst(); do{ @@ -66,6 +69,13 @@ public ArrayList getAllPictureContents(Uri contentLocation){ pictureContent.setDate_added(0000); } + try{ + pictureContent.setDate_taken(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_TAKEN))); + }catch (Exception ex){ + ex.printStackTrace(); + pictureContent.setDate_taken(0000); + } + try{ pictureContent.setDate_modified(cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_MODIFIED))); }catch (Exception ex){ @@ -83,6 +93,7 @@ public ArrayList getAllPictureContents(Uri contentLocation){ } /**Returns an ArrayList of {@link pictureFolderContent} */ + public ArrayList getPictureFolders(){ ArrayList picFolders = new ArrayList<>(); ArrayList picPaths = new ArrayList<>(); @@ -97,13 +108,10 @@ public ArrayList getPictureFolders(){ cursor.moveToFirst(); do{ pictureFolderContent photoFolder = new pictureFolderContent(); - String name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME)); String folder = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME)); String datapath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)); - //if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { int bucket_id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_ID)); - //}else {} String folderpaths = datapath.substring(0, datapath.lastIndexOf(folder+"/")); folderpaths = folderpaths+folder+"/"; @@ -159,24 +167,114 @@ public ArrayList getAllPictureContentByBucket_id(int bucket_id){ pictureContent.setDate_added(0000); } + try{ + pictureContent.setDate_taken(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_TAKEN))); + }catch (Exception ex){ + ex.printStackTrace(); + pictureContent.setDate_taken(0000); + } + try{ pictureContent.setDate_modified(cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_MODIFIED))); }catch (Exception ex){ ex.printStackTrace(); pictureContent.setDate_added(0000); } + images.add(pictureContent); }while(cursor.moveToNext()); cursor.close(); -// ArrayList reSelection = new ArrayList<>(); -// for(int i = images.size()-1;i > -1;i--){ -// reSelection.add(images.get(i)); -// } -// images = reSelection; } catch (Exception e) { e.printStackTrace(); } return images; } + public ArrayList getAbsolutePictureFolders(){ + ArrayList absolutePictureFolders = new ArrayList<>(); + ArrayList picturePaths = new ArrayList<>(); + @SuppressLint("InlinedApi") String[] projection = { + MediaStore.Images.ImageColumns.DATA, + MediaStore.Images.Media.DISPLAY_NAME, + MediaStore.Images.Media.BUCKET_DISPLAY_NAME, + MediaStore.Images.Media.BUCKET_ID, + MediaStore.Images.Media.SIZE, + MediaStore.Images.Media.DATE_ADDED, + MediaStore.Images.Media._ID, + MediaStore.Images.Media.DATE_TAKEN, + MediaStore.Images.Media.DATE_MODIFIED}; + cursor = pictureContex.getContentResolver().query( externalContentUri, projection, null, null, + "LOWER ("+MediaStore.Images.Media.DATE_TAKEN+") DESC"); + try{ + cursor.moveToFirst(); + do{ + + pictureFolderContent photoFolder = new pictureFolderContent(); + pictureContent pictureContent = new pictureContent(); + + pictureContent.setPicturName(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME))); + + pictureContent.setPicturePath(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA))); + + pictureContent.setPictureSize(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE))); + + int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID)); + pictureContent.setPictureId(id); + + Uri contentUri = Uri.withAppendedPath(externalContentUri, String.valueOf(id)); + pictureContent.setAssertFileStringUri(contentUri.toString()); + + try{ + pictureContent.setDate_added(cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_ADDED))); + }catch (Exception ex){ + ex.printStackTrace(); + pictureContent.setDate_added(0000); + } + + try{ + pictureContent.setDate_taken(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_TAKEN))); + }catch (Exception ex){ + ex.printStackTrace(); + pictureContent.setDate_taken(0000); + } + + try{ + pictureContent.setDate_modified(cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_MODIFIED))); + }catch (Exception ex){ + ex.printStackTrace(); + pictureContent.setDate_added(0000); + } + + String folder = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME)); + String datapath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)); + + int bucket_id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_ID)); + + String folderpaths = datapath.substring(0, datapath.lastIndexOf(folder+"/")); + folderpaths = folderpaths+folder+"/"; + if (!picturePaths.contains(bucket_id)) { + picturePaths.add(bucket_id); + + photoFolder.setBucket_id(bucket_id); + photoFolder.setFolderPath(folderpaths); + photoFolder.setFolderName(folder); + photoFolder.getPhotos().add(pictureContent); + absolutePictureFolders.add(photoFolder); + }else { + for (int i = 0; i < absolutePictureFolders.size();i++){ + if(absolutePictureFolders.get(i).getBucket_id() == bucket_id){ + absolutePictureFolders.get(i).getPhotos().add(pictureContent); + } + } + } + }while (cursor.moveToNext()); + }catch (Exception e){ + e.printStackTrace(); + } + + + + return absolutePictureFolders; + } + } diff --git a/mediafacer/src/main/java/com/CodeBoy/MediaFacer/VideoGet.java b/mediafacer/src/main/java/com/CodeBoy/MediaFacer/VideoGet.java index 537cb44..6bc22db 100644 --- a/mediafacer/src/main/java/com/CodeBoy/MediaFacer/VideoGet.java +++ b/mediafacer/src/main/java/com/CodeBoy/MediaFacer/VideoGet.java @@ -75,6 +75,13 @@ public ArrayList getAllVideoContent(Uri contentLocation) { videoContent.setDate_added(0000); } + try{ + videoContent.setDate_taken(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATE_TAKEN))); + }catch (Exception ex){ + ex.printStackTrace(); + videoContent.setDate_added(0000); + } + try{ videoContent.setDate_modified(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATE_MODIFIED))); }catch (Exception ex){ @@ -107,13 +114,10 @@ public ArrayList getVideoFolders(Uri contentLocation){ cursor.moveToFirst(); do{ videoFolderContent videoFolder = new videoFolderContent(); - String name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME)); String folder = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.BUCKET_DISPLAY_NAME)); String datapath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); - //if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { int bucket_id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.BUCKET_ID)); - //}else {} String folderpaths = datapath.substring(0, datapath.lastIndexOf(folder+"/")); folderpaths = folderpaths+folder+"/"; @@ -180,6 +184,14 @@ public ArrayList getAllVideoContentByBucket_id(int bucket_id){ videoContent.setDate_added(0000); } + try{ + videoContent.setDate_taken(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATE_TAKEN))); + }catch (Exception ex){ + ex.printStackTrace(); + videoContent.setDate_added(0000); + } + + try{ videoContent.setDate_modified(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATE_MODIFIED))); }catch (Exception ex){ @@ -207,15 +219,85 @@ public ArrayList getAbsoluteVideoFolders(Uri contentLocation MediaStore.Video.Media.BUCKET_ID, MediaStore.Video.Media.SIZE, MediaStore.Video.Media._ID, + MediaStore.Video.Media.DURATION, MediaStore.Video.Media.DATE_ADDED, MediaStore.Video.Media.DATE_MODIFIED, MediaStore.Video.Media.DATE_TAKEN, MediaStore.Video.Media.ALBUM, MediaStore.Video.Media.ARTIST}; cursor = videoContex.getContentResolver().query(contentLocation, projection, null, null, "LOWER ("+MediaStore.Video.Media.DATE_TAKEN+") DESC");//DESC + try{ + cursor.moveToFirst(); + do{ + videoFolderContent videoFolder = new videoFolderContent(); + videoContent videoContent = new videoContent(); + + videoContent.setVideoName(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME))); + + videoContent.setPath(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA))); + + videoContent.setVideoDuration(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION))); + + videoContent.setVideoSize(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE))); + + int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID)); + videoContent.setVideoId(id); + + Uri contentUri = Uri.withAppendedPath(contentLocation, String.valueOf(id)); + videoContent.setAssetFileStringUri(contentUri.toString()); + + videoContent.setAlbum(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.ALBUM))); + + videoContent.setArtist(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.ARTIST))); + try{ + videoContent.setDate_added(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATE_ADDED))); + }catch (Exception ex){ + ex.printStackTrace(); + videoContent.setDate_added(0000); + } + + try{ + videoContent.setDate_taken(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATE_TAKEN))); + }catch (Exception ex){ + ex.printStackTrace(); + videoContent.setDate_added(0000); + } + + try{ + videoContent.setDate_modified(cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATE_MODIFIED))); + }catch (Exception ex){ + ex.printStackTrace(); + videoContent.setDate_added(0000); + } + String folder = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.BUCKET_DISPLAY_NAME)); + String datapath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); + + int bucket_id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.BUCKET_ID)); + String folderpaths = datapath.substring(0, datapath.lastIndexOf(folder+"/")); + folderpaths = folderpaths+folder+"/"; + + if (!videoPaths.contains(bucket_id)) { + videoPaths.add(bucket_id); + videoFolder.setBucket_id(bucket_id); + videoFolder.setFolderPath(folderpaths); + videoFolder.setFolderName(folder); + videoFolder.getVideoFiles().add(videoContent); + allVideoFolders.add(videoFolder); + }else{ + for(int i = 0; i < allVideoFolders.size();i++){ + if(allVideoFolders.get(i).getBucket_id() == bucket_id){ + allVideoFolders.get(i).getVideoFiles().add(videoContent); + } + } + } + }while (cursor.moveToNext()); + cursor.close(); + }catch (Exception e){ + e.printStackTrace(); + } return allVideoFolders; }