aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Zelent <zelent.marcin@gmail.com>2018-04-20 10:50:23 +0200
committerMarcin Zelent <zelent.marcin@gmail.com>2018-04-20 10:50:23 +0200
commitc4db4c26bb531974ba10c62185fd931e723a6859 (patch)
treeb5d6f601c27464c69f6c99cf874ea4511aa01382 /app/src/main/java/org
parent4e6fc4fcdbcc3c75be13b3f8b80c24e4648fe354 (diff)
Added displaying of pictures
Diffstat (limited to 'app/src/main/java/org')
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/AllObservationsFragment.java32
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/ObservationDetailsActivity.java6
-rw-r--r--app/src/main/java/org/marcinzelent/liberavem/ObservationsListAdapter.java14
3 files changed, 33 insertions, 19 deletions
diff --git a/app/src/main/java/org/marcinzelent/liberavem/AllObservationsFragment.java b/app/src/main/java/org/marcinzelent/liberavem/AllObservationsFragment.java
index 3f3ad7b..e41b29e 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/AllObservationsFragment.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/AllObservationsFragment.java
@@ -58,20 +58,31 @@ public class AllObservationsFragment extends Fragment {
Intent detailsIntent = new Intent(getActivity(), ObservationDetailsActivity.class);
detailsIntent.putExtra("Observation", observations[position]);
- //String photoUrl = "";
- //for (Bird bird : birds)
- // if (bird.getId() == observations[position].getBirdId())
- // photoUrl = bird.getPhotoUrl();
- //detailsIntent.putExtra("Photo", photoUrl);
+ String photoUrl = "";
+ for (Bird bird : birds)
+ if (bird.getId() == observations[position].getBirdId())
+ photoUrl = bird.getPhotoUrl();
+ detailsIntent.putExtra("Photo", photoUrl);
startActivity(detailsIntent);
}
});
- //final ObservationsListAdapter adapter = new ObservationsListAdapter(getActivity(), observations, birds);
- //observationsListView.setAdapter(adapter);
+ String birdsUrl = "http://birdobservationservice.azurewebsites.net/Service1.svc/birds";
+ final StringRequest birdsRequest = new StringRequest(Request.Method.GET, birdsUrl, new Response.Listener<String>() {
+ @Override
+ public void onResponse(String response) {
+ Gson gson = new GsonBuilder().create();
+ birds = gson.fromJson(response, Bird[].class);
+ }
+ }, new com.android.volley.Response.ErrorListener() {
+ @Override
+ public void onErrorResponse(VolleyError error) {
+ Toast.makeText(getActivity(), "Couldn't connect to the database!", Toast.LENGTH_LONG).show();
+ }
+ });
String observationsUrl = "http://birdobservationservice.azurewebsites.net/Service1.svc/observations";
- final StringRequest observationRequest = new StringRequest(Request.Method.GET, observationsUrl, new Response.Listener<String>() {
+ final StringRequest observationsRequest = new StringRequest(Request.Method.GET, observationsUrl, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Gson gson = new GsonBuilder().create();
@@ -89,10 +100,11 @@ public class AllObservationsFragment extends Fragment {
}, new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
- Toast.makeText(getActivity(), "Database connection error :( ", Toast.LENGTH_LONG).show();
+ Toast.makeText(getActivity(), "Couldn't connect to the database!", Toast.LENGTH_LONG).show();
}
});
- Volley.newRequestQueue(getActivity()).add(observationRequest);
+ Volley.newRequestQueue(getActivity()).add(birdsRequest);
+ Volley.newRequestQueue(getActivity()).add(observationsRequest);
}
}
diff --git a/app/src/main/java/org/marcinzelent/liberavem/ObservationDetailsActivity.java b/app/src/main/java/org/marcinzelent/liberavem/ObservationDetailsActivity.java
index 8373145..83e9c9a 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/ObservationDetailsActivity.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/ObservationDetailsActivity.java
@@ -5,6 +5,8 @@ import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
+import com.squareup.picasso.Picasso;
+
public class ObservationDetailsActivity extends AppCompatActivity {
@Override
@@ -14,8 +16,10 @@ public class ObservationDetailsActivity extends AppCompatActivity {
Intent intent = getIntent();
Observation observation = (Observation) intent.getSerializableExtra("Observation");
- //String photoUrl = (String) intent.getSerializableExtra("Photo");
+ String photoUrl = (String) intent.getSerializableExtra("Photo");
+ SquareImageView detailsPhoto = findViewById(R.id.details_photo);
+ Picasso.get().load(photoUrl).into(detailsPhoto);
TextView detailsName = findViewById(R.id.details_name);
detailsName.setText(observation.getNameEnglish());
TextView detailsCreated = findViewById(R.id.details_created);
diff --git a/app/src/main/java/org/marcinzelent/liberavem/ObservationsListAdapter.java b/app/src/main/java/org/marcinzelent/liberavem/ObservationsListAdapter.java
index b73f103..b28e162 100644
--- a/app/src/main/java/org/marcinzelent/liberavem/ObservationsListAdapter.java
+++ b/app/src/main/java/org/marcinzelent/liberavem/ObservationsListAdapter.java
@@ -10,6 +10,8 @@ import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
+import com.squareup.picasso.Picasso;
+
public class ObservationsListAdapter extends BaseAdapter {
@@ -66,19 +68,15 @@ public class ObservationsListAdapter extends BaseAdapter {
viewHolder.date.setText(observations[position].getCreated());
String photoUrl = "";
- //for (Bird bird : birds)
- // if (bird.getId() == observations[position].getBirdId())
- // photoUrl = bird.getPhotoUrl();
+ for (Bird bird : birds)
+ if (bird.getId() == observations[position].getBirdId())
+ photoUrl = bird.getPhotoUrl();
- //viewHolder.photo.setImageResource(photoUrl);
+ Picasso.get().load(photoUrl).into(viewHolder.photo);
return convertView;
}
- public void add(int position, Observation observation, Bird bird) {
-
- }
-
private static class ViewHolder {
TextView name;
TextView date;