From 1b3086572f2cd24111f1f849bc65d77079c7440d Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Thu, 21 Jan 2021 00:34:29 +0100 Subject: [PATCH 1/2] Styling tag for Markdown content --- .../ui/findcontent/FileViewFragment.java | 30 ++++++++++++++++++- app/src/main/res/values-night/colors.xml | 3 ++ app/src/main/res/values/colors.xml | 3 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index 8686c0e3..e04e5068 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java @@ -40,6 +40,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.AppCompatSpinner; import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.core.content.ContextCompat; import androidx.core.text.HtmlCompat; import androidx.core.widget.NestedScrollView; import androidx.preference.PreferenceManager; @@ -76,8 +77,12 @@ import com.google.android.material.button.MaterialButton; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.textfield.TextInputEditText; +import org.commonmark.node.Code; import org.commonmark.node.Node; import org.commonmark.parser.Parser; +import org.commonmark.renderer.html.AttributeProvider; +import org.commonmark.renderer.html.AttributeProviderContext; +import org.commonmark.renderer.html.AttributeProviderFactory; import org.commonmark.renderer.html.HtmlRenderer; import org.json.JSONException; import org.json.JSONObject; @@ -2194,7 +2199,14 @@ public class FileViewFragment extends BaseFragment implements private String buildMarkdownHtml(String markdown) { Parser parser = Parser.builder().build(); Node document = parser.parse(markdown); - HtmlRenderer renderer = HtmlRenderer.builder().build(); + HtmlRenderer renderer = HtmlRenderer.builder() + .attributeProviderFactory(new AttributeProviderFactory() { + @Override + public AttributeProvider create(AttributeProviderContext context) { + return new CodeAttributeProvider(); + } + }) + .build(); String markdownHtml = renderer.render(document); return "\n" + @@ -3235,4 +3247,20 @@ public class FileViewFragment extends BaseFragment implements }); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } + + class CodeAttributeProvider implements AttributeProvider { + + @Override + public void setAttributes(Node node, String tagName, Map attributes) { + if (node instanceof Code) { + Context context = getContext(); + String colorCodeText = "#".concat(Integer.toHexString(ContextCompat.getColor(context, R.color.codeTagText) & 0x00ffffff)); + String colorCodeBg = "#".concat(Integer.toHexString(ContextCompat.getColor(context, R.color.codeTagBackground) & 0x00ffffff)); + String codeStyle = "display: inline-block; border-radius: 0.2rem" + + "; color: " + colorCodeText + "; background-color: " + colorCodeBg + + "; font-size: 0.8571rem; padding: calc(2rem/5 - 4px) calc(2rem/5) calc(2rem/5 - 5px);"; + attributes.put("style", codeStyle); + } + } + } } diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 59546685..e2a7f6bb 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -58,4 +58,7 @@ #CAEDB9 #CC333333 + + #E8B692 + #464B50 \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index d35fef96..7b5bdf3b 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -58,4 +58,7 @@ #CAEDB9 #CC333333 + + #2E3439 + #D0E8FF \ No newline at end of file From 127d8052cafbab466bbb8dca1abd1398234c033f Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Fri, 12 Feb 2021 01:28:22 +0100 Subject: [PATCH 2/2] Change HelperTest to JUnit4 and remove example test class --- .../java/io/lbry/browser/ExampleUnitTest.java | 17 ----------------- .../java/io/lbry/browser/utils/HelperTest.java | 4 +--- 2 files changed, 1 insertion(+), 20 deletions(-) delete mode 100644 app/src/test/java/io/lbry/browser/ExampleUnitTest.java diff --git a/app/src/test/java/io/lbry/browser/ExampleUnitTest.java b/app/src/test/java/io/lbry/browser/ExampleUnitTest.java deleted file mode 100644 index 8374b9c4..00000000 --- a/app/src/test/java/io/lbry/browser/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.lbry.browser; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/app/src/test/java/io/lbry/browser/utils/HelperTest.java b/app/src/test/java/io/lbry/browser/utils/HelperTest.java index 7eba6a8a..429d470f 100644 --- a/app/src/test/java/io/lbry/browser/utils/HelperTest.java +++ b/app/src/test/java/io/lbry/browser/utils/HelperTest.java @@ -1,7 +1,5 @@ package io.lbry.browser.utils; -import junit.framework.TestCase; - -public class HelperTest extends TestCase { +public class HelperTest { } \ No newline at end of file