use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class Inbox method onCreate.
@Override
public void onCreate(Bundle savedInstance) {
overrideSwipeFromAnywhere();
if (Authentication.reddit == null || !Authentication.reddit.isAuthenticated() || Authentication.me == null) {
LogUtil.v("Reauthenticating");
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
if (Authentication.reddit == null) {
new Authentication(getApplicationContext());
}
try {
Authentication.me = Authentication.reddit.me();
Authentication.mod = Authentication.me.isMod();
Authentication.authentication.edit().putBoolean(Reddit.SHARED_PREF_IS_MOD, Authentication.mod).apply();
if (Reddit.notificationTime != -1) {
Reddit.notifications = new NotificationJobScheduler(Inbox.this);
Reddit.notifications.start();
}
if (Reddit.cachedData.contains("toCache")) {
Reddit.autoCache = new AutoCacheScheduler(Inbox.this);
Reddit.autoCache.start();
}
final String name = Authentication.me.getFullName();
Authentication.name = name;
LogUtil.v("AUTHENTICATED");
UserSubscriptions.doCachedModSubs();
if (Authentication.reddit.isAuthenticated()) {
final Set<String> accounts = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
if (accounts.contains(name)) {
// convert to new system
accounts.remove(name);
accounts.add(name + ":" + Authentication.refresh);
Authentication.authentication.edit().putStringSet("accounts", accounts).apply();
}
Authentication.isLoggedIn = true;
Reddit.notFirst = true;
}
} catch (Exception ignored) {
}
return null;
}
}.execute();
}
super.onCreate(savedInstance);
last = SettingValues.prefs.getLong("lastInbox", System.currentTimeMillis() - (60 * 1000 * 60));
SettingValues.prefs.edit().putLong("lastInbox", System.currentTimeMillis()).apply();
applyColorTheme("");
setContentView(R.layout.activity_inbox);
setupAppBar(R.id.toolbar, R.string.title_inbox, true, true);
mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
tabs = (TabLayout) findViewById(R.id.sliding_tabs);
tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
tabs.setSelectedTabIndicatorColor(new ColorPreferences(Inbox.this).getColor("no sub"));
pager = (ViewPager) findViewById(R.id.content_view);
findViewById(R.id.header).setBackgroundColor(Palette.getDefaultColor());
adapter = new InboxPagerAdapter(getSupportFragmentManager());
pager.setAdapter(adapter);
if (getIntent() != null && getIntent().hasExtra(EXTRA_UNREAD)) {
pager.setCurrentItem(1);
}
tabs.setupWithViewPager(pager);
pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
findViewById(R.id.header).animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
if (position == 3 && findViewById(R.id.read) != null) {
findViewById(R.id.read).setVisibility(View.GONE);
} else if (findViewById(R.id.read) != null) {
findViewById(R.id.read).setVisibility(View.VISIBLE);
}
}
});
}
use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class Discover method onCreate.
@Override
public void onCreate(Bundle savedInstance) {
overrideSwipeFromAnywhere();
super.onCreate(savedInstance);
applyColorTheme("");
setContentView(R.layout.activity_multireddits);
((DrawerLayout) findViewById(R.id.drawer_layout)).setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
setupAppBar(R.id.toolbar, R.string.discover_title, true, false);
mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
findViewById(R.id.header).setBackgroundColor(Palette.getDefaultColor());
TabLayout tabs = (TabLayout) findViewById(R.id.sliding_tabs);
tabs.setTabMode(TabLayout.MODE_FIXED);
tabs.setSelectedTabIndicatorColor(new ColorPreferences(Discover.this).getColor("no sub"));
ViewPager pager = (ViewPager) findViewById(R.id.content_view);
pager.setAdapter(new DiscoverPagerAdapter(getSupportFragmentManager()));
tabs.setupWithViewPager(pager);
pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
findViewById(R.id.header).animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
}
});
}
use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class CommentPage method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
v = localInflater.inflate(R.layout.fragment_verticalcontenttoolbar, container, false);
rv = v.findViewById(R.id.vertical_content);
rv.setLayoutManager(mLayoutManager);
rv.getLayoutManager().scrollToPosition(0);
toolbar = v.findViewById(R.id.toolbar);
toolbar.setPopupTheme(new ColorPreferences(getActivity()).getFontStyle().getBaseId());
if (!SettingValues.fabComments || archived || np || locked) {
v.findViewById(R.id.comment_floating_action_button).setVisibility(View.GONE);
} else {
fab = v.findViewById(R.id.comment_floating_action_button);
if (SettingValues.fastscroll) {
FrameLayout.LayoutParams fabs = (FrameLayout.LayoutParams) fab.getLayoutParams();
fabs.setMargins(fabs.leftMargin, fabs.topMargin, fabs.rightMargin, fabs.bottomMargin * 3);
fab.setLayoutParams(fabs);
}
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final MaterialDialog replyDialog = new MaterialDialog.Builder(getActivity()).customView(R.layout.edit_comment, false).cancelable(false).build();
final View replyView = replyDialog.getCustomView();
// Make the account selector visible
replyView.findViewById(R.id.profile).setVisibility(View.VISIBLE);
final EditText e = replyView.findViewById(R.id.entry);
// Tint the replyLine appropriately if the base theme is Light or Sepia
if (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5) {
final int TINT = ContextCompat.getColor(getContext(), R.color.md_grey_600);
e.setHintTextColor(TINT);
BlendModeUtil.tintDrawableAsSrcIn(e.getBackground(), TINT);
}
DoEditorActions.doActions(e, replyView, getActivity().getSupportFragmentManager(), getActivity(), adapter.submission.isSelfPost() ? adapter.submission.getSelftext() : null, new String[] { adapter.submission.getAuthor() });
replyDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
replyView.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
replyDialog.dismiss();
}
});
final TextView profile = replyView.findViewById(R.id.profile);
final String[] changedProfile = { Authentication.name };
profile.setText("/u/" + changedProfile[0]);
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final HashMap<String, String> accounts = new HashMap<>();
for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
if (s.contains(":")) {
accounts.put(s.split(":")[0], s.split(":")[1]);
} else {
accounts.put(s, "");
}
}
final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
final int i = keys.indexOf(changedProfile[0]);
MaterialDialog.Builder builder = new MaterialDialog.Builder(getContext());
builder.title(getString(R.string.replies_switch_accounts));
builder.items(keys.toArray(new String[0]));
builder.itemsCallbackSingleChoice(i, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
changedProfile[0] = keys.get(which);
profile.setText("/u/" + changedProfile[0]);
return true;
}
});
builder.alwaysCallSingleChoiceCallback();
builder.negativeText(R.string.btn_cancel);
builder.show();
}
});
replyView.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapter.dataSet.refreshLayout.setRefreshing(true);
adapter.new ReplyTaskComment(adapter.submission, changedProfile[0]).execute(e.getText().toString());
replyDialog.dismiss();
}
});
replyDialog.show();
}
});
}
if (fab != null)
fab.show();
resetScroll(false);
fastScroll = v.findViewById(R.id.commentnav);
if (!SettingValues.fastscroll) {
fastScroll.setVisibility(View.GONE);
} else {
if (!SettingValues.showCollapseExpand) {
v.findViewById(R.id.collapse_expand).setVisibility(View.GONE);
} else {
v.findViewById(R.id.collapse_expand).setVisibility(View.VISIBLE);
v.findViewById(R.id.collapse_expand).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (adapter != null) {
if (collapsed) {
adapter.expandAll();
} else {
adapter.collapseAll();
}
collapsed = !collapsed;
}
}
});
}
v.findViewById(R.id.down).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (adapter != null && adapter.keys != null && adapter.keys.size() > 0) {
goDown();
}
}
});
v.findViewById(R.id.up).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (adapter != null && adapter.keys != null && adapter.keys.size() > 0)
goUp();
}
});
v.findViewById(R.id.nav).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (adapter != null && adapter.currentComments != null) {
int parentCount = 0;
int opCount = 0;
int linkCount = 0;
int awardCount = 0;
String op = adapter.submission.getAuthor();
for (CommentObject o : adapter.currentComments) {
if (o.comment != null && !(o instanceof MoreChildItem)) {
if (o.comment.isTopLevel())
parentCount++;
if (o.comment.getComment().getTimesGilded() > 0 || o.comment.getComment().getTimesSilvered() > 0 || o.comment.getComment().getTimesPlatinized() > 0)
awardCount++;
if (o.comment.getComment().getAuthor() != null && o.comment.getComment().getAuthor().equals(op)) {
opCount++;
}
if (o.comment.getComment().getDataNode().has("body_html") && o.comment.getComment().getDataNode().get("body_html").asText().contains("</a")) {
linkCount++;
}
}
}
new AlertDialog.Builder(getActivity()).setTitle(R.string.set_nav_mode).setSingleChoiceItems(StringUtil.stringToArray("Parent comment (" + parentCount + ")" + "," + "Children comment (highlight child comment & navigate)" + "," + "OP (" + opCount + ")" + "," + "Time" + "," + "Link (" + linkCount + ")" + "," + ((Authentication.isLoggedIn) ? "You" + "," : "") + "Awarded (" + awardCount + ")").toArray(new String[Authentication.isLoggedIn ? 6 : 5]), getCurrentSort(), (dialog, which) -> {
switch(which) {
case 0:
currentSort = CommentNavType.PARENTS;
break;
case 1:
currentSort = CommentNavType.CHILDREN;
break;
case 2:
currentSort = CommentNavType.OP;
break;
case 3:
currentSort = CommentNavType.TIME;
LayoutInflater inflater1 = getActivity().getLayoutInflater();
final View dialoglayout = inflater1.inflate(R.layout.commenttime, null);
final Slider landscape = dialoglayout.findViewById(R.id.landscape);
final TextView since = dialoglayout.findViewById(R.id.time_string);
landscape.setValueRange(60, 18000, false);
landscape.setOnPositionChangeListener(new Slider.OnPositionChangeListener() {
@Override
public void onPositionChanged(Slider slider, boolean b, float v12, float v1, int i, int i1) {
Calendar c = Calendar.getInstance();
sortTime = c.getTimeInMillis() - i1 * 1000L;
int commentcount = 0;
for (CommentObject o : adapter.currentComments) {
if (o.comment != null && o.comment.getComment().getDataNode().has("created") && o.comment.getComment().getCreated().getTime() > sortTime) {
commentcount += 1;
}
}
since.setText(TimeUtils.getTimeAgo(sortTime, getActivity()) + " (" + commentcount + " comments)");
}
});
landscape.setValue(600, false);
new AlertDialog.Builder(getActivity()).setView(dialoglayout).setPositiveButton(R.string.btn_set, null).show();
break;
case 5:
currentSort = (Authentication.isLoggedIn ? CommentNavType.YOU : // gilded is 5 if not logged in
CommentNavType.GILDED);
break;
case 4:
currentSort = CommentNavType.LINK;
break;
case 6:
currentSort = CommentNavType.GILDED;
break;
}
}).show();
}
}
});
}
v.findViewById(R.id.up).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// Scroll to top
rv.getLayoutManager().scrollToPosition(1);
return true;
}
});
if (SettingValues.voteGestures) {
v.findViewById(R.id.up).setOnTouchListener(new OnFlingGestureListener() {
@Override
public void onRightToLeft() {
}
@Override
public void onLeftToRight() {
}
@Override
public void onBottomToTop() {
adapter.submissionViewHolder.upvote.performClick();
Context context = getContext();
int duration = Toast.LENGTH_SHORT;
CharSequence text;
if (!upvoted) {
text = getString(R.string.profile_upvoted);
downvoted = false;
} else {
text = getString(R.string.vote_removed);
}
upvoted = !upvoted;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
@Override
public void onTopToBottom() {
}
});
}
if (SettingValues.voteGestures) {
v.findViewById(R.id.down).setOnTouchListener(new OnFlingGestureListener() {
@Override
public void onRightToLeft() {
}
@Override
public void onLeftToRight() {
}
@Override
public void onBottomToTop() {
adapter.submissionViewHolder.downvote.performClick();
Context context = getContext();
int duration = Toast.LENGTH_SHORT;
CharSequence text;
if (!downvoted) {
text = getString(R.string.profile_downvoted);
upvoted = false;
} else {
text = getString(R.string.vote_removed);
}
downvoted = !downvoted;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
@Override
public void onTopToBottom() {
}
});
}
toolbar.setBackgroundColor(Palette.getColor(subreddit));
mSwipeRefreshLayout = v.findViewById(R.id.activity_main_swipe_refresh_layout);
mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(subreddit, getActivity()));
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if (comments != null) {
comments.loadMore(adapter, subreddit, true);
} else {
mSwipeRefreshLayout.setRefreshing(false);
}
// TODO catch errors
}
});
toolbar.setTitle(subreddit);
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().onBackPressed();
}
});
toolbar.inflateMenu(R.menu.menu_comment_items);
toolbar.setOnMenuItemClickListener(this);
toolbar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((LinearLayoutManager) rv.getLayoutManager()).scrollToPositionWithOffset(1, headerHeight);
resetScroll(false);
}
});
addClickFunctionSubName(toolbar);
doTopBar();
if (Authentication.didOnline && !NetworkUtil.isConnectedNoOverride(getActivity())) {
new AlertDialog.Builder(getActivity()).setTitle(R.string.err_title).setMessage(R.string.err_connection_failed_msg).setNegativeButton(R.string.btn_close, (dialog, which) -> {
if (!(getActivity() instanceof MainActivity)) {
getActivity().finish();
}
}).setPositiveButton(R.string.btn_offline, (dialog, which) -> {
Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
Reddit.forceRestart(getActivity(), false);
}).show();
}
doAdapter(!(getActivity() instanceof CommentsScreen) || ((CommentsScreen) getActivity()).currentPage == page);
return v;
}
use of me.ccrama.redditslide.Visuals.ColorPreferences 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.from(contextThemeWrapper).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 = createLayoutManager(LayoutUtils.getNumColumns(getResources().getConfiguration().orientation, getActivity()));
if (!(getActivity() instanceof SubredditView)) {
v.findViewById(R.id.back).setBackground(null);
}
rv.setLayoutManager(mLayoutManager);
rv.setItemAnimator(new SlideUpAlphaAnimator().withInterpolator(new LinearOutSlowInInterpolator()));
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);
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.ic_add);
fab.setContentDescription(getString(R.string.btn_fab_post));
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.ic_visibility_off);
fab.setContentDescription(getString(R.string.btn_fab_hide));
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!Reddit.fabClear) {
new AlertDialog.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, (dialog, 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.0f) || (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 AlertDialog.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, (dialog, 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) {
}
});*/
LayoutUtils.showSnackbar(s);
}
};
}
} 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");
// KeyboardUtil.hideKeyboard(getActivity(), 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.Visuals.ColorPreferences 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.from(contextThemeWrapper).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 = createLayoutManager(LayoutUtils.getNumColumns(getResources().getConfiguration().orientation, getActivity()));
if (!(getActivity() instanceof SubredditView)) {
v.findViewById(R.id.back).setBackground(null);
}
rv.setLayoutManager(mLayoutManager);
rv.setItemAnimator(new SlideUpAlphaAnimator().withInterpolator(new LinearOutSlowInInterpolator()));
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);
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.ic_add);
fab.setContentDescription(getString(R.string.btn_fab_post));
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 if (SettingValues.fabType == Constants.FAB_SEARCH) {
fab.setImageResource(R.drawable.ic_search);
fab.setContentDescription(getString(R.string.btn_fab_search));
fab.setOnClickListener(new View.OnClickListener() {
String term;
@Override
public void onClick(View v) {
MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).title(R.string.search_title).alwaysCallInputCallback().input(getString(R.string.search_msg), "", new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
term = charSequence.toString();
}
});
// Add "search current sub" if it is not frontpage/all/random
if (!id.equalsIgnoreCase("frontpage") && !id.equalsIgnoreCase("all") && !id.contains(".") && !id.contains("/m/") && !id.equalsIgnoreCase("friends") && !id.equalsIgnoreCase("random") && !id.equalsIgnoreCase("popular") && !id.equalsIgnoreCase("myrandom") && !id.equalsIgnoreCase("randnsfw")) {
builder.positiveText(getString(R.string.search_subreddit, id)).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(getActivity(), Search.class);
i.putExtra(Search.EXTRA_TERM, term);
i.putExtra(Search.EXTRA_SUBREDDIT, id);
startActivity(i);
}
});
builder.neutralText(R.string.search_all).onNeutral(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(getActivity(), Search.class);
i.putExtra(Search.EXTRA_TERM, term);
startActivity(i);
}
});
} else {
builder.positiveText(R.string.search_all).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(getActivity(), Search.class);
i.putExtra(Search.EXTRA_TERM, term);
startActivity(i);
}
});
}
builder.show();
}
});
} else {
fab.setImageResource(R.drawable.ic_visibility_off);
fab.setContentDescription(getString(R.string.btn_fab_hide));
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!Reddit.fabClear) {
new AlertDialog.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, (dialog, 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.0f) || (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 AlertDialog.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, (dialog, 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) {
}
});*/
LayoutUtils.showSnackbar(s);
}
};
}
} 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");
// KeyboardUtil.hideKeyboard(getActivity(), 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