Example #1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView =
        (ViewGroup) inflater.inflate(R.layout.submission_albumcard, container, false);

    TextView title = (TextView) rootView.findViewById(R.id.title);
    TextView desc = (TextView) rootView.findViewById(R.id.desc);

    title.setText(s.getTitle());
    desc.setText(
        s.getAuthor() + " " + TimeUtils.getTimeAgo(s.getCreated().getTime(), getContext()));
    ContentType.ImageType type = ContentType.getImageType(s);

    String url = "";

    if (s.getUrl().contains("gallery")) {
      gallery = true;
    }

    list = rootView.findViewById(R.id.images);

    list.setVisibility(View.VISIBLE);
    String rawDat = cutEnds(s.getUrl());
    String rawdat2 = rawDat;
    if (rawdat2.substring(rawDat.lastIndexOf("/"), rawdat2.length()).length() < 4) {
      rawDat = rawDat.replace(rawDat.substring(rawDat.lastIndexOf("/"), rawdat2.length()), "");
    }
    if (!rawDat.isEmpty()) {

      new AsyncImageLoaderAlbum().execute(getHash(rawDat));
    }

    rootView
        .findViewById(R.id.base)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (Reddit.tabletUI
                    && getActivity().getResources().getConfiguration().orientation
                        == Configuration.ORIENTATION_LANDSCAPE) {
                  Intent i2 = new Intent(getActivity(), CommentsScreenPopup.class);
                  i2.putExtra("page", i);
                  (getActivity()).startActivity(i2);

                } else {
                  Intent i2 = new Intent(getActivity(), CommentsScreen.class);
                  i2.putExtra("page", i);
                  (getActivity()).startActivity(i2);
                }
              }
            });
    return rootView;
  }
Example #2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = (ViewGroup) inflater.inflate(R.layout.submission_imagecard, container, false);
    image = (SubsamplingScaleImageView) rootView.findViewById(R.id.image);

    PopulateShadowboxInfo.doActionbar(s, rootView, getActivity());

    (rootView.findViewById(R.id.thumbimage2)).setVisibility(View.GONE);

    type = ContentType.getImageType(s);

    if (type.toString().toLowerCase().contains("image")
        && type != ContentType.ImageType.IMAGE_LINK) {
      addClickFunctions(image, rootView, type, getActivity(), s);
      loadImage(s.getUrl());
    } else if (s.getDataNode().has("preview")
        && s.getDataNode().get("preview").get("images").get(0).get("source").has("height")
        && s.getDataNode().get("preview").get("images").get(0).get("source").get("height").asInt()
            > 200) {
      loadImage(
          s.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText());
    } else {
      image.recycle();
      (rootView.findViewById(R.id.thumbimage2)).setVisibility(View.VISIBLE);
      ((ImageView) rootView.findViewById(R.id.thumbimage2)).setImageResource(R.drawable.web);
      addClickFunctions(
          (rootView.findViewById(R.id.thumbimage2)), rootView, type, getActivity(), s);

      (rootView.findViewById(R.id.progress)).setVisibility(View.GONE);
    }

    rootView
        .findViewById(R.id.base)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {

                Intent i2 = new Intent(getActivity(), CommentsScreen.class);
                i2.putExtra(CommentsScreen.EXTRA_PAGE, i);
                i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, sub);
                (getActivity()).startActivity(i2);
              }
            });
    return rootView;
  }
Example #3
0
 @EndpointImplementation(Endpoints.APPROVE)
 public void approve(Submission s) throws NetworkException, ApiException {
   genericPost(
       reddit
           .request()
           .endpoint(Endpoints.APPROVE)
           .post(JrawUtils.mapOf("api_type", "json", "id", s.getFullName()))
           .build());
 }
Example #4
0
 /**
  * Set or unset a self post as a sticky. You must be a moderator of the subreddit the submission
  * was posted in for this request to complete successfully.
  *
  * @param s The submission to set as a sticky. Must be a self post
  * @param sticky Whether or not to set the submission as a stickied post
  * @throws NetworkException If the request was not successful
  * @throws ApiException If the Reddit API returned an error
  */
 @EndpointImplementation(Endpoints.SET_SUBREDDIT_STICKY)
 public void setSticky(Submission s, boolean sticky) throws NetworkException, ApiException {
   genericPost(
       reddit
           .request()
           .endpoint(Endpoints.SET_SUBREDDIT_STICKY)
           .post(JrawUtils.mapOf("api_type", "json", "id", s.getFullName(), "state", sticky))
           .build());
 }
Example #5
0
 @EndpointImplementation(Endpoints.REMOVE)
 public void remove(Submission s, boolean spam) throws NetworkException, ApiException {
   genericPost(
       reddit
           .request()
           .endpoint(Endpoints.REMOVE)
           .post(JrawUtils.mapOf("api_type", "json", "id", s.getFullName(), "spam", spam))
           .build());
 }
Example #6
0
 /**
  * Sets whether or not this submission should be marked as not safe for work
  *
  * @param s The submission to modify
  * @param nsfw Whether or not this submission is not safe for work
  * @throws net.dean.jraw.http.NetworkException If the request was not successful
  * @throws net.dean.jraw.ApiException If the API returned an error
  */
 @EndpointImplementation({Endpoints.MARKNSFW, Endpoints.UNMARKNSFW})
 public void setNsfw(Submission s, boolean nsfw) throws NetworkException, ApiException {
   // "/api/marknsfw" if nsfw == true, "/api/unmarknsfw" if nsfw == false
   genericPost(
       reddit
           .request()
           .endpoint(nsfw ? Endpoints.MARKNSFW : Endpoints.UNMARKNSFW)
           .post(JrawUtils.mapOf("id", s.getFullName()))
           .build());
 }
Example #7
0
  public static boolean doesMatch(Submission s) {
    String title = s.getTitle();
    String body = s.getSelftext();
    String domain = s.getUrl();
    String subreddit = s.getSubredditName();

    boolean titlec;
    boolean bodyc;
    boolean domainc;
    boolean subredditc;

    if (titles == null) {
      titles = SettingValues.titleFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }
    if (texts == null) {
      texts = SettingValues.textFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }
    if (domains == null) {
      domains = SettingValues.domainFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }
    if (subreddits == null) {
      subreddits = SettingValues.subredditFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }

    titlec = !SettingValues.titleFilters.isEmpty() && contains(title.toLowerCase(), titles, false);

    bodyc = !SettingValues.textFilters.isEmpty() && contains(body.toLowerCase(), texts, false);

    domainc =
        !SettingValues.domainFilters.isEmpty() && contains(domain.toLowerCase(), domains, false);

    subredditc =
        subreddit != null
            && !subreddit.isEmpty()
            && !SettingValues.subredditFilters.isEmpty()
            && contains(subreddit.toLowerCase(), subreddits, true);

    return (titlec || bodyc || domainc || subredditc);
  }
Example #8
0
  /**
   * Sets either a user's flair or a submission's flair. If the submission and username are both
   * non-null, then the submission will be used in the request. If they are both null and there is
   * no authenticated user, then an IllegalArgumentException will be thrown.
   *
   * @param subreddit The subreddit where the flair will take effect
   * @param template The template to use
   * @param text Optional text that will be used if the FlairTemplate's text is editable. If this is
   *     null and the template is editable, the template's default text will be used.
   * @param submission The submission to set the flair for
   * @param username The name of the user to set the flair for. If this is null the authenticated
   *     user's name will be used.
   * @throws IllegalArgumentException If both the submission and the username are null
   * @throws NetworkException If the request was not successful
   */
  @EndpointImplementation(Endpoints.SELECTFLAIR)
  private void setFlair(
      String subreddit, FlairTemplate template, String text, Submission submission, String username)
      throws IllegalArgumentException, NetworkException, ApiException {
    if (subreddit == null) {
      throw new IllegalArgumentException("subreddit cannot be null");
    }
    Map<String, String> args =
        JrawUtils.mapOf("api_type", "json", "flair_template_id", template.getId());

    if (submission != null) {
      args.put("link", submission.getFullName());
    } else {
      if (username == null) {
        if (reddit.getAuthenticationMethod() == AuthenticationMethod.NOT_YET) {
          throw new IllegalArgumentException(
              "Not logged in and both submission and username were null");
        }
        if (!reddit.hasActiveUserContext())
          throw new IllegalStateException(
              "Cannot set the flair for self because there is no active user context");
        username = reddit.getAuthenticatedUser();
      }
      args.put("name", username);
    }

    if (template.isTextEditable()) {
      if (text == null) {
        // Set default text flair if none is provided
        text = template.getText();
      }
      args.put("text", text);
    }

    RestResponse response =
        reddit.execute(
            reddit
                .request()
                .post(args)
                .path("/r/" + subreddit + Endpoints.SELECTFLAIR.getEndpoint().getUri())
                .build());
    if (response.hasErrors()) {
      throw response.getError();
    }
  }
Example #9
0
  public static boolean doesMatch(Submission s, String baseSubreddit, boolean ignore18) {
    String title = s.getTitle();
    String body = s.getSelftext();
    String domain = s.getUrl();
    String subreddit = s.getSubredditName();
    String flair = s.getSubmissionFlair().getText() != null ? s.getSubmissionFlair().getText() : "";

    boolean titlec;
    boolean bodyc;
    boolean domainc;
    boolean subredditc;
    boolean userc;

    if (titles == null) {
      titles = SettingValues.titleFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }
    if (texts == null) {
      texts = SettingValues.textFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }
    if (domains == null) {
      domains = SettingValues.domainFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }
    if (subreddits == null) {
      subreddits = SettingValues.subredditFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }
    if (flairs == null) {
      flairs = SettingValues.flairFilters.replaceAll("^[,]+", "").split("[,]+");
    }
    if (users == null) {
      users = SettingValues.userFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }

    titlec = !SettingValues.titleFilters.isEmpty() && contains(title.toLowerCase(), titles, false);

    bodyc = !SettingValues.textFilters.isEmpty() && contains(body.toLowerCase(), texts, false);

    userc =
        !SettingValues.userFilters.isEmpty() && contains(s.getAuthor().toLowerCase(), users, false);

    try {
      domainc = !SettingValues.domainFilters.isEmpty() && isDomain(domain.toLowerCase(), domains);
    } catch (MalformedURLException e) {
      domainc = false;
    }

    subredditc =
        !subreddit.equalsIgnoreCase(baseSubreddit)
            && !SettingValues.subredditFilters.isEmpty()
            && contains(subreddit.toLowerCase(), subreddits, true);

    boolean contentMatch = false;

    if (baseSubreddit == null || baseSubreddit.isEmpty()) {
      baseSubreddit = "frontpage";
    }

    baseSubreddit = baseSubreddit.toLowerCase();
    boolean gifs = isGif(baseSubreddit);
    boolean images = isImage(baseSubreddit);
    boolean nsfw = isNsfw(baseSubreddit);
    boolean albums = isAlbums(baseSubreddit);
    boolean urls = isUrls(baseSubreddit);
    boolean selftext = isSelftext(baseSubreddit);
    boolean videos = isVideo(baseSubreddit);

    if (s.isNsfw()) {
      if (nsfw) {
        contentMatch = true;
      }
      if (!Reddit.over18 && !ignore18) {
        contentMatch = true;
      }
    }
    switch (ContentType.getContentType(s)) {
      case REDDIT:
      case EMBEDDED:
      case LINK:
        if (urls) {
          contentMatch = true;
        }
        break;
      case SELF:
      case NONE:
        if (selftext) {
          contentMatch = true;
        }
        break;
      case ALBUM:
        if (albums) {
          contentMatch = true;
        }
        break;
      case IMAGE:
      case DEVIANTART:
      case IMGUR:
      case XKCD:
        if (images) {
          contentMatch = true;
        }
        break;
      case GIF:
        if (gifs) {
          contentMatch = true;
        }
        break;
      case VID_ME:
      case STREAMABLE:
      case VIDEO:
        if (videos) {
          contentMatch = true;
        }
        break;
    }

    if (!flair.isEmpty())
      for (String flairText : flairs) {
        if (flairText.toLowerCase().startsWith(baseSubreddit)) {
          String[] split = flairText.split(":");
          if (split[0].equalsIgnoreCase(baseSubreddit)) {
            if (flair.equalsIgnoreCase(split[1].trim())) {
              contentMatch = true;
              break;
            }
          }
        }
      }

    return (titlec
        || bodyc
        || userc
        || domainc
        || subredditc
        || contentMatch
        || Hidden.id.contains(s.getFullName()));
  }
Example #10
0
  private void loadImages(List<Submission> submissions) {
    for (Submission s : submissions) {
      ContentType.Type type = ContentType.getContentType(s);

      String url = "";

      ImageLoadingListener l = new SimpleImageLoadingListener();

      if (type == ContentType.Type.IMAGE) {
        url = s.getUrl();
        if (SettingValues.bigPicEnabled) {
          ((Reddit) mSwipeRefreshLayout.getContext().getApplicationContext())
              .getImageLoader()
              .loadImage(url, l);
        } else {
          if (s.getThumbnailType() != Submission.ThumbnailType.NONE) {
            ((Reddit) mSwipeRefreshLayout.getContext().getApplicationContext())
                .getImageLoader()
                .loadImage(s.getThumbnail(), l);
          }
        }
      } else if (s.getDataNode().has("preview")
          && s.getDataNode().get("preview").get("images").get(0).get("source").has("height")) {
        url = s.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
        if (SettingValues.bigPicEnabled) {
          ((Reddit) mSwipeRefreshLayout.getContext().getApplicationContext())
              .getImageLoader()
              .loadImage(url, l);
        } else if (s.getThumbnailType() != Submission.ThumbnailType.NONE) {
          ((Reddit) mSwipeRefreshLayout.getContext().getApplicationContext())
              .getImageLoader()
              .loadImage(s.getThumbnail(), l);
        }
      } else if (s.getThumbnail() != null
          && (s.getThumbnailType() == Submission.ThumbnailType.URL
              || s.getThumbnailType() == Submission.ThumbnailType.NSFW)) {
        if ((s.getThumbnailType() == Submission.ThumbnailType.NSFW)
            || s.getThumbnailType() == Submission.ThumbnailType.URL) {
          if (SettingValues.bigPicEnabled) {
            ((Reddit) mSwipeRefreshLayout.getContext().getApplicationContext())
                .getImageLoader()
                .loadImage(url, l);
          } else if (s.getThumbnailType() != Submission.ThumbnailType.NONE) {
            ((Reddit) mSwipeRefreshLayout.getContext().getApplicationContext())
                .getImageLoader()
                .loadImage(s.getThumbnail(), l);
          }
        }
      }
    }
  }
Example #11
0
  public void loadPhotos(List<Submission> submissions) {
    for (Submission submission : submissions) {
      boolean forceThumb = false;
      String url;
      ContentType.Type type = ContentType.getContentType(submission);
      if (submission.getThumbnails() != null) {

        int height = submission.getThumbnails().getSource().getHeight();
        int width = submission.getThumbnails().getSource().getWidth();

        if (type != ContentType.Type.IMAGE
            && type != ContentType.Type.SELF
            && (submission.getThumbnailType() != Submission.ThumbnailType.URL)) {

        } else if (type == ContentType.Type.IMAGE) {
          if (((!NetworkUtil.isConnectedWifi(c) && SettingValues.lowResMobile)
                  || SettingValues.lowResAlways)
              && submission.getThumbnails() != null
              && submission.getThumbnails().getVariations() != null) {

            int length = submission.getThumbnails().getVariations().length;
            url =
                Html.fromHtml(submission.getThumbnails().getVariations()[length / 2].getUrl())
                    .toString(); // unescape url characters

          } else {
            if (submission.getDataNode().has("preview")
                && submission
                    .getDataNode()
                    .get("preview")
                    .get("images")
                    .get(0)
                    .get("source")
                    .has(
                        "height")) { // Load the preview image which has probably already been
                                     // cached in memory instead of the direct link
              url =
                  submission
                      .getDataNode()
                      .get("preview")
                      .get("images")
                      .get(0)
                      .get("source")
                      .get("url")
                      .asText();
            } else {
              url = submission.getUrl();
            }
          }

          ((Reddit) c.getApplicationContext())
              .getImageLoader()
              .loadImage(
                  url,
                  new ImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {}

                    @Override
                    public void onLoadingFailed(
                        String imageUri, View view, FailReason failReason) {}

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {}

                    @Override
                    public void onLoadingCancelled(String imageUri, View view) {}
                  });

        } else if (submission.getThumbnails() != null) {

          if (((!NetworkUtil.isConnectedWifi(c) && SettingValues.lowResMobile)
                  || SettingValues.lowResAlways)
              && submission.getThumbnails().getVariations().length != 0) {

            int length = submission.getThumbnails().getVariations().length;
            url =
                Html.fromHtml(submission.getThumbnails().getVariations()[length / 2].getUrl())
                    .toString(); // unescape url characters

          } else {
            url =
                Html.fromHtml(submission.getThumbnails().getSource().getUrl())
                    .toString(); // unescape url characters
          }

          ((Reddit) c.getApplicationContext())
              .getImageLoader()
              .loadImage(
                  url,
                  new ImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {}

                    @Override
                    public void onLoadingFailed(
                        String imageUri, View view, FailReason failReason) {}

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {}

                    @Override
                    public void onLoadingCancelled(String imageUri, View view) {}
                  });

        } else if (submission.getThumbnail() != null
            && (submission.getThumbnailType() == Submission.ThumbnailType.URL
                || submission.getThumbnailType() == Submission.ThumbnailType.NSFW)) {

          ((Reddit) c.getApplicationContext())
              .getImageLoader()
              .loadImage(
                  submission.getUrl(),
                  new ImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {}

                    @Override
                    public void onLoadingFailed(
                        String imageUri, View view, FailReason failReason) {}

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {}

                    @Override
                    public void onLoadingCancelled(String imageUri, View view) {}
                  });
        }
      }
    }
  }
Example #12
0
    @Override
    public void onPostExecute(List<Submission> submissions) {
      loading = false;
      context = null;

      if (submissions != null && !submissions.isEmpty()) {
        // new submissions found
        int start = 0;
        if (posts != null) {
          start = posts.size() + 1;
        }

        List<Submission> filteredSubmissions = new ArrayList<>();
        for (Submission s : submissions) {
          if (!PostMatch.doesMatch(s, paginator.getMultiReddit().getDisplayName(), false)) {
            filteredSubmissions.add(s);
          }
        }
        String[] ids = new String[filteredSubmissions.size()];
        int i = 0;
        for (Submission s : filteredSubmissions) {
          ids[i] = s.getId();
          i++;
        }
        if (!SettingValues.synccitName.isEmpty() && !offline) {
          new MySynccitReadTask().execute(ids);
        }
        loadPhotos(filteredSubmissions);
        if (reset || offline || posts == null) {
          posts = new ArrayList<>(new LinkedHashSet(filteredSubmissions));
          start = -1;
        } else {
          posts.addAll(filteredSubmissions);
          posts = new ArrayList<>(new LinkedHashSet(posts));
          offline = false;
        }

        final int finalStart = start;

        if (!usedOffline)
          OfflineSubreddit.getSubreddit("multi" + multiReddit.getDisplayName().toLowerCase())
              .overwriteSubmissions(posts)
              .writeToMemory();

        // update online
        displayer.updateSuccess(posts, finalStart);

      } else if (submissions != null) {
        // end of submissions
        nomore = true;
      } else if (!OfflineSubreddit.getSubreddit(
                  "multi" + multiReddit.getDisplayName().toLowerCase())
              .submissions
              .isEmpty()
          && !nomore
          && SettingValues.cache) {
        offline = true;
        final OfflineSubreddit cached =
            OfflineSubreddit.getSubreddit("multi" + multiReddit.getDisplayName().toLowerCase());

        List<Submission> finalSubs = new ArrayList<>();
        for (Submission s : cached.submissions) {
          if (!PostMatch.doesMatch(
              s, "multi" + multiReddit.getDisplayName().toLowerCase(), false)) {
            finalSubs.add(s);
          }
        }

        posts = finalSubs;

        if (cached.submissions.size() > 0) {
          stillShow = true;
        } else {
          displayer.updateOfflineError();
        }
        // update offline
        displayer.updateOffline(submissions, cached.time);
      } else if (!nomore) {
        // error
        displayer.updateError();
      }
    }
Example #13
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = (ViewGroup) inflater.inflate(R.layout.submission_mediacard, container, false);
    if (savedInstanceState != null && savedInstanceState.containsKey("position"))
      stopPosition = savedInstanceState.getInt("position");
    if (!firstUrl.isEmpty()) {
      displayImage(firstUrl);
    }

    PopulateShadowboxInfo.doActionbar(s, rootView, getActivity(), true);

    (rootView.findViewById(R.id.thumbimage2)).setVisibility(View.GONE);

    ContentType.Type type = ContentType.getContentType(s);

    if (!ContentType.fullImage(type)) {
      if (!s.getDataNode().has("preview")
          || !s.getDataNode().get("preview").get("images").get(0).get("source").has("height")) {
        (rootView.findViewById(R.id.thumbimage2)).setVisibility(View.VISIBLE);
        ((ImageView) rootView.findViewById(R.id.thumbimage2)).setImageResource(R.drawable.web);
        addClickFunctions(
            (rootView.findViewById(R.id.thumbimage2)), rootView, type, getActivity(), s);
        (rootView.findViewById(R.id.progress)).setVisibility(View.GONE);
      } else {
        addClickFunctions(
            (rootView.findViewById(R.id.submission_image)), rootView, type, getActivity(), s);
      }
    } else {
      (rootView.findViewById(R.id.thumbimage2)).setVisibility(View.GONE);
      addClickFunctions(
          (rootView.findViewById(R.id.submission_image)), rootView, type, getActivity(), s);
    }
    doLoad(contentUrl);

    rootView
        .findViewById(R.id.base)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {

                Intent i2 = new Intent(getActivity(), CommentsScreen.class);
                i2.putExtra(CommentsScreen.EXTRA_PAGE, i);
                i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, sub);
                getActivity().startActivity(i2);
              }
            });
    final View.OnClickListener openClick =
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            ((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout))
                .setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
          }
        };
    rootView.findViewById(R.id.base).setOnClickListener(openClick);
    final View title = rootView.findViewById(R.id.title);
    title
        .getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                ((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout))
                    .setPanelHeight(title.getMeasuredHeight());
                title.getViewTreeObserver().removeOnGlobalLayoutListener(this);
              }
            });
    ((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout))
        .addPanelSlideListener(
            new SlidingUpPanelLayout.PanelSlideListener() {
              @Override
              public void onPanelSlide(View panel, float slideOffset) {}

              @Override
              public void onPanelStateChanged(
                  View panel,
                  SlidingUpPanelLayout.PanelState previousState,
                  SlidingUpPanelLayout.PanelState newState) {
                if (newState == SlidingUpPanelLayout.PanelState.EXPANDED) {
                  rootView
                      .findViewById(R.id.base)
                      .setOnClickListener(
                          new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                              Intent i2 = new Intent(getActivity(), CommentsScreen.class);
                              i2.putExtra(CommentsScreen.EXTRA_PAGE, i);
                              i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, sub);
                              getActivity().startActivity(i2);
                            }
                          });
                } else {
                  rootView.findViewById(R.id.base).setOnClickListener(openClick);
                }
              }
            });
    return rootView;
  }
Example #14
0
  private static void addClickFunctions(
      final View base,
      final View clickingArea,
      ContentType.ImageType type,
      final Activity contextActivity,
      final Submission submission) {
    if (!PostMatch.openExternal(submission.getUrl())) {

      switch (type) {
        case NSFW_IMAGE:
          base.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v2) {
                  PopulateSubmissionViewHolder.openImage(contextActivity, submission);
                }
              });
          break;
        case VID_ME:
        case STREAMABLE:
          base.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  if (SettingValues.video) {
                    Intent myIntent = new Intent(contextActivity, GifView.class);

                    myIntent.putExtra(GifView.EXTRA_STREAMABLE, submission.getUrl());
                    contextActivity.startActivity(myIntent);

                  } else {
                    Reddit.defaultShare(submission.getUrl(), contextActivity);
                  }
                }
              });
        case EMBEDDED:
          base.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v2) {
                  if (SettingValues.video) {
                    Reddit.defaultShare(submission.getUrl(), contextActivity);
                    String data =
                        submission.getDataNode().get("media_embed").get("content").asText();
                    {
                      Intent i = new Intent(contextActivity, FullscreenVideo.class);
                      i.putExtra(FullscreenVideo.EXTRA_HTML, data);
                      contextActivity.startActivity(i);
                    }
                  } else {
                    Reddit.defaultShare(submission.getUrl(), contextActivity);
                  }
                }
              });
          break;
        case NSFW_GIF:
          base.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v2) {
                  PopulateSubmissionViewHolder.openGif(false, contextActivity, submission);
                }
              });
          break;
        case NSFW_GFY:
          base.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v2) {
                  PopulateSubmissionViewHolder.openGif(true, contextActivity, submission);
                }
              });
          break;
        case REDDIT:
          base.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v2) {
                  PopulateSubmissionViewHolder.openRedditContent(
                      submission.getUrl(), contextActivity);
                }
              });
          break;
        case LINK:
          base.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v2) {
                  CustomTabUtil.openUrl(
                      submission.getUrl(),
                      Palette.getColor(submission.getSubredditName()),
                      contextActivity);
                }
              });
          break;
        case IMAGE_LINK:
          base.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v2) {
                  CustomTabUtil.openUrl(
                      submission.getUrl(),
                      Palette.getColor(submission.getSubredditName()),
                      contextActivity);
                }
              });
          break;
        case NSFW_LINK:
          base.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v2) {
                  CustomTabUtil.openUrl(
                      submission.getUrl(),
                      Palette.getColor(submission.getSubredditName()),
                      contextActivity);
                }
              });
          break;
        case SELF:
          break;
        case GFY:
          base.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v2) {
                  PopulateSubmissionViewHolder.openGif(true, contextActivity, submission);
                }
              });
          break;
        case ALBUM:
          base.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v2) {

                  if (SettingValues.album) {
                    if (SettingValues.albumSwipe) {
                      Intent i = new Intent(contextActivity, AlbumPager.class);
                      i.putExtra(Album.EXTRA_URL, submission.getUrl());
                      contextActivity.startActivity(i);
                      contextActivity.overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                    } else {
                      Intent i = new Intent(contextActivity, Album.class);
                      i.putExtra(Album.EXTRA_URL, submission.getUrl());
                      contextActivity.startActivity(i);
                      contextActivity.overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                    }

                  } else {
                    Reddit.defaultShare(submission.getUrl(), contextActivity);
                  }
                }
              });
          break;
        case DEVIANTART:
        case IMAGE:
          base.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v2) {
                  PopulateSubmissionViewHolder.openImage(contextActivity, submission);
                }
              });
          break;
        case GIF:
          base.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v2) {
                  PopulateSubmissionViewHolder.openGif(false, contextActivity, submission);
                }
              });
          break;
        case NONE_GFY:
          base.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v2) {
                  PopulateSubmissionViewHolder.openGif(true, contextActivity, submission);
                }
              });
          break;
        case NONE_GIF:
          base.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v2) {
                  PopulateSubmissionViewHolder.openGif(false, contextActivity, submission);
                }
              });
          break;

        case NONE:
          base.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v2) {
                  CustomTabUtil.openUrl(
                      submission.getUrl(),
                      Palette.getColor(submission.getSubredditName()),
                      contextActivity);
                }
              });
          break;
        case NONE_IMAGE:
          base.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v2) {
                  PopulateSubmissionViewHolder.openImage(contextActivity, submission);
                }
              });
          break;
        case NONE_URL:
          base.setOnClickListener(
              new View.OnClickListener() {

                @Override
                public void onClick(View v2) {
                  CustomTabUtil.openUrl(
                      submission.getUrl(),
                      Palette.getColor(submission.getSubredditName()),
                      contextActivity);
                }
              });
          break;
        case VIDEO:
          base.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                  Reddit.defaultShare(submission.getUrl(), contextActivity);
                }
              });
      }
    } else {
      Reddit.defaultShare(submission.getUrl(), contextActivity);
    }
  }
Example #15
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.submission_albumcard, container, false);
    PopulateShadowboxInfo.doActionbar(s, rootView, getActivity());

    if (s.getUrl().contains("gallery")) {
      gallery = true;
    }

    list = rootView.findViewById(R.id.images);

    list.setVisibility(View.VISIBLE);
    final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    ((RecyclerView) list).setLayoutManager(layoutManager);

    ((RecyclerView) list)
        .setOnScrollListener(
            new RecyclerView.OnScrollListener() {

              @Override
              public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                ValueAnimator va = null;

                if (dy > 0 && !hidden) {
                  hidden = true;

                  if (va != null && va.isRunning()) va.cancel();

                  final View base = rootView.findViewById(R.id.base);
                  va = ValueAnimator.ofFloat(1.0f, 0.2f);
                  int mDuration = 250; // in millis
                  va.setDuration(mDuration);
                  va.addUpdateListener(
                      new ValueAnimator.AnimatorUpdateListener() {
                        public void onAnimationUpdate(ValueAnimator animation) {
                          Float value = (Float) animation.getAnimatedValue();
                          base.setAlpha(value);
                        }
                      });

                  va.start();

                } else if (hidden && dy <= 0) {
                  final View base = rootView.findViewById(R.id.base);

                  if (va != null && va.isRunning()) va.cancel();

                  hidden = false;
                  va = ValueAnimator.ofFloat(0.2f, 1.0f);
                  int mDuration = 250; // in millis
                  va.setDuration(mDuration);
                  va.addUpdateListener(
                      new ValueAnimator.AnimatorUpdateListener() {
                        public void onAnimationUpdate(ValueAnimator animation) {
                          Float value = (Float) animation.getAnimatedValue();
                          base.setAlpha(value);
                        }
                      });

                  va.start();
                }
              }

              @Override
              public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
              }
            });

    rootView
        .findViewById(R.id.base)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {

                Intent i2 = new Intent(getActivity(), CommentsScreen.class);
                i2.putExtra(CommentsScreen.EXTRA_PAGE, i);
                i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, s.getSubredditName());
                (getActivity()).startActivity(i2);
              }
            });

    new LoadIntoRecycler(s.getUrl(), getActivity()).execute();

    return rootView;
  }
Example #16
0
  @Override
  public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int i) {

    if (holder2 instanceof SubmissionViewHolder) {
      final SubmissionViewHolder holder = (SubmissionViewHolder) holder2;

      final Submission submission = dataSet.posts.get(i);

      CreateCardView.resetColorCard(holder.itemView);
      CreateCardView.colorCard(
          submission.getSubredditName().toLowerCase(),
          holder.itemView,
          subreddit,
          (subreddit.equals("frontpage")
              || (subreddit.equals("all"))
              || subreddit.contains(".")
              || subreddit.contains("+")));
      holder.itemView.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

              if (Authentication.didOnline || submission.getComments() != null) {
                holder2.itemView.setAlpha(0.65f);
                if (SettingValues.tabletUI
                    && holder2.itemView.getContext().getResources().getConfiguration().orientation
                        == Configuration.ORIENTATION_LANDSCAPE) {
                  Intent i2 = new Intent(holder2.itemView.getContext(), CommentsScreenPopup.class);
                  i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
                  i2.putExtra(CommentsScreenPopup.EXTRA_PAGE, holder2.getAdapterPosition());
                  (holder2.itemView.getContext()).startActivity(i2);

                } else {
                  Intent i2 = new Intent(holder2.itemView.getContext(), CommentsScreen.class);
                  i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition());
                  i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
                  (holder2.itemView.getContext()).startActivity(i2);
                }
              } else {
                Snackbar.make(
                        holder.itemView,
                        R.string.offline_comments_not_loaded,
                        Snackbar.LENGTH_SHORT)
                    .show();
              }
            }
          });
      final boolean saved = submission.isSaved();

      holder.itemView.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {

              if (context instanceof MainActivity && ((MainActivity) context).t != null) {
                Tooltip.removeAll(context);
                Reddit.appRestart.edit().putString("tutorial_4", "A").apply();
              }
              if (!dataSet.stillShow) {

                Snackbar.make(
                        holder.itemView,
                        holder2.itemView.getContext().getString(R.string.offline_msg),
                        Snackbar.LENGTH_SHORT)
                    .show();

              } else {
                LayoutInflater inflater = LayoutInflater.from(holder2.itemView.getContext());
                final View dialoglayout = inflater.inflate(R.layout.postmenu, null);
                AlertDialogWrapper.Builder builder =
                    new AlertDialogWrapper.Builder(holder2.itemView.getContext());
                final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
                title.setText(Html.fromHtml(submission.getTitle()));

                ((TextView) dialoglayout.findViewById(R.id.userpopup))
                    .setText("/u/" + submission.getAuthor());
                ((TextView) dialoglayout.findViewById(R.id.subpopup))
                    .setText("/r/" + submission.getSubredditName());
                dialoglayout
                    .findViewById(R.id.sidebar)
                    .setOnClickListener(
                        new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {

                            Intent i = new Intent(holder2.itemView.getContext(), Profile.class);
                            i.putExtra(Profile.EXTRA_PROFILE, submission.getAuthor());
                            holder2.itemView.getContext().startActivity(i);
                          }
                        });

                dialoglayout
                    .findViewById(R.id.wiki)
                    .setOnClickListener(
                        new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                            Intent i =
                                new Intent(holder2.itemView.getContext(), SubredditView.class);
                            i.putExtra(
                                SubredditView.EXTRA_SUBREDDIT, submission.getSubredditName());
                            holder2.itemView.getContext().startActivity(i);
                          }
                        });

                dialoglayout
                    .findViewById(R.id.save)
                    .setOnClickListener(
                        new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                            if (saved) {
                              ((TextView) dialoglayout.findViewById(R.id.savedtext))
                                  .setText(R.string.submission_save);
                            } else {
                              ((TextView) dialoglayout.findViewById(R.id.savedtext))
                                  .setText(R.string.submission_post_saved);
                            }
                            new AsyncSave(holder.itemView).execute(submission);
                          }
                        });
                if (saved) {
                  ((TextView) dialoglayout.findViewById(R.id.savedtext))
                      .setText(R.string.submission_post_saved);
                }
                dialoglayout
                    .findViewById(R.id.gild)
                    .setOnClickListener(
                        new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                            String urlString = "https://reddit.com" + submission.getPermalink();
                            OpenRedditLink.customIntentChooser(
                                urlString, holder2.itemView.getContext());
                          }
                        });
                dialoglayout
                    .findViewById(R.id.share)
                    .setOnClickListener(
                        new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                            if (submission.isSelfPost())
                              Reddit.defaultShareText(
                                  "https://reddit.com" + submission.getPermalink(),
                                  holder2.itemView.getContext());
                            else {
                              new BottomSheet.Builder(context)
                                  .title(R.string.submission_share_title)
                                  .grid()
                                  .sheet(R.menu.share_menu)
                                  .listener(
                                      new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                          switch (which) {
                                            case R.id.reddit_url:
                                              Reddit.defaultShareText(
                                                  "https://reddit.com" + submission.getPermalink(),
                                                  holder2.itemView.getContext());
                                              break;
                                            case R.id.link_url:
                                              Reddit.defaultShareText(
                                                  submission.getUrl(),
                                                  holder2.itemView.getContext());
                                              break;
                                          }
                                        }
                                      })
                                  .show();
                            }
                          }
                        });
                dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE);
                if (!Authentication.isLoggedIn || !Authentication.didOnline) {
                  dialoglayout.findViewById(R.id.save).setVisibility(View.GONE);
                  dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE);
                }
                title.setBackgroundColor(Palette.getColor(submission.getSubredditName()));

                builder.setView(dialoglayout);
                final Dialog d = builder.show();
                if (!SettingValues.hideButton) {
                  dialoglayout
                      .findViewById(R.id.hide)
                      .setOnClickListener(
                          new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                              final int pos = dataSet.posts.indexOf(submission);
                              final Submission old = dataSet.posts.get(pos);
                              dataSet.posts.remove(submission);

                              notifyItemRemoved(pos);
                              d.dismiss();
                              Hidden.setHidden(old);

                              OfflineSubreddit.getSubreddit(dataSet.subreddit).hide(pos);

                              Snackbar.make(
                                      listView,
                                      R.string.submission_info_hidden,
                                      Snackbar.LENGTH_LONG)
                                  .setAction(
                                      R.string.btn_undo,
                                      new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                          OfflineSubreddit.getSubreddit(dataSet.subreddit)
                                              .unhideLast();

                                          dataSet.posts.add(pos, old);
                                          notifyItemInserted(pos);
                                          Hidden.undoHidden(old);
                                        }
                                      })
                                  .show();
                            }
                          });
                } else {
                  dialoglayout.findViewById(R.id.hide).setVisibility(View.GONE);
                }
              }
              return true;
            }
          });

      new PopulateSubmissionViewHolder()
          .populateSubmissionViewHolder(
              holder,
              submission,
              context,
              false,
              false,
              dataSet.posts,
              listView,
              custom,
              !dataSet.stillShow,
              dataSet.subreddit.toLowerCase());
    }
    if (holder2 instanceof SubmissionFooterViewHolder) {
      Handler handler = new Handler();

      final Runnable r =
          new Runnable() {
            public void run() {
              notifyItemChanged(
                  dataSet.posts.size() + 1); // the loading spinner to replaced by nomoreposts.xml
            }
          };

      handler.post(r);
    }
  }
Example #17
0
  @Override
  public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int i) {

    if (holder2 instanceof SubmissionViewHolder) {
      final SubmissionViewHolder holder = (SubmissionViewHolder) holder2;
      final Submission submission = dataSet.posts.get(i);
      CreateCardView.resetColorCard(holder.itemView);
      CreateCardView.colorCard(
          submission.getSubredditName().toLowerCase(), holder.itemView, "nomatching", false);
      holder.itemView.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
              DataShare.sharedSubreddit = dataSet.posts;

              if (Reddit.tabletUI
                  && mContext.getResources().getConfiguration().orientation
                      == Configuration.ORIENTATION_LANDSCAPE) {
                Intent i2 = new Intent(mContext, CommentsScreenPopup.class);
                i2.putExtra("page", i);
                (mContext).startActivity(i2);

              } else {
                Intent i2 = new Intent(mContext, CommentsScreen.class);
                i2.putExtra("page", i);
                ((Activity) mContext).startActivityForResult(i2, 2);
              }
            }
          });

      new PopulateSubmissionViewHolder()
          .PopulateSubmissionViewHolder(
              holder, submission, mContext, false, false, dataSet.posts, listView, false);
      holder.itemView.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
              final View dialoglayout = inflater.inflate(R.layout.postmenu, null);
              AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
              final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
              title.setText(submission.getTitle());

              ((TextView) dialoglayout.findViewById(R.id.userpopup))
                  .setText("/u/" + submission.getAuthor());
              ((TextView) dialoglayout.findViewById(R.id.subpopup))
                  .setText("/r/" + submission.getSubredditName());
              dialoglayout
                  .findViewById(R.id.sidebar)
                  .setOnClickListener(
                      new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                          Intent i = new Intent(mContext, Profile.class);
                          i.putExtra("profile", submission.getAuthor());
                          mContext.startActivity(i);
                        }
                      });

              dialoglayout
                  .findViewById(R.id.wiki)
                  .setOnClickListener(
                      new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                          Intent i = new Intent(mContext, SubredditView.class);
                          i.putExtra("subreddit", submission.getSubredditName());
                          mContext.startActivity(i);
                        }
                      });

              dialoglayout
                  .findViewById(R.id.save)
                  .setOnClickListener(
                      new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                          if (submission.isSaved()) {
                            ((TextView) dialoglayout.findViewById(R.id.savedtext))
                                .setText(R.string.submission_save);
                          } else {
                            ((TextView) dialoglayout.findViewById(R.id.savedtext))
                                .setText(R.string.submission_post_saved);
                          }
                          new SubmissionAdapter.AsyncSave(holder.itemView).execute(submission);
                        }
                      });
              if (submission.isSaved()) {
                ((TextView) dialoglayout.findViewById(R.id.savedtext))
                    .setText(R.string.submission_post_saved);
              }
              dialoglayout
                  .findViewById(R.id.gild)
                  .setOnClickListener(
                      new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                          String urlString = "https://reddit.com" + submission.getPermalink();
                          Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString));
                          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                          intent.setPackage(
                              "com.android.chrome"); // Force open in chrome so it doesn't open back
                                                     // in Slide
                          try {
                            mContext.startActivity(intent);
                          } catch (ActivityNotFoundException ex) {
                            intent.setPackage(null);
                            mContext.startActivity(intent);
                          }
                        }
                      });
              dialoglayout
                  .findViewById(R.id.share)
                  .setOnClickListener(
                      new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                          new AlertDialogWrapper.Builder(mContext)
                              .setTitle(R.string.submission_share_title)
                              .setNegativeButton(
                                  R.string.submission_share_reddit,
                                  new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                      Reddit.defaultShareText(
                                          "http://reddit.com" + submission.getPermalink(),
                                          mContext);
                                    }
                                  })
                              .setPositiveButton(
                                  R.string.submission_share_content,
                                  new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                      Reddit.defaultShareText(submission.getUrl(), mContext);
                                    }
                                  })
                              .show();
                        }
                      });
              if (!Authentication.isLoggedIn) {
                dialoglayout.findViewById(R.id.save).setVisibility(View.GONE);
                dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE);
              }
              title.setBackgroundColor(Pallete.getColor(submission.getSubredditName()));

              builder.setView(dialoglayout);
              final Dialog d = builder.show();
              dialoglayout
                  .findViewById(R.id.hide)
                  .setOnClickListener(
                      new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                          final int pos = dataSet.posts.indexOf(submission);
                          final Submission old = dataSet.posts.get(pos);
                          dataSet.posts.remove(submission);
                          notifyItemRemoved(pos);
                          d.dismiss();
                          Hidden.setHidden(old);

                          Snackbar.make(
                                  listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG)
                              .setAction(
                                  R.string.btn_undo,
                                  new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                      dataSet.posts.add(pos, old);
                                      notifyItemInserted(pos);
                                      Hidden.undoHidden(old);
                                    }
                                  })
                              .show();
                        }
                      });
              return true;
            }
          });
      int lastPosition = i;
    }
  }
Example #18
0
    @Override
    public Fragment getItem(int i) {

      Fragment f;
      ContentType.ImageType t = ContentType.getImageType(subredditPosts.getPosts().get(i));

      if (subredditPosts.getPosts().size() - 2 <= i && subredditPosts.hasMore()) {
        subredditPosts.loadMore(Shadowbox.this.getApplicationContext(), Shadowbox.this, false);
      }
      switch (t) {
        case NSFW_IMAGE:
        case NSFW_GIF:
        case NSFW_GFY:
        case GFY:
        case GIF:
        case IMAGE:
        case NONE_GFY:
        case NONE_GIF:
        case NONE_IMAGE:
          {
            f = new MediaFragment();
            Bundle args = new Bundle();
            Submission submission = OfflineSubreddit.getSubreddit(subreddit).submissions.get(i);
            String previewUrl = "";
            if (submission.getDataNode().has("preview")
                && submission
                    .getDataNode()
                    .get("preview")
                    .get("images")
                    .get(0)
                    .get("source")
                    .has("height")) { // Load the preview image which has probably already been
              // cached in memory instead of the direct link
              previewUrl =
                  submission
                      .getDataNode()
                      .get("preview")
                      .get("images")
                      .get(0)
                      .get("source")
                      .get("url")
                      .asText();
            }
            args.putString("contentUrl", submission.getUrl());
            args.putString("firstUrl", previewUrl);
            args.putInt("page", i);
            args.putString("sub", subreddit);
            f.setArguments(args);
          }
          break;
        case REDDIT:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case EMBEDDED:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case LINK:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case IMAGE_LINK:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case NSFW_LINK:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case SELF:
          {
            if (subredditPosts.getPosts().get(i).getSelftext().isEmpty()) {
              f = new TitleFull();
              Bundle args = new Bundle();
              args.putInt("page", i);
              args.putString("sub", subreddit);

              f.setArguments(args);
            } else {
              f = new SelftextFull();
              Bundle args = new Bundle();
              args.putInt("page", i);
              args.putString("sub", subreddit);

              f.setArguments(args);
            }
          }
          break;
        case ALBUM:
          {
            f = new AlbumFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case VID_ME:
        case STREAMABLE:
          {
            f = new Gif();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case NONE:
          {
            if (subredditPosts.getPosts().get(i).getSelftext().isEmpty()) {
              f = new TitleFull();
              Bundle args = new Bundle();
              args.putInt("page", i);
              args.putString("sub", subreddit);

              f.setArguments(args);
            } else {
              f = new SelftextFull();
              Bundle args = new Bundle();
              args.putInt("page", i);
              args.putString("sub", subreddit);

              f.setArguments(args);
            }
          }
          break;
        case VIDEO:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case NONE_URL:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        default:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
      }

      return f;
    }
Example #19
0
  @Override
  public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int i) {
    if (holder2 instanceof SubmissionViewHolder) {
      final SubmissionViewHolder holder = (SubmissionViewHolder) holder2;
      final Submission submission = dataSet.posts.get(i);

      CreateCardView.resetColorCard(holder.itemView);
      CreateCardView.colorCard(
          submission.getSubredditName().toLowerCase(), holder.itemView, subreddit, custom);
      holder.itemView.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
              if (dataSet.stillShow) {
                DataShare.sharedSubreddit = dataSet.posts;
                holder2.itemView.setAlpha(0.5f);
                if (Reddit.tabletUI
                    && mContext.getResources().getConfiguration().orientation
                        == Configuration.ORIENTATION_LANDSCAPE) {
                  Intent i2 = new Intent(mContext, CommentsScreenPopup.class);
                  i2.putExtra("page", holder2.getAdapterPosition());
                  (mContext).startActivity(i2);

                } else {
                  Intent i2 = new Intent(mContext, CommentsScreen.class);
                  i2.putExtra("page", holder2.getAdapterPosition());
                  (mContext).startActivity(i2);
                }
              } else {
                Snackbar.make(
                        holder.itemView,
                        "Please go online and refresh the subreddit to do that",
                        Snackbar.LENGTH_SHORT)
                    .show();
              }
            }
          });
      final boolean saved = submission.isSaved();

      holder.itemView.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              if (!dataSet.stillShow) {

                Snackbar.make(
                        holder.itemView,
                        "Please go online and refresh the subreddit to do that",
                        Snackbar.LENGTH_SHORT)
                    .show();

              } else {
                LayoutInflater inflater = mContext.getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.postmenu, null);
                AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(mContext);
                final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
                title.setText(submission.getTitle());

                ((TextView) dialoglayout.findViewById(R.id.userpopup))
                    .setText("/u/" + submission.getAuthor());
                ((TextView) dialoglayout.findViewById(R.id.subpopup))
                    .setText("/r/" + submission.getSubredditName());
                dialoglayout
                    .findViewById(R.id.sidebar)
                    .setOnClickListener(
                        new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {

                            Intent i = new Intent(mContext, Profile.class);
                            i.putExtra("profile", submission.getAuthor());
                            mContext.startActivity(i);
                          }
                        });

                dialoglayout
                    .findViewById(R.id.wiki)
                    .setOnClickListener(
                        new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                            Intent i = new Intent(mContext, SubredditView.class);
                            i.putExtra("subreddit", submission.getSubredditName());
                            mContext.startActivity(i);
                          }
                        });

                dialoglayout
                    .findViewById(R.id.save)
                    .setOnClickListener(
                        new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                            if (saved) {
                              ((TextView) dialoglayout.findViewById(R.id.savedtext))
                                  .setText(R.string.submission_save);
                            } else {
                              ((TextView) dialoglayout.findViewById(R.id.savedtext))
                                  .setText(R.string.submission_post_saved);
                            }
                            new AsyncSave(holder.itemView).execute(submission);
                          }
                        });
                if (saved) {
                  ((TextView) dialoglayout.findViewById(R.id.savedtext))
                      .setText(R.string.submission_post_saved);
                }
                dialoglayout
                    .findViewById(R.id.gild)
                    .setOnClickListener(
                        new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                            String urlString = "https://reddit.com" + submission.getPermalink();
                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString));
                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.setPackage(
                                "com.android.chrome"); // Force open in chrome so it doesn't open
                                                       // back in Slide
                            try {
                              mContext.startActivity(intent);
                            } catch (ActivityNotFoundException ex) {
                              intent.setPackage(null);
                              mContext.startActivity(intent);
                            }
                          }
                        });
                dialoglayout
                    .findViewById(R.id.share)
                    .setOnClickListener(
                        new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                            if (submission.isSelfPost())
                              Reddit.defaultShareText(
                                  "http://reddit.com" + submission.getPermalink(), mContext);
                            else {
                              new BottomSheet.Builder(mContext, R.style.BottomSheet_Dialog)
                                  .title(R.string.submission_share_title)
                                  .grid()
                                  .sheet(R.menu.share_menu)
                                  .listener(
                                      new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                          switch (which) {
                                            case R.id.reddit_url:
                                              Reddit.defaultShareText(
                                                  "http://reddit.com" + submission.getPermalink(),
                                                  mContext);
                                              break;
                                            case R.id.link_url:
                                              Reddit.defaultShareText(
                                                  submission.getUrl(), mContext);
                                              break;
                                          }
                                        }
                                      })
                                  .show();
                            }
                          }
                        });
                dialoglayout.findViewById(R.id.copy).setVisibility(View.GONE);
                if (!Authentication.isLoggedIn) {
                  dialoglayout.findViewById(R.id.save).setVisibility(View.GONE);
                  dialoglayout.findViewById(R.id.gild).setVisibility(View.GONE);
                }
                title.setBackgroundColor(Pallete.getColor(submission.getSubredditName()));

                builder.setView(dialoglayout);
                final Dialog d = builder.show();
                dialoglayout
                    .findViewById(R.id.hide)
                    .setOnClickListener(
                        new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                            final int pos = dataSet.posts.indexOf(submission);
                            final Submission old = dataSet.posts.get(pos);
                            dataSet.posts.remove(submission);
                            notifyItemRemoved(pos);
                            d.dismiss();
                            Hidden.setHidden(old);

                            Snackbar.make(
                                    listView, R.string.submission_info_hidden, Snackbar.LENGTH_LONG)
                                .setAction(
                                    R.string.btn_undo,
                                    new View.OnClickListener() {
                                      @Override
                                      public void onClick(View v) {
                                        dataSet.posts.add(pos, old);
                                        notifyItemInserted(pos);
                                        Hidden.undoHidden(old);
                                      }
                                    })
                                .show();
                          }
                        });
              }
              return true;
            }
          });

      new PopulateSubmissionViewHolder()
          .PopulateSubmissionViewHolder(
              holder,
              submission,
              mContext,
              false,
              false,
              dataSet.posts,
              listView,
              custom,
              !dataSet.stillShow);

      holder.itemView.addOnLayoutChangeListener(
          new View.OnLayoutChangeListener() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onLayoutChange(
                final View v,
                int left,
                int top,
                int right,
                int bottom,
                int oldLeft,
                int oldTop,
                int oldRight,
                int oldBottom) {
              v.removeOnLayoutChangeListener(this);
              setAnimation(v, i);
            }
          });
    }
    if (holder2 instanceof SubmissionFooterViewHolder) {
      Handler handler = new Handler();

      final Runnable r =
          new Runnable() {
            public void run() {
              notifyItemChanged(
                  dataSet.posts.size() + 1); // the loading spinner to replaced by nomoreposts.xml
            }
          };

      handler.post(r);
    }
    views.add(holder2);
  }