private Cursor getImageMediaCursor(Context context, int nSort, int limit, int offset) {
Cursor mPictureCursor;
String[] proj = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_MODIFIED, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.SIZE, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.MIME_TYPE };
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
{
Bundle bundle = new Bundle();
bundle.putInt(ContentResolver.QUERY_ARG_LIMIT, limit);
bundle.putInt(ContentResolver.QUERY_ARG_OFFSET, offset);
bundle.putString(ContentResolver.QUERY_ARG_SORT_COLUMNS, MediaStore.Images.Media.DATE_TAKEN);
bundle.putString(ContentResolver.QUERY_ARG_SORT_COLUMNS, MediaStore.Images.Media.DATE_MODIFIED);
bundle.putInt(ContentResolver.QUERY_ARG_SORT_DIRECTION, ContentResolver.QUERY_SORT_DIRECTION_DESCENDING);
mPictureCursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, bundle, null);
} else {
String sort = MediaStore.Images.Media.DATE_TAKEN + " desc ," + MediaStore.Images.Media.DATE_MODIFIED + " desc LIMIT " + limit + " OFFSET " + offset;
mPictureCursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, null, null, sort);
}
return mPictureCursor;
}
fun setData() {
val loading = false // 로딩 중이면 쿼리를 실행하지 않음
val list = functionSearchPictureFileItemList(this, true, 0, mLimit, mOffset)
val adapter = GalleryAdapter(this, this, this, applicationContext)
adapter.setData(list)
binding.gridGallery.setScrollListener { view, firstVisibleItem, visibleItemCount, totalItemCount ->
if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem)) {
loading = true
mOffset += mLimit
val getData = functionSearchPictureFileItemList(this, true, 0, mLimit, mOffset)
list.addAll(getData)
adapter.setData(list)
adapter.notifyDataSetChanged()
} else {
loading = false
}
}
binding.gridGallery.adapter = adapter
}
'Study > Android' 카테고리의 다른 글
FragmentStateAdapter (0) | 2022.03.07 |
---|---|
코루틴 기본 개념 및 활용(CoroutineScope/GlobalScope/ViewModelScope/LifecycleScope) (1) | 2021.12.27 |
앱 서명 jks -> pepk (0) | 2021.11.10 |
CoroutineScope Network Example (0) | 2021.10.21 |
Kotlin SingleTon with Fragment (0) | 2021.10.06 |