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.

@ReceiverAction should allow for multiple values #1232

Closed

Description

@djMax

If a single method wants to receive multiple broadcast messages.

Activity

  1. WonderCsabo commented on Nov 11, 2014

    @WonderCsabo
    Member

    Yep, @Receiver already supports multiple actions, @ReceiverAction should do the same.

    @dodgex WDYT?

  2. dodgex commented on Nov 11, 2014

    @dodgex
    Member

    yeah, makes sense.

    i wonder if there is a good reason why the generated class is like

    public final class MusicIntentReceiver_
        extends MusicIntentReceiver
    {
    
        private Context context_;
        public final static String ACTION_ON_MEDIA_BUTTON = "android.intent.action.MEDIA_BUTTON";
        public final static String ANDROID_INTENT_EXTRA_KEYEVENT_EXTRA = "android.intent.extra.KEY_EVENT";
        @Override
        public void onReceive(Context context, Intent intent) {
            context_ = context;
            super.onReceive(context, intent);
            String action = intent.getAction();
            String dataScheme = intent.getScheme();
            if (ACTION_ON_MEDIA_BUTTON.equals(action)) {
                Bundle extras_ = ((intent.getExtras()!= null)?intent.getExtras():new Bundle());
                KeyEvent keyEvent = extras_.getParcelable(ANDROID_INTENT_EXTRA_KEYEVENT_EXTRA);
                MusicIntentReceiver_.this.onMediaButton(context, keyEvent);
                return ;
            }
        }
    }

    instead of

    public final class MusicIntentReceiver_
        extends MusicIntentReceiver
    {
    
        private Context context_;
    
        @Override
        public void onReceive(Context context, Intent intent) {
            context_ = context;
            super.onReceive(context, intent);
            String action = intent.getAction();
            String dataScheme = intent.getScheme();
            if ("android.intent.action.MEDIA_BUTTON".equals(action)) {
                Bundle extras_ = ((intent.getExtras()!= null)?intent.getExtras():new Bundle());
                KeyEvent keyEvent = extras_.getParcelable("android.intent.extra.KEY_EVENT");
                MusicIntentReceiver_.this.onMediaButton(context, keyEvent);
                return ;
            }
        }
    }

    i mean: why add public final static fields if the string could be used directly?

  3. WonderCsabo commented on Nov 11, 2014

    @WonderCsabo
    Member

    Because it is a good coding practice? We also do this in other places, for example @Extra.

  4. dodgex commented on Nov 11, 2014

    @dodgex
    Member

    okay. i think we can implement the action the same way i did for dataSchemes...

    there we get

    public final static String ACTION_ON_MEDIA_BUTTONX =  "android.intent.action.MEDIA_BUTTON";
    public final static List<String> DATA_SCHEMES_ON_MEDIA_BUTTONX = Arrays.asList("x");
    
    if (ACTION_ON_MEDIA_BUTTONX.equals(action)&&DATA_SCHEMES_ON_MEDIA_BUTTONX.contains(dataScheme)) {
      // stuff
    }

    the new code would be like

    public final static List<String>ACTION_ON_MEDIA_BUTTONX = Arrays.asList("android.intent.action.MEDIA_BUTTON");
    public final static List<String> DATA_SCHEMES_ON_MEDIA_BUTTONX = Arrays.asList("x");
    
    if (ACTION_ON_MEDIA_BUTTONX.contains(action)&&DATA_SCHEMES_ON_MEDIA_BUTTONX.contains(dataScheme)) {
      // stuff
    }
  5. WonderCsabo commented on Nov 11, 2014

    @WonderCsabo
    Member

    Yeah, that can work. @yDelouis do you agree?

  6. yDelouis commented on Nov 11, 2014

    @yDelouis
    Contributor

    Sure.

  7. WonderCsabo commented on Nov 11, 2014

    @WonderCsabo
    Member

    Guys, feel free to contribute the feature.

  8. dodgex commented on Nov 11, 2014

    @dodgex
    Member

    @yDelouis ok. already working on it. and i'll add a little optimization to not create a list for only 1 item.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions