예제 #1
0
    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;
    }
예제 #2
0
    @Override
    protected List<Submission> doInBackground(MultiReddit... subredditPaginators) {

      if (!NetworkUtil.isConnected(context)) {
        offline = true;
        return null;
      } else {
        offline = false;
      }

      stillShow = true;

      if (reset || paginator == null) {
        offline = false;
        paginator = new MultiRedditPaginator(Authentication.reddit, subredditPaginators[0]);
        paginator.setSorting(
            Reddit.getSorting("multi" + subredditPaginators[0].getDisplayName().toLowerCase()));
        paginator.setTimePeriod(
            Reddit.getTime("multi" + subredditPaginators[0].getDisplayName().toLowerCase()));

        LogUtil.v("Sorting is " + paginator.getSorting().name());
        paginator.setLimit(50);
      }

      List<Submission> things = new ArrayList<>();

      try {
        if (paginator != null && paginator.hasNext()) {
          things.addAll(paginator.next());
        } else {
          nomore = true;
        }

      } catch (Exception e) {
        e.printStackTrace();
        if (e.getMessage().contains("Forbidden")) {
          Reddit.authentication.updateToken(context);
        }
      }

      return things;
    }
예제 #3
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   LogUtil.v("Destroying");
   ((SubsamplingScaleImageView) rootView.findViewById(R.id.submission_image)).recycle();
 }
예제 #4
0
  public void doLoadImgur(String url) {

    final String finalUrl = url;
    final String finalUrl1 = url;
    if (url.endsWith("/")) {
      url = url.substring(0, url.length() - 1);
    }
    String hash = url.substring(url.lastIndexOf("/"), url.length());

    if (NetworkUtil.isConnected(getActivity())) {

      if (hash.startsWith("/")) hash = hash.substring(1, hash.length());
      LogUtil.v("Loading" + "https://imgur-apiv3.p.mashape.com/3/image/" + hash + ".json");
      Ion.with(this)
          .load("https://imgur-apiv3.p.mashape.com/3/image/" + hash + ".json")
          .addHeader("X-Mashape-Key", SecretConstants.getImgurApiKey(getActivity()))
          .addHeader("Authorization", "Client-ID " + "bef87913eb202e9")
          .asJsonObject()
          .setCallback(
              new FutureCallback<JsonObject>() {
                @Override
                public void onCompleted(Exception e, JsonObject obj) {

                  if (obj != null && !obj.isJsonNull() && obj.has("error")) {
                    LogUtil.v("Error loading content");
                    (getActivity()).finish();
                  } else {
                    try {
                      if (obj != null && !obj.isJsonNull() && obj.has("image")) {
                        String type =
                            obj.get("image")
                                .getAsJsonObject()
                                .get("image")
                                .getAsJsonObject()
                                .get("type")
                                .getAsString();
                        String urls =
                            obj.get("image")
                                .getAsJsonObject()
                                .get("links")
                                .getAsJsonObject()
                                .get("original")
                                .getAsString();

                        if (type.contains("gif")) {
                          doLoadGif(urls);
                        } else if (!imageShown) { // only load if there is no image
                          doLoadImage(urls);
                        }
                      } else if (obj.has("data")) {
                        String type = obj.get("data").getAsJsonObject().get("type").getAsString();
                        String urls = obj.get("data").getAsJsonObject().get("link").getAsString();
                        String mp4 = "";
                        if (obj.get("data").getAsJsonObject().has("mp4")) {
                          mp4 = obj.get("data").getAsJsonObject().get("mp4").getAsString();
                        }

                        if (type.contains("gif")) {
                          doLoadGif(((mp4 == null || mp4.isEmpty()) ? urls : mp4));
                        } else if (!imageShown) { // only load if there is no image
                          doLoadImage(urls);
                        }
                      } else {
                        if (!imageShown) doLoadImage(finalUrl1);
                      }
                    } catch (Exception e2) {
                      e2.printStackTrace();
                      Intent i = new Intent(getActivity(), Website.class);
                      i.putExtra(Website.EXTRA_URL, finalUrl);
                      getActivity().startActivity(i);
                    }
                  }
                }
              });
    }
  }
예제 #5
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;
    }
예제 #6
0
파일: Search.java 프로젝트: rigardin/Slide
  @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
          }
        });
  }