With landscape view enabled (e.g. e06b2c7) in the app and auto
rotation enabled on the phone, switching between portrait and
landscape orientations leaks instances of MainActivity. This prevents
garbage collection of not just the MainActivity object, but fragments
and other objects referenced by the Activity.
This is caused by repositories, the AppContext instance, the player
service, and authentication code maintaining a reference to the
context which with they are initialized. So rather than initialize
these with an Activity context, pass them the Application context.
Activities are torn down and rebuilt on screen rotation. The
Application context is not.
To enable instantiation of the FavoritedRepository with the
Application context, delay that repository’s initialization until
first use. This ensures the Application context is fully initialized.
It is not fully initialized until the MainActivity has been fully
initialized.
Having changed the context object in CoverArt from a received function
parameter to an initialization time derived variable, withContext no
longer needs a Context parameter.
That leaves the method misnamed. So rename withContext ->
requestCreator and drop the first parameter.
Address "java.lang.IllegalStateException: Too many receivers"
exceptions. (See Issue #145). Each new Picasso object registers its
own NetworkBroadcastReceiver. Worse, we create a new Picasso object
each time we transform an AlbumCover image. So do not create
unnecessary Picasso objects.
Rather than depend on receiving a Context object when called to load
an cover art, fetch the Application context as returned from FFA.get()
at singleton construction time. The Application context is long
lived.
This has an additional advantage. Not generation new Picasso objects
for each CoverArt image avoids holding a reference to an object that
cannot, later, be garbage collected.
Migrate startActivityForResult/onActivityResult to
StartActivityForResult/registerForActivityResult in
LoginActivity/OAuth.
This moves responsibility for scheduling the starting Intent from
OAuth to LoginActivity.
OAuth still generates the Intent. But instead of starting the intent
directly in OAuth, the intent is returned to LoginActivity. This
better associates processing the activity result with its invocation.
OAuthTest module updated to accommodate internal API change.