Open tobiasKaminsky opened 6 years ago
So many things depends on getting application context that it might be very hard to release this dependency. One simplification might be to move some parts of logic to ViewModel and bind it with Activity with LiveData.
getApplicationContext() from activity will still be there, but not the hard bound context in MainApp. I am unsure if this is enough...
From Activity yes, but a lot of utils and helpers are using MainApp context. It is reasonable to move that away from them, but nothing that could be done all at once.
I had a deeper look now and the whole static context is so deep into the system that untangling this will be a bit problematic. A lot of static fields in other parts of the code depends on this so hard that those parts become unusable (eg. ProviderMeta)
If we really want to do this, then we would have to initiate those (e.g. ProviderMeta) with a context reference. But then we cannot statically access it...
https://github.com/nextcloud/android/blob/f04f500669b1ea3c9fc85eb022b10f4345ae464e/src/main/java/com/owncloud/android/MainApp.java#L101-L101
Maybe we can avoid this somehow?