Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

RoboGuice problem #1368

Closed
Closed

Description

@dmitrikudrenko

I created listener and indicated it in my Activity:

@EActivity(R.layout.activity_currency)
@RoboGuice(value = {FlurrySessionListener.class})

Listener:

public class FlurrySessionListener {
    @Inject
    Context context;

    public void onStartSession(@Observes OnStartEvent event) {
        FlurryAgent.onStartSession(context, getApiKey(context));
    }

    public void onStopSession(@Observes OnStopEvent event) {
        FlurryAgent.onEndSession(context);
    }

    protected String getApiKey(Context context) {
        return context.getResources().getString(R.string.flurry_api_key);
    }
}

But on build there is an error:
Error:(23, 58) error: expected
Error:(70, 29) error: '{' expected
Error:(290, 2) error: reached end of file while parsing

It is problem in import in Activity_:
import com.delphin.currency.flurry.FlurrySessionListener.class;

Activity

  1. WonderCsabo commented on Apr 17, 2015

    @WonderCsabo
    Member

    What is the version of AA you are using? What is the RoboGuice version?

    Can you paste the generated class?

  2. dmitrikudrenko commented on Apr 17, 2015

    @dmitrikudrenko
    Author

    AA - 3.2. RoboGuice - 2.0

  3. WonderCsabo commented on Apr 17, 2015

    @WonderCsabo
    Member

    And can you copy the generated class here?

  4. dmitrikudrenko commented on Apr 17, 2015

    @dmitrikudrenko
    Author
    package com.delphin.currency.ui;
    
    import java.util.HashMap;
    import android.content.Context;
    import android.content.Intent;
    import android.content.res.Configuration;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.CheckBox;
    import android.widget.CompoundButton;
    import android.widget.CompoundButton.OnCheckedChangeListener;
    import android.widget.TextView;
    import com.delphin.currency.R.id;
    import com.delphin.currency.R.layout;
    import com.delphin.currency.R.string;
    import com.delphin.currency.flurry.FlurrySessionListener.class;
    import com.delphin.currency.helper.Calculator_;
    import com.delphin.currency.helper.ColorHelper_;
    import com.delphin.currency.helper.CurrencyFormatter_;
    import com.delphin.currency.model.PairCourse;
    import com.delphin.currency.notification.CurrencyNotificationManager_;
    import com.delphin.currency.otto.OttoBus_;
    import com.delphin.currency.storage.Storage_;
    import com.google.inject.Inject;
    import com.google.inject.Key;
    import com.squareup.otto.Subscribe;
    import org.androidannotations.api.builder.ActivityIntentBuilder;
    import org.androidannotations.api.roboguice.RoboGuiceHelper;
    import org.androidannotations.api.view.HasViews;
    import org.androidannotations.api.view.OnViewChangedListener;
    import org.androidannotations.api.view.OnViewChangedNotifier;
    import roboguice.RoboGuice;
    import roboguice.activity.event.OnActivityResultEvent;
    import roboguice.activity.event.OnConfigurationChangedEvent;
    import roboguice.activity.event.OnContentChangedEvent;
    import roboguice.activity.event.OnCreateEvent;
    import roboguice.activity.event.OnDestroyEvent;
    import roboguice.activity.event.OnNewIntentEvent;
    import roboguice.activity.event.OnPauseEvent;
    import roboguice.activity.event.OnRestartEvent;
    import roboguice.activity.event.OnResumeEvent;
    import roboguice.activity.event.OnStartEvent;
    import roboguice.activity.event.OnStopEvent;
    import roboguice.event.EventManager;
    import roboguice.inject.ContentViewListener;
    import roboguice.inject.ContextScope;
    import roboguice.inject.RoboInjector;
    import roboguice.util.RoboContext;
    
    public final class CurrencyActivity_
        extends CurrencyActivity
        implements HasViews, OnViewChangedListener, RoboContext
    {
    
        private final OnViewChangedNotifier onViewChangedNotifier_ = new OnViewChangedNotifier();
        private ContextScope scope_;
        protected HashMap<Key<?> , Object> scopedObjects_;
        protected EventManager eventManager_;
        @Inject
        ContentViewListener ignored_;
        @SuppressWarnings("unused")
        @Inject
        private class listener1_;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            OnViewChangedNotifier previousNotifier = OnViewChangedNotifier.replaceNotifier(onViewChangedNotifier_);
            init_(savedInstanceState);
            super.onCreate(savedInstanceState);
            OnViewChangedNotifier.replaceNotifier(previousNotifier);
            setContentView(layout.activity_currency);
        }
    
        private void init_(Bundle savedInstanceState) {
            storage = new Storage_(this);
            scopedObjects_ = new HashMap<Key<?> , Object>();
            RoboInjector injector_ = RoboGuice.getInjector(this);
            scope_ = injector_.getInstance(ContextScope.class);
            eventManager_ = injector_.getInstance(EventManager.class);
            injector_.injectMembersWithoutViews(this);
            eventManager_.fire(new OnCreateEvent(savedInstanceState));
            OnViewChangedNotifier.registerOnViewChangedListener(this);
            Resources resources_ = this.getResources();
            formatEurToUsd = resources_.getString(string.format_eur_to_usd);
            currencyWithDiff = resources_.getString(string.currency_with_diff);
            ottoBus = OttoBus_.getInstance_(this);
            calculator = Calculator_.getInstance_(this);
            currencyFormatter = CurrencyFormatter_.getInstance_(this);
            notificationManager = CurrencyNotificationManager_.getInstance_(this);
            colorHelper = ColorHelper_.getInstance_(this);
        }
    
        @Override
        public void setContentView(int layoutResID) {
            super.setContentView(layoutResID);
            onViewChangedNotifier_.notifyViewChanged(this);
        }
    
        @Override
        public void setContentView(View view, LayoutParams params) {
            super.setContentView(view, params);
            onViewChangedNotifier_.notifyViewChanged(this);
        }
    
        @Override
        public void setContentView(View view) {
            super.setContentView(view);
            onViewChangedNotifier_.notifyViewChanged(this);
        }
    
        public static CurrencyActivity_.IntentBuilder_ intent(Context context) {
            return new CurrencyActivity_.IntentBuilder_(context);
        }
    
        public static CurrencyActivity_.IntentBuilder_ intent(android.app.Fragment fragment) {
            return new CurrencyActivity_.IntentBuilder_(fragment);
        }
    
        public static CurrencyActivity_.IntentBuilder_ intent(android.support.v4.app.Fragment supportFragment) {
            return new CurrencyActivity_.IntentBuilder_(supportFragment);
        }
    
        @Override
        public void onRestart() {
            super.onRestart();
            eventManager_.fire(new OnRestartEvent());
        }
    
        @Override
        public void onStart() {
            super.onStart();
            eventManager_.fire(new OnStartEvent());
        }
    
        @Override
        public void onResume() {
            super.onResume();
            eventManager_.fire(new OnResumeEvent());
        }
    
        @Override
        public void onPause() {
            super.onPause();
            eventManager_.fire(new OnPauseEvent());
        }
    
        @Override
        public void onNewIntent(Intent intent) {
            super.onNewIntent(intent);
            setIntent(intent);
            eventManager_.fire(new OnNewIntentEvent());
        }
    
        @Override
        public void setIntent(Intent newIntent) {
            super.setIntent(newIntent);
        }
    
        @Override
        public void onStop() {
            try {
                eventManager_.fire(new OnStopEvent());
            } finally {
                super.onStop();
            }
        }
    
        @Override
        public void onDestroy() {
            try {
                eventManager_.fire(new OnDestroyEvent());
            } finally {
                try {
                    RoboGuice.destroyInjector(this);
                } finally {
                    super.onDestroy();
                }
            }
        }
    
        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            Configuration currentConfig = getResources().getConfiguration();
            super.onConfigurationChanged(newConfig);
            eventManager_.fire(new OnConfigurationChangedEvent(currentConfig, newConfig));
        }
    
        /**
         * We cannot simply copy the code from RoboActivity, because that can cause classpath issues. For further details see issue #1116.
         * 
         */
        @Override
        public void onContentChanged() {
            super.onContentChanged();
            synchronized(ContextScope.class)
            {
                scope_.enter(this);
                try {
                    RoboGuiceHelper.callInjectViews(this);
                } finally {
                    scope_.exit(this);
                }
            }
            eventManager_.fire(new OnContentChangedEvent());
        }
    
        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            eventManager_.fire(new OnActivityResultEvent(requestCode, resultCode, data));
        }
    
        @Override
        public HashMap<Key<?> , Object> getScopedObjectMap() {
            return scopedObjects_;
        }
    
        @Override
        public void onViewChanged(HasViews hasViews) {
            notificationVisibility = ((CheckBox) hasViews.findViewById(id.notification_visibility));
            usdRub = ((TextView) hasViews.findViewById(id.usd_rub));
            eurUsd = ((TextView) hasViews.findViewById(id.eur_usd));
            oilRub = ((TextView) hasViews.findViewById(id.oil_rub));
            eurRub = ((TextView) hasViews.findViewById(id.eur_rub));
            oil = ((TextView) hasViews.findViewById(id.oil));
            if (notificationVisibility!= null) {
                notificationVisibility.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
    
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        CurrencyActivity_.this.onNotificationVisibilityChanged(isChecked);
                    }
    
                }
                );
            }
            afterViews();
        }
    
        @Subscribe
        @Override
        public void onCourseUpdate(final PairCourse courses) {
            CurrencyActivity_.super.onCourseUpdate(courses);
        }
    
        public static class IntentBuilder_
            extends ActivityIntentBuilder<CurrencyActivity_.IntentBuilder_>
        {
    
            private android.app.Fragment fragment_;
            private android.support.v4.app.Fragment fragmentSupport_;
    
            public IntentBuilder_(Context context) {
                super(context, CurrencyActivity_.class);
            }
    
            public IntentBuilder_(android.app.Fragment fragment) {
                super(fragment.getActivity(), CurrencyActivity_.class);
                fragment_ = fragment;
            }
    
            public IntentBuilder_(android.support.v4.app.Fragment fragment) {
                super(fragment.getActivity(), CurrencyActivity_.class);
                fragmentSupport_ = fragment;
            }
    
            @Override
            public void startForResult(int requestCode) {
                if (fragmentSupport_!= null) {
                    fragmentSupport_.startActivityForResult(intent, requestCode);
                } else {
                    if (fragment_!= null) {
                        fragment_.startActivityForResult(intent, requestCode);
                    } else {
                        super.startForResult(requestCode);
                    }
                }
            }
    
        }
    
    }
  5. dmitrikudrenko commented on Apr 17, 2015

    @dmitrikudrenko
    Author

    As you can see variable listener1_ has type "class" instead of FlurrySessionListener

  6. WonderCsabo commented on Apr 17, 2015

    @WonderCsabo
    Member

    Thanks for posting the code. This is indeed a bug. I'll look into it soon.

  7. self-assigned this
    on Apr 17, 2015
  8. WonderCsabo commented on Apr 17, 2015

    @WonderCsabo
    Member

    I just tried with the latest AndroidAnnotations 3.3-SNAPSHOT build, and i cannot reproduce. Can you try that version? Please note you will have to use at least RoboGuice 3.0.

  9. dmitrikudrenko commented on Apr 17, 2015

    @dmitrikudrenko
    Author

    I published test project with the error reproducing. Link: https://github.com/ray1984/AA-RoboGuice_TestProject and some proves
    1
    2
    3

    In build.gradle you can see usage of AA-3.3-SNAPHOT & RG-3.0

  10. WonderCsabo commented on Apr 17, 2015

    @WonderCsabo
    Member

    Thanks for taking the time for creating the test project! I can reproduce the problem. I think i have a fix. Can you try this branch?

  11. dmitrikudrenko commented on Apr 18, 2015

    @dmitrikudrenko
    Author

    How can I connect that branch by gradle without downloading and building whole project?

  12. WonderCsabo commented on Apr 18, 2015

    @WonderCsabo
    Member
  13. WonderCsabo commented on Apr 18, 2015

    @WonderCsabo
    Member
  14. dmitrikudrenko commented on Apr 18, 2015

    @dmitrikudrenko
    Author

    Yeah, it would be the best

  15. dmitrikudrenko commented on Apr 18, 2015

    @dmitrikudrenko
    Author

    OK, I compiled your fork and it works. I commited changes in my test project, you can watch it

  16. WonderCsabo commented on Apr 18, 2015

    @WonderCsabo
    Member

    I've just uploaded the binaries to a Maven Repo. 😑 Repo url is: https://raw.github.com/WonderCsabo/MavenRepo/master

    I am glad you managed to compile the branch, and it solves the problem for you.

  17. dmitrikudrenko commented on Apr 18, 2015

    @dmitrikudrenko
    Author

    It's usefull too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions