public class PkRSS
extends java.lang.Object
Use #with(android.content.Context)
for the global singleton instance or construct your
own instance with PkRSS.Builder
.
Modifier and Type | Class and Description |
---|---|
static class |
PkRSS.Builder
Fluent API for creating
PkRSS instances. |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
KEY_ARTICLE |
static java.lang.String |
KEY_ARTICLE_ID |
static java.lang.String |
KEY_ARTICLE_URL |
static java.lang.String |
KEY_CATEGORY |
static java.lang.String |
KEY_CATEGORY_NAME |
static java.lang.String |
KEY_FAVORITES |
static java.lang.String |
KEY_FEED_URL |
static java.lang.String |
KEY_READ_ARRAY |
static java.lang.String |
KEY_SEARCH |
protected static java.lang.String |
TAG |
Modifier and Type | Method and Description |
---|---|
boolean |
clearCache()
Clears
Downloader cache. |
boolean |
clearData()
Clears all PkRSS data including Downloader cache, all articles in Favorite
Database, and all articles marked as read.
|
boolean |
containsFavorite(int id)
Searches the FavoriteDatabase for the specified ID.
|
void |
deleteAllFavorites()
Clears the favorites database.
|
boolean |
equals(java.lang.Object o) |
java.util.Map<java.lang.String,java.util.List<Article>> |
get()
Returns a
HashMap containing all loaded
Article objects. |
Article |
get(int id)
Returns an
Article object associated with the specified id. |
java.util.List<Article> |
get(java.lang.String url)
Looks up the specified URL String from the saved HashMap.
|
java.util.List<Article> |
get(java.lang.String url,
java.lang.String search)
Similar to
get(String) but also looks for the search term. |
java.util.List<Article> |
getFavorites()
Retrieves an ArrayList of articles from the Favorite Database.
|
protected static PkRSS |
getInstance()
Returns the global singleton instance.
|
protected java.util.Map<java.lang.String,java.lang.Integer> |
getPageTracker() |
int |
hashCode() |
boolean |
isLoggingEnabled()
true if debug logging is enabled. |
boolean |
isRead(int id) |
protected void |
load(Request request)
Handles the specified
Request . |
RequestCreator |
load(java.lang.String url)
Starts a request with the specified URL.
|
protected void |
log(java.lang.String message) |
protected void |
log(java.lang.String message,
int type) |
protected void |
log(java.lang.String tag,
java.lang.String message) |
protected void |
log(java.lang.String tag,
java.lang.String message,
int type) |
void |
markAllRead(boolean read)
Marks/Unmarks all loaded articles as read.
|
void |
markRead(int id,
boolean read)
Marks an article id as read.
|
boolean |
saveFavorite(Article article)
Saves an
Article object to the favorites database. |
boolean |
saveFavorite(Article article,
boolean favorite)
Saves/Deletes an
Article object to the favorites database. |
boolean |
saveFavorite(int id)
Saves an
Article object to the favorites database. |
boolean |
saveFavorite(int id,
boolean favorite)
Saves/Deletes an
Article object to the favorites database. |
void |
setLoggingEnabled(boolean enabled)
Toggle whether debug logging is enabled.
|
static PkRSS |
with(Context context)
The global default
PkRSS instance. |
public static final java.lang.String KEY_ARTICLE
public static final java.lang.String KEY_ARTICLE_ID
public static final java.lang.String KEY_ARTICLE_URL
public static final java.lang.String KEY_FEED_URL
public static final java.lang.String KEY_CATEGORY_NAME
public static final java.lang.String KEY_CATEGORY
public static final java.lang.String KEY_SEARCH
public static final java.lang.String KEY_READ_ARRAY
public static final java.lang.String KEY_FAVORITES
protected static final java.lang.String TAG
public static PkRSS with(Context context)
PkRSS
instance.
This instance is automatically initialized with defaults that are suitable to most implementations.
If these settings do not meet the requirements of your application, you can construct your own
instance with full control over the configuration by using PkRSS.Builder
.
You may also use PkRSS.Builder.buildSingleton()
to build the singleton or
PkRSS.Builder.replaceSingleton()
to replace the existing singleton if it differs.
protected static PkRSS getInstance()
public void setLoggingEnabled(boolean enabled)
public boolean isLoggingEnabled()
true
if debug logging is enabled.public RequestCreator load(java.lang.String url)
URLs may be anything you wish as long as the Parser
and/or
Downloader
supports it. See PkRSS.Builder
for using
your own custom Downloaders/Parsers.
url
- URL to load feed from.protected void load(Request request) throws java.io.IOException
Request
. May throw an IOException
for
mishandled URLs or timeouts.request
- Request to execute.java.io.IOException
public java.util.Map<java.lang.String,java.util.List<Article>> get()
HashMap
containing all loaded
Article objects. The map key being the safe url.public java.util.List<Article> get(java.lang.String url)
url
- Safe URL to look up loaded articles from. May also be KEY_FAVORITES
.List
containing all loaded articles associated with that
URL. May be null if no such URL has yet been loaded.public java.util.List<Article> get(java.lang.String url, java.lang.String search)
get(String)
but also looks for the search term.url
- Safe URL to look up loaded articles from.search
- Search term.List
containing all loaded articles associated with that
URL and query. May be null if no such URL has yet been loaded.public Article get(int id)
Article
object associated with the specified id.id
- ID belonging to such article.public java.util.List<Article> getFavorites()
public void markAllRead(boolean read)
read
- public void markRead(int id, boolean read)
id
- Article id to store its read state.read
- Whether or not to mark this id as read.public boolean isRead(int id)
id
- Article ID to check for its read state.true
if such id was previously marked as read,
false
if it has not yet been marked as read.public boolean saveFavorite(int id)
Article
object to the favorites database.
If possible, use the Article object itself instead to increase performance!
id
- ID of the article to save.true
if successful, false
if otherwise.public boolean saveFavorite(int id, boolean favorite)
Article
object to the favorites database.
If possible, use the Article object itself instead to increase performance!
id
- ID of the article to save.favorite
- Whether to save or delete. true
to save; false
to delete.true
if successful, false
if otherwise.public boolean saveFavorite(Article article)
Article
object to the favorites database.article
- Article object to save.true
if successful, false
if otherwise.public boolean saveFavorite(Article article, boolean favorite)
Article
object to the favorites database.article
- Article object to save.favorite
- Whether to save or delete. true
to save; false
to delete.true
if successful, false
if otherwise.public void deleteAllFavorites()
public boolean containsFavorite(int id)
id
- Article ID which to search for.true
if database contains it or false
if otherwise
or database not yet started.public boolean clearCache()
Downloader
cache.true
if successfully cleared or false
if otherwise.public boolean clearData()
true
if successfully cleared or false
if otherwise.protected java.util.Map<java.lang.String,java.lang.Integer> getPageTracker()
Map
used for storing page states.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
protected final void log(java.lang.String message)
protected final void log(java.lang.String tag, java.lang.String message)
protected final void log(java.lang.String message, int type)
protected final void log(java.lang.String tag, java.lang.String message, int type)