Skip to content

Instantly share code, notes, and snippets.

View kelmer44's full-sized avatar
🤔

Gabriel Sanmartín kelmer44

🤔
View GitHub Profile
{
"photos":{
"page":1,
"pages":193,
"perpage":100,
"total":"19211",
"photo":[
{
"id":"49809118937",
"owner":"62416743@N08",
data class ApiResponse(
val photos: PhotoListResponse,
val stat: String
)
data class PhotoListResponse(
val page: Int,
val pages: Int,
val perPage: Int,
val total: Int,
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'androidx.core:core-ktx:1.1.0'
// Jetpack Architecture Components
implementation "androidx.lifecycle:lifecycle-extensions:2.1.0"
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'androidx.core:core-ktx:1.1.0'
// Reactive Programming
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'androidx.core:core-ktx:1.1.0'
// Reactive Programming
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'androidx.core:core-ktx:1.1.0'
// Reactive Programming
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'androidx.core:core-ktx:1.1.0'
// Reactive Programming
private fun decodeFile(f: File, height: Int): Bitmap? {
try {
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
BitmapFactory.decodeStream(FileInputStream(f), null, options)
// Width and height of the bitmap
val bmpWidth = options.outWidth
private fun getBitmap(url: String, height: Int): Bitmap? {
return try {
val imageUrl = URL(url)
val connection = imageUrl.openConnection() as HttpURLConnection
connection.instanceFollowRedirects = true
val inputStream = connection.inputStream
val outputStream = FileOutputStream(f)
copyStream(inputStream, outputStream)
outputStream.close()
private val executor: ExecutorService = Executors.newSingleThreadExecutor()
private val handler: Handler = Handler(Looper.getMainLooper())
interface Callback {
fun onFinished(photoListPage: PhotoListPage)
}
private val adapter = PhotoAdapter()
override fun search(term: String, page: Int, callback: Callback) {
executor.submit {
val apiResponse = flickrService.search(apiKey, term, PERPAGE, page)
callback.onFinished(PhotoListPage(term, page, apiResponse.photos.photo.map(adapter::convert), page < apiResponse.photos.pages))