mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-12-18 08:32:24 +03:00
- Fix #6 (Show Excerpt instead of Modified Date in List-View)
- Add some further JUnit Tests
This commit is contained in:
parent
9097f0050a
commit
727c8a93f2
5 changed files with 114 additions and 22 deletions
|
@ -0,0 +1,28 @@
|
||||||
|
package it.niedermann.owncloud.notes.util;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the NoteUtil
|
||||||
|
* Created by stefan on 06.10.15.
|
||||||
|
*/
|
||||||
|
public class NoteUtilTest extends TestCase {
|
||||||
|
public void testParseMarkDown() {
|
||||||
|
assertTrue(NoteUtil.parseMarkDown("*cursive*").contains("<em>cursive</em>"));
|
||||||
|
assertTrue(NoteUtil.parseMarkDown("**bold**").contains("<strong>bold</strong>"));
|
||||||
|
assertTrue(NoteUtil.parseMarkDown("##header").contains("<h2>header</h2>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testRemoveMarkDown() {
|
||||||
|
assertTrue("Aufzählung".equals(NoteUtil.removeMarkDown("* Aufzählung")));
|
||||||
|
assertTrue("Header".equals(NoteUtil.removeMarkDown("# Header")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIsEmptyLine() {
|
||||||
|
assertTrue(NoteUtil.isEmptyLine(" "));
|
||||||
|
assertTrue(NoteUtil.isEmptyLine("\n"));
|
||||||
|
assertTrue(NoteUtil.isEmptyLine("\n "));
|
||||||
|
assertTrue(NoteUtil.isEmptyLine(" \n"));
|
||||||
|
assertTrue(NoteUtil.isEmptyLine(" \n "));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,30 +1,26 @@
|
||||||
package it.niedermann.owncloud.notes.model;
|
package it.niedermann.owncloud.notes.model;
|
||||||
|
|
||||||
import android.text.Html;
|
|
||||||
|
|
||||||
import com.commonsware.cwac.anddown.AndDown;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
|
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
|
||||||
|
import it.niedermann.owncloud.notes.util.NoteUtil;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class Note implements Serializable {
|
public class Note implements Serializable {
|
||||||
|
|
||||||
private static final AndDown and_down = new AndDown();
|
|
||||||
private long id = 0;
|
private long id = 0;
|
||||||
private String title = "";
|
private String title = "";
|
||||||
private Calendar modified = null;
|
private Calendar modified = null;
|
||||||
private String content = "";
|
private String content = "";
|
||||||
|
private String excerpt = "";
|
||||||
private String htmlContent = null;
|
private String htmlContent = null;
|
||||||
|
|
||||||
public Note(long id, Calendar modified, String title, String content) {
|
public Note(long id, Calendar modified, String title, String content) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
if(title != null)
|
if(title != null)
|
||||||
this.title = Html.fromHtml(and_down.markdownToHtml(title)).toString().trim();
|
setTitle(title);
|
||||||
setTitle(title);
|
setTitle(title);
|
||||||
setContent(content);
|
setContent(content);
|
||||||
this.modified = modified;
|
this.modified = modified;
|
||||||
|
@ -39,7 +35,7 @@ public class Note implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
this.title = Html.fromHtml(and_down.markdownToHtml(title)).toString().trim();
|
this.title = NoteUtil.removeMarkDown(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
|
@ -57,13 +53,31 @@ public class Note implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContent(String content) {
|
public void setContent(String content) {
|
||||||
|
setExcerpt(content);
|
||||||
this.content = content;
|
this.content = content;
|
||||||
this.htmlContent = null;
|
this.htmlContent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getExcerpt() {
|
||||||
|
return excerpt;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setExcerpt(String content) {
|
||||||
|
if (content.contains("\n")) {
|
||||||
|
String[] lines = content.split("\n");
|
||||||
|
int currentLine = 1;
|
||||||
|
while (NoteUtil.isEmptyLine(lines[currentLine]) && currentLine < lines.length) {
|
||||||
|
currentLine++;
|
||||||
|
}
|
||||||
|
excerpt = NoteUtil.removeMarkDown(lines[currentLine]);
|
||||||
|
} else {
|
||||||
|
excerpt = content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getHtmlContent() {
|
public String getHtmlContent() {
|
||||||
if(htmlContent == null && getContent() != null) {
|
if(htmlContent == null && getContent() != null) {
|
||||||
htmlContent = and_down.markdownToHtml(getContent());
|
htmlContent = NoteUtil.parseMarkDown(getContent());
|
||||||
}
|
}
|
||||||
return htmlContent;
|
return htmlContent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,18 +51,18 @@ public class NoteAdapter extends ArrayAdapter<Note> {
|
||||||
// These TextViews are created in the XML files we defined.
|
// These TextViews are created in the XML files we defined.
|
||||||
|
|
||||||
TextView noteTitle = (TextView) v.findViewById(R.id.noteTitle);
|
TextView noteTitle = (TextView) v.findViewById(R.id.noteTitle);
|
||||||
TextView noteModified = (TextView) v
|
TextView noteExcerpt = (TextView) v
|
||||||
.findViewById(R.id.noteModified);
|
.findViewById(R.id.noteExcerpt);
|
||||||
|
|
||||||
// check to see if each individual textview is null.
|
// check to see if each individual textview is null.
|
||||||
// if not, assign some text!
|
// if not, assign some text!
|
||||||
if (noteTitle != null) {
|
if (noteTitle != null) {
|
||||||
noteTitle.setText(note.getTitle());
|
noteTitle.setText(note.getTitle());
|
||||||
}
|
}
|
||||||
if (noteModified != null) {
|
if (noteExcerpt != null) {
|
||||||
noteModified.setText(note.getModified("dd.MM.yyyy HH:mm"));
|
noteExcerpt.setText(note.getExcerpt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the view must be returned to our activity
|
// the view must be returned to our activity
|
||||||
return v;
|
return v;
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package it.niedermann.owncloud.notes.util;
|
||||||
|
|
||||||
|
import android.text.Html;
|
||||||
|
|
||||||
|
import com.commonsware.cwac.anddown.AndDown;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides basic functionality for Note operations.
|
||||||
|
* Created by stefan on 06.10.15.
|
||||||
|
*/
|
||||||
|
public class NoteUtil {
|
||||||
|
|
||||||
|
private static final AndDown and_down = new AndDown();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a MarkDown-String and returns its HTML-Pendant
|
||||||
|
*
|
||||||
|
* @param s String MarkDown
|
||||||
|
* @return String HTML
|
||||||
|
*/
|
||||||
|
public static String parseMarkDown(String s) {
|
||||||
|
return and_down.markdownToHtml(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strips all MarkDown from the given String
|
||||||
|
*
|
||||||
|
* @param s String - MarkDown
|
||||||
|
* @return Plain Text-String
|
||||||
|
*/
|
||||||
|
public static String removeMarkDown(String s) {
|
||||||
|
return s == null ? "" : Html.fromHtml(and_down.markdownToHtml(s)).toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a line is empty.
|
||||||
|
* " " -> empty
|
||||||
|
* "\n" -> empty
|
||||||
|
* "\n " -> empty
|
||||||
|
* " \n" -> empty
|
||||||
|
* " \n " -> empty
|
||||||
|
*
|
||||||
|
* @param line String - a single Line which ends with \n
|
||||||
|
* @return boolean isEmpty
|
||||||
|
*/
|
||||||
|
public static boolean isEmptyLine(String line) {
|
||||||
|
return removeMarkDown(line).trim().length() == 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,18 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout
|
||||||
|
android:id="@+id/noteItem"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||||
android:padding="16dp"
|
|
||||||
android:background="@drawable/list_item_background_selector"
|
android:background="@drawable/list_item_background_selector"
|
||||||
android:id="@+id/noteItem" >
|
android:padding="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/noteTitle"
|
android:id="@+id/noteTitle"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:layout_alignWithParentIfMissing="true"
|
android:layout_alignWithParentIfMissing="true"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
|
@ -19,15 +20,15 @@
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/noteModified"
|
android:id="@+id/noteExcerpt"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_below="@id/noteTitle"
|
||||||
android:ellipsize="marquee"
|
android:ellipsize="marquee"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:layout_below="@id/noteTitle"
|
|
||||||
android:textColor="@drawable/list_item_color_selector_low"
|
android:textColor="@drawable/list_item_color_selector_low"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue