Search in sources :

Example 11 with OfflineSubreddit

use of me.ccrama.redditslide.OfflineSubreddit 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)

Example 12 with OfflineSubreddit

use of me.ccrama.redditslide.OfflineSubreddit in project Slide by ccrama.

the class CommentsScreen method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    popup = SettingValues.tabletUI && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && !SettingValues.fullCommentOverride;
    seen = new ArrayList<>();
    if (popup) {
        disableSwipeBackLayout();
        applyColorTheme();
        setTheme(R.style.popup);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        super.onCreate(savedInstance);
        setContentView(R.layout.activity_slide_popup);
    } else {
        overrideSwipeFromAnywhere();
        applyColorTheme();
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().getDecorView().setBackgroundDrawable(null);
        super.onCreate(savedInstance);
        setContentView(R.layout.activity_slide);
    }
    Reddit.setDefaultErrorHandler(this);
    firstPage = getIntent().getExtras().getInt(EXTRA_PAGE, -1);
    baseSubreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT);
    subreddit = baseSubreddit;
    multireddit = getIntent().getExtras().getString(EXTRA_MULTIREDDIT);
    profile = getIntent().getExtras().getString(EXTRA_PROFILE, "");
    currentPosts = new ArrayList<>();
    if (multireddit != null) {
        subredditPosts = new MultiredditPosts(multireddit, profile);
    } else {
        baseSubreddit = subreddit.toLowerCase(Locale.ENGLISH);
        subredditPosts = new SubredditPosts(baseSubreddit, CommentsScreen.this);
    }
    if (firstPage == RecyclerView.NO_POSITION || firstPage < 0) {
        firstPage = 0;
    // IS SINGLE POST
    } else {
        OfflineSubreddit o = OfflineSubreddit.getSubreddit(multireddit == null ? baseSubreddit : "multi" + multireddit, OfflineSubreddit.currentid, !Authentication.didOnline, CommentsScreen.this);
        subredditPosts.getPosts().addAll(o.submissions);
        currentPosts.addAll(subredditPosts.getPosts());
    }
    if (getIntent().hasExtra("fullname")) {
        String fullname = getIntent().getStringExtra("fullname");
        for (int i = 0; i < currentPosts.size(); i++) {
            if (currentPosts.get(i).getFullName().equals(fullname)) {
                if (i != firstPage)
                    firstPage = i;
                break;
            }
        }
    }
    if (currentPosts.isEmpty() || currentPosts.size() < firstPage || currentPosts.get(firstPage) == null || firstPage < 0) {
        finish();
    } else {
        updateSubredditAndSubmission(currentPosts.get(firstPage));
        final ViewPager pager = (ViewPager) findViewById(R.id.content_view);
        comments = new OverviewPagerAdapter(getSupportFragmentManager());
        pager.setAdapter(comments);
        currentPage = firstPage;
        pager.setCurrentItem(firstPage + 1);
        pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                if (position <= firstPage && positionOffsetPixels == 0) {
                    finish();
                }
                if (position == firstPage && !popup) {
                    if (((OverviewPagerAdapter) pager.getAdapter()).blankPage != null) {
                        ((OverviewPagerAdapter) pager.getAdapter()).blankPage.doOffset(positionOffset);
                    }
                    pager.setBackgroundColor(adjustAlpha(positionOffset * 0.7f));
                }
            }

            @Override
            public void onPageSelected(int position) {
                if (position != firstPage && position < currentPosts.size()) {
                    position = position - 1;
                    if (position < 0)
                        position = 0;
                    updateSubredditAndSubmission(currentPosts.get(position));
                    if (currentPosts.size() - 2 <= position && subredditPosts.hasMore()) {
                        subredditPosts.loadMore(CommentsScreen.this.getApplicationContext(), CommentsScreen.this, false);
                    }
                    currentPage = position;
                    seen.add(position);
                    Bundle conData = new Bundle();
                    conData.putIntegerArrayList("seen", seen);
                    conData.putInt("lastPage", position);
                    Intent intent = new Intent();
                    intent.putExtras(conData);
                    setResult(RESULT_OK, intent);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
    }
    if (!Reddit.appRestart.contains("tutorialSwipeComments")) {
        Intent i = new Intent(this, SwipeTutorial.class);
        i.putExtra("subtitle", "Swipe from the left edge to exit comments.\n\nYou can swipe in the middle to get to the previous/next submission.");
        startActivityForResult(i, 333);
    }
}
Also used : Bundle(android.os.Bundle) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) Intent(android.content.Intent) ViewPager(android.support.v4.view.ViewPager) MultiredditPosts(me.ccrama.redditslide.Adapters.MultiredditPosts) ColorDrawable(android.graphics.drawable.ColorDrawable) SubredditPosts(me.ccrama.redditslide.Adapters.SubredditPosts)

Aggregations

OfflineSubreddit (me.ccrama.redditslide.OfflineSubreddit)12 Submission (net.dean.jraw.models.Submission)8 RecyclerView (android.support.v7.widget.RecyclerView)5 AsyncTask (android.os.AsyncTask)4 Snackbar (android.support.design.widget.Snackbar)4 View (android.view.View)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 ArrayList (java.util.ArrayList)4 MediaView (me.ccrama.redditslide.Activities.MediaView)4 SubredditView (me.ccrama.redditslide.Activities.SubredditView)4 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)4 CreateCardView (me.ccrama.redditslide.Views.CreateCardView)4 ApiException (net.dean.jraw.ApiException)4 Intent (android.content.Intent)3 AlphaInAnimator (com.mikepenz.itemanimators.AlphaInAnimator)3 SlideUpAlphaAnimator (com.mikepenz.itemanimators.SlideUpAlphaAnimator)3 MultiredditPosts (me.ccrama.redditslide.Adapters.MultiredditPosts)3 SubredditPosts (me.ccrama.redditslide.Adapters.SubredditPosts)3 ClipData (android.content.ClipData)2