Search in sources :

Example 96 with FeedItem

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

the class MediaplayerActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (controller == null) {
        return false;
    }
    Playable media = controller.getMedia();
    if (item.getItemId() == android.R.id.home) {
        Intent intent = new Intent(MediaplayerActivity.this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        return true;
    } else {
        if (media != null) {
            switch(item.getItemId()) {
                case R.id.add_to_favorites_item:
                    if (media instanceof FeedMedia) {
                        FeedItem feedItem = ((FeedMedia) media).getItem();
                        if (feedItem != null) {
                            DBWriter.addFavoriteItem(feedItem);
                            isFavorite = true;
                            invalidateOptionsMenu();
                            Toast.makeText(this, R.string.added_to_favorites, Toast.LENGTH_SHORT).show();
                        }
                    }
                    break;
                case R.id.remove_from_favorites_item:
                    if (media instanceof FeedMedia) {
                        FeedItem feedItem = ((FeedMedia) media).getItem();
                        if (feedItem != null) {
                            DBWriter.removeFavoriteItem(feedItem);
                            isFavorite = false;
                            invalidateOptionsMenu();
                            Toast.makeText(this, R.string.removed_from_favorites, Toast.LENGTH_SHORT).show();
                        }
                    }
                    break;
                case R.id.disable_sleeptimer_item:
                    if (controller.serviceAvailable()) {
                        MaterialDialog.Builder stDialog = new MaterialDialog.Builder(this);
                        stDialog.title(R.string.sleep_timer_label);
                        stDialog.content(getString(R.string.time_left_label) + Converter.getDurationStringLong((int) controller.getSleepTimerTimeLeft()));
                        stDialog.positiveText(R.string.disable_sleeptimer_label);
                        stDialog.negativeText(R.string.cancel_label);
                        stDialog.onPositive((dialog, which) -> {
                            dialog.dismiss();
                            controller.disableSleepTimer();
                        });
                        stDialog.onNegative((dialog, which) -> dialog.dismiss());
                        stDialog.build().show();
                    }
                    break;
                case R.id.set_sleeptimer_item:
                    if (controller.serviceAvailable()) {
                        SleepTimerDialog td = new SleepTimerDialog(this) {

                            @Override
                            public void onTimerSet(long millis, boolean shakeToReset, boolean vibrate) {
                                controller.setSleepTimer(millis, shakeToReset, vibrate);
                            }
                        };
                        td.createNewDialog().show();
                    }
                    break;
                case R.id.audio_controls:
                    MaterialDialog dialog = new MaterialDialog.Builder(this).title(R.string.audio_controls).customView(R.layout.audio_controls, true).neutralText(R.string.close_label).onNeutral((dialog1, which) -> {
                        final SeekBar left = (SeekBar) dialog1.findViewById(R.id.volume_left);
                        final SeekBar right = (SeekBar) dialog1.findViewById(R.id.volume_right);
                        UserPreferences.setVolume(left.getProgress(), right.getProgress());
                    }).show();
                    final SeekBar barPlaybackSpeed = (SeekBar) dialog.findViewById(R.id.playback_speed);
                    final Button butDecSpeed = (Button) dialog.findViewById(R.id.butDecSpeed);
                    butDecSpeed.setOnClickListener(v -> {
                        if (controller != null && controller.canSetPlaybackSpeed()) {
                            barPlaybackSpeed.setProgress(barPlaybackSpeed.getProgress() - 2);
                        } else {
                            VariableSpeedDialog.showGetPluginDialog(this);
                        }
                    });
                    final Button butIncSpeed = (Button) dialog.findViewById(R.id.butIncSpeed);
                    butIncSpeed.setOnClickListener(v -> {
                        if (controller != null && controller.canSetPlaybackSpeed()) {
                            barPlaybackSpeed.setProgress(barPlaybackSpeed.getProgress() + 2);
                        } else {
                            VariableSpeedDialog.showGetPluginDialog(this);
                        }
                    });
                    final TextView txtvPlaybackSpeed = (TextView) dialog.findViewById(R.id.txtvPlaybackSpeed);
                    float currentSpeed = 1.0f;
                    try {
                        currentSpeed = Float.parseFloat(UserPreferences.getPlaybackSpeed());
                    } catch (NumberFormatException e) {
                        Log.e(TAG, Log.getStackTraceString(e));
                        UserPreferences.setPlaybackSpeed(String.valueOf(currentSpeed));
                    }
                    txtvPlaybackSpeed.setText(String.format("%.2fx", currentSpeed));
                    barPlaybackSpeed.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                        @Override
                        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                            if (controller != null && controller.canSetPlaybackSpeed()) {
                                float playbackSpeed = (progress + 10) / 20.0f;
                                controller.setPlaybackSpeed(playbackSpeed);
                                String speedPref = String.format(Locale.US, "%.2f", playbackSpeed);
                                UserPreferences.setPlaybackSpeed(speedPref);
                                String speedStr = String.format("%.2fx", playbackSpeed);
                                txtvPlaybackSpeed.setText(speedStr);
                            } else if (fromUser) {
                                float speed = Float.valueOf(UserPreferences.getPlaybackSpeed());
                                barPlaybackSpeed.post(() -> barPlaybackSpeed.setProgress((int) (20 * speed) - 10));
                            }
                        }

                        @Override
                        public void onStartTrackingTouch(SeekBar seekBar) {
                            if (controller != null && !controller.canSetPlaybackSpeed()) {
                                VariableSpeedDialog.showGetPluginDialog(MediaplayerActivity.this);
                            }
                        }

                        @Override
                        public void onStopTrackingTouch(SeekBar seekBar) {
                        }
                    });
                    barPlaybackSpeed.setProgress((int) (20 * currentSpeed) - 10);
                    final SeekBar barLeftVolume = (SeekBar) dialog.findViewById(R.id.volume_left);
                    barLeftVolume.setProgress(UserPreferences.getLeftVolumePercentage());
                    final SeekBar barRightVolume = (SeekBar) dialog.findViewById(R.id.volume_right);
                    barRightVolume.setProgress(UserPreferences.getRightVolumePercentage());
                    final CheckBox stereoToMono = (CheckBox) dialog.findViewById(R.id.stereo_to_mono);
                    stereoToMono.setChecked(UserPreferences.stereoToMono());
                    if (controller != null && !controller.canDownmix()) {
                        stereoToMono.setEnabled(false);
                        String sonicOnly = getString(R.string.sonic_only);
                        stereoToMono.setText(stereoToMono.getText() + " [" + sonicOnly + "]");
                    }
                    barLeftVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                        @Override
                        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                            controller.setVolume(Converter.getVolumeFromPercentage(progress), Converter.getVolumeFromPercentage(barRightVolume.getProgress()));
                        }

                        @Override
                        public void onStartTrackingTouch(SeekBar seekBar) {
                        }

                        @Override
                        public void onStopTrackingTouch(SeekBar seekBar) {
                        }
                    });
                    barRightVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                        @Override
                        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                            controller.setVolume(Converter.getVolumeFromPercentage(barLeftVolume.getProgress()), Converter.getVolumeFromPercentage(progress));
                        }

                        @Override
                        public void onStartTrackingTouch(SeekBar seekBar) {
                        }

                        @Override
                        public void onStopTrackingTouch(SeekBar seekBar) {
                        }
                    });
                    stereoToMono.setOnCheckedChangeListener((buttonView, isChecked) -> {
                        UserPreferences.stereoToMono(isChecked);
                        if (controller != null) {
                            controller.setDownmix(isChecked);
                        }
                    });
                    break;
                case R.id.visit_website_item:
                    Uri uri = Uri.parse(media.getWebsiteLink());
                    startActivity(new Intent(Intent.ACTION_VIEW, uri));
                    break;
                case R.id.support_item:
                    if (media instanceof FeedMedia) {
                        DBTasks.flattrItemIfLoggedIn(this, ((FeedMedia) media).getItem());
                    }
                    break;
                case R.id.share_link_item:
                    if (media instanceof FeedMedia) {
                        ShareUtils.shareFeedItemLink(this, ((FeedMedia) media).getItem());
                    }
                    break;
                case R.id.share_download_url_item:
                    if (media instanceof FeedMedia) {
                        ShareUtils.shareFeedItemDownloadLink(this, ((FeedMedia) media).getItem());
                    }
                    break;
                case R.id.share_link_with_position_item:
                    if (media instanceof FeedMedia) {
                        ShareUtils.shareFeedItemLink(this, ((FeedMedia) media).getItem(), true);
                    }
                    break;
                case R.id.share_download_url_with_position_item:
                    if (media instanceof FeedMedia) {
                        ShareUtils.shareFeedItemDownloadLink(this, ((FeedMedia) media).getItem(), true);
                    }
                    break;
                default:
                    return false;
            }
            return true;
        } else {
            return false;
        }
    }
}
Also used : Converter(de.danoeh.antennapod.core.util.Converter) PlaybackController(de.danoeh.antennapod.core.util.playback.PlaybackController) ImageButton(android.widget.ImageButton) Bundle(android.os.Bundle) SleepTimerDialog(de.danoeh.antennapod.dialog.SleepTimerDialog) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) PixelFormat(android.graphics.PixelFormat) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) Observable(rx.Observable) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) SeekBar(android.widget.SeekBar) CheckBox(android.widget.CheckBox) MenuInflater(android.view.MenuInflater) Locale(java.util.Locale) ShareUtils(de.danoeh.antennapod.core.util.ShareUtils) Toast(android.widget.Toast) Menu(android.view.Menu) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Button(android.widget.Button) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) StorageUtils(de.danoeh.antennapod.core.util.StorageUtils) Playable(de.danoeh.antennapod.core.util.playback.Playable) Build(android.os.Build) TargetApi(android.annotation.TargetApi) Log(android.util.Log) MediaPlayerError(de.danoeh.antennapod.core.util.playback.MediaPlayerError) PlaybackService(de.danoeh.antennapod.core.service.playback.PlaybackService) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) R(de.danoeh.antennapod.R) VariableSpeedDialog(de.danoeh.antennapod.dialog.VariableSpeedDialog) Color(android.graphics.Color) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FontAwesomeIcons(com.joanzapata.iconify.fonts.FontAwesomeIcons) IconDrawable(com.joanzapata.iconify.IconDrawable) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) DBWriter(de.danoeh.antennapod.core.storage.DBWriter) Flavors(de.danoeh.antennapod.core.util.Flavors) DBReader(de.danoeh.antennapod.core.storage.DBReader) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DBTasks(de.danoeh.antennapod.core.storage.DBTasks) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SeekBar(android.widget.SeekBar) Intent(android.content.Intent) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) Uri(android.net.Uri) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Playable(de.danoeh.antennapod.core.util.playback.Playable) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ImageButton(android.widget.ImageButton) Button(android.widget.Button) CheckBox(android.widget.CheckBox) SleepTimerDialog(de.danoeh.antennapod.dialog.SleepTimerDialog) TextView(android.widget.TextView)

Example 97 with FeedItem

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

the class FeedItemlistDescriptionAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Holder holder;
    FeedItem item = getItem(position);
    // Inflate layout
    if (convertView == null) {
        holder = new Holder();
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.itemdescription_listitem, parent, false);
        holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
        holder.pubDate = (TextView) convertView.findViewById(R.id.txtvPubDate);
        holder.description = (TextView) convertView.findViewById(R.id.txtvDescription);
        convertView.setTag(holder);
    } else {
        holder = (Holder) convertView.getTag();
    }
    holder.title.setText(item.getTitle());
    holder.pubDate.setText(DateUtils.formatAbbrev(getContext(), item.getPubDate()));
    if (item.getDescription() != null) {
        String description = item.getDescription().replaceAll("\n", " ").replaceAll("\\s+", " ").trim();
        holder.description.setText(description);
    }
    return convertView;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) LayoutInflater(android.view.LayoutInflater)

Example 98 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem 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 99 with FeedItem

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

the class AllEpisodesFragment method onEventMainThread.

public void onEventMainThread(FeedItemEvent event) {
    Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
    if (episodes == null || listAdapter == null) {
        return;
    }
    for (int i = 0, size = event.items.size(); i < size; i++) {
        FeedItem item = event.items.get(i);
        int pos = FeedItemUtil.indexOfItemWithId(episodes, item.getId());
        if (pos >= 0) {
            episodes.remove(pos);
            episodes.add(pos, item);
            listAdapter.notifyItemChanged(pos);
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem)

Example 100 with FeedItem

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

the class EpisodesApplyActionFragment method refreshCheckboxes.

private void refreshCheckboxes() {
    for (int i = 0; i < episodes.size(); i++) {
        FeedItem episode = episodes.get(i);
        boolean checked = checkedIds.contains(episode.getId());
        mListView.setItemChecked(i, checked);
    }
    ActivityCompat.invalidateOptionsMenu(EpisodesApplyActionFragment.this.getActivity());
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem)

Aggregations

FeedItem (de.danoeh.antennapod.core.feed.FeedItem)149 Feed (de.danoeh.antennapod.core.feed.Feed)53 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)40 Date (java.util.Date)35 ArrayList (java.util.ArrayList)33 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)28 Cursor (android.database.Cursor)23 File (java.io.File)18 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)15 Context (android.content.Context)12 FlakyTest (android.test.FlakyTest)11 View (android.view.View)10 Playable (de.danoeh.antennapod.core.util.playback.Playable)7 Intent (android.content.Intent)6 LayoutInflater (android.view.LayoutInflater)5 ListView (android.widget.ListView)5 SharedPreferences (android.content.SharedPreferences)4 Chapter (de.danoeh.antennapod.core.feed.Chapter)4 FeedFilter (de.danoeh.antennapod.core.feed.FeedFilter)4 LongList (de.danoeh.antennapod.core.util.LongList)4