data flow issue + declaration redundancy

make final
unused methods
make final

BUILD SUCCESSFUL in 0s
39 actionable tasks: 39 up-to-date
This commit is contained in:
BO41 2018-08-28 20:02:25 +02:00
parent 3ab06bf383
commit 0ab86937d2
38 changed files with 98 additions and 112 deletions

View file

@ -28,9 +28,6 @@ import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.extractor.Info;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
public final class InfoCache {
@ -58,7 +55,7 @@ public final class InfoCache {
public Info getFromKey(int serviceId, @NonNull String url) {
if (DEBUG) Log.d(TAG, "getFromKey() called with: serviceId = [" + serviceId + "], url = [" + url + "]");
synchronized (lruCache) {
return getInfo(lruCache, keyOf(serviceId, url));
return getInfo(keyOf(serviceId, url));
}
}
@ -89,7 +86,7 @@ public final class InfoCache {
public void trimCache() {
if (DEBUG) Log.d(TAG, "trimCache() called");
synchronized (lruCache) {
removeStaleCache(lruCache);
removeStaleCache();
lruCache.trimToSize(TRIM_CACHE_TO);
}
}
@ -105,23 +102,22 @@ public final class InfoCache {
return serviceId + url;
}
private static void removeStaleCache(@NonNull final LruCache<String, CacheData> cache) {
for (Map.Entry<String, CacheData> entry : cache.snapshot().entrySet()) {
private static void removeStaleCache() {
for (Map.Entry<String, CacheData> entry : InfoCache.lruCache.snapshot().entrySet()) {
final CacheData data = entry.getValue();
if (data != null && data.isExpired()) {
cache.remove(entry.getKey());
InfoCache.lruCache.remove(entry.getKey());
}
}
}
@Nullable
private static Info getInfo(@NonNull final LruCache<String, CacheData> cache,
@NonNull final String key) {
final CacheData data = cache.get(key);
private static Info getInfo(@NonNull final String key) {
final CacheData data = InfoCache.lruCache.get(key);
if (data == null) return null;
if (data.isExpired()) {
cache.remove(key);
InfoCache.lruCache.remove(key);
return null;
}

View file

@ -204,7 +204,7 @@ public final class ListHelper {
*/
private static void sortStreamList(List<VideoStream> videoStreams, final boolean ascendingOrder) {
Collections.sort(videoStreams, (o1, o2) -> {
int result = compareVideoStreamResolution(o1, o2, VIDEO_FORMAT_QUALITY_RANKING);
int result = compareVideoStreamResolution(o1, o2);
return result == 0 ? 0 : (ascendingOrder ? result : -result);
});
}
@ -399,8 +399,7 @@ public final class ListHelper {
}
// Compares the quality of two video streams.
private static int compareVideoStreamResolution(VideoStream streamA, VideoStream streamB,
List<MediaFormat> formatRanking) {
private static int compareVideoStreamResolution(VideoStream streamA, VideoStream streamB) {
if (streamA == null) {
return -1;
}
@ -414,7 +413,7 @@ public final class ListHelper {
}
// Same bitrate and format
return formatRanking.indexOf(streamA.getFormat()) - formatRanking.indexOf(streamB.getFormat());
return ListHelper.VIDEO_FORMAT_QUALITY_RANKING.indexOf(streamA.getFormat()) - ListHelper.VIDEO_FORMAT_QUALITY_RANKING.indexOf(streamB.getFormat());
}

View file

@ -31,7 +31,7 @@ import us.shandian.giga.util.Utility;
public class StreamItemAdapter<T extends Stream> extends BaseAdapter {
private final Context context;
private StreamSizeWrapper<T> streamsWrapper;
private final StreamSizeWrapper<T> streamsWrapper;
private final boolean showIconNoAudio;
public StreamItemAdapter(Context context, StreamSizeWrapper<T> streamsWrapper, boolean showIconNoAudio) {
@ -124,7 +124,7 @@ public class StreamItemAdapter<T extends Stream> extends BaseAdapter {
public static class StreamSizeWrapper<T extends Stream> implements Serializable {
private static final StreamSizeWrapper<Stream> EMPTY = new StreamSizeWrapper<>(Collections.emptyList());
private final List<T> streamsList;
private long[] streamSizes;
private final long[] streamSizes;
public StreamSizeWrapper(List<T> streamsList) {
this.streamsList = streamsList;