Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
fixed crash 1731 that app names with spaces may crash the pinyin inde…
Browse files Browse the repository at this point in the history
…xing logic
  • Loading branch information
xingrz committed Nov 13, 2015
1 parent cc790af commit bd33e43
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ android {

targetSdkVersion 23

versionCode 10501
versionName "1.5.1"
versionCode 10502
versionName "1.5.2"

buildConfigField "boolean", "FIR_ENABLED", "!DEBUG && ${project.hasProperty('FIR_API_TOKEN')}"
buildConfigField "String", "FIR_API_TOKEN",
Expand Down
21 changes: 14 additions & 7 deletions app/src/main/java/ooo/oxo/apps/materialize/SearchMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package ooo.oxo.apps.materialize;

import android.text.TextUtils;
import android.util.Log;

import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;
Expand Down Expand Up @@ -62,8 +61,7 @@ public boolean filter(AppInfo app) {
if (pinyinCache.containsKey(app.label)) {
pinyin = pinyinCache.get(app.label);
} else {
pinyin = new Pinyin(PinyinHelper.convertToPinyinString(
app.label.trim().toLowerCase(), " ", PinyinFormat.WITHOUT_TONE).split(" "));
pinyin = Pinyin.from(app.label);
pinyinCache.put(app.label, pinyin);
}

Expand All @@ -84,25 +82,34 @@ public interface KeywordProvider {

}

public class Pinyin {
public static class Pinyin {

public final String pinyinLong;

public final String pinyinShort;

public Pinyin(String[] source) {
private Pinyin(String[] source) {
StringBuilder builderLong = new StringBuilder();
StringBuilder builderShort = new StringBuilder();

for (String s : source) {
builderLong.append(s);
builderShort.append(s.charAt(0));
s = s.trim();
if (TextUtils.isGraphic(s)) {
builderLong.append(s);
builderShort.append(s.charAt(0));
}
}

this.pinyinLong = builderLong.toString();
this.pinyinShort = builderShort.toString();
}

public static Pinyin from(String source) {
return new Pinyin(PinyinHelper.convertToPinyinString(source, " ", PinyinFormat.WITHOUT_TONE)
.toLowerCase()
.split(" "));
}

}

}

0 comments on commit bd33e43

Please sign in to comment.