Search in sources :

Example 1 with TimePeriod

use of net.dean.jraw.paginators.TimePeriod in project Slide by ccrama.

the class Reddit method getSortingIdTime.

public static Integer getSortingIdTime(String subreddit) {
    subreddit = subreddit.toLowerCase(Locale.ENGLISH);
    TimePeriod time = times.containsKey(subreddit) ? times.get(subreddit) : Reddit.timePeriod;
    return getSortingIdTime(time);
}
Also used : TimePeriod(net.dean.jraw.paginators.TimePeriod)

Example 2 with TimePeriod

use of net.dean.jraw.paginators.TimePeriod in project Slide by ccrama.

the class SortingUtil method getSortingTimeId.

public static Integer getSortingTimeId(String subreddit) {
    subreddit = subreddit.toLowerCase(Locale.ENGLISH);
    TimePeriod time = times.containsKey(subreddit) ? times.get(subreddit) : SortingUtil.timePeriod;
    return getSortingTimeId(time);
}
Also used : TimePeriod(net.dean.jraw.paginators.TimePeriod)

Example 3 with TimePeriod

use of net.dean.jraw.paginators.TimePeriod in project Slide by ccrama.

the class Search method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstanceState);
    applyColorTheme("");
    setContentView(R.layout.activity_search);
    where = getIntent().getExtras().getString(EXTRA_TERM, "");
    time = TimePeriod.ALL;
    if (getIntent().hasExtra(EXTRA_MULTIREDDIT)) {
        multireddit = true;
        subreddit = getIntent().getExtras().getString(EXTRA_MULTIREDDIT);
    } else {
        if (getIntent().hasExtra(EXTRA_AUTHOR)) {
            where = where + "&author=" + getIntent().getExtras().getString(EXTRA_AUTHOR);
        }
        if (getIntent().hasExtra(EXTRA_NSFW)) {
            where = where + "&nsfw=" + (getIntent().getExtras().getBoolean(EXTRA_NSFW) ? "yes" : "no");
        }
        if (getIntent().hasExtra(EXTRA_SELF)) {
            where = where + "&selftext=" + (getIntent().getExtras().getBoolean(EXTRA_SELF) ? "yes" : "no");
        }
        if (getIntent().hasExtra(EXTRA_SITE)) {
            where = where + "&site=" + getIntent().getExtras().getString(EXTRA_SITE);
        }
        if (getIntent().hasExtra(EXTRA_URL)) {
            where = where + "&url=" + getIntent().getExtras().getString(EXTRA_URL);
        }
        if (getIntent().hasExtra(EXTRA_TIME)) {
            TimePeriod timePeriod = TimeUtils.stringToTimePeriod(getIntent().getExtras().getString(EXTRA_TIME));
            if (timePeriod != null) {
                time = timePeriod;
            }
        }
        subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT, "");
    }
    where = StringEscapeUtils.unescapeHtml4(where);
    setupSubredditAppBar(R.id.toolbar, "Search", true, subreddit.toLowerCase(Locale.ENGLISH));
    getSupportActionBar().setTitle(CompatUtil.fromHtml(where));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // it won't be, trust me
    assert mToolbar != null;
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // Simulate a system's "Back" button functionality.
            onBackPressed();
        }
    });
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    // When the .name() is returned for both of the ENUMs, it will be in all caps.
    // So, make it lowercase, then capitalize the first letter of each.
    getSupportActionBar().setSubtitle(StringUtils.capitalize(SortingUtil.search.name().toLowerCase(Locale.ENGLISH)) + " › " + StringUtils.capitalize(time.name().toLowerCase(Locale.ENGLISH)));
    rv = ((RecyclerView) findViewById(R.id.vertical_content));
    final RecyclerView.LayoutManager mLayoutManager = createLayoutManager(LayoutUtils.getNumColumns(getResources().getConfiguration().orientation, Search.this));
    rv.setLayoutManager(mLayoutManager);
    rv.addOnScrollListener(new ToolbarScrollHideHandler(mToolbar, findViewById(R.id.header)) {

        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();
            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
                pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
                int[] firstVisibleItems = null;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisiblesItems = firstVisibleItems[0];
                }
            }
            if (!posts.loading && (visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) {
                posts.loading = true;
                posts.loadMore(adapter, subreddit, where, false, multireddit, time);
            }
        }
    });
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(subreddit, this));
    // If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    // So, we estimate the height of the header in dp.
    mSwipeRefreshLayout.setProgressViewOffset(false, Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.SINGLE_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    mSwipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new SubredditSearchPosts(subreddit, where.toLowerCase(Locale.ENGLISH), this, multireddit);
    adapter = new ContributionAdapter(this, posts, rv);
    rv.setAdapter(adapter);
    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    // TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            posts.loadMore(adapter, subreddit, where, true, multireddit, time);
        // TODO catch errors
        }
    });
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) TimePeriod(net.dean.jraw.paginators.TimePeriod) SubredditSearchPosts(me.ccrama.redditslide.Adapters.SubredditSearchPosts) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) ContributionAdapter(me.ccrama.redditslide.Adapters.ContributionAdapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Aggregations

TimePeriod (net.dean.jraw.paginators.TimePeriod)3 View (android.view.View)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)1 ContributionAdapter (me.ccrama.redditslide.Adapters.ContributionAdapter)1 SubredditSearchPosts (me.ccrama.redditslide.Adapters.SubredditSearchPosts)1 CatchStaggeredGridLayoutManager (me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager)1 PreCachingLayoutManager (me.ccrama.redditslide.Views.PreCachingLayoutManager)1 ColorPreferences (me.ccrama.redditslide.Visuals.ColorPreferences)1 ToolbarScrollHideHandler (me.ccrama.redditslide.handler.ToolbarScrollHideHandler)1