Split dialog shells into ui/; move image fetchers to app.net; use shared LastLocationStore; clean imports
- Move Nearby/Username/About shells to app.klottr.ui.CommonDialogsShell - Move Wiki/Fornsok/DM shells to app.klottr.ui.DetailDialogsShell - Extract fetchWikiThumbBitmap to app.klottr.net.WikiThumb - Add app.klottr.net.HttpImage (fetchBitmapFromUrl) and use it from DM dialog - Switch detail dialogs to LastLocationStore.lastKnown (GeoPoint) from shared API - Remove unused imports from MainActivity
This commit is contained in:
24
shared/src/androidMain/kotlin/app/klottr/net/HttpImage.kt
Normal file
24
shared/src/androidMain/kotlin/app/klottr/net/HttpImage.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
package app.klottr.net
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import java.io.BufferedInputStream
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
|
||||
// Enkel (blockerande) hämtning av bitmap från URL. Kör detta på Dispatchers.IO i anroparen.
|
||||
suspend fun fetchBitmapFromUrl(url: String): Bitmap? {
|
||||
return try {
|
||||
val conn = (URL(url).openConnection() as HttpURLConnection).apply {
|
||||
connectTimeout = 7000
|
||||
readTimeout = 7000
|
||||
}
|
||||
conn.inputStream.use { ins ->
|
||||
BufferedInputStream(ins).use { bis ->
|
||||
BitmapFactory.decodeStream(bis)
|
||||
}
|
||||
}
|
||||
} catch (_: Throwable) {
|
||||
null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user