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

Proposed by Koichi Akabe
Status: Rejected
Rejected by: Stefan Hammer
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 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

remove unused variable

Revision history for this message
Stefan Hammer (j-4-deactivatedaccount) wrote :

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

remove unused variable

459. By Koichi Akabe

sort titles when create Linkify match pattern

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/org/tomdroid/NoteManager.java'
--- src/org/tomdroid/NoteManager.java 2012-09-07 08:55:07 +0000
+++ src/org/tomdroid/NoteManager.java 2012-09-08 09:23:19 +0000
@@ -550,7 +550,6 @@
550 */550 */
551 public static Pattern buildNoteLinkifyPattern(Activity activity, String noteTitle) {551 public static Pattern buildNoteLinkifyPattern(Activity activity, String noteTitle) {
552 552
553 StringBuilder sb = new StringBuilder();
554 Cursor cursor = getTitles(activity);553 Cursor cursor = getTitles(activity);
555 554
556 // cursor must not be null and must return more than 0 entry555 // cursor must not be null and must return more than 0 entry
@@ -560,21 +559,25 @@
560 559
561 cursor.moveToFirst();560 cursor.moveToFirst();
562 561
562 ArrayList<String> titles = new ArrayList<String>();
563
563 do {564 do {
564 title = cursor.getString(cursor.getColumnIndexOrThrow(Note.TITLE));565 title = cursor.getString(cursor.getColumnIndexOrThrow(Note.TITLE));
565 if(title.length() == 0 || title.equals(noteTitle))566 if(title.length() == 0 || title.equals(noteTitle))
566 continue;567 continue;
567 // Pattern.quote() here make sure that special characters in the note's title are properly escaped568 // Pattern.quote() here make sure that special characters in the note's title are properly escaped
568 sb.append("("+Pattern.quote(title)+")|");569 titles.add("("+Pattern.quote(title)+")");
569 570
570 } while (cursor.moveToNext());571 } while (cursor.moveToNext());
571 572
572 // if only empty titles, return573 // if only empty titles, return
573 if (sb.length() == 0)574 if (titles.size() == 0)
574 return null;575 return null;
575 576
576 // get rid of the last | that is not needed (I know, its ugly.. better idea?)577 // sort titles to give priority to long titles
577 String pt = sb.substring(0, sb.length()-1);578 String[] titlearray = titles.toArray(new String[0]);
579 Arrays.sort(titlearray, new StringLengthComparator());
580 String pt = TextUtils.join("|", titlearray);
578 581
579 // return a compiled match pattern582 // return a compiled match pattern
580 return Pattern.compile(pt, Pattern.CASE_INSENSITIVE);583 return Pattern.compile(pt, Pattern.CASE_INSENSITIVE);
@@ -588,4 +591,10 @@
588 return null;591 return null;
589 }592 }
590 593
594 public static class StringLengthComparator implements Comparator<String>{
595 public int compare(String str1, String str2) {
596 return ((String)str2).length() - ((String)str1).length();
597 }
598 }
599
591}600}

Subscribers

People subscribed via source and target branches