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

Add JFrog Configuration To Replace JCenter #25

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix Crash on Android 11 #23
  • Loading branch information
Yazan Tarifi committed Apr 29, 2021
commit d8d692b148517e5dad25caa39c256fd91ec9f9e2
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -39,5 +39,5 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.opensooq:gligar:1.1.1'
implementation project(":gligar")
}
Original file line number Diff line number Diff line change
@@ -2,7 +2,10 @@ package com.opensooq.supernova.gligar.dataSource

import android.content.ContentResolver
import android.database.Cursor
import android.os.Build
import android.os.Bundle
import android.provider.MediaStore
import androidx.annotation.RequiresApi
import androidx.paging.PositionalDataSource
import com.opensooq.OpenSooq.ui.imagePicker.model.AlbumItem
import com.opensooq.OpenSooq.ui.imagePicker.model.ImageItem
@@ -55,40 +58,61 @@ internal class ImagesDataSource(private val contentResolver: ContentResolver){
return list
}

private fun getCurserQuery(albumItem: AlbumItem?, offset: Int): Cursor? {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val queryBundle = Bundle().apply {
putInt(ContentResolver.QUERY_ARG_LIMIT, PAGE_SIZE)
putInt(ContentResolver.QUERY_ARG_OFFSET, offset)
putString(ContentResolver.QUERY_ARG_SQL_SORT_ORDER, ORDER_BY)
}

if (!(albumItem == null || albumItem.isAll)) {
queryBundle.putString(ContentResolver.QUERY_ARG_SQL_SELECTION, "${MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME} =?")
queryBundle.putStringArray(ContentResolver.QUERY_ARG_SQL_SELECTION_ARGS, arrayOf(albumItem.name))
}

return contentResolver.query(
cursorUri,
getSelectionProjection(),
queryBundle,
null
)
} else {
return if (albumItem == null || albumItem.isAll) {
contentResolver.query(cursorUri, getSelectionProjection(), null, null, ORDER_BY + " LIMIT $PAGE_SIZE" + " OFFSET $offset")
} else {
contentResolver.query(cursorUri, getSelectionProjection(), "${MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME} =?", arrayOf(albumItem.name), ORDER_BY + " LIMIT $PAGE_SIZE" + " OFFSET $offset")
}
}
} catch (ex: Exception) {
print("III :: ${ex.message}")
ex.printStackTrace()
return null
}
}

private fun getSelectionProjection(): Array<String> {
return arrayOf(ID_COLUMN, PATH_COLUMN)
}

fun loadAlbumImages(
albumItem: AlbumItem?,
page: Int,
supportedImages: String? = null,
preSelectedImages: Array<out String?>? = null
): ArrayList<ImageItem> {
val offset = page * PAGE_SIZE
val list: ArrayList<ImageItem> = arrayListOf()
var photoCursor: Cursor? = null
val list: ArrayList<ImageItem> = ArrayList()
try {
if (albumItem == null || albumItem.isAll) {
photoCursor = contentResolver.query(
cursorUri,
arrayOf(
ID_COLUMN,
PATH_COLUMN
),
null,
null,
"$ORDER_BY LIMIT $PAGE_SIZE OFFSET $offset"
)
} else {
photoCursor = contentResolver.query(
cursorUri,
arrayOf(
ID_COLUMN,
PATH_COLUMN
),
"${MediaStore.Images.ImageColumns.BUCKET_ID} =?",
arrayOf(albumItem.bucketId),
"$ORDER_BY LIMIT $PAGE_SIZE OFFSET $offset"
)
val offset = page * PAGE_SIZE
photoCursor = getCurserQuery(albumItem, offset)

photoCursor?.isAfterLast
if (photoCursor == null) {
return list
}
photoCursor?.isAfterLast ?: return list

while(photoCursor.moveToNext()) {
val image = photoCursor.getString((photoCursor.getColumnIndex(PATH_COLUMN)))
if (supportedImages != null) {
@@ -108,6 +132,9 @@ internal class ImagesDataSource(private val contentResolver: ContentResolver){
}
}
}
} catch (ex: Exception) {
println("III :: ${ex.message}")
ex.printStackTrace()
} finally {
if (photoCursor != null && !photoCursor.isClosed()) {
photoCursor.close()
Original file line number Diff line number Diff line change
@@ -118,15 +118,16 @@ internal class PickerViewModel(private val savedStateHandle: SavedStateHandle) :
}
}

private suspend fun getImages() = withContext(Dispatchers.Default) {
if (!TextUtils.equals(supportedImages, ALL_TYPES)) {
mImageDataSource.loadAlbumImages(mSelectedAlbum, mPage, supportedImages, preSelectedImages)
} else {
mImageDataSource.loadAlbumImages(mSelectedAlbum, mPage, null, preSelectedImages)
private suspend fun getImages(): ArrayList<ImageItem> {
return withContext(Dispatchers.IO) {
if (!TextUtils.equals(supportedImages, ALL_TYPES)) {
mImageDataSource.loadAlbumImages(mSelectedAlbum, mPage, supportedImages, preSelectedImages)
} else {
mImageDataSource.loadAlbumImages(mSelectedAlbum, mPage, null, preSelectedImages)
}
}
}


private suspend fun getAlbums() = withContext(Dispatchers.Default) {
mImageDataSource.loadAlbums()
}