示例#1
0
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
      Comic comic = comics.get(position);

      if (comic == null) return;

      if (SharedPrefs.getInstance().isNightModeEnabled()) {
        holder.backgroundCard.setCardBackgroundColor(
            getResources().getColor(R.color.primary_night));
        holder.title.setTextColor(getResources().getColor(android.R.color.white));
        holder.date.setTextColor(getResources().getColor(android.R.color.white));
        holder.alt.setTextColor(getResources().getColor(android.R.color.white));
        holder.transcript.setColorFilter(getResources().getColor(android.R.color.white));
        holder.share.setColorFilter(getResources().getColor(android.R.color.white));
        holder.explain.setColorFilter(getResources().getColor(android.R.color.white));
        holder.browser.setColorFilter(getResources().getColor(android.R.color.white));
      }

      holder.title.setText(comic.getNum() + ". " + comic.getTitle());

      Calendar calendar = Calendar.getInstance();
      calendar.set(Calendar.YEAR, Integer.parseInt(comic.getYear()));
      calendar.set(Calendar.MONTH, Integer.parseInt(comic.getMonth()) - 1);
      calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(comic.getDay()));
      holder.date.setText(simpleDateFormat.format(calendar.getTime()));

      if (SharedPrefs.getInstance().isAltSpoilerized()) {
        String altText = getResources().getString(R.string.title_pager_alt_spoiler);
        holder.alt.setClickable(true);
        holder.alt.setText(altText);
      } else {
        holder.alt.setClickable(false);
        holder.alt.setText(comic.getAlt());
      }

      Picasso.with(holder.img.getContext())
          .load(comic.getImg())
          .error(R.drawable.error_network)
          .into(holder.img);

      if (comic.isFavourite()) {
        holder.favourite.setColorFilter(getResources().getColor(R.color.accent));
      } else {
        if (SharedPrefs.getInstance().isNightModeEnabled()) {
          holder.favourite.setColorFilter(getResources().getColor(android.R.color.white));
        } else {
          holder.favourite.setColorFilter(getResources().getColor(R.color.icons_dark));
        }
      }
    }
示例#2
0
 @Override
 protected void onHandleIntent(Intent intent) {
   DatabaseManager databaseManager = new DatabaseManager(this);
   Gson gson = new Gson();
   Request request = new Request.Builder().url("http://xkcd.com/info.0.json").build();
   try {
     Response response = BlipApplication.getInstance().client.newCall(request).execute();
     if (!response.isSuccessful()) throw new IOException();
     Comic comic = gson.fromJson(response.body().string(), Comic.class);
     if (!databaseManager.comicExists(comic)) {
       databaseManager.addComic(comic);
       Intent notifIntent = new Intent(NEW_COMIC);
       notifIntent.putExtra(EXTRA_NUM, comic.getNum());
       sendBroadcast(notifIntent);
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }