Search in sources :

Example 1 with WatchlistDatabaseHelper

use of com.amazon.android.contentbrowser.database.helpers.WatchlistDatabaseHelper in project zype-firebuilder by zype.

the class ContentBrowser method watchlistButtonClicked.

/**
 * The action for when the watchlist button is clicked.
 *
 * @param contentId     The content id.
 * @param addContent    True if the content should be added to the watchlist, false if it
 *                      shouldn't.
 * @param actionAdapter The action adapter.
 */
private void watchlistButtonClicked(String contentId, boolean addContent, SparseArrayObjectAdapter actionAdapter) {
    WatchlistDatabaseHelper databaseHelper = WatchlistDatabaseHelper.getInstance();
    if (databaseHelper != null) {
        if (addContent) {
            databaseHelper.addRecord(mAppContext, contentId);
        } else {
            databaseHelper.deleteRecord(mAppContext, contentId);
        }
    } else {
        Log.e(TAG, "Unable to perform watchlist button action because database is null");
    }
    toggleWatchlistButton(addContent, actionAdapter);
}
Also used : WatchlistDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.WatchlistDatabaseHelper)

Example 2 with WatchlistDatabaseHelper

use of com.amazon.android.contentbrowser.database.helpers.WatchlistDatabaseHelper in project zype-firebuilder by zype.

the class ContentBrowser method isContentInWatchlist.

/**
 * Tests whether or not the given content id is in the watchlist.
 *
 * @param id The content id.
 * @return True if the watchlist contains the content; false otherwise.
 */
private boolean isContentInWatchlist(String id) {
    WatchlistDatabaseHelper databaseHelper = WatchlistDatabaseHelper.getInstance();
    if (databaseHelper != null) {
        return databaseHelper.recordExists(mAppContext, id);
    }
    Log.e(TAG, "Unable to load content because database is null");
    return false;
}
Also used : WatchlistDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.WatchlistDatabaseHelper)

Example 3 with WatchlistDatabaseHelper

use of com.amazon.android.contentbrowser.database.helpers.WatchlistDatabaseHelper in project zype-firebuilder by zype.

the class ContentBrowser method getWatchlistContent.

/**
 * Get a list of content that belong in the watchlist.
 *
 * @return List of content.
 */
public List<Content> getWatchlistContent() {
    List<Content> contentList = new ArrayList<>();
    WatchlistDatabaseHelper databaseHelper = WatchlistDatabaseHelper.getInstance();
    if (databaseHelper != null) {
        List<String> contendIds = databaseHelper.getWatchlistContentIds(mAppContext);
        for (String contentId : contendIds) {
            Content content = mContentLoader.getRootContentContainer().findContentById(contentId);
            if (content != null) {
                contentList.add(content);
            } else // The content is no longer valid so remove from database.
            {
                Log.d(TAG, "Content no longer valid");
                databaseHelper.deleteRecord(mAppContext, contentId);
            }
        }
    }
    return contentList;
}
Also used : Content(com.amazon.android.model.content.Content) ArrayList(java.util.ArrayList) WatchlistDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.WatchlistDatabaseHelper)

Aggregations

WatchlistDatabaseHelper (com.amazon.android.contentbrowser.database.helpers.WatchlistDatabaseHelper)3 Content (com.amazon.android.model.content.Content)1 ArrayList (java.util.ArrayList)1