This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"photos":{ | |
"page":1, | |
"pages":193, | |
"perpage":100, | |
"total":"19211", | |
"photo":[ | |
{ | |
"id":"49809118937", | |
"owner":"62416743@N08", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class ApiResponse( | |
val photos: PhotoListResponse, | |
val stat: String | |
) | |
data class PhotoListResponse( | |
val page: Int, | |
val pages: Int, | |
val perPage: Int, | |
val total: Int, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
NewerOlder