Created
October 19, 2015 12:54
-
-
Save muratcanbur/4fac3be2b0ad6225a407 to your computer and use it in GitHub Desktop.
RadioListFragment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RadioListFragment extends Fragment implements RadioListView, SwipeRefreshLayout.OnRefreshListener { | |
@Inject | |
RadioListPresenter radioListPresenter; | |
public RadioListFragment() { | |
} | |
public static RadioListFragment newInstance() { | |
RadioListFragment fragment = new RadioListFragment(); | |
return fragment; | |
} | |
@Override | |
public void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
BusUtil.BUS.register(this); | |
initializeInjector(); | |
} | |
@Override | |
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | |
super.onActivityCreated(savedInstanceState); | |
radioListPresenter.loadRadioList(); | |
} | |
private void initializeInjector() { | |
RadyolandApp app = (RadyolandApp) getActivity().getApplication(); | |
DaggerGetRadioListComponent.builder() | |
.appComponent(app.getAppComponent()) | |
.getRadioListModule(new GetRadioListModule()) | |
.build() | |
.inject(this); | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.fragment_radio_list, container, false); | |
ButterKnife.bind(this, view); | |
BusUtil.BUS.post(new TitleEvent(R.string.radio_list)); | |
radioListPresenter.start(); | |
radioListPresenter.attachView(this); | |
return view; | |
} | |
@Override | |
public void showLoading() { | |
swipeRefresh.setRefreshing(true); | |
} | |
@Override | |
public void dismissLoading() { | |
swipeRefresh.setRefreshing(false); | |
} | |
@Override | |
public void onListLoaded(RadioWrapper radioWrapper) { | |
radioListAdapter.setRadioList(radioWrapper.radioList); | |
radioListAdapter.notifyDataSetChanged(); | |
DatabaseUtil.saveRadioList(radioWrapper.radioList); | |
} | |
@Subscribe | |
public void RefreshRadioListEvent(RefreshRadioListEvent radioListEvent) { | |
radioListPresenter.loadRadioList(); | |
} | |
@Override | |
public void onDestroy() { | |
super.onDestroy(); | |
BusUtil.BUS.unregister(this); | |
} | |
@Override | |
public void onRefresh() { | |
radioListPresenter.loadRadioList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment