Removed last references to FeedManager

This commit is contained in:
daniel oeh 2013-08-04 21:42:28 +02:00
parent 24c50f7840
commit edd84c6a4c
7 changed files with 427 additions and 413 deletions

View File

@ -1,6 +1,7 @@
package de.danoeh.antennapod.activity; package de.danoeh.antennapod.activity;
import java.util.Date; import java.util.Date;
import java.util.List;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;
@ -25,11 +26,11 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.MiroGuideItemlistAdapter; import de.danoeh.antennapod.adapter.MiroGuideItemlistAdapter;
import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.feed.Feed; import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.miroguide.conn.MiroGuideException; import de.danoeh.antennapod.miroguide.conn.MiroGuideException;
import de.danoeh.antennapod.miroguide.conn.MiroGuideService; import de.danoeh.antennapod.miroguide.conn.MiroGuideService;
import de.danoeh.antennapod.miroguide.model.MiroGuideChannel; import de.danoeh.antennapod.miroguide.model.MiroGuideChannel;
import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.storage.DBReader;
import de.danoeh.antennapod.storage.DownloadRequestException; import de.danoeh.antennapod.storage.DownloadRequestException;
import de.danoeh.antennapod.storage.DownloadRequester; import de.danoeh.antennapod.storage.DownloadRequester;
@ -38,146 +39,163 @@ import de.danoeh.antennapod.storage.DownloadRequester;
* his library. * his library.
*/ */
public class MiroGuideChannelViewActivity extends SherlockActivity { public class MiroGuideChannelViewActivity extends SherlockActivity {
private static final String TAG = "MiroGuideChannelViewActivity"; private static final String TAG = "MiroGuideChannelViewActivity";
public static final String EXTRA_CHANNEL_ID = "id"; public static final String EXTRA_CHANNEL_ID = "id";
public static final String EXTRA_CHANNEL_URL = "url"; public static final String EXTRA_CHANNEL_URL = "url";
private RelativeLayout layoutContent; private RelativeLayout layoutContent;
private ProgressBar progLoading; private ProgressBar progLoading;
private TextView txtvTitle; private TextView txtvTitle;
private TextView txtVDescription; private TextView txtVDescription;
private ListView listEntries; private ListView listEntries;
private long channelId; private long channelId;
private String channelUrl; private String channelUrl;
private MiroGuideChannel channel; private MiroGuideChannel channel;
private volatile List<Feed> feeds;
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
channelLoader.cancel(true); channelLoader.cancel(true);
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme()); setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.miroguide_channelview); setContentView(R.layout.miroguide_channelview);
layoutContent = (RelativeLayout) findViewById(R.id.layout_content); layoutContent = (RelativeLayout) findViewById(R.id.layout_content);
progLoading = (ProgressBar) findViewById(R.id.progLoading); progLoading = (ProgressBar) findViewById(R.id.progLoading);
txtvTitle = (TextView) findViewById(R.id.txtvTitle); txtvTitle = (TextView) findViewById(R.id.txtvTitle);
txtVDescription = (TextView) findViewById(R.id.txtvDescription); txtVDescription = (TextView) findViewById(R.id.txtvDescription);
listEntries = (ListView) findViewById(R.id.itemlist); listEntries = (ListView) findViewById(R.id.itemlist);
channelId = getIntent().getLongExtra(EXTRA_CHANNEL_ID, -1); channelId = getIntent().getLongExtra(EXTRA_CHANNEL_ID, -1);
channelUrl = getIntent().getStringExtra(EXTRA_CHANNEL_URL); channelUrl = getIntent().getStringExtra(EXTRA_CHANNEL_URL);
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
channelLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); channelLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else { } else {
channelLoader.execute(); channelLoader.execute();
} }
} }
/** Is used to load channel information asynchronously. */ /**
private AsyncTask<Void, Void, Void> channelLoader = new AsyncTask<Void, Void, Void>() { * Is used to load channel information asynchronously.
private static final String TAG = "ChannelLoader"; */
private Exception exception; private AsyncTask<Void, Void, Void> channelLoader = new AsyncTask<Void, Void, Void>() {
private static final String TAG = "ChannelLoader";
private Exception exception;
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Starting background task"); Log.d(TAG, "Starting background task");
MiroGuideService service = new MiroGuideService(); feeds = DBReader.getFeedList(MiroGuideChannelViewActivity.this);
try { MiroGuideService service = new MiroGuideService();
channel = service.getChannel(channelId); try {
} catch (MiroGuideException e) { channel = service.getChannel(channelId);
e.printStackTrace(); } catch (MiroGuideException e) {
exception = e; e.printStackTrace();
} exception = e;
return null; }
} return null;
}
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
protected void onPostExecute(Void result) { protected void onPostExecute(Void result) {
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Loading finished"); Log.d(TAG, "Loading finished");
if (exception == null) { if (exception == null) {
txtvTitle.setText(channel.getName()); txtvTitle.setText(channel.getName());
txtVDescription.setText(channel.getDescription()); txtVDescription.setText(channel.getDescription());
MiroGuideItemlistAdapter listAdapter = new MiroGuideItemlistAdapter( MiroGuideItemlistAdapter listAdapter = new MiroGuideItemlistAdapter(
MiroGuideChannelViewActivity.this, 0, MiroGuideChannelViewActivity.this, 0,
channel.getItems()); channel.getItems());
listEntries.setAdapter(listAdapter); listEntries.setAdapter(listAdapter);
progLoading.setVisibility(View.GONE); progLoading.setVisibility(View.GONE);
layoutContent.setVisibility(View.VISIBLE); layoutContent.setVisibility(View.VISIBLE);
supportInvalidateOptionsMenu(); supportInvalidateOptionsMenu();
} else { } else {
finish(); finish();
} }
} }
}; };
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = new MenuInflater(this); MenuInflater inflater = new MenuInflater(this);
inflater.inflate(R.menu.channelview, menu); inflater.inflate(R.menu.channelview, menu);
return true; return true;
} }
@Override @Override
public boolean onPrepareOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) {
boolean channelLoaded = channel != null; boolean channelLoaded = channel != null;
boolean beingDownloaded = channelLoaded boolean beingDownloaded = channelLoaded
&& DownloadRequester.getInstance().isDownloadingFile( && DownloadRequester.getInstance().isDownloadingFile(
channel.getDownloadUrl()); channel.getDownloadUrl());
boolean notAdded = channelLoaded boolean notAdded = channelLoaded
&& !((FeedManager.getInstance().feedExists( && !((feedExists(
channel.getDownloadUrl()) || beingDownloaded)); channel.getDownloadUrl()) || beingDownloaded));
menu.findItem(R.id.add_feed).setVisible(notAdded); menu.findItem(R.id.add_feed).setVisible(notAdded);
menu.findItem(R.id.visit_website_item).setVisible( menu.findItem(R.id.visit_website_item).setVisible(
channelLoaded && channel.getWebsiteUrl() != null); channelLoaded && channel.getWebsiteUrl() != null);
return true; return true;
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
finish(); finish();
return true; return true;
case R.id.visit_website_item: case R.id.visit_website_item:
Uri uri = Uri.parse(channel.getWebsiteUrl()); Uri uri = Uri.parse(channel.getWebsiteUrl());
startActivity(new Intent(Intent.ACTION_VIEW, uri)); startActivity(new Intent(Intent.ACTION_VIEW, uri));
return true; return true;
case R.id.add_feed: case R.id.add_feed:
try { try {
DownloadRequester.getInstance().downloadFeed( DownloadRequester.getInstance().downloadFeed(
this, this,
new Feed(channel.getDownloadUrl(), new Date(), channel new Feed(channel.getDownloadUrl(), new Date(), channel
.getName())); .getName()));
} catch (DownloadRequestException e) { } catch (DownloadRequestException e) {
e.printStackTrace(); e.printStackTrace();
DownloadRequestErrorDialogCreator.newRequestErrorDialog(this, DownloadRequestErrorDialogCreator.newRequestErrorDialog(this,
e.getMessage()); e.getMessage());
} }
Toast toast = Toast.makeText(this, R.string.miro_feed_added, Toast toast = Toast.makeText(this, R.string.miro_feed_added,
Toast.LENGTH_LONG); Toast.LENGTH_LONG);
toast.show(); toast.show();
supportInvalidateOptionsMenu(); supportInvalidateOptionsMenu();
return true; return true;
default: default:
return false; return false;
} }
} }
private boolean feedExists(String downloadUrl) {
if (feeds == null) {
return false;
}
for (Feed feed : feeds) {
if (feed.getDownload_url().equals(downloadUrl)) {
return true;
}
}
return false;
}
} }

View File

@ -26,334 +26,334 @@ import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.asynctask.FlattrClickWorker; import de.danoeh.antennapod.asynctask.FlattrClickWorker;
import de.danoeh.antennapod.asynctask.OpmlExportWorker; import de.danoeh.antennapod.asynctask.OpmlExportWorker;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.util.flattr.FlattrUtils; import de.danoeh.antennapod.util.flattr.FlattrUtils;
/** The main preference activity */ /**
* The main preference activity
*/
public class PreferenceActivity extends SherlockPreferenceActivity { public class PreferenceActivity extends SherlockPreferenceActivity {
private static final String TAG = "PreferenceActivity"; private static final String TAG = "PreferenceActivity";
private static final String PREF_FLATTR_THIS_APP = "prefFlattrThisApp"; private static final String PREF_FLATTR_THIS_APP = "prefFlattrThisApp";
private static final String PREF_FLATTR_AUTH = "pref_flattr_authenticate"; private static final String PREF_FLATTR_AUTH = "pref_flattr_authenticate";
private static final String PREF_FLATTR_REVOKE = "prefRevokeAccess"; private static final String PREF_FLATTR_REVOKE = "prefRevokeAccess";
private static final String PREF_OPML_EXPORT = "prefOpmlExport"; private static final String PREF_OPML_EXPORT = "prefOpmlExport";
private static final String PREF_ABOUT = "prefAbout"; private static final String PREF_ABOUT = "prefAbout";
private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir"; private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir";
private static final String AUTO_DL_PREF_SCREEN = "prefAutoDownloadSettings"; private static final String AUTO_DL_PREF_SCREEN = "prefAutoDownloadSettings";
private CheckBoxPreference[] selectedNetworks; private CheckBoxPreference[] selectedNetworks;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme()); setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
findPreference(PREF_FLATTR_THIS_APP).setOnPreferenceClickListener( findPreference(PREF_FLATTR_THIS_APP).setOnPreferenceClickListener(
new OnPreferenceClickListener() { new OnPreferenceClickListener() {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
new FlattrClickWorker(PreferenceActivity.this, new FlattrClickWorker(PreferenceActivity.this,
FlattrUtils.APP_URL).executeAsync(); FlattrUtils.APP_URL).executeAsync();
return true; return true;
} }
}); });
findPreference(PREF_FLATTR_REVOKE).setOnPreferenceClickListener( findPreference(PREF_FLATTR_REVOKE).setOnPreferenceClickListener(
new OnPreferenceClickListener() { new OnPreferenceClickListener() {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
FlattrUtils.revokeAccessToken(PreferenceActivity.this); FlattrUtils.revokeAccessToken(PreferenceActivity.this);
checkItemVisibility(); checkItemVisibility();
return true; return true;
} }
}); });
findPreference(PREF_ABOUT).setOnPreferenceClickListener( findPreference(PREF_ABOUT).setOnPreferenceClickListener(
new OnPreferenceClickListener() { new OnPreferenceClickListener() {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
PreferenceActivity.this.startActivity(new Intent( PreferenceActivity.this.startActivity(new Intent(
PreferenceActivity.this, AboutActivity.class)); PreferenceActivity.this, AboutActivity.class));
return true; return true;
} }
}); });
findPreference(PREF_OPML_EXPORT).setOnPreferenceClickListener( findPreference(PREF_OPML_EXPORT).setOnPreferenceClickListener(
new OnPreferenceClickListener() { new OnPreferenceClickListener() {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
if (FeedManager.getInstance().getFeedsSize() > 0) { new OpmlExportWorker(PreferenceActivity.this)
new OpmlExportWorker(PreferenceActivity.this) .executeAsync();
.executeAsync();
}
return true;
}
});
findPreference(PREF_CHOOSE_DATA_DIR).setOnPreferenceClickListener( return true;
new OnPreferenceClickListener() { }
});
@Override findPreference(PREF_CHOOSE_DATA_DIR).setOnPreferenceClickListener(
public boolean onPreferenceClick(Preference preference) { new OnPreferenceClickListener() {
startActivityForResult(
new Intent(PreferenceActivity.this,
DirectoryChooserActivity.class),
DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED);
return true;
}
});
findPreference(UserPreferences.PREF_THEME)
.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange( public boolean onPreferenceClick(Preference preference) {
Preference preference, Object newValue) { startActivityForResult(
Intent i = getIntent(); new Intent(PreferenceActivity.this,
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK DirectoryChooserActivity.class),
| Intent.FLAG_ACTIVITY_NEW_TASK); DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED);
finish(); return true;
startActivity(i); }
return true; });
} findPreference(UserPreferences.PREF_THEME)
}); .setOnPreferenceChangeListener(
findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER) new OnPreferenceChangeListener() {
.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange( public boolean onPreferenceChange(
Preference preference, Object newValue) { Preference preference, Object newValue) {
if (newValue instanceof Boolean) { Intent i = getIntent();
setSelectedNetworksEnabled((Boolean) newValue); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
return true; | Intent.FLAG_ACTIVITY_NEW_TASK);
} else { finish();
return false; startActivity(i);
} return true;
} }
}); });
findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE) findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER)
.setOnPreferenceChangeListener( .setOnPreferenceChangeListener(
new OnPreferenceChangeListener() { new OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange( public boolean onPreferenceChange(
Preference preference, Object newValue) { Preference preference, Object newValue) {
if (newValue instanceof String) { if (newValue instanceof Boolean) {
setEpisodeCacheSizeText(Integer setSelectedNetworksEnabled((Boolean) newValue);
.valueOf((String) newValue)); return true;
} } else {
return true; return false;
} }
}); }
findPreference(UserPreferences.PREF_ENABLE_AUTODL) });
.setOnPreferenceClickListener(new OnPreferenceClickListener() { findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE)
.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceChange(
checkItemVisibility(); Preference preference, Object newValue) {
return true; if (newValue instanceof String) {
} setEpisodeCacheSizeText(Integer
}); .valueOf((String) newValue));
}
return true;
}
});
findPreference(UserPreferences.PREF_ENABLE_AUTODL)
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
buildAutodownloadSelectedNetworsPreference(); @Override
setSelectedNetworksEnabled(UserPreferences public boolean onPreferenceClick(Preference preference) {
.isEnableAutodownloadWifiFilter()); checkItemVisibility();
return true;
}
});
} buildAutodownloadSelectedNetworsPreference();
setSelectedNetworksEnabled(UserPreferences
.isEnableAutodownloadWifiFilter());
private void setSelectedNetworksEnabled(boolean b) { }
if (selectedNetworks != null) {
for (Preference p : selectedNetworks) {
p.setEnabled(b);
}
}
}
@Override private void setSelectedNetworksEnabled(boolean b) {
protected void onResume() { if (selectedNetworks != null) {
super.onResume(); for (Preference p : selectedNetworks) {
checkItemVisibility(); p.setEnabled(b);
setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize()); }
setDataFolderText(); }
} }
@SuppressWarnings("deprecation") @Override
private void checkItemVisibility() { protected void onResume() {
super.onResume();
checkItemVisibility();
setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize());
setDataFolderText();
}
boolean hasFlattrToken = FlattrUtils.hasToken(); @SuppressWarnings("deprecation")
private void checkItemVisibility() {
findPreference(PREF_FLATTR_AUTH).setEnabled(!hasFlattrToken); boolean hasFlattrToken = FlattrUtils.hasToken();
findPreference(PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken);
findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER) findPreference(PREF_FLATTR_AUTH).setEnabled(!hasFlattrToken);
.setEnabled(UserPreferences.isEnableAutodownload()); findPreference(PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken);
setSelectedNetworksEnabled(UserPreferences.isEnableAutodownload()
&& UserPreferences.isEnableAutodownloadWifiFilter());
} findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER)
.setEnabled(UserPreferences.isEnableAutodownload());
setSelectedNetworksEnabled(UserPreferences.isEnableAutodownload()
&& UserPreferences.isEnableAutodownloadWifiFilter());
private void setEpisodeCacheSizeText(int cacheSize) { }
String s;
if (cacheSize == getResources().getInteger(
R.integer.episode_cache_size_unlimited)) {
s = getString(R.string.pref_episode_cache_unlimited);
} else {
s = Integer.toString(cacheSize)
+ getString(R.string.episodes_suffix);
}
findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setSummary(s);
}
private void setDataFolderText() { private void setEpisodeCacheSizeText(int cacheSize) {
File f = UserPreferences.getDataFolder(this, null); String s;
if (f != null) { if (cacheSize == getResources().getInteger(
findPreference(PREF_CHOOSE_DATA_DIR) R.integer.episode_cache_size_unlimited)) {
.setSummary(f.getAbsolutePath()); s = getString(R.string.pref_episode_cache_unlimited);
} } else {
} s = Integer.toString(cacheSize)
+ getString(R.string.episodes_suffix);
}
findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setSummary(s);
}
@Override private void setDataFolderText() {
public boolean onCreateOptionsMenu(Menu menu) { File f = UserPreferences.getDataFolder(this, null);
return true; if (f != null) {
} findPreference(PREF_CHOOSE_DATA_DIR)
.setSummary(f.getAbsolutePath());
}
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onCreateOptionsMenu(Menu menu) {
switch (item.getItemId()) { return true;
case android.R.id.home: }
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
break;
default:
return false;
}
return true;
}
@Override @Override
protected void onApplyThemeResource(Theme theme, int resid, boolean first) { public boolean onOptionsItemSelected(MenuItem item) {
theme.applyStyle(UserPreferences.getTheme(), true); switch (item.getItemId()) {
} case android.R.id.home:
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
break;
default:
return false;
}
return true;
}
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
super.onActivityResult(requestCode, resultCode, data); theme.applyStyle(UserPreferences.getTheme(), true);
if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) { }
String dir = data
.getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR);
if (AppConfig.DEBUG)
Log.d(TAG, "Setting data folder");
UserPreferences.setDataFolder(dir);
}
}
private void buildAutodownloadSelectedNetworsPreference() { @Override
if (selectedNetworks != null) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
clearAutodownloadSelectedNetworsPreference(); super.onActivityResult(requestCode, resultCode, data);
} if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) {
// get configured networks String dir = data
WifiManager wifiservice = (WifiManager) getSystemService(Context.WIFI_SERVICE); .getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR);
List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks(); if (AppConfig.DEBUG)
Log.d(TAG, "Setting data folder");
UserPreferences.setDataFolder(dir);
}
}
if (networks != null) { private void buildAutodownloadSelectedNetworsPreference() {
selectedNetworks = new CheckBoxPreference[networks.size()]; if (selectedNetworks != null) {
List<String> prefValues = Arrays.asList(UserPreferences clearAutodownloadSelectedNetworsPreference();
.getAutodownloadSelectedNetworks()); }
PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN); // get configured networks
OnPreferenceClickListener clickListener = new OnPreferenceClickListener() { WifiManager wifiservice = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks();
@Override if (networks != null) {
public boolean onPreferenceClick(Preference preference) { selectedNetworks = new CheckBoxPreference[networks.size()];
if (preference instanceof CheckBoxPreference) { List<String> prefValues = Arrays.asList(UserPreferences
String key = preference.getKey(); .getAutodownloadSelectedNetworks());
ArrayList<String> prefValuesList = new ArrayList<String>( PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN);
Arrays.asList(UserPreferences OnPreferenceClickListener clickListener = new OnPreferenceClickListener() {
.getAutodownloadSelectedNetworks()));
boolean newValue = ((CheckBoxPreference) preference)
.isChecked();
if (AppConfig.DEBUG)
Log.d(TAG, "Selected network " + key
+ ". New state: " + newValue);
int index = prefValuesList.indexOf(key); @Override
if (index >= 0 && newValue == false) { public boolean onPreferenceClick(Preference preference) {
// remove network if (preference instanceof CheckBoxPreference) {
prefValuesList.remove(index); String key = preference.getKey();
} else if (index < 0 && newValue == true) { ArrayList<String> prefValuesList = new ArrayList<String>(
prefValuesList.add(key); Arrays.asList(UserPreferences
} .getAutodownloadSelectedNetworks()));
boolean newValue = ((CheckBoxPreference) preference)
.isChecked();
if (AppConfig.DEBUG)
Log.d(TAG, "Selected network " + key
+ ". New state: " + newValue);
UserPreferences.setAutodownloadSelectedNetworks( int index = prefValuesList.indexOf(key);
PreferenceActivity.this, prefValuesList if (index >= 0 && newValue == false) {
.toArray(new String[prefValuesList // remove network
.size()])); prefValuesList.remove(index);
return true; } else if (index < 0 && newValue == true) {
} else { prefValuesList.add(key);
return false; }
}
}
};
// create preference for each known network. attach listener and set
// value
for (int i = 0; i < networks.size(); i++) {
WifiConfiguration config = networks.get(i);
CheckBoxPreference pref = new CheckBoxPreference(this); UserPreferences.setAutodownloadSelectedNetworks(
String key = Integer.toString(config.networkId); PreferenceActivity.this, prefValuesList
pref.setTitle(config.SSID); .toArray(new String[prefValuesList
pref.setKey(key); .size()]));
pref.setOnPreferenceClickListener(clickListener); return true;
pref.setPersistent(false); } else {
pref.setChecked(prefValues.contains(key)); return false;
selectedNetworks[i] = pref; }
prefScreen.addPreference(pref); }
} };
} else { // create preference for each known network. attach listener and set
Log.e(TAG, "Couldn't get list of configure Wi-Fi networks"); // value
} for (int i = 0; i < networks.size(); i++) {
} WifiConfiguration config = networks.get(i);
private void clearAutodownloadSelectedNetworsPreference() { CheckBoxPreference pref = new CheckBoxPreference(this);
if (selectedNetworks != null) { String key = Integer.toString(config.networkId);
PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN); pref.setTitle(config.SSID);
pref.setKey(key);
pref.setOnPreferenceClickListener(clickListener);
pref.setPersistent(false);
pref.setChecked(prefValues.contains(key));
selectedNetworks[i] = pref;
prefScreen.addPreference(pref);
}
} else {
Log.e(TAG, "Couldn't get list of configure Wi-Fi networks");
}
}
for (int i = 0; i < selectedNetworks.length; i++) { private void clearAutodownloadSelectedNetworsPreference() {
if (selectedNetworks[i] != null) { if (selectedNetworks != null) {
prefScreen.removePreference(selectedNetworks[i]); PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN);
}
}
}
}
@SuppressWarnings("deprecation") for (int i = 0; i < selectedNetworks.length; i++) {
@Override if (selectedNetworks[i] != null) {
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, prefScreen.removePreference(selectedNetworks[i]);
Preference preference) { }
super.onPreferenceTreeClick(preferenceScreen, preference); }
if (preference != null) }
if (preference instanceof PreferenceScreen) }
if (((PreferenceScreen) preference).getDialog() != null)
((PreferenceScreen) preference) @SuppressWarnings("deprecation")
.getDialog() @Override
.getWindow() public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
.getDecorView() Preference preference) {
.setBackgroundDrawable( super.onPreferenceTreeClick(preferenceScreen, preference);
this.getWindow().getDecorView() if (preference != null)
.getBackground().getConstantState() if (preference instanceof PreferenceScreen)
.newDrawable()); if (((PreferenceScreen) preference).getDialog() != null)
return false; ((PreferenceScreen) preference)
} .getDialog()
.getWindow()
.getDecorView()
.setBackgroundDrawable(
this.getWindow().getDecorView()
.getBackground().getConstantState()
.newDrawable());
return false;
}
} }

View File

@ -14,7 +14,6 @@ import android.os.AsyncTask;
import android.util.Log; import android.util.Log;
import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.opml.OpmlWriter; import de.danoeh.antennapod.opml.OpmlWriter;
import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.storage.DBReader; import de.danoeh.antennapod.storage.DBReader;

View File

@ -224,8 +224,8 @@ public class FeedMedia extends FeedFile implements Playable {
public void loadChapterMarks() { public void loadChapterMarks() {
if (getChapters() == null && !localFileAvailable()) { if (getChapters() == null && !localFileAvailable()) {
ChapterUtils.loadChaptersFromStreamUrl(this); ChapterUtils.loadChaptersFromStreamUrl(this);
if (getChapters() != null) { if (getChapters() != null && item != null) {
FeedManager.getInstance().setFeedItem(PodcastApp.getInstance(), DBWriter.setFeedItem(PodcastApp.getInstance(),
item); item);
} }
} }

View File

@ -26,7 +26,6 @@ import de.danoeh.antennapod.adapter.ExternalEpisodesListAdapter;
import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.EventDistributor;
import de.danoeh.antennapod.feed.FeedItem; import de.danoeh.antennapod.feed.FeedItem;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.storage.DBReader; import de.danoeh.antennapod.storage.DBReader;
import de.danoeh.antennapod.storage.DBTasks; import de.danoeh.antennapod.storage.DBTasks;
import de.danoeh.antennapod.storage.DBWriter; import de.danoeh.antennapod.storage.DBWriter;

View File

@ -7,7 +7,6 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.util.Log; import android.util.Log;
import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.storage.DBTasks; import de.danoeh.antennapod.storage.DBTasks;
import de.danoeh.antennapod.storage.DownloadRequester; import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.util.NetworkUtils; import de.danoeh.antennapod.util.NetworkUtils;

View File

@ -7,7 +7,6 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.util.Log; import android.util.Log;
import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.storage.DBTasks; import de.danoeh.antennapod.storage.DBTasks;