コード例 #1
0
ファイル: SearchActivity.java プロジェクト: rbnpst/Blip
    @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
ファイル: SearchActivity.java プロジェクト: rbnpst/Blip
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    databaseManager = new DatabaseManager(this);

    recyclerView = (RecyclerView) findViewById(R.id.results);
    StaggeredGridLayoutManager layoutManager;
    if (getResources().getBoolean(R.bool.landscape)) {
      layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    } else {
      layoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
    }
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    adapter = new SearchListAdapter();
    recyclerView.setAdapter(adapter);

    searchBar = (EditText) findViewById(R.id.search_bar);
    searchBar.addTextChangedListener(this);

    searchContainer = findViewById(R.id.search_container);
    parent = findViewById(R.id.parent);

    if (SharedPrefs.getInstance().transcriptSearchEnabled()) {
      searchBar.setHint(R.string.hint_search_transcript);
    } else {
      searchBar.setHint(R.string.hint_search);
    }

    home = findViewById(R.id.home);
    clear = findViewById(R.id.clear);
    clear.setOnClickListener(this);
    home.setOnClickListener(this);

    if (SharedPrefs.getInstance().isNightModeEnabled()) {
      searchContainer.setBackgroundColor(getResources().getColor(R.color.primary_night));
      parent.setBackgroundColor(getResources().getColor(R.color.primary_light_night));
      if (BlipUtils.isLollopopUp()) {
        getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark_night));
      }
    }
  }
コード例 #3
0
ファイル: SearchActivity.java プロジェクト: rbnpst/Blip
 @Override
 public void onTextChanged(CharSequence s, int start, int before, int count) {
   if (!s.toString().equals("")) {
     adapter.updateList(
         databaseManager.search(
             s.toString(), SharedPrefs.getInstance().transcriptSearchEnabled()));
   } else {
     adapter.updateList(Collections.<Comic>emptyList());
   }
 }
コード例 #4
0
ファイル: SearchActivity.java プロジェクト: rbnpst/Blip
      @Override
      public void onClick(View v) {
        final int position = getAdapterPosition();
        switch (v.getId()) {
          case R.id.open_in_browser:
            Intent intent =
                new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("http://xkcd.com/" + comics.get(position).getNum()));
            startActivity(intent);
            break;
          case R.id.transcript:
            String content = comics.get(position).getTranscript();
            if (content.equals("")) {
              content = getResources().getString(R.string.message_no_transcript);
            }
            final String speakingContent = content;
            new MaterialDialog.Builder(SearchActivity.this)
                .title(R.string.title_dialog_transcript)
                .content(content)
                .negativeText(R.string.negative_text_dialog)
                .neutralText(R.string.neutral_text_dialog_speak)
                .autoDismiss(false)
                .callback(
                    new MaterialDialog.ButtonCallback() {
                      @Override
                      public void onNegative(MaterialDialog dialog) {
                        super.onNegative(dialog);
                        dialog.dismiss();
                      }

                      @Override
                      public void onNeutral(MaterialDialog dialog) {
                        super.onNeutral(dialog);
                        SpeechSynthesizer.getInstance().convertToSpeechFlush(speakingContent);
                      }
                    })
                .dismissListener(
                    new DialogInterface.OnDismissListener() {
                      @Override
                      public void onDismiss(DialogInterface dialog) {
                        SpeechSynthesizer.getInstance().stopSpeaking();
                      }
                    })
                .show();
            break;
          case R.id.img_container:
            ImageActivity.launch(SearchActivity.this, img, comics.get(position).getNum());
            break;
          case R.id.favourite:
            boolean fav = comics.get(position).isFavourite();
            comics.get(position).setFavourite(!fav);
            databaseManager.setFavourite(comics.get(position).getNum(), !fav);
            if (fav) {
              if (SharedPrefs.getInstance().isNightModeEnabled()) {
                favourite.setColorFilter(getResources().getColor(android.R.color.white));
              } else {
                favourite.setColorFilter(getResources().getColor(R.color.icons_dark));
              }
            } else {
              // make fav
              favourite.setColorFilter(getResources().getColor(R.color.accent));
            }
            break;
          case R.id.help:
            Intent explainIntent =
                new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse(
                        "http://www.explainxkcd.com/wiki/index.php/"
                            + comics.get(position).getNum()));
            startActivity(explainIntent);
            break;
          case R.id.share:
            Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            if (BlipUtils.isLollopopUp()) {
              shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
            } else {
              shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            }
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, comics.get(position).getTitle());
            shareIntent.putExtra(Intent.EXTRA_TEXT, comics.get(position).getImg());
            startActivity(
                Intent.createChooser(
                    shareIntent, getResources().getString(R.string.tip_share_image_url)));
            break;
          case R.id.alt:
            alt.setText(comics.get(position).getAlt());
            alt.setClickable(false);
            break;
        }
      }