Search in sources :

Example 1 with OfflineSubreddit

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

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

the class SubredditPosts method doMainActivityOffline.

public void doMainActivityOffline(final Context c, final SubmissionDisplay displayer) {
    LogUtil.v(subreddit);
    if (all == null) {
        all = OfflineSubreddit.getAll(subreddit);
    }
    // Move 0, or "submission only", to the end
    Collections.rotate(all, -1);
    offline = true;
    final String[] titles = new String[all.size()];
    final String[] base = new String[all.size()];
    int i = 0;
    for (String s : all) {
        String[] split = s.split(",");
        titles[i] = (Long.valueOf(split[1]) == 0 ? c.getString(R.string.settings_backup_submission_only) : TimeUtils.getTimeAgo(Long.valueOf(split[1]), c) + c.getString(R.string.settings_backup_comments));
        base[i] = s;
        i++;
    }
    ((MainActivity) c).getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    ((MainActivity) c).getSupportActionBar().setListNavigationCallbacks(new OfflineSubAdapter(c, android.R.layout.simple_list_item_1, titles), new ActionBar.OnNavigationListener() {

        @Override
        public boolean onNavigationItemSelected(int itemPosition, long itemId) {
            final String[] s2 = base[itemPosition].split(",");
            OfflineSubreddit.currentid = Long.valueOf(s2[1]);
            currentid = OfflineSubreddit.currentid;
            new AsyncTask<Void, Void, Void>() {

                OfflineSubreddit cached;

                @Override
                protected Void doInBackground(Void... params) {
                    cached = OfflineSubreddit.getSubreddit(subreddit, Long.valueOf(s2[1]), true, c);
                    List<Submission> finalSubs = new ArrayList<>();
                    for (Submission s : cached.submissions) {
                        if (!PostMatch.doesMatch(s, subreddit, force18)) {
                            finalSubs.add(s);
                        }
                    }
                    posts = finalSubs;
                    return null;
                }

                @Override
                protected void onPostExecute(Void aVoid) {
                    if (cached.submissions.isEmpty()) {
                        displayer.updateOfflineError();
                    }
                    // update offline
                    displayer.updateOffline(posts, Long.valueOf(s2[1]));
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            return true;
        }
    });
}
Also used : Submission(net.dean.jraw.models.Submission) AsyncTask(android.os.AsyncTask) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) ArrayList(java.util.ArrayList) ActionBar(android.support.v7.app.ActionBar)

Example 3 with OfflineSubreddit

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

the class MultiredditView method clearSeenPosts.

private List<Submission> clearSeenPosts(boolean forever) {
    if (posts.posts != null) {
        List<Submission> originalDataSetPosts = posts.posts;
        OfflineSubreddit o = OfflineSubreddit.getSubreddit("multi" + posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), false, getActivity());
        for (int i = posts.posts.size(); i > -1; i--) {
            try {
                if (HasSeen.getSeen(posts.posts.get(i))) {
                    if (forever) {
                        Hidden.setHidden(posts.posts.get(i));
                    }
                    o.clearPost(posts.posts.get(i));
                    posts.posts.remove(i);
                    if (posts.posts.isEmpty()) {
                        adapter.notifyDataSetChanged();
                    } else {
                        rv.setItemAnimator(new AlphaInAnimator());
                        adapter.notifyItemRemoved(i + 1);
                    }
                }
            } catch (IndexOutOfBoundsException e) {
            // Let the loop reset itself
            }
        }
        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 4 with OfflineSubreddit

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

the class PopulateNewsViewHolder method hideSubmission.

public <T extends Contribution> void hideSubmission(final Submission submission, final List<T> posts, final String baseSub, final RecyclerView recyclerview, Context c) {
    final int pos = posts.indexOf(submission);
    if (pos != -1) {
        if (submission.isHidden()) {
            posts.remove(pos);
            Hidden.undoHidden(submission);
            recyclerview.getAdapter().notifyItemRemoved(pos + 1);
            Snackbar snack = Snackbar.make(recyclerview, R.string.submission_info_unhidden, Snackbar.LENGTH_LONG);
            View view = snack.getView();
            TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
            tv.setTextColor(Color.WHITE);
            snack.show();
        } else {
            final T t = posts.get(pos);
            posts.remove(pos);
            Hidden.setHidden(t);
            final OfflineSubreddit s;
            boolean success = false;
            if (baseSub != null) {
                s = OfflineSubreddit.getSubreddit(baseSub, false, c);
                try {
                    s.hide(pos);
                    success = true;
                } catch (Exception e) {
                }
            } else {
                success = false;
                s = null;
            }
            recyclerview.getAdapter().notifyItemRemoved(pos + 1);
            final boolean finalSuccess = success;
            Snackbar snack = Snackbar.make(recyclerview, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (baseSub != null && s != null && finalSuccess) {
                        s.unhideLast();
                    }
                    posts.add(pos, t);
                    recyclerview.getAdapter().notifyItemInserted(pos + 1);
                    Hidden.undoHidden(t);
                }
            });
            View view = snack.getView();
            TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
            tv.setTextColor(Color.WHITE);
            snack.show();
        }
    }
}
Also used : OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) TextView(android.widget.TextView) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) RecyclerView(android.support.v7.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) ApiException(net.dean.jraw.ApiException) Snackbar(android.support.design.widget.Snackbar)

Example 5 with OfflineSubreddit

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

the class PopulateSubmissionViewHolder method hideSubmission.

public <T extends Contribution> void hideSubmission(final Submission submission, final List<T> posts, final String baseSub, final RecyclerView recyclerview, Context c) {
    final int pos = posts.indexOf(submission);
    if (pos != -1) {
        if (submission.isHidden()) {
            posts.remove(pos);
            Hidden.undoHidden(submission);
            recyclerview.getAdapter().notifyItemRemoved(pos + 1);
            Snackbar snack = Snackbar.make(recyclerview, R.string.submission_info_unhidden, Snackbar.LENGTH_LONG);
            View view = snack.getView();
            TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
            tv.setTextColor(Color.WHITE);
            snack.show();
        } else {
            final T t = posts.get(pos);
            posts.remove(pos);
            Hidden.setHidden(t);
            final OfflineSubreddit s;
            boolean success = false;
            if (baseSub != null) {
                s = OfflineSubreddit.getSubreddit(baseSub, false, c);
                try {
                    s.hide(pos);
                    success = true;
                } catch (Exception e) {
                }
            } else {
                success = false;
                s = null;
            }
            recyclerview.getAdapter().notifyItemRemoved(pos + 1);
            final boolean finalSuccess = success;
            Snackbar snack = Snackbar.make(recyclerview, R.string.submission_info_hidden, Snackbar.LENGTH_LONG).setAction(R.string.btn_undo, new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (baseSub != null && s != null && finalSuccess) {
                        s.unhideLast();
                    }
                    posts.add(pos, t);
                    recyclerview.getAdapter().notifyItemInserted(pos + 1);
                    Hidden.undoHidden(t);
                }
            });
            View view = snack.getView();
            TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
            tv.setTextColor(Color.WHITE);
            snack.show();
        }
    }
}
Also used : OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) TextView(android.widget.TextView) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) RecyclerView(android.support.v7.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) InvalidScopeException(net.dean.jraw.http.oauth.InvalidScopeException) ApiException(net.dean.jraw.ApiException) Snackbar(android.support.design.widget.Snackbar)

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