Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f6fe28d3 authored by cketti's avatar cketti Committed by Vincent Breitmoser
Browse files

Add Globals class so we can avoid passing Context through layers of code

If your class requires a Context instance make it a constructor argument. Then
create a static factory method that calls Globals.getContext(). The result can
then be passed to the constructor.
This allows testing individual classes using test doubles by directly invoking
the constructor and not having to deal with Globals. For integrated tests
spanning multiple classes you might have to use Globals.setContext().
parent 8b719a32
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
package com.fsck.k9;


import android.content.Context;


public class Globals {
    private static Context context;

    static void setContext(Context context) {
        Globals.context = context;
    }

    public static Context getContext() {
        if (context == null) {
            throw new IllegalStateException("No context provided");
        }

        return context;
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -505,6 +505,7 @@ public class K9 extends Application {

        super.onCreate();
        app = this;
        Globals.setContext(this);

        K9MailLib.setDebugStatus(new K9MailLib.DebugStatus() {
            @Override public boolean enabled() {