Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e0b4b792 authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

Fix #216 "Help: format" option in the menu

parent 868ddcc2
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -90,8 +90,6 @@ public class NotesListViewActivity extends LockedActivity implements NoteClickLi

    private static final String TAG = NotesListViewActivity.class.getSimpleName();

    private static final boolean FEATURE_TOGGLE_FORMATTING_HELP_ENABLED = false;

    public static final String CREATED_NOTE = "it.niedermann.owncloud.notes.created_notes";
    public static final String ADAPTER_KEY_RECENT = "recent";
    public static final String ADAPTER_KEY_STARRED = "starred";
@@ -586,11 +584,7 @@ public class NotesListViewActivity extends LockedActivity implements NoteClickLi
                onItemClick(item);
            }
        });
        if(FEATURE_TOGGLE_FORMATTING_HELP_ENABLED) {
        adapterMenu.setItems(asList(itemFormattingHelp, itemTrashbin, itemSettings, itemAbout));
        } else {
            adapterMenu.setItems(asList(itemTrashbin, itemSettings, itemAbout));
        }
        binding.navigationMenu.setAdapter(adapterMenu);
    }

+133 −16
Original line number Diff line number Diff line
@@ -10,18 +10,14 @@ import android.text.method.LinkMovementMethod;
import android.util.TypedValue;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;

import com.yydcdut.markdown.MarkdownProcessor;
import com.yydcdut.markdown.syntax.text.TextFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.android.fragment.ExceptionDialogFragment;
import it.niedermann.owncloud.notes.branding.BrandedActivity;
import it.niedermann.owncloud.notes.databinding.ActivityFormattingHelpBinding;

@@ -35,7 +31,6 @@ import static it.niedermann.owncloud.notes.util.NoteUtil.getFontSizeFromPreferen

public class FormattingHelpActivity extends BrandedActivity {

    private static final String TAG = FormattingHelpActivity.class.getSimpleName();
    private ActivityFormattingHelpBinding binding;
    private String content;

@@ -47,17 +42,8 @@ public class FormattingHelpActivity extends BrandedActivity {
        setContentView(binding.getRoot());

        setSupportActionBar(binding.toolbar);
        final StringBuilder stringBuilder = new StringBuilder();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.formatting_help)))) {
            String line;
            while ((line = reader.readLine()) != null) {
                stringBuilder.append(line).append("\n");
            }
        } catch (IOException e) {
            ExceptionDialogFragment.newInstance(e).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
        }

        content = stringBuilder.toString();
        content = buildFormattingHelp();

        final MarkdownProcessor markdownProcessor = new MarkdownProcessor(this);
        markdownProcessor.factory(TextFactory.create());
@@ -118,6 +104,137 @@ public class FormattingHelpActivity extends BrandedActivity {
        }
    }

    @NonNull
    private String buildFormattingHelp() {
        final String lineBreak = "\n";
        final String indention = "  ";
        final String divider = getString(R.string.formatting_help_divider);
        final String codefence = getString(R.string.formatting_help_codefence);

        final String lists = getString(R.string.formatting_help_lists_body_1) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_lists_body_2) + lineBreak +
                getString(R.string.formatting_help_lists_body_3) + lineBreak +
                getString(R.string.formatting_help_lists_body_4) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_lists_body_5) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_lists_body_6) + lineBreak +
                getString(R.string.formatting_help_lists_body_7) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_lists_body_8) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_lists_body_9) + lineBreak +
                getString(R.string.formatting_help_lists_body_10) + lineBreak +
                indention + getString(R.string.formatting_help_lists_body_11) + lineBreak +
                indention + getString(R.string.formatting_help_lists_body_12) + lineBreak;

        final String checkboxes = getString(R.string.formatting_help_checkboxes_body_1) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_checkboxes_body_2) + lineBreak +
                getString(R.string.formatting_help_checkboxes_body_3) + lineBreak;

        final String structuredDocuments = getString(R.string.formatting_help_structured_documents_body_1) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_structured_documents_body_2) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_structured_documents_body_3) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_structured_documents_body_4) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_structured_documents_body_5) + lineBreak +
                getString(R.string.formatting_help_structured_documents_body_6) + lineBreak;

        final String javascript = getString(R.string.formatting_help_javascript_1) + lineBreak +
                indention + indention + getString(R.string.formatting_help_javascript_2) + lineBreak +
                getString(R.string.formatting_help_javascript_3) + lineBreak;

        return getString(R.string.formatting_help_title, getString(R.string.formatting_help_cbf_title)) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_cbf_body_1) + lineBreak +
                getString(R.string.formatting_help_cbf_body_2) + lineBreak +
                lineBreak +
                divider + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_title, getString(R.string.formatting_help_text_title)) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_text_body) + lineBreak +
                lineBreak +
                codefence + lineBreak +
                getString(R.string.formatting_help_text_body) + lineBreak +
                codefence + lineBreak +
                lineBreak +
                divider + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_title, getString(R.string.formatting_help_lists_title)) + lineBreak +
                lineBreak +
                lists +
                lineBreak +
                codefence + lineBreak +
                lists +
                codefence + lineBreak +
                lineBreak +
                divider + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_title, getString(R.string.formatting_help_checkboxes_title)) + lineBreak +
                lineBreak +
                checkboxes +
                lineBreak +
                codefence + lineBreak +
                checkboxes +
                codefence + lineBreak +
                lineBreak +
                divider + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_title, getString(R.string.formatting_help_structured_documents_title)) + lineBreak +
                lineBreak +
                structuredDocuments +
                lineBreak +
                codefence + lineBreak +
                structuredDocuments +
                codefence + lineBreak +
                lineBreak +
                divider + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_title, getString(R.string.formatting_help_code_title)) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_code_body_1) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_code_body_2) + lineBreak +
                getString(R.string.formatting_help_code_body_3) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_code_body_4) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_codefence_escaped) + lineBreak +
                javascript +
                getString(R.string.formatting_help_codefence_escaped) + lineBreak +
                lineBreak +
                codefence + lineBreak +
                javascript +
                codefence + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_code_body_5) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_codefence_javascript_escaped) + lineBreak +
                javascript +
                getString(R.string.formatting_help_codefence_escaped) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_codefence_javascript) + lineBreak +
                javascript +
                codefence + lineBreak +
                lineBreak +
                divider + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_title, getString(R.string.formatting_help_unsupported_title)) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_unsupported_body_1) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_unsupported_body_2) + lineBreak +
                getString(R.string.formatting_help_unsupported_body_3) + lineBreak +
                lineBreak +
                getString(R.string.formatting_help_unsupported_body_4) + lineBreak;
    }

    @Override
    public void applyBrand(int mainColor, int textColor) {

+0 −150
Original line number Diff line number Diff line
# Context based formatting

A major design goal of the Notes app is to provide a distraction free tool. Though you will be able to format your texts with Markdown. For various of the below mentioned examples, you can use shortcuts so you can format your notes without typing in the codes below.
Just select a range of text or tap on your cursor at any position and you will get a popup menu which contains next to the default entries `Cut`, `Copy`, `Select all` entries like `Link` or `Checkbox`.

---

# Text

It's very easy to make some words **bold** and other words *italic* with Markdown. You can ~~strike~~ some words through and even [link to Google](http://google.com).

```
It's very easy to make some words **bold** and other words *italic* with Markdown. You can ~~strike~~ some words through and even [link to Google](http://google.com).
```

---

# Lists

Sometimes you want numbered lists:

1. One
2. Two
3. Three

Sometimes you want bullet points:

* Start a line with a star
* Profit!

Alternatively,

- Dashes work just as well
- And if you have sub points, put two spaces before the dash or star:
  - Like this
  - And this

```
Sometimes you want numbered lists:

1. One
2. Two
3. Three

Sometimes you want bullet points:

* Start a line with a star
* Profit!

Alternatively,

- Dashes work just as well
- And if you have sub points, put two spaces before the dash or star:
  - Like this
  - And this
```

---

# Checkbox

To create a checkbox, use a list followed by brackets

- [ ] Item 1
* [ ] Item 2

```
To create a checkbox, use a list followed by brackets

- [ ] Item 1
* [ ] Item 2
```

---

# Structured documents

Sometimes it's useful to have different levels of headings to structure your documents. Start lines with a `#` to create headings. Multiple `##` in a row denote smaller heading sizes.

### This is a third-tier heading

You can use one `#` all the way up to `######` six for different heading sizes.

If you'd like to quote someone, use the > character before the line:

> Coffee. The finest organic suspension ever devised... I beat the Borg with it.
> - Captain Janeway

```
# Structured documents

Sometimes it's useful to have different levels of headings to structure your documents. Start lines with a `#` to create headings. Multiple `##` in a row denote smaller heading sizes.

### This is a third-tier heading

You can use one `#` all the way up to `######` six for different heading sizes.

If you'd like to quote someone, use the > character before the line:

> Coffee. The finest organic suspension ever devised... I beat the Borg with it.
> - Captain Janeway
```

---

# Code

There are many different ways to style code with Markdown. If you have inline code blocks, wrap them in backticks:

\`var example = true\`
`var example = true`

Markdown also supports something called code fencing, which allows for multiple lines without indentation:

\`\`\`
if (isAwesome){
  return true
}
\`\`\`

```
if (isAwesome){
  return true
}
```

And if you'd like to use syntax highlighting, include the language:

\`\`\`javascript
if (isAwesome){
  return true
}
\`\`\`

```javascript
if (isAwesome){
  return true
}
```

---

# Unsupported

While we try to continuously improve the support for Markdown, there are a few features which are not yet supported by Notes:

- Tables
- Images

If you are interested in contributing support for one of those features, get in contact with us via GitHub or E-Mail.
 No newline at end of file
+57 −0
Original line number Diff line number Diff line
@@ -232,4 +232,61 @@
        <item quantity="one">%d selected</item>
        <item quantity="other">%d selected</item>
    </plurals>

    <string name="formatting_help_title" translatable="false"># %1$s</string>
    <string name="formatting_help_divider" translateable="false">---</string>
    <string name="formatting_help_codefence" translateable="false">```</string>
    <string name="formatting_help_codefence_escaped" translatable="false">\\`\\`\\`</string>
    <string name="formatting_help_javascript_1" translatable="false">if (isAwesome){</string>
    <string name="formatting_help_javascript_2" translatable="false">return true</string>
    <string name="formatting_help_javascript_3" translatable="false">}</string>
    <string name="formatting_help_codefence_javascript_escaped" translatable="false">\\`\\`\\`javascript</string>
    <string name="formatting_help_codefence_javascript" translateable="false">```javascript</string>

    <string name="formatting_help_cbf_title">Context based formatting</string>
    <string name="formatting_help_cbf_body_1">A major design goal of the Notes app is to provide a distraction free tool. Though you will be able to format your texts with Markdown. For various of the below mentioned examples, you can use shortcuts so you can format your notes without typing in the codes below.</string>
    <string name="formatting_help_cbf_body_2">Just select a range of text or tap on your cursor at any position and you will get a popup menu which contains next to the default entries `Cut`, `Copy`, `Select all` entries like `Link` or `Checkbox`.</string>

    <string name="formatting_help_text_title">Text</string>
    <string name="formatting_help_text_body">It\'s very easy to make some words **bold** and other words *italic* with Markdown. You can ~~strike~~ some words through and even [link to Nextcloud](https://nextcloud.com).</string>

    <string name="formatting_help_lists_title">Lists</string>
    <string name="formatting_help_lists_body_1">Sometimes you want numbered lists:</string>
    <string name="formatting_help_lists_body_2">1. One</string>
    <string name="formatting_help_lists_body_3">2. Two</string>
    <string name="formatting_help_lists_body_4">3. Three</string>
    <string name="formatting_help_lists_body_5">Sometimes you want bullet points:</string>
    <string name="formatting_help_lists_body_6">* Start a line with a star</string>
    <string name="formatting_help_lists_body_7">* Profit!</string>
    <string name="formatting_help_lists_body_8">Alternatively,</string>
    <string name="formatting_help_lists_body_9">- Dashes work just as well</string>
    <string name="formatting_help_lists_body_10">- And if you have sub points, put two spaces before the dash or star:</string>
    <string name="formatting_help_lists_body_11">- Like this</string>
    <string name="formatting_help_lists_body_12">- And this</string>

    <string name="formatting_help_checkboxes_title">Checkboxes</string>
    <string name="formatting_help_checkboxes_body_1">To create a checkbox, use a list followed by brackets</string>
    <string name="formatting_help_checkboxes_body_2">- [ ] Item 1</string>
    <string name="formatting_help_checkboxes_body_3">* [ ] Item 2</string>

    <string name="formatting_help_structured_documents_title">Structured documents</string>
    <string name="formatting_help_structured_documents_body_1">Sometimes it\'s useful to have different levels of headings to structure your documents. Start lines with a `#` to create headings. Multiple `##` in a row denote smaller heading sizes.</string>
    <string name="formatting_help_structured_documents_body_2">### This is a third-tier heading</string>
    <string name="formatting_help_structured_documents_body_3">You can use one `#` all the way up to `######` six for different heading sizes.</string>
    <string name="formatting_help_structured_documents_body_4">If you\'d like to quote someone, use the > character before the line:</string>
    <string name="formatting_help_structured_documents_body_5">> Coffee. The finest organic suspension ever devised… I beat the Borg with it.</string>
    <string name="formatting_help_structured_documents_body_6">> - Captain Janeway</string>

    <string name="formatting_help_code_title">Code</string>
    <string name="formatting_help_code_body_1">There are many different ways to style code with Markdown. If you have inline code blocks, wrap them in backticks:</string>
    <string name="formatting_help_code_body_2">\\`var example = true\\`</string>
    <string name="formatting_help_code_body_3">`var example = true`</string>
    <string name="formatting_help_code_body_4">Markdown also supports something called code fencing, which allows for multiple lines without indentation:</string>
    <string name="formatting_help_code_body_5">And if you\'d like to use syntax highlighting, include the language:</string>

    <string name="formatting_help_unsupported_title">Unsupported</string>
    <string name="formatting_help_unsupported_body_1">While we try to continuously improve the support for Markdown, there are a few features which are not yet supported by Notes:</string>
    <string name="formatting_help_unsupported_body_2">- Tables</string>
    <string name="formatting_help_unsupported_body_3">- Images</string>
    <string name="formatting_help_unsupported_body_4">If you are interested in contributing support for one of those features, get in contact with us via GitHub or E-Mail.</string>
</resources>
+1 −0
Original line number Diff line number Diff line
- 📌 Remember last scrolling position per note (#227)
- ❓ "Help: format" option in the menu (#216)
- 🐞 Fix toggling checkboxes when note contains codefences with empty lines
 No newline at end of file