Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error with Fragment parent #84

Open
renaudfavier opened this issue Dec 13, 2016 · 2 comments
Open

Compilation error with Fragment parent #84

renaudfavier opened this issue Dec 13, 2016 · 2 comments

Comments

@renaudfavier
Copy link

Hello,

I followed this example : https://github.com/soundcloud/lightcycle/blob/master/lightcycle-lib/src/main/java/com/soundcloud/lightcycle/LightCycleSupportFragment.java
to build my parent class wich will be inherited by all fragments :

public abstract class M360LightCycleSupportFragment<FragmentType extends M360Fragment> extends M360Fragment implements LightCycleDispatcher<SupportFragmentLightCycle<FragmentType>> {

    private final SupportFragmentLightCycleDispatcher<FragmentType> lifeCycleDispatcher;
    private boolean bound;

    public M360LightCycleSupportFragment() {
        lifeCycleDispatcher = new SupportFragmentLightCycleDispatcher<>();
    }

    @Override
    public void bind(SupportFragmentLightCycle<FragmentType> lifeCycleComponent) {
        Preconditions.checkBindingTarget(lifeCycleComponent);
        lifeCycleDispatcher.bind(lifeCycleComponent);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        bindIfNecessary();
        lifeCycleDispatcher.onAttach(fragment(), activity);
    }

    private void bindIfNecessary() {
        if (!bound) {
            LightCycles.bind(this);
            bound = true;
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        lifeCycleDispatcher.onCreate(fragment(), savedInstanceState);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        lifeCycleDispatcher.onViewCreated(fragment(), view, savedInstanceState);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        lifeCycleDispatcher.onActivityCreated(fragment(), savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
        lifeCycleDispatcher.onStart(fragment());
    }

    @Override
    public void onResume() {
        super.onResume();
        lifeCycleDispatcher.onResume(fragment());
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return lifeCycleDispatcher.onOptionsItemSelected(fragment(), item);
    }

    @Override
    public void onPause() {
        lifeCycleDispatcher.onPause(fragment());
        super.onPause();
    }

    @Override
    public void onStop() {
        lifeCycleDispatcher.onStop(fragment());
        super.onStop();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        lifeCycleDispatcher.onSaveInstanceState(fragment(), outState);
        super.onSaveInstanceState(outState);
    }

    @Override
    public void onDestroyView() {
        lifeCycleDispatcher.onDestroyView(fragment());
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        lifeCycleDispatcher.onDestroy(fragment());
        super.onDestroy();
    }

    @Override
    public void onDetach() {
        lifeCycleDispatcher.onDetach(fragment());
        super.onDetach();
    }

    @SuppressWarnings("unchecked")
    private FragmentType fragment() {
        return (FragmentType) this;
    }
}

Then my Fragment :

public class ProgramDetailsFragment extends M360LightCycleSupportFragment<ProgramDetailsFragment> {


    @LightCycle
    final ProgramPresenter programPresenter = new ProgramPresenter();

 [...]

my Controller :

public class ProgramPresenter extends DefaultSupportFragmentLightCycle<ProgramDetailsFragment> {

    private static final String TAG = "ProgramPresenter";

    @Override
    public void onAttach(ProgramDetailsFragment fragment, Activity activity) {
        Log.i(TAG, "onAttach");
        super.onAttach(fragment, activity);
    }

[...]

when I extends this class in my code I obtain the following error at compilation :
Error:(5, 63) error: cannot find symbol class FragmentType

Is there something I didn't understand ? It feels like it won't be possible

A gist of a working 'parent fragment dispatcher' - 'inherited fragment' - 'controller' would be the perfect resource for me, maybe it already exists.

Thank you all,

@renaudfavier
Copy link
Author

Hello,

Looks like I had to add implements LightCycleDispatcher<SupportFragmentLightCycle<ProgramDetailsFragment>> to my child fragment :

public class ProgramDetailsFragment extends M360LightCycleSupportFragment<ProgramDetailsFragment> implements LightCycleDispatcher<SupportFragmentLightCycle<ProgramDetailsFragment>> {


    @LightCycle
    final ProgramPresenter programPresenter = new ProgramPresenter();

 [...]

I think it's what you were refering in the doc :

Implement the LightCycleDispatcher interface. Note: The processor needs to know the exact type being dispatched, so if your base activity is templated then the activities inheriting from it must explicitly implements LightCycleDispatcher<ActivityLightCycle> (for more details, refer to #49)

@NikoYuwono
Copy link
Contributor

NikoYuwono commented Dec 14, 2016

@renaudfavier Yes, unfortunately it's one of the current processor limitation and we're trying to fix it in the next 2.0 release! (Please join the discussion here)
As you already noticed you need to add

implements LightCycleDispatcher<SupportFragmentLightCycle<ProgramDetailsFragment>>

So the processor can know what type will be dispatched. Currently the processor only recognize these types

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

No branches or pull requests

2 participants