From 24dec2bdc7ebe00ae2784454dce36a724596c1c6 Mon Sep 17 00:00:00 2001
From: aiman-al-masoud
Date: Sun, 8 Aug 2021 18:21:33 +0200
Subject: [PATCH] Added some more html tags and option to remove them from
paragraph.
---
.../model/classes/SinglePage.java | 62 ++++++++++++++++---
.../noadpadlight/model/interfaces/Page.java | 6 ++
.../noadpadlight/ui/ReaderActivity.java | 23 ++++++-
.../main/res/menu/reader_activity_toolbar.xml | 32 +++++++++-
4 files changed, 112 insertions(+), 11 deletions(-)
diff --git a/app/src/main/java/com/luxlunaris/noadpadlight/model/classes/SinglePage.java b/app/src/main/java/com/luxlunaris/noadpadlight/model/classes/SinglePage.java
index 5f0e9d9..9a5947f 100644
--- a/app/src/main/java/com/luxlunaris/noadpadlight/model/classes/SinglePage.java
+++ b/app/src/main/java/com/luxlunaris/noadpadlight/model/classes/SinglePage.java
@@ -445,9 +445,27 @@ private int getLine(int pos){
}
+ /**
+ * Get the html source as a list of paragraphs.
+ * @return
+ */
+ private String[] getParagraphs(){
+ //split the html source by end of paragraph tags
+ String[] pars = getText().split("
");
+
+ //adjust each paragraph
+ for(int i =0; i";
+ }
+
+ return pars;
+ }
+
/**
* Surround some text with an html tag and save.
+ * (Works on entire paragraphs.)
* @param pos
* @param tag
*/
@@ -459,14 +477,8 @@ public void addHtmlTag(int pos, String tag){
int lineNum = getLine(pos);
Log.d("LINE_NUM", lineNum+"");
- //split the html source by end of paragraph tags
- String[] pars = getText().split("");
-
- //adjust each paragraph
- for(int i =0; i";
- }
+ //get the paragraphs
+ String[] pars = getParagraphs();
//Log.d("LINE_NUM", "PARAGRAPHS:");
//for(int i =0; i", "").replaceAll("[abcefghijklmnoqrstuvwxyz]>", "");
+
+ //replace the paragraph
+ pars[lineNum] = modifiedPar;
+
+ //re-build the html source from the single paragraphs.
+ String newHtml = "";
+ for(String par : pars){
+ newHtml+=par;
+ }
+
+ //save it.
+ setText(newHtml);
+
+ }
+
diff --git a/app/src/main/java/com/luxlunaris/noadpadlight/model/interfaces/Page.java b/app/src/main/java/com/luxlunaris/noadpadlight/model/interfaces/Page.java
index fa483b3..56bab69 100644
--- a/app/src/main/java/com/luxlunaris/noadpadlight/model/interfaces/Page.java
+++ b/app/src/main/java/com/luxlunaris/noadpadlight/model/interfaces/Page.java
@@ -154,6 +154,12 @@ public interface Page extends Serializable {
public void addHtmlTag(int pos, String tag);
+ /**
+ * Remove all of the html tags from a position.
+ * @param pos
+ */
+ public void removeHtmlTags(int pos);
+
}
diff --git a/app/src/main/java/com/luxlunaris/noadpadlight/ui/ReaderActivity.java b/app/src/main/java/com/luxlunaris/noadpadlight/ui/ReaderActivity.java
index fb166eb..08b9566 100644
--- a/app/src/main/java/com/luxlunaris/noadpadlight/ui/ReaderActivity.java
+++ b/app/src/main/java/com/luxlunaris/noadpadlight/ui/ReaderActivity.java
@@ -277,9 +277,19 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
Toast.makeText(this, currentMode, Toast.LENGTH_LONG).show();
break;
case R.id.make_bold:
+ applyTag("b");
+ break;
+ case R.id.make_underlined:
+ applyTag("u");
+ break;
+ case R.id.make_italics:
+ applyTag("i");
+ break;
+
+ case R.id.make_plain:
int currentPos = textView.getSelectionStart();
saveToPage();
- page.addHtmlTag(textView.getSelectionStart(), "b");
+ page.removeHtmlTags(textView.getSelectionStart());
reloadText();
jumpToPosition(currentPos);
break;
@@ -291,6 +301,17 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
}
+ @RequiresApi(api = Build.VERSION_CODES.N)
+ private void applyTag(String tag){
+ int currentPos = textView.getSelectionStart();
+ saveToPage();
+ page.addHtmlTag(textView.getSelectionStart(), tag);
+ reloadText();
+ jumpToPosition(currentPos);
+ }
+
+
+
/**
* Uses volume keys to navigate up and down between token positions.
* @param keyCode
diff --git a/app/src/main/res/menu/reader_activity_toolbar.xml b/app/src/main/res/menu/reader_activity_toolbar.xml
index 9251e96..4db5482 100644
--- a/app/src/main/res/menu/reader_activity_toolbar.xml
+++ b/app/src/main/res/menu/reader_activity_toolbar.xml
@@ -26,9 +26,37 @@
android:icon="@android:drawable/btn_plus"
android:title="enlarge text"
app:showAsAction="always" />
+
+
+
+ android:id="@+id/styles_menu"
+ android:title="style">
+
+
+
+