-
-
Notifications
You must be signed in to change notification settings - Fork 585
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 #590 from nmitsou/fixBugsOnTags
fixing search on tags
- Loading branch information
Showing
7 changed files
with
84 additions
and
20 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,6 +1,64 @@ | ||
package fr.neamar.kiss.pojo; | ||
|
||
import android.util.Pair; | ||
|
||
import fr.neamar.kiss.normalizer.StringNormalizer; | ||
|
||
public class AppPojo extends Pojo { | ||
public String packageName; | ||
public String activityName; | ||
|
||
// Tags assigned to this pojo | ||
public String tags; | ||
// Tags normalized | ||
public String tagsNormalized; | ||
// Array that contains the non-normalized positions for every normalized | ||
// character entry | ||
private int[] tagsPositionMap = null; | ||
// Variable to store the formated (user selection in bold) tag | ||
public String displayTags = ""; | ||
|
||
|
||
public void setTags(String tags) { | ||
// Set the actual user-friendly name | ||
this.tags = tags; | ||
|
||
if (this.tags != null) { | ||
this.tags = this.tags.replaceAll("<", "<"); | ||
// Normalize name for faster searching | ||
Pair<String, int[]> normalized = StringNormalizer.normalizeWithMap(this.tags); | ||
this.tagsNormalized = normalized.first; | ||
this.tagsPositionMap = normalized.second; | ||
} | ||
} | ||
|
||
public void setTagHighlight(int positionStart, int positionEnd) { | ||
int posStart = this.mapTagsPosition(positionStart); | ||
int posEnd = this.mapTagsPosition(positionEnd); | ||
|
||
this.displayTags = this.tags.substring(0, posStart) | ||
+ '{' + this.tags.substring(posStart, posEnd) + '}' + this.tags.substring(posEnd, this.tags.length()); | ||
} | ||
|
||
/** | ||
* Map a position in the normalized name to a position in the standard name string | ||
* | ||
* @param position Position in normalized name | ||
* @return Position in non-normalized string | ||
*/ | ||
public int mapTagsPosition(int position) { | ||
if (this.tagsPositionMap != null) { | ||
if (position < this.tagsPositionMap.length) { | ||
return this.tagsPositionMap[position]; | ||
} | ||
return this.tags.length(); | ||
} else { | ||
// No mapping defined | ||
if (position < this.tags.length()) { | ||
return position; | ||
} | ||
return this.tags.length(); | ||
} | ||
} | ||
|
||
} |
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
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