Browse Source

Added filter feature for rss checker and server notifications. Special request by Xirvik!

pull/280/head
Eric Kok 9 years ago
parent
commit
c09807f191
  1. 4
      app/build.gradle
  2. 6
      app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java
  3. 14
      app/src/main/java/org/transdroid/core/app/settings/RssfeedSetting.java
  4. 24
      app/src/main/java/org/transdroid/core/app/settings/ServerSetting.java
  5. 21
      app/src/main/java/org/transdroid/core/app/settings/SettingsPersistence.java
  6. 21
      app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java
  7. 8
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java
  8. 4
      app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java
  9. 19
      app/src/main/java/org/transdroid/core/gui/rss/RssitemsFragment.java
  10. 2
      app/src/main/java/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java
  11. 38
      app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java
  12. 47
      app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java
  13. 6
      app/src/main/java/org/transdroid/core/rssparser/Channel.java
  14. 2
      app/src/main/java/org/transdroid/core/rssparser/Item.java
  15. 76
      app/src/main/java/org/transdroid/core/rssparser/RssParser.java
  16. 9
      app/src/main/java/org/transdroid/core/seedbox/DediseedboxSettings.java
  17. 20
      app/src/main/java/org/transdroid/core/seedbox/DediseedboxSettingsActivity.java
  18. 9
      app/src/main/java/org/transdroid/core/seedbox/SeedstuffSettings.java
  19. 19
      app/src/main/java/org/transdroid/core/seedbox/SeedstuffSettingsActivity.java
  20. 6
      app/src/main/java/org/transdroid/core/seedbox/XirvikDediSettings.java
  21. 19
      app/src/main/java/org/transdroid/core/seedbox/XirvikDediSettingsActivity.java
  22. 6
      app/src/main/java/org/transdroid/core/seedbox/XirvikSemiSettings.java
  23. 19
      app/src/main/java/org/transdroid/core/seedbox/XirvikSemiSettingsActivity.java
  24. 6
      app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettings.java
  25. 13
      app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettingsActivity.java
  26. 2
      app/src/main/java/org/transdroid/core/service/RssCheckerService.java
  27. 50
      app/src/main/java/org/transdroid/core/service/ServerCheckerService.java
  28. 8
      app/src/main/res/values/strings.xml
  29. 12
      app/src/main/res/xml/pref_rssfeed.xml
  30. 23
      app/src/main/res/xml/pref_seedbox_dediseedbox.xml
  31. 23
      app/src/main/res/xml/pref_seedbox_seedstuff.xml
  32. 23
      app/src/main/res/xml/pref_seedbox_xirvikdedi.xml
  33. 23
      app/src/main/res/xml/pref_seedbox_xirviksemi.xml
  34. 23
      app/src/main/res/xml/pref_seedbox_xirvikshared.xml
  35. 10
      app/src/main/res/xml/pref_server.xml

4
app/build.gradle

@ -9,8 +9,8 @@ android { @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 224
versionName '2.5.4'
versionCode 225
versionName '2.5.5'
}
buildTypes {
release {

6
app/src/main/java/org/transdroid/core/app/settings/ApplicationSettings.java

@ -184,7 +184,9 @@ public class ApplicationSettings { @@ -184,7 +184,9 @@ public class ApplicationSettings {
prefs.getString("server_ftppass_" + order, null),
Integer.parseInt(prefs.getString("server_timeout_" + order, "8")),
prefs.getBoolean("server_alarmfinished_" + order, true),
prefs.getBoolean("server_alarmnew_" + order, false),
prefs.getBoolean("server_alarmnew_" + order, false),
prefs.getString("server_alarmexclude_" + order, null),
prefs.getString("server_alarminclude_" + order, null),
false);
// @formatter:on
}
@ -472,6 +474,8 @@ public class ApplicationSettings { @@ -472,6 +474,8 @@ public class ApplicationSettings {
prefs.getString("rssfeed_url_" + order, null),
prefs.getBoolean("rssfeed_reqauth_" + order, false),
prefs.getBoolean("rssfeed_alarmnew_" + order, true),
prefs.getString("rssfeed_exclude_" + order, null),
prefs.getString("rssfeed_include_" + order, null),
lastViewed == -1L ? null : new Date(lastViewed),
prefs.getString("rssfeed_lastvieweditemurl_" + order, null));
// @formatter:on

14
app/src/main/java/org/transdroid/core/app/settings/RssfeedSetting.java

@ -36,16 +36,20 @@ public class RssfeedSetting implements SimpleListItem { @@ -36,16 +36,20 @@ public class RssfeedSetting implements SimpleListItem {
private final String url;
private final boolean requiresAuth;
private final boolean alarm;
private final String excludeFilter;
private final String includeFilter;
private Date lastViewed;
private final String lastViewedItemUrl;
public RssfeedSetting(int order, String name, String baseUrl, boolean needsAuth, boolean alarm, Date lastViewed,
public RssfeedSetting(int order, String name, String baseUrl, boolean needsAuth, boolean alarm, String excludeFilter, String includeFilter, Date lastViewed,
String lastViewedItemUrl) {
this.order = order;
this.name = name;
this.url = baseUrl;
this.requiresAuth = needsAuth;
this.alarm = alarm;
this.excludeFilter = excludeFilter;
this.includeFilter = includeFilter;
this.lastViewed = lastViewed;
this.lastViewedItemUrl = lastViewedItemUrl;
}
@ -77,6 +81,14 @@ public class RssfeedSetting implements SimpleListItem { @@ -77,6 +81,14 @@ public class RssfeedSetting implements SimpleListItem {
return alarm;
}
public String getExcludeFilter() {
return excludeFilter;
}
public String getIncludeFilter() {
return includeFilter;
}
/**
* Returns the date on which we last checked this feed. Note that this is NOT updated automatically after the
* settings were loaded from {@link ApplicationSettings}; instead the settings have to be manually loaded again

24
app/src/main/java/org/transdroid/core/app/settings/ServerSetting.java

@ -21,7 +21,7 @@ import android.net.Uri; @@ -21,7 +21,7 @@ import android.net.Uri;
import android.text.TextUtils;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.log.*;
import org.transdroid.core.gui.log.Log_;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.DaemonSettings;
import org.transdroid.daemon.IDaemonAdapter;
@ -58,6 +58,8 @@ public class ServerSetting implements SimpleListItem { @@ -58,6 +58,8 @@ public class ServerSetting implements SimpleListItem {
private final boolean ssl;
private final boolean sslTrustAll;
private final String sslTrustKey;
private final String excludeFilter;
private final String includeFilter;
private final boolean isAutoGenerated;
/**
@ -80,11 +82,11 @@ public class ServerSetting implements SimpleListItem { @@ -80,11 +82,11 @@ public class ServerSetting implements SimpleListItem {
* @param timeout The number of seconds to wait before timing out a connection attempt
* @param isAutoGenerated Whether this setting was generated rather than manually inputed by the user
*/
public ServerSetting(int key, String name, Daemon type, String address, String localAddress, int localPort,
String localNetwork, int port, boolean ssl, boolean sslTrustAll, String sslTrustKey,
String folder, boolean useAuthentication, String username, String password, String extraPass,
OS os, String downloadDir, String ftpUrl, String ftpPassword, int timeout,
boolean alarmOnFinishedDownload, boolean alarmOnNewTorrent, boolean isAutoGenerated) {
public ServerSetting(int key, String name, Daemon type, String address, String localAddress, int localPort, String localNetwork, int port,
boolean ssl, boolean sslTrustAll, String sslTrustKey, String folder, boolean useAuthentication, String username,
String password, String extraPass, OS os, String downloadDir, String ftpUrl, String ftpPassword, int timeout,
boolean alarmOnFinishedDownload, boolean alarmOnNewTorrent, String excludeFilter, String includeFilter,
boolean isAutoGenerated) {
this.key = key;
this.name = name;
this.type = type;
@ -108,6 +110,8 @@ public class ServerSetting implements SimpleListItem { @@ -108,6 +110,8 @@ public class ServerSetting implements SimpleListItem {
this.timeout = timeout;
this.alarmOnFinishedDownload = alarmOnFinishedDownload;
this.alarmOnNewTorrent = alarmOnNewTorrent;
this.excludeFilter = excludeFilter;
this.includeFilter = includeFilter;
this.isAutoGenerated = isAutoGenerated;
}
@ -207,6 +211,14 @@ public class ServerSetting implements SimpleListItem { @@ -207,6 +211,14 @@ public class ServerSetting implements SimpleListItem {
return alarmOnNewTorrent;
}
public String getExcludeFilter() {
return excludeFilter;
}
public String getIncludeFilter() {
return includeFilter;
}
public boolean isAutoGenerated() {
return isAutoGenerated;
}

21
app/src/main/java/org/transdroid/core/app/settings/SettingsPersistence.java

@ -133,6 +133,10 @@ public class SettingsPersistence { @@ -133,6 +133,10 @@ public class SettingsPersistence {
editor.putBoolean("server_alarmfinished_" + postfix, server.getBoolean("download_alarm"));
if (server.has("new_torrent_alarm"))
editor.putBoolean("server_alarmnew_" + postfix, server.getBoolean("new_torrent_alarm"));
if (server.has("alarm_filter_exclude"))
editor.putBoolean("server_alarmexclude_" + postfix, server.getBoolean("alarm_filter_exclude"));
if (server.has("alarm_filter_include"))
editor.putBoolean("server_alarminclude_" + postfix, server.getBoolean("alarm_filter_include"));
}
}
@ -169,6 +173,10 @@ public class SettingsPersistence { @@ -169,6 +173,10 @@ public class SettingsPersistence {
editor.putBoolean("rssfeed_reqauth_" + postfix, feed.getBoolean("needs_auth"));
if (feed.has("new_item_alarm"))
editor.putBoolean("rssfeed_alarmnew_" + postfix, feed.getBoolean("new_item_alarm"));
if (feed.has("alarm_filter_include"))
editor.putBoolean("rssfeed_alarminclude_" + postfix, feed.getBoolean("alarm_filter_include"));
if (feed.has("alarm_filter_exclude"))
editor.putBoolean("rssfeed_alarmexclude_" + postfix, feed.getBoolean("alarm_filter_exclude"));
if (feed.has("last_seen"))
editor.putString("rssfeed_lastnew_" + postfix, feed.getString("last_seen"));
@ -176,7 +184,11 @@ public class SettingsPersistence { @@ -176,7 +184,11 @@ public class SettingsPersistence {
}
// Import background service and system settings
if (json.has("alarm_enabled"))
if (json.has("alarm_enabled_rss"))
editor.putBoolean("notifications_enabledrss", json.getBoolean("alarm_enabled_rss"));
if (json.has("alarm_enabled_torrents"))
editor.putBoolean("notifications_enabled", json.getBoolean("alarm_enabled_torrents"));
else if (json.has("alarm_enabled")) // Compat
editor.putBoolean("notifications_enabled", json.getBoolean("alarm_enabled"));
if (json.has("alarm_interval"))
editor.putString("notifications_interval", json.getString("alarm_interval"));
@ -268,6 +280,8 @@ public class SettingsPersistence { @@ -268,6 +280,8 @@ public class SettingsPersistence {
server.put("server_timeout", prefs.getString("server_timeout_" + postfixi, null));
server.put("download_alarm", prefs.getBoolean("server_alarmfinished_" + postfixi, false));
server.put("new_torrent_alarm", prefs.getBoolean("server_alarmnew_" + postfixi, false));
server.put("alarm_filter_exclude", prefs.getBoolean("server_alarmexclude_" + postfixi, false));
server.put("alarm_filter_include", prefs.getBoolean("server_alarminclude_" + postfixi, false));
servers.put(server);
i++;
@ -303,6 +317,8 @@ public class SettingsPersistence { @@ -303,6 +317,8 @@ public class SettingsPersistence {
feed.put("url", prefs.getString("rssfeed_url_" + postfixk, null));
feed.put("needs_auth", prefs.getBoolean("rssfeed_reqauth_" + postfixk, false));
feed.put("new_item_alarm", prefs.getBoolean("rssfeed_alarmnew_" + postfixk, false));
feed.put("alarm_filter_exclude", prefs.getBoolean("server_alarmexclude_" + postfixk, false));
feed.put("alarm_filter_include", prefs.getBoolean("server_alarminclude_" + postfixk, false));
feed.put("last_seen", prefs.getString("rssfeed_lastnew_" + postfixk, null));
feeds.put(feed);
@ -312,7 +328,8 @@ public class SettingsPersistence { @@ -312,7 +328,8 @@ public class SettingsPersistence {
json.put("rssfeeds", feeds);
// Convert background service and system settings into JSON
json.put("alarm_enabled", prefs.getBoolean("notifications_enabled", true));
json.put("alarm_enabled_rss", prefs.getBoolean("notifications_enabledrss", true));
json.put("alarm_enabled_torrents", prefs.getBoolean("notifications_enabled", true));
json.put("alarm_interval", prefs.getString("notifications_interval", null));
json.put("alarm_sound_uri", prefs.getString("notifications_sound", null));
json.put("alarm_vibrate", prefs.getBoolean("notifications_vibrate", false));

21
app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java

@ -18,6 +18,8 @@ package org.transdroid.core.gui.navigation; @@ -18,6 +18,8 @@ package org.transdroid.core.gui.navigation;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.text.Spannable;
import android.text.SpannableString;
@ -37,6 +39,7 @@ import org.transdroid.BuildConfig; @@ -37,6 +39,7 @@ import org.transdroid.BuildConfig;
import org.transdroid.R;
import java.io.IOException;
import java.util.List;
/**
* Helper for activities to make navigation-related decisions, such as when a device can display a larger, tablet style layout or how to display
@ -143,6 +146,24 @@ public class NavigationHelper { @@ -143,6 +146,24 @@ public class NavigationHelper {
return imageCache;
}
public void forceOpenInBrowser(Uri link) {
Intent intent = new Intent(Intent.ACTION_VIEW).setData(link);
List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : activities) {
if (activities.size() == 1 || (resolveInfo.isDefault && resolveInfo.activityInfo.packageName.equals(context.getPackageName()))) {
// There is a default browser; use this
intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
return;
}
}
// No default browser found: open chooser
try {
context.startActivity(Intent.createChooser(intent, "Open..."));
} catch (Exception e) {
// No browser installed; consume and fail silently
}
}
/**
* Returns the application name (like Transdroid) and version name (like 1.5.0), appended by the version code (like 180).
* @return The app name and version, such as 'Transdroid 1.5.0 (180)'

8
app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java

@ -119,7 +119,8 @@ public class RssfeedsActivity extends AppCompatActivity { @@ -119,7 +119,8 @@ public class RssfeedsActivity extends AppCompatActivity {
protected void loadRssfeed(RssfeedLoader loader) {
try {
// Load and parse the feed
RssParser parser = new RssParser(loader.getSetting().getUrl());
RssParser parser =
new RssParser(loader.getSetting().getUrl(), loader.getSetting().getExcludeFilter(), loader.getSetting().getIncludeFilter());
parser.parse();
handleRssfeedResult(loader, parser.getChannel(), false);
} catch (Exception e) {
@ -162,7 +163,7 @@ public class RssfeedsActivity extends AppCompatActivity { @@ -162,7 +163,7 @@ public class RssfeedsActivity extends AppCompatActivity {
}
applicationSettings.setRssfeedLastViewer(loader.getSetting().getOrder(), new Date(), lastViewedItemUrl);
}
fragmentItems.update(loader.getChannel(), loader.hasError());
fragmentItems.update(loader.getChannel(), loader.hasError(), loader.getSetting().requiresExternalAuthentication());
} else {
@ -193,7 +194,8 @@ public class RssfeedsActivity extends AppCompatActivity { @@ -193,7 +194,8 @@ public class RssfeedsActivity extends AppCompatActivity {
if (TextUtils.isEmpty(name) && !TextUtils.isEmpty(loader.getSetting().getUrl())) {
name = Uri.parse(loader.getSetting().getUrl()).getHost();
}
RssitemsActivity_.intent(this).rssfeed(loader.getChannel()).rssfeedName(name).start();
RssitemsActivity_.intent(this).rssfeed(loader.getChannel()).rssfeedName(name)
.requiresExternalAuthentication(loader.getSetting().requiresExternalAuthentication()).start();
}

4
app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java

@ -42,6 +42,8 @@ public class RssitemsActivity extends AppCompatActivity { @@ -42,6 +42,8 @@ public class RssitemsActivity extends AppCompatActivity {
protected Channel rssfeed = null;
@Extra
protected String rssfeedName;
@Extra
protected boolean requiresExternalAuthentication;
@FragmentById(R.id.rssitems_fragment)
protected RssitemsFragment fragmentItems;
@ -71,7 +73,7 @@ public class RssitemsActivity extends AppCompatActivity { @@ -71,7 +73,7 @@ public class RssitemsActivity extends AppCompatActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Get the intent extras and show them to the already loaded fragment
fragmentItems.update(rssfeed, false);
fragmentItems.update(rssfeed, false, requiresExternalAuthentication);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)

19
app/src/main/java/org/transdroid/core/gui/rss/RssitemsFragment.java

@ -48,7 +48,9 @@ import org.androidannotations.annotations.InstanceState; @@ -48,7 +48,9 @@ import org.androidannotations.annotations.InstanceState;
import org.androidannotations.annotations.ItemClick;
import org.androidannotations.annotations.ViewById;
import org.transdroid.R;
import org.transdroid.core.app.settings.RssfeedSetting;
import org.transdroid.core.gui.TorrentsActivity_;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.gui.navigation.SelectionManagerMode;
import org.transdroid.core.gui.search.SearchActivity_;
import org.transdroid.core.rssparser.Channel;
@ -68,6 +70,11 @@ public class RssitemsFragment extends Fragment { @@ -68,6 +70,11 @@ public class RssitemsFragment extends Fragment {
protected Channel rssfeed = null;
@InstanceState
protected boolean hasError = false;
@InstanceState
protected boolean requiresExternalAuthentication = false;
@Bean
protected NavigationHelper navigationHelper;
// Views
@ViewById(R.id.rssitems_list)
@ -192,7 +199,7 @@ public class RssitemsFragment extends Fragment { @@ -192,7 +199,7 @@ public class RssitemsFragment extends Fragment {
// Set up the list adapter, which allows multi-select
rssitemsList.setAdapter(rssitemsAdapter);
rssitemsList.setMultiChoiceModeListener(onItemsSelected);
update(rssfeed, hasError);
update(rssfeed, hasError, requiresExternalAuthentication);
}
@ -200,8 +207,10 @@ public class RssitemsFragment extends Fragment { @@ -200,8 +207,10 @@ public class RssitemsFragment extends Fragment {
* Update the shown RSS items in the list.
* @param channel The loaded RSS content channel object
* @param hasError True if there were errors in loading the channel, in which case an error text is shown; false otherwise
* @param requiresExternalAuthentication Whether this RSS feed requires external authentication and should thus be redirected to a browser
*/
public void update(Channel channel, boolean hasError) {
public void update(Channel channel, boolean hasError, boolean requiresExternalAuthentication) {
this.requiresExternalAuthentication = requiresExternalAuthentication;
rssitemsAdapter.update(channel);
rssitemsList.setVisibility(View.GONE);
emptyText.setVisibility(View.VISIBLE);
@ -223,6 +232,12 @@ public class RssitemsFragment extends Fragment { @@ -223,6 +232,12 @@ public class RssitemsFragment extends Fragment {
@ItemClick(resName = "rssitems_list")
protected void onItemClicked(Item item) {
if (requiresExternalAuthentication) {
// Redirect to the browser, as this feed requires cookie authentication which we piggy-back on using the browser cookies
navigationHelper.forceOpenInBrowser(item.getTheLinkUri());
return;
}
// Don't broadcast this intent; we can safely assume this is intended for Transdroid only
Intent i = TorrentsActivity_.intent(getActivity()).get();
i.setData(item.getTheLinkUri());

2
app/src/main/java/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java

@ -30,6 +30,7 @@ import android.preference.ListPreference; @@ -30,6 +30,7 @@ import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.text.TextUtils;
import android.text.method.PasswordTransformationMethod;
/**
@ -220,6 +221,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi @@ -220,6 +221,7 @@ public abstract class KeyBoundPreferencesActivity extends PreferenceCompatActivi
Preference pref = findPreference(prefKey);
if (sharedPrefs.contains(prefKey)
&& pref instanceof EditTextPreference
&& !TextUtils.isEmpty(sharedPrefs.getString(prefKey, ""))
&& !(((EditTextPreference) pref).getEditText().getTransformationMethod() instanceof PasswordTransformationMethod)) {
// Non-password edit preferences show the user-entered value
pref.setSummary(sharedPrefs.getString(prefKey, ""));

38
app/src/main/java/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java

@ -16,12 +16,6 @@ @@ -16,12 +16,6 @@
*/
package org.transdroid.core.gui.settings;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.transdroid.R;
import org.transdroid.core.app.settings.*;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog;
@ -31,9 +25,15 @@ import android.content.Intent; @@ -31,9 +25,15 @@ import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.transdroid.R;
import org.transdroid.core.app.settings.ApplicationSettings_;
/**
* Activity that allows for a configuration of some RSS feed. The key can be supplied to update an existing RSS feed
* setting instead of creating a new one.
* Activity that allows for a configuration of some RSS feed. The key can be supplied to update an existing RSS feed setting instead of creating a new
* one.
* @author Eric Kok
*/
@EActivity
@ -53,8 +53,10 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity { @@ -53,8 +53,10 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity {
initTextPreference("rssfeed_name");
initTextPreference("rssfeed_url");
initBooleanPreference("rssfeed_alarmnew");
initBooleanPreference("rssfeed_reqauth");
initTextPreference("rssfeed_exclude");
initTextPreference("rssfeed_include");
// TODO: Replace this for cookies support like web searches
initBooleanPreference("rssfeed_reqauth");
}
@ -73,15 +75,15 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity { @@ -73,15 +75,15 @@ public class RssfeedSettingsActivity extends KeyBoundPreferencesActivity {
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_CONFIRMREMOVE:
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove)
.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key);
finish();
}
}).setNegativeButton(android.R.string.cancel, null).create();
case DIALOG_CONFIRMREMOVE:
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove)
.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ApplicationSettings_.getInstance_(RssfeedSettingsActivity.this).removeRssfeedSettings(key);
finish();
}
}).setNegativeButton(android.R.string.cancel, null).create();
}
return null;
}

47
app/src/main/java/org/transdroid/core/gui/settings/ServerSettingsActivity.java

@ -16,13 +16,6 @@ @@ -16,13 +16,6 @@
*/
package org.transdroid.core.gui.settings;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.transdroid.R;
import org.transdroid.core.app.settings.*;
import org.transdroid.daemon.Daemon;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog;
@ -34,10 +27,17 @@ import android.os.Build; @@ -34,10 +27,17 @@ import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.transdroid.R;
import org.transdroid.core.app.settings.ApplicationSettings_;
import org.transdroid.daemon.Daemon;
/**
* Activity that allows for a configuration of a server. The key can be supplied to update an existing server setting
* instead of creating a new one.
* Activity that allows for a configuration of a server. The key can be supplied to update an existing server setting instead of creating a new one.
* @author Eric Kok
*/
@EActivity
@ -46,7 +46,7 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity { @@ -46,7 +46,7 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
private static final int DIALOG_CONFIRMREMOVE = 0;
private EditTextPreference extraPass, folder, downloadDir;
private EditTextPreference extraPass, folder, downloadDir, excludeFilter, includeFilter;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -70,6 +70,8 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity { @@ -70,6 +70,8 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
initTextPreference("server_timeout");
initBooleanPreference("server_alarmfinished", true);
initBooleanPreference("server_alarmnew");
excludeFilter = initTextPreference("server_exclude");
includeFilter = initTextPreference("server_include");
initListPreference("server_os", "type_linux");
downloadDir = initTextPreference("server_downloaddir");
initTextPreference("server_ftpurl");
@ -97,16 +99,15 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity { @@ -97,16 +99,15 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_CONFIRMREMOVE:
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove)
.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ApplicationSettings_.getInstance_(ServerSettingsActivity.this).removeNormalServerSettings(
key);
finish();
}
}).setNegativeButton(android.R.string.cancel, null).create();
case DIALOG_CONFIRMREMOVE:
return new AlertDialog.Builder(this).setMessage(R.string.pref_confirmremove)
.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ApplicationSettings_.getInstance_(ServerSettingsActivity.this).removeNormalServerSettings(key);
finish();
}
}).setNegativeButton(android.R.string.cancel, null).create();
}
return null;
}
@ -127,6 +128,12 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity { @@ -127,6 +128,12 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
// Adjust title texts accordingly
folder.setTitle(daemonType == Daemon.rTorrent ? R.string.pref_scgifolder : R.string.pref_folder);
// Show the exclude and the include filters if notifying
boolean alarmFinished = prefs.getBoolean("server_alarmfinished_" + key, true);
boolean alarmNew = prefs.getBoolean("server_alarmnew_" + key, true);
excludeFilter.setEnabled(alarmNew || alarmFinished);
includeFilter.setEnabled(alarmNew || alarmFinished);
}
}

6
app/src/main/java/org/transdroid/core/rssparser/Channel.java

@ -24,8 +24,8 @@ public class Channel implements Parcelable { @@ -24,8 +24,8 @@ public class Channel implements Parcelable {
private String image;
public Channel() {
this.categories = new ArrayList<String>();
this.items = new ArrayList<Item>();
this.categories = new ArrayList<>();
this.items = new ArrayList<>();
}
public void setId(int id) {
@ -145,7 +145,7 @@ public class Channel implements Parcelable { @@ -145,7 +145,7 @@ public class Channel implements Parcelable {
long pubDateIn = in.readLong();
pubDate = pubDateIn == -1 ? null : new Date(pubDateIn);
lastBuildDate = in.readLong();
categories = new ArrayList<String>();
categories = new ArrayList<>();
in.readTypedList(items, Item.CREATOR);
in.readStringList(categories);
image = in.readString();

2
app/src/main/java/org/transdroid/core/rssparser/Item.java

@ -161,7 +161,7 @@ public class Item implements Parcelable { @@ -161,7 +161,7 @@ public class Item implements Parcelable {
enclosureUrl = in.readString();
enclosureType = in.readString();
enclosureLength = in.readLong();
isNew = in.readInt() == 1 ? true : false;
isNew = in.readInt() == 1;
}
}

76
app/src/main/java/org/transdroid/core/rssparser/RssParser.java

@ -4,12 +4,7 @@ @@ -4,12 +4,7 @@
*/
package org.transdroid.core.rssparser;
import java.io.IOException;
import java.util.Date;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import android.text.TextUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
@ -27,9 +22,21 @@ import org.xml.sax.Attributes; @@ -27,9 +22,21 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
@SuppressWarnings("deprecation")
public class RssParser extends DefaultHandler {
private String urlString;
private final String urlString;
private final String[] excludeFilters;
private final String[] includeFilters;
private Channel channel;
private StringBuilder text;
private Item item;
@ -38,16 +45,34 @@ public class RssParser extends DefaultHandler { @@ -38,16 +45,34 @@ public class RssParser extends DefaultHandler {
/**
* The constructor for the RSS parser; call {@link #parse()} to synchronously create an HTTP connection and parse
* the RSS feed contents. The results can be retrieved with {@link #getChannel()}.
* @param url
* @param url The url of the feed to retrieve
* @param excludeFilter A |-separated list of words that may not be included in the item title or they are excluded
* @param includeFilter A |-separated list of words that need to be included in the item title or they are excluded
*/
public RssParser(String url) {
public RssParser(String url, String excludeFilter, String includeFilter) {
this.urlString = url;
if (!TextUtils.isEmpty(excludeFilter)) {
this.excludeFilters = excludeFilter.split("\\|");
for (int i = 0; i < excludeFilters.length; i++) {
excludeFilters[i] = excludeFilters[i].toUpperCase(Locale.getDefault());
}
} else {
this.excludeFilters = null;
}
if (!TextUtils.isEmpty(includeFilter)) {
this.includeFilters = includeFilter.split("\\|");
for (int i = 0; i < includeFilters.length; i++) {
includeFilters[i] = includeFilters[i].toUpperCase(Locale.getDefault());
}
} else {
this.includeFilters = null;
}
this.text = new StringBuilder();
}
/**
* Returns the loaded RSS feed as channel which contains the individual {@link Item}s
* @return A channel object that ocntains the feed details and individual items
* @return A channel object that contains the feed details and individual items
*/
public Channel getChannel() {
return this.channel;
@ -69,6 +94,37 @@ public class RssParser extends DefaultHandler { @@ -69,6 +94,37 @@ public class RssParser extends DefaultHandler {
sp.parse(result.getEntity().getContent(), this);
}
// Apply filters
if (channel != null && (includeFilters != null || excludeFilters != null)) {
Iterator<Item> i = channel.getItems().iterator();
while (i.hasNext()) {
if (!matchesFilters(i.next()))
i.remove();
}
}
}
private boolean matchesFilters(Item next) {
String title = next.getTitle().toUpperCase();
if (includeFilters != null) {
boolean include = false;
for (String includeWord : includeFilters) {
if (includeWord.equals("") || title.contains(includeWord)) {
include = true;
break;
}
}
if (!include)
return false;
}
if (excludeFilters != null) {
for (String excludeWord : excludeFilters) {
if (!excludeWord.equals("") && title.contains(excludeWord))
return false;
}
}
return true;
}
private DefaultHttpClient initialise() {

9
app/src/main/java/org/transdroid/core/seedbox/DediseedboxSettings.java

@ -19,6 +19,7 @@ package org.transdroid.core.seedbox; @@ -19,6 +19,7 @@ package org.transdroid.core.seedbox;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.EditTextPreference;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.daemon.Daemon;
@ -30,6 +31,8 @@ import org.transdroid.daemon.OS; @@ -30,6 +31,8 @@ import org.transdroid.daemon.OS;
*/
public class DediseedboxSettings extends SeedboxSettingsImpl implements SeedboxSettings {
private EditTextPreference excludeFilter, includeFilter;
@Override
public String getName() {
return "Dediseedbox";
@ -66,8 +69,10 @@ public class DediseedboxSettings extends SeedboxSettingsImpl implements SeedboxS @@ -66,8 +69,10 @@ public class DediseedboxSettings extends SeedboxSettingsImpl implements SeedboxS
"ftp://" + user + "@" + server + "/",
pass,
6,
true,
true,
prefs.getBoolean("seedbox_dediseedbox_alarmfinished_" + order, true),
prefs.getBoolean("seedbox_dediseedbox_alarmnew_" + order, false),
prefs.getString("seedbox_dediseedbox_alarmexclude_" + order, null),
prefs.getString("seedbox_dediseedbox_alarminclude_" + order, null),
true);
// @formatter:on
}

20
app/src/main/java/org/transdroid/core/seedbox/DediseedboxSettingsActivity.java

@ -21,6 +21,7 @@ import android.content.Intent; @@ -21,6 +21,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.PreferenceManager;
import org.androidannotations.annotations.EActivity;
@ -29,6 +30,7 @@ import org.androidannotations.annotations.OptionsMenu; @@ -29,6 +30,7 @@ import org.androidannotations.annotations.OptionsMenu;
import org.transdroid.R;
import org.transdroid.core.gui.settings.KeyBoundPreferencesActivity;
import org.transdroid.core.gui.settings.MainSettingsActivity_;
import org.transdroid.daemon.Daemon;
/**
* Activity that allows for the configuration of a Dediseedbox seedbox. The key can be supplied to update an
@ -39,6 +41,8 @@ import org.transdroid.core.gui.settings.MainSettingsActivity_; @@ -39,6 +41,8 @@ import org.transdroid.core.gui.settings.MainSettingsActivity_;
@OptionsMenu(resName = "activity_deleteableprefs")
public class DediseedboxSettingsActivity extends KeyBoundPreferencesActivity {
private EditTextPreference excludeFilter, includeFilter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -53,6 +57,10 @@ public class DediseedboxSettingsActivity extends KeyBoundPreferencesActivity { @@ -53,6 +57,10 @@ public class DediseedboxSettingsActivity extends KeyBoundPreferencesActivity {
initTextPreference("seedbox_dediseedbox_server");
initTextPreference("seedbox_dediseedbox_user");
initTextPreference("seedbox_dediseedbox_pass");
initBooleanPreference("seedbox_dediseedbox_alarmfinished", true);
initBooleanPreference("seedbox_dediseedbox_alarmnew", true);
excludeFilter = initTextPreference("seedbox_dediseedbox_alarmexclude");
includeFilter = initTextPreference("seedbox_dediseedbox_alarminclude");
}
@ -69,4 +77,16 @@ public class DediseedboxSettingsActivity extends KeyBoundPreferencesActivity { @@ -69,4 +77,16 @@ public class DediseedboxSettingsActivity extends KeyBoundPreferencesActivity {
finish();
}
@Override
protected void onPreferencesChanged() {
// Show the exclude and the include filters if notifying
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean alarmFinished = prefs.getBoolean("seedbox_dediseedbox_alarmfinished_" + key, true);
boolean alarmNew = prefs.getBoolean("seedbox_dediseedbox_alarmnew_" + key, true);
excludeFilter.setEnabled(alarmNew || alarmFinished);
includeFilter.setEnabled(alarmNew || alarmFinished);
}
}

9
app/src/main/java/org/transdroid/core/seedbox/SeedstuffSettings.java

@ -23,6 +23,7 @@ import org.transdroid.daemon.OS; @@ -23,6 +23,7 @@ import org.transdroid.daemon.OS;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.EditTextPreference;
/**
* Implementation of {@link SeedboxSettings} for Seedstuff seedboxes.
@ -30,6 +31,8 @@ import android.content.SharedPreferences; @@ -30,6 +31,8 @@ import android.content.SharedPreferences;
*/
public class SeedstuffSettings extends SeedboxSettingsImpl implements SeedboxSettings {
private EditTextPreference excludeFilter, includeFilter;
@Override
public String getName() {
return "Seedstuff";
@ -66,8 +69,10 @@ public class SeedstuffSettings extends SeedboxSettingsImpl implements SeedboxSet @@ -66,8 +69,10 @@ public class SeedstuffSettings extends SeedboxSettingsImpl implements SeedboxSet
"ftp://" + user + "@" + server + ":32001/rtorrent/downloads",
pass,
6,
true,
true,
prefs.getBoolean("seedbox_seedstuff_alarmfinished_" + order, true),
prefs.getBoolean("seedbox_seedstuff_alarmnew_" + order, false),
prefs.getString("seedbox_seedstuff_alarmexclude_" + order, null),
prefs.getString("seedbox_seedstuff_alarminclude_" + order, null),
true);
// @formatter:on
}

19
app/src/main/java/org/transdroid/core/seedbox/SeedstuffSettingsActivity.java

@ -27,6 +27,7 @@ import android.content.Intent; @@ -27,6 +27,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.PreferenceManager;
/**
@ -38,6 +39,8 @@ import android.preference.PreferenceManager; @@ -38,6 +39,8 @@ import android.preference.PreferenceManager;
@OptionsMenu(resName = "activity_deleteableprefs")
public class SeedstuffSettingsActivity extends KeyBoundPreferencesActivity {
private EditTextPreference excludeFilter, includeFilter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -52,6 +55,10 @@ public class SeedstuffSettingsActivity extends KeyBoundPreferencesActivity { @@ -52,6 +55,10 @@ public class SeedstuffSettingsActivity extends KeyBoundPreferencesActivity {
initTextPreference("seedbox_seedstuff_server");
initTextPreference("seedbox_seedstuff_user");
initTextPreference("seedbox_seedstuff_pass");
initBooleanPreference("seedbox_seedstuff_alarmfinished", true);
initBooleanPreference("seedbox_seedstuff_alarmnew", true);
excludeFilter = initTextPreference("seedbox_seedstuff_alarmexclude");
includeFilter = initTextPreference("seedbox_seedstuff_alarminclude");
}
@ -68,4 +75,16 @@ public class SeedstuffSettingsActivity extends KeyBoundPreferencesActivity { @@ -68,4 +75,16 @@ public class SeedstuffSettingsActivity extends KeyBoundPreferencesActivity {
finish();
}
@Override
protected void onPreferencesChanged() {
// Show the exclude and the include filters if notifying
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean alarmFinished = prefs.getBoolean("seedbox_seedstuff_alarmfinished_" + key, true);
boolean alarmNew = prefs.getBoolean("seedbox_seedstuff_alarmnew_" + key, true);
excludeFilter.setEnabled(alarmNew || alarmFinished);
includeFilter.setEnabled(alarmNew || alarmFinished);
}
}

6
app/src/main/java/org/transdroid/core/seedbox/XirvikDediSettings.java

@ -67,8 +67,10 @@ public class XirvikDediSettings extends SeedboxSettingsImpl implements SeedboxSe @@ -67,8 +67,10 @@ public class XirvikDediSettings extends SeedboxSettingsImpl implements SeedboxSe
"ftp://" + user + "@" + server + "/downloads",
pass,
6,
true,
true,
prefs.getBoolean("seedbox_xirvikdedi_alarmfinished_" + order, true),
prefs.getBoolean("seedbox_xirvikdedi_alarmnew_" + order, false),
prefs.getString("seedbox_xirvikdedi_alarmexclude_" + order, null),
prefs.getString("seedbox_xirvikdedi_alarminclude_" + order, null),
true);
// @formatter:on
}

19
app/src/main/java/org/transdroid/core/seedbox/XirvikDediSettingsActivity.java

@ -27,6 +27,7 @@ import android.content.Intent; @@ -27,6 +27,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.PreferenceManager;
/**
@ -38,6 +39,8 @@ import android.preference.PreferenceManager; @@ -38,6 +39,8 @@ import android.preference.PreferenceManager;
@OptionsMenu(resName = "activity_deleteableprefs")
public class XirvikDediSettingsActivity extends KeyBoundPreferencesActivity {
private EditTextPreference excludeFilter, includeFilter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -53,6 +56,10 @@ public class XirvikDediSettingsActivity extends KeyBoundPreferencesActivity { @@ -53,6 +56,10 @@ public class XirvikDediSettingsActivity extends KeyBoundPreferencesActivity {
initTextPreference("seedbox_xirvikdedi_server");
initTextPreference("seedbox_xirvikdedi_user");
initTextPreference("seedbox_xirvikdedi_pass");
initBooleanPreference("seedbox_xirvikdedi_alarmfinished", true);
initBooleanPreference("seedbox_xirvikdedi_alarmnew", true);
excludeFilter = initTextPreference("seedbox_xirvikdedi_alarmexclude");
includeFilter = initTextPreference("seedbox_xirvikdedi_alarminclude");
}
@ -69,4 +76,16 @@ public class XirvikDediSettingsActivity extends KeyBoundPreferencesActivity { @@ -69,4 +76,16 @@ public class XirvikDediSettingsActivity extends KeyBoundPreferencesActivity {
finish();
}
@Override
protected void onPreferencesChanged() {
// Show the exclude and the include filters if notifying
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean alarmFinished = prefs.getBoolean("seedbox_xirvikdedi_alarmfinished_" + key, true);
boolean alarmNew = prefs.getBoolean("seedbox_xirvikdedi_alarmnew_" + key, true);
excludeFilter.setEnabled(alarmNew || alarmFinished);
includeFilter.setEnabled(alarmNew || alarmFinished);
}
}

6
app/src/main/java/org/transdroid/core/seedbox/XirvikSemiSettings.java

@ -66,8 +66,10 @@ public class XirvikSemiSettings extends SeedboxSettingsImpl implements SeedboxSe @@ -66,8 +66,10 @@ public class XirvikSemiSettings extends SeedboxSettingsImpl implements SeedboxSe
"ftp://" + user + "@" + server + "/downloads",
pass,
6,
true,
true,
prefs.getBoolean("seedbox_xirviksemi_alarmfinished_" + order, true),
prefs.getBoolean("seedbox_xirviksemi_alarmnew_" + order, false),
prefs.getString("seedbox_xirviksemi_alarmexclude_" + order, null),
prefs.getString("seedbox_xirviksemi_alarminclude_" + order, null),
true);
// @formatter:on
}

19
app/src/main/java/org/transdroid/core/seedbox/XirvikSemiSettingsActivity.java

@ -27,6 +27,7 @@ import android.content.Intent; @@ -27,6 +27,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.PreferenceManager;
/**
@ -38,6 +39,8 @@ import android.preference.PreferenceManager; @@ -38,6 +39,8 @@ import android.preference.PreferenceManager;
@OptionsMenu(resName = "activity_deleteableprefs")
public class XirvikSemiSettingsActivity extends KeyBoundPreferencesActivity {
private EditTextPreference excludeFilter, includeFilter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -52,6 +55,10 @@ public class XirvikSemiSettingsActivity extends KeyBoundPreferencesActivity { @@ -52,6 +55,10 @@ public class XirvikSemiSettingsActivity extends KeyBoundPreferencesActivity {
initTextPreference("seedbox_xirviksemi_server");
initTextPreference("seedbox_xirviksemi_user");
initTextPreference("seedbox_xirviksemi_pass");
initBooleanPreference("seedbox_xirviksemi_alarmfinished", true);
initBooleanPreference("seedbox_xirviksemi_alarmnew", true);
excludeFilter = initTextPreference("seedbox_xirviksemi_alarmexclude");
includeFilter = initTextPreference("seedbox_xirviksemi_alarminclude");
}
@ -68,4 +75,16 @@ public class XirvikSemiSettingsActivity extends KeyBoundPreferencesActivity { @@ -68,4 +75,16 @@ public class XirvikSemiSettingsActivity extends KeyBoundPreferencesActivity {
finish();
}
@Override
protected void onPreferencesChanged() {
// Show the exclude and the include filters if notifying
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean alarmFinished = prefs.getBoolean("seedbox_xirviksemi_alarmfinished_" + key, true);
boolean alarmNew = prefs.getBoolean("seedbox_xirviksemi_alarmnew_" + key, true);
excludeFilter.setEnabled(alarmNew || alarmFinished);
includeFilter.setEnabled(alarmNew || alarmFinished);
}
}

6
app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettings.java

@ -67,8 +67,10 @@ public class XirvikSharedSettings extends SeedboxSettingsImpl implements Seedbox @@ -67,8 +67,10 @@ public class XirvikSharedSettings extends SeedboxSettingsImpl implements Seedbox
"ftp://" + user + "@" + server + "/downloads",
pass,
6,
true,
true,
prefs.getBoolean("seedbox_xirvikshared_alarmfinished_" + order, true),
prefs.getBoolean("seedbox_xirvikshared_alarmnew_" + order, false),
prefs.getString("seedbox_xirvikshared_alarmexclude_" + order, null),
prefs.getString("seedbox_xirvikshared_alarminclude_" + order, null),
true);
// @formatter:on
}

13
app/src/main/java/org/transdroid/core/seedbox/XirvikSharedSettingsActivity.java

@ -53,6 +53,8 @@ import java.io.InputStream; @@ -53,6 +53,8 @@ import java.io.InputStream;
@OptionsMenu(resName = "activity_deleteableprefs")
public class XirvikSharedSettingsActivity extends KeyBoundPreferencesActivity {
private EditTextPreference excludeFilter, includeFilter;
@Bean
protected Log log;
@ -70,12 +72,23 @@ public class XirvikSharedSettingsActivity extends KeyBoundPreferencesActivity { @@ -70,12 +72,23 @@ public class XirvikSharedSettingsActivity extends KeyBoundPreferencesActivity {
initTextPreference("seedbox_xirvikshared_user");
initTextPreference("seedbox_xirvikshared_pass");
initTextPreference("seedbox_xirvikshared_rpc");
initBooleanPreference("seedbox_xirvikshared_alarmfinished", true);
initBooleanPreference("seedbox_xirvikshared_alarmnew", true);
excludeFilter = initTextPreference("seedbox_xirvikshared_alarmexclude");
includeFilter = initTextPreference("seedbox_xirvikshared_alarminclude");
}
@Override
protected void onPreferencesChanged() {
// Show the exclude and the include filters if notifying
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean alarmFinished = prefs.getBoolean("seedbox_xirvikshared_alarmfinished_" + key, true);
boolean alarmNew = prefs.getBoolean("seedbox_xirvikshared_alarmnew_" + key, true);
excludeFilter.setEnabled(alarmNew || alarmFinished);
includeFilter.setEnabled(alarmNew || alarmFinished);
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {

2
app/src/main/java/org/transdroid/core/service/RssCheckerService.java

@ -83,7 +83,7 @@ public class RssCheckerService extends IntentService { @@ -83,7 +83,7 @@ public class RssCheckerService extends IntentService {
}
log.d(this, "Try to parse " + feed.getName() + " (" + feed.getUrl() + ")");
RssParser parser = new RssParser(feed.getUrl());
RssParser parser = new RssParser(feed.getUrl(), feed.getExcludeFilter(), feed.getIncludeFilter());
parser.parse();
if (parser.getChannel() == null) {
continue;

50
app/src/main/java/org/transdroid/core/service/ServerCheckerService.java

@ -46,6 +46,7 @@ import android.app.NotificationManager; @@ -46,6 +46,7 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Build;
import android.text.TextUtils;
/**
* A background service that checks all user-configured servers (if so desired) for new and finished torrents.
@ -102,10 +103,26 @@ public class ServerCheckerService extends IntentService { @@ -102,10 +103,26 @@ public class ServerCheckerService extends IntentService {
List<Torrent> retrieved = ((RetrieveTaskSuccessResult) result).getTorrents();
log.d(this, server.getName() + ": Retrieved torrent listing");
// Preload filters to match torrent names
String[] excludeFilters = null;
String[] includeFilters = null;
if (!TextUtils.isEmpty(server.getExcludeFilter())) {
excludeFilters = server.getExcludeFilter().split("\\|");
for (int i = 0; i < excludeFilters.length; i++) {
excludeFilters[i] = excludeFilters[i].toUpperCase();
}
}
if (!TextUtils.isEmpty(server.getIncludeFilter())) {
includeFilters = server.getIncludeFilter().split("\\|");
for (int i = 0; i < includeFilters.length; i++) {
includeFilters[i] = includeFilters[i].toUpperCase();
}
}
// Check for differences between the last and the current stats
JSONArray currentStats = new JSONArray();
List<Torrent> newTorrents = new ArrayList<Torrent>();
List<Torrent> doneTorrents = new ArrayList<Torrent>();
List<Torrent> newTorrents = new ArrayList<>();
List<Torrent> doneTorrents = new ArrayList<>();
for (Torrent torrent : retrieved) {
// Remember this torrent for the next time
@ -119,12 +136,13 @@ public class ServerCheckerService extends IntentService { @@ -119,12 +136,13 @@ public class ServerCheckerService extends IntentService {
// See if this torrent was done the last time we checked
if (lastStats != null) {
Boolean wasDone = findLastDoneStat(lastStats, torrent);
if (server.shouldAlarmOnNewTorrent() && wasDone == null) {
boolean shouldNotify = matchFilters(torrent.getName(), excludeFilters, includeFilters);
if (server.shouldAlarmOnNewTorrent() && shouldNotify && wasDone == null) {
// This torrent wasn't present earlier
newTorrents.add(torrent);
continue;
}
if (server.shouldAlarmOnFinishedDownload() && torrent.getPartDone() == 1F && wasDone != null && !wasDone)
if (server.shouldAlarmOnFinishedDownload() && shouldNotify && torrent.getPartDone() == 1F && wasDone != null && !wasDone)
// This torrent is now done, but wasn't before
doneTorrents.add(torrent);
}
@ -142,7 +160,7 @@ public class ServerCheckerService extends IntentService { @@ -142,7 +160,7 @@ public class ServerCheckerService extends IntentService {
// Should start the main activity directly into this server
PendingIntent pi = PendingIntent.getActivity(this, notifyBase + server.getOrder(), i,
Intent.FLAG_ACTIVITY_NEW_TASK);
ArrayList<Torrent> affectedTorrents = new ArrayList<Torrent>(newTorrents.size() + doneTorrents.size());
ArrayList<Torrent> affectedTorrents = new ArrayList<>(newTorrents.size() + doneTorrents.size());
affectedTorrents.addAll(newTorrents);
affectedTorrents.addAll(doneTorrents);
@ -213,4 +231,26 @@ public class ServerCheckerService extends IntentService { @@ -213,4 +231,26 @@ public class ServerCheckerService extends IntentService {
return null;
}
private boolean matchFilters(String name, String[] excludeFilters, String[] includeFilters) {
String upperName = name.toUpperCase();
if (includeFilters != null) {
boolean include = false;
for (String includeWord : includeFilters) {
if (includeWord.equals("") || upperName.contains(includeWord)) {
include = true;
break;
}
}
if (!include)
return false;
}
if (excludeFilters != null) {
for (String excludeWord : excludeFilters) {
if (!excludeWord.equals("") && upperName.contains(excludeWord))
return false;
}
}
return true;
}
}

8
app/src/main/res/values/strings.xml

@ -246,6 +246,10 @@ @@ -246,6 +246,10 @@
<string name="pref_reqauth_info">Opens links in the webbrowser for user login</string>
<string name="pref_alarmrssnew">New item notification</string>
<string name="pref_alarmrssnew_info">Nofity when new torrents are released</string>
<string name="pref_alarmrssexclude">Exclude filter</string>
<string name="pref_alarmrssexclude_info">Don\'t show torrents whose name matches these |-separated words</string>
<string name="pref_alarmrssinclude">Include filter</string>
<string name="pref_alarmrssinclude_info">Only show torrents whose name matches these |-separated words</string>
<string name="pref_servertype">Server type</string>
<string name="pref_address">IP or host name</string>
@ -268,6 +272,10 @@ @@ -268,6 +272,10 @@
<string name="pref_alarmdone_info">Notify when a torrent finishes</string>
<string name="pref_alarmnew">New torrent notification</string>
<string name="pref_alarmnew_info">Nofity when a torrent was added</string>
<string name="pref_alarmexclude">Exclude filter</string>
<string name="pref_alarmexclude_info">Notify only if torrent name matches these |-separated words</string>
<string name="pref_alarminclude">Include filter</string>
<string name="pref_alarminclude_info">Notify never if torrent name matches these |-separated words</string>
<string name="pref_os">Server OS</string>
<string name="pref_downdir">Download directory</string>
<string name="pref_downdir_info">Manually set absolute path for remote connections</string>

12
app/src/main/res/xml/pref_rssfeed.xml

@ -40,4 +40,16 @@ @@ -40,4 +40,16 @@
android:summary="@string/pref_alarmrssnew_info"
android:defaultValue="true" />
<EditTextPreference
android:key="rssfeed_exclude"
android:title="@string/pref_alarmrssexclude"
android:summary="@string/pref_alarmrssexclude_info"
android:inputType="textFilter" />
<EditTextPreference
android:key="rssfeed_include"
android:title="@string/pref_alarmrssinclude"
android:summary="@string/pref_alarmrssinclude_info"
android:inputType="textFilter" />
</PreferenceScreen>

23
app/src/main/res/xml/pref_seedbox_dediseedbox.xml

@ -36,4 +36,27 @@ @@ -36,4 +36,27 @@
android:title="@string/pref_pass"
android:inputType="textPassword" />
<PreferenceScreen android:title="@string/pref_optional" >
<CheckBoxPreference
android:key="seedbox_dediseedbox_alarmfinished"
android:title="@string/pref_alarmdone"
android:summary="@string/pref_alarmdone_info"
android:defaultValue="true" />
<CheckBoxPreference
android:key="seedbox_dediseedbox_alarmnew"
android:title="@string/pref_alarmnew"
android:summary="@string/pref_alarmnew_info"
android:defaultValue="false" />
<EditTextPreference
android:key="seedbox_dediseedbox_alarmexclude"
android:title="@string/pref_alarmexclude"
android:summary="@string/pref_alarmexclude_info"
android:inputType="textFilter" />
<EditTextPreference
android:key="seedbox_dediseedbox_alarminclude"
android:title="@string/pref_alarminclude"
android:summary="@string/pref_alarminclude_info"
android:inputType="textFilter" />
</PreferenceScreen>
</PreferenceScreen>

23
app/src/main/res/xml/pref_seedbox_seedstuff.xml

@ -36,4 +36,27 @@ @@ -36,4 +36,27 @@
android:title="@string/pref_pass"
android:inputType="textPassword" />
<PreferenceScreen android:title="@string/pref_optional" >
<CheckBoxPreference
android:key="seedbox_seedstuff_alarmfinished"
android:title="@string/pref_alarmdone"
android:summary="@string/pref_alarmdone_info"
android:defaultValue="true" />
<CheckBoxPreference
android:key="seedbox_seedstuff_alarmnew"
android:title="@string/pref_alarmnew"
android:summary="@string/pref_alarmnew_info"
android:defaultValue="false" />
<EditTextPreference
android:key="seedbox_seedstuff_alarmexclude"
android:title="@string/pref_alarmexclude"
android:summary="@string/pref_alarmexclude_info"
android:inputType="textFilter" />
<EditTextPreference
android:key="seedbox_seedstuff_alarminclude"
android:title="@string/pref_alarminclude"
android:summary="@string/pref_alarminclude_info"
android:inputType="textFilter" />
</PreferenceScreen>
</PreferenceScreen>

23
app/src/main/res/xml/pref_seedbox_xirvikdedi.xml

@ -42,4 +42,27 @@ @@ -42,4 +42,27 @@
android:title="@string/pref_pass"
android:inputType="textPassword" />
<PreferenceScreen android:title="@string/pref_optional" >
<CheckBoxPreference
android:key="seedbox_xirvikdedi_alarmfinished"
android:title="@string/pref_alarmdone"
android:summary="@string/pref_alarmdone_info"
android:defaultValue="true" />
<CheckBoxPreference
android:key="seedbox_xirvikdedi_alarmnew"
android:title="@string/pref_alarmnew"
android:summary="@string/pref_alarmnew_info"
android:defaultValue="false" />
<EditTextPreference
android:key="seedbox_xirvikdedi_alarmexclude"
android:title="@string/pref_alarmexclude"
android:summary="@string/pref_alarmexclude_info"
android:inputType="textFilter" />
<EditTextPreference
android:key="seedbox_xirvikdedi_alarminclude"
android:title="@string/pref_alarminclude"
android:summary="@string/pref_alarminclude_info"
android:inputType="textFilter" />
</PreferenceScreen>
</PreferenceScreen>

23
app/src/main/res/xml/pref_seedbox_xirviksemi.xml

@ -36,4 +36,27 @@ @@ -36,4 +36,27 @@
android:title="@string/pref_pass"
android:inputType="textPassword" />
<PreferenceScreen android:title="@string/pref_optional" >
<CheckBoxPreference
android:key="seedbox_xirviksemi_alarmfinished"
android:title="@string/pref_alarmdone"
android:summary="@string/pref_alarmdone_info"
android:defaultValue="true" />
<CheckBoxPreference
android:key="seedbox_xirviksemi_alarmnew"
android:title="@string/pref_alarmnew"
android:summary="@string/pref_alarmnew_info"
android:defaultValue="false" />
<EditTextPreference
android:key="seedbox_xirviksemi_alarmexclude"
android:title="@string/pref_alarmexclude"
android:summary="@string/pref_alarmexclude_info"
android:inputType="textFilter" />
<EditTextPreference
android:key="seedbox_xirviksemi_alarminclude"
android:title="@string/pref_alarminclude"
android:summary="@string/pref_alarminclude_info"
android:inputType="textFilter" />
</PreferenceScreen>
</PreferenceScreen>

23
app/src/main/res/xml/pref_seedbox_xirvikshared.xml

@ -40,4 +40,27 @@ @@ -40,4 +40,27 @@
android:title="@string/pref_folder"
android:enabled="false" />
<PreferenceScreen android:title="@string/pref_optional" >
<CheckBoxPreference
android:key="seedbox_xirvikshared_alarmfinished"
android:title="@string/pref_alarmdone"
android:summary="@string/pref_alarmdone_info"
android:defaultValue="true" />
<CheckBoxPreference
android:key="seedbox_xirvikshared_alarmnew"
android:title="@string/pref_alarmnew"
android:summary="@string/pref_alarmnew_info"
android:defaultValue="false" />
<EditTextPreference
android:key="seedbox_xirvikshared_alarmexclude"
android:title="@string/pref_alarmexclude"
android:summary="@string/pref_alarmexclude_info"
android:inputType="textFilter" />
<EditTextPreference
android:key="seedbox_xirvikshared_alarminclude"
android:title="@string/pref_alarminclude"
android:summary="@string/pref_alarminclude_info"
android:inputType="textFilter" />
</PreferenceScreen>
</PreferenceScreen>

10
app/src/main/res/xml/pref_server.xml

@ -109,6 +109,16 @@ @@ -109,6 +109,16 @@
android:title="@string/pref_alarmnew"
android:summary="@string/pref_alarmnew_info"
android:defaultValue="false" />
<EditTextPreference
android:key="server_exclude"
android:title="@string/pref_alarmexclude"
android:summary="@string/pref_alarmexclude_info"
android:inputType="textFilter" />
<EditTextPreference
android:key="server_include"
android:title="@string/pref_alarminclude"
android:summary="@string/pref_alarminclude_info"
android:inputType="textFilter" />
<ListPreference
android:key="server_os"
android:title="@string/pref_os"

Loading…
Cancel
Save