Allow custom CSS for previews
This commit is contained in:
parent
6ca95063b9
commit
e3b6a3bfa5
4 changed files with 26 additions and 6 deletions
|
@ -35,7 +35,7 @@ public class MarkdownInfoActivity extends AppCompatActivity {
|
||||||
setTitle(intent.getStringExtra("title"));
|
setTitle(intent.getStringExtra("title"));
|
||||||
infoWebview.loadDataWithBaseURL(
|
infoWebview.loadDataWithBaseURL(
|
||||||
null,
|
null,
|
||||||
PreviewFragment.style + intent.getStringExtra("html"),
|
getString(R.string.pref_custom_css_default) + intent.getStringExtra("html"),
|
||||||
"text/html",
|
"text/html",
|
||||||
"UTF-8",
|
"UTF-8",
|
||||||
null
|
null
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.wbrawner.simplemarkdown.view.fragment;
|
package com.wbrawner.simplemarkdown.view.fragment;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
@ -24,17 +26,18 @@ import butterknife.Unbinder;
|
||||||
|
|
||||||
public class PreviewFragment extends Fragment implements MarkdownPreviewView {
|
public class PreviewFragment extends Fragment implements MarkdownPreviewView {
|
||||||
private static final String TAG = PreviewFragment.class.getSimpleName();
|
private static final String TAG = PreviewFragment.class.getSimpleName();
|
||||||
public static String style = "<style>" +
|
public static String FORMAT_CSS = "<style>" +
|
||||||
"pre {overflow:scroll; padding:15px; background: #F1F1F1;}" +
|
"%s" +
|
||||||
"</style>";
|
"</style>";
|
||||||
@Inject
|
@Inject
|
||||||
MarkdownPresenter presenter;
|
MarkdownPresenter presenter;
|
||||||
@BindView(R.id.markdown_view)
|
@BindView(R.id.markdown_view)
|
||||||
WebView markdownPreview;
|
WebView markdownPreview;
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
|
private SharedPreferences sharedPreferences;
|
||||||
|
|
||||||
public PreviewFragment() {
|
public PreviewFragment() {
|
||||||
// Required empty public constructor
|
// Required empty constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,6 +46,7 @@ public class PreviewFragment extends Fragment implements MarkdownPreviewView {
|
||||||
ViewGroup container,
|
ViewGroup container,
|
||||||
Bundle savedInstanceState
|
Bundle savedInstanceState
|
||||||
) {
|
) {
|
||||||
|
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(container.getContext());
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View view = inflater.inflate(R.layout.fragment_preview, container, false);
|
View view = inflater.inflate(R.layout.fragment_preview, container, false);
|
||||||
unbinder = ButterKnife.bind(this, view);
|
unbinder = ButterKnife.bind(this, view);
|
||||||
|
@ -60,7 +64,6 @@ public class PreviewFragment extends Fragment implements MarkdownPreviewView {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreview(String html) {
|
public void updatePreview(String html) {
|
||||||
if (markdownPreview == null) {
|
if (markdownPreview == null) {
|
||||||
|
@ -71,6 +74,14 @@ public class PreviewFragment extends Fragment implements MarkdownPreviewView {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String style = String.format(
|
||||||
|
FORMAT_CSS,
|
||||||
|
sharedPreferences.getString(
|
||||||
|
getString(R.string.pref_custom_css),
|
||||||
|
""
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
markdownPreview.loadDataWithBaseURL(
|
markdownPreview.loadDataWithBaseURL(
|
||||||
null,
|
null,
|
||||||
style + html,
|
style + html,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<resources>
|
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
|
||||||
<string name="app_name">Simple Markdown</string>
|
<string name="app_name">Simple Markdown</string>
|
||||||
<string name="app_name_short">Markdown</string>
|
<string name="app_name_short">Markdown</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
|
@ -49,6 +49,10 @@
|
||||||
<string name="pref_error_reports_on">Error reports will be sent</string>
|
<string name="pref_error_reports_on">Error reports will be sent</string>
|
||||||
<string name="pref_autosave_on">Files will automatically save</string>
|
<string name="pref_autosave_on">Files will automatically save</string>
|
||||||
<string name="pref_autosave_off">Files will not be automatically saved</string>
|
<string name="pref_autosave_off">Files will not be automatically saved</string>
|
||||||
|
<string name="pref_custom_css">pref.custom_css</string>
|
||||||
|
<string name="pref_title_custom_css">Custom CSS</string>
|
||||||
|
<string name="pref_description_custom_css">Paste or write your own CSS to be used for the preview pane</string>
|
||||||
|
<string name="pref_custom_css_default" translatable="false">pre {overflow:scroll; padding:15px; background: #F1F1F1;}</string>
|
||||||
<string-array name="pref_entries_default_view">
|
<string-array name="pref_entries_default_view">
|
||||||
<item>@string/value_edit_view</item>
|
<item>@string/value_edit_view</item>
|
||||||
<item>@string/value_explorer_view</item>
|
<item>@string/value_explorer_view</item>
|
||||||
|
|
|
@ -21,5 +21,10 @@
|
||||||
android:summaryOff="@string/pref_error_reports_off"
|
android:summaryOff="@string/pref_error_reports_off"
|
||||||
android:summaryOn="@string/pref_error_reports_on"
|
android:summaryOn="@string/pref_error_reports_on"
|
||||||
android:title="@string/pref_title_error_reports" />
|
android:title="@string/pref_title_error_reports" />
|
||||||
|
<EditTextPreference
|
||||||
|
android:defaultValue="@string/pref_custom_css_default"
|
||||||
|
android:key="@string/pref_custom_css"
|
||||||
|
android:title="@string/pref_title_custom_css"
|
||||||
|
android:summary="@string/pref_description_custom_css" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
Loading…
Reference in a new issue