Ali
03/31/2022, 3:32 PMAdam Powell
03/31/2022, 3:37 PMIgor Milakovic
03/31/2022, 3:39 PMval resId = context.resources.getIdentifier(
"your/image/path",
"drawable",
context.packageName
)
So you would have a plain string in the repository, but you can retrieve the actual identifier where you have access to the ContextAli
03/31/2022, 3:43 PMAli
03/31/2022, 3:44 PMIgor Milakovic
03/31/2022, 3:46 PMIgor Milakovic
03/31/2022, 3:48 PMIgor Milakovic
03/31/2022, 3:50 PMres/drawable
? Or does the image come from web? I mean, either way, you should be able to work with String in the repo and load/convert/process/whatever you need to do with Context outside of the repoAli
03/31/2022, 3:50 PMAli
03/31/2022, 3:52 PMMaybe I'm misunderstanding your use case - is the image bundled with the app, in theyes. Its fallback image incase no network?res/drawable
Igor Milakovic
03/31/2022, 3:52 PMIgor Milakovic
03/31/2022, 3:52 PMAli
03/31/2022, 3:56 PMIgor Milakovic
03/31/2022, 4:06 PMnull
or nothing from the repository in which case presentation layer can show the placeholder image. Alternatively, you can actually start with the placeholder image and replace it with an actual image if/when you get it from the repo. Depending on your logic, but I don't think repo should be responsible for this.
Like, you can load images in two ways:
1. Show placeholder right away and only replace it if you get an actual image from the repo
2. Show loading indicator while waiting and then replace it with an actual image or a placeholder image.
In my opinion, in either case repo shouldn't know or care about how you want to present your image to the userAli
03/31/2022, 4:17 PMIgor Milakovic
03/31/2022, 4:41 PMAdam Powell
03/31/2022, 5:46 PMresources.getIdentifier
outside of debugging code paths. It's extremely slow.Igor Milakovic
03/31/2022, 5:51 PMAli
04/01/2022, 7:56 AMAppCompatResources.getDrawable(context, R.drawable.image)