mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
footnote text in the toast
This commit is contained in:
parent
67217c4264
commit
e06804dda1
8 changed files with 90 additions and 32 deletions
|
@ -255,6 +255,9 @@
|
|||
<node name="saveText" value="Save text"/>
|
||||
<node name="editStyle" value="Edit style…"/>
|
||||
</node>
|
||||
<node name="footnoteToast">
|
||||
<node name="more" value="More"/>
|
||||
</node>
|
||||
<node name="cancelMenu">
|
||||
<node name="library" value="Open library"/>
|
||||
<node name="networkLibrary" value="Open network library"/>
|
||||
|
|
|
@ -30,6 +30,8 @@ import com.github.johnpersano.supertoasts.SuperToast;
|
|||
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
|
||||
|
||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
import org.geometerplus.zlibrary.text.util.AutoTextSnippet;
|
||||
import org.geometerplus.zlibrary.text.view.*;
|
||||
|
||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||
|
@ -70,16 +72,18 @@ class ProcessHyperlinkAction extends FBAndroidAction {
|
|||
case FBHyperlinkType.INTERNAL:
|
||||
Reader.Collection.markHyperlinkAsVisited(Reader.getCurrentBook(), hyperlink.Id);
|
||||
{
|
||||
final FBReaderApp.FootnoteData data = Reader.getFootnoteData(hyperlink.Id);
|
||||
if (data != null) {
|
||||
final SuperActivityToast toast =
|
||||
new SuperActivityToast(BaseActivity, SuperToast.Type.BUTTON);
|
||||
toast.setText(data.Text);
|
||||
toast.setDuration(SuperToast.Duration.LONG);
|
||||
final AutoTextSnippet snippet = Reader.getFootnoteData(hyperlink.Id);
|
||||
if (snippet == null) {
|
||||
break;
|
||||
}
|
||||
final SuperActivityToast toast;
|
||||
if (snippet.IsEndOfText) {
|
||||
toast = new SuperActivityToast(BaseActivity, SuperToast.Type.STANDARD);
|
||||
} else {
|
||||
toast = new SuperActivityToast(BaseActivity, SuperToast.Type.BUTTON);
|
||||
toast.setButtonIcon(
|
||||
android.R.drawable.ic_menu_more,
|
||||
"More"
|
||||
//ZLResource.resource("dialog").getResource("button").getResource("edit").getValue()
|
||||
ZLResource.resource("footnoteToast").getResource("more").getValue()
|
||||
);
|
||||
toast.setOnClickWrapper(new OnClickWrapper("ftnt", new SuperToast.OnClickListener() {
|
||||
@Override
|
||||
|
@ -87,8 +91,10 @@ class ProcessHyperlinkAction extends FBAndroidAction {
|
|||
Reader.tryOpenFootnote(hyperlink.Id);
|
||||
}
|
||||
}));
|
||||
toast.show();
|
||||
}
|
||||
toast.setText(snippet.getText());
|
||||
toast.setDuration(SuperToast.Duration.LONG);
|
||||
toast.show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ import java.util.*;
|
|||
|
||||
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||
import org.geometerplus.zlibrary.text.view.*;
|
||||
import org.geometerplus.zlibrary.text.util.AutoTextSnippet;
|
||||
import org.geometerplus.zlibrary.text.util.TextSnippet;
|
||||
import org.geometerplus.zlibrary.text.util.TextSnippetImpl;
|
||||
|
||||
public final class Bookmark extends ZLTextFixedPosition {
|
||||
public enum DateType {
|
||||
|
@ -35,7 +35,7 @@ public final class Bookmark extends ZLTextFixedPosition {
|
|||
}
|
||||
|
||||
public static Bookmark createBookmark(Book book, String modelId, ZLTextWordCursor startCursor, int maxWords, boolean isVisible) {
|
||||
return new Bookmark(book, modelId, new TextSnippetImpl(startCursor, maxWords), isVisible);
|
||||
return new Bookmark(book, modelId, new AutoTextSnippet(startCursor, maxWords), isVisible);
|
||||
}
|
||||
|
||||
private long myId;
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.geometerplus.zlibrary.core.util.*;
|
|||
|
||||
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
||||
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
||||
import org.geometerplus.zlibrary.text.util.AutoTextSnippet;
|
||||
import org.geometerplus.zlibrary.text.util.EmptyTextSnippet;
|
||||
import org.geometerplus.zlibrary.text.view.*;
|
||||
|
||||
|
@ -211,17 +212,7 @@ public final class FBReaderApp extends ZLApplication {
|
|||
return (FBView)getCurrentView();
|
||||
}
|
||||
|
||||
public static class FootnoteData {
|
||||
public final String Text;
|
||||
public final boolean IsFull;
|
||||
|
||||
private FootnoteData(String text, boolean isFull) {
|
||||
Text = text;
|
||||
IsFull = isFull;
|
||||
}
|
||||
}
|
||||
|
||||
public FootnoteData getFootnoteData(String id) {
|
||||
public AutoTextSnippet getFootnoteData(String id) {
|
||||
if (Model == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -229,7 +220,18 @@ public final class FBReaderApp extends ZLApplication {
|
|||
if (label == null) {
|
||||
return null;
|
||||
}
|
||||
return new FootnoteData("Here will be the footnote text", false);
|
||||
final ZLTextModel model;
|
||||
if (label.ModelId != null) {
|
||||
model = Model.getFootnoteModel(label.ModelId);
|
||||
} else {
|
||||
model = Model.getTextModel();
|
||||
}
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
final ZLTextWordCursor cursor =
|
||||
new ZLTextWordCursor(new ZLTextParagraphCursor(model, label.ParagraphIndex));
|
||||
return new AutoTextSnippet(cursor, 20);
|
||||
}
|
||||
|
||||
public void tryOpenFootnote(String id) {
|
||||
|
|
|
@ -29,8 +29,8 @@ import org.geometerplus.zlibrary.core.util.ZLColor;
|
|||
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
||||
|
||||
import org.geometerplus.zlibrary.text.model.ZLTextModel;
|
||||
import org.geometerplus.zlibrary.text.util.FixedTextSnippet;
|
||||
import org.geometerplus.zlibrary.text.util.TextSnippet;
|
||||
import org.geometerplus.zlibrary.text.util.TextSnippetImpl;
|
||||
import org.geometerplus.zlibrary.text.view.*;
|
||||
import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection;
|
||||
|
||||
|
@ -747,7 +747,7 @@ public final class FBView extends ZLTextView {
|
|||
if (!isSelectionEmpty()) {
|
||||
traverser.traverse(start, end);
|
||||
}
|
||||
return new TextSnippetImpl(start, end, traverser.getText());
|
||||
return new FixedTextSnippet(start, end, traverser.getText());
|
||||
}
|
||||
|
||||
public int getCountOfSelectedWords() {
|
||||
|
|
|
@ -23,18 +23,14 @@ import java.util.*;
|
|||
|
||||
import org.geometerplus.zlibrary.text.view.*;
|
||||
|
||||
public class TextSnippetImpl implements TextSnippet {
|
||||
public final class AutoTextSnippet implements TextSnippet {
|
||||
private final ZLTextPosition myStart;
|
||||
private final ZLTextPosition myEnd;
|
||||
private final String myText;
|
||||
|
||||
public TextSnippetImpl(ZLTextPosition start, ZLTextPosition end, String text) {
|
||||
myStart = start;
|
||||
myEnd = end;
|
||||
myText = text;
|
||||
}
|
||||
public final boolean IsEndOfText;
|
||||
|
||||
public TextSnippetImpl(ZLTextWordCursor start, int maxWords) {
|
||||
public AutoTextSnippet(ZLTextWordCursor start, int maxWords) {
|
||||
final ZLTextWordCursor cursor = new ZLTextWordCursor(start);
|
||||
|
||||
final Buffer buffer = new Buffer(cursor);
|
||||
|
@ -118,6 +114,7 @@ mainLoop:
|
|||
myStart = new ZLTextFixedPosition(start);
|
||||
myEnd = buffer.Cursor;
|
||||
myText = buffer.Builder.toString();
|
||||
IsEndOfText = cursor.isEndOfText() && sentenceBuffer.isEmpty() && phraseBuffer.isEmpty();
|
||||
}
|
||||
|
||||
private static class Buffer {
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2015 FBReader.ORG Limited <contact@fbreader.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.zlibrary.text.util;
|
||||
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||
|
||||
public final class FixedTextSnippet implements TextSnippet {
|
||||
private final ZLTextPosition myStart;
|
||||
private final ZLTextPosition myEnd;
|
||||
private final String myText;
|
||||
|
||||
public FixedTextSnippet(ZLTextPosition start, ZLTextPosition end, String text) {
|
||||
myStart = start;
|
||||
myEnd = end;
|
||||
myText = text;
|
||||
}
|
||||
|
||||
public ZLTextPosition getStart() {
|
||||
return myStart;
|
||||
}
|
||||
|
||||
public ZLTextPosition getEnd() {
|
||||
return myEnd;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return myText;
|
||||
}
|
||||
}
|
|
@ -210,6 +210,10 @@ public final class ZLTextParagraphCursor {
|
|||
public final ZLTextModel Model;
|
||||
private final ArrayList<ZLTextElement> myElements = new ArrayList<ZLTextElement>();
|
||||
|
||||
public ZLTextParagraphCursor(ZLTextModel model, int index) {
|
||||
this(new CursorManager(model, null), model, index);
|
||||
}
|
||||
|
||||
ZLTextParagraphCursor(CursorManager cManager, ZLTextModel model, int index) {
|
||||
CursorManager = cManager;
|
||||
Model = model;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue