Skip to content

Commit 8371bc7

Browse files
committed
internal links
1 parent cfe5b61 commit 8371bc7

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

android/src/org/coolreader/crengine/BookmarkEditDialog.java

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class BookmarkEditDialog extends BaseDialog {
2525
private final Bookmark mOriginalBookmark;
2626
private final Bookmark mBookmark;
2727
private final boolean mIsNew;
28+
final TextView lblBookmarkLink;
2829
BookInfo mBookInfo;
2930
final EditText commentEdit;
3031
final EditText posEdit;
@@ -52,6 +53,8 @@ protected void onPositiveButtonClick() {
5253
} else {
5354
if (mIsNew) {
5455
mBookmark.setCommentText(commentEdit.getText().toString());
56+
if (mBookmark.getType() == Bookmark.TYPE_INTERNAL_LINK)
57+
mBookmark.setType(Bookmark.TYPE_COMMENT);
5558
mReaderView.addBookmark(mBookmark);
5659
} else {
5760
if (mOriginalBookmark.setCommentText(commentEdit.getText().toString())) {
@@ -63,7 +66,23 @@ protected void onPositiveButtonClick() {
6366
super.onPositiveButtonClick();
6467
}
6568

66-
public BookmarkEditDialog( CoolReader activity, ReaderView readerView, Bookmark bookmark, boolean isNew)
69+
public void BookmarkChooseCallback(Bookmark bm) {
70+
if (bm!=null) {
71+
String s1 = bm.getTitleText();
72+
String s2 = bm.getPosText();
73+
String s3 = bm.getCommentText();
74+
lblBookmarkLink.setText("");
75+
if (!StrUtils.isEmptyStr(s1)) lblBookmarkLink.setText(activity.getString(R.string.dlg_bookmark_link) +": " +s1);
76+
else if (!StrUtils.isEmptyStr(s2)) lblBookmarkLink.setText(activity.getString(R.string.dlg_bookmark_link) +": " +s2);
77+
else if (!StrUtils.isEmptyStr(s3)) lblBookmarkLink.setText(activity.getString(R.string.dlg_bookmark_link) +": " + s3);
78+
mBookmark.setLinkPos(bm.getStartPos());
79+
} else {
80+
mBookmark.setLinkPos("");
81+
lblBookmarkLink.setText("");
82+
}
83+
}
84+
85+
public BookmarkEditDialog(final CoolReader activity, ReaderView readerView, Bookmark bookmark, boolean isNew, int chosenType)
6786
{
6887
super(activity, "", true, false);
6988
mCoolReader = activity;
@@ -89,7 +108,8 @@ public BookmarkEditDialog( CoolReader activity, ReaderView readerView, Bookmark
89108
final RadioButton btnCorrection = (RadioButton)view.findViewById(R.id.rb_correction);
90109
final RadioButton btnUserDic = (RadioButton)view.findViewById(R.id.rb_user_dic);
91110
final RadioButton btnInternalLink = (RadioButton)view.findViewById(R.id.rb_internal_link);
92-
btnInternalLink.setEnabled(false);
111+
112+
//btnInternalLink.setEnabled(false);
93113
final TextView posLabel = (TextView)view.findViewById(R.id.lbl_position);
94114
final TextView commentLabel = (TextView)view.findViewById(R.id.lbl_comment_text);
95115

@@ -111,7 +131,18 @@ public void onClick(View v) {
111131

112132
final ImageButton btnSetComment = (ImageButton)view.findViewById(R.id.set_comment_from_cb);
113133
final TextView lblSetComment = (TextView)view.findViewById(R.id.lbl_comment_from_cb);
114-
134+
lblBookmarkLink = (TextView)view.findViewById(R.id.lbl_bookmark_link);
135+
String sL = mBookmark.getLinkPos();
136+
if (StrUtils.isEmptyStr(sL)) lblBookmarkLink.setText(""); else
137+
lblBookmarkLink.setText(activity.getString(R.string.dlg_bookmark_link) +": " +sL);
138+
if (!StrUtils.isEmptyStr(sL)) {
139+
for (Bookmark b: mBookInfo.getAllBookmarks()) {
140+
if (b.getStartPos().equals(sL)) {
141+
BookmarkChooseCallback(b);
142+
break;
143+
}
144+
}
145+
}
115146
String sClpb = "<empty>";
116147
try {
117148
android.text.ClipboardManager cm = mCoolReader.getClipboardmanager();
@@ -127,7 +158,9 @@ public void onClick(View v) {
127158
cbtext = "<empty>";
128159
}
129160
final String cbtextFull = StrUtils.textShrinkLines(sClpb.trim(),false);
130-
lblSetComment.setText(cbtext.trim());
161+
lblSetComment.setText("");
162+
if (!cbtext.trim().equals(""))
163+
lblSetComment.setText(activity.getString(R.string.clipb_contents) +" "+cbtext.trim());
131164
if (cbtext.trim().equals("")) {
132165
btnSetComment.setEnabled(false);
133166
}
@@ -144,6 +177,20 @@ public void onClick(View v) {
144177
onPositiveButtonClick();
145178
}
146179
});
180+
lblBookmarkLink.setOnClickListener(new View.OnClickListener() {
181+
@Override
182+
public void onClick(View v) {
183+
if (mIsNew)
184+
activity.showBookmarksDialog(true, BookmarkEditDialog.this);
185+
}
186+
});
187+
btnInternalLink.setOnClickListener(new View.OnClickListener() {
188+
@Override
189+
public void onClick(View v) {
190+
if (mIsNew)
191+
activity.showBookmarksDialog(true, BookmarkEditDialog.this);
192+
}
193+
});
147194
commentEdit = (EditText)view.findViewById(R.id.comment_edit);
148195
String postext = mBookmark.getPercent()/100 + "%";
149196
if ( mBookmark.getTitleText()!=null )
@@ -224,6 +271,11 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
224271
btnInternalLink.setClickable(false);
225272
btnUserDic.setClickable(false);
226273
}
274+
btnComment.setChecked(chosenType==Bookmark.TYPE_COMMENT);
275+
btnCorrection.setChecked(chosenType==Bookmark.TYPE_CORRECTION);
276+
btnInternalLink.setChecked(chosenType==Bookmark.TYPE_INTERNAL_LINK);
277+
btnUserDic.setChecked(chosenType==Bookmark.TYPE_USER_DIC);
278+
227279
setView( view );
228280
}
229281

0 commit comments

Comments
 (0)