use of me.ccrama.redditslide.Activities.SubredditView in project Slide by ccrama.
the class PopulateSubmissionViewHolder method addClickFunctions.
private static void addClickFunctions(final View base, final ContentType.Type type, final Activity contextActivity, final Submission submission, final SubmissionViewHolder holder, final boolean full) {
base.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (NetworkUtil.isConnected(contextActivity) || (!NetworkUtil.isConnected(contextActivity) && ContentType.fullImage(type))) {
if (SettingValues.storeHistory && !full) {
if (!submission.isNsfw() || SettingValues.storeNSFWHistory) {
HasSeen.addSeen(submission.getFullName());
if (contextActivity instanceof MainActivity || contextActivity instanceof MultiredditOverview || contextActivity instanceof SubredditView || contextActivity instanceof Search || contextActivity instanceof Profile) {
holder.title.setAlpha(0.54f);
holder.body.setAlpha(0.54f);
}
}
}
if (!(contextActivity instanceof PeekViewActivity) || !((PeekViewActivity) contextActivity).isPeeking() || (base instanceof HeaderImageLinkView && ((HeaderImageLinkView) base).popped)) {
if (!PostMatch.openExternal(submission.getUrl()) || type == ContentType.Type.VIDEO) {
switch(type) {
case VID_ME:
case STREAMABLE:
if (SettingValues.video) {
Intent myIntent = new Intent(contextActivity, MediaView.class);
myIntent.putExtra(MediaView.SUBREDDIT, submission.getSubredditName());
myIntent.putExtra(MediaView.EXTRA_URL, submission.getUrl());
addAdaptorPosition(myIntent, submission, holder.getAdapterPosition());
contextActivity.startActivity(myIntent);
} else {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
break;
case IMGUR:
openImage(type, contextActivity, submission, holder.leadImage, holder.getAdapterPosition());
break;
case EMBEDDED:
if (SettingValues.video) {
String data = Html.fromHtml(submission.getDataNode().get("media_embed").get("content").asText()).toString();
{
Intent i = new Intent(contextActivity, FullscreenVideo.class);
i.putExtra(FullscreenVideo.EXTRA_HTML, data);
contextActivity.startActivity(i);
}
} else {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
break;
case REDDIT:
openRedditContent(submission.getUrl(), contextActivity);
break;
case LINK:
LinkUtil.openUrl(submission.getUrl(), Palette.getColor(submission.getSubredditName()), contextActivity, holder.getAdapterPosition(), submission);
break;
case SELF:
if (holder != null) {
OnSingleClickListener.override = true;
holder.itemView.performClick();
}
break;
case ALBUM:
if (SettingValues.album) {
Intent i;
if (SettingValues.albumSwipe) {
i = new Intent(contextActivity, AlbumPager.class);
i.putExtra(AlbumPager.SUBREDDIT, submission.getSubredditName());
i.putExtra(Album.EXTRA_URL, submission.getUrl());
} else {
i = new Intent(contextActivity, Album.class);
i.putExtra(Album.SUBREDDIT, submission.getSubredditName());
i.putExtra(Album.EXTRA_URL, submission.getUrl());
}
addAdaptorPosition(i, submission, holder.getAdapterPosition());
contextActivity.startActivity(i);
contextActivity.overridePendingTransition(R.anim.slideright, R.anim.fade_out);
} else {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
break;
case TUMBLR:
if (SettingValues.album) {
Intent i;
if (SettingValues.albumSwipe) {
i = new Intent(contextActivity, TumblrPager.class);
i.putExtra(TumblrPager.SUBREDDIT, submission.getSubredditName());
i.putExtra(Album.EXTRA_URL, submission.getUrl());
} else {
i = new Intent(contextActivity, Tumblr.class);
i.putExtra(Tumblr.SUBREDDIT, submission.getSubredditName());
i.putExtra(Album.EXTRA_URL, submission.getUrl());
}
addAdaptorPosition(i, submission, holder.getAdapterPosition());
contextActivity.startActivity(i);
contextActivity.overridePendingTransition(R.anim.slideright, R.anim.fade_out);
} else {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
break;
case DEVIANTART:
case XKCD:
case IMAGE:
openImage(type, contextActivity, submission, holder.leadImage, holder.getAdapterPosition());
break;
case VREDDIT_REDIRECT:
case GIF:
case VREDDIT_DIRECT:
openGif(contextActivity, submission, holder.getAdapterPosition());
break;
case NONE:
if (holder != null) {
holder.itemView.performClick();
}
break;
case VIDEO:
if (Reddit.videoPlugin) {
try {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setClassName("ccrama.me.slideyoutubeplugin", "ccrama.me.slideyoutubeplugin.YouTubeView");
sharingIntent.putExtra("url", submission.getUrl());
contextActivity.startActivity(sharingIntent);
} catch (Exception e) {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
} else {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
break;
}
} else {
LinkUtil.openExternally(submission.getUrl(), contextActivity);
}
}
} else {
if (!(contextActivity instanceof PeekViewActivity) || !((PeekViewActivity) contextActivity).isPeeking()) {
Snackbar s = Snackbar.make(holder.itemView, R.string.go_online_view_content, Snackbar.LENGTH_SHORT);
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
}
}
});
}
use of me.ccrama.redditslide.Activities.SubredditView in project Slide by ccrama.
the class NewsView method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), new ColorPreferences(inflater.getContext()).getThemeSubreddit(id));
final View v = ((LayoutInflater) contextThemeWrapper.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.fragment_verticalcontent, container, false);
if (getActivity() instanceof MainActivity) {
v.findViewById(R.id.back).setBackgroundResource(0);
}
rv = v.findViewById(R.id.vertical_content);
rv.setHasFixedSize(true);
final RecyclerView.LayoutManager mLayoutManager;
mLayoutManager = createLayoutManager(getNumColumns(getResources().getConfiguration().orientation, getActivity()));
if (!(getActivity() instanceof SubredditView)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
v.findViewById(R.id.back).setBackground(null);
} else {
v.findViewById(R.id.back).setBackgroundDrawable(null);
}
}
rv.setLayoutManager(mLayoutManager);
rv.setItemAnimator(new SlideUpAlphaAnimator());
rv.getLayoutManager().scrollToPosition(0);
mSwipeRefreshLayout = v.findViewById(R.id.activity_main_swipe_refresh_layout);
mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getContext()));
/**
* If using List view mode, we need to remove the start margin from the SwipeRefreshLayout.
* The scrollbar style of "outsideInset" creates a 4dp padding around it. To counter this,
* change the scrollbar style to "insideOverlay" when list view is enabled.
* To recap: this removes the margins from the start/end so list view is full-width.
*/
if (SettingValues.defaultCardView == CreateCardView.CardEnum.LIST) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginStart(0);
} else {
MarginLayoutParamsCompat.setMarginStart(params, 0);
}
rv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mSwipeRefreshLayout.setLayoutParams(params);
}
/**
* If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
* So, we estimate the height of the header in dp.
* If the view type is "single" (and therefore "commentPager"), we need a different offset
*/
final int HEADER_OFFSET = (SettingValues.single || getActivity() instanceof SubredditView) ? Constants.SINGLE_HEADER_VIEW_OFFSET : Constants.TAB_HEADER_VIEW_OFFSET;
mSwipeRefreshLayout.setProgressViewOffset(false, HEADER_OFFSET - Constants.PTR_OFFSET_TOP, HEADER_OFFSET + Constants.PTR_OFFSET_BOTTOM);
if (SettingValues.fab) {
fab = v.findViewById(R.id.post_floating_action_button);
if (SettingValues.fabType == Constants.FAB_POST) {
fab.setImageResource(R.drawable.add);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent inte = new Intent(getActivity(), Submit.class);
inte.putExtra(Submit.EXTRA_SUBREDDIT, id);
getActivity().startActivity(inte);
}
});
} else {
fab.setImageResource(R.drawable.hide);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!Reddit.fabClear) {
new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
Reddit.fabClear = true;
clearSeenPosts(false);
}
}).show();
} else {
clearSeenPosts(false);
}
}
});
final Handler handler = new Handler();
fab.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
detector.onTouchEvent(event);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
origY = event.getY();
handler.postDelayed(mLongPressRunnable, android.view.ViewConfiguration.getLongPressTimeout());
}
if (((event.getAction() == MotionEvent.ACTION_MOVE) && Math.abs(event.getY() - origY) > fab.getHeight() / 2) || (event.getAction() == MotionEvent.ACTION_UP)) {
handler.removeCallbacks(mLongPressRunnable);
}
return false;
}
});
mLongPressRunnable = new Runnable() {
public void run() {
fab.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
if (!Reddit.fabClear) {
new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
Reddit.fabClear = true;
clearSeenPosts(true);
}
}).show();
} else {
clearSeenPosts(true);
}
Snackbar s = Snackbar.make(rv, getResources().getString(R.string.posts_hidden_forever), Snackbar.LENGTH_LONG);
/*Todo a way to unhide
s.setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});*/
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
};
}
} else {
v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
}
if (fab != null)
fab.show();
header = getActivity().findViewById(R.id.header);
// TODO, have it so that if the user clicks anywhere in the rv to hide and cancel GoToSubreddit?
// final TextInputEditText GO_TO_SUB_FIELD = (TextInputEditText) getActivity().findViewById(R.id.toolbar_search);
// final Toolbar TOOLBAR = ((Toolbar) getActivity().findViewById(R.id.toolbar));
// final String PREV_TITLE = TOOLBAR.getTitle().toString();
// final ImageView CLOSE_BUTTON = (ImageView) getActivity().findViewById(R.id.close);
//
// rv.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View v, MotionEvent event) {
// System.out.println("touched");
// InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
// imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
//
// GO_TO_SUB_FIELD.setText("");
// GO_TO_SUB_FIELD.setVisibility(View.GONE);
// CLOSE_BUTTON.setVisibility(View.GONE);
// TOOLBAR.setTitle(PREV_TITLE);
//
// return false;
// }
// });
resetScroll();
Reddit.isLoading = false;
if (MainActivity.shouldLoad == null || id == null || (MainActivity.shouldLoad != null && MainActivity.shouldLoad.equals(id)) || !(getActivity() instanceof MainActivity)) {
doAdapter();
}
return v;
}
use of me.ccrama.redditslide.Activities.SubredditView in project Slide by ccrama.
the class SubmissionNewsAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int pos) {
int i = pos != 0 ? pos - 1 : pos;
if (holder2 instanceof NewsViewHolder) {
final NewsViewHolder holder = (NewsViewHolder) holder2;
final Submission submission = dataSet.posts.get(i);
CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, subreddit, (subreddit.equals("frontpage") || subreddit.equals("mod") || subreddit.equals("friends") || (subreddit.equals("all")) || subreddit.contains(".") || subreddit.contains("+")));
holder.itemView.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
if (Authentication.didOnline || submission.getComments() != null) {
holder.title.setAlpha(0.54f);
if (context instanceof MainActivity) {
final MainActivity a = (MainActivity) context;
if (a.singleMode && a.commentPager && a.adapter instanceof MainActivity.OverviewPagerAdapterComment) {
if (a.openingComments != submission) {
clicked = holder2.getAdapterPosition();
a.openingComments = submission;
a.toOpenComments = a.pager.getCurrentItem() + 1;
a.currentComment = holder.getAdapterPosition() - 1;
((MainActivity.OverviewPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
((MainActivity.OverviewPagerAdapterComment) (a).adapter).size = a.toOpenComments + 1;
try {
a.adapter.notifyDataSetChanged();
} catch (Exception ignored) {
}
}
a.pager.postDelayed(new Runnable() {
@Override
public void run() {
a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
}
}, 400);
} else {
Intent i2 = new Intent(context, CommentsScreen.class);
i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
i2.putExtra("fullname", submission.getFullName());
context.startActivityForResult(i2, 940);
clicked = holder2.getAdapterPosition();
}
} else if (context instanceof SubredditView) {
final SubredditView a = (SubredditView) context;
if (a.singleMode && a.commentPager) {
if (a.openingComments != submission) {
clicked = holder2.getAdapterPosition();
a.openingComments = submission;
a.currentComment = holder.getAdapterPosition() - 1;
((SubredditView.OverviewPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
((SubredditView.OverviewPagerAdapterComment) a.adapter).size = 3;
a.adapter.notifyDataSetChanged();
}
a.pager.postDelayed(new Runnable() {
@Override
public void run() {
a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
}
}, 400);
} else {
Intent i2 = new Intent(context, CommentsScreen.class);
i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
i2.putExtra("fullname", submission.getFullName());
context.startActivityForResult(i2, 940);
clicked = holder2.getAdapterPosition();
}
}
} else {
if (!Reddit.appRestart.contains("offlinepopup")) {
new AlertDialogWrapper.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.appRestart.edit().putString("offlinepopup", "").apply();
}
}).show();
} else {
Snackbar s = Snackbar.make(holder.itemView, R.string.cache_no_comments_found_snackbar, Snackbar.LENGTH_SHORT);
s.setAction(R.string.misc_more_info, new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialogWrapper.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.appRestart.edit().putString("offlinepopup", "").apply();
}
}).show();
}
});
View view = s.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
}
}
});
new PopulateNewsViewHolder().populateNewsViewHolder(holder, submission, context, false, false, dataSet.posts, listView, custom, dataSet.offline, dataSet.subreddit.toLowerCase(Locale.ENGLISH), null);
}
if (holder2 instanceof SubmissionFooterViewHolder) {
Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
notifyItemChanged(dataSet.posts.size() + // the loading spinner to replaced by nomoreposts.xml
1);
}
};
handler.post(r);
if (holder2.itemView.findViewById(R.id.reload) != null) {
holder2.itemView.findViewById(R.id.reload).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dataSet.loadMore(context, displayer, true);
}
});
}
}
if (holder2 instanceof SpacerViewHolder) {
View header = (context).findViewById(R.id.header);
int height = header.getHeight();
if (height == 0) {
header.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
height = header.getMeasuredHeight();
holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
layoutParams.setFullSpan(true);
holder2.itemView.setLayoutParams(layoutParams);
}
} else {
holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
layoutParams.setFullSpan(true);
holder2.itemView.setLayoutParams(layoutParams);
}
}
}
}
use of me.ccrama.redditslide.Activities.SubredditView in project Slide by ccrama.
the class SubmissionsView method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), new ColorPreferences(inflater.getContext()).getThemeSubreddit(id));
final View v = ((LayoutInflater) contextThemeWrapper.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.fragment_verticalcontent, container, false);
if (getActivity() instanceof MainActivity) {
v.findViewById(R.id.back).setBackgroundResource(0);
}
rv = v.findViewById(R.id.vertical_content);
rv.setHasFixedSize(true);
final RecyclerView.LayoutManager mLayoutManager;
mLayoutManager = createLayoutManager(getNumColumns(getResources().getConfiguration().orientation, getActivity()));
if (!(getActivity() instanceof SubredditView)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
v.findViewById(R.id.back).setBackground(null);
} else {
v.findViewById(R.id.back).setBackgroundDrawable(null);
}
}
rv.setLayoutManager(mLayoutManager);
rv.setItemAnimator(new SlideUpAlphaAnimator());
rv.getLayoutManager().scrollToPosition(0);
mSwipeRefreshLayout = v.findViewById(R.id.activity_main_swipe_refresh_layout);
mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getContext()));
/**
* If using List view mode, we need to remove the start margin from the SwipeRefreshLayout.
* The scrollbar style of "outsideInset" creates a 4dp padding around it. To counter this,
* change the scrollbar style to "insideOverlay" when list view is enabled.
* To recap: this removes the margins from the start/end so list view is full-width.
*/
if (SettingValues.defaultCardView == CreateCardView.CardEnum.LIST) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginStart(0);
} else {
MarginLayoutParamsCompat.setMarginStart(params, 0);
}
rv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mSwipeRefreshLayout.setLayoutParams(params);
}
/**
* If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
* So, we estimate the height of the header in dp.
* If the view type is "single" (and therefore "commentPager"), we need a different offset
*/
final int HEADER_OFFSET = (SettingValues.single || getActivity() instanceof SubredditView) ? Constants.SINGLE_HEADER_VIEW_OFFSET : Constants.TAB_HEADER_VIEW_OFFSET;
mSwipeRefreshLayout.setProgressViewOffset(false, HEADER_OFFSET - Constants.PTR_OFFSET_TOP, HEADER_OFFSET + Constants.PTR_OFFSET_BOTTOM);
if (SettingValues.fab) {
fab = v.findViewById(R.id.post_floating_action_button);
if (SettingValues.fabType == Constants.FAB_POST) {
fab.setImageResource(R.drawable.add);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent inte = new Intent(getActivity(), Submit.class);
inte.putExtra(Submit.EXTRA_SUBREDDIT, id);
getActivity().startActivity(inte);
}
});
} else {
fab.setImageResource(R.drawable.hide);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!Reddit.fabClear) {
new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
Reddit.fabClear = true;
clearSeenPosts(false);
}
}).show();
} else {
clearSeenPosts(false);
}
}
});
final Handler handler = new Handler();
fab.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
detector.onTouchEvent(event);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
origY = event.getY();
handler.postDelayed(mLongPressRunnable, android.view.ViewConfiguration.getLongPressTimeout());
}
if (((event.getAction() == MotionEvent.ACTION_MOVE) && Math.abs(event.getY() - origY) > fab.getHeight() / 2) || (event.getAction() == MotionEvent.ACTION_UP)) {
handler.removeCallbacks(mLongPressRunnable);
}
return false;
}
});
mLongPressRunnable = new Runnable() {
public void run() {
fab.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
if (!Reddit.fabClear) {
new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
Reddit.fabClear = true;
clearSeenPosts(true);
}
}).show();
} else {
clearSeenPosts(true);
}
Snackbar s = Snackbar.make(rv, getResources().getString(R.string.posts_hidden_forever), Snackbar.LENGTH_LONG);
/*Todo a way to unhide
s.setAction(R.string.btn_undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});*/
View view = s.getView();
TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.show();
}
};
}
} else {
v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
}
if (fab != null)
fab.show();
header = getActivity().findViewById(R.id.header);
// TODO, have it so that if the user clicks anywhere in the rv to hide and cancel GoToSubreddit?
// final TextInputEditText GO_TO_SUB_FIELD = (TextInputEditText) getActivity().findViewById(R.id.toolbar_search);
// final Toolbar TOOLBAR = ((Toolbar) getActivity().findViewById(R.id.toolbar));
// final String PREV_TITLE = TOOLBAR.getTitle().toString();
// final ImageView CLOSE_BUTTON = (ImageView) getActivity().findViewById(R.id.close);
//
// rv.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View v, MotionEvent event) {
// System.out.println("touched");
// InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
// imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
//
// GO_TO_SUB_FIELD.setText("");
// GO_TO_SUB_FIELD.setVisibility(View.GONE);
// CLOSE_BUTTON.setVisibility(View.GONE);
// TOOLBAR.setTitle(PREV_TITLE);
//
// return false;
// }
// });
resetScroll();
Reddit.isLoading = false;
if (MainActivity.shouldLoad == null || id == null || (MainActivity.shouldLoad != null && MainActivity.shouldLoad.equals(id)) || !(getActivity() instanceof MainActivity)) {
doAdapter();
}
return v;
}
Aggregations