Search in sources :

Example 6 with FeedFilter

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

the class FeedFilterTest method testComplexIncludeFilter.

public void testComplexIncludeFilter() throws Exception {
    String includeFilter = "Hello \n\"Two words\"";
    FeedFilter filter = new FeedFilter(includeFilter, "");
    FeedItem item = new FeedItem();
    item.setTitle("hello world");
    FeedItem item2 = new FeedItem();
    item2.setTitle("Two three words");
    FeedItem item3 = new FeedItem();
    item3.setTitle("One two words");
    assertTrue(!filter.excludeOnly());
    assertTrue(filter.includeOnly());
    assertEquals("", filter.getExcludeFilter());
    assertEquals(includeFilter, filter.getIncludeFilter());
    assertTrue(filter.shouldAutoDownload(item));
    assertTrue(!filter.shouldAutoDownload(item2));
    assertTrue(filter.shouldAutoDownload(item3));
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedFilter(de.danoeh.antennapod.core.feed.FeedFilter)

Example 7 with FeedFilter

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

the class FeedInfoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(UserPreferences.getTheme());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.feedinfo);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    long feedId = getIntent().getLongExtra(EXTRA_FEED_ID, -1);
    imgvCover = (ImageView) findViewById(R.id.imgvCover);
    txtvTitle = (TextView) findViewById(R.id.txtvTitle);
    txtvDescription = (TextView) findViewById(R.id.txtvDescription);
    lblLanguage = (TextView) findViewById(R.id.lblLanguage);
    txtvLanguage = (TextView) findViewById(R.id.txtvLanguage);
    lblAuthor = (TextView) findViewById(R.id.lblAuthor);
    txtvAuthor = (TextView) findViewById(R.id.txtvAuthor);
    txtvUrl = (TextView) findViewById(R.id.txtvUrl);
    cbxAutoDownload = (CheckBox) findViewById(R.id.cbxAutoDownload);
    cbxKeepUpdated = (CheckBox) findViewById(R.id.cbxKeepUpdated);
    spnAutoDelete = (Spinner) findViewById(R.id.spnAutoDelete);
    etxtUsername = (EditText) findViewById(R.id.etxtUsername);
    etxtPassword = (EditText) findViewById(R.id.etxtPassword);
    etxtFilterText = (EditText) findViewById(R.id.etxtEpisodeFilterText);
    rdoFilterInclude = (RadioButton) findViewById(R.id.radio_filter_include);
    rdoFilterInclude.setOnClickListener(v -> {
        filterInclude = true;
        filterTextChanged = true;
    });
    rdoFilterExclude = (RadioButton) findViewById(R.id.radio_filter_exclude);
    rdoFilterExclude.setOnClickListener(v -> {
        filterInclude = false;
        filterTextChanged = true;
    });
    txtvUrl.setOnClickListener(copyUrlToClipboard);
    subscription = Observable.fromCallable(() -> DBReader.getFeed(feedId)).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
        if (result == null) {
            Log.e(TAG, "Activity was started with invalid arguments");
            finish();
        }
        feed = result;
        Log.d(TAG, "Language is " + feed.getLanguage());
        Log.d(TAG, "Author is " + feed.getAuthor());
        Log.d(TAG, "URL is " + feed.getDownload_url());
        FeedPreferences prefs = feed.getPreferences();
        Glide.with(FeedInfoActivity.this).load(feed.getImageLocation()).placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate().into(imgvCover);
        txtvTitle.setText(feed.getTitle());
        String description = feed.getDescription();
        if (description != null) {
            if (Feed.TYPE_ATOM1.equals(feed.getType())) {
                HtmlToPlainText formatter = new HtmlToPlainText();
                Document feedDescription = Jsoup.parse(feed.getDescription());
                description = StringUtils.trim(formatter.getPlainText(feedDescription));
            }
        } else {
            description = "";
        }
        txtvDescription.setText(description);
        if (!TextUtils.isEmpty(feed.getAuthor())) {
            txtvAuthor.setText(feed.getAuthor());
        } else {
            lblAuthor.setVisibility(View.GONE);
            txtvAuthor.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(feed.getLanguage())) {
            txtvLanguage.setText(LangUtils.getLanguageString(feed.getLanguage()));
        } else {
            lblLanguage.setVisibility(View.GONE);
            txtvLanguage.setVisibility(View.GONE);
        }
        txtvUrl.setText(feed.getDownload_url() + " {fa-paperclip}");
        Iconify.addIcons(txtvUrl);
        cbxAutoDownload.setEnabled(UserPreferences.isEnableAutodownload());
        cbxAutoDownload.setChecked(prefs.getAutoDownload());
        cbxAutoDownload.setOnCheckedChangeListener((compoundButton, checked) -> {
            feed.getPreferences().setAutoDownload(checked);
            feed.savePreferences(FeedInfoActivity.this);
            updateAutoDownloadSettings();
            ApplyToEpisodesDialog dialog = new ApplyToEpisodesDialog(FeedInfoActivity.this, feed, checked);
            dialog.createNewDialog().show();
        });
        cbxKeepUpdated.setChecked(prefs.getKeepUpdated());
        cbxKeepUpdated.setOnCheckedChangeListener((compoundButton, checked) -> {
            feed.getPreferences().setKeepUpdated(checked);
            feed.savePreferences(FeedInfoActivity.this);
        });
        spnAutoDelete.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                FeedPreferences.AutoDeleteAction auto_delete_action;
                switch(parent.getSelectedItemPosition()) {
                    case 0:
                        auto_delete_action = FeedPreferences.AutoDeleteAction.GLOBAL;
                        break;
                    case 1:
                        auto_delete_action = FeedPreferences.AutoDeleteAction.YES;
                        break;
                    case 2:
                        auto_delete_action = FeedPreferences.AutoDeleteAction.NO;
                        break;
                    default:
                        return;
                }
                feed.getPreferences().setAutoDeleteAction(auto_delete_action);
                autoDeleteChanged = true;
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        spnAutoDelete.setSelection(prefs.getAutoDeleteAction().ordinal());
        etxtUsername.setText(prefs.getUsername());
        etxtPassword.setText(prefs.getPassword());
        etxtUsername.addTextChangedListener(authTextWatcher);
        etxtPassword.addTextChangedListener(authTextWatcher);
        FeedFilter filter = prefs.getFilter();
        if (filter.includeOnly()) {
            etxtFilterText.setText(filter.getIncludeFilter());
            rdoFilterInclude.setChecked(true);
            rdoFilterExclude.setChecked(false);
            filterInclude = true;
        } else if (filter.excludeOnly()) {
            etxtFilterText.setText(filter.getExcludeFilter());
            rdoFilterInclude.setChecked(false);
            rdoFilterExclude.setChecked(true);
            filterInclude = false;
        } else {
            Log.d(TAG, "No filter set");
            rdoFilterInclude.setChecked(false);
            rdoFilterExclude.setChecked(false);
            etxtFilterText.setText("");
        }
        etxtFilterText.addTextChangedListener(filterTextWatcher);
        supportInvalidateOptionsMenu();
        updateAutoDownloadSettings();
    }, error -> {
        Log.d(TAG, Log.getStackTraceString(error));
        finish();
    });
}
Also used : FeedMenuHandler(de.danoeh.antennapod.menuhandler.FeedMenuHandler) Context(android.content.Context) Bundle(android.os.Bundle) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException) ConfirmationDialog(de.danoeh.antennapod.core.dialog.ConfirmationDialog) Uri(android.net.Uri) ImageView(android.widget.ImageView) RadioButton(android.widget.RadioButton) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) ApGlideSettings(de.danoeh.antennapod.core.glide.ApGlideSettings) StringUtils(org.apache.commons.lang3.StringUtils) Editable(android.text.Editable) DownloadRequestErrorDialogCreator(de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator) MenuItem(android.view.MenuItem) Observable(rx.Observable) ClipData(android.content.ClipData) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) FeedFilter(de.danoeh.antennapod.core.feed.FeedFilter) CheckBox(android.widget.CheckBox) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) HtmlToPlainText(de.danoeh.antennapod.core.util.syndication.HtmlToPlainText) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Feed(de.danoeh.antennapod.core.feed.Feed) AdapterView(android.widget.AdapterView) Log(android.util.Log) DialogInterface(android.content.DialogInterface) IntentUtils(de.danoeh.antennapod.core.util.IntentUtils) R(de.danoeh.antennapod.R) TextUtils(android.text.TextUtils) AppCompatActivity(android.support.v7.app.AppCompatActivity) Spinner(android.widget.Spinner) LangUtils(de.danoeh.antennapod.core.util.LangUtils) FeedPreferences(de.danoeh.antennapod.core.feed.FeedPreferences) TextView(android.widget.TextView) Glide(com.bumptech.glide.Glide) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) DBWriter(de.danoeh.antennapod.core.storage.DBWriter) Iconify(com.joanzapata.iconify.Iconify) Document(org.jsoup.nodes.Document) DBReader(de.danoeh.antennapod.core.storage.DBReader) Jsoup(org.jsoup.Jsoup) Subscription(rx.Subscription) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) FeedPreferences(de.danoeh.antennapod.core.feed.FeedPreferences) HtmlToPlainText(de.danoeh.antennapod.core.util.syndication.HtmlToPlainText) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) AdapterView(android.widget.AdapterView) Document(org.jsoup.nodes.Document) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) FeedFilter(de.danoeh.antennapod.core.feed.FeedFilter)

Example 8 with FeedFilter

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

the class FeedInfoActivity method onPause.

@Override
protected void onPause() {
    super.onPause();
    if (feed != null) {
        FeedPreferences prefs = feed.getPreferences();
        if (authInfoChanged) {
            Log.d(TAG, "Auth info changed, saving credentials");
            prefs.setUsername(etxtUsername.getText().toString());
            prefs.setPassword(etxtPassword.getText().toString());
        }
        if (filterTextChanged) {
            Log.d(TAG, "Filter info changed, saving...");
            String filterText = etxtFilterText.getText().toString();
            String includeString = "";
            String excludeString = "";
            if (filterInclude) {
                includeString = filterText;
            } else {
                excludeString = filterText;
            }
            prefs.setFilter(new FeedFilter(includeString, excludeString));
        }
        if (authInfoChanged || autoDeleteChanged || filterTextChanged) {
            DBWriter.setFeedPreferences(prefs);
        }
        authInfoChanged = false;
        autoDeleteChanged = false;
        filterTextChanged = false;
    }
}
Also used : FeedPreferences(de.danoeh.antennapod.core.feed.FeedPreferences) FeedFilter(de.danoeh.antennapod.core.feed.FeedFilter)

Aggregations

FeedFilter (de.danoeh.antennapod.core.feed.FeedFilter)8 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)6 FeedPreferences (de.danoeh.antennapod.core.feed.FeedPreferences)2 ClipData (android.content.ClipData)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 Editable (android.text.Editable)1 TextUtils (android.text.TextUtils)1 TextWatcher (android.text.TextWatcher)1 Log (android.util.Log)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 OnItemSelectedListener (android.widget.AdapterView.OnItemSelectedListener)1