Search in sources :

Example 1 with CatchStaggeredGridLayoutManager

use of me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager in project Slide by ccrama.

the class NewsActivity method getCurrentPage.

public int getCurrentPage() {
    int position = 0;
    int currentOrientation = getResources().getConfiguration().orientation;
    if (adapter.getCurrentFragment() == null) {
        return 0;
    }
    if (((NewsView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof LinearLayoutManager && currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
        position = ((LinearLayoutManager) ((NewsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPosition() - 1;
    } else if (((NewsView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
        int[] firstVisibleItems = null;
        firstVisibleItems = ((CatchStaggeredGridLayoutManager) ((NewsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPositions(firstVisibleItems);
        if (firstVisibleItems != null && firstVisibleItems.length > 0) {
            position = firstVisibleItems[0] - 1;
        }
    } else {
        position = ((PreCachingLayoutManager) ((NewsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPosition() - 1;
    }
    return position;
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) NewsView(me.ccrama.redditslide.Fragments.NewsView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Point(android.graphics.Point)

Example 2 with CatchStaggeredGridLayoutManager

use of me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager in project Slide by ccrama.

the class Related method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstanceState);
    applyColorTheme("");
    setContentView(R.layout.activity_search);
    Intent intent = getIntent();
    if (intent.hasExtra(Intent.EXTRA_TEXT) && !intent.getExtras().getString(Intent.EXTRA_TEXT, "").isEmpty()) {
        url = intent.getStringExtra(Intent.EXTRA_TEXT);
    }
    if (intent.hasExtra(EXTRA_URL)) {
        url = intent.getStringExtra(EXTRA_URL);
    }
    if (url == null || url.isEmpty()) {
        new AlertDialogWrapper.Builder(this).setTitle("URL is empty").setMessage("Try again with a different link!").setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                finish();
            }
        }).show();
    } else {
    }
    setupAppBar(R.id.toolbar, "Related links", true, true);
    // it won't be, trust me
    assert mToolbar != null;
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    final RecyclerView rv = ((RecyclerView) findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(this);
    rv.setLayoutManager(mLayoutManager);
    rv.addOnScrollListener(new ToolbarScrollHideHandler(mToolbar, findViewById(R.id.header)) {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();
            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
                pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
                int[] firstVisibleItems = null;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisiblesItems = firstVisibleItems[0];
                }
            }
            if (!posts.loading && (visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
                posts.loading = true;
                posts.loadMore(adapter, "", "url:" + url, false);
            }
        }
    });
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("", this));
    // If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    // So, we estimate the height of the header in dp.
    mSwipeRefreshLayout.setProgressViewOffset(false, Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.SINGLE_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    mSwipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new SubredditSearchPosts("", "url:" + url, this);
    adapter = new ContributionAdapter(this, posts, rv);
    rv.setAdapter(adapter);
    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    // TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            posts.loadMore(adapter, "", "url:" + url, true);
        // TODO catch errors
        }
    });
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) ColorPreferences(me.ccrama.redditslide.ColorPreferences) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) SubredditSearchPosts(me.ccrama.redditslide.Adapters.SubredditSearchPosts) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) ContributionAdapter(me.ccrama.redditslide.Adapters.ContributionAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Example 3 with CatchStaggeredGridLayoutManager

use of me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager in project Slide by ccrama.

the class Search method onConfigurationChanged.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    final int currentOrientation = newConfig.orientation;
    final CatchStaggeredGridLayoutManager mLayoutManager = (CatchStaggeredGridLayoutManager) rv.getLayoutManager();
    mLayoutManager.setSpanCount(getNumColumns(currentOrientation, Search.this));
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager)

Example 4 with CatchStaggeredGridLayoutManager

use of me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager in project Slide by ccrama.

the class SubredditView method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    overrideSwipeFromAnywhere();
    if (SettingValues.commentPager && SettingValues.single) {
        disableSwipeBackLayout();
    }
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    getWindow().getDecorView().setBackgroundDrawable(null);
    super.onCreate(savedInstanceState);
    if (!restarting) {
        overridePendingTransition(R.anim.slideright, 0);
    } else {
        restarting = false;
    }
    subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT, "");
    applyColorTheme(subreddit);
    setContentView(R.layout.activity_singlesubreddit);
    setupSubredditAppBar(R.id.toolbar, subreddit, true, subreddit);
    header = findViewById(R.id.header);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    setResult(3);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    pager = (ToggleSwipeViewPager) findViewById(R.id.content_view);
    singleMode = SettingValues.single;
    commentPager = false;
    if (singleMode)
        commentPager = SettingValues.commentPager;
    if (commentPager) {
        adapter = new OverviewPagerAdapterComment(getSupportFragmentManager());
        pager.setSwipeLeftOnly(false);
        pager.setSwipingEnabled(true);
    } else {
        adapter = new OverviewPagerAdapter(getSupportFragmentManager());
    }
    pager.setAdapter(adapter);
    pager.setCurrentItem(1);
    mToolbar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int[] firstVisibleItems;
            int pastVisiblesItems = 0;
            firstVisibleItems = ((CatchStaggeredGridLayoutManager) ((SubmissionsView) (adapter.getCurrentFragment())).rv.getLayoutManager()).findFirstVisibleItemPositions(null);
            if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                for (int firstVisibleItem : firstVisibleItems) {
                    pastVisiblesItems = firstVisibleItem;
                }
            }
            if (pastVisiblesItems > 8) {
                ((SubmissionsView) (adapter.getCurrentFragment())).rv.scrollToPosition(0);
                header.animate().translationY(header.getHeight()).setInterpolator(new LinearInterpolator()).setDuration(180);
            } else {
                ((SubmissionsView) (adapter.getCurrentFragment())).rv.smoothScrollToPosition(0);
            }
            ((SubmissionsView) (adapter.getCurrentFragment())).resetScroll();
        }
    });
    if (!subreddit.equals("random") && !subreddit.equals("all") && !subreddit.equals("frontpage") && !subreddit.equals("friends") && !subreddit.equals("mod") && !subreddit.equals("myrandom") && !subreddit.equals("randnsfw") && !subreddit.equals("popular") && !subreddit.contains("+")) {
        executeAsyncSubreddit(subreddit);
    } else {
        drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END);
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorPreferences(me.ccrama.redditslide.ColorPreferences) LinearInterpolator(android.view.animation.LinearInterpolator) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) View(android.view.View) TextView(android.widget.TextView)

Example 5 with CatchStaggeredGridLayoutManager

use of me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager in project Slide by ccrama.

the class SubmissionAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int pos) {
    int i = pos != 0 ? pos - 1 : pos;
    if (holder2 instanceof SubmissionViewHolder) {
        final SubmissionViewHolder holder = (SubmissionViewHolder) 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);
                    holder.body.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 = view.findViewById(android.support.design.R.id.snackbar_text);
                        tv.setTextColor(Color.WHITE);
                        s.show();
                    }
                }
            }
        });
        new PopulateSubmissionViewHolder().populateSubmissionViewHolder(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) {
                    ((SubmissionsView) displayer).forceRefresh();
                }
            });
        }
    }
    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);
            }
        }
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) DialogInterface(android.content.DialogInterface) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TextView(android.widget.TextView) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) Submission(net.dean.jraw.models.Submission) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Handler(android.os.Handler) Intent(android.content.Intent) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) LinearLayout(android.widget.LinearLayout) Snackbar(android.support.design.widget.Snackbar)

Aggregations

CatchStaggeredGridLayoutManager (me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager)24 RecyclerView (android.support.v7.widget.RecyclerView)15 View (android.view.View)13 ToolbarScrollHideHandler (me.ccrama.redditslide.handler.ToolbarScrollHideHandler)9 Intent (android.content.Intent)7 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)7 TextView (android.widget.TextView)7 PreCachingLayoutManager (me.ccrama.redditslide.Views.PreCachingLayoutManager)6 DialogInterface (android.content.DialogInterface)5 Snackbar (android.support.design.widget.Snackbar)5 Toolbar (android.support.v7.widget.Toolbar)5 LinearLayout (android.widget.LinearLayout)5 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)5 ContributionAdapter (me.ccrama.redditslide.Adapters.ContributionAdapter)5 CreateCardView (me.ccrama.redditslide.Views.CreateCardView)5 Submission (net.dean.jraw.models.Submission)5 Handler (android.os.Handler)4 MainActivity (me.ccrama.redditslide.Activities.MainActivity)4 SubredditView (me.ccrama.redditslide.Activities.SubredditView)4 ColorPreferences (me.ccrama.redditslide.ColorPreferences)4