Search in sources :

Example 6 with NetworkException

use of net.dean.jraw.http.NetworkException in project Slide by ccrama.

the class UserSubscriptions method syncMultiReddits.

public static void syncMultiReddits(Context c) {
    try {
        multireddits = new ArrayList<>(new MultiRedditManager(Authentication.reddit).mine());
        for (MultiReddit multiReddit : multireddits) {
            if (MainActivity.multiNameToSubsMap.containsKey(ReorderSubreddits.MULTI_REDDIT + multiReddit.getDisplayName())) {
                StringBuilder concatenatedSubs = new StringBuilder();
                for (MultiSubreddit subreddit : multiReddit.getSubreddits()) {
                    concatenatedSubs.append(subreddit.getDisplayName());
                    concatenatedSubs.append("+");
                }
                MainActivity.multiNameToSubsMap.put(ReorderSubreddits.MULTI_REDDIT + multiReddit.getDisplayName(), concatenatedSubs.toString());
                UserSubscriptions.setSubNameToProperties(ReorderSubreddits.MULTI_REDDIT + multiReddit.getDisplayName(), concatenatedSubs.toString());
            }
        }
    } catch (ApiException e) {
        e.printStackTrace();
    } catch (NetworkException e) {
        e.printStackTrace();
    }
}
Also used : MultiRedditManager(net.dean.jraw.managers.MultiRedditManager) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) MultiReddit(net.dean.jraw.models.MultiReddit) NetworkException(net.dean.jraw.http.NetworkException) ApiException(net.dean.jraw.ApiException)

Example 7 with NetworkException

use of net.dean.jraw.http.NetworkException in project Slide by ccrama.

the class CommentCacheAsync method getSubmission.

public JsonNode getSubmission(SubmissionRequest request) throws NetworkException {
    Map<String, String> args = new HashMap<>();
    if (request.getDepth() != null)
        args.put("depth", Integer.toString(request.getDepth()));
    if (request.getContext() != null) {
        args.put("context", Integer.toString(request.getContext()));
    }
    if (request.getLimit() != null)
        args.put("limit", Integer.toString(request.getLimit()));
    if (request.getFocus() != null && !JrawUtils.isFullname(request.getFocus())) {
        args.put("comment", request.getFocus());
    }
    CommentSort sort = request.getSort();
    if (sort == null) // Reddit sorts by confidence by default
    {
        sort = CommentSort.CONFIDENCE;
    }
    args.put("sort", sort.name().toLowerCase(Locale.ENGLISH));
    try {
        RestResponse response = Authentication.reddit.execute(Authentication.reddit.request().path(String.format("/comments/%s", request.getId())).query(args).build());
        return response.getJson();
    } catch (Exception e) {
        return null;
    }
}
Also used : HashMap(java.util.HashMap) RestResponse(net.dean.jraw.http.RestResponse) CommentSort(net.dean.jraw.models.CommentSort) NetworkException(net.dean.jraw.http.NetworkException)

Aggregations

NetworkException (net.dean.jraw.http.NetworkException)7 DialogInterface (android.content.DialogInterface)3 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)3 HashMap (java.util.HashMap)3 ApiException (net.dean.jraw.ApiException)3 MultiRedditManager (net.dean.jraw.managers.MultiRedditManager)3 MultiReddit (net.dean.jraw.models.MultiReddit)3 MultiSubreddit (net.dean.jraw.models.MultiSubreddit)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Intent (android.content.Intent)2 AsyncTask (android.os.AsyncTask)2 Snackbar (android.support.design.widget.Snackbar)2 AppCompatCheckBox (android.support.v7.widget.AppCompatCheckBox)2 View (android.view.View)2 CompoundButton (android.widget.CompoundButton)2 HorizontalScrollView (android.widget.HorizontalScrollView)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 ArrayList (java.util.ArrayList)2