Closed bsakai2000 closed 2 years ago
Testing code downloads and displays Google logo, presumably the download portion of this will work for us once I get it into an ApiGetter method
val queue = Volley.newRequestQueue(this)
val imgLdr = ImageLoader(queue, object : ImageLoader.ImageCache {
val cache = LruCache<String, Bitmap>(50)
override fun getBitmap(url: String?): Bitmap? {
return cache.get(url)
}
override fun putBitmap(url: String?, bitmap: Bitmap?) {
cache.put(url, bitmap)
}
})
val elephantArrReq = imgLdr.get(
"https://www.google.com/images/branding/googlelogo/1x/googlelogo_light_color_272x92dp.png",
object : ImageLoader.ImageListener {
override fun onResponse(
response: ImageLoader.ImageContainer,
isImmediate: Boolean
) {
if (isImmediate && (response?.bitmap == null)) return
applicationContext.openFileOutput("path.png", Context.MODE_PRIVATE).use {
val stream = ByteArrayOutputStream()
response.bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
it.write(stream.toByteArray())
}
val myDraw = Drawable.createFromStream(applicationContext.openFileInput("path.png"), "path.png")
println(myDraw)
simpleImageView.setImageDrawable(myDraw)
}
override fun onErrorResponse(err: VolleyError) {
println(err)
}
}
)
General flow should be a call from the UI to DatabaseWrapper.updateDatabase()
, which should call some helper function like private fun DatabaseWrapper.updateProfilePictures()
, which can iterate through the list of Elephant pfps and use something like ApiGetter.downloadImage(url: String, path: String)
for each
Need to check which images are present in filesystem already (#19), could be in downloadImage
but probably better to handle it in updateProfilePictures
, so it won't be covered by this issue. Probably using some combination of context.fileList()
and context.getDir()
but not sure how we access those.
Also should probably refactor the VolleyQueue into a constructor-time class attribute rather than re-generating the queue on every request, especially now that we're using it from multiple places in ApiGetter
Probably using some combination of
context.fileList()
andcontext.getDir()
but not sure how we access those.
Side-stepped the issue by flattening our filesystem. Replace path separator /
with underscore _
when storing in the filesystem. This means everything is in the top-level directory and we don't have to worry about getDir()
Probably using Volley ImageLoader/ImageListener (https://afzaln.com/volley/com/android/volley/toolbox/ImageLoader.html) to download bitmaps, then using local storage (#5) to store them in the filesystem