Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash " Invalid token LIMIT " on android 11 #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,90 @@ import kotlin.coroutines.CoroutineContext

/**
* Created by Hani AlMomani on 24,September,2019
Modified by Omkar Tenkale to apply fix https://github.com/OpenSooq/Gligar/issues/23#issuecomment-798877787 by Shay-BH for issue https://github.com/OpenSooq/Gligar/issues/23
*/


internal class ImagesDataSource(private val contentResolver: ContentResolver){

fun loadAlbums(): ArrayList<AlbumItem> {
val albumCursor = contentResolver.query(
cursorUri,
arrayOf(DISPLAY_NAME_COLUMN,MediaStore.Images.ImageColumns.BUCKET_ID),
fun getCursorUri(): Uri {

val collection: Uri
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
collection = newCursorUri;
} else {
collection = cursorUri;
}

return collection;
}

fun loadAlbums(): ArrayList<AlbumItem> {
val albumCursor = contentResolver.query(
getCursorUri(),
arrayOf(DISPLAY_NAME_COLUMN, MediaStore.Images.ImageColumns.BUCKET_ID),
null,
null,
ORDER_BY
)
val list = arrayListOf<AlbumItem>()
try {
list.add(AlbumItem("All", true,"0"))
if (albumCursor == null) {
return list
}
albumCursor.doWhile {
)
val list = arrayListOf<AlbumItem>()
try {
list.add(AlbumItem("All", true, "0"))
if (albumCursor == null) {
return list
}
albumCursor.doWhile {
try {
val bucketId = albumCursor.getString(albumCursor.getColumnIndex(MediaStore.Images.ImageColumns.BUCKET_ID))
val name = albumCursor.getString(albumCursor.getColumnIndex(DISPLAY_NAME_COLUMN)) ?: bucketId
val name = albumCursor.getString(albumCursor.getColumnIndex(DISPLAY_NAME_COLUMN))
?: bucketId
var albumItem = AlbumItem(name, false, bucketId)
if (!list.contains(albumItem)) {
list.add(albumItem)
}
}
} finally {
if (albumCursor != null && !albumCursor.isClosed) {
albumCursor.close()
catch (ex: Exception) {
ex.printStackTrace()
}
}
return list
} finally {
if (albumCursor != null && !albumCursor.isClosed) {
albumCursor.close()
}
}
return list
}

fun loadAlbumImages(
fun loadAlbumImages(
albumItem: AlbumItem?,
page: Int
): ArrayList<ImageItem> {
val offset = page * PAGE_SIZE
val list: ArrayList<ImageItem> = arrayListOf()
var photoCursor: Cursor? = null
try {
): ArrayList<ImageItem> {
val offset = page * PAGE_SIZE
val list: ArrayList<ImageItem> = arrayListOf()
var photoCursor: Cursor? = null
try {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {

val bundle = Bundle().apply {
putInt(ContentResolver.QUERY_ARG_LIMIT, PAGE_SIZE)
putInt(ContentResolver.QUERY_ARG_OFFSET, offset)
putString(ContentResolver.QUERY_ARG_SQL_SORT_ORDER, "${MediaStore.MediaColumns.DATE_MODIFIED} DESC")
}

photoCursor = contentResolver.query(
getCursorUri(),
arrayOf(
ID_COLUMN,
PATH_COLUMN
),
bundle,
null
)
}
else {
if (albumItem == null || albumItem.isAll) {
photoCursor = contentResolver.query(
cursorUri,
getCursorUri(),
arrayOf(
ID_COLUMN,
PATH_COLUMN
Expand All @@ -73,7 +111,7 @@ internal class ImagesDataSource(private val contentResolver: ContentResolver){
)
} else {
photoCursor = contentResolver.query(
cursorUri,
getCursorUri(),
arrayOf(
ID_COLUMN,
PATH_COLUMN
Expand All @@ -83,16 +121,25 @@ internal class ImagesDataSource(private val contentResolver: ContentResolver){
"$ORDER_BY LIMIT $PAGE_SIZE OFFSET $offset"
)
}
photoCursor?.isAfterLast ?: return list
photoCursor.doWhile {
}
photoCursor?.isAfterLast ?: return list
photoCursor.doWhile {
try {
val image = photoCursor.getString((photoCursor.getColumnIndex(PATH_COLUMN)))
list.add(ImageItem(image, ImageSource.GALLERY, 0))
}
} finally {
if (photoCursor != null && !photoCursor.isClosed()) {
catch (ex: Exception) {
ex.printStackTrace()
}
}
} finally {
if (photoCursor != null) {
if (!photoCursor.isClosed()) {
photoCursor.close()
}
}
return list
}
}
return list
}

}