diff --git a/app/src/main/assets/logback.xml b/app/src/main/assets/logback.xml
index 9b46179..fa4036d 100644
--- a/app/src/main/assets/logback.xml
+++ b/app/src/main/assets/logback.xml
@@ -1,4 +1,23 @@
+
+
+
+
+
+ ${LOG_DIR}/logs/urban-explorer.txt
+
+ %d{HH:mm:ss.SSS} [%-20thread] %-5level %logger{36} - %msg
+
+
+
+
+ ${LOG_DIR}/log.%d.txt
+
+
+ 7
+
+
+
%logger{12}
@@ -8,9 +27,13 @@
-
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/adapters/PlacesAdapter.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/adapters/PlacesAdapter.java
index cbf85c6..0c4395b 100644
--- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/adapters/PlacesAdapter.java
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/adapters/PlacesAdapter.java
@@ -16,6 +16,7 @@ import pl.tpolgrabia.urbanexplorer.AppConstants;
import pl.tpolgrabia.urbanexplorer.MainActivity;
import pl.tpolgrabia.urbanexplorer.R;
+import java.util.Collections;
import java.util.List;
/**
@@ -24,6 +25,8 @@ import java.util.List;
public class PlacesAdapter extends ArrayAdapter {
+ private static final int MAX_CHARS_FOR_TAGS_IN_INDEX_FRAG = 40;
+
public PlacesAdapter(Context context, List objects) {
super(context, R.layout.google_place_item, objects);
}
@@ -55,7 +58,7 @@ public class PlacesAdapter extends ArrayAdapter {
placeAddressWidget.setText(item.getVicinity());
TextView placeType = (TextView) resultView.findViewById(R.id.place_type);
- placeType.setText(item.getTypes() != null ? StringUtils.join(item.getTypes(), ",") : "N/A");
+ placeType.setText(makeTagsString(item));
TextView placeRateWidget = (TextView) resultView.findViewById(R.id.place_rate);
if (item.getRating() != null && !item.getRating().equals(Double.NaN)) {
@@ -78,4 +81,18 @@ public class PlacesAdapter extends ArrayAdapter {
return resultView;
}
+
+ private static String makeTagsString(GooglePlaceResult item) {
+ if (item.getTypes() != null) {
+ List types = item.getTypes();
+ Collections.sort(types); // TODO make maybe in the frequency tags by user favorites
+ final String typesString = StringUtils.join(types, ",");
+ final int n = typesString.length();
+ return n <= MAX_CHARS_FOR_TAGS_IN_INDEX_FRAG
+ ? typesString
+ : typesString.substring(0, MAX_CHARS_FOR_TAGS_IN_INDEX_FRAG) + "...";
+ } else {
+ return "N/A";
+ }
+ }
}
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/panoramio/PanoramioLocationCallback.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/panoramio/PanoramioLocationCallback.java
index b405b3f..b9870a0 100644
--- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/panoramio/PanoramioLocationCallback.java
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/panoramio/PanoramioLocationCallback.java
@@ -1,11 +1,13 @@
package pl.tpolgrabia.urbanexplorer.callbacks.panoramio;
import android.location.Location;
+import org.greenrobot.eventbus.EventBus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.tpolgrabia.panoramiobindings.dto.PanoramioImageInfo;
import pl.tpolgrabia.urbanexplorerutils.callbacks.StandardLocationListenerCallback;
import pl.tpolgrabia.urbanexplorer.fragments.HomeFragment;
+import pl.tpolgrabia.urbanexplorerutils.events.RefreshEvent;
import java.util.ArrayList;
@@ -24,5 +26,6 @@ public class PanoramioLocationCallback implements StandardLocationListenerCallba
public void callback(Location location) {
homeFragment.setNoMorePhotos(false);
homeFragment.setPhotos(new ArrayList());
+ EventBus.getDefault().post(new RefreshEvent(this));
}
}
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/wiki/WikiFetchAppDataCallback.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/wiki/WikiFetchAppDataCallback.java
index d85f2ac..cf38b96 100644
--- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/wiki/WikiFetchAppDataCallback.java
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/wiki/WikiFetchAppDataCallback.java
@@ -1,6 +1,7 @@
package pl.tpolgrabia.urbanexplorer.callbacks.wiki;
import android.support.v4.app.FragmentActivity;
+import android.view.View;
import android.widget.ListView;
import android.widget.Toast;
import org.greenrobot.eventbus.EventBus;
@@ -45,7 +46,13 @@ public class WikiFetchAppDataCallback implements WikiAppResponseCallback {
// TODO on success
- ListView locations = (ListView) wikiLocationsFragment.getView().findViewById(R.id.wiki_places);
+ final View view = wikiLocationsFragment.getView();
+
+ if (view == null) {
+ return;
+ }
+
+ ListView locations = (ListView) view.findViewById(R.id.wiki_places);
locations.setOnItemLongClickListener(new FetchWikiLocationsCallback(wikiLocationsFragment, nobjects));
locations.setAdapter(new WikiLocationsAdapter(activity, objects));
if (objects.isEmpty()) {
diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PlacesFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PlacesFragment.java
index 206c5aa..ef5dc29 100644
--- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PlacesFragment.java
+++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PlacesFragment.java
@@ -1,13 +1,16 @@
package pl.tpolgrabia.urbanexplorer.fragments;
+import android.content.Intent;
import android.location.Location;
+import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
@@ -19,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.tpolgrabia.googleutils.callback.LocationGeoCoderCallback;
import pl.tpolgrabia.googleutils.constants.GooglePlacesConstants;
+import pl.tpolgrabia.googleutils.dto.GooglePlacePhoto;
import pl.tpolgrabia.googleutils.dto.GooglePlaceResult;
import pl.tpolgrabia.googleutils.utils.GeocoderUtils;
import pl.tpolgrabia.googleutils.utils.PlacesUtils;
@@ -41,6 +45,8 @@ import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Semaphore;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
@@ -58,6 +64,7 @@ public class PlacesFragment extends Fragment {
private Semaphore semaphore = new Semaphore(1);
private boolean noMoreResults = false;
+ private final Pattern pattern = Pattern.compile(".*href=\"(.*)\".*");
public PlacesFragment() {
// Required empty public constructor
@@ -76,7 +83,35 @@ public class PlacesFragment extends Fragment {
// Inflate the layout for this fragment
final View inflatedView = inflater.inflate(R.layout.fragment_places, container, false);
- ListView placesWidget = (ListView) inflatedView.findViewById(R.id.google_places);
+ final ListView placesWidget = (ListView) inflatedView.findViewById(R.id.google_places);
+ placesWidget.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
+ GooglePlaceResult item = (GooglePlaceResult) placesWidget.getAdapter().getItem(position);
+ if (item.getPhotos() != null && !item.getPhotos().isEmpty()) {
+ GooglePlacePhoto alink = item.getPhotos().get(0);
+ lg.debug("Photo link: {}", alink);
+ final List htmlAttributions = alink.getHtmlAttributions();
+ lg.debug("Html attributions: {}", htmlAttributions);
+ if (htmlAttributions != null && !htmlAttributions.isEmpty()) {
+ String attribute = htmlAttributions.get(0);
+ lg.debug("Attribute {}", attribute);
+ Matcher matcher = pattern.matcher(attribute);
+ boolean found = matcher.find();
+ if (found) {
+ String link = matcher.group(1);
+ lg.debug("Link: {}", link);
+ Uri uri = Uri.parse(link);
+ Intent intent = new Intent(Intent.ACTION_VIEW, uri);
+ getActivity().startActivity(intent);
+ } else {
+ lg.warn("Not expected link url html attribute expression {}", attribute);
+ }
+ }
+ }
+ return false;
+ }
+ });
placesWidget.setOnScrollListener(new GooglePlacesScrollListener(this));
return inflatedView;