From e3b6a3bfa550631c14d2f9b945884ce4ae6f0257 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Fri, 8 Feb 2019 20:35:18 -0600 Subject: [PATCH] Allow custom CSS for previews --- .../view/activity/MarkdownInfoActivity.java | 2 +- .../view/fragment/PreviewFragment.java | 19 +++++++++++++++---- app/src/main/res/values/strings.xml | 6 +++++- app/src/main/res/xml/pref_general.xml | 5 +++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MarkdownInfoActivity.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MarkdownInfoActivity.java index 0eec104..d5c40b7 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MarkdownInfoActivity.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MarkdownInfoActivity.java @@ -35,7 +35,7 @@ public class MarkdownInfoActivity extends AppCompatActivity { setTitle(intent.getStringExtra("title")); infoWebview.loadDataWithBaseURL( null, - PreviewFragment.style + intent.getStringExtra("html"), + getString(R.string.pref_custom_css_default) + intent.getStringExtra("html"), "text/html", "UTF-8", null diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/PreviewFragment.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/PreviewFragment.java index 066849a..bbf10d0 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/PreviewFragment.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/PreviewFragment.java @@ -1,7 +1,9 @@ package com.wbrawner.simplemarkdown.view.fragment; import android.app.Activity; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; @@ -24,17 +26,18 @@ import butterknife.Unbinder; public class PreviewFragment extends Fragment implements MarkdownPreviewView { private static final String TAG = PreviewFragment.class.getSimpleName(); - public static String style = ""; @Inject MarkdownPresenter presenter; @BindView(R.id.markdown_view) WebView markdownPreview; private Unbinder unbinder; + private SharedPreferences sharedPreferences; public PreviewFragment() { - // Required empty public constructor + // Required empty constructor } @Override @@ -43,6 +46,7 @@ public class PreviewFragment extends Fragment implements MarkdownPreviewView { ViewGroup container, Bundle savedInstanceState ) { + sharedPreferences = PreferenceManager.getDefaultSharedPreferences(container.getContext()); // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_preview, container, false); unbinder = ButterKnife.bind(this, view); @@ -60,7 +64,6 @@ public class PreviewFragment extends Fragment implements MarkdownPreviewView { super.onViewCreated(view, savedInstanceState); } - @Override public void updatePreview(String html) { if (markdownPreview == null) { @@ -71,6 +74,14 @@ public class PreviewFragment extends Fragment implements MarkdownPreviewView { return; } + String style = String.format( + FORMAT_CSS, + sharedPreferences.getString( + getString(R.string.pref_custom_css), + "" + ) + ); + markdownPreview.loadDataWithBaseURL( null, style + html, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 86729fd..6522f5e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,4 @@ - + Simple Markdown Markdown Settings @@ -49,6 +49,10 @@ Error reports will be sent Files will automatically save Files will not be automatically saved + pref.custom_css + Custom CSS + Paste or write your own CSS to be used for the preview pane + pre {overflow:scroll; padding:15px; background: #F1F1F1;} @string/value_edit_view @string/value_explorer_view diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index a51d022..f381a78 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -21,5 +21,10 @@ android:summaryOff="@string/pref_error_reports_off" android:summaryOn="@string/pref_error_reports_on" android:title="@string/pref_title_error_reports" /> +