Пример #1
0
 public synchronized String getFeedfileName(Feed feed) {
   String filename = feed.getDownload_url();
   if (feed.getTitle() != null && !feed.getTitle().isEmpty()) {
     filename = feed.getTitle();
   }
   return "feed-" + FileNameGenerator.generateFileName(filename);
 }
  @Override
  protected void showFeedInformation(final Feed feed, final Map<String, String> alternateFeedUrls) {
    super.showFeedInformation(feed, alternateFeedUrls);
    setContentView(R.layout.listview_activity);

    this.feed = feed;
    this.selectedDownloadUrl = feed.getDownload_url();
    EventDistributor.getInstance().register(listener);
    ListView listView = (ListView) findViewById(R.id.listview);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View header = inflater.inflate(R.layout.onlinefeedview_header, listView, false);
    listView.addHeaderView(header);

    listView.setAdapter(new FeedItemlistDescriptionAdapter(this, 0, feed.getItems()));

    ImageView cover = (ImageView) header.findViewById(R.id.imgvCover);
    TextView title = (TextView) header.findViewById(R.id.txtvTitle);
    TextView author = (TextView) header.findViewById(R.id.txtvAuthor);
    TextView description = (TextView) header.findViewById(R.id.txtvDescription);
    Spinner spAlternateUrls = (Spinner) header.findViewById(R.id.spinnerAlternateUrls);

    subscribeButton = (Button) header.findViewById(R.id.butSubscribe);

    if (feed.getImage() != null && StringUtils.isNotBlank(feed.getImage().getDownload_url())) {
      Glide.with(this)
          .load(feed.getImage().getDownload_url())
          .placeholder(R.color.light_gray)
          .error(R.color.light_gray)
          .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
          .fitCenter()
          .dontAnimate()
          .into(cover);
    }

    title.setText(feed.getTitle());
    author.setText(feed.getAuthor());
    description.setText(feed.getDescription());

    subscribeButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            try {
              Feed f = new Feed(selectedDownloadUrl, new Date(0), feed.getTitle());
              f.setPreferences(feed.getPreferences());
              DefaultOnlineFeedViewActivity.this.feed = f;

              DownloadRequester.getInstance().downloadFeed(DefaultOnlineFeedViewActivity.this, f);
            } catch (DownloadRequestException e) {
              e.printStackTrace();
              DownloadRequestErrorDialogCreator.newRequestErrorDialog(
                  DefaultOnlineFeedViewActivity.this, e.getMessage());
            }
            setSubscribeButtonState(feed);
          }
        });

    if (alternateFeedUrls.isEmpty()) {
      spAlternateUrls.setVisibility(View.GONE);
    } else {
      spAlternateUrls.setVisibility(View.VISIBLE);

      final List<String> alternateUrlsList = new ArrayList<String>();
      final List<String> alternateUrlsTitleList = new ArrayList<String>();

      alternateUrlsList.add(feed.getDownload_url());
      alternateUrlsTitleList.add(feed.getTitle());

      alternateUrlsList.addAll(alternateFeedUrls.keySet());
      for (String url : alternateFeedUrls.keySet()) {
        alternateUrlsTitleList.add(alternateFeedUrls.get(url));
      }
      ArrayAdapter<String> adapter =
          new ArrayAdapter<String>(
              this, android.R.layout.simple_spinner_item, alternateUrlsTitleList);
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spAlternateUrls.setAdapter(adapter);
      spAlternateUrls.setOnItemSelectedListener(
          new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
              selectedDownloadUrl = alternateUrlsList.get(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {}
          });
    }
    setSubscribeButtonState(feed);
  }