Search in sources :

Example 1 with MarkDownList

use of com.m2mobi.markymarkcommon.markdownitems.MarkDownList in project MarkyMark-Android by M2Mobi.

the class ListRule method parseMarkDownList.

/**
 * Recursive method that constructs a MarkDownList from markDown
 *
 * @param pMarkDownList
 * 		Root MarkDownList item
 * @param currentLevel
 * 		current nesting level
 * @return Returns a MarkDownList
 */
private void parseMarkDownList(final MarkDownList pMarkDownList, int currentLevel) {
    String line = mMarkDownLines.get(mCurrentLine);
    while (isList(line)) {
        final int level = getNestingLevel(line);
        if (level > currentLevel) {
            // Create sub-list
            final MarkDownList childMarkDownList = new MarkDownList(isOrdered(line), level);
            pMarkDownList.getLastListItem().addChild(childMarkDownList);
            parseMarkDownList(childMarkDownList, level);
        } else if (level == currentLevel) {
            // Add a list item
            pMarkDownList.addListItem(new ListItem(getTextForLine(line)));
            mCurrentLine++;
        } else {
            break;
        }
        if (mCurrentLine >= mMarkDownLines.size()) {
            break;
        }
        line = mMarkDownLines.get(mCurrentLine);
    }
}
Also used : MarkDownList(com.m2mobi.markymarkcommon.markdownitems.MarkDownList) ListItem(com.m2mobi.markymarkcommon.markdownitems.ListItem)

Example 2 with MarkDownList

use of com.m2mobi.markymarkcommon.markdownitems.MarkDownList in project MarkyMark-Android by M2Mobi.

the class ListDisplayItem method createLayout.

private LinearLayout createLayout(final MarkDownList pMarkDownItem, final InlineConverter<Spanned> pInlineConverter) {
    LinearLayout layout = new LinearLayout(mContext);
    layout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
    layout.setOrientation(LinearLayout.VERTICAL);
    final List<ListItem> items = pMarkDownItem.getListItems();
    for (int i = 0; i < items.size(); i++) {
        final ListItem item = items.get(i);
        final View view = getTextView(pMarkDownItem, pInlineConverter.convert(item.getText()), i);
        layout.addView(view);
        if (item.hasChild()) {
            for (MarkDownList list : item.getChild()) {
                final LinearLayout nestedLayout = createLayout(list, pInlineConverter);
                LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                params.setMargins(mIndentationSpacingPixels, 0, 0, 0);
                nestedLayout.setLayoutParams(params);
                layout.addView(nestedLayout);
            }
        }
    }
    return layout;
}
Also used : LayoutParams(android.widget.TableLayout.LayoutParams) MarkDownList(com.m2mobi.markymarkcommon.markdownitems.MarkDownList) ListItem(com.m2mobi.markymarkcommon.markdownitems.ListItem) TextView(android.widget.TextView) View(android.view.View) LinearLayout(android.widget.LinearLayout)

Example 3 with MarkDownList

use of com.m2mobi.markymarkcommon.markdownitems.MarkDownList in project MarkyMark-Android by M2Mobi.

the class ListRule method toMarkDownItem.

@Override
public MarkDownItem toMarkDownItem(final List<String> pMarkDownLines) {
    mMarkDownLines = pMarkDownLines;
    mCurrentLine = 0;
    MarkDownList list = new MarkDownList(isOrdered(mMarkDownLines.get(mCurrentLine)), 0);
    parseMarkDownList(list, getNestingLevel(mMarkDownLines.get(mCurrentLine)));
    return list;
}
Also used : MarkDownList(com.m2mobi.markymarkcommon.markdownitems.MarkDownList)

Aggregations

MarkDownList (com.m2mobi.markymarkcommon.markdownitems.MarkDownList)3 ListItem (com.m2mobi.markymarkcommon.markdownitems.ListItem)2 View (android.view.View)1 LinearLayout (android.widget.LinearLayout)1 LayoutParams (android.widget.TableLayout.LayoutParams)1 TextView (android.widget.TextView)1