Search in sources :

Example 1 with FeedComponent

use of de.danoeh.antennapod.core.feed.FeedComponent in project AntennaPod by AntennaPod.

the class PodDBAdapter method setImage.

/**
     * Inserts or updates an image entry
     *
     * @return the id of the entry
     */
public long setImage(FeedImage image) {
    boolean startedTransaction = false;
    try {
        if (!db.inTransaction()) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                db.beginTransactionNonExclusive();
            } else {
                db.beginTransaction();
            }
            startedTransaction = true;
        }
        ContentValues values = new ContentValues();
        values.put(KEY_TITLE, image.getTitle());
        values.put(KEY_DOWNLOAD_URL, image.getDownload_url());
        values.put(KEY_DOWNLOADED, image.isDownloaded());
        values.put(KEY_FILE_URL, image.getFile_url());
        if (image.getId() == 0) {
            image.setId(db.insert(TABLE_NAME_FEED_IMAGES, null, values));
        } else {
            db.update(TABLE_NAME_FEED_IMAGES, values, KEY_ID + "=?", new String[] { String.valueOf(image.getId()) });
        }
        final FeedComponent owner = image.getOwner();
        if (owner != null && owner.getId() != 0) {
            values.clear();
            values.put(KEY_IMAGE, image.getId());
            if (owner instanceof Feed) {
                db.update(TABLE_NAME_FEEDS, values, KEY_ID + "=?", new String[] { String.valueOf(image.getOwner().getId()) });
            }
        }
        if (startedTransaction) {
            db.setTransactionSuccessful();
        }
    } catch (SQLException e) {
        Log.e(TAG, Log.getStackTraceString(e));
    } finally {
        if (startedTransaction) {
            db.endTransaction();
        }
    }
    return image.getId();
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) FeedComponent(de.danoeh.antennapod.core.feed.FeedComponent) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 2 with FeedComponent

use of de.danoeh.antennapod.core.feed.FeedComponent in project AntennaPod by AntennaPod.

the class SearchlistAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final Holder holder;
    SearchResult result = getItem(position);
    FeedComponent component = result.getComponent();
    // Inflate Layout
    if (convertView == null) {
        holder = new Holder();
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.searchlist_item, parent, false);
        holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
        if (Build.VERSION.SDK_INT >= 23) {
            holder.title.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_FULL);
        }
        holder.cover = (ImageView) convertView.findViewById(R.id.imgvFeedimage);
        holder.subtitle = (TextView) convertView.findViewById(R.id.txtvSubtitle);
        convertView.setTag(holder);
    } else {
        holder = (Holder) convertView.getTag();
    }
    if (component.getClass() == Feed.class) {
        final Feed feed = (Feed) component;
        holder.title.setText(feed.getTitle());
        holder.subtitle.setVisibility(View.GONE);
        Glide.with(context).load(feed.getImageLocation()).placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate().into(holder.cover);
    } else if (component.getClass() == FeedItem.class) {
        final FeedItem item = (FeedItem) component;
        holder.title.setText(item.getTitle());
        if (result.getSubtitle() != null) {
            holder.subtitle.setVisibility(View.VISIBLE);
            holder.subtitle.setText(result.getSubtitle());
        }
        ViewHelper.setAlpha(convertView, item.isPlayed() ? 0.5f : 1.0f);
        Glide.with(context).load(item.getFeed().getImageLocation()).placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate().into(holder.cover);
    }
    return convertView;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) LayoutInflater(android.view.LayoutInflater) SearchResult(de.danoeh.antennapod.core.feed.SearchResult) FeedComponent(de.danoeh.antennapod.core.feed.FeedComponent) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 3 with FeedComponent

use of de.danoeh.antennapod.core.feed.FeedComponent in project AntennaPod by AntennaPod.

the class SearchFragment method onListItemClick.

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    SearchResult result = (SearchResult) l.getAdapter().getItem(position);
    FeedComponent comp = result.getComponent();
    if (comp.getClass() == Feed.class) {
        ((MainActivity) getActivity()).loadFeedFragmentById(comp.getId(), null);
    } else {
        if (comp.getClass() == FeedItem.class) {
            FeedItem item = (FeedItem) comp;
            ((MainActivity) getActivity()).loadChildFragment(ItemFragment.newInstance(item.getId()));
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) SearchResult(de.danoeh.antennapod.core.feed.SearchResult) FeedComponent(de.danoeh.antennapod.core.feed.FeedComponent) MainActivity(de.danoeh.antennapod.activity.MainActivity)

Aggregations

FeedComponent (de.danoeh.antennapod.core.feed.FeedComponent)3 Feed (de.danoeh.antennapod.core.feed.Feed)2 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)2 SearchResult (de.danoeh.antennapod.core.feed.SearchResult)2 ContentValues (android.content.ContentValues)1 SQLException (android.database.SQLException)1 LayoutInflater (android.view.LayoutInflater)1 MainActivity (de.danoeh.antennapod.activity.MainActivity)1