4

I have a problem with dagger, I am trying to understand how it work. I have a custom class that extend of dialog class, So I would like to inject this class in all activitys or fragment for just to show o hide my dialog.

This is my custom class.

public class Loader extends Dialog {

    public static AVLoadingIndicatorView avi;
    public static TextView title;

    @Inject
    public Loader(@ApplicationContext  Context context) {
        super(context, R.style.TransparentProgressDialog);
        this.setContentView(R.layout.loader);
        avi = (AVLoadingIndicatorView) findViewById(R.id.load);
        title = (TextView) findViewById(R.id.title);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    public void setTitle(String t){
        title.setText(t);
    }
}

Note: this class need to a context like parm in the constructor and used a library to show a cool progress.

enter code here
My module class is this.

    @Provides
    @ApplicationContext
    Context provideContext() {
        return mApplication;
    }

    @Provides
    public Loader provideLoader(@ApplicationContext Context context){
        return new Loader(context);
    }

My component.

enter code here
@Singleton
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {

     @ApplicationContext
     Context context();

     Application application();
     PreferencesHelper getPreferences();
     Loader loader();


     void inject(MyFirebaseInstanceIDService myFirebaseInstanceIDService);
     void inject(SplashActivity splashActivity);
     void inject(SignUpActivity signUpActivity);
}

Finally I inject to in my activity.

enter code here
public class SignUpActivity extends AppCompatActivity{

    SignUpContract.Presenter presenter;

    @Inject
    PreferencesHelper preferences;

    @Inject
    Loader loader;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signup);
        ButterKnife.bind(this);


        ((MyApplication) getApplicationContext()).getComponent().inject(this);

        loader.setTitle(getString(R.string.dialog_processing));

        loader.show();

    }
}

I appreciate any help to understand more about dagger. Thanks

 Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
user1153174
  • 133
  • 1
  • 10

0 Answers0