commit
d394996970
|
@ -72,20 +72,6 @@ public class HTTPBin extends NanoHTTPD {
|
|||
return servedFiles.size() - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the file with the given ID from the server.
|
||||
*
|
||||
* @return True if a file was removed, false otherwise
|
||||
*/
|
||||
public synchronized boolean removeFile(int id) {
|
||||
if (id < 0) throw new IllegalArgumentException("ID < 0");
|
||||
if (id >= servedFiles.size()) {
|
||||
return false;
|
||||
} else {
|
||||
return servedFiles.remove(id) != null;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized File accessFile(int id) {
|
||||
if (id < 0 || id >= servedFiles.size()) {
|
||||
return null;
|
||||
|
|
|
@ -7,212 +7,9 @@ import android.support.v7.app.AppCompatActivity;
|
|||
* network.
|
||||
*/
|
||||
public abstract class CastEnabledActivity extends AppCompatActivity {
|
||||
// implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public static final String TAG = "CastEnabledActivity";
|
||||
|
||||
// protected CastManager castManager;
|
||||
// protected SwitchableMediaRouteActionProvider mediaRouteActionProvider;
|
||||
// private final CastButtonVisibilityManager castButtonVisibilityManager = new CastButtonVisibilityManager();
|
||||
//
|
||||
// @Override
|
||||
// protected void onCreate(Bundle savedInstanceState) {
|
||||
// super.onCreate(savedInstanceState);
|
||||
//
|
||||
// PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).
|
||||
// registerOnSharedPreferenceChangeListener(this);
|
||||
//
|
||||
// castManager = CastManager.getInstance();
|
||||
// castManager.addCastConsumer(castConsumer);
|
||||
// castButtonVisibilityManager.setPrefEnabled(UserPreferences.isCastEnabled());
|
||||
// onCastConnectionChanged(castManager.isConnected());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onDestroy() {
|
||||
// PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
|
||||
// .unregisterOnSharedPreferenceChangeListener(this);
|
||||
// castManager.removeCastConsumer(castConsumer);
|
||||
// super.onDestroy();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @CallSuper
|
||||
// public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// super.onCreateOptionsMenu(menu);
|
||||
// getMenuInflater().inflate(R.menu.cast_enabled, menu);
|
||||
// castButtonVisibilityManager.setMenu(menu);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @CallSuper
|
||||
// public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
// super.onPrepareOptionsMenu(menu);
|
||||
// mediaRouteActionProvider = castManager
|
||||
// .addMediaRouterButton(menu.findItem(R.id.media_route_menu_item));
|
||||
// mediaRouteActionProvider.setEnabled(castButtonVisibilityManager.shouldEnable());
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onResume() {
|
||||
// super.onResume();
|
||||
// castButtonVisibilityManager.setResumed(true);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPause() {
|
||||
// super.onPause();
|
||||
// castButtonVisibilityManager.setResumed(false);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
// if (UserPreferences.PREF_CAST_ENABLED.equals(key)) {
|
||||
// boolean newValue = UserPreferences.isCastEnabled();
|
||||
// Log.d(TAG, "onSharedPreferenceChanged(), isCastEnabled set to " + newValue);
|
||||
// castButtonVisibilityManager.setPrefEnabled(newValue);
|
||||
// // PlaybackService has its own listener, so if it's active we don't have to take action here.
|
||||
// if (!newValue && !PlaybackService.isRunning) {
|
||||
// CastManager.getInstance().disconnect();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// CastConsumer castConsumer = new DefaultCastConsumer() {
|
||||
// @Override
|
||||
// public void onApplicationConnected(ApplicationMetadata appMetadata, String sessionId, boolean wasLaunched) {
|
||||
// onCastConnectionChanged(true);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onDisconnected() {
|
||||
// onCastConnectionChanged(false);
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// private void onCastConnectionChanged(boolean connected) {
|
||||
// if (connected) {
|
||||
// castButtonVisibilityManager.onConnected();
|
||||
// setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);
|
||||
// } else {
|
||||
// castButtonVisibilityManager.onDisconnected();
|
||||
// setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Should be called by any activity or fragment for which the cast button should be shown.
|
||||
// *
|
||||
// * @param showAsAction refer to {@link MenuItem#setShowAsAction(int)}
|
||||
// */
|
||||
public final void requestCastButton(int showAsAction) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
// private class CastButtonVisibilityManager {
|
||||
// private volatile boolean prefEnabled = false;
|
||||
// private volatile boolean viewRequested = false;
|
||||
// private volatile boolean resumed = false;
|
||||
// private volatile boolean connected = false;
|
||||
// private volatile int showAsAction = MenuItem.SHOW_AS_ACTION_IF_ROOM;
|
||||
// private Menu menu;
|
||||
//
|
||||
// public synchronized void setPrefEnabled(boolean newValue) {
|
||||
// if (prefEnabled != newValue && resumed && (viewRequested || connected)) {
|
||||
// if (newValue) {
|
||||
// castManager.incrementUiCounter();
|
||||
// } else {
|
||||
// castManager.decrementUiCounter();
|
||||
// }
|
||||
// }
|
||||
// prefEnabled = newValue;
|
||||
// if (mediaRouteActionProvider != null) {
|
||||
// mediaRouteActionProvider.setEnabled(prefEnabled && (viewRequested || connected));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public synchronized void setResumed(boolean newValue) {
|
||||
// if (resumed == newValue) {
|
||||
// Log.e(TAG, "resumed should never change to the same value");
|
||||
// return;
|
||||
// }
|
||||
// resumed = newValue;
|
||||
// if (prefEnabled && (viewRequested || connected)) {
|
||||
// if (resumed) {
|
||||
// castManager.incrementUiCounter();
|
||||
// } else {
|
||||
// castManager.decrementUiCounter();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public synchronized void setViewRequested(boolean newValue) {
|
||||
// if (viewRequested != newValue && resumed && prefEnabled && !connected) {
|
||||
// if (newValue) {
|
||||
// castManager.incrementUiCounter();
|
||||
// } else {
|
||||
// castManager.decrementUiCounter();
|
||||
// }
|
||||
// }
|
||||
// viewRequested = newValue;
|
||||
// if (mediaRouteActionProvider != null) {
|
||||
// mediaRouteActionProvider.setEnabled(prefEnabled && (viewRequested || connected));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public synchronized void setConnected(boolean newValue) {
|
||||
// if (connected != newValue && resumed && prefEnabled && !prefEnabled) {
|
||||
// if (newValue) {
|
||||
// castManager.incrementUiCounter();
|
||||
// } else {
|
||||
// castManager.decrementUiCounter();
|
||||
// }
|
||||
// }
|
||||
// connected = newValue;
|
||||
// if (mediaRouteActionProvider != null) {
|
||||
// mediaRouteActionProvider.setEnabled(prefEnabled && (viewRequested || connected));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public synchronized boolean shouldEnable() {
|
||||
// return prefEnabled && viewRequested;
|
||||
// }
|
||||
//
|
||||
// public void setMenu(Menu menu) {
|
||||
// setViewRequested(false);
|
||||
// showAsAction = MenuItem.SHOW_AS_ACTION_IF_ROOM;
|
||||
// this.menu = menu;
|
||||
// setShowAsAction();
|
||||
// }
|
||||
//
|
||||
// public void requestCastButton(int showAsAction) {
|
||||
// setViewRequested(true);
|
||||
// this.showAsAction = showAsAction;
|
||||
// setShowAsAction();
|
||||
// }
|
||||
//
|
||||
// public void onConnected() {
|
||||
// setConnected(true);
|
||||
// setShowAsAction();
|
||||
// }
|
||||
//
|
||||
// public void onDisconnected() {
|
||||
// setConnected(false);
|
||||
// setShowAsAction();
|
||||
// }
|
||||
//
|
||||
// private void setShowAsAction() {
|
||||
// if (menu == null) {
|
||||
// Log.d(TAG, "setShowAsAction() without a menu");
|
||||
// return;
|
||||
// }
|
||||
// MenuItem item = menu.findItem(R.id.media_route_menu_item);
|
||||
// if (item == null) {
|
||||
// Log.e(TAG, "setShowAsAction(), but cast button not inflated");
|
||||
// return;
|
||||
// }
|
||||
// MenuItemCompat.setShowAsAction(item, connected? MenuItem.SHOW_AS_ACTION_ALWAYS : showAsAction);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -171,7 +171,9 @@ public class StoragePreferencesFragment extends PreferenceFragmentCompat {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void unsubscribeExportSubscription() {
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
if (disposable != null) {
|
||||
disposable.dispose();
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package de.danoeh.antennapod.core.event;
|
||||
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
|
||||
public class FeedMediaEvent {
|
||||
|
||||
public enum Action {
|
||||
UPDATE
|
||||
}
|
||||
|
||||
private final Action action;
|
||||
private final FeedMedia media;
|
||||
|
||||
private FeedMediaEvent(Action action, FeedMedia media) {
|
||||
this.action = action;
|
||||
this.media = media;
|
||||
}
|
||||
|
||||
public static FeedMediaEvent update(FeedMedia media) {
|
||||
return new FeedMediaEvent(Action.UPDATE, media);
|
||||
}
|
||||
|
||||
}
|
|
@ -890,13 +890,6 @@ public class UserPreferences {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads episode cache size as it is saved in the episode_cache_size_values array.
|
||||
*/
|
||||
public static int readEpisodeCacheSize(String valueFromPrefs) {
|
||||
return readEpisodeCacheSizeInternal(valueFromPrefs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates whether Cast support (Chromecast, Audio Cast, etc) is enabled on the preferences.
|
||||
*/
|
||||
|
|
|
@ -193,10 +193,6 @@ public class DownloadStatus {
|
|||
this.cancelled = true;
|
||||
}
|
||||
|
||||
public void setCompletionDate(Date completionDate) {
|
||||
this.completionDate = (Date) completionDate.clone();
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
|
|
@ -193,11 +193,6 @@ public final class DBTasks {
|
|||
}).start();
|
||||
}
|
||||
|
||||
public static long getLastRefreshAllFeedsTimeMillis(final Context context) {
|
||||
SharedPreferences prefs = context.getSharedPreferences(DBTasks.PREF_NAME, MODE_PRIVATE);
|
||||
return prefs.getLong(DBTasks.PREF_LAST_REFRESH, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* @param feedList the list of feeds to refresh
|
||||
|
|
|
@ -34,7 +34,6 @@ import de.danoeh.antennapod.core.util.URLChecker;
|
|||
public class DownloadRequester {
|
||||
private static final String TAG = "DownloadRequester";
|
||||
|
||||
public static final String IMAGE_DOWNLOADPATH = "images/";
|
||||
private static final String FEED_DOWNLOADPATH = "cache/";
|
||||
private static final String MEDIA_DOWNLOADPATH = "media/";
|
||||
|
||||
|
@ -274,10 +273,6 @@ public class DownloadRequester {
|
|||
return item.getDownload_url() != null && downloads.containsKey(item.getDownload_url());
|
||||
}
|
||||
|
||||
public synchronized DownloadRequest getDownload(String downloadUrl) {
|
||||
return downloads.get(downloadUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if feedfile with the given download url is in the downloads list
|
||||
*/
|
||||
|
|
|
@ -55,16 +55,10 @@ public class PodDBAdapter {
|
|||
*/
|
||||
private static final int IN_OPERATOR_MAXIMUM = 800;
|
||||
|
||||
/**
|
||||
* Maximum number of entries per search request.
|
||||
*/
|
||||
public static final int SEARCH_LIMIT = 30;
|
||||
|
||||
// Key-constants
|
||||
public static final String KEY_ID = "id";
|
||||
public static final String KEY_TITLE = "title";
|
||||
public static final String KEY_CUSTOM_TITLE = "custom_title";
|
||||
public static final String KEY_NAME = "name";
|
||||
public static final String KEY_LINK = "link";
|
||||
public static final String KEY_DESCRIPTION = "description";
|
||||
public static final String KEY_FILE_URL = "file_url";
|
||||
|
@ -1400,13 +1394,6 @@ public class PodDBAdapter {
|
|||
return db.rawQuery(query, null);
|
||||
}
|
||||
|
||||
|
||||
public static final int IDX_FEEDSTATISTICS_FEED = 0;
|
||||
public static final int IDX_FEEDSTATISTICS_NUM_ITEMS = 1;
|
||||
public static final int IDX_FEEDSTATISTICS_NEW_ITEMS = 2;
|
||||
public static final int IDX_FEEDSTATISTICS_LATEST_EPISODE = 3;
|
||||
public static final int IDX_FEEDSTATISTICS_IN_PROGRESS_EPISODES = 4;
|
||||
|
||||
/**
|
||||
* Select number of items, new items, the date of the latest episode and the number of episodes in progress. The result
|
||||
* is sorted by the title of the feed.
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
/* Adapted from: http://thinking-in-code.blogspot.com/2008/11/duck-typing-in-java-using-dynamic.html */
|
||||
|
||||
package de.danoeh.antennapod.core.util;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import de.danoeh.antennapod.core.BuildConfig;
|
||||
|
||||
/**
|
||||
* Allows "duck typing" or dynamic invocation based on method signature rather
|
||||
* than type hierarchy. In other words, rather than checking whether something
|
||||
* IS-a duck, check whether it WALKS-like-a duck or QUACKS-like a duck.
|
||||
*
|
||||
* To use first use the coerce static method to indicate the object you want to
|
||||
* do Duck Typing for, then specify an interface to the to method which you want
|
||||
* to coerce the type to, e.g:
|
||||
*
|
||||
* public interface Foo { void aMethod(); } class Bar { ... public void
|
||||
* aMethod() { ... } ... } Bar bar = ...; Foo foo =
|
||||
* DuckType.coerce(bar).to(Foo.class); foo.aMethod();
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DuckType {
|
||||
|
||||
private final Object objectToCoerce;
|
||||
|
||||
private DuckType(Object objectToCoerce) {
|
||||
this.objectToCoerce = objectToCoerce;
|
||||
}
|
||||
|
||||
private class CoercedProxy implements InvocationHandler {
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
Method delegateMethod = findMethodBySignature(method);
|
||||
assert delegateMethod != null;
|
||||
return delegateMethod.invoke(DuckType.this.objectToCoerce, args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the duck typed object to coerce.
|
||||
*
|
||||
* @param object
|
||||
* the object to coerce
|
||||
* @return
|
||||
*/
|
||||
public static DuckType coerce(Object object) {
|
||||
return new DuckType(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerce the Duck Typed object to the given interface providing it
|
||||
* implements all the necessary methods.
|
||||
*
|
||||
* @param
|
||||
* @param iface
|
||||
* @return an instance of the given interface that wraps the duck typed
|
||||
* class
|
||||
* @throws ClassCastException
|
||||
* if the object being coerced does not implement all the
|
||||
* methods in the given interface.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public <T> T to(Class iface) {
|
||||
if (BuildConfig.DEBUG && !iface.isInterface()) throw new AssertionError("cannot coerce object to a class, must be an interface");
|
||||
if (isA(iface)) {
|
||||
return (T) iface.cast(objectToCoerce);
|
||||
}
|
||||
if (quacksLikeA(iface)) {
|
||||
return generateProxy(iface);
|
||||
}
|
||||
throw new ClassCastException("Could not coerce object of type " + objectToCoerce.getClass() + " to " + iface);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private boolean isA(Class iface) {
|
||||
return objectToCoerce.getClass().isInstance(iface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the duck typed object can be used with the given
|
||||
* interface.
|
||||
*
|
||||
* @param Type
|
||||
* of the interface to check.
|
||||
* @param iface
|
||||
* Interface class to check
|
||||
* @return true if the object will support all the methods in the interface,
|
||||
* false otherwise.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private boolean quacksLikeA(Class iface) {
|
||||
for (Method method : iface.getMethods()) {
|
||||
if (findMethodBySignature(method) == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private <T> T generateProxy(Class iface) {
|
||||
return (T) Proxy.newProxyInstance(iface.getClassLoader(), new Class[] { iface }, new CoercedProxy());
|
||||
}
|
||||
|
||||
private Method findMethodBySignature(Method method) {
|
||||
try {
|
||||
return objectToCoerce.getClass().getMethod(method.getName(), method.getParameterTypes());
|
||||
} catch (NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7,19 +7,6 @@ import de.danoeh.antennapod.core.feed.FeedItem;
|
|||
public class FeedItemUtil {
|
||||
private FeedItemUtil(){}
|
||||
|
||||
public static int indexOfItemWithDownloadUrl(List<FeedItem> items, String downloadUrl) {
|
||||
if(items == null) {
|
||||
return -1;
|
||||
}
|
||||
for(int i=0; i < items.size(); i++) {
|
||||
FeedItem item = items.get(i);
|
||||
if(item.hasMedia() && item.getMedia().getDownload_url().equals(downloadUrl)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int indexOfItemWithId(List<FeedItem> items, long id) {
|
||||
for(int i=0; i < items.size(); i++) {
|
||||
FeedItem item = items.get(i);
|
||||
|
@ -40,17 +27,6 @@ public class FeedItemUtil {
|
|||
return -1;
|
||||
}
|
||||
|
||||
public static long[] getIds(FeedItem... items) {
|
||||
if(items == null || items.length == 0) {
|
||||
return new long[0];
|
||||
}
|
||||
long[] result = new long[items.length];
|
||||
for(int i=0; i < items.length; i++) {
|
||||
result[i] = items[i].getId();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static long[] getIds(List<FeedItem> items) {
|
||||
if(items == null || items.size() == 0) {
|
||||
return new long[0];
|
||||
|
@ -62,20 +38,6 @@ public class FeedItemUtil {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static boolean containsAnyId(List<FeedItem> items, long[] ids) {
|
||||
if(items == null || items.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
for(FeedItem item : items) {
|
||||
for(long id : ids) {
|
||||
if(item.getId() == id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the link for the feed item for the purpose of Share. It fallbacks to
|
||||
* use the feed's link if the named feed item has no link.
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package de.danoeh.antennapod.core.util;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
|
||||
/** Compares the title of two feeds for sorting. */
|
||||
class FeedtitleComparator implements Comparator<Feed> {
|
||||
|
||||
@Override
|
||||
public int compare(Feed lhs, Feed rhs) {
|
||||
return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package de.danoeh.antennapod.core.util.comparator;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.SearchResult;
|
||||
|
||||
public class SearchResultValueComparator implements Comparator<SearchResult> {
|
||||
|
||||
/**
|
||||
* Compare items based, first, on where they were found (ie. title, chapters, or show notes).
|
||||
* If they were found in the same section, then compare based on the title, in lexicographic
|
||||
* order. This is still not ideal since, for example, "#12 Example A" would be considered
|
||||
* before "#8 Example B" due to the fact that "8" has a larger unicode value than "1"
|
||||
*/
|
||||
@Override
|
||||
public int compare(SearchResult lhs, SearchResult rhs) {
|
||||
int value = rhs.getValue() - lhs.getValue();
|
||||
if (value == 0 && lhs.getComponent() instanceof FeedItem && rhs.getComponent() instanceof FeedItem) {
|
||||
String lhsTitle = ((FeedItem) lhs.getComponent()).getTitle();
|
||||
String rhsTitle = ((FeedItem) rhs.getComponent()).getTitle();
|
||||
return lhsTitle.compareTo(rhsTitle);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue