Clicked google place redirects now to google maps for much more details.

master
Tomasz Półgrabia 2016-10-08 13:35:43 +02:00
parent fb462fac13
commit 6b2c8b247e
5 changed files with 89 additions and 4 deletions

View File

@ -1,4 +1,23 @@
<configuration>
<property name="LOG_DIR" value="/sdcard/urbanexplorer" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- active log file -->
<file>${LOG_DIR}/logs/urban-explorer.txt</file>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-20thread] %-5level %logger{36} - %msg</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover period -->
<fileNamePattern>${LOG_DIR}/log.%d.txt</fileNamePattern>
<!-- keep 7 days' worth of history -->
<maxHistory>7</maxHistory>
</rollingPolicy>
</appender>
<appender name="logcat" class="ch.qos.logback.classic.android.LogcatAppender">
<tagEncoder>
<pattern>%logger{12}</pattern>
@ -8,9 +27,13 @@
</encoder>
</appender>
<logger name="pl.tpolgrabia.urbanexplorer" level="ALL"/>
<logger name="pl.tpolgrabia.urbanexplorer" level="ALL">
<appender-ref ref="logcat" />
<appender-ref ref="FILE" />
</logger>
<root level="INFO">
<appender-ref ref="logcat" />
</root>
</configuration>

View File

@ -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<GooglePlaceResult> {
private static final int MAX_CHARS_FOR_TAGS_IN_INDEX_FRAG = 40;
public PlacesAdapter(Context context, List<GooglePlaceResult> objects) {
super(context, R.layout.google_place_item, objects);
}
@ -55,7 +58,7 @@ public class PlacesAdapter extends ArrayAdapter<GooglePlaceResult> {
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<GooglePlaceResult> {
return resultView;
}
private static String makeTagsString(GooglePlaceResult item) {
if (item.getTypes() != null) {
List<String> 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";
}
}
}

View File

@ -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<PanoramioImageInfo>());
EventBus.getDefault().post(new RefreshEvent(this));
}
}

View File

@ -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()) {

View File

@ -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<String> 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;