public boolean onTouchEvent(TextView widget, final Spannable buffer, MotionEvent event) {
      if (event.getAction() == MotionEvent.ACTION_DOWN)
        position = event.getY(); // used to see if the user scrolled or not
      if (!(event.getAction() == MotionEvent.ACTION_UP
          || event.getAction() == MotionEvent.ACTION_DOWN)) {
        if (Math.abs((position - event.getY())) > 10) {
          handler.removeCallbacksAndMessages(null);
          Log.v(LogUtil.getTag(), "POSITION NOT CLICK IS " + event.getY());
        }

        return super.onTouchEvent(widget, buffer, event);
      }

      Log.v(LogUtil.getTag(), "POSITION IS " + position);

      comm = (SpoilerRobotoTextView) widget;

      int x = (int) event.getX();
      int y = (int) event.getY();

      x -= widget.getTotalPaddingLeft();
      y -= widget.getTotalPaddingTop();

      x += widget.getScrollX();
      y += widget.getScrollY();

      Layout layout = widget.getLayout();
      int line = layout.getLineForVertical(y);
      final int off = layout.getOffsetForHorizontal(line, x);

      link = buffer.getSpans(off, off, URLSpan.class);

      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          clickHandled = false;
          if (link.length != 0) {
            handler.postDelayed(longClicked, android.view.ViewConfiguration.getLongPressTimeout());
          }
          break;
        case MotionEvent.ACTION_UP:
          handler.removeCallbacksAndMessages(null);

          if (!clickHandled) {
            // regular click
            if (link.length != 0) {
              int i = 0;
              if (sequence != null) {
                i = ((Spannable) sequence).getSpanEnd(link[0]);
              }
              onLinkClick(link[0].getURL(), i);
            }
          }
          break;
      }
      return true;
    }
Example #2
0
    @Override
    protected Void doInBackground(Void... params) {
      try {
        String multiName = title.getText().toString().replace(" ", "").replace("-", "_");
        Pattern validName = Pattern.compile("^[A-Za-z0-9][A-Za-z0-9_]{2,20}$");
        Matcher m = validName.matcher(multiName);

        if (!m.matches()) {
          Log.v(LogUtil.getTag(), "Invalid multi name");
          throw new IllegalArgumentException(multiName);
        }
        if (delete) {
          Log.v(LogUtil.getTag(), "Deleting");
          new MultiRedditManager(Authentication.reddit).delete(old);

        } else {
          if (old != null && !old.isEmpty() && !old.replace(" ", "").equals(multiName)) {
            Log.v(LogUtil.getTag(), "Renaming");
            new MultiRedditManager(Authentication.reddit).rename(old, multiName);
          }
          Log.v(LogUtil.getTag(), "Create or Update, Name: " + multiName);
          new MultiRedditManager(Authentication.reddit)
              .createOrUpdate(
                  new MultiRedditUpdateRequest.Builder(Authentication.name, multiName)
                      .subreddits(subs)
                      .build());
          runOnUiThread(
              new Runnable() {
                @Override
                public void run() {
                  Log.v(LogUtil.getTag(), "Update Subreddits");
                  new UserSubscriptions.SyncMultireddits(CreateMulti.this).execute();
                }
              });
        }

      } catch (final NetworkException | ApiException e) {
        runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                new AlertDialogWrapper.Builder(CreateMulti.this)
                    .setTitle(R.string.err_title)
                    .setMessage(
                        e instanceof ApiException
                            ? getString(R.string.misc_err)
                                + ": "
                                + ((ApiException) e).getExplanation()
                                + "\n"
                                + getString(R.string.misc_retry)
                            : getString(R.string.misc_err))
                    .setNeutralButton(
                        R.string.btn_ok,
                        new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialogInterface, int i) {
                            finish();
                          }
                        })
                    .create()
                    .show();
              }
            });
        e.printStackTrace();
      } catch (IllegalArgumentException e) {
        runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                new AlertDialogWrapper.Builder(CreateMulti.this)
                    .setTitle(R.string.multireddit_invalid_name)
                    .setMessage(R.string.multireddit_invalid_name_msg)
                    .setNeutralButton(
                        R.string.btn_ok,
                        new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialogInterface, int i) {
                            finish();
                          }
                        })
                    .create()
                    .show();
              }
            });
      }
      return null;
    }
Example #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
          }
        });
  }