From 3f8d2880ea2cd27c46ced73691dd287ba6d038f4 Mon Sep 17 00:00:00 2001 From: hissingpanda Date: Tue, 18 Aug 2015 15:25:00 -0500 Subject: [PATCH] prod 1.01: fixed accented characters bug --- .idea/gradle.xml | 2 +- .idea/misc.xml | 24 + .idea/workspace.xml | 757 +++++++++++++++--- README.md | 1 + app/app.iml | 8 +- app/build.gradle | 4 +- .../org/refugerestrooms/models/Bathroom.java | 58 +- .../org/refugerestrooms/servers/Server.java | 2 +- .../refugerestrooms/views/MainActivity.java | 12 +- refugerestrooms-android.iml | 2 +- 10 files changed, 723 insertions(+), 147 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 3ec5955..0833b17 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -5,7 +5,7 @@ @@ -1770,10 +2003,10 @@ - @@ -1813,17 +2046,6 @@ - - - - - - - - - @@ -1895,8 +2117,26 @@ + - + + + + + + + + @@ -1917,6 +2157,10 @@ + + + + + + + + + @@ -1941,12 +2196,12 @@ - + - + @@ -1970,10 +2225,15 @@ - - + + - + - + - + - - + + - - + + @@ -2233,12 +2503,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2276,6 +2600,20 @@ + + + + + + + + + + + + + + @@ -2294,6 +2632,20 @@ + + + + + + + + + + + + + + @@ -2312,6 +2664,20 @@ + + + + + + + + + + + + + + @@ -2366,6 +2732,20 @@ + + + + + + + + + + + + + + @@ -2384,6 +2764,20 @@ + + + + + + + + + + + + + + @@ -2402,6 +2796,20 @@ + + + + + + + + + + + + + + @@ -2420,6 +2828,20 @@ + + + + + + + + + + + + + + @@ -2485,99 +2907,172 @@ - + - + - - + + + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + + - + + + + + + - + + - + - - + + + - + - - + + + + + + - + - - + + + + + + - + - - + + + - + + + + + + + + + + + + + + + - - + + - + - - + + + + + + + + + + + + + + + + - + - + - - + + diff --git a/README.md b/README.md index aaea29b..aa89a3c 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ If you push code, please make sure it builds correctly. Feel free to use pull re - [ ] Contact form without email client - [ ] Update text directions while on tab - [ ] Actionbar activity depreciated (HttpClient as well) +- [ ] Add different locales in strings.xml file ## Bugs - [ ] Screen rotation re-updates map to initial closest location diff --git a/app/app.iml b/app/app.iml index de2d273..5faf74c 100644 --- a/app/app.iml +++ b/app/app.iml @@ -12,10 +12,12 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 1ee50d2..afc8d4b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,8 +21,8 @@ android { applicationId "org.refugerestrooms" minSdkVersion 14 targetSdkVersion 22 - versionCode 2 - versionName "1" + versionCode 3 + versionName "1.01" } buildTypes { release { diff --git a/app/src/main/java/org/refugerestrooms/models/Bathroom.java b/app/src/main/java/org/refugerestrooms/models/Bathroom.java index 7f604c1..133b471 100644 --- a/app/src/main/java/org/refugerestrooms/models/Bathroom.java +++ b/app/src/main/java/org/refugerestrooms/models/Bathroom.java @@ -6,6 +6,10 @@ import android.text.TextUtils; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; + /** * Placeholder * @author Refuge Restrooms @@ -41,6 +45,29 @@ public class Bathroom { private double mLongitude; public String getName() { + /****************************************************************************************** + * Following section encodes result into ISO-8859-1 and then decodes it into UTF-8. + * This is necessary for displaying accented characters; previously "é" was showing as "é", etc.. + * Most likely because of an encoding redundancy from the restroom API, so this may break in the future + * if that is changed/fixed. + ******************************************************************************************/ + if (mName != null) { + String encodedString = null; + String decodedString = null; + try { + encodedString = URLEncoder.encode(mName, "ISO-8859-1"); + } catch (UnsupportedEncodingException e) { + //e.printStackTrace(); + } + try { + decodedString = URLDecoder.decode(encodedString, "UTF-8"); + } catch (UnsupportedEncodingException e) { + //e.printStackTrace(); + } + if (decodedString != null) { + mName = decodedString; + } + } return mName; } @@ -70,6 +97,29 @@ public boolean isUnisex() { } public String getDirections() { + /****************************************************************************************** + * Following section encodes result into ISO-8859-1 and then decodes it into UTF-8. + * This is necessary for displaying accented characters; previously "é" was showing as "é", etc.. + * Most likely because of an encoding redundancy from the restroom API, so this may break in the future + * if that is changed/fixed. + ******************************************************************************************/ + if (mDirections != null) { + String encodedString = null; + String decodedString = null; + try { + encodedString = URLEncoder.encode(mDirections, "ISO-8859-1"); + } catch (UnsupportedEncodingException e) { + //e.printStackTrace(); + } + try { + decodedString = URLDecoder.decode(encodedString, "UTF-8"); + } catch (UnsupportedEncodingException e) { + //e.printStackTrace(); + } + if (decodedString != null) { + mDirections = decodedString; + } + } return mDirections; } @@ -84,14 +134,10 @@ public String getComments() { return mComments; } - public void setName(String name) { - this.mName = name; - } + public void setName(String name) { this.mName = name; } @Override - public String toString() { - return mName; - } + public String toString() { return mName; } public String toJson() { Gson gson = new Gson(); diff --git a/app/src/main/java/org/refugerestrooms/servers/Server.java b/app/src/main/java/org/refugerestrooms/servers/Server.java index 49c2cbe..0b1654a 100644 --- a/app/src/main/java/org/refugerestrooms/servers/Server.java +++ b/app/src/main/java/org/refugerestrooms/servers/Server.java @@ -52,7 +52,7 @@ private RemoteCallTask setSearchTerm(String searchTerm) { public URI buildUrl() throws URISyntaxException { if(!location) // limit per_page=20 so only the 20 nearest/most relevant results display - return new URI("http://www.refugerestrooms.org:80/api/v1/restrooms/search.json?per_page=20&query=" + Uri.encode(searchTerm)); + return new URI("http://www.refugerestrooms.org:80/api/v1/restrooms/search.json?per_page=20&query=" + Uri.encode(searchTerm, "UTF-8")); else { // Refuge Restrooms API bathrooms queried // http://www.refugerestrooms.org/api/docs/#!/restrooms/GET_version_restrooms_search_format diff --git a/app/src/main/java/org/refugerestrooms/views/MainActivity.java b/app/src/main/java/org/refugerestrooms/views/MainActivity.java index add111c..dc7b9c3 100644 --- a/app/src/main/java/org/refugerestrooms/views/MainActivity.java +++ b/app/src/main/java/org/refugerestrooms/views/MainActivity.java @@ -62,8 +62,15 @@ import org.refugerestrooms.servers.JsonRequest; import org.refugerestrooms.servers.Server; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.nio.charset.Charset; +import java.text.Normalizer; import java.util.List; +import static java.lang.Character.getNumericValue; + //TODO ActionBarActivity has been depreciated... use toolbar instead public class MainActivity extends ActionBarActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks, @@ -848,6 +855,7 @@ public void onSearchResults(List results) { Bathroom bathroom = results.get(i); LatLng temp = bathroom.getLocation(); String name = bathroom.getName(); + int score = bathroom.getScore(); //String comment = bathroom.getComments(); // Adds bathroom markers, blue for accessible, red for not @@ -855,7 +863,7 @@ public void onSearchResults(List results) { { mMap.addMarker(new MarkerOptions() .position(new LatLng(temp.latitude, temp.longitude)) - .title(bathroom.getName()) + .title(name) .snippet(bathroom.getDirections()) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))); } @@ -863,7 +871,7 @@ public void onSearchResults(List results) { { mMap.addMarker(new MarkerOptions() .position(new LatLng(temp.latitude,temp.longitude)) - .title(bathroom.getName()) + .title(name) .snippet(bathroom.getDirections()) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))); } diff --git a/refugerestrooms-android.iml b/refugerestrooms-android.iml index 5a2f2b5..7872bf9 100644 --- a/refugerestrooms-android.iml +++ b/refugerestrooms-android.iml @@ -8,7 +8,7 @@ - +