diff options
author | Marcin Zelent <zelent.marcin@gmail.com> | 2018-04-20 10:50:23 +0200 |
---|---|---|
committer | Marcin Zelent <zelent.marcin@gmail.com> | 2018-04-20 10:50:23 +0200 |
commit | c4db4c26bb531974ba10c62185fd931e723a6859 (patch) | |
tree | b5d6f601c27464c69f6c99cf874ea4511aa01382 | |
parent | 4e6fc4fcdbcc3c75be13b3f8b80c24e4648fe354 (diff) |
Added displaying of pictures
-rw-r--r-- | .DS_Store | bin | 0 -> 6148 bytes | |||
-rw-r--r-- | .idea/caches/build_file_checksums.ser | bin | 535 -> 549 bytes | |||
-rw-r--r-- | .idea/vcs.xml | 6 | ||||
-rw-r--r-- | app/.DS_Store | bin | 0 -> 6148 bytes | |||
-rw-r--r-- | app/build.gradle | 2 | ||||
-rw-r--r-- | app/src/main/java/org/marcinzelent/liberavem/AllObservationsFragment.java | 32 | ||||
-rw-r--r-- | app/src/main/java/org/marcinzelent/liberavem/ObservationDetailsActivity.java | 6 | ||||
-rw-r--r-- | app/src/main/java/org/marcinzelent/liberavem/ObservationsListAdapter.java | 14 | ||||
-rw-r--r-- | build.gradle | 2 |
9 files changed, 41 insertions, 21 deletions
diff --git a/.DS_Store b/.DS_Store Binary files differnew file mode 100644 index 0000000..5f38f7f --- /dev/null +++ b/.DS_Store diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser Binary files differindex 0f5c9d1..f8b329e 100644 --- a/.idea/caches/build_file_checksums.ser +++ b/.idea/caches/build_file_checksums.ser diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project>
\ No newline at end of file diff --git a/app/.DS_Store b/app/.DS_Store Binary files differnew file mode 100644 index 0000000..3d0bb0e --- /dev/null +++ b/app/.DS_Store diff --git a/app/build.gradle b/app/build.gradle index fe925d9..1d3e59b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,7 +33,7 @@ dependencies { implementation 'com.android.support:support-vector-drawable:27.1.1' implementation 'com.android.volley:volley:1.1.0' implementation 'com.google.code.gson:gson:2.8.2' - implementation 'com.squareup.retrofit2:retrofit:2.4.0' + implementation 'com.squareup.picasso:picasso:2.71828' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 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; diff --git a/build.gradle b/build.gradle index eb8c588..6bcd33f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.30' + ext.kotlin_version = '1.2.31' repositories { google() jcenter() |