packageorg.marcinzelent.liberavem;importandroid.content.Intent;importandroid.os.Bundle;importandroid.support.v4.app.Fragment;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.ViewGroup;importandroid.widget.AdapterView;importandroid.widget.ArrayAdapter;importandroid.widget.ListView;importandroid.widget.Toast;importcom.android.volley.Request;importcom.android.volley.RequestQueue;importcom.android.volley.Response;importcom.android.volley.VolleyError;importcom.android.volley.toolbox.StringRequest;importcom.android.volley.toolbox.Volley;importcom.google.gson.Gson;importcom.google.gson.GsonBuilder;importorg.jetbrains.annotations.Nullable;importjava.text.DateFormat;importjava.text.SimpleDateFormat;importjava.util.Date;importjava.util.Locale;importjava.util.TimeZone;/** * A simple {@link Fragment} subclass. */publicclassAllObservationsFragmentextendsFragment{Observation[]observations;Bird[]birds;publicAllObservationsFragment(){// Required empty public constructor}@OverridepublicViewonCreateView(LayoutInflaterinflater,ViewGroupcontainer,BundlesavedInstanceState){ViewrootView=inflater.inflate(R.layout.observations_list,container,false);returnrootView;}@OverridepublicvoidonViewCreated(Viewview,@NullableBundlesavedInstanceState){finalListViewobservationsListView=view.findViewById(R.id.observations_list_view);observationsListView.setOnItemClickListener(newAdapterView.OnItemClickListener(){@OverridepublicvoidonItemClick(AdapterView<?>arg0,Viewarg1,intposition,longarg3){IntentdetailsIntent=newIntent(getActivity(),ObservationDetailsActivity.class);detailsIntent.putExtra("Observation",observations[position]);StringphotoUrl="";for(Birdbird:birds)if(bird.getId()==observations[position].getBirdId())photoUrl=bird.getPhotoUrl();detailsIntent.putExtra("Photo",photoUrl);startActivity(detailsIntent);}});StringbirdsUrl="http://birdobservationservice.azurewebsites.net/Service1.svc/birds";finalStringRequestbirdsRequest=newStringRequest(Request.Method.GET,birdsUrl,newResponse.Listener<String>(){@OverridepublicvoidonResponse(Stringresponse){Gsongson=newGsonBuilder().create();birds=gson.fromJson(response,Bird[].class);}},newcom.android.volley.Response.ErrorListener(){@OverridepublicvoidonErrorResponse(VolleyErrorerror){Toast.makeText(getActivity(),"Couldn't connect to the database!",Toast.LENGTH_LONG).show();}});StringobservationsUrl="http://birdobservationservice.azurewebsites.net/Service1.svc/observations";finalStringRequestobservationsRequest=newStringRequest(Request.Method.GET,observationsUrl,newResponse.Listener<String>(){@OverridepublicvoidonResponse(Stringresponse){Gsongson=newGsonBuilder().create();observations=gson.fromJson(response,Observation[].class);for(Observationo:observations){intp=o.getCreated().indexOf('+');longepoch=Long.parseLong(o.getCreated().substring(6,p));Datedate=newDate(epoch);Stringformatted=newSimpleDateFormat("dd.MM.yyyy HH:mm",Locale.ENGLISH).format(date);o.setCreated(formatted);}finalObservationsListAdapteradapter=newObservationsListAdapter(getActivity(),observations,birds);observationsListView.setAdapter(adapter);}},newcom.android.volley.Response.ErrorListener(){@OverridepublicvoidonErrorResponse(VolleyErrorerror){Toast.makeText(getActivity(),"Couldn't connect to the database!",Toast.LENGTH_LONG).show();}});Volley.newRequestQueue(getActivity()).add(birdsRequest);Volley.newRequestQueue(getActivity()).add(observationsRequest);}}