Search in sources :

Example 1 with MultiredditPosts

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

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

the class MultiredditView method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);
    rv = v.findViewById(R.id.vertical_content);
    final RecyclerView.LayoutManager mLayoutManager = createLayoutManager(getNumColumns(getResources().getConfiguration().orientation));
    rv.setLayoutManager(mLayoutManager);
    if (SettingValues.fab) {
        fab = v.findViewById(R.id.post_floating_action_button);
        if (SettingValues.fabType == Constants.FAB_POST) {
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    final ArrayList<String> subs = new ArrayList<>();
                    for (MultiSubreddit s : posts.multiReddit.getSubreddits()) {
                        subs.add(s.getDisplayName());
                    }
                    new MaterialDialog.Builder(getActivity()).title(R.string.multi_submit_which_sub).items(subs).itemsCallback(new MaterialDialog.ListCallback() {

                        @Override
                        public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                            Intent i = new Intent(getActivity(), Submit.class);
                            i.putExtra(Submit.EXTRA_SUBREDDIT, subs.get(which));
                            startActivity(i);
                        }
                    }).show();
                }
            });
        } else {
            fab.setImageResource(R.drawable.hide);
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (!Reddit.fabClear) {
                        new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
                                Reddit.fabClear = true;
                                clearSeenPosts(false);
                            }
                        }).show();
                    } else {
                        clearSeenPosts(false);
                    }
                }
            });
            fab.setOnLongClickListener(new View.OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    if (!Reddit.fabClear) {
                        new AlertDialogWrapper.Builder(getActivity()).setTitle(R.string.settings_fabclear).setMessage(R.string.settings_fabclear_msg).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Reddit.colors.edit().putBoolean(SettingValues.PREF_FAB_CLEAR, true).apply();
                                Reddit.fabClear = true;
                                clearSeenPosts(true);
                            }
                        }).show();
                    } else {
                        clearSeenPosts(true);
                    }
                    /*
                        ToDo Make a sncakbar with an undo option of the clear all
                        View.OnClickListener undoAction = new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                adapter.dataSet.posts = original;
                                for(Submission post : adapter.dataSet.posts){
                                    if(HasSeen.getSeen(post.getFullName()))
                                        Hidden.undoHidden(post);
                                }
                            }
                        };*/
                    Snackbar s = Snackbar.make(rv, getResources().getString(R.string.posts_hidden_forever), Snackbar.LENGTH_LONG);
                    View view = s.getView();
                    TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                    tv.setTextColor(Color.WHITE);
                    s.show();
                    return false;
                }
            });
        }
    } else {
        v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    }
    refreshLayout = v.findViewById(R.id.activity_main_swipe_refresh_layout);
    /**
     * If using List view mode, we need to remove the start margin from the SwipeRefreshLayout.
     * The scrollbar style of "outsideInset" creates a 4dp padding around it. To counter this,
     * change the scrollbar style to "insideOverlay" when list view is enabled.
     * To recap: this removes the margins from the start/end so list view is full-width.
     */
    if (SettingValues.defaultCardView == CreateCardView.CardEnum.LIST) {
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            params.setMarginStart(0);
        }
        rv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        refreshLayout.setLayoutParams(params);
    }
    List<MultiReddit> multireddits;
    if (profile.isEmpty()) {
        multireddits = UserSubscriptions.multireddits;
    } else {
        multireddits = UserSubscriptions.public_multireddits.get(profile);
    }
    if ((multireddits != null) && !multireddits.isEmpty()) {
        refreshLayout.setColorSchemeColors(Palette.getColors(multireddits.get(id).getDisplayName(), getActivity()));
    }
    // If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    // So, we estimate the height of the header in dp
    refreshLayout.setProgressViewOffset(false, Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    refreshLayout.post(new Runnable() {

        @Override
        public void run() {
            refreshLayout.setRefreshing(true);
        }
    });
    if ((multireddits != null) && !multireddits.isEmpty()) {
        posts = new MultiredditPosts(multireddits.get(id).getDisplayName(), profile);
        adapter = new MultiredditAdapter(getActivity(), posts, rv, refreshLayout, this);
        rv.setAdapter(adapter);
        rv.setItemAnimator(new SlideUpAlphaAnimator());
        posts.loadMore(getActivity(), this, true, adapter);
        refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

            @Override
            public void onRefresh() {
                posts.loadMore(getActivity(), MultiredditView.this, true, adapter);
            // TODO catch errors
            }
        });
        if (fab != null) {
            fab.show();
        }
        rv.addOnScrollListener(new ToolbarScrollHideHandler((Toolbar) (getActivity()).findViewById(R.id.toolbar), getActivity().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();
                int[] firstVisibleItems;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(null);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    for (int firstVisibleItem : firstVisibleItems) {
                        pastVisiblesItems = firstVisibleItem;
                        if (SettingValues.scrollSeen && pastVisiblesItems > 0 && SettingValues.storeHistory) {
                            HasSeen.addSeenScrolling(posts.posts.get(pastVisiblesItems - 1).getFullName());
                        }
                    }
                }
                if (!posts.loading) {
                    if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) {
                        posts.loading = true;
                        posts.loadMore(getActivity(), MultiredditView.this, false, adapter);
                    }
                }
                if (recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) {
                    diff += dy;
                } else {
                    diff = 0;
                }
                if (fab != null) {
                    if (dy <= 0 && fab.getId() != 0 && SettingValues.fab) {
                        if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_DRAGGING || diff < -fab.getHeight() * 2)
                            fab.show();
                    } else {
                        fab.hide();
                    }
                }
            }
        });
    }
    return v;
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) MultiReddit(net.dean.jraw.models.MultiReddit) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SlideUpAlphaAnimator(com.mikepenz.itemanimators.SlideUpAlphaAnimator) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TextView(android.widget.TextView) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) Toolbar(android.support.v7.widget.Toolbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Intent(android.content.Intent) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) MultiredditPosts(me.ccrama.redditslide.Adapters.MultiredditPosts) RelativeLayout(android.widget.RelativeLayout) Submit(me.ccrama.redditslide.Activities.Submit) RecyclerView(android.support.v7.widget.RecyclerView) MultiredditAdapter(me.ccrama.redditslide.Adapters.MultiredditAdapter) Snackbar(android.support.design.widget.Snackbar)

Example 3 with MultiredditPosts

use of me.ccrama.redditslide.Adapters.MultiredditPosts 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 4 with MultiredditPosts

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

MultiredditPosts (me.ccrama.redditslide.Adapters.MultiredditPosts)4 SubredditPosts (me.ccrama.redditslide.Adapters.SubredditPosts)3 OfflineSubreddit (me.ccrama.redditslide.OfflineSubreddit)3 Intent (android.content.Intent)2 ViewPager (android.support.v4.view.ViewPager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 CatchStaggeredGridLayoutManager (me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager)2 DialogInterface (android.content.DialogInterface)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Bundle (android.os.Bundle)1 Snackbar (android.support.design.widget.Snackbar)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 SlideUpAlphaAnimator (com.mikepenz.itemanimators.SlideUpAlphaAnimator)1 ArrayList (java.util.ArrayList)1