diff options
7 files changed, 488 insertions, 474 deletions
diff --git a/src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java b/src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java index f9fe912cd..eae54f712 100644 --- a/src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java +++ b/src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java @@ -1,6 +1,7 @@ package de.danoeh.antennapod.activity; import java.util.Date; +import java.util.List; import android.annotation.SuppressLint; import android.content.Intent; @@ -25,11 +26,11 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.MiroGuideItemlistAdapter; import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; 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.MiroGuideService; import de.danoeh.antennapod.miroguide.model.MiroGuideChannel; import de.danoeh.antennapod.preferences.UserPreferences; +import de.danoeh.antennapod.storage.DBReader; import de.danoeh.antennapod.storage.DownloadRequestException; import de.danoeh.antennapod.storage.DownloadRequester; @@ -38,146 +39,163 @@ import de.danoeh.antennapod.storage.DownloadRequester; * his library. */ public class MiroGuideChannelViewActivity extends SherlockActivity { - private static final String TAG = "MiroGuideChannelViewActivity"; - - public static final String EXTRA_CHANNEL_ID = "id"; - public static final String EXTRA_CHANNEL_URL = "url"; - - private RelativeLayout layoutContent; - private ProgressBar progLoading; - private TextView txtvTitle; - private TextView txtVDescription; - private ListView listEntries; - - private long channelId; - private String channelUrl; - private MiroGuideChannel channel; - - @Override - protected void onPause() { - super.onPause(); - channelLoader.cancel(true); - } - - @SuppressLint("NewApi") - @Override - protected void onCreate(Bundle savedInstanceState) { - setTheme(UserPreferences.getTheme()); - super.onCreate(savedInstanceState); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - setContentView(R.layout.miroguide_channelview); - - layoutContent = (RelativeLayout) findViewById(R.id.layout_content); - progLoading = (ProgressBar) findViewById(R.id.progLoading); - txtvTitle = (TextView) findViewById(R.id.txtvTitle); - txtVDescription = (TextView) findViewById(R.id.txtvDescription); - listEntries = (ListView) findViewById(R.id.itemlist); - - channelId = getIntent().getLongExtra(EXTRA_CHANNEL_ID, -1); - channelUrl = getIntent().getStringExtra(EXTRA_CHANNEL_URL); - - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - channelLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - channelLoader.execute(); - } - - } - - /** Is used to load channel information asynchronously. */ - private AsyncTask<Void, Void, Void> channelLoader = new AsyncTask<Void, Void, Void>() { - private static final String TAG = "ChannelLoader"; - private Exception exception; - - @Override - protected Void doInBackground(Void... params) { - if (AppConfig.DEBUG) - Log.d(TAG, "Starting background task"); - MiroGuideService service = new MiroGuideService(); - try { - channel = service.getChannel(channelId); - } catch (MiroGuideException e) { - e.printStackTrace(); - exception = e; - } - return null; - } - - @SuppressLint("NewApi") - @Override - protected void onPostExecute(Void result) { - if (AppConfig.DEBUG) - Log.d(TAG, "Loading finished"); - if (exception == null) { - txtvTitle.setText(channel.getName()); - txtVDescription.setText(channel.getDescription()); - - MiroGuideItemlistAdapter listAdapter = new MiroGuideItemlistAdapter( - MiroGuideChannelViewActivity.this, 0, - channel.getItems()); - listEntries.setAdapter(listAdapter); - progLoading.setVisibility(View.GONE); - layoutContent.setVisibility(View.VISIBLE); - supportInvalidateOptionsMenu(); - } else { - finish(); - } - } - - }; - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = new MenuInflater(this); - inflater.inflate(R.menu.channelview, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - boolean channelLoaded = channel != null; - boolean beingDownloaded = channelLoaded - && DownloadRequester.getInstance().isDownloadingFile( - channel.getDownloadUrl()); - boolean notAdded = channelLoaded - && !((FeedManager.getInstance().feedExists( - channel.getDownloadUrl()) || beingDownloaded)); - menu.findItem(R.id.add_feed).setVisible(notAdded); - menu.findItem(R.id.visit_website_item).setVisible( - channelLoaded && channel.getWebsiteUrl() != null); - return true; - } - - @SuppressLint("NewApi") - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - finish(); - return true; - case R.id.visit_website_item: - Uri uri = Uri.parse(channel.getWebsiteUrl()); - startActivity(new Intent(Intent.ACTION_VIEW, uri)); - return true; - case R.id.add_feed: - try { - DownloadRequester.getInstance().downloadFeed( - this, - new Feed(channel.getDownloadUrl(), new Date(), channel - .getName())); - } catch (DownloadRequestException e) { - e.printStackTrace(); - DownloadRequestErrorDialogCreator.newRequestErrorDialog(this, - e.getMessage()); - } - Toast toast = Toast.makeText(this, R.string.miro_feed_added, - Toast.LENGTH_LONG); - toast.show(); - supportInvalidateOptionsMenu(); - return true; - default: - return false; - } - } + private static final String TAG = "MiroGuideChannelViewActivity"; + + public static final String EXTRA_CHANNEL_ID = "id"; + public static final String EXTRA_CHANNEL_URL = "url"; + + private RelativeLayout layoutContent; + private ProgressBar progLoading; + private TextView txtvTitle; + private TextView txtVDescription; + private ListView listEntries; + + private long channelId; + private String channelUrl; + private MiroGuideChannel channel; + private volatile List<Feed> feeds; + + @Override + protected void onPause() { + super.onPause(); + channelLoader.cancel(true); + } + + @SuppressLint("NewApi") + @Override + protected void onCreate(Bundle savedInstanceState) { + setTheme(UserPreferences.getTheme()); + super.onCreate(savedInstanceState); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + setContentView(R.layout.miroguide_channelview); + + layoutContent = (RelativeLayout) findViewById(R.id.layout_content); + progLoading = (ProgressBar) findViewById(R.id.progLoading); + txtvTitle = (TextView) findViewById(R.id.txtvTitle); + txtVDescription = (TextView) findViewById(R.id.txtvDescription); + listEntries = (ListView) findViewById(R.id.itemlist); + + channelId = getIntent().getLongExtra(EXTRA_CHANNEL_ID, -1); + channelUrl = getIntent().getStringExtra(EXTRA_CHANNEL_URL); + + if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { + channelLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + channelLoader.execute(); + } + + } + + /** + * Is used to load channel information asynchronously. + */ + private AsyncTask<Void, Void, Void> channelLoader = new AsyncTask<Void, Void, Void>() { + private static final String TAG = "ChannelLoader"; + private Exception exception; + + @Override + protected Void doInBackground(Void... params) { + if (AppConfig.DEBUG) + Log.d(TAG, "Starting background task"); + feeds = DBReader.getFeedList(MiroGuideChannelViewActivity.this); + MiroGuideService service = new MiroGuideService(); + try { + channel = service.getChannel(channelId); + } catch (MiroGuideException e) { + e.printStackTrace(); + exception = e; + } + return null; + } + + @SuppressLint("NewApi") + @Override + protected void onPostExecute(Void result) { + if (AppConfig.DEBUG) + Log.d(TAG, "Loading finished"); + if (exception == null) { + txtvTitle.setText(channel.getName()); + txtVDescription.setText(channel.getDescription()); + + MiroGuideItemlistAdapter listAdapter = new MiroGuideItemlistAdapter( + MiroGuideChannelViewActivity.this, 0, + channel.getItems()); + listEntries.setAdapter(listAdapter); + progLoading.setVisibility(View.GONE); + layoutContent.setVisibility(View.VISIBLE); + supportInvalidateOptionsMenu(); + } else { + finish(); + } + } + + }; + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = new MenuInflater(this); + inflater.inflate(R.menu.channelview, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + boolean channelLoaded = channel != null; + boolean beingDownloaded = channelLoaded + && DownloadRequester.getInstance().isDownloadingFile( + channel.getDownloadUrl()); + boolean notAdded = channelLoaded + && !((feedExists( + channel.getDownloadUrl()) || beingDownloaded)); + menu.findItem(R.id.add_feed).setVisible(notAdded); + menu.findItem(R.id.visit_website_item).setVisible( + channelLoaded && channel.getWebsiteUrl() != null); + return true; + } + + @SuppressLint("NewApi") + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + case R.id.visit_website_item: + Uri uri = Uri.parse(channel.getWebsiteUrl()); + startActivity(new Intent(Intent.ACTION_VIEW, uri)); + return true; + case R.id.add_feed: + try { + DownloadRequester.getInstance().downloadFeed( + this, + new Feed(channel.getDownloadUrl(), new Date(), channel + .getName())); + } catch (DownloadRequestException e) { + e.printStackTrace(); + DownloadRequestErrorDialogCreator.newRequestErrorDialog(this, + e.getMessage()); + } + Toast toast = Toast.makeText(this, R.string.miro_feed_added, + Toast.LENGTH_LONG); + toast.show(); + supportInvalidateOptionsMenu(); + return true; + default: + 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; + } } diff --git a/src/de/danoeh/antennapod/activity/PreferenceActivity.java b/src/de/danoeh/antennapod/activity/PreferenceActivity.java index c59b14c03..14d9c29cc 100644 --- a/src/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/src/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -26,334 +26,334 @@ import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.asynctask.FlattrClickWorker; import de.danoeh.antennapod.asynctask.OpmlExportWorker; -import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.util.flattr.FlattrUtils; -/** The main preference activity */ +/** + * The main preference activity + */ public class PreferenceActivity extends SherlockPreferenceActivity { - private static final String TAG = "PreferenceActivity"; - - 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_REVOKE = "prefRevokeAccess"; - private static final String PREF_OPML_EXPORT = "prefOpmlExport"; - private static final String PREF_ABOUT = "prefAbout"; - private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir"; - private static final String AUTO_DL_PREF_SCREEN = "prefAutoDownloadSettings"; - - private CheckBoxPreference[] selectedNetworks; - - @SuppressWarnings("deprecation") - @Override - public void onCreate(Bundle savedInstanceState) { - setTheme(UserPreferences.getTheme()); - super.onCreate(savedInstanceState); - - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - addPreferencesFromResource(R.xml.preferences); - findPreference(PREF_FLATTR_THIS_APP).setOnPreferenceClickListener( - new OnPreferenceClickListener() { - - @Override - public boolean onPreferenceClick(Preference preference) { - new FlattrClickWorker(PreferenceActivity.this, - FlattrUtils.APP_URL).executeAsync(); - - return true; - } - }); - - findPreference(PREF_FLATTR_REVOKE).setOnPreferenceClickListener( - new OnPreferenceClickListener() { - - @Override - public boolean onPreferenceClick(Preference preference) { - FlattrUtils.revokeAccessToken(PreferenceActivity.this); - checkItemVisibility(); - return true; - } - - }); - - findPreference(PREF_ABOUT).setOnPreferenceClickListener( - new OnPreferenceClickListener() { - - @Override - public boolean onPreferenceClick(Preference preference) { - PreferenceActivity.this.startActivity(new Intent( - PreferenceActivity.this, AboutActivity.class)); - return true; - } - - }); - - findPreference(PREF_OPML_EXPORT).setOnPreferenceClickListener( - new OnPreferenceClickListener() { - - @Override - public boolean onPreferenceClick(Preference preference) { - if (FeedManager.getInstance().getFeedsSize() > 0) { - new OpmlExportWorker(PreferenceActivity.this) - .executeAsync(); - } - return true; - } - }); - - findPreference(PREF_CHOOSE_DATA_DIR).setOnPreferenceClickListener( - new OnPreferenceClickListener() { - - @Override - public boolean onPreferenceClick(Preference preference) { - startActivityForResult( - new Intent(PreferenceActivity.this, - DirectoryChooserActivity.class), - DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED); - return true; - } - }); - findPreference(UserPreferences.PREF_THEME) - .setOnPreferenceChangeListener( - new OnPreferenceChangeListener() { - - @Override - public boolean onPreferenceChange( - Preference preference, Object newValue) { - Intent i = getIntent(); - i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK - | Intent.FLAG_ACTIVITY_NEW_TASK); - finish(); - startActivity(i); - return true; - } - }); - findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER) - .setOnPreferenceChangeListener( - new OnPreferenceChangeListener() { - - @Override - public boolean onPreferenceChange( - Preference preference, Object newValue) { - if (newValue instanceof Boolean) { - setSelectedNetworksEnabled((Boolean) newValue); - return true; - } else { - return false; - } - } - }); - findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE) - .setOnPreferenceChangeListener( - new OnPreferenceChangeListener() { - - @Override - public boolean onPreferenceChange( - Preference preference, Object newValue) { - if (newValue instanceof String) { - setEpisodeCacheSizeText(Integer - .valueOf((String) newValue)); - } - return true; - } - }); - findPreference(UserPreferences.PREF_ENABLE_AUTODL) - .setOnPreferenceClickListener(new OnPreferenceClickListener() { - - @Override - public boolean onPreferenceClick(Preference preference) { - checkItemVisibility(); - return true; - } - }); - - buildAutodownloadSelectedNetworsPreference(); - setSelectedNetworksEnabled(UserPreferences - .isEnableAutodownloadWifiFilter()); - - } - - private void setSelectedNetworksEnabled(boolean b) { - if (selectedNetworks != null) { - for (Preference p : selectedNetworks) { - p.setEnabled(b); - } - } - } - - @Override - protected void onResume() { - super.onResume(); - checkItemVisibility(); - setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize()); - setDataFolderText(); - } - - @SuppressWarnings("deprecation") - private void checkItemVisibility() { - - boolean hasFlattrToken = FlattrUtils.hasToken(); - - findPreference(PREF_FLATTR_AUTH).setEnabled(!hasFlattrToken); - findPreference(PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken); - - 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() { - File f = UserPreferences.getDataFolder(this, null); - if (f != null) { - findPreference(PREF_CHOOSE_DATA_DIR) - .setSummary(f.getAbsolutePath()); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - 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 - protected void onApplyThemeResource(Theme theme, int resid, boolean first) { - theme.applyStyle(UserPreferences.getTheme(), true); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - 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() { - if (selectedNetworks != null) { - clearAutodownloadSelectedNetworsPreference(); - } - // get configured networks - WifiManager wifiservice = (WifiManager) getSystemService(Context.WIFI_SERVICE); - List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks(); - - if (networks != null) { - selectedNetworks = new CheckBoxPreference[networks.size()]; - List<String> prefValues = Arrays.asList(UserPreferences - .getAutodownloadSelectedNetworks()); - PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN); - OnPreferenceClickListener clickListener = new OnPreferenceClickListener() { - - @Override - public boolean onPreferenceClick(Preference preference) { - if (preference instanceof CheckBoxPreference) { - String key = preference.getKey(); - ArrayList<String> prefValuesList = new ArrayList<String>( - Arrays.asList(UserPreferences - .getAutodownloadSelectedNetworks())); - boolean newValue = ((CheckBoxPreference) preference) - .isChecked(); - if (AppConfig.DEBUG) - Log.d(TAG, "Selected network " + key - + ". New state: " + newValue); - - int index = prefValuesList.indexOf(key); - if (index >= 0 && newValue == false) { - // remove network - prefValuesList.remove(index); - } else if (index < 0 && newValue == true) { - prefValuesList.add(key); - } - - UserPreferences.setAutodownloadSelectedNetworks( - PreferenceActivity.this, prefValuesList - .toArray(new String[prefValuesList - .size()])); - return true; - } else { - 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); - String key = Integer.toString(config.networkId); - 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"); - } - } - - private void clearAutodownloadSelectedNetworsPreference() { - if (selectedNetworks != null) { - PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN); - - for (int i = 0; i < selectedNetworks.length; i++) { - if (selectedNetworks[i] != null) { - prefScreen.removePreference(selectedNetworks[i]); - } - } - } - } - - @SuppressWarnings("deprecation") - @Override - public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, - Preference preference) { - super.onPreferenceTreeClick(preferenceScreen, preference); - if (preference != null) - if (preference instanceof PreferenceScreen) - if (((PreferenceScreen) preference).getDialog() != null) - ((PreferenceScreen) preference) - .getDialog() - .getWindow() - .getDecorView() - .setBackgroundDrawable( - this.getWindow().getDecorView() - .getBackground().getConstantState() - .newDrawable()); - return false; - } + private static final String TAG = "PreferenceActivity"; + + 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_REVOKE = "prefRevokeAccess"; + private static final String PREF_OPML_EXPORT = "prefOpmlExport"; + private static final String PREF_ABOUT = "prefAbout"; + private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir"; + private static final String AUTO_DL_PREF_SCREEN = "prefAutoDownloadSettings"; + + private CheckBoxPreference[] selectedNetworks; + + @SuppressWarnings("deprecation") + @Override + public void onCreate(Bundle savedInstanceState) { + setTheme(UserPreferences.getTheme()); + super.onCreate(savedInstanceState); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + addPreferencesFromResource(R.xml.preferences); + findPreference(PREF_FLATTR_THIS_APP).setOnPreferenceClickListener( + new OnPreferenceClickListener() { + + @Override + public boolean onPreferenceClick(Preference preference) { + new FlattrClickWorker(PreferenceActivity.this, + FlattrUtils.APP_URL).executeAsync(); + + return true; + } + }); + + findPreference(PREF_FLATTR_REVOKE).setOnPreferenceClickListener( + new OnPreferenceClickListener() { + + @Override + public boolean onPreferenceClick(Preference preference) { + FlattrUtils.revokeAccessToken(PreferenceActivity.this); + checkItemVisibility(); + return true; + } + + }); + + findPreference(PREF_ABOUT).setOnPreferenceClickListener( + new OnPreferenceClickListener() { + + @Override + public boolean onPreferenceClick(Preference preference) { + PreferenceActivity.this.startActivity(new Intent( + PreferenceActivity.this, AboutActivity.class)); + return true; + } + + }); + + findPreference(PREF_OPML_EXPORT).setOnPreferenceClickListener( + new OnPreferenceClickListener() { + + @Override + public boolean onPreferenceClick(Preference preference) { + new OpmlExportWorker(PreferenceActivity.this) + .executeAsync(); + + return true; + } + }); + + findPreference(PREF_CHOOSE_DATA_DIR).setOnPreferenceClickListener( + new OnPreferenceClickListener() { + + @Override + public boolean onPreferenceClick(Preference preference) { + startActivityForResult( + new Intent(PreferenceActivity.this, + DirectoryChooserActivity.class), + DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED); + return true; + } + }); + findPreference(UserPreferences.PREF_THEME) + .setOnPreferenceChangeListener( + new OnPreferenceChangeListener() { + + @Override + public boolean onPreferenceChange( + Preference preference, Object newValue) { + Intent i = getIntent(); + i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK + | Intent.FLAG_ACTIVITY_NEW_TASK); + finish(); + startActivity(i); + return true; + } + }); + findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER) + .setOnPreferenceChangeListener( + new OnPreferenceChangeListener() { + + @Override + public boolean onPreferenceChange( + Preference preference, Object newValue) { + if (newValue instanceof Boolean) { + setSelectedNetworksEnabled((Boolean) newValue); + return true; + } else { + return false; + } + } + }); + findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE) + .setOnPreferenceChangeListener( + new OnPreferenceChangeListener() { + + @Override + public boolean onPreferenceChange( + Preference preference, Object newValue) { + if (newValue instanceof String) { + setEpisodeCacheSizeText(Integer + .valueOf((String) newValue)); + } + return true; + } + }); + findPreference(UserPreferences.PREF_ENABLE_AUTODL) + .setOnPreferenceClickListener(new OnPreferenceClickListener() { + + @Override + public boolean onPreferenceClick(Preference preference) { + checkItemVisibility(); + return true; + } + }); + + buildAutodownloadSelectedNetworsPreference(); + setSelectedNetworksEnabled(UserPreferences + .isEnableAutodownloadWifiFilter()); + + } + + private void setSelectedNetworksEnabled(boolean b) { + if (selectedNetworks != null) { + for (Preference p : selectedNetworks) { + p.setEnabled(b); + } + } + } + + @Override + protected void onResume() { + super.onResume(); + checkItemVisibility(); + setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize()); + setDataFolderText(); + } + + @SuppressWarnings("deprecation") + private void checkItemVisibility() { + + boolean hasFlattrToken = FlattrUtils.hasToken(); + + findPreference(PREF_FLATTR_AUTH).setEnabled(!hasFlattrToken); + findPreference(PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken); + + 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() { + File f = UserPreferences.getDataFolder(this, null); + if (f != null) { + findPreference(PREF_CHOOSE_DATA_DIR) + .setSummary(f.getAbsolutePath()); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + 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 + protected void onApplyThemeResource(Theme theme, int resid, boolean first) { + theme.applyStyle(UserPreferences.getTheme(), true); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + 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() { + if (selectedNetworks != null) { + clearAutodownloadSelectedNetworsPreference(); + } + // get configured networks + WifiManager wifiservice = (WifiManager) getSystemService(Context.WIFI_SERVICE); + List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks(); + + if (networks != null) { + selectedNetworks = new CheckBoxPreference[networks.size()]; + List<String> prefValues = Arrays.asList(UserPreferences + .getAutodownloadSelectedNetworks()); + PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN); + OnPreferenceClickListener clickListener = new OnPreferenceClickListener() { + + @Override + public boolean onPreferenceClick(Preference preference) { + if (preference instanceof CheckBoxPreference) { + String key = preference.getKey(); + ArrayList<String> prefValuesList = new ArrayList<String>( + Arrays.asList(UserPreferences + .getAutodownloadSelectedNetworks())); + boolean newValue = ((CheckBoxPreference) preference) + .isChecked(); + if (AppConfig.DEBUG) + Log.d(TAG, "Selected network " + key + + ". New state: " + newValue); + + int index = prefValuesList.indexOf(key); + if (index >= 0 && newValue == false) { + // remove network + prefValuesList.remove(index); + } else if (index < 0 && newValue == true) { + prefValuesList.add(key); + } + + UserPreferences.setAutodownloadSelectedNetworks( + PreferenceActivity.this, prefValuesList + .toArray(new String[prefValuesList + .size()])); + return true; + } else { + 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); + String key = Integer.toString(config.networkId); + 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"); + } + } + + private void clearAutodownloadSelectedNetworsPreference() { + if (selectedNetworks != null) { + PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN); + + for (int i = 0; i < selectedNetworks.length; i++) { + if (selectedNetworks[i] != null) { + prefScreen.removePreference(selectedNetworks[i]); + } + } + } + } + + @SuppressWarnings("deprecation") + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, + Preference preference) { + super.onPreferenceTreeClick(preferenceScreen, preference); + if (preference != null) + if (preference instanceof PreferenceScreen) + if (((PreferenceScreen) preference).getDialog() != null) + ((PreferenceScreen) preference) + .getDialog() + .getWindow() + .getDecorView() + .setBackgroundDrawable( + this.getWindow().getDecorView() + .getBackground().getConstantState() + .newDrawable()); + return false; + } } diff --git a/src/de/danoeh/antennapod/asynctask/OpmlExportWorker.java b/src/de/danoeh/antennapod/asynctask/OpmlExportWorker.java index 0ae328378..e14e22917 100644 --- a/src/de/danoeh/antennapod/asynctask/OpmlExportWorker.java +++ b/src/de/danoeh/antennapod/asynctask/OpmlExportWorker.java @@ -14,7 +14,6 @@ import android.os.AsyncTask; import android.util.Log; import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.opml.OpmlWriter; import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.storage.DBReader; diff --git a/src/de/danoeh/antennapod/feed/FeedMedia.java b/src/de/danoeh/antennapod/feed/FeedMedia.java index f9b9f9aa8..2e0eac7a4 100644 --- a/src/de/danoeh/antennapod/feed/FeedMedia.java +++ b/src/de/danoeh/antennapod/feed/FeedMedia.java @@ -224,8 +224,8 @@ public class FeedMedia extends FeedFile implements Playable { public void loadChapterMarks() { if (getChapters() == null && !localFileAvailable()) { ChapterUtils.loadChaptersFromStreamUrl(this); - if (getChapters() != null) { - FeedManager.getInstance().setFeedItem(PodcastApp.getInstance(), + if (getChapters() != null && item != null) { + DBWriter.setFeedItem(PodcastApp.getInstance(), item); } } diff --git a/src/de/danoeh/antennapod/fragment/EpisodesFragment.java b/src/de/danoeh/antennapod/fragment/EpisodesFragment.java index 3acc39143..c3cfb6557 100644 --- a/src/de/danoeh/antennapod/fragment/EpisodesFragment.java +++ b/src/de/danoeh/antennapod/fragment/EpisodesFragment.java @@ -26,7 +26,6 @@ import de.danoeh.antennapod.adapter.ExternalEpisodesListAdapter; import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.FeedItem; -import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.storage.DBReader; import de.danoeh.antennapod.storage.DBTasks; import de.danoeh.antennapod.storage.DBWriter; diff --git a/src/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java b/src/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java index bbc8880a0..aebe5a681 100644 --- a/src/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java +++ b/src/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java @@ -7,7 +7,6 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; import de.danoeh.antennapod.AppConfig; -import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.storage.DBTasks; import de.danoeh.antennapod.storage.DownloadRequester; import de.danoeh.antennapod.util.NetworkUtils; diff --git a/src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java b/src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java index 6e0f4c52a..fdbaa97f0 100644 --- a/src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java +++ b/src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java @@ -7,7 +7,6 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; import de.danoeh.antennapod.AppConfig; -import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.storage.DBTasks; |