Back to project page StravaFlow.
The source code is released under:
MIT License
If you think the Android project StravaFlow listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package me.mattlogan.stravaflow.ui.fragment; /*from www. j a va 2s. c o m*/ import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ListView; import java.util.List; import butterknife.ButterKnife; import butterknife.InjectView; import me.mattlogan.stravaflow.R; import me.mattlogan.stravaflow.api.StravaApi; import me.mattlogan.stravaflow.api.model.StravaActivity; import me.mattlogan.stravaflow.ui.activity.StravaApiInjector; import me.mattlogan.stravaflow.ui.view.ActivitiesAdapter; import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; public class ActivitiesFragment extends BaseFragment implements ActivitiesAdapter.OnActivitySelectedListener { @InjectView(R.id.activities_list) ListView listView; public interface Listener { public void onActivitySelected(StravaActivity stravaActivity); } ActivitiesAdapter adapter; StravaApi stravaApi; public static ActivitiesFragment newInstance() { return new ActivitiesFragment(); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Activity activity = getActivity(); adapter = new ActivitiesAdapter(getActivity(), this); if (activity instanceof StravaApiInjector) { stravaApi = ((StravaApiInjector) activity).getStravaApi(); } else { throw new IllegalStateException("Activity must implement StravaApiInjector"); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View activitiesView = inflater.inflate(R.layout.activities, container, false); ButterKnife.inject(this, activitiesView); setupListView(); return activitiesView; } void setupListView() { listView.setAdapter(adapter); } @Override protected String getTitle() { return getString(R.string.app_name); } @Override public void onResume() { super.onResume(); fetchActivities(); } void fetchActivities() { stravaApi.getActivities(System.currentTimeMillis(), new Callback<List<StravaActivity>>() { @Override public void success(List<StravaActivity> stravaActivities, Response response) { if (isAdded()) { populateList(stravaActivities); } } @Override public void failure(RetrofitError error) { } }); } void populateList(List<StravaActivity> stravaActivities) { adapter.setActivitiesList(stravaActivities); adapter.notifyDataSetChanged(); } @Override public void onActivitySelected(StravaActivity stravaActivity) { Activity activity = getActivity(); if (activity instanceof Listener) { ((Listener) activity).onActivitySelected(stravaActivity); } } }