Short answer: yes, but you shouldn't
If you absolutely must:
You can wrap the async calls in the Firebase API by using CountDownLatch
to create your own Future
implementation. Future
is a Java Interface similar to Promises in JavaScript, which allow you to pass around the "future result" of an async computation until you absolutely need it.
Check this StackOverflow answer for a sample implementation.
You would then implement your "Adapter-like class" with this wrapper, which would return a Future
, and the methods in your class would return future.get()
. This call blocks the thread which executes it and when the Future
resolves, the call evaluates to the value contained in the Future
("unwrapping" it).
Here's why you shouldn't:
- In Android, it's usually a Very Bad Idea to block the UI thread, so if your current Adapter is already a synchronous call, it will keep blocking until the Firebase query finishes.
- If you are already blocking the UI thread with your SQLite queries, and think you might be fine because of that, consider the possibility that this is not a problem now just because the SQLite queries are too fast for it to matter. When you switch to Firestore, the queries are likely to take much longer on average and have way more variance in their response time due to different network conditions, etc.
- If it's not very unfeasible to consider refactoring to use the async APIs, seriously consider it. Your queries are going to take longer now and you might need "loading" indicators anyway, so using the async APIs will help with that. You may also see opportunities to run queries in parallel when you need both but they don't depend on each other, and keeping it async allows you to do that.
- This might not have mattered before if the queries were fast enough that sequential vs. parallel didn't matter much, but now it may.