Skip to content

Commit

Permalink
Merge pull request #107 from huttneab/ui_updates
Browse files Browse the repository at this point in the history
Bunch of UI updates
  • Loading branch information
huttneab authored Oct 20, 2016
2 parents 30fb035 + 144e26d commit 0f99a65
Show file tree
Hide file tree
Showing 21 changed files with 538 additions and 671 deletions.
229 changes: 0 additions & 229 deletions .idea/codeStyleSettings.xml

This file was deleted.

3 changes: 1 addition & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ dependencies {
internalDebugCompile 'com.jakewharton.scalpel:scalpel:1.1.2'
internalDebugCompile 'com.jakewharton:process-phoenix:1.0.2'

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-SNAPSHOT'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-SNAPSHOT'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-SNAPSHOT'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4'
// testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4'

internalCompile 'com.mattprecious.telescope:telescope:2.1.0'

Expand Down
10 changes: 2 additions & 8 deletions app/src/main/java/com/rockthevote/grommet/data/DataModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.rockthevote.grommet.data.api.ApiModule;
import com.rockthevote.grommet.data.api.RegistrationService;
import com.rockthevote.grommet.data.api.RockyAdapterFactory;
import com.rockthevote.grommet.data.api.StringNormalizerFactory;
import com.rockthevote.grommet.data.db.DbModule;
import com.rockthevote.grommet.data.prefs.AppRegTotal;
import com.rockthevote.grommet.data.prefs.CanvasserName;
import com.rockthevote.grommet.data.prefs.CurrentRockyRequestId;
import com.rockthevote.grommet.data.prefs.EventName;
Expand Down Expand Up @@ -73,13 +73,6 @@ Preference<Integer> provideEventRegTotal(RxSharedPreferences prefs, Application
return prefs.getInteger(app.getResources().getString(R.string.pref_key_event_reg_total), 0);
}

@Provides
@Singleton
@AppRegTotal
Preference<Integer> provideAppRegTotal(RxSharedPreferences prefs, Application app){
return prefs.getInteger(app.getResources().getString(R.string.pref_key_app_reg_total), 0);
}

@Provides
@Singleton
@PartnerId
Expand Down Expand Up @@ -126,6 +119,7 @@ Preference<Long> provideCurrentRockyRequestId(RxSharedPreferences prefs) {
@Singleton
Moshi provideMoshi() {
return new Moshi.Builder()
.add(new StringNormalizerFactory())
.add(RockyAdapterFactory.create())
.build();
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/rockthevote/grommet/data/api/Normalize.java
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 {
}
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));
}
};
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.support.annotation.Nullable;

import com.google.auto.value.AutoValue;
import com.rockthevote.grommet.data.api.Normalize;
import com.rockthevote.grommet.data.db.model.AdditionalInfo;
import com.squareup.moshi.Json;
import com.squareup.moshi.JsonAdapter;
Expand All @@ -13,6 +14,7 @@ public abstract class ApiAdditionalInfo {

abstract String name();

@Normalize
@Json(name = "string_value")
abstract String stringValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.support.annotation.Nullable;

import com.google.auto.value.AutoValue;
import com.rockthevote.grommet.data.api.Normalize;
import com.rockthevote.grommet.data.db.model.Address;
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.JsonReader;
Expand All @@ -15,10 +16,13 @@
@AutoValue
public abstract class ApiAddress {

@Normalize
abstract String streetName();

@Normalize
abstract String subAddress();

@Normalize
abstract String municipalJurisdiction();

abstract String county();
Expand Down
Loading

0 comments on commit 0f99a65

Please sign in to comment.