Esempio n. 1
0
  @Override
  @Background
  public void loadListFromFavorite() {
    try {
      String providerUri =
          preferences
              .provider()
              .get()
              .replace(Providers.SCHEME_HTTPS, "")
              .replace(Providers.SCHEME_HTTP, "");

      List<FavoriteImage> favoriteImages =
          new Select()
              .from(FavoriteImage.class)
              .where(Condition.column(FavoriteImage$Table.PREVIEWURL).like("%" + providerUri + "%"))
              .orderBy(false, FavoriteImage$Table.LAST)
              .queryList();
      for (Image image : favoriteImages) {
        this.images.add(image);
      }
      notifyDataSetChanged();
      if (this.images.size() == 0 && context != null) {
        ((MainActivity) context).makeToast(R.string.no_favorite);
        ((MainActivity) context).clearFavoriteMode();
      }
    } catch (Exception e) {
      e.printStackTrace();
      onError(e.getMessage());
    }
  }
Esempio n. 2
0
  @Override
  public int getCount() {

    int count;

    String apiUri = preferences.provider().get();
    switch (apiUri) {
      case Providers.ANIME_PICTURES_URI:
        count = 80 * page;
        break;
      default:
        count = LIMIT * page;
    }
    return count;
  }
Esempio n. 3
0
  @Background
  public void loadList(String tags) {

    try {
      page++;

      String apiUri = preferences.provider().get();

      RestAdapter restAdapter =
          new RestAdapter.Builder()
              .setEndpoint(apiUri)
              // .setLogLevel(RestAdapter.LogLevel.FULL)
              .build();

      List<? extends Image> images;

      switch (apiUri) {
        case Providers.DANBOORU_URI:
          Danbooru danbooru = restAdapter.create(Danbooru.class);
          images = danbooru.list(LIMIT, page, tags);
          break;
        case Providers.KONACHAN_URI:
        case Providers.YANDERE_URI:
          Moebooru moebooru = restAdapter.create(Moebooru.class);
          images = moebooru.list(LIMIT, page, tags);
          break;
        case Providers.BEHOIMI_URI:
          Behoimi behoimi = restAdapter.create(Behoimi.class);
          images = behoimi.list(LIMIT, page, tags);
          break;
        case Providers.ANIME_PICTURES_URI:
          AnimePictures animePictures = restAdapter.create(AnimePictures.class);
          AnimePicturesList animePicturesList;

          if (tags.isEmpty()) {
            animePicturesList = animePictures.list(page - 1, "json", "en");
          } else {
            animePicturesList = animePictures.search(page - 1, tags, "date", 0, "json", "en");
          }

          images = animePicturesList.getPreviews();
          break;
        case Providers.GELBOORU_URI:
          restAdapter =
              new RestAdapter.Builder()
                  .setEndpoint(apiUri)
                  // .setLogLevel(RestAdapter.LogLevel.FULL)
                  .setConverter(new SimpleXMLConverter())
                  .build();
          Gelbooru gelbooru = restAdapter.create(Gelbooru.class);
          GelbooruList gelbooruList = gelbooru.list(LIMIT, page - 1, tags);

          images = gelbooruList.getPost();

          break;
        default:
          images = new ArrayList<>();
      }

      for (Image image : images) {
        this.images.add(image);
      }
      notifyDataSetChanged();
    } catch (Exception e) {
      e.printStackTrace();
      page--;
      onError(e.getMessage());
    }
  }