-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PostCapture screen implementation with in memory Image storage #32
base: main
Are you sure you want to change the base?
Conversation
TODOs for later - Use image orientation from the transform data of ImageProxy - Scale image to fit screen width/height - Overlay buttons for saving/discarding - Async listening for image to be ready (might be needed for lower end devices)
/** | ||
* Used to store a single [Image]. | ||
*/ | ||
interface ImageCache { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: You can replace the set/get with a var
interface ImageCache {
var image: Bitmap?
}
class ImageCacheImpl : ImageCache {
override var image: Bitmap?
get() = TODO("Not yet implemented")
set(value) {}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it makes it cleaner / simpler to rely on a image loading library to manage all this for you.
So if you're using Coil for example, you will want to take the JPEG byte array and save that somewhere
Then in you're Composable you can use AsyncImage and in it's ImageRequest use .data(jpegByteArray)
You can then tie to a custom fetcher (I got this from coil-kt/coil#171 (comment))
class ByteArrayFetcher : Fetcher<ByteArray> {
override fun key(data: ByteArray): String? = null
override suspend fun fetch(
pool: BitmapPool,
data: ByteArray,
size: Size,
options: Options
): FetchResult {
return SourceResult(
source = ByteArrayInputStream(data).source().buffer(),
mimeType = null,
dataSource = DataSource.MEMORY
)
}
}
Register the new fetcher -- add to ComponentRegistry when creating the ImageLoader
Now you should get more efficient bitmap pool management as well, resizing, rotation handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't currently navigate back after a successful image capture
) | ||
} | ||
composable(SettingsRoute) { SettingsScreen(navController = navController) } | ||
composable(PostCaptureRoute) { PostCaptureScreen( | ||
onBackPressed = { navController.navigateUp() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we'd only be navigating to this page from within the app, we can just use .popBackStack()
they behave the same, except when using navigateUp()
will return to the other app that brought you to a page. wont have to worry about that here.
Regardless, right now we can't use either without the app crashing (after rebinding use cases), i found that to be the case when navigating back to preview from the settings page. A quick fix for this is to just use navController.navigate(PreviewRoute)
, though the bug causing this issue should still be addressed; i think we have already touched on it.
There are some issues with orientation of the image captured. front-facing camera is mirrored, and the rear-facing camera is upside-down |
implementation("androidx.hilt:hilt-navigation-compose:1.0.0") | ||
|
||
// Compose - Testing | ||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does compose_version come from? Other packages just use:
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
TODOs for later