use of com.yydcdut.noteplugin.bean.MediaFolder in project PhotoNoter by yydcdut.
the class MediaPhotoFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mMediaFolderByNameMap = PhotoModel.getInstance().findByMedia(getContext());
mFolderNameList = new ArrayList<>(mMediaFolderByNameMap.size());
for (Map.Entry<String, MediaFolder> entry : mMediaFolderByNameMap.entrySet()) {
mFolderNameList.add(entry.getKey());
}
mFolderNameList.remove(MediaFolder.ALL);
mFolderNameList.add(0, MediaFolder.ALL);
mCurrentFolderName = MediaFolder.ALL;
mFolderAdapter = new ArrayAdapter<>(getContext(), R.layout.item_spinner, mFolderNameList);
mActionBar = mMainActivity.getSupportActionBar();
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
mActionBar.setListNavigationCallbacks(mFolderAdapter, this);
int size = getResources().getDisplayMetrics().widthPixels / 3;
mMediaPhotoAdapter = new MediaPhotoAdapter(getContext(), size, mMediaFolderByNameMap.get(mCurrentFolderName), this, this);
mRecyclerView.setAdapter(mMediaPhotoAdapter);
}
use of com.yydcdut.noteplugin.bean.MediaFolder in project PhotoNoter by yydcdut.
the class PhotoModel method findByMedia.
@NonNull
public Map<String, MediaFolder> findByMedia(@NonNull Context context) {
WeakReference<Context> contextWeakReference = new WeakReference<>(context);
if (mMediaCache == null) {
mMediaCache = new HashMap<>();
MediaFolder mediaFolder4All = new MediaFolder(MediaFolder.ALL, new ArrayList<MediaPhoto>());
mMediaCache.put(MediaFolder.ALL, mediaFolder4All);
final String[] projectionPhotos = { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.ORIENTATION, MediaStore.Images.Thumbnails.DATA };
Cursor cursor = MediaStore.Images.Media.query(contextWeakReference.get().getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projectionPhotos, "", null, MediaStore.Images.Media.DATE_TAKEN + " DESC");
if (cursor == null) {
return mMediaCache;
}
while (cursor.moveToNext()) {
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
String thumb = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA));
File file = new File(path);
if (file.exists() && file.length() > 0) {
MediaPhoto mediaPhoto = new MediaPhoto(path, thumb);
String folderName = file.getParentFile().getName();
MediaFolder mediaFolder = mMediaCache.get(folderName);
if (mediaFolder == null) {
List<MediaPhoto> mediaPhotoList = new ArrayList<>();
mediaPhotoList.add(mediaPhoto);
mediaFolder = new MediaFolder(folderName, mediaPhotoList);
mMediaCache.put(folderName, mediaFolder);
} else {
mediaFolder.getMediaPhotoList().add(mediaPhoto);
}
mediaFolder4All.getMediaPhotoList().add(mediaPhoto);
}
}
}
contextWeakReference.clear();
return mMediaCache;
}
Aggregations