Search in sources :

Example 1 with AnnouncementsRequest

use of com.ferg.awfulapp.task.AnnouncementsRequest in project Awful.apk by Awful.

the class AnnouncementsFragment method showAnnouncements.

/**
 * Fire off the network request to get and show the current announcements.
 * Not caching these in the DB! Maybe later! Probably not!!
 */
private void showAnnouncements() {
    Context context = getContext().getApplicationContext();
    statusFrog.setStatusText(R.string.announcements_status_fetching).showSpinner(true);
    queueRequest(new AnnouncementsRequest(context).build(this, new AwfulRequest.AwfulResultCallback<List<AwfulPost>>() {

        @Override
        public void success(List<AwfulPost> result) {
            AnnouncementsManager.getInstance().markAllRead();
            // update the status frog if there are no announcements, otherwise hide it and display them
            if (result.size() < 1) {
                statusFrog.setStatusText(R.string.announcements_status_none).showSpinner(false);
            } else {
                webView.setVisibility(View.VISIBLE);
                // these page params don't mean anything in the context of the announcement page
                // we just want it to a) display ok, and b) not let the user click anything bad
                bodyHtml = ThreadDisplay.getHtml(result, AwfulPreferences.getInstance(), 1, 1);
                if (webView != null) {
                    webView.refreshPageContents(true);
                }
                statusFrog.setVisibility(View.INVISIBLE);
            }
        }

        @Override
        public void failure(VolleyError error) {
            statusFrog.setStatusText(R.string.announcements_status_failed).showSpinner(false);
            Timber.w("Announcement get failed!\n" + error.getMessage());
        }
    }));
}
Also used : Context(android.content.Context) VolleyError(com.android.volley.VolleyError) AwfulPost(com.ferg.awfulapp.thread.AwfulPost) AnnouncementsRequest(com.ferg.awfulapp.task.AnnouncementsRequest) List(java.util.List)

Aggregations

Context (android.content.Context)1 VolleyError (com.android.volley.VolleyError)1 AnnouncementsRequest (com.ferg.awfulapp.task.AnnouncementsRequest)1 AwfulPost (com.ferg.awfulapp.thread.AwfulPost)1 List (java.util.List)1