Skip to content
josheroff edited this page Jan 27, 2017 · 16 revisions

#View This is either an Activity or Fragment. These are dumb classes whose only purpose is to hold the references to the widgets from the XML. It simply receives UI events, such as a click, and passes them off to be handled elsewhere (its presenter). There is minimal to no logic in the entire class due to this delegation of responsibility. In addition to the references to the widgets, the View needs a reference to its Presenter, which it gets from the Host component (more on Dagger to come).

Example of a Skeleton View is below. Every portion of this code is necessary:

import ....

/**
* Views must implement their Component-specific Contract's View interface in order to be referenced 
* in the BasePresenter
**/
public class SkeletonFragment extends Fragment implements SkeletonContract.View {

    @Inject
    SkeletonComponent mSkeletonComponent;

    private SkeletonContract.Presenter presenter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ((MainActivity) getActivity()).hostComponent.sliverComponent().inject(this);
        presenter = mSkeletonComponent.presenter();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.main_activity, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ButterKnife.bind(this, view);
        presenter.setView(this);
    }

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

}
Clone this wiki locally