Merge lp:~vbkaisetsu/tomdroid/link-to-long-title into lp:tomdroid/beta

Proposed by Koichi Akabe on 2012-09-08
Status: Rejected
Rejected by: Stefan Hammer on 2014-01-04
Proposed branch: lp:~vbkaisetsu/tomdroid/link-to-long-title
Merge into: lp:tomdroid/beta
Diff against target: 52 lines (+14/-5)
1 file modified
src/org/tomdroid/NoteManager.java (+14/-5)
To merge this branch: bzr merge lp:~vbkaisetsu/tomdroid/link-to-long-title
Reviewer Review Type Date Requested Status
Tomdroid Developers 2012-09-08 Pending
Review via email: mp+123406@code.launchpad.net

Description of the change

This branch sorts titles on create match pattern for Linkify.
Therefore, it chooses long titles to create links.

For example, there are two notes which are named "Ubuntu" and "UbuntuOne", and the third note has "UbuntuOne" in the content.
This branch always link to "UbuntuOne", because I think nobody want to link to "Ubuntu" in this situation.

To post a comment you must log in.
460. By Koichi Akabe on 2012-09-08

remove unused variable

This is already fixed in the current code. Thanks for the input, it helped a lot!
I am looking forward to new contributions from you :-)

Unmerged revisions

460. By Koichi Akabe on 2012-09-08

remove unused variable

459. By Koichi Akabe on 2012-09-08

sort titles when create Linkify match pattern

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/org/tomdroid/NoteManager.java'
2--- src/org/tomdroid/NoteManager.java 2012-09-07 08:55:07 +0000
3+++ src/org/tomdroid/NoteManager.java 2012-09-08 09:23:19 +0000
4@@ -550,7 +550,6 @@
5 */
6 public static Pattern buildNoteLinkifyPattern(Activity activity, String noteTitle) {
7
8- StringBuilder sb = new StringBuilder();
9 Cursor cursor = getTitles(activity);
10
11 // cursor must not be null and must return more than 0 entry
12@@ -560,21 +559,25 @@
13
14 cursor.moveToFirst();
15
16+ ArrayList<String> titles = new ArrayList<String>();
17+
18 do {
19 title = cursor.getString(cursor.getColumnIndexOrThrow(Note.TITLE));
20 if(title.length() == 0 || title.equals(noteTitle))
21 continue;
22 // Pattern.quote() here make sure that special characters in the note's title are properly escaped
23- sb.append("("+Pattern.quote(title)+")|");
24+ titles.add("("+Pattern.quote(title)+")");
25
26 } while (cursor.moveToNext());
27
28 // if only empty titles, return
29- if (sb.length() == 0)
30+ if (titles.size() == 0)
31 return null;
32
33- // get rid of the last | that is not needed (I know, its ugly.. better idea?)
34- String pt = sb.substring(0, sb.length()-1);
35+ // sort titles to give priority to long titles
36+ String[] titlearray = titles.toArray(new String[0]);
37+ Arrays.sort(titlearray, new StringLengthComparator());
38+ String pt = TextUtils.join("|", titlearray);
39
40 // return a compiled match pattern
41 return Pattern.compile(pt, Pattern.CASE_INSENSITIVE);
42@@ -588,4 +591,10 @@
43 return null;
44 }
45
46+ public static class StringLengthComparator implements Comparator<String>{
47+ public int compare(String str1, String str2) {
48+ return ((String)str2).length() - ((String)str1).length();
49+ }
50+ }
51+
52 }

Subscribers

People subscribed via source and target branches