Ejemplo n.º 1
0
  public void openPopup() {

    final DialogInterface.OnClickListener l2 =
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialogInterface, int i) {
            switch (i) {
              case 0:
                time = TimePeriod.HOUR;
                break;
              case 1:
                time = TimePeriod.DAY;
                break;
              case 2:
                time = TimePeriod.WEEK;
                break;
              case 3:
                time = TimePeriod.MONTH;
                break;
              case 4:
                time = TimePeriod.YEAR;
                break;
              case 5:
                time = TimePeriod.ALL;
                break;
            }
            reloadSubs();
            getSupportActionBar()
                .setSubtitle(
                    Reddit.getSortingStringsSearch(getBaseContext())[
                        Reddit.getSortingIdSearch(Search.this)]);
          }
        };
    AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(Search.this);
    builder.setTitle(R.string.sorting_choose);
    builder.setSingleChoiceItems(
        Reddit.getSortingStringsSearch(getBaseContext()), Reddit.getSortingIdSearch(this), l2);
    builder.show();
  }
Ejemplo n.º 2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    overrideRedditSwipeAnywhere();

    super.onCreate(savedInstanceState);
    applyColorTheme("");
    setContentView(R.layout.activity_saved);
    where = getIntent().getExtras().getString(EXTRA_TERM, "");
    subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT, "");
    setupSubredditAppBar(R.id.toolbar, "Search", true, subreddit.toLowerCase());

    Log.v(LogUtil.getTag(), "Searching for " + where + " in " + subreddit);

    time = TimePeriod.ALL;

    getSupportActionBar().setTitle(where);
    getSupportActionBar()
        .setSubtitle(
            Reddit.getSortingStringsSearch(getBaseContext())[Reddit.getSortingIdSearch(this)]);
    final RecyclerView rv = ((RecyclerView) findViewById(R.id.vertical_content));
    if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE
        || !SettingValues.tabletUI) {
      final PreCachingLayoutManager mLayoutManager;
      mLayoutManager = new PreCachingLayoutManager(this);
      rv.setLayoutManager(mLayoutManager);
    } else {
      final StaggeredGridLayoutManager mLayoutManager;
      mLayoutManager =
          new StaggeredGridLayoutManager(Reddit.dpWidth, StaggeredGridLayoutManager.VERTICAL);
      rv.setLayoutManager(mLayoutManager);
    }
    rv.addOnScrollListener(
        new RecyclerView.OnScrollListener() {
          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();
            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
              pastVisiblesItems =
                  ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
              int[] firstVisibleItems = null;
              firstVisibleItems =
                  ((StaggeredGridLayoutManager) rv.getLayoutManager())
                      .findFirstVisibleItemPositions(firstVisibleItems);
              if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                pastVisiblesItems = firstVisibleItems[0];
              }
            }

            if (!posts.loading) {
              if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
                posts.loading = true;
                posts.loadMore(adapter, subreddit, where, false);
              }
            }
          }
        });
    SwipeRefreshLayout mSwipeRefreshLayout =
        (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
    TypedValue typed_value = new TypedValue();
    getTheme()
        .resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, typed_value, true);
    mSwipeRefreshLayout.setProgressViewOffset(
        false, 0, getResources().getDimensionPixelSize(typed_value.resourceId));

    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(subreddit, this));

    mSwipeRefreshLayout.setRefreshing(true);
    posts = new SubredditSearchPosts(subreddit, where.toLowerCase(), this);
    adapter = new ContributionAdapter(this, posts, rv);
    rv.setAdapter(adapter);

    try {
      posts.bindAdapter(adapter, mSwipeRefreshLayout);
    } catch (ExecutionException | InterruptedException e) {
      e.printStackTrace();
    }
    // TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            posts.loadMore(adapter, subreddit, where, true);

            // TODO catch errors
          }
        });
  }