Example #1
0
    @Override
    protected List<Submission> doInBackground(MultiReddit... subredditPaginators) {

      if (!NetworkUtil.isConnected(context)) {
        offline = true;
        return null;
      } else {
        offline = false;
      }

      stillShow = true;

      if (reset || paginator == null) {
        offline = false;
        paginator = new MultiRedditPaginator(Authentication.reddit, subredditPaginators[0]);
        paginator.setSorting(
            Reddit.getSorting("multi" + subredditPaginators[0].getDisplayName().toLowerCase()));
        paginator.setTimePeriod(
            Reddit.getTime("multi" + subredditPaginators[0].getDisplayName().toLowerCase()));

        LogUtil.v("Sorting is " + paginator.getSorting().name());
        paginator.setLimit(50);
      }

      List<Submission> things = new ArrayList<>();

      try {
        if (paginator != null && paginator.hasNext()) {
          things.addAll(paginator.next());
        } else {
          nomore = true;
        }

      } catch (Exception e) {
        e.printStackTrace();
        if (e.getMessage().contains("Forbidden")) {
          Reddit.authentication.updateToken(context);
        }
      }

      return things;
    }
Example #2
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   LogUtil.v("Destroying");
   ((SubsamplingScaleImageView) rootView.findViewById(R.id.submission_image)).recycle();
 }
Example #3
0
  public void doLoadImgur(String url) {

    final String finalUrl = url;
    final String finalUrl1 = url;
    if (url.endsWith("/")) {
      url = url.substring(0, url.length() - 1);
    }
    String hash = url.substring(url.lastIndexOf("/"), url.length());

    if (NetworkUtil.isConnected(getActivity())) {

      if (hash.startsWith("/")) hash = hash.substring(1, hash.length());
      LogUtil.v("Loading" + "https://imgur-apiv3.p.mashape.com/3/image/" + hash + ".json");
      Ion.with(this)
          .load("https://imgur-apiv3.p.mashape.com/3/image/" + hash + ".json")
          .addHeader("X-Mashape-Key", SecretConstants.getImgurApiKey(getActivity()))
          .addHeader("Authorization", "Client-ID " + "bef87913eb202e9")
          .asJsonObject()
          .setCallback(
              new FutureCallback<JsonObject>() {
                @Override
                public void onCompleted(Exception e, JsonObject obj) {

                  if (obj != null && !obj.isJsonNull() && obj.has("error")) {
                    LogUtil.v("Error loading content");
                    (getActivity()).finish();
                  } else {
                    try {
                      if (obj != null && !obj.isJsonNull() && obj.has("image")) {
                        String type =
                            obj.get("image")
                                .getAsJsonObject()
                                .get("image")
                                .getAsJsonObject()
                                .get("type")
                                .getAsString();
                        String urls =
                            obj.get("image")
                                .getAsJsonObject()
                                .get("links")
                                .getAsJsonObject()
                                .get("original")
                                .getAsString();

                        if (type.contains("gif")) {
                          doLoadGif(urls);
                        } else if (!imageShown) { // only load if there is no image
                          doLoadImage(urls);
                        }
                      } else if (obj.has("data")) {
                        String type = obj.get("data").getAsJsonObject().get("type").getAsString();
                        String urls = obj.get("data").getAsJsonObject().get("link").getAsString();
                        String mp4 = "";
                        if (obj.get("data").getAsJsonObject().has("mp4")) {
                          mp4 = obj.get("data").getAsJsonObject().get("mp4").getAsString();
                        }

                        if (type.contains("gif")) {
                          doLoadGif(((mp4 == null || mp4.isEmpty()) ? urls : mp4));
                        } else if (!imageShown) { // only load if there is no image
                          doLoadImage(urls);
                        }
                      } else {
                        if (!imageShown) doLoadImage(finalUrl1);
                      }
                    } catch (Exception e2) {
                      e2.printStackTrace();
                      Intent i = new Intent(getActivity(), Website.class);
                      i.putExtra(Website.EXTRA_URL, finalUrl);
                      getActivity().startActivity(i);
                    }
                  }
                }
              });
    }
  }