Clean up some dead code (#6952)

This commit is contained in:
Taco 2024-03-04 17:07:28 -05:00 committed by GitHub
parent c06a3a6d27
commit 40da13e014
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 8 additions and 220 deletions

View File

@ -1,46 +0,0 @@
package de.test.antennapod.util.event;
import androidx.annotation.NonNull;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.List;
import de.danoeh.antennapod.event.FeedItemEvent;
import io.reactivex.functions.Consumer;
/**
* Test helpers to listen {@link FeedItemEvent} and handle them accordingly
*
*/
public class FeedItemEventListener {
private final List<FeedItemEvent> events = new ArrayList<>();
/**
* Provides an listener subscribing to {@link FeedItemEvent} that the callers can use
*
* Note: it uses RxJava's version of {@link Consumer} because it allows exceptions to be thrown.
*/
public static void withFeedItemEventListener(@NonNull Consumer<FeedItemEventListener> consumer)
throws Exception {
FeedItemEventListener feedItemEventListener = new FeedItemEventListener();
try {
EventBus.getDefault().register(feedItemEventListener);
consumer.accept(feedItemEventListener);
} finally {
EventBus.getDefault().unregister(feedItemEventListener);
}
}
@Subscribe
public void onEvent(FeedItemEvent event) {
events.add(event);
}
@NonNull
public List<? extends FeedItemEvent> getEvents() {
return events;
}
}

View File

@ -11,7 +11,6 @@ import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomViewTarget;
import com.bumptech.glide.request.transition.Transition;
import de.danoeh.antennapod.activity.MainActivity;
import java.lang.ref.WeakReference;
@ -21,11 +20,9 @@ public class CoverLoader {
private String fallbackUri;
private ImageView imgvCover;
private boolean textAndImageCombined;
private MainActivity activity;
private TextView fallbackTitle;
public CoverLoader(MainActivity activity) {
this.activity = activity;
public CoverLoader() {
}
public CoverLoader withUri(String uri) {

View File

@ -244,7 +244,7 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter<Subscription
count.setVisibility(View.GONE);
}
CoverLoader coverLoader = new CoverLoader(mainActivityRef.get());
CoverLoader coverLoader = new CoverLoader();
boolean textAndImageCombined;
if (drawerItem.type == NavDrawerData.DrawerItem.Type.FEED) {
Feed feed = ((NavDrawerData.FeedDrawerItem) drawerItem).feed;

View File

@ -129,7 +129,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder {
}
if (coverHolder.getVisibility() == View.VISIBLE) {
new CoverLoader(activity)
new CoverLoader()
.withUri(ImageResourceUtils.getEpisodeListImageLocation(item))
.withFallbackUri(item.getFeed().getImageUrl())
.withPlaceholderView(placeholder)
@ -225,7 +225,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder {
itemView.setBackgroundResource(ThemeUtils.getDrawableFromAttr(activity, R.attr.selectableItemBackground));
placeholder.setText("");
if (coverHolder.getVisibility() == View.VISIBLE) {
new CoverLoader(activity)
new CoverLoader()
.withResource(R.color.medium_gray)
.withPlaceholderView(placeholder)
.withCoverView(cover)

View File

@ -58,7 +58,7 @@ public class HorizontalItemViewHolder extends RecyclerView.ViewHolder {
card.setAlpha(1.0f);
float density = activity.getResources().getDisplayMetrics().density;
card.setCardBackgroundColor(SurfaceColors.getColorForElevation(activity, 1 * density));
new CoverLoader(activity)
new CoverLoader()
.withUri(ImageResourceUtils.getEpisodeListImageLocation(item))
.withFallbackUri(item.getFeed().getImageUrl())
.withCoverView(cover)
@ -102,7 +102,7 @@ public class HorizontalItemViewHolder extends RecyclerView.ViewHolder {
public void bindDummy() {
card.setAlpha(0.1f);
new CoverLoader(activity)
new CoverLoader()
.withResource(android.R.color.transparent)
.withCoverView(cover)
.load();

View File

@ -66,7 +66,6 @@ public class ExoPlayerWrapper {
public static final int BUFFERING_STARTED = -1;
public static final int BUFFERING_ENDED = -2;
private static final String TAG = "ExoPlayerWrapper";
public static final int ERROR_CODE_OFFSET = 1000;
private final Context context;
private final Disposable bufferingUpdateDisposable;

View File

@ -1,41 +0,0 @@
package de.danoeh.antennapod.core.util.download;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.util.Log;
public class ConnectionStateMonitor
extends ConnectivityManager.NetworkCallback
implements ConnectivityManager.OnNetworkActiveListener {
private static final String TAG = "ConnectionStateMonitor";
final NetworkRequest networkRequest;
public ConnectionStateMonitor() {
networkRequest = new NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.build();
}
@Override
public void onNetworkActive() {
Log.d(TAG, "ConnectionStateMonitor::onNetworkActive network connection changed");
NetworkConnectionChangeHandler.networkChangedDetected();
}
public void enable(Context context) {
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
connectivityManager.registerNetworkCallback(networkRequest, this);
connectivityManager.addDefaultNetworkActiveListener(this);
}
public void disable(Context context) {
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
connectivityManager.unregisterNetworkCallback(this);
connectivityManager.removeDefaultNetworkActiveListener(this);
}
}

View File

@ -1,36 +0,0 @@
package de.danoeh.antennapod.core.util.playback;
import android.content.Context;
import android.media.MediaPlayer;
import com.google.android.exoplayer2.ExoPlaybackException;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.service.playback.ExoPlayerWrapper;
/** Utility class for MediaPlayer errors. */
public class MediaPlayerError {
private MediaPlayerError(){}
/** Get a human-readable string for a specific error code. */
public static String getErrorString(Context context, int code) {
int resId;
switch (code) {
case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
resId = R.string.playback_error_server_died;
break;
case MediaPlayer.MEDIA_ERROR_UNSUPPORTED: // fall-through
case ExoPlayerWrapper.ERROR_CODE_OFFSET + ExoPlaybackException.TYPE_RENDERER:
resId = R.string.playback_error_unsupported;
break;
case MediaPlayer.MEDIA_ERROR_TIMED_OUT:
resId = R.string.playback_error_timeout;
break;
case ExoPlayerWrapper.ERROR_CODE_OFFSET + ExoPlaybackException.TYPE_SOURCE:
resId = R.string.playback_error_source;
break;
default:
resId = R.string.playback_error_unknown;
break;
}
return context.getString(resId) + " (" + code + ")";
}
}

View File

@ -13,6 +13,7 @@ public class TextUtils {
* @param b second CharSequence to check
* @return true if a and b are equal
*/
@SuppressWarnings("unused")
public static boolean equals(CharSequence a, CharSequence b) {
if (a == b) return true;
int length;

View File

@ -252,25 +252,4 @@ public class DbTasksTest {
lastDate = item.getPubDate();
}
}
private Feed createSavedFeed(String title, int numFeedItems) {
final Feed feed = new Feed("url", null, title);
if (numFeedItems > 0) {
List<FeedItem> items = new ArrayList<>(numFeedItems);
for (int i = 1; i <= numFeedItems; i++) {
FeedItem item = new FeedItem(0, "item " + i + " of " + title, "id" + title + i, "link",
new Date(), FeedItem.UNPLAYED, feed);
items.add(item);
}
feed.setItems(items);
}
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(feed);
adapter.close();
return feed;
}
}

View File

@ -333,10 +333,6 @@ public class FeedItem implements Serializable {
}
}
public enum State {
UNREAD, IN_PROGRESS, READ, PLAYING
}
public long getFeedId() {
return feedId;
}

View File

@ -72,12 +72,4 @@ public enum SortOrder {
public static String toCodeString(@Nullable SortOrder sortOrder) {
return sortOrder != null ? Integer.toString(sortOrder.code) : null;
}
public static SortOrder[] valuesOf(String[] stringValues) {
SortOrder[] values = new SortOrder[stringValues.length];
for (int i = 0; i < stringValues.length; i++) {
values[i] = SortOrder.valueOf(stringValues[i]);
}
return values;
}
}

View File

@ -166,38 +166,6 @@ public class GpodnetService implements ISyncService {
}
}
/**
* Uploads the subscriptions of a specific device.
* <p/>
* This method requires authentication.
*
* @param deviceId The ID of the device whose subscriptions should be updated.
* @param subscriptions A list of feed URLs containing all subscriptions of the
* device.
* @throws IllegalArgumentException If username, deviceId or subscriptions is null.
* @throws GpodnetServiceAuthenticationException If there is an authentication error.
*/
public void uploadSubscriptions(@NonNull String deviceId, @NonNull List<String> subscriptions)
throws GpodnetServiceException {
requireLoggedIn();
try {
URL url = new URI(baseScheme, null, baseHost, basePort,
String.format("/subscriptions/%s/%s.txt", username, deviceId), null, null).toURL();
StringBuilder builder = new StringBuilder();
for (String s : subscriptions) {
builder.append(s);
builder.append("\n");
}
RequestBody body = RequestBody.create(TEXT, builder.toString());
Request.Builder request = new Request.Builder().put(body).url(url);
executeRequest(request);
} catch (MalformedURLException | URISyntaxException e) {
e.printStackTrace();
throw new GpodnetServiceException(e);
}
}
/**
* Updates the subscription list of a specific device.
* <p/>

View File

@ -1,6 +1,5 @@
package de.danoeh.antennapod.ui.common;
import androidx.annotation.NonNull;
import com.google.android.material.appbar.MaterialToolbar;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;
@ -10,23 +9,8 @@ import androidx.viewpager2.widget.ViewPager2;
* All items share the same general menu items and are just allowed to show/hide them.
*/
public abstract class PagedToolbarFragment extends Fragment {
private MaterialToolbar toolbar;
private ViewPager2 viewPager;
/**
* Invalidate the toolbar menu if the current child fragment is visible.
* @param child The fragment to invalidate
*/
public void invalidateOptionsMenuIfActive(@NonNull Fragment child) {
Fragment visibleChild = getChildFragmentManager().findFragmentByTag("f" + viewPager.getCurrentItem());
if (visibleChild == child) {
visibleChild.onPrepareOptionsMenu(toolbar.getMenu());
}
}
protected void setupPagedToolbar(MaterialToolbar toolbar, ViewPager2 viewPager) {
this.toolbar = toolbar;
this.viewPager = viewPager;
protected void setupPagedToolbar(final MaterialToolbar toolbar, final ViewPager2 viewPager) {
toolbar.setOnMenuItemClickListener(item -> {
if (this.onOptionsItemSelected(item)) {

View File

@ -320,11 +320,6 @@
<!-- Mediaplayer messages -->
<string name="playback_error_generic"><![CDATA[The media file could not be played.\n\n- Try deleting and re-downloading the episode.\n- Check your network connection, and make sure no VPN or login page is blocking access.\n- Try long-pressing and sharing the \"Media address\" to your web browser to see if it can be played there. If not, contact the podcast creators.]]></string>
<string name="playback_error_server_died">Server died</string>
<string name="playback_error_unsupported">Unsupported media type</string>
<string name="playback_error_timeout">Operation timed out</string>
<string name="playback_error_source">Unable to access media file</string>
<string name="playback_error_unknown">Unknown error</string>
<string name="no_media_playing_label">No media playing</string>
<string name="position_default_label" translatable="false">00:00:00</string>
<string name="unknown_media_key">AntennaPod - Unknown media key: %1$d</string>