private static void setViews( String rawHTML, String subredditName, SpoilerRobotoTextView firstTextView, CommentOverflow commentOverflow) { if (rawHTML.isEmpty()) { return; } List<String> blocks = SubmissionParser.getBlocks(rawHTML); int startIndex = 0; // the <div class="md"> case is when the body contains a table or code block first if (!blocks.get(0).equals("<div class=\"md\">")) { firstTextView.setVisibility(View.VISIBLE); firstTextView.setTextHtml(blocks.get(0), subredditName); firstTextView.setLinkTextColor( new ColorPreferences(firstTextView.getContext()).getColor(subredditName)); startIndex = 1; } else { firstTextView.setText(""); firstTextView.setVisibility(View.GONE); } if (blocks.size() > 1) { if (startIndex == 0) { commentOverflow.setViews(blocks, subredditName); } else { commentOverflow.setViews(blocks.subList(startIndex, blocks.size()), subredditName); } } else { commentOverflow.removeAllViews(); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.submission_imagecard_album, container, false); String url; if (gallery) { url = ("https://imgur.com/" + user.getAsJsonObject().get("hash").getAsString() + ".png"); } else { url = (user.getAsJsonObject().getAsJsonObject("links").get("original").getAsString()); } final SubsamplingScaleImageView image = (SubsamplingScaleImageView) rootView.findViewById(R.id.image); TitleTextView title = (TitleTextView) rootView.findViewById(R.id.title); SpoilerRobotoTextView desc = (SpoilerRobotoTextView) rootView.findViewById(R.id.desc); ImageView fakeImage = new ImageView(getActivity()); fakeImage.setLayoutParams(new LinearLayout.LayoutParams(image.getWidth(), image.getHeight())); fakeImage.setScaleType(ImageView.ScaleType.CENTER_CROP); ((Reddit) getActivity().getApplication()) .getImageLoader() .displayImage( url, new ImageViewAware(fakeImage), ImageLoaderUtils.options, new ImageLoadingListener() { private View mView; @Override public void onLoadingStarted(String imageUri, View view) { mView = view; } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { Log.v("Slide", "LOADING FAILED"); } @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { image.setImage(ImageSource.bitmap(loadedImage)); (rootView.findViewById(R.id.progress)).setVisibility(View.GONE); } @Override public void onLoadingCancelled(String imageUri, View view) { Log.v("Slide", "LOADING CANCELLED"); } }, new ImageLoadingProgressListener() { @Override public void onProgressUpdate(String imageUri, View view, int current, int total) { ((ProgressBar) rootView.findViewById(R.id.progress)) .setProgress(Math.round(100.0f * current / total)); } }); title.setVisibility(View.VISIBLE); desc.setVisibility(View.VISIBLE); if (user.getAsJsonObject().has("image")) { if (!user.getAsJsonObject().getAsJsonObject("image").get("title").isJsonNull()) { List<String> text = SubmissionParser.getBlocks( user.getAsJsonObject().getAsJsonObject("image").get("title").getAsString()); title.setTextHtml(text.get(0)); if (desc.getText().toString().isEmpty()) { desc.setVisibility(View.GONE); } } else { desc.setVisibility(View.GONE); } if (!user.getAsJsonObject().getAsJsonObject("image").get("caption").isJsonNull()) { List<String> text = SubmissionParser.getBlocks( user.getAsJsonObject().getAsJsonObject("image").get("caption").getAsString()); title.setText(Html.fromHtml(text.get(0))); if (title.getText().toString().isEmpty()) { title.setVisibility(View.GONE); } } else { title.setVisibility(View.GONE); } } else { if (user.getAsJsonObject().has("title")) { List<String> text = SubmissionParser.getBlocks(user.getAsJsonObject().get("title").getAsString()); title.setText(Html.fromHtml(text.get(0))); if (desc.getText().toString().isEmpty()) { desc.setVisibility(View.GONE); } } else { desc.setVisibility(View.GONE); } if (user.getAsJsonObject().has("description")) { List<String> text = SubmissionParser.getBlocks(user.getAsJsonObject().get("description").getAsString()); title.setText(Html.fromHtml(text.get(0))); if (title.getText().toString().isEmpty()) { title.setVisibility(View.GONE); } } else { title.setVisibility(View.GONE); } } return rootView; }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = (ViewGroup) inflater.inflate(R.layout.submission_gifcard_album, container, false); loader = (ProgressBar) rootView.findViewById(R.id.gifprogress); TitleTextView title = (TitleTextView) rootView.findViewById(R.id.title); SpoilerRobotoTextView desc = (SpoilerRobotoTextView) rootView.findViewById(R.id.desc); title.setVisibility(View.VISIBLE); desc.setVisibility(View.VISIBLE); if (user.getAsJsonObject().has("image")) { if (!user.getAsJsonObject().getAsJsonObject("image").get("title").isJsonNull()) { List<String> text = SubmissionParser.getBlocks( user.getAsJsonObject().getAsJsonObject("image").get("title").getAsString()); desc.setTextHtml(text.get(0)); if (desc.getText().toString().isEmpty()) { desc.setVisibility(View.GONE); } } else { desc.setVisibility(View.GONE); } if (!user.getAsJsonObject().getAsJsonObject("image").get("caption").isJsonNull()) { title.setTextHtml( user.getAsJsonObject().getAsJsonObject("image").get("caption").getAsString(), "FORCE_LINK_HANDLING"); if (title.getText().toString().isEmpty()) { title.setVisibility(View.GONE); } } else { title.setVisibility(View.GONE); } } else { if (user.getAsJsonObject().has("title")) { desc.setTextHtml( user.getAsJsonObject().get("title").getAsString(), "FORCE_LINK_HANDLING"); if (desc.getText().toString().isEmpty()) { desc.setVisibility(View.GONE); } } else { desc.setVisibility(View.GONE); } if (user.getAsJsonObject().has("description")) { title.setTextHtml( user.getAsJsonObject().get("description").getAsString(), "FORCE_LINK_HANDLING"); if (title.getText().toString().isEmpty()) { title.setVisibility(View.GONE); } } else { title.setVisibility(View.GONE); } } gif = rootView.findViewById(R.id.gif); gif.setVisibility(View.VISIBLE); final MediaVideoView v = (MediaVideoView) gif; v.clearFocus(); String dat; if (gallery) { dat = ("https://imgur.com/" + images.get(i).getAsJsonObject().get("hash").getAsString() + ".gif"); } else { dat = (images .get(i) .getAsJsonObject() .getAsJsonObject("links") .get("original") .getAsString()); } new GifUtils.AsyncLoadGif( AlbumPager.this, (MediaVideoView) rootView.findViewById(R.id.gif), loader, null, null, false) .execute(dat); return rootView; }