Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nearby plases tmp #21980

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions OsmAnd-java/src/main/java/net/osmand/osm/io/NetworkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,44 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class NetworkUtils {
private static final Log log = PlatformUtil.getLog(NetworkUtils.class);
private static final String GPX_UPLOAD_USER_AGENT = "OsmGPXUploadAgent";
private static Proxy proxy = null;

public static String sendGetRequest(String urlText, String userNamePassword, StringBuilder responseBody){
public static String sendGetRequest(String urlText, String userNamePassword, StringBuilder responseBody) {
return sendGetRequest(urlText, userNamePassword, responseBody, false);
}

public static String sendGetRequest(String urlText, String userNamePassword, StringBuilder responseBody, boolean useGzip) {
try {
log.info("GET : " + urlText);
HttpURLConnection conn = getHttpURLConnection(urlText);
conn.setDoInput(true);
conn.setDoOutput(false);
conn.setRequestMethod("GET");
if(userNamePassword != null) {
conn.setRequestProperty("Authorization", "Basic " + Base64.encode(userNamePassword)); //$NON-NLS-1$ //$NON-NLS-2$
if (userNamePassword != null) {
conn.setRequestProperty("Authorization", "Basic " + Base64.encode(userNamePassword));
}
conn.setRequestProperty("User-Agent", "OsmAnd");
if (useGzip) {
conn.setRequestProperty("Accept-Encoding", "gzip");
}
conn.setRequestProperty("User-Agent", "OsmAnd"); //$NON-NLS-1$ //$NON-NLS-2$
log.info("Response code and message : " + conn.getResponseCode() + " " + conn.getResponseMessage());
if(conn.getResponseCode() != 200){
if (conn.getResponseCode() != 200) {
return conn.getResponseMessage();
}
InputStream is = conn.getInputStream();
String contentEncoding = conn.getHeaderField("Content-Encoding");
InputStream inputStream = conn.getInputStream();
if (useGzip && contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) {
inputStream = new GZIPInputStream(inputStream);
}
responseBody.setLength(0);
if (is != null) {
BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8")); //$NON-NLS-1$
if (inputStream != null) {
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); //$NON-NLS-1$
String s;
boolean first = true;
while ((s = in.readLine()) != null) {
Expand All @@ -49,7 +61,7 @@ public static String sendGetRequest(String urlText, String userNamePassword, Str
}
responseBody.append(s);
}
is.close();
inputStream.close();
}
return null;
} catch (IOException e) {
Expand Down
35 changes: 21 additions & 14 deletions OsmAnd-java/src/main/java/net/osmand/wiki/WikiCoreHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static List<OsmandApiFeatureData> getExploreImageList(KQuadRect mapRect,
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
LOG.debug("Download images " + url.toString());
LOG.debug("Download images " + url + " {" + Thread.currentThread().getName() + "}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have thread name in PlatformUtil, is it necessary?

getNearbyImagesOsmAndAPIRequest(url.toString(), wikiImages);
return wikiImages;
}
Expand Down Expand Up @@ -144,7 +144,7 @@ private static void addFile(List<WikiImage> wikiImages, String wikimediaCommons)
private static List<WikiImage> getWikimediaImageCategory(String categoryName, List<WikiImage> wikiImages, int depth) {
String url = WIKIMEDIA_API_ENDPOINT + WIKIMEDIA_ACTION + WIKIMEDIA_CATEGORY + categoryName + CM_LIMIT
+ FORMAT_JSON;
WikimediaResponse response = sendWikipediaApiRequest(url, WikimediaResponse.class);
WikimediaResponse response = sendWikipediaApiRequest(url, WikimediaResponse.class, false);
if (response != null) {
List<String> subCategories = new ArrayList<>();
for (Categorymember cm : response.query.categorymembers) {
Expand All @@ -169,7 +169,7 @@ private static List<WikiImage> getWikimediaImageCategory(String categoryName, Li

protected static List<WikiImage> getWikidataImageWikidata(String wikidataId, List<WikiImage> wikiImages) {
String url = WIKIDATA_API_ENDPOINT + WIKIDATA_ACTION + wikidataId + FORMAT_JSON;
WikidataResponse response = sendWikipediaApiRequest(url, WikidataResponse.class);
WikidataResponse response = sendWikipediaApiRequest(url, WikidataResponse.class, false);
if (response != null && response.claims != null && response.claims.p18 != null) {
for (P18 p18 : response.claims.p18) {
String imageFileName = p18.mainsnak.datavalue.value;
Expand All @@ -185,7 +185,7 @@ protected static List<WikiImage> getWikidataImageWikidata(String wikidataId, Lis
}

private static List<WikiImage> getImagesOsmAndAPIRequestV2(String url, List<WikiImage> wikiImages) {
OsmandAPIResponseV2 response = sendWikipediaApiRequest(url, OsmandAPIResponseV2.class);
OsmandAPIResponseV2 response = sendWikipediaApiRequest(url, OsmandAPIResponseV2.class, false);
if (response != null && !Algorithms.isEmpty(response.images)) {
for (Map<String, String> image : response.images) {
WikiImage wikiImage = parseImageDataWithMetaData(image);
Expand All @@ -207,14 +207,14 @@ private static boolean isUrlFileImage(WikiImage wikiImage) {
}

private static void getNearbyImagesOsmAndAPIRequest(String url, List<OsmandApiFeatureData> wikiImages) {
OsmandAPIFeaturesResponse response = sendWikipediaApiRequest(url, OsmandAPIFeaturesResponse.class);
OsmandAPIFeaturesResponse response = sendWikipediaApiRequest(url, OsmandAPIFeaturesResponse.class, true);
if (response != null && !Algorithms.isEmpty(response.features)) {
wikiImages.addAll(response.features);
}
}

private static List<WikiImage> getImagesOsmAndAPIRequest(String url, List<WikiImage> wikiImages) {
OsmandAPIResponse response = sendWikipediaApiRequest(url, OsmandAPIResponse.class);
OsmandAPIResponse response = sendWikipediaApiRequest(url, OsmandAPIResponse.class, false);
if (response != null && !Algorithms.isEmpty(response.images)) {
for (String imageUrl : response.images) {
if (imageUrl != null) {
Expand Down Expand Up @@ -286,17 +286,24 @@ public static WikiImage getImageData(String imageFileName) {
return null;
}

private static <T> T sendWikipediaApiRequest(String url, Class<T> responseClass) {
private static <T> T sendWikipediaApiRequest(String url, Class<T> responseClass, boolean useGzip) {
StringBuilder rawResponse = new StringBuilder();
String errorMessage = NetworkUtils.sendGetRequest(url, null, rawResponse);
if (errorMessage == null) {
try {
return new Gson().fromJson(rawResponse.toString(), responseClass);
} catch (JsonSyntaxException e) {
errorMessage = e.getLocalizedMessage();
try {
// Send the GET request with GZIP support
String errorMessage = NetworkUtils.sendGetRequest(url, null, rawResponse, useGzip);
if (errorMessage == null) {
try {
// Parse the JSON response
return new Gson().fromJson(rawResponse.toString(), responseClass);
} catch (JsonSyntaxException e) {
LOG.error(e.getLocalizedMessage());
}
} else {
LOG.error(errorMessage);
}
} catch (Exception e) {
LOG.error(e.getLocalizedMessage());
}
LOG.error(errorMessage);
return null;
}

Expand Down
163 changes: 123 additions & 40 deletions OsmAnd/res/layout/fragment_nearby_places.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/activity_background_color"
android:background="@null"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this @null necessary?

android:orientation="vertical">

<com.google.android.material.appbar.AppBarLayout
Expand All @@ -22,58 +22,141 @@
android:gravity="center_vertical"
android:visibility="visible"
app:title="@string/popular_places_nearby" />
</com.google.android.material.appbar.AppBarLayout>

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="@dimen/context_menu_buttons_bottom_height"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/activity_background_color"
android:orientation="horizontal">
android:orientation="vertical"
app:behavior_peekHeight="@dimen/bottom_sheet_menu_peek_height"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

<ImageView
android:id="@+id/location_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/content_padding"
android:src="@drawable/ic_action_marker_dark" />
<LinearLayout
android:id="@+id/show_on_map_container"
android:layout_width="match_parent"
android:layout_height="@dimen/context_menu_buttons_bottom_height"
android:background="?attr/activity_background_color"
android:orientation="horizontal">

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/show_on_map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:layout_marginStart="@dimen/content_padding"
android:paddingTop="@dimen/list_header_padding"
android:paddingBottom="@dimen/list_header_padding"
android:text="@string/shared_string_show_on_map"
android:textAllCaps="true"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_desc_text_size"
app:typefaceWeight="medium"
tools:text="SHOW ALL"
tools:visibility="visible" />
<ImageView
android:id="@+id/location_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/content_padding"
android:src="@drawable/ic_action_marker_dark" />

</LinearLayout>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/show_on_map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:layout_marginStart="@dimen/content_padding"
android:paddingTop="@dimen/list_header_padding"
android:paddingBottom="@dimen/list_header_padding"
android:text="@string/shared_string_show_on_map"
android:textAllCaps="true"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_desc_text_size"
app:typefaceWeight="medium"
tools:text="SHOW ALL"
tools:visibility="visible" />
</LinearLayout>

</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:id="@+id/main_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="UselessParent">

<LinearLayout
android:id="@+id/main_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical"
tools:ignore="UselessParent">
<include layout="@layout/card_bottom_divider" />

<include layout="@layout/card_bottom_divider" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/vertical_nearby_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/content_padding" />
</LinearLayout>
</LinearLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/vertical_nearby_list"
<!-- Show list button -->
<LinearLayout
android:id="@+id/show_list_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/content_padding" />
android:layout_gravity="bottom|start"
android:orientation="vertical"
android:visibility="gone">

<include
layout="@layout/map_compass_button"
android:layout_width="@dimen/map_small_button_size"
android:layout_height="@dimen/map_small_button_size"
android:layout_marginStart="@dimen/map_button_margin"
android:layout_marginTop="@dimen/map_small_button_margin" />

<androidx.legacy.widget.Space
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_weight="1" />

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<include
layout="@layout/map_ruler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|bottom" />

<include
layout="@layout/map_hud_controls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom" />

</FrameLayout>

<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@drawable/bg_contextmenu_shadow_top_light" />

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color">

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/show_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/text_margin_small"
android:layout_marginTop="@dimen/content_padding_small_half"
android:layout_marginBottom="@dimen/content_padding_small_half"
android:background="?attr/list_background_color"
android:padding="@dimen/content_padding_half"
android:text="@string/show_list"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/default_desc_text_size"
app:typefaceWeight="medium"
tools:text="Show list" />

</FrameLayout>

</LinearLayout>

</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

</LinearLayout>
4 changes: 3 additions & 1 deletion OsmAnd/res/layout/search_nearby_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="@dimen/nearby_place_image_width"
android:layout_height="wrap_content"
android:layout_height="@dimen/nearby_place_item_height"
android:orientation="vertical"
android:paddingStart="@dimen/content_padding"
android:paddingTop="@dimen/content_padding"
Expand All @@ -21,6 +21,8 @@
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:textColor="?android:textColorPrimary"
android:maxLines="2"
android:ellipsize="end"
android:textSize="16sp"
tools:text="Eiffel Tower" />

Expand Down
5 changes: 3 additions & 2 deletions OsmAnd/res/layout/search_nearby_item_vertical.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@

<TextView
android:id="@+id/item_type"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:textSize="14sp"
tools:text="Monument" />

<LinearLayout
android:id="@+id/compass_layout"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="bottom|right"
android:orientation="horizontal">
Expand Down
1 change: 1 addition & 0 deletions OsmAnd/res/values/sizes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -482,5 +482,6 @@

<dimen name="nearby_place_image_height">108dp</dimen>
<dimen name="nearby_place_image_width">144dp</dimen>
<dimen name="nearby_place_item_height">210dp</dimen>
<dimen name="nearby_place_image_vertical_size">66dp</dimen>
</resources>
1 change: 1 addition & 0 deletions OsmAnd/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- For wording and consistency, please note https://docs.osmand.net/docs/technical/contributions/translating-osmand
Thx - Hardy
-->
<string name="show_list">Show list</string>
<string name="save_favorite_default_appearance">Apply changes to the existing points in the folder or only to new ones?</string>
<string name="original_color_description">Each point would keep its own color.</string>
<string name="original_icon_description">Each point would keep its own icon.</string>
Expand Down
Loading
Loading