-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from huttneab/ui_updates
Bunch of UI updates
- Loading branch information
Showing
21 changed files
with
538 additions
and
671 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/rockthevote/grommet/data/api/Normalize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.rockthevote.grommet.data.api; | ||
|
||
import com.squareup.moshi.JsonQualifier; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
/** | ||
* Created by Aaron Huttner on 9/23/16. Grommet | ||
*/ | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@JsonQualifier | ||
public @interface Normalize { | ||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/com/rockthevote/grommet/data/api/StringNormalizerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.rockthevote.grommet.data.api; | ||
|
||
import com.rockthevote.grommet.util.MoshiUtils; | ||
import com.squareup.moshi.JsonAdapter; | ||
import com.squareup.moshi.JsonReader; | ||
import com.squareup.moshi.JsonWriter; | ||
import com.squareup.moshi.Moshi; | ||
|
||
import java.io.IOException; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
import java.text.Normalizer; | ||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
|
||
|
||
/** | ||
* Created by Aaron Huttner on 9/23/16. Grommet | ||
*/ | ||
|
||
public class StringNormalizerFactory implements JsonAdapter.Factory { | ||
|
||
private static final String regex = Pattern.quote("[\\p{InCombiningDiacriticalMarks}\\p{IsLm}\\p{IsSk}]+"); | ||
private static final Pattern DIACRITICS_AND_FRIENDS = Pattern.compile(regex); | ||
|
||
private static String stripDiacritics(String str) { | ||
str = Normalizer.normalize(str, Normalizer.Form.NFD); | ||
str = DIACRITICS_AND_FRIENDS.matcher(str).replaceAll(""); | ||
return str; | ||
} | ||
|
||
@Override | ||
public JsonAdapter<?> create( | ||
Type type, Set<? extends Annotation> annotations, Moshi moshi) { | ||
if (!type.equals(String.class)) return null; | ||
if (!MoshiUtils.isAnnotationPresent(annotations, Normalize.class)) return null; | ||
|
||
final JsonAdapter<String> stringAdapter | ||
= moshi.nextAdapter(this, String.class, MoshiUtils.NO_ANNOTATIONS); | ||
return new JsonAdapter<String>() { | ||
@Override | ||
public String fromJson(JsonReader reader) throws IOException { | ||
String s = stringAdapter.fromJson(reader); | ||
return stripDiacritics(s); | ||
} | ||
|
||
@Override | ||
public void toJson(JsonWriter writer, String value) throws IOException { | ||
stringAdapter.toJson(writer, stripDiacritics(value)); | ||
} | ||
}; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.