Ejemplo n.º 1
0
  @Override
  public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();

    super.onCreate(savedInstance);

    subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT, "");
    applyColorTheme(subreddit);
    setContentView(R.layout.activity_slidetabs);
    setupSubredditAppBar(R.id.toolbar, "/r/" + subreddit + " wiki", true, subreddit);

    tabs = (TabLayout) findViewById(R.id.sliding_tabs);
    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
    pager = (ViewPager) findViewById(R.id.content_view);
    findViewById(R.id.header).setBackgroundColor(Palette.getColor(subreddit));

    new AsyncGetWiki().execute();
  }
Ejemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    overrideRedditSwipeAnywhere();

    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_createmulti);
    setupAppBar(R.id.toolbar, "", true, true);

    findViewById(R.id.add)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                showSelectDialog();
              }
            });
    title = (EditText) findViewById(R.id.name);

    subs = new ArrayList<>();
    if (getIntent().hasExtra(EXTRA_MULTI)) {
      String multi = getIntent().getExtras().getString(EXTRA_MULTI);
      old = multi;
      title.setText(multi.replace("%20", " "));
      for (MultiReddit multiReddit : UserSubscriptions.getMultireddits()) {
        if (multiReddit.getDisplayName().equals(multi)) {
          for (MultiSubreddit sub : multiReddit.getSubreddits()) {
            subs.add(sub.getDisplayName().toLowerCase());
          }
        }
      }
    }
    recyclerView = (RecyclerView) findViewById(R.id.subslist);

    findViewById(R.id.delete).setVisibility(View.GONE); // todo make this work
    findViewById(R.id.ok)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (title.getText().toString().isEmpty()) {
                  new AlertDialogWrapper.Builder(CreateMulti.this)
                      .setTitle(R.string.multireddit_title_empty)
                      .setMessage(R.string.multireddit_title_empty_msg)
                      .setPositiveButton(
                          R.string.btn_ok,
                          new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                              dialog.dismiss();
                              title.requestFocus();
                            }
                          })
                      .show();
                } else if (subs.size() == 0) {
                  new AlertDialogWrapper.Builder(CreateMulti.this)
                      .setTitle(R.string.multireddit_no_subs)
                      .setMessage(R.string.multireddit_no_subs_msg)
                      .setPositiveButton(
                          R.string.btn_ok,
                          new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                              dialog.dismiss();
                            }
                          })
                      .show();
                } else {
                  new SaveMulti().execute();
                }
              }
            });
    adapter = new CustomAdapter(subs);
    //  adapter.setHasStableIds(true);

    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
  }
Ejemplo n.º 3
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
          }
        });
  }