Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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.

Add @RootFragment annotation for @EBean #1636

Copy link
Copy link
@LouisCAD

Description

@LouisCAD
Issue body actions

Hi!

Currently, the only way to access the parent Fragment in an @EBean is by writing a setter in the bean manually, or by making a @FragmentById/@FragmentByTag public in the @RootContextannotated Activity. The code is not that beautiful, so why not create an @RootFragment annotation?

It would work the same way as @RootContext, excepted that it would not need to be re-injected if the Fragment instance is retained (see setRetainInstance() & getRetainInstance()) and the field is annotated with NonConfigurationInstance when config changes occurs (screen rotation, locale change, etc) as the Fragment itself (only it's View hierarchy) is not destroyed if retained.

Examples speak better than words, so here's how it would look like:

@EBean
public class MyRecyclerView extends RecyclerView.Adapter {

    @RootFragment
    MyEFragment mFragment;

    // I can now access the fragment, it's @InstanceState members,
    // and keep easily my adapter state, such as selected items
}

Below are the quotes to "help" implementation, from Gitter:

  • @WonderCsabo: the problem is that it is not trivial to implement
  • @LouisCAD: What would be the hard part(s)? Wouldn't it work by adding a setFragment_(MyEFragment fragment) call in onCreate() for all @ebeans in MyEFragment containing an @rootfragment field?
  • @WonderCsabo: Yeah, it is not too hard, that was an overstatement.

I'm on the way to learn how Annotation Processors work under the hood, so I hope I'll be able to add this myself (If I begin working on this, I'll post updates here), but if in the meantime, someone with the skills wants to add this new feature, I'd be very grateful (and I hope I would not be the only one).

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.