diff --git a/app/images/nav_left.svg b/app/images/nav_left.svg
new file mode 100644
index 0000000..6fab838
--- /dev/null
+++ b/app/images/nav_left.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/app/images/nav_right.svg b/app/images/nav_right.svg
new file mode 100644
index 0000000..346a8a1
--- /dev/null
+++ b/app/images/nav_right.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java
index a72565f..5a85ce3 100644
--- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java
@@ -9,15 +9,13 @@ import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
-import com.nostra13.universalimageloader.core.assist.ImageScaleType;
-import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import pl.tpolgrabia.urbanexplorer.dto.PanoramioImageInfo;
import pl.tpolgrabia.urbanexplorer.fragments.HomeFragment;
import pl.tpolgrabia.urbanexplorer.fragments.PanoramioShowerFragment;
+import pl.tpolgrabia.urbanexplorer.utils.ImageLoaderUtils;
public class MainActivity extends ActionBarActivity {
- private static final int LOCATION_SETTINGS_REQUEST_ID = 1;
private static final String CLASS_TAG = MainActivity.class.getSimpleName();
private static final String PHOTO_BACKSTACK = "PHOTO_BACKSTACK";
public static DisplayImageOptions options;
@@ -30,10 +28,7 @@ public class MainActivity extends ActionBarActivity {
// setSupportActionBar(toolbar);
// UNIVERSAL IMAGE LOADER SETUP
- DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
- .cacheOnDisc(true).cacheInMemory(true)
- .imageScaleType(ImageScaleType.EXACTLY)
- .displayer(new FadeInBitmapDisplayer(300)).build();
+ DisplayImageOptions defaultOptions = ImageLoaderUtils.createDefaultOptions();
options = defaultOptions;
@@ -65,18 +60,12 @@ public class MainActivity extends ActionBarActivity {
public void switchToPhoto(PanoramioImageInfo photoInfo) {
FragmentManager fragmentManager = getSupportFragmentManager();
- //HomeFragment homeFragment = (HomeFragment) fragmentManager.findFragmentById(R.id.home_frag);
FragmentTransaction ctx = fragmentManager.beginTransaction();
-// ctx.remove(homeFragment);
-
- // TODO add inserting photo showing fragment
-
PanoramioShowerFragment panoramioShower = new PanoramioShowerFragment();
Bundle arguments = new Bundle();
arguments.putSerializable(PanoramioShowerFragment.PANORAMIO_PHOTO_ARG_KEY, photoInfo);
panoramioShower.setArguments(arguments);
- // ctx.add(R.id.fragments, panoramioShower);
ctx.replace(R.id.fragments, panoramioShower);
ctx.addToBackStack(PHOTO_BACKSTACK);
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/PanoramioResponseCallback.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/PanoramioResponseCallback.java
new file mode 100644
index 0000000..0153e8e
--- /dev/null
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/PanoramioResponseCallback.java
@@ -0,0 +1,10 @@
+package pl.tpolgrabia.urbanexplorer.callbacks;
+
+import org.json.JSONObject;
+
+/**
+ * Created by tpolgrabia on 28.08.16.
+ */
+public interface PanoramioResponseCallback {
+ void callback(PanoramioResponseStatus status, JSONObject response);
+}
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/PanoramioResponseStatus.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/PanoramioResponseStatus.java
new file mode 100644
index 0000000..49507b4
--- /dev/null
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/PanoramioResponseStatus.java
@@ -0,0 +1,10 @@
+package pl.tpolgrabia.urbanexplorer.callbacks;
+
+/**
+ * Created by tpolgrabia on 28.08.16.
+ */
+public enum PanoramioResponseStatus {
+ GENERAL_ERROR,
+ NETWORK_ERROR,
+ SUCCESS
+}
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioImageInfo.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioImageInfo.java
index 19dc586..1fbe599 100644
--- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioImageInfo.java
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioImageInfo.java
@@ -1,7 +1,6 @@
package pl.tpolgrabia.urbanexplorer.dto;
import java.io.Serializable;
-import java.util.Date;
/**
* Created by tpolgrabia on 27.08.16.
@@ -13,8 +12,13 @@ public class PanoramioImageInfo implements Serializable{
private Long ownerId;
private String photoFileUrl;
private String photoTitle;
- private Date uploadDate;
+ private String uploadDate;
private Double width;
+ private Double latitude;
+ private Double longitude;
+ private String ownerUrl;
+ private Long photoId;
+ private String photoUrl;
public Double getHeight() {
return height;
@@ -56,11 +60,11 @@ public class PanoramioImageInfo implements Serializable{
this.photoTitle = photoTitle;
}
- public Date getUploadDate() {
+ public String getUploadDate() {
return uploadDate;
}
- public void setUploadDate(Date uploadDate) {
+ public void setUploadDate(String uploadDate) {
this.uploadDate = uploadDate;
}
@@ -71,4 +75,44 @@ public class PanoramioImageInfo implements Serializable{
public void setWidth(Double width) {
this.width = width;
}
+
+ public void setLatitude(Double latitude) {
+ this.latitude = latitude;
+ }
+
+ public Double getLatitude() {
+ return latitude;
+ }
+
+ public void setLongitude(Double longitude) {
+ this.longitude = longitude;
+ }
+
+ public Double getLongitude() {
+ return longitude;
+ }
+
+ public void setOwnerUrl(String ownerUrl) {
+ this.ownerUrl = ownerUrl;
+ }
+
+ public String getOwnerUrl() {
+ return ownerUrl;
+ }
+
+ public void setPhotoId(Long photoId) {
+ this.photoId = photoId;
+ }
+
+ public Long getPhotoId() {
+ return photoId;
+ }
+
+ public void setPhotoUrl(String photoUrl) {
+ this.photoUrl = photoUrl;
+ }
+
+ public String getPhotoUrl() {
+ return photoUrl;
+ }
}
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioMapLocation.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioMapLocation.java
new file mode 100644
index 0000000..bdbd88f
--- /dev/null
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioMapLocation.java
@@ -0,0 +1,46 @@
+package pl.tpolgrabia.urbanexplorer.dto;
+
+import java.io.Serializable;
+
+/**
+ * Created by tpolgrabia on 28.08.16.
+ */
+public class PanoramioMapLocation implements Serializable{
+ private static final long serialVersionUID = -3048527017887972550L;
+ private Double latitude;
+ private Double longitude;
+ private Long zoom;
+
+ public Double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(Double latitude) {
+ this.latitude = latitude;
+ }
+
+ public Double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(Double longitude) {
+ this.longitude = longitude;
+ }
+
+ public Long getZoom() {
+ return zoom;
+ }
+
+ public void setZoom(Long zoom) {
+ this.zoom = zoom;
+ }
+
+ @Override
+ public String toString() {
+ return "PanoramioMapLocation{" +
+ "latitude=" + latitude +
+ ", longitude=" + longitude +
+ ", zoom=" + zoom +
+ '}';
+ }
+}
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioResponse.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioResponse.java
new file mode 100644
index 0000000..ef07cdb
--- /dev/null
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioResponse.java
@@ -0,0 +1,57 @@
+package pl.tpolgrabia.urbanexplorer.dto;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Created by tpolgrabia on 28.08.16.
+ */
+public class PanoramioResponse implements Serializable{
+ private static final long serialVersionUID = 8840731825651350777L;
+ private List photos;
+ private Long count;
+ private Boolean moreAvailable;
+ private PanoramioMapLocation mapLocation;
+
+ public List getPhotos() {
+ return photos;
+ }
+
+ public void setPhotos(List photos) {
+ this.photos = photos;
+ }
+
+ public Long getCount() {
+ return count;
+ }
+
+ public void setCount(Long count) {
+ this.count = count;
+ }
+
+ public Boolean getMoreAvailable() {
+ return moreAvailable;
+ }
+
+ public void setMoreAvailable(Boolean moreAvailable) {
+ this.moreAvailable = moreAvailable;
+ }
+
+ public PanoramioMapLocation getMapLocation() {
+ return mapLocation;
+ }
+
+ public void setMapLocation(PanoramioMapLocation mapLocation) {
+ this.mapLocation = mapLocation;
+ }
+
+ @Override
+ public String toString() {
+ return "PanoramioResponse{" +
+ "photos=" + photos +
+ ", count=" + count +
+ ", moreAvailable=" + moreAvailable +
+ ", mapLocation=" + mapLocation +
+ '}';
+ }
+}
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java
index 268e67e..7fbe69d 100644
--- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java
@@ -26,6 +26,8 @@ import pl.tpolgrabia.urbanexplorer.dto.PanoramioImageInfo;
import pl.tpolgrabia.urbanexplorer.utils.NumberUtils;
import pl.tpolgrabia.urbanexplorer.utils.PanoramioUtils;
+import java.text.ParseException;
+import java.util.ArrayList;
import java.util.List;
import static android.content.Context.LOCATION_SERVICE;
@@ -39,6 +41,8 @@ public class HomeFragment extends Fragment implements LocationListener {
private static final long MIN_TIME = 60000;
private static final float MIN_DISTANCE = 100;
private static final int LOCATION_SETTINGS_REQUEST_ID = 1;
+ private static final String LOCATIONS_LIST_IMAGE_SIZE = "medium";
+ private static final String LOCATIONS_ORDER = "popularity";
private boolean gpsLocationEnabled;
private boolean networkLocationEnabled;
private boolean locationEnabled;
@@ -46,13 +50,14 @@ public class HomeFragment extends Fragment implements LocationListener {
private String locationProvider;
private boolean locationServicesActivated = false;
private AQuery aq;
+
private View inflatedView;
private TextView pageSizeWidget;
private TextView pageIdWidget;
private Long pageId = 1L;
private ListView locations;
- private Button prevWidget;
- private Button nextWidget;
+ private ImageView prevWidget;
+ private ImageView nextWidget;
private Long photosCount;
private TextView locationsResultInfo;
@@ -165,8 +170,8 @@ public class HomeFragment extends Fragment implements LocationListener {
}
});
- prevWidget = (Button)inflatedView.findViewById(R.id.prev);
- nextWidget = (Button)inflatedView.findViewById(R.id.next);
+ prevWidget = (ImageView)inflatedView.findViewById(R.id.prev);
+ nextWidget = (ImageView)inflatedView.findViewById(R.id.next);
prevWidget.setOnClickListener(new View.OnClickListener() {
@Override
@@ -193,6 +198,10 @@ public class HomeFragment extends Fragment implements LocationListener {
private void fetchPanoramioLocations() {
+ fetchPanoramioPhotos();
+ }
+
+ private void fetchPanoramioPhotos() {
final Location location = locationService.getLastKnownLocation(locationProvider);
Double radiusX = fetchRadiusX();
Double radiusY = fetchRadiusY();
@@ -204,7 +213,8 @@ public class HomeFragment extends Fragment implements LocationListener {
"&miny=" + (location.getLatitude() - radiusY) +
"&maxx=" + (location.getLongitude() + radiusX) +
"&maxy=" + (location.getLatitude() + radiusX) +
- "&size=medium" +
+ "&size=" + LOCATIONS_LIST_IMAGE_SIZE +
+ "&order=" + LOCATIONS_ORDER +
"&mapfilter=true";
Log.d(CLASS_TAG, "Query: " + aqQuery);
aq.ajax(aqQuery,
@@ -219,8 +229,13 @@ public class HomeFragment extends Fragment implements LocationListener {
return;
}
- List photosInfos =
- PanoramioUtils.fetchPanoramioImagesFromResponse(object);
+ List photosInfos;
+ try {
+ photosInfos = PanoramioUtils.fetchPanoramioImagesFromResponse(object.getJSONArray("photos"));
+ } catch (ParseException e) {
+ Log.w(CLASS_TAG, "Parse exception", e);
+ photosInfos = new ArrayList<>();
+ }
photosCount = PanoramioUtils.fetchPanoramioImagesCountFromResponse(object);
locationsResultInfo = (TextView)inflatedView.findViewById(R.id.locations_result_info);
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioShowerFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioShowerFragment.java
index 5978895..ca5887a 100644
--- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioShowerFragment.java
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioShowerFragment.java
@@ -22,6 +22,10 @@ public class PanoramioShowerFragment extends Fragment {
public static final String PANORAMIO_PHOTO_ARG_KEY = "PANORAMIO_PHOTO_ARG_KEY";
private TextView photoTitle;
+ private TextView photoUploadDate;
+ private TextView photoAuthor;
+ private TextView photoUrl;
+ private TextView photoLocation;
public PanoramioShowerFragment() {
// Required empty public constructor
@@ -47,8 +51,21 @@ public class PanoramioShowerFragment extends Fragment {
(ImageView) inflatedView.findViewById(R.id.photo_container),
MainActivity.options);
- photoTitle = (TextView)inflatedView.findViewById(R.id.phot_title);
+ photoTitle = (TextView)inflatedView.findViewById(R.id.photo_title);
photoTitle.setText(imageInfo.getPhotoTitle());
+
+ photoUploadDate = (TextView)inflatedView.findViewById(R.id.photo_upload);
+ photoUploadDate.setText(imageInfo.getUploadDate());
+
+ photoAuthor = (TextView)inflatedView.findViewById(R.id.photo_author);
+ photoAuthor.setText(imageInfo.getOwnerName());
+
+ photoUrl = (TextView)inflatedView.findViewById(R.id.photo_url);
+ photoUrl.setText(imageInfo.getPhotoUrl());
+
+ photoLocation = (TextView)inflatedView.findViewById(R.id.photo_location);
+ photoLocation.setText(imageInfo.getLatitude() + "," + imageInfo.getLongitude());
+
}
return inflatedView;
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/ImageLoaderUtils.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/ImageLoaderUtils.java
new file mode 100644
index 0000000..f823bc0
--- /dev/null
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/ImageLoaderUtils.java
@@ -0,0 +1,17 @@
+package pl.tpolgrabia.urbanexplorer.utils;
+
+import com.nostra13.universalimageloader.core.DisplayImageOptions;
+import com.nostra13.universalimageloader.core.assist.ImageScaleType;
+import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
+
+/**
+ * Created by tpolgrabia on 28.08.16.
+ */
+public class ImageLoaderUtils {
+ public static DisplayImageOptions createDefaultOptions() {
+ return new DisplayImageOptions.Builder()
+ .cacheOnDisc(true).cacheInMemory(true)
+ .imageScaleType(ImageScaleType.EXACTLY)
+ .displayer(new FadeInBitmapDisplayer(300)).build();
+ }
+}
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/PanoramioUtils.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/PanoramioUtils.java
index 0357b0c..cae65f0 100644
--- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/PanoramioUtils.java
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/PanoramioUtils.java
@@ -4,8 +4,12 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import pl.tpolgrabia.urbanexplorer.dto.PanoramioImageInfo;
+import pl.tpolgrabia.urbanexplorer.dto.PanoramioMapLocation;
+import pl.tpolgrabia.urbanexplorer.dto.PanoramioResponse;
import pl.tpolgrabia.urbanexplorer.exceptions.PanoramioResponseNotExpected;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
@@ -14,12 +18,22 @@ import java.util.List;
*/
public class PanoramioUtils {
- public static PanoramioImageInfo fetchPanoramioDto(JSONObject photo) throws JSONException {
+ private static SimpleDateFormat panoramioDateFormatter = new SimpleDateFormat("dd MMMMMMMMMMMMMM yyyy");
+
+ public static PanoramioImageInfo fetchPanoramioDto(JSONObject photo) throws JSONException, ParseException {
PanoramioImageInfo info = new PanoramioImageInfo();
info.setPhotoTitle(photo.getString("photo_title"));
info.setPhotoFileUrl(photo.getString("photo_file_url"));
info.setWidth(photo.getDouble("width"));
info.setHeight(photo.getDouble("height"));
+ info.setLatitude(photo.getDouble("latitude"));
+ info.setLongitude(photo.getDouble("longitude"));
+ info.setOwnerId(photo.getLong("owner_id"));
+ info.setOwnerName(photo.getString("owner_name"));
+ info.setOwnerUrl(photo.getString("owner_url"));
+ info.setPhotoId(photo.getLong("photo_id"));
+ info.setPhotoUrl(photo.getString("photo_url"));
+ info.setUploadDate(photo.getString("upload_date"));
return info;
}
@@ -31,14 +45,13 @@ public class PanoramioUtils {
}
}
- public static List fetchPanoramioImagesFromResponse(JSONObject object) throws JSONException {
+ public static List fetchPanoramioImagesFromResponse(JSONArray photos) throws JSONException, ParseException {
- JSONArray photos = object.getJSONArray("photos");
if (photos == null) {
- throw new PanoramioResponseNotExpected("Panoramio response doesn't contain phots");
+ throw new PanoramioResponseNotExpected("photos arg cannot be null");
}
- List photosInfos = new ArrayList();
+ List photosInfos = new ArrayList<>();
int n = photos.length();
for (int i = 0; i < n; i++) {
photosInfos.add(
@@ -48,4 +61,23 @@ public class PanoramioUtils {
return photosInfos;
}
+
+ public static PanoramioResponse fetchPanoramioResponse(JSONObject panoramioResponse) throws JSONException, ParseException {
+ PanoramioResponse response = new PanoramioResponse();
+ response.setCount(panoramioResponse.getLong("count"));
+ response.setMoreAvailable(panoramioResponse.getBoolean("has_more"));
+ response.setPhotos(fetchPanoramioImagesFromResponse(panoramioResponse.getJSONArray("photos")));
+ response.setMapLocation(fetchPanoramioLocation(panoramioResponse.getJSONObject("map_location")));
+ return response;
+ }
+
+ private static PanoramioMapLocation fetchPanoramioLocation(JSONObject mapLocation) throws JSONException {
+ PanoramioMapLocation location = new PanoramioMapLocation();
+ location.setLatitude(mapLocation.getDouble("lat"));
+ location.setLongitude(mapLocation.getDouble("lon"));
+ location.setZoom(mapLocation.getLong("panoramio_zoom"));
+ return location;
+ }
+
+
}
diff --git a/app/src/main/res/drawable/nav_left.png b/app/src/main/res/drawable/nav_left.png
new file mode 100644
index 0000000..249ff29
Binary files /dev/null and b/app/src/main/res/drawable/nav_left.png differ
diff --git a/app/src/main/res/drawable/nav_right.png b/app/src/main/res/drawable/nav_right.png
new file mode 100644
index 0000000..52ecd10
Binary files /dev/null and b/app/src/main/res/drawable/nav_right.png differ
diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml
index d7cdf3e..83f5419 100644
--- a/app/src/main/res/layout/fragment_home.xml
+++ b/app/src/main/res/layout/fragment_home.xml
@@ -54,10 +54,10 @@
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+