Search in sources :

Example 1 with SubredditPosts

use of me.ccrama.redditslide.Adapters.SubredditPosts in project Slide by ccrama.

the class Shadowbox method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();
    subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT);
    firstPage = getIntent().getExtras().getInt(EXTRA_PAGE, 0);
    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, Shadowbox.this);
    }
    subreddit = multireddit == null ? subreddit : ("multi" + multireddit);
    if (multireddit == null) {
        setShareUrl("https://reddit.com/r/" + subreddit);
    }
    applyDarkColorTheme(subreddit);
    super.onCreate(savedInstance);
    setContentView(R.layout.activity_slide);
    long offline = getIntent().getLongExtra("offline", 0L);
    OfflineSubreddit submissions = OfflineSubreddit.getSubreddit(subreddit, offline, !Authentication.didOnline, this);
    subredditPosts.getPosts().addAll(submissions.submissions);
    pager = (ViewPager) findViewById(R.id.content_view);
    submissionsPager = new OverviewPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(submissionsPager);
    pager.setCurrentItem(firstPage);
    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            if (SettingValues.storeHistory) {
                if (subredditPosts.getPosts().get(position).isNsfw() && !SettingValues.storeNSFWHistory) {
                } else
                    HasSeen.addSeen(subredditPosts.getPosts().get(position).getFullName());
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
}
Also used : OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) SubredditPosts(me.ccrama.redditslide.Adapters.SubredditPosts) ViewPager(android.support.v4.view.ViewPager) MultiredditPosts(me.ccrama.redditslide.Adapters.MultiredditPosts)

Example 2 with SubredditPosts

use of me.ccrama.redditslide.Adapters.SubredditPosts in project Slide by ccrama.

the class SubmissionsView method doAdapter.

public void doAdapter(boolean force18) {
    mSwipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new SubredditPosts(id, getContext(), force18);
    adapter = new SubmissionAdapter(getActivity(), posts, rv, id, this);
    adapter.setHasStableIds(true);
    rv.setAdapter(adapter);
    posts.loadMore(getActivity(), this, true);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refresh();
        }
    });
}
Also used : SubmissionAdapter(me.ccrama.redditslide.Adapters.SubmissionAdapter) SubredditPosts(me.ccrama.redditslide.Adapters.SubredditPosts) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 3 with SubredditPosts

use of me.ccrama.redditslide.Adapters.SubredditPosts in project Slide by ccrama.

the class MainActivity method doPageSelectedComments.

public void doPageSelectedComments(int position) {
    pager.setSwipeLeftOnly(false);
    header.animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
    Reddit.currentPosition = position;
    if (position + 1 != currentComment) {
        doSubSidebarNoLoad(usedArray.get(position));
    }
    SubmissionsView page = (SubmissionsView) adapter.getCurrentFragment();
    if (page != null && page.adapter != null) {
        SubredditPosts p = page.adapter.dataSet;
        if (p.offline && p.cached != null) {
            Toast.makeText(MainActivity.this, getString(R.string.offline_last_update, TimeUtils.getTimeAgo(p.cached.time, MainActivity.this)), Toast.LENGTH_LONG).show();
        }
    }
    if (hea != null) {
        hea.setBackgroundColor(Palette.getColor(usedArray.get(position)));
        if (accountsArea != null) {
            accountsArea.setBackgroundColor(Palette.getDarkerColor(usedArray.get(position)));
        }
    }
    header.setBackgroundColor(Palette.getColor(usedArray.get(position)));
    themeSystemBars(usedArray.get(position));
    setRecentBar(usedArray.get(position));
    if (SettingValues.single) {
        getSupportActionBar().setTitle(usedArray.get(position));
    } else {
        if (mTabLayout != null) {
            mTabLayout.setSelectedTabIndicatorColor(new ColorPreferences(MainActivity.this).getColor(usedArray.get(position)));
        }
    }
    selectedSub = usedArray.get(position);
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) LinearInterpolator(android.view.animation.LinearInterpolator) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) SubredditPosts(me.ccrama.redditslide.Adapters.SubredditPosts)

Example 4 with SubredditPosts

use of me.ccrama.redditslide.Adapters.SubredditPosts in project Slide by ccrama.

the class SubmissionsView method doAdapter.

public void doAdapter() {
    if (!MainActivity.isRestart) {
        mSwipeRefreshLayout.post(new Runnable() {

            @Override
            public void run() {
                mSwipeRefreshLayout.setRefreshing(true);
            }
        });
    }
    posts = new SubredditPosts(id, getContext());
    adapter = new SubmissionAdapter(getActivity(), posts, rv, id, this);
    adapter.setHasStableIds(true);
    rv.setAdapter(adapter);
    posts.loadMore(getActivity(), this, true);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refresh();
        }
    });
}
Also used : SubmissionAdapter(me.ccrama.redditslide.Adapters.SubmissionAdapter) SubredditPosts(me.ccrama.redditslide.Adapters.SubredditPosts) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 5 with SubredditPosts

use of me.ccrama.redditslide.Adapters.SubredditPosts 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

SubredditPosts (me.ccrama.redditslide.Adapters.SubredditPosts)6 MultiredditPosts (me.ccrama.redditslide.Adapters.MultiredditPosts)3 OfflineSubreddit (me.ccrama.redditslide.OfflineSubreddit)3 ViewPager (android.support.v4.view.ViewPager)2 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)2 SubmissionAdapter (me.ccrama.redditslide.Adapters.SubmissionAdapter)2 Intent (android.content.Intent)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Bundle (android.os.Bundle)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LinearInterpolator (android.view.animation.LinearInterpolator)1 GalleryView (me.ccrama.redditslide.Adapters.GalleryView)1 ColorPreferences (me.ccrama.redditslide.ColorPreferences)1 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)1 CatchStaggeredGridLayoutManager (me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager)1 Submission (net.dean.jraw.models.Submission)1