Search in sources :

Example 21 with CatchStaggeredGridLayoutManager

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

the class SubredditAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int pos) {
    int i = pos != 0 ? pos - 1 : pos;
    if (holder2 instanceof SubredditViewHolder) {
        final SubredditViewHolder holder = (SubredditViewHolder) holder2;
        final Subreddit sub = dataSet.posts.get(i);
        holder.name.setText(sub.getDisplayName());
        holder.color.setBackgroundResource(R.drawable.circle);
        holder.color.getBackground().setColorFilter(Palette.getColor(sub.getDisplayName().toLowerCase(Locale.ENGLISH)), PorterDuff.Mode.MULTIPLY);
        holder.itemView.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(context, SubredditView.class);
                inte.putExtra(SubredditView.EXTRA_SUBREDDIT, sub.getDisplayName());
                context.startActivityForResult(inte, 4);
            }
        });
        holder.overflow.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(context, SubredditView.class);
                inte.putExtra(SubredditView.EXTRA_SUBREDDIT, sub.getDisplayName());
                context.startActivityForResult(inte, 4);
            }
        });
        holder.body.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(context, SubredditView.class);
                inte.putExtra(SubredditView.EXTRA_SUBREDDIT, sub.getDisplayName());
                context.startActivityForResult(inte, 4);
            }
        });
        if (sub.getDataNode().get("public_description_html").asText().equals("null")) {
            holder.body.setVisibility(View.GONE);
            holder.overflow.setVisibility(View.GONE);
        } else {
            holder.body.setVisibility(View.VISIBLE);
            holder.overflow.setVisibility(View.VISIBLE);
            setViews(sub.getDataNode().get("public_description_html").asText().trim(), sub.getDisplayName().toLowerCase(Locale.ENGLISH), holder.body, holder.overflow);
        }
        try {
            int state = sub.isUserSubscriber() ? View.VISIBLE : View.INVISIBLE;
            holder.subbed.setVisibility(state);
        } catch (Exception e) {
            holder.subbed.setVisibility(View.INVISIBLE);
        }
    } else if (holder2 instanceof SubmissionFooterViewHolder) {
        Handler handler = new Handler();
        final Runnable r = new Runnable() {

            public void run() {
                // the loading spinner to replaced by nomoreposts.xml
                notifyItemChanged(dataSet.posts.size() + 1);
            }
        };
        handler.post(r);
        if (holder2.itemView.findViewById(R.id.reload) != null) {
            holder2.itemView.setVisibility(View.INVISIBLE);
        }
    }
    if (holder2 instanceof SpacerViewHolder) {
        final int height = (context).findViewById(R.id.header).getHeight();
        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) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) Handler(android.os.Handler) Intent(android.content.Intent) SubredditView(me.ccrama.redditslide.Activities.SubredditView) SubredditListView(me.ccrama.redditslide.Fragments.SubredditListView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) RecyclerView(android.support.v7.widget.RecyclerView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) View(android.view.View) Subreddit(net.dean.jraw.models.Subreddit) LinearLayout(android.widget.LinearLayout)

Example 22 with CatchStaggeredGridLayoutManager

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

the class SubmissionsView 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, getActivity()));
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager)

Example 23 with CatchStaggeredGridLayoutManager

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

the class Gallery 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));
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager)

Example 24 with CatchStaggeredGridLayoutManager

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

the class Gallery method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();
    subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT);
    String multireddit = getIntent().getExtras().getString(EXTRA_MULTIREDDIT);
    String profile = getIntent().getExtras().getString(EXTRA_PROFILE, "");
    if (multireddit != null) {
        subredditPosts = new MultiredditPosts(multireddit, profile);
    } else {
        subredditPosts = new SubredditPosts(subreddit, Gallery.this);
    }
    subreddit = multireddit == null ? subreddit : ("multi" + multireddit);
    if (multireddit == null) {
        setShareUrl("https://reddit.com/r/" + subreddit);
    }
    applyDarkColorTheme(subreddit);
    super.onCreate(savedInstance);
    setContentView(R.layout.gallery);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE);
    long offline = getIntent().getLongExtra("offline", 0L);
    final OfflineSubreddit submissions = OfflineSubreddit.getSubreddit(subreddit, offline, !Authentication.didOnline, this);
    baseSubs = new ArrayList<>();
    for (Submission s : submissions.submissions) {
        if (s.getThumbnails() != null && s.getThumbnails().getSource() != null) {
            baseSubs.add(s);
        } else if (ContentType.getContentType(s) == ContentType.Type.IMAGE) {
            baseSubs.add(s);
        }
        subredditPosts.getPosts().add(s);
    }
    rv = (RecyclerView) findViewById(R.id.content_view);
    recyclerAdapter = new GalleryView(this, baseSubs, subreddit);
    RecyclerView.LayoutManager layoutManager = createLayoutManager(getNumColumns(getResources().getConfiguration().orientation));
    rv.setLayoutManager(layoutManager);
    rv.setAdapter(recyclerAdapter);
    rv.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            int[] firstVisibleItems;
            firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(null);
            if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                for (int firstVisibleItem : firstVisibleItems) {
                    pastVisiblesItems = firstVisibleItem;
                }
            }
            if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
                if (subredditPosts instanceof SubredditPosts) {
                    if (!((SubredditPosts) subredditPosts).loading) {
                        ((SubredditPosts) subredditPosts).loading = true;
                        ((SubredditPosts) subredditPosts).loadMore(Gallery.this, Gallery.this, false, subreddit);
                    }
                } else if (subredditPosts instanceof MultiredditPosts) {
                    if (!((MultiredditPosts) subredditPosts).loading) {
                        ((MultiredditPosts) subredditPosts).loading = true;
                        (subredditPosts).loadMore(Gallery.this, Gallery.this, false);
                    }
                }
            }
        }
    });
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) Submission(net.dean.jraw.models.Submission) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) MultiredditPosts(me.ccrama.redditslide.Adapters.MultiredditPosts) GalleryView(me.ccrama.redditslide.Adapters.GalleryView) RecyclerView(android.support.v7.widget.RecyclerView) SubredditPosts(me.ccrama.redditslide.Adapters.SubredditPosts)

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