use of me.ccrama.redditslide.Activities.Album in project Slide by ccrama.
the class SpoilerRobotoTextView method onLinkClick.
@Override
public void onLinkClick(String url, int xOffset, String subreddit, URLSpan span) {
if (url == null) {
((View) getParent()).callOnClick();
return;
}
ContentType.Type type = ContentType.getContentType(url);
Context context = getContext();
Activity activity = null;
if (context instanceof Activity) {
activity = (Activity) context;
} else if (context instanceof ContextThemeWrapper) {
activity = (Activity) ((ContextThemeWrapper) context).getBaseContext();
} else if (context instanceof ContextWrapper) {
Context context1 = ((ContextWrapper) context).getBaseContext();
if (context1 instanceof Activity) {
activity = (Activity) context1;
} else if (context1 instanceof ContextWrapper) {
Context context2 = ((ContextWrapper) context1).getBaseContext();
if (context2 instanceof Activity) {
activity = (Activity) context2;
} else if (context2 instanceof ContextWrapper) {
activity = (Activity) ((ContextThemeWrapper) context2).getBaseContext();
}
}
} else {
throw new RuntimeException("Could not find activity from context:" + context);
}
if (!PostMatch.openExternal(url) || type == ContentType.Type.VIDEO) {
switch(type) {
case DEVIANTART:
case IMGUR:
case XKCD:
if (SettingValues.image) {
Intent intent2 = new Intent(activity, MediaView.class);
intent2.putExtra(MediaView.EXTRA_URL, url);
intent2.putExtra(MediaView.SUBREDDIT, subreddit);
activity.startActivity(intent2);
} else {
LinkUtil.openExternally(url);
}
break;
case REDDIT:
OpenRedditLink.openUrl(activity, url, true);
break;
case LINK:
LogUtil.v("Opening link");
LinkUtil.openUrl(url, Palette.getColor(subreddit), activity);
break;
case SELF:
case NONE:
break;
case STREAMABLE:
openStreamable(url, subreddit);
break;
case ALBUM:
if (SettingValues.album) {
Intent i;
if (SettingValues.albumSwipe) {
i = new Intent(activity, AlbumPager.class);
i.putExtra(Album.EXTRA_URL, url);
i.putExtra(AlbumPager.SUBREDDIT, subreddit);
} else {
i = new Intent(activity, Album.class);
i.putExtra(Album.SUBREDDIT, subreddit);
i.putExtra(Album.EXTRA_URL, url);
}
activity.startActivity(i);
} else {
LinkUtil.openExternally(url);
}
break;
case TUMBLR:
if (SettingValues.image) {
Intent i = new Intent(activity, TumblrPager.class);
i.putExtra(Album.EXTRA_URL, url);
activity.startActivity(i);
} else {
LinkUtil.openExternally(url);
}
break;
case IMAGE:
openImage(url, subreddit);
break;
case VREDDIT_REDIRECT:
openVReddit(url, subreddit, activity);
break;
case GIF:
case VREDDIT_DIRECT:
openGif(url, subreddit, activity);
break;
case VIDEO:
if (!LinkUtil.tryOpenWithVideoPlugin(url)) {
LinkUtil.openUrl(url, Palette.getStatusBarColor(), activity);
}
case SPOILER:
spoilerClicked = true;
setOrRemoveSpoilerSpans(xOffset, span);
break;
case EXTERNAL:
LinkUtil.openExternally(url);
break;
}
} else {
LinkUtil.openExternally(url);
}
}
use of me.ccrama.redditslide.Activities.Album in project Slide by ccrama.
the class CommentPage method onMenuItemClick.
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.search:
{
if (comments.comments != null && comments.submission != null) {
DataShare.sharedComments = comments.comments;
DataShare.subAuthor = comments.submission.getAuthor();
Intent i = new Intent(getActivity(), CommentSearch.class);
if (getActivity() instanceof MainActivity) {
getActivity().startActivityForResult(i, 423);
} else {
startActivityForResult(i, 423);
}
}
}
return true;
case R.id.sidebar:
doSidebarOpen();
return true;
case R.id.related:
if (adapter.submission.isSelfPost()) {
new AlertDialog.Builder(getActivity()).setTitle("Selftext posts have no related submissions").setPositiveButton(R.string.btn_ok, null).show();
} else {
Intent i = new Intent(getActivity(), Related.class);
i.putExtra(Related.EXTRA_URL, adapter.submission.getUrl());
startActivity(i);
}
return true;
case R.id.shadowbox:
if (SettingValues.isPro) {
if (comments.comments != null && comments.submission != null) {
ShadowboxComments.comments = new ArrayList<>();
for (CommentObject c : comments.comments) {
if (c instanceof CommentItem) {
if (c.comment.getComment().getDataNode().get("body_html").asText().contains("</a")) {
String body = c.comment.getComment().getDataNode().get("body_html").asText();
String url;
String[] split = body.split("<a href=\"");
if (split.length > 1) {
for (String chunk : split) {
url = chunk.substring(0, chunk.indexOf("\"", 1));
ContentType.Type t = ContentType.getContentType(url);
if (ContentType.mediaType(t)) {
ShadowboxComments.comments.add(new CommentUrlObject(c.comment, url, subreddit));
}
}
} else {
int start = body.indexOf("<a href=\"");
url = body.substring(start, body.indexOf("\"", start + 1));
ContentType.Type t = ContentType.getContentType(url);
if (ContentType.mediaType(t)) {
ShadowboxComments.comments.add(new CommentUrlObject(c.comment, url, subreddit));
}
}
}
}
}
if (!ShadowboxComments.comments.isEmpty()) {
Intent i = new Intent(getActivity(), ShadowboxComments.class);
startActivity(i);
} else {
Snackbar.make(mSwipeRefreshLayout, R.string.shadowbox_comments_nolinks, Snackbar.LENGTH_SHORT).show();
}
}
} else {
ProUtil.proUpgradeMsg(getContext(), R.string.general_shadowbox_comments_ispro).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss()).show();
}
return true;
case R.id.sort:
{
openPopup(toolbar);
return true;
}
case R.id.content:
{
if (adapter != null && adapter.submission != null) {
if (!PostMatch.openExternal(adapter.submission.getUrl())) {
ContentType.Type type = ContentType.getContentType(adapter.submission);
switch(type) {
case STREAMABLE:
if (SettingValues.video) {
Intent myIntent = new Intent(getActivity(), MediaView.class);
myIntent.putExtra(MediaView.SUBREDDIT, subreddit);
myIntent.putExtra(MediaView.EXTRA_URL, adapter.submission.getUrl());
myIntent.putExtra(EXTRA_SUBMISSION_TITLE, adapter.submission.getTitle());
getActivity().startActivity(myIntent);
} else {
LinkUtil.openExternally(adapter.submission.getUrl());
}
break;
case IMGUR:
case XKCD:
Intent i2 = new Intent(getActivity(), MediaView.class);
i2.putExtra(MediaView.SUBREDDIT, subreddit);
i2.putExtra(EXTRA_SUBMISSION_TITLE, adapter.submission.getTitle());
if (adapter.submission.getDataNode().has("preview") && adapter.submission.getDataNode().get("preview").get("images").get(0).get("source").has("height") && type != ContentType.Type.XKCD) {
// Load the preview image which has probably already been cached in memory instead of the direct link
String previewUrl = adapter.submission.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
i2.putExtra(MediaView.EXTRA_DISPLAY_URL, previewUrl);
}
i2.putExtra(MediaView.EXTRA_URL, adapter.submission.getUrl());
getActivity().startActivity(i2);
break;
case EMBEDDED:
if (SettingValues.video) {
String data = adapter.submission.getDataNode().get("media_embed").get("content").asText();
{
Intent i = new Intent(getActivity(), FullscreenVideo.class);
i.putExtra(FullscreenVideo.EXTRA_HTML, data);
getActivity().startActivity(i);
}
} else {
LinkUtil.openExternally(adapter.submission.getUrl());
}
break;
case REDDIT:
PopulateSubmissionViewHolder.openRedditContent(adapter.submission.getUrl(), getActivity());
break;
case LINK:
LinkUtil.openUrl(adapter.submission.getUrl(), Palette.getColor(adapter.submission.getSubredditName()), getActivity());
break;
case NONE:
case SELF:
if (adapter.submission.getSelftext().isEmpty()) {
Snackbar s = Snackbar.make(rv, R.string.submission_nocontent, Snackbar.LENGTH_SHORT);
LayoutUtils.showSnackbar(s);
} else {
LayoutInflater inflater = getActivity().getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.parent_comment_dialog, null);
adapter.setViews(adapter.submission.getDataNode().get("selftext_html").asText(), adapter.submission.getSubredditName(), dialoglayout.findViewById(R.id.firstTextView), dialoglayout.findViewById(R.id.commentOverflow));
new AlertDialog.Builder(getActivity()).setView(dialoglayout).show();
}
break;
case ALBUM:
if (SettingValues.album) {
Intent i;
if (SettingValues.albumSwipe) {
i = new Intent(getActivity(), AlbumPager.class);
i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
i.putExtra(AlbumPager.SUBREDDIT, subreddit);
} else {
i = new Intent(getActivity(), Album.class);
i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
i.putExtra(Album.SUBREDDIT, subreddit);
}
i.putExtra(EXTRA_SUBMISSION_TITLE, adapter.submission.getTitle());
getActivity().startActivity(i);
getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
} else {
LinkUtil.openExternally(adapter.submission.getUrl());
}
break;
case TUMBLR:
if (SettingValues.image) {
Intent i;
if (SettingValues.albumSwipe) {
i = new Intent(getActivity(), TumblrPager.class);
i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
i.putExtra(TumblrPager.SUBREDDIT, subreddit);
} else {
i = new Intent(getActivity(), Tumblr.class);
i.putExtra(Tumblr.SUBREDDIT, subreddit);
i.putExtra(Album.EXTRA_URL, adapter.submission.getUrl());
}
getActivity().startActivity(i);
getActivity().overridePendingTransition(R.anim.slideright, R.anim.fade_out);
} else {
LinkUtil.openExternally(adapter.submission.getUrl());
}
break;
case IMAGE:
PopulateSubmissionViewHolder.openImage(type, getActivity(), adapter.submission, null, -1);
break;
case VREDDIT_REDIRECT:
case VREDDIT_DIRECT:
case GIF:
PopulateSubmissionViewHolder.openGif(getActivity(), adapter.submission, -1);
break;
case VIDEO:
if (!LinkUtil.tryOpenWithVideoPlugin(adapter.submission.getUrl())) {
LinkUtil.openUrl(adapter.submission.getUrl(), Palette.getStatusBarColor(), getActivity());
}
}
} else {
LinkUtil.openExternally(adapter.submission.getUrl());
}
}
}
return true;
case R.id.reload:
if (comments != null) {
mSwipeRefreshLayout.setRefreshing(true);
comments.loadMore(adapter, subreddit);
}
return true;
case R.id.collapse:
{
if (adapter != null) {
adapter.collapseAll();
}
}
return true;
case android.R.id.home:
getActivity().onBackPressed();
return true;
}
return false;
}
Aggregations