public class ContentListFragment extends BaseFragment {

    private static final String ARG_USER = "user";
    private static final String ARG_REPO = "repo";

    @Inject
    ContentListFragmentViewModel viewModel;

    public ContentListFragment() {
        // Required empty public constructor
    }

    public static ContentListFragment newInstance(String param1, String param2) {
        ContentListFragment fragment = new ContentListFragment();
        Bundle args = new Bundle();
        args.putString(ARG_USER, param1);
        args.putString(ARG_REPO, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getInjector().inject(this);
        bindViewModel(viewModel);

        if (getArguments() != null) {
            String user = getArguments().getString(ARG_USER);
            String repo = getArguments().getString(ARG_REPO);
            viewModel.setRepo(user, repo);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        ContentListFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.content_list_fragment, container, false);
        binding.setViewModel(viewModel);

        binding.listView.setAdapter(new ContentAdapter(getContext(), getInjector(), viewModel.contents));

        return binding.getRoot();
    }
} public class IssueListFragment extends BaseFragment {

    private static final String ARG_USER = "user";
    private static final String ARG_REPO = "repo";

    @Inject
    IssueListFragmentViewModel viewModel;

    public IssueListFragment() {
        // Required empty public constructor
    }

    public static IssueListFragment newInstance(String param1, String param2) {
        IssueListFragment fragment = new IssueListFragment();
        Bundle args = new Bundle();
        args.putString(ARG_USER, param1);
        args.putString(ARG_REPO, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getInjector().inject(this);
        bindViewModel(viewModel);

        if (getArguments() != null) {
            String user = getArguments().getString(ARG_USER);
            String repo = getArguments().getString(ARG_REPO);
            viewModel.setRepo(user, repo);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        IssueListFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.issue_list_fragment, container, false);
        binding.setViewModel(viewModel);

        binding.listView.setAdapter(new IssueAdapter(getContext(), getInjector(), viewModel.issues));

        return binding.getRoot();
    }
} public class MyRepoListFragment extends BaseFragment {

    @Inject
    MyRepoListFragmentViewModel viewModel;

    public MyRepoListFragment() {
        // Required empty public constructor
    }

    public static MyRepoListFragment newInstance() {
        MyRepoListFragment fragment = new MyRepoListFragment();
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        getInjector().inject(this);
        bindViewModel(viewModel);

        MyRepoListFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.my_repo_list_fragment, container, false);
        binding.setViewModel(viewModel);

        // Set up listview
        RepoAdapter adapter = new RepoAdapter(getContext(), getInjector(), viewModel.repos);
        binding.listView.setAdapter(adapter);

        return binding.getRoot();
    }
} public class PullRequestListFragment extends BaseFragment {

    private static final String ARG_USER = "user";
    private static final String ARG_REPO = "repo";

    @Inject
    PullRequestListFragmentViewModel viewModel;

    public PullRequestListFragment() {
        // Required empty public constructor
    }

    public static PullRequestListFragment newInstance(String param1, String param2) {
        PullRequestListFragment fragment = new PullRequestListFragment();
        Bundle args = new Bundle();
        args.putString(ARG_USER, param1);
        args.putString(ARG_REPO, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getInjector().inject(this);
        bindViewModel(viewModel);

        if (getArguments() != null) {
            String user = getArguments().getString(ARG_USER);
            String repo = getArguments().getString(ARG_REPO);
            viewModel.setRepo(user, repo);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        PullRequestListFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.pull_request_list_fragment, container, false);
        binding.setViewModel(viewModel);

        binding.listView.setAdapter(new PullRequestAdapter(getContext(), getInjector(), viewModel.pullRequests));

        return binding.getRoot();
    }
} public class RepoInfoFragment extends BaseFragment {

    @Inject
    RepoInfoFragmentViewModel viewModel;

    private String user;
    private String repo;

    public static RepoInfoFragment newInstance(final String user, final String repo) {
        RepoInfoFragment fragment = new RepoInfoFragment();
        Bundle args = new Bundle();
        args.putString("user", user);
        args.putString("repo", repo);
        fragment.setArguments(args);
        return fragment;
    }

    public RepoInfoFragment() {
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getArguments();
        user = args.getString("user");
        repo = args.getString("repo");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getInjector().inject(this);
        bindViewModel(viewModel);

        RepoInfoFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.repo_info_fragment, container, false);
        binding.setViewModel(viewModel);
        viewModel.setParams(user, repo);
        return binding.getRoot();
    }
} public class StarredRepoListFragment extends BaseFragment {

    @Inject
    StarredRepoListFragmentViewModel viewModel;

    public StarredRepoListFragment() {
        // Required empty public constructor
    }

    public static StarredRepoListFragment newInstance() {
        StarredRepoListFragment fragment = new StarredRepoListFragment();
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        getInjector().inject(this);
        bindViewModel(viewModel);

        StarredRepoListFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.starred_repo_list_fragment, container, false);
        binding.setViewModel(viewModel);

        // Set up listview
        RepoAdapter adapter = new RepoAdapter(getContext(), getInjector(), viewModel.repos);
        binding.listView.setAdapter(adapter);

        return binding.getRoot();
    }
} public class ContentListItemViewModel extends FragmentViewModel {

    public ObservableField<Content> content;

    @Inject
    public ContentListItemViewModel(BaseFragment fragment) {
        super(fragment);
        content = new ObservableField<>();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onResume() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onStop() {

    }
} public class IssueListItemViewModel extends FragmentViewModel {

    public ObservableField<Issue> issue;

    @Inject
    public IssueListItemViewModel(BaseFragment fragment) {
        super(fragment);
        issue = new ObservableField<>();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onResume() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onStop() {

    }
} public class PullRequestListItemViewModel extends FragmentViewModel {

    public ObservableField<PullRequest> pullRequest;

    @Inject
    public PullRequestListItemViewModel(BaseFragment fragment) {
        super(fragment);
        pullRequest = new ObservableField<>();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onResume() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onStop() {

    }
} public class RepoListItemViewModel extends FragmentViewModel {

    private final StarUseCase starUseCase;
    private final UnstarUseCase unstarUseCase;
    private final EventBus eventBus;

    public ObservableField<Repo> repo;
    public ObservableBoolean starred;

    @Inject
    public RepoListItemViewModel(BaseFragment fragment,
                                 StarUseCase starUseCase,
                                 UnstarUseCase unstarUseCase,
                                 EventBus eventBus) {
        super(fragment);
        this.starUseCase = starUseCase;
        this.unstarUseCase = unstarUseCase;
        this.eventBus = eventBus;

        this.repo = new ObservableField<>();
        this.starred = new ObservableBoolean(false);
    }

    public void onImageClick(View view) {
        UserActivity.startActivity(getContext(), repo.get().owner.login);
    }

    public void onStarClick(View view) {
        if (starred.get()) {
            unstarUseCase.run(repo.get().owner.login, repo.get().name)
                    .compose(bindToLifecycle().forCompletable())
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(() -> {
                        eventBus.post(new StarEvent());
                        Snackbar.make(view, "Unstarred!", Snackbar.LENGTH_SHORT).show();
                    });
        } else {
            starUseCase.run(repo.get().owner.login, repo.get().name)
                    .compose(bindToLifecycle().forCompletable())
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(() -> {
                        eventBus.post(new StarEvent());
                        Snackbar.make(view, "Starred!", Snackbar.LENGTH_SHORT).show();
                    });
        }
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onResume() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onStop() {

    }

    public static class StarEvent {}
}
import dagger.Subcomponent;
import io.github.kobakei.anago.fragment.ContentListFragment;
import io.github.kobakei.anago.fragment.IssueListFragment;
import io.github.kobakei.anago.fragment.MyRepoListFragment;
import io.github.kobakei.anago.fragment.PullRequestListFragment;
import io.github.kobakei.anago.fragment.RepoInfoFragment;
import io.github.kobakei.anago.fragment.StarredRepoListFragment;
import io.github.kobakei.anago.viewmodel.ContentListItemViewModel;
import io.github.kobakei.anago.viewmodel.IssueListItemViewModel;
import io.github.kobakei.anago.viewmodel.PullRequestListItemViewModel;
import io.github.kobakei.anago.viewmodel.RepoListItemViewModel;
package io.github.kobakei.anago.di;


/**
 * Created by keisuke on 2016/09/18.
 */
@Subcomponent(modules = {FragmentModule.class})
public interface FragmentComponent {
    void inject(MyRepoListFragment fragment);
    void inject(StarredRepoListFragment fragment);
    void inject(RepoInfoFragment fragment);
    void inject(IssueListFragment fragment);
    void inject(PullRequestListFragment fragment);
    void inject(ContentListFragment fragment);

    RepoListItemViewModel repoListItemViewModel();
    IssueListItemViewModel issueListItemViewModel();
    PullRequestListItemViewModel pullRequestListItemViewModel();
    ContentListItemViewModel contentListItemViewModel();