Search in sources :

Example 31 with Submission

use of net.dean.jraw.models.Submission in project Slide by ccrama.

the class SubmissionsView method clearSeenPosts.

public List<Submission> clearSeenPosts(boolean forever) {
    if (adapter.dataSet.posts != null) {
        List<Submission> originalDataSetPosts = adapter.dataSet.posts;
        OfflineSubreddit o = OfflineSubreddit.getSubreddit(id.toLowerCase(Locale.ENGLISH), false, getActivity());
        for (int i = adapter.dataSet.posts.size(); i > -1; i--) {
            try {
                if (HasSeen.getSeen(adapter.dataSet.posts.get(i))) {
                    if (forever) {
                        Hidden.setHidden(adapter.dataSet.posts.get(i));
                    }
                    o.clearPost(adapter.dataSet.posts.get(i));
                    adapter.dataSet.posts.remove(i);
                    if (adapter.dataSet.posts.isEmpty()) {
                        adapter.notifyDataSetChanged();
                    } else {
                        rv.setItemAnimator(new AlphaInAnimator());
                        adapter.notifyItemRemoved(i + 1);
                    }
                }
            } catch (IndexOutOfBoundsException e) {
            // Let the loop reset itself
            }
        }
        adapter.notifyItemRangeChanged(0, adapter.dataSet.posts.size());
        o.writeToMemoryNoStorage();
        rv.setItemAnimator(new SlideUpAlphaAnimator());
        return originalDataSetPosts;
    }
    return null;
}
Also used : AlphaInAnimator(com.mikepenz.itemanimators.AlphaInAnimator) Submission(net.dean.jraw.models.Submission) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) SlideUpAlphaAnimator(com.mikepenz.itemanimators.SlideUpAlphaAnimator)

Example 32 with Submission

use of net.dean.jraw.models.Submission 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

Submission (net.dean.jraw.models.Submission)32 Intent (android.content.Intent)15 View (android.view.View)14 DialogInterface (android.content.DialogInterface)10 Snackbar (android.support.design.widget.Snackbar)10 TextView (android.widget.TextView)10 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)10 ArrayList (java.util.ArrayList)10 RecyclerView (android.support.v7.widget.RecyclerView)9 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)9 ImageView (android.widget.ImageView)8 SubredditView (me.ccrama.redditslide.Activities.SubredditView)8 OfflineSubreddit (me.ccrama.redditslide.OfflineSubreddit)8 CreateCardView (me.ccrama.redditslide.Views.CreateCardView)7 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)6 TypedArray (android.content.res.TypedArray)5 LinearLayout (android.widget.LinearLayout)5 DialogAction (com.afollestad.materialdialogs.DialogAction)5 BottomSheet (com.cocosw.bottomsheet.BottomSheet)5 CommentsScreen (me.ccrama.redditslide.Activities.CommentsScreen)5