My question is not really technical, so there will be no definite right or wrong. For extension functions, I have a package containing a file for every type: Context.kt contains all extension functions for Context, Uri.kt contains all extension functions for Uri and so on.
While refactoring my project, I came across these two functions:
fun Context.getImageSize(uri: Uri): Size? = try {
val bitmapOptions = BitmapFactory.Options()
bitmapOptions.inJustDecodeBounds = true
val inputStream = contentResolver.openInputStream(uri)
BitmapFactory.decodeStream(inputStream, null, bitmapOptions)
Size(bitmapOptions.outWidth, bitmapOptions.outHeight)
} catch (e: ErrnoException) {
null
}
fun Uri.getImageSize(context: Context): Size? = try {
val bitmapOptions = BitmapFactory.Options()
bitmapOptions.inJustDecodeBounds = true
val inputStream = context.contentResolver.openInputStream(this)
BitmapFactory.decodeStream(inputStream, null, bitmapOptions)
Size(bitmapOptions.outWidth, bitmapOptions.outHeight)
} catch (e: ErrnoException) {
null
}
The exact same function, extending a different type. Are there any conventions if a function depends on multiple variables, which type to extend?