Removed last references to FeedManager
This commit is contained in:
parent
24c50f7840
commit
edd84c6a4c
|
@ -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";
|
||||
private static final String TAG = "MiroGuideChannelViewActivity";
|
||||
|
||||
public static final String EXTRA_CHANNEL_ID = "id";
|
||||
public static final String EXTRA_CHANNEL_URL = "url";
|
||||
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 RelativeLayout layoutContent;
|
||||
private ProgressBar progLoading;
|
||||
private TextView txtvTitle;
|
||||
private TextView txtVDescription;
|
||||
private ListView listEntries;
|
||||
|
||||
private long channelId;
|
||||
private String channelUrl;
|
||||
private MiroGuideChannel channel;
|
||||
private long channelId;
|
||||
private String channelUrl;
|
||||
private MiroGuideChannel channel;
|
||||
private volatile List<Feed> feeds;
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
channelLoader.cancel(true);
|
||||
}
|
||||
@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);
|
||||
@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);
|
||||
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);
|
||||
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();
|
||||
}
|
||||
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;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
@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());
|
||||
@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();
|
||||
}
|
||||
}
|
||||
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 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;
|
||||
}
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 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 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;
|
||||
private CheckBoxPreference[] selectedNetworks;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(UserPreferences.getTheme());
|
||||
super.onCreate(savedInstanceState);
|
||||
@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() {
|
||||
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();
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
new FlattrClickWorker(PreferenceActivity.this,
|
||||
FlattrUtils.APP_URL).executeAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
findPreference(PREF_FLATTR_REVOKE).setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
findPreference(PREF_FLATTR_REVOKE).setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
FlattrUtils.revokeAccessToken(PreferenceActivity.this);
|
||||
checkItemVisibility();
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
FlattrUtils.revokeAccessToken(PreferenceActivity.this);
|
||||
checkItemVisibility();
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
findPreference(PREF_ABOUT).setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
findPreference(PREF_ABOUT).setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
PreferenceActivity.this.startActivity(new Intent(
|
||||
PreferenceActivity.this, AboutActivity.class));
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
PreferenceActivity.this.startActivity(new Intent(
|
||||
PreferenceActivity.this, AboutActivity.class));
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
findPreference(PREF_OPML_EXPORT).setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
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;
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
new OpmlExportWorker(PreferenceActivity.this)
|
||||
.executeAsync();
|
||||
|
||||
findPreference(PREF_CHOOSE_DATA_DIR).setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
@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() {
|
||||
findPreference(PREF_CHOOSE_DATA_DIR).setOnPreferenceClickListener(
|
||||
new OnPreferenceClickListener() {
|
||||
|
||||
@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 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) {
|
||||
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) {
|
||||
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 String) {
|
||||
setEpisodeCacheSizeText(Integer
|
||||
.valueOf((String) newValue));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
findPreference(UserPreferences.PREF_ENABLE_AUTODL)
|
||||
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@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 onPreferenceClick(Preference preference) {
|
||||
checkItemVisibility();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@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() {
|
||||
|
||||
buildAutodownloadSelectedNetworsPreference();
|
||||
setSelectedNetworksEnabled(UserPreferences
|
||||
.isEnableAutodownloadWifiFilter());
|
||||
@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();
|
||||
}
|
||||
private void setSelectedNetworksEnabled(boolean b) {
|
||||
if (selectedNetworks != null) {
|
||||
for (Preference p : selectedNetworks) {
|
||||
p.setEnabled(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void checkItemVisibility() {
|
||||
@Override
|
||||
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);
|
||||
findPreference(PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken);
|
||||
boolean hasFlattrToken = FlattrUtils.hasToken();
|
||||
|
||||
findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER)
|
||||
.setEnabled(UserPreferences.isEnableAutodownload());
|
||||
setSelectedNetworksEnabled(UserPreferences.isEnableAutodownload()
|
||||
&& UserPreferences.isEnableAutodownloadWifiFilter());
|
||||
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());
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
return true;
|
||||
}
|
||||
private void setDataFolderText() {
|
||||
File f = UserPreferences.getDataFolder(this, null);
|
||||
if (f != null) {
|
||||
findPreference(PREF_CHOOSE_DATA_DIR)
|
||||
.setSummary(f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
@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
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
|
||||
theme.applyStyle(UserPreferences.getTheme(), 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 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);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
|
||||
theme.applyStyle(UserPreferences.getTheme(), true);
|
||||
}
|
||||
|
||||
private void buildAutodownloadSelectedNetworsPreference() {
|
||||
if (selectedNetworks != null) {
|
||||
clearAutodownloadSelectedNetworsPreference();
|
||||
}
|
||||
// get configured networks
|
||||
WifiManager wifiservice = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks();
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
private void buildAutodownloadSelectedNetworsPreference() {
|
||||
if (selectedNetworks != null) {
|
||||
clearAutodownloadSelectedNetworsPreference();
|
||||
}
|
||||
// get configured networks
|
||||
WifiManager wifiservice = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks();
|
||||
|
||||
@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);
|
||||
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() {
|
||||
|
||||
int index = prefValuesList.indexOf(key);
|
||||
if (index >= 0 && newValue == false) {
|
||||
// remove network
|
||||
prefValuesList.remove(index);
|
||||
} else if (index < 0 && newValue == true) {
|
||||
prefValuesList.add(key);
|
||||
}
|
||||
@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);
|
||||
|
||||
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);
|
||||
int index = prefValuesList.indexOf(key);
|
||||
if (index >= 0 && newValue == false) {
|
||||
// remove network
|
||||
prefValuesList.remove(index);
|
||||
} else if (index < 0 && newValue == true) {
|
||||
prefValuesList.add(key);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
private void clearAutodownloadSelectedNetworsPreference() {
|
||||
if (selectedNetworks != null) {
|
||||
PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN);
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < selectedNetworks.length; i++) {
|
||||
if (selectedNetworks[i] != null) {
|
||||
prefScreen.removePreference(selectedNetworks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void clearAutodownloadSelectedNetworsPreference() {
|
||||
if (selectedNetworks != null) {
|
||||
PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN);
|
||||
|
||||
@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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue