Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First simple OPDS catalog browsing implemented.

  • Loading branch information...
commit 8341358df3eded910a9fe4288f564dae6305137c 1 parent 5a5586a
@NightWhistler NightWhistler authored
Showing with 1,075 additions and 1 deletion.
  1. +12 −1 AndroidManifest.xml
  2. +34 −0 res/layout/catalog_item.xml
  3. +75 −0 src/main/java/net/nightwhistler/nucular/atom/AtomElement.java
  4. +53 −0 src/main/java/net/nightwhistler/nucular/atom/Author.java
  5. +42 −0 src/main/java/net/nightwhistler/nucular/atom/Content.java
  6. +34 −0 src/main/java/net/nightwhistler/nucular/atom/Entry.java
  7. +42 −0 src/main/java/net/nightwhistler/nucular/atom/Feed.java
  8. +47 −0 src/main/java/net/nightwhistler/nucular/atom/Link.java
  9. +81 −0 src/main/java/net/nightwhistler/nucular/parser/AuthorParser.java
  10. +74 −0 src/main/java/net/nightwhistler/nucular/parser/ContentParser.java
  11. +79 −0 src/main/java/net/nightwhistler/nucular/parser/ElementParser.java
  12. +49 −0 src/main/java/net/nightwhistler/nucular/parser/EntryParser.java
  13. +64 −0 src/main/java/net/nightwhistler/nucular/parser/FeedParser.java
  14. +46 −0 src/main/java/net/nightwhistler/nucular/parser/LinkParser.java
  15. +103 −0 src/main/java/net/nightwhistler/nucular/parser/Nucular.java
  16. +37 −0 src/main/java/net/nightwhistler/nucular/parser/TitleParser.java
  17. +27 −0 src/main/java/net/nightwhistler/nucular/parser/UnknownElementParser.java
  18. +98 −0 src/main/java/net/nightwhistler/pageturner/activity/CatalogActivity.java
  19. +78 −0 src/main/java/net/nightwhistler/pageturner/catalog/CatalogListAdapter.java
View
13 AndroidManifest.xml
@@ -51,7 +51,18 @@
<activity android:name=".activity.LibraryActivity"
android:label="@string/library" />
-
+
+ <activity android:name=".activity.CatalogActivity"
+ android:label="Catalog" >
+
+
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+
+ </activity>
+
<activity android:name="org.acra.CrashReportDialog"
android:theme="@android:style/Theme.Dialog"
android:launchMode="singleInstance"
View
34 res/layout/catalog_item.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="horizontal" >
+
+ <ImageView
+ android:id="@+id/itemIcon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@drawable/book" />
+ <LinearLayout android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/itemTitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Large Text"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <TextView
+ android:id="@+id/itemDescription"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Small Text"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+
+ </LinearLayout>
+
+
+
+</LinearLayout>
View
75 src/main/java/net/nightwhistler/nucular/atom/AtomElement.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.atom;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public abstract class AtomElement {
+
+ private String title;
+ private String id;
+ private Content content;
+
+ private Author author;
+
+ private List<Link> links = new ArrayList<Link>();
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public Content getContent() {
+ return content;
+ }
+
+ public void setContent(Content content) {
+ this.content = content;
+ }
+
+ public Author getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(Author author) {
+ this.author = author;
+ }
+
+ public List<Link> getLinks() {
+ return Collections.unmodifiableList( links );
+ }
+
+ public void addLink( Link link ) {
+ this.links.add(link);
+ }
+
+}
View
53 src/main/java/net/nightwhistler/nucular/atom/Author.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.atom;
+
+public class Author {
+
+ private String name;
+ private String email;
+
+ private String uri;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getUri() {
+ return uri;
+ }
+
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+
+}
View
42 src/main/java/net/nightwhistler/nucular/atom/Content.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.atom;
+
+public class Content {
+
+ private String type;
+ private String text;
+
+ public String getText() {
+ return text;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+}
View
34 src/main/java/net/nightwhistler/nucular/atom/Entry.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.atom;
+
+public class Entry extends AtomElement {
+
+ private String updated;
+
+ public String getUpdated() {
+ return updated;
+ }
+
+ public void setUpdated(String updated) {
+ this.updated = updated;
+ }
+
+
+}
View
42 src/main/java/net/nightwhistler/nucular/atom/Feed.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.atom;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Represents a low-level Atom feed, as parsed from XML.
+ *
+ * @author Alex Kuiper
+ *
+ */
+public class Feed extends AtomElement {
+
+ private List<Entry> entries = new ArrayList<Entry>();
+
+ public List<Entry> getEntries() {
+ return Collections.unmodifiableList( entries );
+ }
+
+ public void addEntry(Entry entry) {
+ this.entries.add(entry);
+ }
+}
View
47 src/main/java/net/nightwhistler/nucular/atom/Link.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.atom;
+
+public class Link {
+
+ private String href;
+ private String type;
+ private String rel;
+
+ public String getHref() {
+ return href;
+ }
+ public void setHref(String href) {
+ this.href = href;
+ }
+ public String getType() {
+ return type;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+ public String getRel() {
+ return rel;
+ }
+ public void setRel(String rel) {
+ this.rel = rel;
+ }
+
+
+}
View
81 src/main/java/net/nightwhistler/nucular/parser/AuthorParser.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.parser;
+
+import net.nightwhistler.nucular.atom.AtomElement;
+import net.nightwhistler.nucular.atom.Author;
+
+public class AuthorParser extends ElementParser {
+
+ private Author author;
+
+ public AuthorParser(AtomElement parent) {
+ super("author");
+ this.author = new Author();
+ parent.setAuthor(author);
+ }
+
+ @Override
+ protected ElementParser createChildParser(String tagName) {
+
+ if ( tagName.equals("name")) {
+ return new NameParser();
+ } else if ( tagName.equals("uri")) {
+ return new UriParser();
+ } else if ( tagName.equals("email")) {
+ return new EmailParser();
+ }
+
+ return super.createChildParser(tagName);
+ }
+
+ private class NameParser extends ElementParser {
+ public NameParser() {
+ super("name");
+ }
+
+ @Override
+ public void setTextContent(String text) {
+ author.setName(text);
+ }
+ }
+
+ private class UriParser extends ElementParser {
+ public UriParser() {
+ super("uri");
+ }
+
+ @Override
+ public void setTextContent(String text) {
+ author.setUri(text);
+ }
+ }
+
+ private class EmailParser extends ElementParser {
+ public EmailParser() {
+ super("email");
+ }
+
+ @Override
+ public void setTextContent(String text) {
+ author.setEmail(text);
+ }
+ }
+
+}
View
74 src/main/java/net/nightwhistler/nucular/parser/ContentParser.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.parser;
+
+import java.util.Map;
+
+import net.nightwhistler.nucular.atom.AtomElement;
+import net.nightwhistler.nucular.atom.Content;
+
+public class ContentParser extends ElementParser {
+
+ private Content content;
+
+ StringBuffer buffer;
+
+ private boolean finished;
+
+ public ContentParser(AtomElement parent) {
+ super("content");
+ this.content = new Content();
+ parent.setContent(content);
+
+ this.buffer = new StringBuffer();
+ this.finished = false;
+ }
+
+ @Override
+ public void startElement(String name, Map<String, String> attributes) {
+ this.buffer.append("<" + name + ">");
+ }
+
+ @Override
+ public boolean isFinished() {
+ return finished;
+ }
+
+ @Override
+ public void setAttributes(Map<String, String> attributes) {
+ this.content.setType(attributes.get("type"));
+ }
+
+ @Override
+ public void endElement(String name) {
+
+ if ( name.equals("content") ) {
+ finished = true;
+ this.content.setText(buffer.toString());
+ } else {
+ this.buffer.append( "</" + name + ">" );
+ }
+
+ }
+
+ @Override
+ public void setTextContent(String text) {
+ this.buffer.append( text );
+ }
+}
View
79 src/main/java/net/nightwhistler/nucular/parser/ElementParser.java
@@ -0,0 +1,79 @@
+
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.parser;
+
+import java.util.Map;
+
+public abstract class ElementParser {
+
+ private String elementName;
+
+ private ElementParser childParser;
+
+ private boolean finished;
+
+ public ElementParser(String elementName) {
+ this.elementName = elementName;
+ this.finished = false;
+ }
+
+ public void startElement( String name, Map<String, String> attributes ) {
+
+ if ( this.childParser != null ) {
+ childParser.startElement(name, attributes);
+ } else {
+ this.childParser = createChildParser(name);
+ this.childParser.setAttributes(attributes);
+ }
+ }
+
+ public boolean isFinished() {
+ return finished;
+ }
+
+ public void endElement( String name ) {
+
+ if ( this.childParser != null ) {
+ this.childParser.endElement(name);
+
+ if ( childParser.isFinished() ) {
+ childParser = null;
+ }
+ } else {
+ if ( name.equals(this.elementName) ) {
+ this.finished = true;
+ }
+ }
+
+ }
+
+ public void setTextContent( String text ) {
+ if ( childParser != null ) {
+ childParser.setTextContent(text);
+ }
+ }
+
+ public void setAttributes( Map<String, String> attributes ) {}
+
+ protected ElementParser createChildParser(String tagName) {
+ return new UnknownElementParser(tagName);
+ }
+
+}
View
49 src/main/java/net/nightwhistler/nucular/parser/EntryParser.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.parser;
+
+import net.nightwhistler.nucular.atom.Entry;
+import net.nightwhistler.nucular.atom.Feed;
+
+public class EntryParser extends ElementParser {
+
+ private Entry entry;
+
+ public EntryParser(Feed parent) {
+ super("entry");
+ this.entry = new Entry();
+ parent.addEntry(entry);
+ }
+
+ @Override
+ protected ElementParser createChildParser(String tagName) {
+
+ if ( tagName.equals("link")) {
+ return new LinkParser(entry);
+ } else if ( tagName.equals("content")) {
+ return new ContentParser(entry);
+ } else if ( tagName.equals("title") ) {
+ return new TitleParser(entry);
+ } else if ( tagName.equals("author")) {
+ return new AuthorParser(entry);
+ }
+
+ return super.createChildParser(tagName);
+ }
+}
View
64 src/main/java/net/nightwhistler/nucular/parser/FeedParser.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.parser;
+
+import java.util.Map;
+
+import net.nightwhistler.nucular.atom.Feed;
+
+
+public class FeedParser extends ElementParser {
+
+ private Feed feed;
+
+ public FeedParser() {
+ super("feed");
+ this.feed = new Feed();
+ }
+
+ public Feed getFeed() {
+ return feed;
+ }
+
+ @Override
+ public void startElement(String name, Map<String, String> attributes) {
+ if ( ! name.equals("feed") ) { //Minor bootstrapping hack
+ super.startElement(name, attributes);
+ }
+ }
+
+ @Override
+ protected ElementParser createChildParser(String tagName) {
+
+ if ( tagName.equals("link")) {
+ return new LinkParser(feed);
+ } else if ( tagName.equals("content")) {
+ return new ContentParser(feed);
+ } else if ( tagName.equals("title") ) {
+ return new TitleParser(feed);
+ } else if ( tagName.equals("entry")) {
+ return new EntryParser(feed);
+ } else if ( tagName.equals("author")) {
+ return new AuthorParser(feed);
+ }
+
+ return super.createChildParser(tagName);
+ }
+
+}
View
46 src/main/java/net/nightwhistler/nucular/parser/LinkParser.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.parser;
+
+import java.util.Map;
+
+import net.nightwhistler.nucular.atom.AtomElement;
+import net.nightwhistler.nucular.atom.Link;
+
+public class LinkParser extends ElementParser {
+
+ private AtomElement element;
+
+ public LinkParser(AtomElement parent) {
+ super("link");
+ this.element = parent;
+ }
+
+ @Override
+ public void setAttributes(Map<String, String> attributes) {
+ Link link = new Link();
+
+ link.setHref(attributes.get("href"));
+ link.setRel(attributes.get("rel"));
+ link.setType(attributes.get("type"));
+
+ this.element.addLink(link);
+ }
+
+}
View
103 src/main/java/net/nightwhistler/nucular/parser/Nucular.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.parser;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import net.nightwhistler.nucular.atom.Feed;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class Nucular extends DefaultHandler {
+
+ private FeedParser feedParser;
+
+ public static Feed readFromStream(InputStream stream)
+ throws ParserConfigurationException, SAXException, IOException {
+
+ SAXParserFactory parseFactory = SAXParserFactory.newInstance();
+ SAXParser xmlParser = parseFactory.newSAXParser();
+
+ XMLReader xmlIn = xmlParser.getXMLReader();
+ Nucular catalogParser = new Nucular();
+ xmlIn.setContentHandler(catalogParser);
+
+ xmlIn.parse(new InputSource(stream));
+
+ return catalogParser.getFeed();
+ }
+
+ private Nucular() {
+ this.feedParser = new FeedParser();
+ }
+
+ public Feed getFeed() {
+ return feedParser.getFeed();
+ }
+
+ private String pickName( String qName, String localName ) {
+ if ( localName.length() == 0 ) {
+ return qName;
+ } else {
+ return localName;
+ }
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) throws SAXException {
+
+ Map<String, String> attrMap = new HashMap<String, String>();
+ for (int i = 0; i < attributes.getLength(); i++) {
+ String value = attributes.getValue(i);
+ String key = attributes.getLocalName(i);
+ attrMap.put(key, value);
+ }
+
+ this.feedParser.startElement(pickName(qName, localName), attrMap);
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length)
+ throws SAXException {
+
+ StringBuffer buff = new StringBuffer();
+ buff.append(ch, start, length);
+
+ this.feedParser.setTextContent(buff.toString());
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+ this.feedParser.endElement(pickName(qName,localName));
+ }
+
+}
View
37 src/main/java/net/nightwhistler/nucular/parser/TitleParser.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.parser;
+
+import net.nightwhistler.nucular.atom.AtomElement;
+
+public class TitleParser extends ElementParser {
+
+ private AtomElement parent;
+
+ public TitleParser(AtomElement parent) {
+ super("title");
+ this.parent = parent;
+ }
+
+ @Override
+ public void setTextContent(String text) {
+ parent.setTitle(text);
+ }
+
+}
View
27 src/main/java/net/nightwhistler/nucular/parser/UnknownElementParser.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2012 Alex Kuiper
+ *
+ * This file is part of PageTurner
+ *
+ * PageTurner is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * PageTurner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PageTurner. If not, see <http://www.gnu.org/licenses/>.*
+ */
+package net.nightwhistler.nucular.parser;
+
+
+public class UnknownElementParser extends ElementParser {
+
+ public UnknownElementParser(String name) {
+ super(name);
+ }
+}
View
98 src/main/java/net/nightwhistler/pageturner/activity/CatalogActivity.java
@@ -0,0 +1,98 @@
+package net.nightwhistler.pageturner.activity;
+
+
+import java.util.List;
+import java.util.Stack;
+
+import net.nightwhistler.nucular.atom.Entry;
+import net.nightwhistler.nucular.atom.Feed;
+import net.nightwhistler.nucular.atom.Link;
+import net.nightwhistler.nucular.parser.Nucular;
+import net.nightwhistler.pageturner.catalog.CatalogListAdapter;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+
+import android.app.ListActivity;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.ListView;
+
+public class CatalogActivity extends ListActivity {
+
+ private static final String BASE_URL = "http://www.feedbooks.com/catalog.atom";
+
+ private CatalogListAdapter adapter;
+
+ private Stack<String> navStack = new Stack<String>();
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+
+ this.adapter = new CatalogListAdapter(this);
+ setListAdapter(adapter);
+
+ super.onCreate(savedInstanceState);
+
+ new LoadOPDSTask().execute(BASE_URL);
+ }
+
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id) {
+
+ Entry entry = adapter.getItem(position);
+
+ List<Link> links = entry.getLinks();
+
+ for ( Link link: links ) {
+ if ( link.getType().startsWith("application/atom+xml")) {
+ String href = link.getHref();
+ navStack.push(href);
+ new LoadOPDSTask().execute(href);
+ return;
+ }
+ }
+
+ }
+
+ @Override
+ public void onBackPressed() {
+ navStack.pop();
+
+ if ( navStack.isEmpty() ) {
+ new LoadOPDSTask().execute(BASE_URL);
+ } else {
+ new LoadOPDSTask().execute(navStack.peek());
+ }
+ }
+
+
+ private class LoadOPDSTask extends AsyncTask<String, Integer, Feed> {
+
+ @Override
+ protected Feed doInBackground(String... params) {
+
+ DefaultHttpClient client = new DefaultHttpClient();
+ HttpGet get = new HttpGet( params[0] );
+
+ try {
+ HttpResponse response = client.execute(get);
+ Feed feed = Nucular.readFromStream( response.getEntity().getContent() );
+ return feed;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ @Override
+ protected void onPostExecute(Feed result) {
+ adapter.setFeed(result);
+ }
+
+ }
+
+}
View
78 src/main/java/net/nightwhistler/pageturner/catalog/CatalogListAdapter.java
@@ -0,0 +1,78 @@
+package net.nightwhistler.pageturner.catalog;
+
+import net.nightwhistler.htmlspanner.HtmlSpanner;
+import net.nightwhistler.nucular.atom.Entry;
+import net.nightwhistler.nucular.atom.Feed;
+import net.nightwhistler.pageturner.R;
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+public class CatalogListAdapter extends BaseAdapter {
+
+ private Feed feed;
+ private Context context;
+
+ HtmlSpanner spanner = new HtmlSpanner();
+
+ public CatalogListAdapter(Context context) {
+ this.context = context;
+ }
+
+ public void setFeed( Feed feed ) {
+ this.feed = feed;
+ this.notifyDataSetChanged();
+ }
+
+ @Override
+ public int getCount() {
+
+ if ( feed == null ) {
+ return 0;
+ }
+
+ return feed.getEntries().size();
+ }
+
+ @Override
+ public Entry getItem(int position) {
+ return feed.getEntries().get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View rowView;
+
+ if ( convertView == null ) {
+ LayoutInflater inflater = (LayoutInflater) context
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ rowView = inflater.inflate(R.layout.catalog_item, parent, false);
+ } else {
+ rowView = convertView;
+ }
+
+ Entry entry = getItem(position);
+
+ TextView title = (TextView) rowView.findViewById(R.id.itemTitle);
+ TextView desc = (TextView) rowView.findViewById(R.id.itemDescription );
+
+ title.setText(entry.getTitle());
+
+ if ( entry.getContent() != null ) {
+ desc.setText( spanner.fromHtml( entry.getContent().getText() ));
+ } else {
+ desc.setText("");
+ }
+
+ return rowView;
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.