diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2018-01-21 22:50:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-21 22:50:47 +0100 |
commit | 5526937698c6d45188ff273a3b18866da443c29c (patch) | |
tree | 5895b61960ac96cd966ae60e1a7857f58123c74d /app/src | |
parent | 06113b089190f9a4ccfac685b17e38f03964a71e (diff) | |
parent | 34a5d7eb17d2074d746107abcdc6872ae7ad285c (diff) | |
download | AntennaPod-5526937698c6d45188ff273a3b18866da443c29c.zip |
Merge branch 'develop' into picture-in-picture
Diffstat (limited to 'app/src')
102 files changed, 980 insertions, 1340 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/gpodnet/GPodnetServiceTest.java b/app/src/androidTest/java/de/test/antennapod/gpodnet/GPodnetServiceTest.java index 3ca7906cb..a880c330b 100644 --- a/app/src/androidTest/java/de/test/antennapod/gpodnet/GPodnetServiceTest.java +++ b/app/src/androidTest/java/de/test/antennapod/gpodnet/GPodnetServiceTest.java @@ -11,6 +11,8 @@ import de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException; import de.danoeh.antennapod.core.gpoddernet.model.GpodnetDevice; import de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag; +import static java.util.Collections.singletonList; + /** * Test class for GpodnetService */ @@ -38,14 +40,14 @@ public class GPodnetServiceTest extends AndroidTestCase { public void testUploadSubscription() throws GpodnetServiceException { authenticate(); - ArrayList<String> l = new ArrayList<String>(); + ArrayList<String> l = new ArrayList<>(); l.add("http://bitsundso.de/feed"); service.uploadSubscriptions(USER, "radio", l); } public void testUploadSubscription2() throws GpodnetServiceException { authenticate(); - ArrayList<String> l = new ArrayList<String>(); + ArrayList<String> l = new ArrayList<>(); l.add("http://bitsundso.de/feed"); l.add("http://gamesundso.de/feed"); service.uploadSubscriptions(USER, "radio", l); @@ -55,7 +57,7 @@ public class GPodnetServiceTest extends AndroidTestCase { authenticate(); String[] URLS = {"http://bitsundso.de/feed", "http://gamesundso.de/feed", "http://cre.fm/feed/mp3/", "http://freakshow.fm/feed/m4a/"}; List<String> subscriptions = Arrays.asList(URLS[0], URLS[1]); - List<String> removed = Arrays.asList(URLS[0]); + List<String> removed = singletonList(URLS[0]); List<String> added = Arrays.asList(URLS[2], URLS[3]); service.uploadSubscriptions(USER, "radio", subscriptions); service.uploadChanges(USER, "radio", added, removed); diff --git a/app/src/androidTest/java/de/test/antennapod/handler/FeedHandlerTest.java b/app/src/androidTest/java/de/test/antennapod/handler/FeedHandlerTest.java index ee454ce8a..39abe4b7a 100644 --- a/app/src/androidTest/java/de/test/antennapod/handler/FeedHandlerTest.java +++ b/app/src/androidTest/java/de/test/antennapod/handler/FeedHandlerTest.java @@ -32,8 +32,8 @@ import de.test.antennapod.util.syndication.feedgenerator.RSS2Generator; public class FeedHandlerTest extends InstrumentationTestCase { private static final String FEEDS_DIR = "testfeeds"; - File file = null; - OutputStream outputStream = null; + private File file = null; + private OutputStream outputStream = null; protected void setUp() throws Exception { super.setUp(); @@ -165,7 +165,7 @@ public class FeedHandlerTest extends InstrumentationTestCase { Feed feed = new Feed(0, null, "title", "http://example.com", "This is the description", "http://example.com/payment", "Daniel", "en", null, "http://example.com/feed", image, file.getAbsolutePath(), "http://example.com/feed", true); - feed.setItems(new ArrayList<FeedItem>()); + feed.setItems(new ArrayList<>()); for (int i = 0; i < numItems; i++) { FeedItem item = new FeedItem(0, "item-" + i, "http://example.com/item-" + i, diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBCleanupTests.java b/app/src/androidTest/java/de/test/antennapod/storage/DBCleanupTests.java index 5e5eb1e8b..5cd4e9906 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/DBCleanupTests.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/DBCleanupTests.java @@ -27,12 +27,12 @@ import static de.test.antennapod.storage.DBTestUtils.saveFeedlist; public class DBCleanupTests extends InstrumentationTestCase { private static final String TAG = "DBTasksTest"; - protected static final int EPISODE_CACHE_SIZE = 5; + static final int EPISODE_CACHE_SIZE = 5; private final int cleanupAlgorithm; - protected Context context; + Context context; - protected File destFolder; + private File destFolder; public DBCleanupTests() { this.cleanupAlgorithm = UserPreferences.EPISODE_CLEANUP_DEFAULT; @@ -104,9 +104,9 @@ public class DBCleanupTests extends InstrumentationTestCase { } } - protected void populateItems(final int numItems, Feed feed, List<FeedItem> items, - List<File> files, int itemState, boolean addToQueue, - boolean addToFavorites) throws IOException { + void populateItems(final int numItems, Feed feed, List<FeedItem> items, + List<File> files, int itemState, boolean addToQueue, + boolean addToFavorites) throws IOException { for (int i = 0; i < numItems; i++) { Date itemDate = new Date(numItems - i); Date playbackCompletionDate = null; @@ -145,9 +145,9 @@ public class DBCleanupTests extends InstrumentationTestCase { final int NUM_ITEMS = EPISODE_CACHE_SIZE * 2; Feed feed = new Feed("url", null, "title"); - List<FeedItem> items = new ArrayList<FeedItem>(); + List<FeedItem> items = new ArrayList<>(); feed.setItems(items); - List<File> files = new ArrayList<File>(); + List<File> files = new ArrayList<>(); populateItems(NUM_ITEMS, feed, items, files, FeedItem.UNPLAYED, false, false); DBTasks.performAutoCleanup(context); diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java b/app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java index 785d32e93..93a9408b7 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java @@ -18,6 +18,8 @@ import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.PodDBAdapter; +import static java.util.Collections.singletonList; + /** * Test class for DBTasks */ @@ -100,7 +102,7 @@ public class DBTasksTest extends InstrumentationTestCase { assertTrue(feed.getId() != 0); final long feedID = feed.getId(); feed.setId(0); - List<Long> itemIDs = new ArrayList<Long>(); + List<Long> itemIDs = new ArrayList<>(); for (FeedItem item : feed.getItems()) { assertTrue(item.getId() != 0); itemIDs.add(item.getId()); @@ -125,7 +127,7 @@ public class DBTasksTest extends InstrumentationTestCase { public void testUpdateFeedMediaUrlResetState() { final Feed feed = new Feed("url", null, "title"); FeedItem item = new FeedItem(0, "item", "id", "link", new Date(), FeedItem.PLAYED, feed); - feed.setItems(Arrays.asList(item)); + feed.setItems(singletonList(item)); PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); @@ -138,7 +140,7 @@ public class DBTasksTest extends InstrumentationTestCase { FeedMedia media = new FeedMedia(item, "url", 1024, "mime/type"); item.setMedia(media); - feed.setItems(Arrays.asList(item)); + feed.setItems(singletonList(item)); final Feed newFeed = DBTasks.updateFeed(context, feed)[0]; assertTrue(feed != newFeed); diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBTestUtils.java b/app/src/androidTest/java/de/test/antennapod/storage/DBTestUtils.java index d02efa521..c9c715a86 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/DBTestUtils.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/DBTestUtils.java @@ -19,7 +19,7 @@ import de.danoeh.antennapod.core.util.flattr.FlattrStatus; /** * Utility methods for DB* tests. */ -public class DBTestUtils { +class DBTestUtils { /** * Use this method when tests don't involve chapters. diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBWriterTest.java b/app/src/androidTest/java/de/test/antennapod/storage/DBWriterTest.java index 40083e507..b1cc807ea 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/DBWriterTest.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/DBWriterTest.java @@ -138,7 +138,7 @@ public class DBWriterTest extends InstrumentationTestCase { image.setOwner(feed); feed.setImage(image); - List<File> itemFiles = new ArrayList<File>(); + List<File> itemFiles = new ArrayList<>(); // create items with downloaded media files for (int i = 0; i < 10; i++) { FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed, true); @@ -151,7 +151,7 @@ public class DBWriterTest extends InstrumentationTestCase { FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", enc.getAbsolutePath(), "download_url", true, null, 0, 0); item.setMedia(media); - item.setChapters(new ArrayList<Chapter>()); + item.setChapters(new ArrayList<>()); item.getChapters().add(new SimpleChapter(0, "item " + i, item, "example.com")); } @@ -207,7 +207,7 @@ public class DBWriterTest extends InstrumentationTestCase { feed.setImage(null); - List<File> itemFiles = new ArrayList<File>(); + List<File> itemFiles = new ArrayList<>(); // create items with downloaded media files for (int i = 0; i < 10; i++) { FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed); @@ -418,7 +418,7 @@ public class DBWriterTest extends InstrumentationTestCase { image.setOwner(feed); feed.setImage(image); - List<File> itemFiles = new ArrayList<File>(); + List<File> itemFiles = new ArrayList<>(); // create items with downloaded media files for (int i = 0; i < 10; i++) { FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed); @@ -444,7 +444,7 @@ public class DBWriterTest extends InstrumentationTestCase { } - List<FeedItem> queue = new ArrayList<FeedItem>(); + List<FeedItem> queue = new ArrayList<>(); queue.addAll(feed.getItems()); adapter.open(); adapter.setQueue(queue); @@ -482,7 +482,7 @@ public class DBWriterTest extends InstrumentationTestCase { assertNotNull(destFolder); Feed feed = new Feed("url", null, "title"); - feed.setItems(new ArrayList<FeedItem>()); + feed.setItems(new ArrayList<>()); // create Feed image File imgFile = new File(destFolder, "image"); @@ -490,7 +490,7 @@ public class DBWriterTest extends InstrumentationTestCase { image.setOwner(feed); feed.setImage(image); - List<File> itemFiles = new ArrayList<File>(); + List<File> itemFiles = new ArrayList<>(); // create items with downloaded media files for (int i = 0; i < 10; i++) { FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed); @@ -539,7 +539,7 @@ public class DBWriterTest extends InstrumentationTestCase { private FeedMedia playbackHistorySetup(Date playbackCompletionDate) { final Context context = getInstrumentation().getTargetContext(); Feed feed = new Feed("url", null, "title"); - feed.setItems(new ArrayList<FeedItem>()); + feed.setItems(new ArrayList<>()); FeedItem item = new FeedItem(0, "title", "id", "link", new Date(), FeedItem.PLAYED, feed); FeedMedia media = new FeedMedia(0, item, 10, 0, 1, "mime", null, "url", false, playbackCompletionDate, 0, 0); feed.getItems().add(item); @@ -598,7 +598,7 @@ public class DBWriterTest extends InstrumentationTestCase { for (FeedItem item : feed.getItems()) { assertTrue(item.getId() != 0); } - List<Future<?>> futures = new ArrayList<Future<?>>(); + List<Future<?>> futures = new ArrayList<>(); for (FeedItem item : feed.getItems()) { futures.add(DBWriter.addQueueItem(context, item)); } @@ -791,7 +791,7 @@ public class DBWriterTest extends InstrumentationTestCase { public void testMarkFeedRead() throws InterruptedException, ExecutionException, TimeoutException { final int NUM_ITEMS = 10; Feed feed = new Feed("url", null, "title"); - feed.setItems(new ArrayList<FeedItem>()); + feed.setItems(new ArrayList<>()); for (int i = 0; i < NUM_ITEMS; i++) { FeedItem item = new FeedItem(0, "title " + i, "id " + i, "link " + i, new Date(), FeedItem.UNPLAYED, feed); feed.getItems().add(item); diff --git a/app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java b/app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java index bd9057b47..6156da926 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java @@ -15,6 +15,7 @@ import java.util.List; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.OnlineFeedViewActivity; +import de.danoeh.antennapod.activity.PreferenceActivity; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.PodDBAdapter; @@ -22,7 +23,6 @@ import de.danoeh.antennapod.fragment.DownloadsFragment; import de.danoeh.antennapod.fragment.EpisodesFragment; import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; -import de.danoeh.antennapod.preferences.PreferenceController; /** * User interface tests for MainActivity @@ -96,7 +96,7 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv public void testClickNavDrawer() throws Exception { uiTestUtils.addLocalFeedData(false); - UserPreferences.setHiddenDrawerItems(new ArrayList<String>()); + UserPreferences.setHiddenDrawerItems(new ArrayList<>()); // queue openNavDrawer(); @@ -155,11 +155,11 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv public void testGoToPreferences() { openNavDrawer(); solo.clickOnText(solo.getString(R.string.settings_label)); - solo.waitForActivity(PreferenceController.getPreferenceActivity()); + solo.waitForActivity(PreferenceActivity.class); } public void testDrawerPreferencesHideSomeElements() { - UserPreferences.setHiddenDrawerItems(new ArrayList<String>()); + UserPreferences.setHiddenDrawerItems(new ArrayList<>()); openNavDrawer(); solo.clickLongOnText(solo.getString(R.string.queue_label)); solo.waitForDialogToOpen(); @@ -190,7 +190,7 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv } public void testDrawerPreferencesHideAllElements() { - UserPreferences.setHiddenDrawerItems(new ArrayList<String>()); + UserPreferences.setHiddenDrawerItems(new ArrayList<>()); String[] titles = getInstrumentation().getTargetContext().getResources().getStringArray(R.array.nav_drawer_titles); openNavDrawer(); @@ -209,7 +209,7 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv } public void testDrawerPreferencesHideCurrentElement() { - UserPreferences.setHiddenDrawerItems(new ArrayList<String>()); + UserPreferences.setHiddenDrawerItems(new ArrayList<>()); openNavDrawer(); String downloads = solo.getString(R.string.downloads_label); diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackSonicTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PlaybackSonicTest.java index bfbeedd83..293ed2848 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackSonicTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/PlaybackSonicTest.java @@ -33,8 +33,8 @@ import de.danoeh.antennapod.core.storage.PodDBAdapter; public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActivity> { private static final String TAG = PlaybackTest.class.getSimpleName(); - public static final int EPISODES_DRAWER_LIST_INDEX = 1; - public static final int QUEUE_DRAWER_LIST_INDEX = 0; + private static final int EPISODES_DRAWER_LIST_INDEX = 1; + private static final int QUEUE_DRAWER_LIST_INDEX = 0; private Solo solo; private UITestUtils uiTestUtils; diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java index 661c2200b..74d59abd7 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/PlaybackTest.java @@ -30,8 +30,8 @@ import de.danoeh.antennapod.core.storage.PodDBAdapter; public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity> { private static final String TAG = PlaybackTest.class.getSimpleName(); - public static final int EPISODES_DRAWER_LIST_INDEX = 1; - public static final int QUEUE_DRAWER_LIST_INDEX = 0; + private static final int EPISODES_DRAWER_LIST_INDEX = 1; + private static final int QUEUE_DRAWER_LIST_INDEX = 0; private Solo solo; private UITestUtils uiTestUtils; diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java index e18c9ca16..fb74378c7 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java @@ -96,10 +96,10 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference solo.clickOnText(solo.getString(R.string.pref_compact_notification_buttons_title)); solo.waitForDialogToOpen(1000); // First uncheck every checkbox - for (int i=0; i<buttons.length; i++) { - assertTrue(solo.searchText(buttons[i])); - if (solo.isTextChecked(buttons[i])) { - solo.clickOnText(buttons[i]); + for (String button : buttons) { + assertTrue(solo.searchText(button)); + if (solo.isTextChecked(button)) { + solo.clickOnText(button); } } // Now try to check all checkboxes @@ -110,8 +110,8 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference assertTrue(!solo.isTextChecked(buttons[2])); solo.clickOnText(solo.getString(R.string.confirm_label)); solo.waitForDialogToClose(1000); - assertTrue(solo.waitForCondition(() -> UserPreferences.showRewindOnCompactNotification(), Timeout.getLargeTimeout())); - assertTrue(solo.waitForCondition(() -> UserPreferences.showFastForwardOnCompactNotification(), Timeout.getLargeTimeout())); + assertTrue(solo.waitForCondition(UserPreferences::showRewindOnCompactNotification, Timeout.getLargeTimeout())); + assertTrue(solo.waitForCondition(UserPreferences::showFastForwardOnCompactNotification, Timeout.getLargeTimeout())); assertTrue(solo.waitForCondition(() -> !UserPreferences.showSkipOnCompactNotification(), Timeout.getLargeTimeout())); } @@ -134,7 +134,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference public void testHeadPhonesReconnect() { if(UserPreferences.isPauseOnHeadsetDisconnect() == false) { solo.clickOnText(solo.getString(R.string.pref_pauseOnHeadsetDisconnect_title)); - assertTrue(solo.waitForCondition(() -> UserPreferences.isPauseOnHeadsetDisconnect(), Timeout.getLargeTimeout())); + assertTrue(solo.waitForCondition(UserPreferences::isPauseOnHeadsetDisconnect, Timeout.getLargeTimeout())); } final boolean unpauseOnHeadsetReconnect = UserPreferences.isUnpauseOnHeadsetReconnect(); solo.clickOnText(solo.getString(R.string.pref_unpauseOnHeadsetReconnect_title)); @@ -146,7 +146,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference public void testBluetoothReconnect() { if(UserPreferences.isPauseOnHeadsetDisconnect() == false) { solo.clickOnText(solo.getString(R.string.pref_pauseOnHeadsetDisconnect_title)); - assertTrue(solo.waitForCondition(() -> UserPreferences.isPauseOnHeadsetDisconnect(), Timeout.getLargeTimeout())); + assertTrue(solo.waitForCondition(UserPreferences::isPauseOnHeadsetDisconnect, Timeout.getLargeTimeout())); } final boolean unpauseOnBluetoothReconnect = UserPreferences.isUnpauseOnBluetoothReconnect(); solo.clickOnText(solo.getString(R.string.pref_unpauseOnBluetoothReconnect_title)); diff --git a/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java b/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java index 11e033e51..3af22af9d 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/UITestUtils.java @@ -1,9 +1,7 @@ package de.test.antennapod.ui; -import android.annotation.TargetApi; import android.content.Context; import android.graphics.Bitmap; -import android.os.Build; import android.util.Log; import junit.framework.Assert; @@ -20,7 +18,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.event.QueueEvent; import de.danoeh.antennapod.core.feed.EventDistributor; @@ -39,27 +36,25 @@ import de.test.antennapod.util.syndication.feedgenerator.RSS2Generator; * Utility methods for UI tests. * Starts a web server that hosts feeds, episodes and images. */ -@TargetApi(Build.VERSION_CODES.HONEYCOMB) -public class UITestUtils { +class UITestUtils { private static final String TAG = UITestUtils.class.getSimpleName(); private static final String DATA_FOLDER = "test/UITestUtils"; - public static final int NUM_FEEDS = 5; - public static final int NUM_ITEMS_PER_FEED = 10; + private static final int NUM_FEEDS = 5; + private static final int NUM_ITEMS_PER_FEED = 10; - public static final int HOME_VIEW = (Build.VERSION.SDK_INT >= 11) ? android.R.id.home : R.id.home; - public static final String TEST_FILE_NAME = "3sec.mp3"; + private static final String TEST_FILE_NAME = "3sec.mp3"; - private Context context; - private HTTPBin server = new HTTPBin(); + private final Context context; + private final HTTPBin server = new HTTPBin(); private File destDir; private File hostedFeedDir; private File hostedMediaDir; - public List<Feed> hostedFeeds = new ArrayList<Feed>(); + public final List<Feed> hostedFeeds = new ArrayList<>(); public UITestUtils(Context context) { this.context = context; @@ -149,7 +144,7 @@ public class UITestUtils { image.setOwner(feed); // create items - List<FeedItem> items = new ArrayList<FeedItem>(); + List<FeedItem> items = new ArrayList<>(); for (int j = 0; j < NUM_ITEMS_PER_FEED; j++) { FeedItem item = new FeedItem(j, "Feed " + (i+1) + ": Item " + (j+1), "item" + j, "http://example.com/feed" + i + "/item/" + j, new Date(), FeedItem.UNPLAYED, feed); diff --git a/app/src/androidTest/java/de/test/antennapod/util/service/download/HTTPBin.java b/app/src/androidTest/java/de/test/antennapod/util/service/download/HTTPBin.java index 2f2c3fe5b..cde93fd7e 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/service/download/HTTPBin.java +++ b/app/src/androidTest/java/de/test/antennapod/util/service/download/HTTPBin.java @@ -45,11 +45,11 @@ public class HTTPBin extends NanoHTTPD { private static final String MIME_HTML = "text/html"; private static final String MIME_PLAIN = "text/plain"; - private List<File> servedFiles; + private final List<File> servedFiles; public HTTPBin() { super(PORT); - this.servedFiles = new ArrayList<File>(); + this.servedFiles = new ArrayList<>(); } /** diff --git a/app/src/androidTest/java/de/test/antennapod/util/service/download/NanoHTTPD.java b/app/src/androidTest/java/de/test/antennapod/util/service/download/NanoHTTPD.java index 28ff6694e..61ff65809 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/service/download/NanoHTTPD.java +++ b/app/src/androidTest/java/de/test/antennapod/util/service/download/NanoHTTPD.java @@ -88,15 +88,15 @@ public abstract class NanoHTTPD { * This is required as the Keep-Alive HTTP connections would otherwise * block the socket reading thread forever (or as long the browser is open). */ - public static final int SOCKET_READ_TIMEOUT = 5000; + private static final int SOCKET_READ_TIMEOUT = 5000; /** * Common mime type for dynamic content: plain text */ - public static final String MIME_PLAINTEXT = "text/plain"; + private static final String MIME_PLAINTEXT = "text/plain"; /** * Common mime type for dynamic content: html */ - public static final String MIME_HTML = "text/html"; + private static final String MIME_HTML = "text/html"; /** * Pseudo-Parameter to use to store the actual query string in the parameters map for later re-processing. */ @@ -104,7 +104,7 @@ public abstract class NanoHTTPD { private final String hostname; private final int myPort; private ServerSocket myServerSocket; - private Set<Socket> openConnections = new HashSet<Socket>(); + private final Set<Socket> openConnections = new HashSet<>(); private Thread myThread; /** * Pluggable strategy for asynchronously executing requests. @@ -118,14 +118,14 @@ public abstract class NanoHTTPD { /** * Constructs an HTTP server on given port. */ - public NanoHTTPD(int port) { + NanoHTTPD(int port) { this(null, port); } /** * Constructs an HTTP server on given hostname and port. */ - public NanoHTTPD(String hostname, int port) { + private NanoHTTPD(String hostname, int port) { this.hostname = hostname; this.myPort = port; setTempFileManagerFactory(new DefaultTempFileManagerFactory()); @@ -168,44 +168,38 @@ public abstract class NanoHTTPD { myServerSocket = new ServerSocket(); myServerSocket.bind((hostname != null) ? new InetSocketAddress(hostname, myPort) : new InetSocketAddress(myPort)); - myThread = new Thread(new Runnable() { - @Override - public void run() { - do { - try { - final Socket finalAccept = myServerSocket.accept(); - registerConnection(finalAccept); - finalAccept.setSoTimeout(SOCKET_READ_TIMEOUT); - final InputStream inputStream = finalAccept.getInputStream(); - asyncRunner.exec(new Runnable() { - @Override - public void run() { - OutputStream outputStream = null; - try { - outputStream = finalAccept.getOutputStream(); - TempFileManager tempFileManager = tempFileManagerFactory.create(); - HTTPSession session = new HTTPSession(tempFileManager, inputStream, outputStream, finalAccept.getInetAddress()); - while (!finalAccept.isClosed()) { - session.execute(); - } - } catch (Exception e) { - // When the socket is closed by the client, we throw our own SocketException - // to break the "keep alive" loop above. - if (!(e instanceof SocketException && "NanoHttpd Shutdown".equals(e.getMessage()))) { - e.printStackTrace(); - } - } finally { - safeClose(outputStream); - safeClose(inputStream); - safeClose(finalAccept); - unRegisterConnection(finalAccept); - } + myThread = new Thread(() -> { + do { + try { + final Socket finalAccept = myServerSocket.accept(); + registerConnection(finalAccept); + finalAccept.setSoTimeout(SOCKET_READ_TIMEOUT); + final InputStream inputStream = finalAccept.getInputStream(); + asyncRunner.exec(() -> { + OutputStream outputStream = null; + try { + outputStream = finalAccept.getOutputStream(); + TempFileManager tempFileManager = tempFileManagerFactory.create(); + HTTPSession session = new HTTPSession(tempFileManager, inputStream, outputStream, finalAccept.getInetAddress()); + while (!finalAccept.isClosed()) { + session.execute(); } - }); - } catch (IOException e) { - } - } while (!myServerSocket.isClosed()); - } + } catch (Exception e) { + // When the socket is closed by the client, we throw our own SocketException + // to break the "keep alive" loop above. + if (!(e instanceof SocketException && "NanoHttpd Shutdown".equals(e.getMessage()))) { + e.printStackTrace(); + } + } finally { + safeClose(outputStream); + safeClose(inputStream); + safeClose(finalAccept); + unRegisterConnection(finalAccept); + } + }); + } catch (IOException e) { + } + } while (!myServerSocket.isClosed()); }); myThread.setDaemon(true); myThread.setName("NanoHttpd Main Listener"); @@ -232,7 +226,7 @@ public abstract class NanoHTTPD { * * @param socket the {@link Socket} for the connection. */ - public synchronized void registerConnection(Socket socket) { + private synchronized void registerConnection(Socket socket) { openConnections.add(socket); } @@ -242,14 +236,14 @@ public abstract class NanoHTTPD { * @param socket * the {@link Socket} for the connection. */ - public synchronized void unRegisterConnection(Socket socket) { + private synchronized void unRegisterConnection(Socket socket) { openConnections.remove(socket); } /** * Forcibly closes all connections that are open. */ - public synchronized void closeAllConnections() { + private synchronized void closeAllConnections() { for (Socket socket : openConnections) { safeClose(socket); } @@ -259,7 +253,7 @@ public abstract class NanoHTTPD { return myServerSocket == null ? -1 : myServerSocket.getLocalPort(); } - public final boolean wasStarted() { + private boolean wasStarted() { return myServerSocket != null && myThread != null; } @@ -294,7 +288,7 @@ public abstract class NanoHTTPD { * @param session The HTTP session * @return HTTP response, see class Response for details */ - public Response serve(IHTTPSession session) { + Response serve(IHTTPSession session) { Map<String, String> files = new ArrayMap<>(); Method method = session.getMethod(); if (Method.PUT.equals(method) || Method.POST.equals(method)) { @@ -318,7 +312,7 @@ public abstract class NanoHTTPD { * @param str the percent encoded <code>String</code> * @return expanded form of the input, for example "foo%20bar" becomes "foo bar" */ - protected String decodePercent(String str) { + private String decodePercent(String str) { String decoded = null; try { decoded = URLDecoder.decode(str, "UTF8"); @@ -347,8 +341,8 @@ public abstract class NanoHTTPD { * @param queryString a query string pulled from the URL. * @return a map of <code>String</code> (parameter name) to <code>List<String></code> (a list of the values supplied). */ - protected Map<String, List<String>> decodeParameters(String queryString) { - Map<String, List<String>> parms = new ArrayMap<String, List<String>>(); + private Map<String, List<String>> decodeParameters(String queryString) { + Map<String, List<String>> parms = new ArrayMap<>(); if (queryString != null) { StringTokenizer st = new StringTokenizer(queryString, "&"); while (st.hasMoreTokens()) { @@ -356,7 +350,7 @@ public abstract class NanoHTTPD { int sep = e.indexOf('='); String propertyName = (sep >= 0) ? decodePercent(e.substring(0, sep)).trim() : decodePercent(e).trim(); if (!parms.containsKey(propertyName)) { - parms.put(propertyName, new ArrayList<String>()); + parms.put(propertyName, new ArrayList<>()); } String propertyValue = (sep >= 0) ? decodePercent(e.substring(sep + 1)) : null; if (propertyValue != null) { @@ -378,7 +372,7 @@ public abstract class NanoHTTPD { * * @param asyncRunner new strategy for handling threads. */ - public void setAsyncRunner(AsyncRunner asyncRunner) { + private void setAsyncRunner(AsyncRunner asyncRunner) { this.asyncRunner = asyncRunner; } @@ -393,7 +387,7 @@ public abstract class NanoHTTPD { * * @param tempFileManagerFactory new strategy for handling temp files. */ - public void setTempFileManagerFactory(TempFileManagerFactory tempFileManagerFactory) { + private void setTempFileManagerFactory(TempFileManagerFactory tempFileManagerFactory) { this.tempFileManagerFactory = tempFileManagerFactory; } @@ -448,9 +442,9 @@ public abstract class NanoHTTPD { * themselves up when no longer needed.</p> */ public interface TempFile { - OutputStream open() throws Exception; + OutputStream open(); - void delete() throws Exception; + void delete(); String getName(); } @@ -490,7 +484,7 @@ public abstract class NanoHTTPD { public DefaultTempFileManager() { tmpdir = System.getProperty("java.io.tmpdir"); - tempFiles = new ArrayList<TempFile>(); + tempFiles = new ArrayList<>(); } @Override @@ -528,12 +522,12 @@ public abstract class NanoHTTPD { } @Override - public OutputStream open() throws Exception { + public OutputStream open() { return fstream; } @Override - public void delete() throws Exception { + public void delete() { safeClose(fstream); file.delete(); } @@ -563,7 +557,7 @@ public abstract class NanoHTTPD { /** * Headers for the HTTP response. Use addHeader() to add lines. */ - private Map<String, String> header = new ArrayMap<String, String>(); + private final Map<String, String> header = new ArrayMap<>(); /** * The request method that spawned this response. */ @@ -616,7 +610,7 @@ public abstract class NanoHTTPD { /** * Sends given response to the socket. */ - protected void send(OutputStream outputStream) { + void send(OutputStream outputStream) { String mime = mimeType; SimpleDateFormat gmtFrmt = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss 'GMT'", Locale.US); gmtFrmt.setTimeZone(TimeZone.getTimeZone("GMT")); @@ -661,13 +655,13 @@ public abstract class NanoHTTPD { } } - protected void sendContentLengthHeaderIfNotAlreadyPresent(PrintWriter pw, Map<String, String> header, int size) { + void sendContentLengthHeaderIfNotAlreadyPresent(PrintWriter pw, Map<String, String> header, int size) { if (!headerAlreadySent(header, "content-length")) { pw.print("Content-Length: "+ size +"\r\n"); } } - protected void sendConnectionHeaderIfNotAlreadyPresent(PrintWriter pw, Map<String, String> header) { + void sendConnectionHeaderIfNotAlreadyPresent(PrintWriter pw, Map<String, String> header) { if (!headerAlreadySent(header, "connection")) { pw.print("Connection: keep-alive\r\n"); } @@ -694,7 +688,7 @@ public abstract class NanoHTTPD { outputStream.write(buff, 0, read); outputStream.write(CRLF); } - outputStream.write(String.format("0\r\n\r\n").getBytes()); + outputStream.write("0\r\n\r\n".getBytes()); } private void sendAsFixedLength(OutputStream outputStream, int pending) throws IOException { @@ -844,7 +838,7 @@ public abstract class NanoHTTPD { public static final int BUFSIZE = 8192; private final TempFileManager tempFileManager; private final OutputStream outputStream; - private PushbackInputStream inputStream; + private final PushbackInputStream inputStream; private int splitbyte; private int rlen; private String uri; @@ -865,7 +859,7 @@ public abstract class NanoHTTPD { this.inputStream = new PushbackInputStream(inputStream, BUFSIZE); this.outputStream = outputStream; String remoteIp = inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress() ? "127.0.0.1" : inetAddress.getHostAddress().toString(); - headers = new ArrayMap<String, String>(); + headers = new ArrayMap<>(); headers.put("remote-addr", remoteIp); headers.put("http-client-ip", remoteIp); @@ -909,16 +903,16 @@ public abstract class NanoHTTPD { inputStream.unread(buf, splitbyte, rlen - splitbyte); } - parms = new ArrayMap<String, String>(); + parms = new ArrayMap<>(); if(null == headers) { - headers = new ArrayMap<String, String>(); + headers = new ArrayMap<>(); } // Create a BufferedReader for parsing the header. BufferedReader hin = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buf, 0, rlen))); // Decode the header into parms and header java properties - Map<String, String> pre = new ArrayMap<String, String>(); + Map<String, String> pre = new ArrayMap<>(); decodeHeader(hin, pre, parms, headers); method = Method.lookup(pre.get("method")); @@ -1116,7 +1110,7 @@ public abstract class NanoHTTPD { throw new ResponseException(Response.Status.BAD_REQUEST, "BAD REQUEST: Content type is multipart/form-data but next chunk does not start with boundary. Usage: GET /example/file.html"); } boundarycount++; - Map<String, String> item = new ArrayMap<String, String>(); + Map<String, String> item = new ArrayMap<>(); mpline = in.readLine(); while (mpline != null && mpline.trim().length() > 0) { int p = mpline.indexOf(':'); @@ -1131,7 +1125,7 @@ public abstract class NanoHTTPD { throw new ResponseException(Response.Status.BAD_REQUEST, "BAD REQUEST: Content type is multipart/form-data but no content-disposition info found. Usage: GET /example/file.html"); } StringTokenizer st = new StringTokenizer(contentDisposition, ";"); - Map<String, String> disposition = new ArrayMap<String, String>(); + Map<String, String> disposition = new ArrayMap<>(); while (st.hasMoreTokens()) { String token = st.nextToken().trim(); int p = token.indexOf('='); @@ -1144,17 +1138,19 @@ public abstract class NanoHTTPD { String value = ""; if (item.get("content-type") == null) { + StringBuilder tmp = new StringBuilder(); while (mpline != null && !mpline.contains(boundary)) { mpline = in.readLine(); if (mpline != null) { int d = mpline.indexOf(boundary); if (d == -1) { - value += mpline; + tmp.append(mpline); } else { - value += mpline.substring(0, d - 2); + tmp.append(mpline.substring(0, d - 2)); } } } + value = tmp.toString(); } else { if (boundarycount > bpositions.length) { throw new ResponseException(Response.Status.INTERNAL_ERROR, "Error processing request"); @@ -1196,7 +1192,7 @@ public abstract class NanoHTTPD { private int[] getBoundaryPositions(ByteBuffer b, byte[] boundary) { int matchcount = 0; int matchbyte = -1; - List<Integer> matchbytes = new ArrayList<Integer>(); + List<Integer> matchbytes = new ArrayList<>(); for (int i = 0; i < b.limit(); i++) { if (b.get(i) == boundary[matchcount]) { if (matchcount == 0) @@ -1326,7 +1322,9 @@ public abstract class NanoHTTPD { } public static class Cookie { - private String n, v, e; + private final String n; + private final String v; + private final String e; public Cookie(String name, String value, String expires) { n = name; @@ -1366,8 +1364,8 @@ public abstract class NanoHTTPD { * @author LordFokas */ public class CookieHandler implements Iterable<String> { - private ArrayMap<String, String> cookies = new ArrayMap<String, String>(); - private ArrayList<Cookie> queue = new ArrayList<Cookie>(); + private final ArrayMap<String, String> cookies = new ArrayMap<>(); + private final ArrayList<Cookie> queue = new ArrayList<>(); public CookieHandler(Map<String, String> httpHeaders) { String raw = httpHeaders.get("cookie"); diff --git a/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/AtomGenerator.java b/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/AtomGenerator.java index bd3df0f9d..afe15f1b2 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/AtomGenerator.java +++ b/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/AtomGenerator.java @@ -19,7 +19,7 @@ public class AtomGenerator implements FeedGenerator{ private static final String NS_ATOM = "http://www.w3.org/2005/Atom"; - public static final long FEATURE_USE_RFC3339LOCAL = 1; + private static final long FEATURE_USE_RFC3339LOCAL = 1; @Override public void writeFeed(Feed feed, OutputStream outputStream, String encoding, long flags) throws IOException { diff --git a/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/FeedGenerator.java b/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/FeedGenerator.java index 142e3cb57..b63159384 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/FeedGenerator.java +++ b/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/FeedGenerator.java @@ -24,5 +24,5 @@ public interface FeedGenerator { * @param encoding The encoding to use. Must not be null. * @param flags Optional argument for enabling implementation-dependent features. */ - public void writeFeed(Feed feed, OutputStream outputStream, String encoding, long flags) throws IOException; + void writeFeed(Feed feed, OutputStream outputStream, String encoding, long flags) throws IOException; } diff --git a/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/GeneratorUtil.java b/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/GeneratorUtil.java index e7cbb1b42..7f6f0fb0f 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/GeneratorUtil.java +++ b/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/GeneratorUtil.java @@ -7,7 +7,7 @@ import java.io.IOException; /** * Utility methods for FeedGenerator */ -public class GeneratorUtil { +class GeneratorUtil { public static void addPaymentLink(XmlSerializer xml, String paymentLink, boolean withNamespace) throws IOException { String ns = (withNamespace) ? "http://www.w3.org/2005/Atom" : null; diff --git a/app/src/free/java/de/danoeh/antennapod/config/CastCallbackImpl.java b/app/src/free/java/de/danoeh/antennapod/config/CastCallbackImpl.java index 5e714f02c..fb23dfa1a 100644 --- a/app/src/free/java/de/danoeh/antennapod/config/CastCallbackImpl.java +++ b/app/src/free/java/de/danoeh/antennapod/config/CastCallbackImpl.java @@ -2,6 +2,6 @@ package de.danoeh.antennapod.config; import de.danoeh.antennapod.core.CastCallbacks; -public class CastCallbackImpl implements CastCallbacks { +class CastCallbackImpl implements CastCallbacks { } diff --git a/app/src/free/java/de/danoeh/antennapod/preferences/PreferenceControllerFlavorHelper.java b/app/src/free/java/de/danoeh/antennapod/preferences/PreferenceControllerFlavorHelper.java index de604c7c4..4e2c40885 100644 --- a/app/src/free/java/de/danoeh/antennapod/preferences/PreferenceControllerFlavorHelper.java +++ b/app/src/free/java/de/danoeh/antennapod/preferences/PreferenceControllerFlavorHelper.java @@ -5,7 +5,7 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; /** * Implements functions from PreferenceController that are flavor dependent. */ -public class PreferenceControllerFlavorHelper { +class PreferenceControllerFlavorHelper { static void setupFlavoredUI(PreferenceController.PreferenceUI ui) { ui.findPreference(UserPreferences.PREF_CAST_ENABLED).setEnabled(false); diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5b5c1e5ad..5ff41ea30 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -97,15 +97,6 @@ android:launchMode="singleInstance"/> <activity - android:name=".activity.PreferenceActivityGingerbread" - android:configChanges="keyboardHidden|orientation|screenSize" - android:label="@string/settings_label"> - <meta-data - android:name="android.support.PARENT_ACTIVITY" - android:value="de.danoeh.antennapod.activity.MainActivity"/> - </activity> - - <activity android:name=".activity.PreferenceActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:label="@string/settings_label"> @@ -177,6 +168,13 @@ android:value="de.danoeh.antennapod.activity.PreferenceActivity"/> </activity> <activity + android:name=".activity.ImportExportActivity" + android:label="@string/import_export"> + <meta-data + android:name="android.support.PARENT_ACTIVITY" + android:value="de.danoeh.antennapod.activity.PreferenceActivity"/> + </activity> + <activity android:name=".activity.OpmlImportFromPathActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:label="@string/opml_import_label"> diff --git a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java index f6a8db5fb..3abf7557a 100644 --- a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java +++ b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java @@ -41,10 +41,8 @@ public class PodcastApp extends Application { .detectLeakedSqlLiteObjects() .penaltyLog() .penaltyDropBox(); - if (Build.VERSION.SDK_INT >= 11) { - builder.detectActivityLeaks(); - builder.detectLeakedClosableObjects(); - } + builder.detectActivityLeaks(); + builder.detectLeakedClosableObjects(); if(Build.VERSION.SDK_INT >= 16) { builder.detectLeakedRegistrationObjects(); } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index 1b42b274c..041053a25 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -75,53 +75,50 @@ public class AboutActivity extends AppCompatActivity { } private void loadAsset(String filename) { - subscription = Observable.create(new Observable.OnSubscribe<String>() { - @Override - public void call(Subscriber<? super String> subscriber) { - InputStream input = null; - try { - TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes( - new int[] { android.R.attr.textColorPrimary }); - int colorResource = res.getColor(0, 0); - String colorString = String.format("#%06X", 0xFFFFFF & colorResource); - res.recycle(); - input = getAssets().open(filename); - String webViewData = IOUtils.toString(input, Charset.defaultCharset()); - if(!webViewData.startsWith("<!DOCTYPE html>")) { - //webViewData = webViewData.replace("\n\n", "</p><p>"); - webViewData = webViewData.replace("%", "%"); - webViewData = - "<!DOCTYPE html>" + - "<html>" + - "<head>" + - " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">" + - " <style type=\"text/css\">" + - " @font-face {" + - " font-family: 'Roboto-Light';" + - " src: url('file:///android_asset/Roboto-Light.ttf');" + - " }" + - " * {" + - " color: %s;" + - " font-family: roboto-Light;" + - " font-size: 8pt;" + - " }" + - " </style>" + - "</head><body><p>" + webViewData + "</p></body></html>"; - webViewData = webViewData.replace("\n", "<br/>"); - depth++; - } else { - depth = 0; - } - webViewData = String.format(webViewData, colorString); - subscriber.onNext(webViewData); - } catch (IOException e) { - subscriber.onError(e); - } finally { - IOUtils.closeQuietly(input); - } - subscriber.onCompleted(); - } - }) + subscription = Observable.create((Observable.OnSubscribe<String>) subscriber -> { + InputStream input = null; + try { + TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes( + new int[] { android.R.attr.textColorPrimary }); + int colorResource = res.getColor(0, 0); + String colorString = String.format("#%06X", 0xFFFFFF & colorResource); + res.recycle(); + input = getAssets().open(filename); + String webViewData = IOUtils.toString(input, Charset.defaultCharset()); + if(!webViewData.startsWith("<!DOCTYPE html>")) { + //webViewData = webViewData.replace("\n\n", "</p><p>"); + webViewData = webViewData.replace("%", "%"); + webViewData = + "<!DOCTYPE html>" + + "<html>" + + "<head>" + + " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">" + + " <style type=\"text/css\">" + + " @font-face {" + + " font-family: 'Roboto-Light';" + + " src: url('file:///android_asset/Roboto-Light.ttf');" + + " }" + + " * {" + + " color: %s;" + + " font-family: roboto-Light;" + + " font-size: 8pt;" + + " }" + + " </style>" + + "</head><body><p>" + webViewData + "</p></body></html>"; + webViewData = webViewData.replace("\n", "<br/>"); + depth++; + } else { + depth = 0; + } + webViewData = String.format(webViewData, colorString); + subscriber.onNext(webViewData); + } catch (IOException e) { + subscriber.onError(e); + } finally { + IOUtils.closeQuietly(input); + } + subscriber.onCompleted(); + }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java index ca214de9e..123f66661 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -6,6 +6,7 @@ import android.text.TextUtils; import android.util.Log; import android.view.View; +import java.text.DecimalFormat; import java.util.concurrent.atomic.AtomicBoolean; import de.danoeh.antennapod.core.feed.MediaType; @@ -18,15 +19,18 @@ import de.danoeh.antennapod.dialog.VariableSpeedDialog; * Activity for playing audio files. */ public class AudioplayerActivity extends MediaplayerInfoActivity { - public static final String TAG = "AudioPlayerActivity"; + private static final String TAG = "AudioPlayerActivity"; - private AtomicBoolean isSetup = new AtomicBoolean(false); + private final AtomicBoolean isSetup = new AtomicBoolean(false); @Override protected void onResume() { super.onResume(); if (TextUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) { Intent intent = getIntent(); + if (intent.getData() == null) { + return; + } Log.d(TAG, "Received VIEW intent: " + intent.getData().getPath()); ExternalMedia media = new ExternalMedia(intent.getData().getPath(), MediaType.AUDIO); @@ -40,7 +44,8 @@ public class AudioplayerActivity extends MediaplayerInfoActivity { startService(launchIntent); } else if (PlaybackService.isCasting()) { Intent intent = PlaybackService.getPlayerActivityIntent(this); - if (!intent.getComponent().getClassName().equals(AudioplayerActivity.class.getName())) { + if (intent.getComponent() != null && + !intent.getComponent().getClassName().equals(AudioplayerActivity.class.getName())) { saveCurrentFragment(); finish(); startActivity(intent); @@ -95,7 +100,7 @@ public class AudioplayerActivity extends MediaplayerInfoActivity { UserPreferences.setPlaybackSpeed(String.valueOf(speed)); } } - String speedStr = String.format("%.2fx", speed); + String speedStr = new DecimalFormat("0.00x").format(speed); butPlaybackSpeed.setText(speedStr); } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java index a7e9b1e70..871e9c279 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java @@ -13,9 +13,9 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService; * Activity for controlling the remote playback on a Cast device. */ public class CastplayerActivity extends MediaplayerInfoActivity { - public static final String TAG = "CastPlayerActivity"; + private static final String TAG = "CastPlayerActivity"; - private AtomicBoolean isSetup = new AtomicBoolean(false); + private final AtomicBoolean isSetup = new AtomicBoolean(false); @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java index 41b2debdc..e726afaec 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java @@ -3,15 +3,14 @@ package de.danoeh.antennapod.activity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; -import android.util.Log; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import org.apache.commons.lang3.Validate; -import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.DownloadRequest; @@ -23,8 +22,7 @@ import de.danoeh.antennapod.core.storage.DownloadRequester; * Other arguments are optional. * The activity's result will be the same DownloadRequest with the entered username and password. */ -public class DownloadAuthenticationActivity extends ActionBarActivity { - private static final String TAG = "DownloadAuthenticationActivity"; +public class DownloadAuthenticationActivity extends AppCompatActivity { /** * The download request object that contains information about the resource that requires a username and a password @@ -36,47 +34,39 @@ public class DownloadAuthenticationActivity extends ActionBarActivity { */ public static final String ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL = "send_to_downloadrequester"; - public static final String RESULT_REQUEST = "request"; + private static final String RESULT_REQUEST = "request"; private EditText etxtUsername; private EditText etxtPassword; - private Button butConfirm; - private Button butCancel; - private TextView txtvDescription; - - private DownloadRequest request; - private boolean sendToDownloadRequester; @Override protected void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getTheme()); super.onCreate(savedInstanceState); - getSupportActionBar().hide(); - setContentView(R.layout.download_authentication_activity); + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.hide(); + } + setContentView(R.layout.download_authentication_activity); + TextView txtvDescription = (TextView) findViewById(R.id.txtvDescription); etxtUsername = (EditText) findViewById(R.id.etxtUsername); etxtPassword = (EditText) findViewById(R.id.etxtPassword); - butConfirm = (Button) findViewById(R.id.butConfirm); - butCancel = (Button) findViewById(R.id.butCancel); - txtvDescription = (TextView) findViewById(R.id.txtvDescription); + Button butConfirm = (Button) findViewById(R.id.butConfirm); + Button butCancel = (Button) findViewById(R.id.butCancel); Validate.isTrue(getIntent().hasExtra(ARG_DOWNLOAD_REQUEST), "Download request missing"); + DownloadRequest request = getIntent().getParcelableExtra(ARG_DOWNLOAD_REQUEST); + boolean sendToDownloadRequester = getIntent().getBooleanExtra(ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, false); - request = getIntent().getParcelableExtra(ARG_DOWNLOAD_REQUEST); - sendToDownloadRequester = getIntent().getBooleanExtra(ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, false); + String newDescription = txtvDescription.getText() + ":\n\n" + request.getTitle(); + txtvDescription.setText(newDescription); if (savedInstanceState != null) { etxtUsername.setText(savedInstanceState.getString("username")); etxtPassword.setText(savedInstanceState.getString("password")); } - txtvDescription.setText(txtvDescription.getText() + ":\n\n" + request.getTitle()); - - butCancel.setOnClickListener(v -> { - setResult(Activity.RESULT_CANCELED); - finish(); - }); - butConfirm.setOnClickListener(v -> { String username = etxtUsername.getText().toString(); String password = etxtPassword.getText().toString(); @@ -87,11 +77,16 @@ public class DownloadAuthenticationActivity extends ActionBarActivity { setResult(Activity.RESULT_OK, result); if (sendToDownloadRequester) { - if (BuildConfig.DEBUG) Log.d(TAG, "Sending request to DownloadRequester"); DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request); } finish(); }); + + butCancel.setOnClickListener(v -> { + setResult(Activity.RESULT_CANCELED); + finish(); + }); + } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java index 2a58d5104..8dea41b7c 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java @@ -88,16 +88,10 @@ public class FeedInfoActivity extends AppCompatActivity { public void onClick(View v) { if(feed != null && feed.getDownload_url() != null) { String url = feed.getDownload_url(); - if (android.os.Build.VERSION.SDK_INT >= 11) { - ClipData clipData = ClipData.newPlainText(url, url); - android.content.ClipboardManager cm = (android.content.ClipboardManager) FeedInfoActivity.this - .getSystemService(Context.CLIPBOARD_SERVICE); - cm.setPrimaryClip(clipData); - } else { - android.text.ClipboardManager cm = (android.text.ClipboardManager) FeedInfoActivity.this - .getSystemService(Context.CLIPBOARD_SERVICE); - cm.setText(url); - } + ClipData clipData = ClipData.newPlainText(url, url); + android.content.ClipboardManager cm = (android.content.ClipboardManager) FeedInfoActivity.this + .getSystemService(Context.CLIPBOARD_SERVICE); + cm.setPrimaryClip(clipData); Toast t = Toast.makeText(FeedInfoActivity.this, R.string.copied_url_msg, Toast.LENGTH_SHORT); t.show(); } @@ -106,7 +100,7 @@ public class FeedInfoActivity extends AppCompatActivity { private boolean authInfoChanged = false; - private TextWatcher authTextWatcher = new TextWatcher() { + private final TextWatcher authTextWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @@ -123,7 +117,7 @@ public class FeedInfoActivity extends AppCompatActivity { private boolean filterTextChanged = false; - private TextWatcher filterTextWatcher = new TextWatcher() { + private final TextWatcher filterTextWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @@ -385,7 +379,7 @@ public class FeedInfoActivity extends AppCompatActivity { } } - private class ApplyToEpisodesDialog extends ConfirmationDialog { + private static class ApplyToEpisodesDialog extends ConfirmationDialog { private final Feed feed; private final boolean autoDownload; diff --git a/app/src/main/java/de/danoeh/antennapod/activity/FlattrAuthActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/FlattrAuthActivity.java index be1c9f9e6..d9c250b38 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/FlattrAuthActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/FlattrAuthActivity.java @@ -18,7 +18,6 @@ import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.flattr.FlattrUtils; -import de.danoeh.antennapod.preferences.PreferenceController; /** Guides the user through the authentication process */ @@ -104,7 +103,7 @@ public class FlattrAuthActivity extends ActionBarActivity { switch (item.getItemId()) { case android.R.id.home: if (authSuccessful) { - Intent intent = new Intent(this, PreferenceController.getPreferenceActivity()); + Intent intent = new Intent(this, PreferenceActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } else { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/ImportExportActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/ImportExportActivity.java new file mode 100644 index 000000000..6a97adcc3 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/activity/ImportExportActivity.java @@ -0,0 +1,185 @@ +package de.danoeh.antennapod.activity; + +import android.content.ComponentName; +import android.content.Intent; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.os.Environment; +import android.os.ParcelFileDescriptor; +import android.support.design.widget.Snackbar; +import android.support.v4.content.IntentCompat; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.MenuItem; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.core.storage.PodDBAdapter; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.channels.FileChannel; + +/** + * Displays the 'import/export' screen + */ +public class ImportExportActivity extends AppCompatActivity { + private static final int REQUEST_CODE_RESTORE = 43; + private static final int REQUEST_CODE_BACKUP_DOCUMENT = 44; + private static final String EXPORT_FILENAME = "AntennaPodBackup.db"; + private static final String TAG = ImportExportActivity.class.getSimpleName(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + setTheme(UserPreferences.getTheme()); + super.onCreate(savedInstanceState); + getSupportActionBar().setDisplayShowHomeEnabled(true); + setContentView(R.layout.import_export_activity); + + findViewById(R.id.button_export).setOnClickListener(view -> backup()); + findViewById(R.id.button_import).setOnClickListener(view -> restore()); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } else { + return super.onOptionsItemSelected(item); + } + } + + private void backup() { + if (Build.VERSION.SDK_INT >= 19) { + Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT) + .addCategory(Intent.CATEGORY_OPENABLE) + .setType("application/x-sqlite3") + .putExtra(Intent.EXTRA_TITLE, EXPORT_FILENAME); + + startActivityForResult(intent, REQUEST_CODE_BACKUP_DOCUMENT); + } else { + try { + File sd = Environment.getExternalStorageDirectory(); + File backupDB = new File(sd, EXPORT_FILENAME); + writeBackupTo(new FileOutputStream(backupDB)); + } catch (IOException e) { + Log.e(TAG, Log.getStackTraceString(e)); + Snackbar.make(findViewById(R.id.import_export_layout), e.getLocalizedMessage(), Snackbar.LENGTH_SHORT).show(); + } + } + } + + private void restore() { + if (Build.VERSION.SDK_INT >= 19) { + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.setType("*/*"); + startActivityForResult(intent, REQUEST_CODE_RESTORE); + } else { + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("*/*"); + startActivityForResult(Intent.createChooser(intent, + getString(R.string.import_select_file)), REQUEST_CODE_RESTORE); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent resultData) { + if (resultCode != RESULT_OK || resultData == null) { + return; + } + Uri uri = resultData.getData(); + + if (requestCode == REQUEST_CODE_RESTORE) { + restoreFrom(uri); + } else if (requestCode == REQUEST_CODE_BACKUP_DOCUMENT) { + backupToDocument(uri); + } + } + + private void restoreFrom(Uri inputUri) { + File currentDB = getDatabasePath(PodDBAdapter.DATABASE_NAME); + InputStream inputStream = null; + try { + inputStream = getContentResolver().openInputStream(inputUri); + FileUtils.copyInputStreamToFile(inputStream, currentDB); + displayImportSuccessDialog(); + } catch (IOException e) { + Log.e(TAG, Log.getStackTraceString(e)); + Snackbar.make(findViewById(R.id.import_export_layout), e.getLocalizedMessage(), Snackbar.LENGTH_SHORT).show(); + } finally { + IOUtils.closeQuietly(inputStream); + } + } + + private void displayImportSuccessDialog() { + AlertDialog.Builder d = new AlertDialog.Builder(ImportExportActivity.this); + d.setMessage(R.string.import_ok); + d.setCancelable(false); + d.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> { + Intent intent = new Intent(getApplicationContext(), SplashActivity.class); + ComponentName cn = intent.getComponent(); + Intent mainIntent = IntentCompat.makeRestartActivityTask(cn); + startActivity(mainIntent); + }); + d.show(); + } + + private void backupToDocument(Uri uri) { + ParcelFileDescriptor pfd = null; + FileOutputStream fileOutputStream = null; + try { + pfd = getContentResolver().openFileDescriptor(uri, "w"); + fileOutputStream = new FileOutputStream(pfd.getFileDescriptor()); + writeBackupTo(fileOutputStream); + + Snackbar.make(findViewById(R.id.import_export_layout), + R.string.export_ok, Snackbar.LENGTH_SHORT).show(); + } catch (IOException e) { + Log.e(TAG, Log.getStackTraceString(e)); + Snackbar.make(findViewById(R.id.import_export_layout), e.getLocalizedMessage(), Snackbar.LENGTH_SHORT).show(); + } finally { + IOUtils.closeQuietly(fileOutputStream); + + if (pfd != null) { + try { + pfd.close(); + } catch (IOException e) { + Log.d(TAG, "Unable to close ParcelFileDescriptor"); + } + } + } + } + + private void writeBackupTo(FileOutputStream outFileStream) { + FileChannel src = null; + FileChannel dst = null; + try { + File currentDB = getDatabasePath(PodDBAdapter.DATABASE_NAME); + + if (currentDB.exists()) { + src = new FileInputStream(currentDB).getChannel(); + dst = outFileStream.getChannel(); + dst.transferFrom(src, 0, src.size()); + + Snackbar.make(findViewById(R.id.import_export_layout), + R.string.export_ok, Snackbar.LENGTH_SHORT).show(); + } else { + Snackbar.make(findViewById(R.id.import_export_layout), + "Can not access current database", Snackbar.LENGTH_SHORT).show(); + } + } catch (IOException e) { + Log.e(TAG, Log.getStackTraceString(e)); + Snackbar.make(findViewById(R.id.import_export_layout), e.getLocalizedMessage(), Snackbar.LENGTH_SHORT).show(); + } finally { + IOUtils.closeQuietly(src); + IOUtils.closeQuietly(dst); + } + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index f0fcdca90..f56dca173 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -64,7 +64,6 @@ import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.fragment.SubscriptionFragment; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; -import de.danoeh.antennapod.preferences.PreferenceController; import de.greenrobot.event.EventBus; import rx.Observable; import rx.Subscription; @@ -83,7 +82,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi public static final String PREF_NAME = "MainActivityPrefs"; public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch"; - public static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag"; + private static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag"; public static final String EXTRA_NAV_TYPE = "nav_type"; public static final String EXTRA_NAV_INDEX = "nav_index"; @@ -91,8 +90,8 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi public static final String EXTRA_FRAGMENT_ARGS = "fragment_args"; public static final String EXTRA_FEED_ID = "fragment_feed_id"; - public static final String SAVE_BACKSTACK_COUNT = "backstackCount"; - public static final String SAVE_TITLE = "title"; + private static final String SAVE_BACKSTACK_COUNT = "backstackCount"; + private static final String SAVE_TITLE = "title"; public static final String[] NAV_DRAWER_TAGS = { QueueFragment.TAG, @@ -173,7 +172,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi findViewById(R.id.nav_settings).setOnClickListener(v -> { drawerLayout.closeDrawer(navDrawer); - startActivity(new Intent(MainActivity.this, PreferenceController.getPreferenceActivity())); + startActivity(new Intent(MainActivity.this, PreferenceActivity.class)); }); FragmentTransaction transaction = fm.beginTransaction(); @@ -236,7 +235,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi } } - public void showDrawerPreferencesDialog() { + private void showDrawerPreferencesDialog() { final List<String> hiddenDrawerItems = UserPreferences.getHiddenDrawerItems(); String[] navLabels = new String[NAV_DRAWER_TAGS.length]; final boolean[] checked = new boolean[NAV_DRAWER_TAGS.length]; @@ -270,7 +269,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi return (navDrawerData != null) ? navDrawerData.feeds : null; } - public void loadFragment(int index, Bundle args) { + private void loadFragment(int index, Bundle args) { Log.d(TAG, "loadFragment(index: " + index + ", args: " + args + ")"); if (index < navAdapter.getSubscriptionOffset()) { String tag = navAdapter.getTags().get(index); @@ -399,7 +398,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi } } - private AdapterView.OnItemClickListener navListClickListener = new AdapterView.OnItemClickListener() { + private final AdapterView.OnItemClickListener navListClickListener = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { int viewType = parent.getAdapter().getItemViewType(position); @@ -410,7 +409,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi } }; - private AdapterView.OnItemLongClickListener newListLongClickListener = new AdapterView.OnItemLongClickListener() { + private final AdapterView.OnItemLongClickListener newListLongClickListener = new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if(position < navAdapter.getTags().size()) { @@ -631,7 +630,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi private DBReader.NavDrawerData navDrawerData; private int selectedNavListIndex = 0; - private NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() { + private final NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() { @Override public int getCount() { if (navDrawerData != null) { @@ -744,14 +743,12 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi View parentLayout = findViewById(R.id.drawer_layout); Snackbar snackbar = Snackbar.make(parentLayout, event.message, Snackbar.LENGTH_SHORT); if(event.action != null) { - snackbar.setAction(getString(R.string.undo), v -> { - event.action.run(); - }); + snackbar.setAction(getString(R.string.undo), v -> event.action.run()); } snackbar.show(); } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index ffc33eb1a..f3c0760f3 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -67,19 +67,19 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements private static final String PREFS = "MediaPlayerActivityPreferences"; private static final String PREF_SHOW_TIME_LEFT = "showTimeLeft"; - protected PlaybackController controller; + PlaybackController controller; - protected TextView txtvPosition; - protected TextView txtvLength; - protected SeekBar sbPosition; - protected ImageButton butRev; - protected TextView txtvRev; - protected ImageButton butPlay; - protected ImageButton butFF; - protected TextView txtvFF; - protected ImageButton butSkip; + private TextView txtvPosition; + private TextView txtvLength; + SeekBar sbPosition; + private ImageButton butRev; + private TextView txtvRev; + private ImageButton butPlay; + private ImageButton butFF; + private TextView txtvFF; + private ImageButton butSkip; - protected boolean showTimeLeft = false; + private boolean showTimeLeft = false; private boolean isFavorite = false; @@ -184,31 +184,31 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements }; } - protected static TextView getTxtvFFFromActivity(MediaplayerActivity activity) { + private static TextView getTxtvFFFromActivity(MediaplayerActivity activity) { return activity.txtvFF; } - protected static TextView getTxtvRevFromActivity(MediaplayerActivity activity) { + private static TextView getTxtvRevFromActivity(MediaplayerActivity activity) { return activity.txtvRev; } - protected void onSetSpeedAbilityChanged() { + private void onSetSpeedAbilityChanged() { Log.d(TAG, "onSetSpeedAbilityChanged()"); updatePlaybackSpeedButton(); } - protected void onPlaybackSpeedChange() { + private void onPlaybackSpeedChange() { updatePlaybackSpeedButtonText(); } - protected void onServiceQueried() { + private void onServiceQueried() { supportInvalidateOptionsMenu(); } - protected void chooseTheme() { + void chooseTheme() { setTheme(UserPreferences.getTheme()); } - protected void setScreenOn(boolean enable) { + void setScreenOn(boolean enable) { } @Override @@ -251,7 +251,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements */ protected abstract void onBufferEnd(); - protected void onBufferUpdate(float progress) { + private void onBufferUpdate(float progress) { if (sbPosition != null) { sbPosition.setSecondaryProgress((int) progress * sbPosition.getMax()); } @@ -260,7 +260,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements /** * Current screen orientation. */ - protected int orientation; + private int orientation; @Override protected void onStart() { @@ -622,7 +622,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements protected abstract void clearStatusMsg(); - protected void onPositionObserverUpdate() { + void onPositionObserverUpdate() { if (controller == null || txtvPosition == null || txtvLength == null) { return; } @@ -658,7 +658,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements * to the PlaybackService to ensure that the activity has the right * FeedMedia object. */ - protected boolean loadMediaInfo() { + boolean loadMediaInfo() { Log.d(TAG, "loadMediaInfo()"); if(controller == null || controller.getMedia() == null) { return false; @@ -672,18 +672,18 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements return true; } - protected void updatePlaybackSpeedButton() { + void updatePlaybackSpeedButton() { // Only meaningful on AudioplayerActivity, where it is overridden. } - protected void updatePlaybackSpeedButtonText() { + void updatePlaybackSpeedButtonText() { // Only meaningful on AudioplayerActivity, where it is overridden. } /** * Abstract directions to skip forward or back (rewind) and encapsulates behavior to get or set preference (including update of UI on the skip buttons). */ - static public enum SkipDirection { + public enum SkipDirection { SKIP_FORWARD( UserPreferences::getFastForwardSecs, MediaplayerActivity::getTxtvFFFromActivity, @@ -766,7 +766,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements builder.create().show(); } - protected void setupGUI() { + void setupGUI() { setContentView(getContentViewResourceId()); sbPosition = (SeekBar) findViewById(R.id.sbPosition); txtvPosition = (TextView) findViewById(R.id.txtvPosition); @@ -840,7 +840,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements } } - protected void onRewind() { + void onRewind() { if (controller == null) { return; } @@ -848,14 +848,14 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements controller.seekTo(curr - UserPreferences.getRewindSecs() * 1000); } - protected void onPlayPause() { + void onPlayPause() { if(controller == null) { return; } controller.playPause(); } - protected void onFastForward() { + void onFastForward() { if (controller == null) { return; } @@ -865,7 +865,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements protected abstract int getContentViewResourceId(); - void handleError(int errorCode) { + private void handleError(int errorCode) { final AlertDialog.Builder errorDialog = new AlertDialog.Builder(this); errorDialog.setTitle(R.string.error_label); errorDialog.setMessage(MediaPlayerError.getErrorString(this, errorCode)); @@ -878,7 +878,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements errorDialog.create().show(); } - float prog; + private float prog; @Override public void onProgressChanged (SeekBar seekBar,int progress, boolean fromUser) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java index cc7d83e0c..f3ed1cb62 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java @@ -61,7 +61,6 @@ import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.fragment.SubscriptionFragment; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; -import de.danoeh.antennapod.preferences.PreferenceController; import de.greenrobot.event.EventBus; import rx.Observable; import rx.Subscription; @@ -73,16 +72,17 @@ import rx.schedulers.Schedulers; */ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implements NavDrawerActivity { + private static final String TAG = "MediaplayerInfoActivity"; + private static final int POS_COVER = 0; private static final int POS_DESCR = 1; private static final int POS_CHAPTERS = 2; private static final int NUM_CONTENT_FRAGMENTS = 3; - final String TAG = "MediaplayerInfoActivity"; private static final String PREFS = "AudioPlayerActivityPreferences"; private static final String PREF_KEY_SELECTED_FRAGMENT_POSITION = "selectedFragmentPosition"; - public static final String[] NAV_DRAWER_TAGS = { + private static final String[] NAV_DRAWER_TAGS = { QueueFragment.TAG, EpisodesFragment.TAG, SubscriptionFragment.TAG, @@ -92,8 +92,8 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem NavListAdapter.SUBSCRIPTION_LIST_TAG }; - protected Button butPlaybackSpeed; - protected ImageButton butCastDisconnect; + Button butPlaybackSpeed; + ImageButton butCastDisconnect; private DrawerLayout drawerLayout; private NavListAdapter navAdapter; private ListView navList; @@ -152,7 +152,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem setTheme(UserPreferences.getNoTitleTheme()); } - protected void saveCurrentFragment() { + void saveCurrentFragment() { if(pager == null) { return; } @@ -160,7 +160,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); prefs.edit() .putInt(PREF_KEY_SELECTED_FRAGMENT_POSITION, pager.getCurrentItem()) - .commit(); + .apply(); } @Override @@ -242,7 +242,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close); drawerToggle.setDrawerIndicatorEnabled(false); - drawerLayout.setDrawerListener(drawerToggle); + drawerLayout.addDrawerListener(drawerToggle); navAdapter = new NavListAdapter(itemAccess, this); navList.setAdapter(navAdapter); @@ -270,7 +270,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem findViewById(R.id.nav_settings).setOnClickListener(v -> { drawerLayout.closeDrawer(navDrawer); - startActivity(new Intent(MediaplayerInfoActivity.this, PreferenceController.getPreferenceActivity())); + startActivity(new Intent(MediaplayerInfoActivity.this, PreferenceActivity.class)); }); butPlaybackSpeed = (Button) findViewById(R.id.butPlaybackSpeed); @@ -306,7 +306,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem return true; } - public void notifyMediaPositionChanged() { + private void notifyMediaPositionChanged() { if(pagerAdapter == null) { return; } @@ -396,12 +396,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem new RenameFeedDialog(this, feed).show(); return true; case R.id.remove_item: - final FeedRemover remover = new FeedRemover(this, feed) { - @Override - protected void onPostExecute(Void result) { - super.onPostExecute(result); - } - }; + final FeedRemover remover = new FeedRemover(this, feed); ConfirmationDialog conDialog = new ConfirmationDialog(this, R.string.remove_feed_label, getString(R.string.feed_delete_confirmation_msg, feed.getTitle())) { @@ -413,7 +408,8 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem Playable playable = controller.getMedia(); if (playable != null && playable instanceof FeedMedia) { FeedMedia media = (FeedMedia) playable; - if (media.getItem().getFeed().getId() == feed.getId()) { + if (media.getItem() != null && media.getItem().getFeed() != null && + media.getItem().getFeed().getId() == feed.getId()) { Log.d(TAG, "Currently playing episode is about to be deleted, skipping"); remover.skipOnCompletion = true; if(controller.getStatus() == PlayerStatus.PLAYING) { @@ -447,7 +443,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem } } - public void showDrawerPreferencesDialog() { + private void showDrawerPreferencesDialog() { final List<String> hiddenDrawerItems = UserPreferences.getHiddenDrawerItems(); String[] navLabels = new String[NAV_DRAWER_TAGS.length]; final boolean[] checked = new boolean[NAV_DRAWER_TAGS.length]; @@ -492,14 +488,12 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem View parentLayout = findViewById(R.id.drawer_layout); Snackbar snackbar = Snackbar.make(parentLayout, event.message, Snackbar.LENGTH_SHORT); if (event.action != null) { - snackbar.setAction(getString(R.string.undo), v -> { - event.action.run(); - }); + snackbar.setAction(getString(R.string.undo), v -> event.action.run()); } snackbar.show(); } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index f6bf11e66..f859f5466 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -5,8 +5,9 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.os.Looper; +import android.support.annotation.UiThread; import android.support.v4.app.NavUtils; +import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; @@ -55,7 +56,6 @@ import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.syndication.handler.FeedHandler; -import de.danoeh.antennapod.core.syndication.handler.FeedHandlerResult; import de.danoeh.antennapod.core.syndication.handler.UnsupportedFeedtypeException; import de.danoeh.antennapod.core.util.DownloadError; import de.danoeh.antennapod.core.util.FileNameGenerator; @@ -66,7 +66,6 @@ import de.danoeh.antennapod.core.util.syndication.HtmlToPlainText; import de.danoeh.antennapod.dialog.AuthenticationDialog; import de.greenrobot.event.EventBus; import rx.Observable; -import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -84,7 +83,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { public static final String ARG_FEEDURL = "arg.feedurl"; // Optional argument: specify a title for the actionbar. public static final String ARG_TITLE = "title"; - public static final int RESULT_ERROR = 2; + private static final int RESULT_ERROR = 2; private static final String TAG = "OnlineFeedViewActivity"; private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE; private volatile List<Feed> feeds; @@ -101,7 +100,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { private Subscription download; private Subscription parser; private Subscription updater; - private EventDistributor.EventListener listener = new EventDistributor.EventListener() { + private final EventDistributor.EventListener listener = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EventDistributor.FEED_LIST_UPDATE) != 0) { @@ -112,9 +111,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { feeds -> { OnlineFeedViewActivity.this.feeds = feeds; setSubscribeButtonState(feed); - }, error -> { - Log.e(TAG, Log.getStackTraceString(error)); - } + }, error -> Log.e(TAG, Log.getStackTraceString(error)) ); } else if ((arg & EVENTS) != 0) { setSubscribeButtonState(feed); @@ -131,10 +128,13 @@ public class OnlineFeedViewActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getTheme()); super.onCreate(savedInstanceState); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + } - if (getIntent() != null && getIntent().hasExtra(ARG_TITLE)) { - getSupportActionBar().setTitle(getIntent().getStringExtra(ARG_TITLE)); + if (actionBar != null && getIntent() != null && getIntent().hasExtra(ARG_TITLE)) { + actionBar.setTitle(getIntent().getStringExtra(ARG_TITLE)); } StorageUtils.checkStorageAvailability(this); @@ -146,7 +146,9 @@ public class OnlineFeedViewActivity extends AppCompatActivity { || TextUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) { feedUrl = (TextUtils.equals(getIntent().getAction(), Intent.ACTION_SEND)) ? getIntent().getStringExtra(Intent.EXTRA_TEXT) : getIntent().getDataString(); - getSupportActionBar().setTitle(R.string.add_feed_label); + if (actionBar != null) { + actionBar.setTitle(R.string.add_feed_label); + } } else { throw new IllegalArgumentException("Activity must be started with feedurl argument!"); } @@ -265,16 +267,11 @@ public class OnlineFeedViewActivity extends AppCompatActivity { feed.getDownload_url(), "OnlineFeed", 0, Feed.FEEDFILETYPE_FEED, username, password, true, null); - download = Observable.create(new Observable.OnSubscribe<DownloadStatus>() { - @Override - public void call(Subscriber<? super DownloadStatus> subscriber) { - feeds = DBReader.getFeedList(); - downloader = new HttpDownloader(request); - downloader.call(); - Log.d(TAG, "Download was completed"); - subscriber.onNext(downloader.getResult()); - subscriber.onCompleted(); - } + download = Observable.fromCallable(() -> { + feeds = DBReader.getFeedList(); + downloader = new HttpDownloader(request); + downloader.call(); + return downloader.getResult(); }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) @@ -286,6 +283,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { if (status == null) { Log.wtf(TAG, "DownloadStatus returned by Downloader was null"); finish(); + return; } if (status.isCancelled()) { return; @@ -300,7 +298,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { } } else { String errorMsg = status.getReason().getErrorString(OnlineFeedViewActivity.this); - if (errorMsg != null && status.getReasonDetailed() != null) { + if (status.getReasonDetailed() != null) { errorMsg += " (" + status.getReasonDetailed() + ")"; } showErrorDialog(errorMsg); @@ -313,35 +311,33 @@ public class OnlineFeedViewActivity extends AppCompatActivity { } Log.d(TAG, "Parsing feed"); - parser = Observable.create(new Observable.OnSubscribe<FeedHandlerResult>() { - @Override - public void call(Subscriber<? super FeedHandlerResult> subscriber) { - FeedHandler handler = new FeedHandler(); - try { - FeedHandlerResult result = handler.parseFeed(feed); - subscriber.onNext(result); - } catch (UnsupportedFeedtypeException e) { - Log.d(TAG, "Unsupported feed type detected"); - if (TextUtils.equals("html", e.getRootElement().toLowerCase())) { - showFeedDiscoveryDialog(new File(feed.getFile_url()), feed.getDownload_url()); - } else { - subscriber.onError(e); - } - } catch (Exception e) { - Log.e(TAG, Log.getStackTraceString(e)); - subscriber.onError(e); - } finally { - boolean rc = new File(feed.getFile_url()).delete(); - Log.d(TAG, "Deleted feed source file. Result: " + rc); - subscriber.onCompleted(); + parser = Observable.fromCallable(() -> { + FeedHandler handler = new FeedHandler(); + try { + return handler.parseFeed(feed); + } catch (UnsupportedFeedtypeException e) { + Log.d(TAG, "Unsupported feed type detected"); + if (TextUtils.equals("html", e.getRootElement().toLowerCase())) { + showFeedDiscoveryDialog(new File(feed.getFile_url()), feed.getDownload_url()); + return null; + } else { + throw e; } + } catch (Exception e) { + Log.e(TAG, Log.getStackTraceString(e)); + throw e; + } finally { + boolean rc = new File(feed.getFile_url()).delete(); + Log.d(TAG, "Deleted feed source file. Result: " + rc); } }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { - beforeShowFeedInformation(result.feed); - showFeedInformation(result.feed, result.alternateFeedUrls); + if(result != null) { + beforeShowFeedInformation(result.feed); + showFeedInformation(result.feed, result.alternateFeedUrls); + } }, error -> { String errorMsg = DownloadError.ERROR_PARSER_EXCEPTION.getErrorString( OnlineFeedViewActivity.this) + " (" + error.getMessage() + ")"; @@ -383,8 +379,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { this.selectedDownloadUrl = feed.getDownload_url(); EventDistributor.getInstance().register(listener); ListView listView = (ListView) findViewById(R.id.listview); - LayoutInflater inflater = (LayoutInflater) - getSystemService(Context.LAYOUT_INFLATER_SERVICE); + LayoutInflater inflater = LayoutInflater.from(this); View header = inflater.inflate(R.layout.onlinefeedview_header, listView, false); listView.addHeaderView(header); @@ -414,7 +409,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { description.setText(feed.getDescription()); subscribeButton.setOnClickListener(v -> { - if(feed != null && feedInFeedlist(feed)) { + if(feedInFeedlist(feed)) { Intent intent = new Intent(OnlineFeedViewActivity.this, MainActivity.class); // feed.getId() is always 0, we have to retrieve the id from the feed list from // the database @@ -508,8 +503,8 @@ public class OnlineFeedViewActivity extends AppCompatActivity { return 0; } + @UiThread private void showErrorDialog(String errorMsg) { - assert(Looper.myLooper() == Looper.getMainLooper()); // run on UI thread if (!isFinishing() && !isPaused) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.error_label); @@ -586,7 +581,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { private class FeedViewAuthenticationDialog extends AuthenticationDialog { - private String feedUrl; + private final String feedUrl; FeedViewAuthenticationDialog(Context context, int titleRes, String feedUrl) { super(context, titleRes, true, false, null, null); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java index 355e0f372..cd375a65a 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java @@ -97,7 +97,7 @@ public class OpmlFeedChooserActivity extends AppCompatActivity { } private List<String> getTitleList() { - List<String> result = new ArrayList<String>(); + List<String> result = new ArrayList<>(); if (OpmlImportHolder.getReadElements() != null) { for (OpmlElement element : OpmlImportHolder.getReadElements()) { result.add(element.getText()); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java index 07b0b3cdb..c04ae051e 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java @@ -68,7 +68,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity { } } - protected void importUri(@Nullable Uri uri) { + void importUri(@Nullable Uri uri) { if(uri == null) { new MaterialDialog.Builder(this) .content(R.string.opml_import_error_no_file) @@ -114,7 +114,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity { } /** Starts the import process. */ - protected void startImport() { + private void startImport() { try { Reader mReader = new InputStreamReader(getContentResolver().openInputStream(uri), LangUtils.UTF_8); importWorker = new OpmlImportWorker(this, mReader) { @@ -144,7 +144,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity { } } - protected boolean finishWhenCanceled() { + boolean finishWhenCanceled() { return false; } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java index dd932814f..12d918a76 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -1,9 +1,7 @@ package de.danoeh.antennapod.activity; -import android.annotation.TargetApi; import android.app.Activity; import android.content.Intent; -import android.os.Build; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; @@ -30,7 +28,6 @@ public class PreferenceActivity extends AppCompatActivity { private PreferenceController preferenceController; private MainFragment prefFragment; private final PreferenceController.PreferenceUI preferenceUI = new PreferenceController.PreferenceUI() { - @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public Preference findPreference(CharSequence key) { return prefFragment.findPreference(key); @@ -42,7 +39,6 @@ public class PreferenceActivity extends AppCompatActivity { } }; - @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override protected void onCreate(Bundle savedInstanceState) { // This must be the FIRST thing we do, otherwise other code may not have the @@ -95,7 +91,6 @@ public class PreferenceActivity extends AppCompatActivity { } } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static class MainFragment extends PreferenceFragment { @Override diff --git a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java deleted file mode 100644 index 390bec15c..000000000 --- a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java +++ /dev/null @@ -1,97 +0,0 @@ -package de.danoeh.antennapod.activity; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Intent; -import android.content.res.Resources.Theme; -import android.os.Bundle; -import android.preference.Preference; -import android.preference.PreferenceScreen; - -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.preferences.PreferenceController; - -/** - * PreferenceActivity for API 10. In order to change the behavior of the preference UI, see - * PreferenceController. - */ -public class PreferenceActivityGingerbread extends android.preference.PreferenceActivity { - private static final String TAG = "PreferenceActivity"; - private final PreferenceController.PreferenceUI preferenceUI = new PreferenceController.PreferenceUI() { - - @SuppressWarnings("deprecation") - @Override - public Preference findPreference(CharSequence key) { - return PreferenceActivityGingerbread.this.findPreference(key); - } - - @Override - public Activity getActivity() { - return PreferenceActivityGingerbread.this; - } - }; - private PreferenceController preferenceController; - - @SuppressLint("NewApi") - @SuppressWarnings("deprecation") - @Override - public void onCreate(Bundle savedInstanceState) { - setTheme(UserPreferences.getTheme()); - super.onCreate(savedInstanceState); - - addPreferencesFromResource(R.xml.preferences); - preferenceController = new PreferenceController(preferenceUI); - preferenceController.onCreate(); - } - - - @Override - protected void onResume() { - super.onResume(); - preferenceController.onResume(); - } - - @Override - protected void onPause() { - preferenceController.onPause(); - super.onPause(); - } - - @Override - protected void onStop() { - preferenceController.onStop(); - super.onStop(); - } - - @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); - preferenceController.onActivityResult(requestCode, resultCode, data); - } - - @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/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java index d104a9e93..a2a49f54e 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java @@ -164,7 +164,7 @@ public class StorageErrorActivity extends AppCompatActivity { startActivity(new Intent(this, MainActivity.class)); } - private BroadcastReceiver mediaUpdate = new BroadcastReceiver() { + private final BroadcastReceiver mediaUpdate = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java index 90b4c72ea..be5107d75 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java @@ -7,6 +7,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.v4.view.WindowCompat; +import android.support.v7.app.ActionBar; import android.util.Log; import android.util.Pair; import android.view.Menu; @@ -47,7 +48,7 @@ public class VideoplayerActivity extends MediaplayerActivity { private VideoControlsHider videoControlsHider = new VideoControlsHider(this); - private AtomicBoolean isSetup = new AtomicBoolean(false); + private final AtomicBoolean isSetup = new AtomicBoolean(false); private LinearLayout controls; private LinearLayout videoOverlay; @@ -182,7 +183,7 @@ public class VideoplayerActivity extends MediaplayerActivity { progressIndicator.setVisibility(View.INVISIBLE); } - private View.OnTouchListener onVideoviewTouched = (v, event) -> { + private final View.OnTouchListener onVideoviewTouched = (v, event) -> { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInPictureInPictureMode()) { @@ -200,7 +201,7 @@ public class VideoplayerActivity extends MediaplayerActivity { }; @SuppressLint("NewApi") - void setupVideoControlsToggler() { + private void setupVideoControlsToggler() { videoControlsHider.stop(); videoControlsHider.start(); } @@ -400,18 +401,21 @@ public class VideoplayerActivity extends MediaplayerActivity { private WeakReference<VideoplayerActivity> activity; - public VideoControlsHider(VideoplayerActivity activity) { + VideoControlsHider(VideoplayerActivity activity) { this.activity = new WeakReference<>(activity); } private final Runnable hideVideoControls = () -> { - VideoplayerActivity vpa = activity.get(); + VideoplayerActivity vpa = activity != null ? activity.get() : null; if (vpa == null) { return; } if (vpa.videoControlsShowing) { Log.d(TAG, "Hiding video controls"); - vpa.getSupportActionBar().hide(); + ActionBar actionBar = vpa.getSupportActionBar(); + if (actionBar != null) { + actionBar.hide(); + } vpa.hideVideoControls(); vpa.videoControlsShowing = false; } @@ -421,7 +425,7 @@ public class VideoplayerActivity extends MediaplayerActivity { this.postDelayed(hideVideoControls, DELAY); } - public void stop() { + void stop() { this.removeCallbacks(hideVideoControls); } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java index 8ede947c5..8f447ac90 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java @@ -61,7 +61,7 @@ public class GpodnetAuthenticationActivity extends AppCompatActivity { private volatile String password; private volatile GpodnetDevice selectedDevice; - View[] views; + private View[] views; @Override protected void onCreate(Bundle savedInstanceState) { @@ -171,11 +171,7 @@ public class GpodnetAuthenticationActivity extends AppCompatActivity { return null; } }; - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - authTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, service); - } else { - authTask.execute(); - } + authTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, service); } }); } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonCallback.java b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonCallback.java index c18564351..e6b42efcb 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonCallback.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonCallback.java @@ -3,7 +3,7 @@ package de.danoeh.antennapod.adapter; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.util.LongList; -public interface ActionButtonCallback { +interface ActionButtonCallback { /** Is called when the action button of a list item has been pressed. */ void onActionButtonPressed(FeedItem item, LongList queueIds); } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java index f0210f983..a915692d1 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java @@ -16,7 +16,7 @@ import de.danoeh.antennapod.core.storage.DownloadRequester; * Utility methods for the action button that is displayed on the right hand side * of a listitem. */ -public class ActionButtonUtils { +class ActionButtonUtils { private final int[] labels; private final TypedArray drawables; diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java index f12c8285a..715318db1 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java @@ -21,7 +21,6 @@ import android.widget.TextView; import com.bumptech.glide.Glide; import com.joanzapata.iconify.Iconify; -import com.nineoldandroids.view.ViewHelper; import java.lang.ref.WeakReference; @@ -101,7 +100,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR holder.txtvDuration = (TextView) view.findViewById(R.id.txtvDuration); holder.item = null; holder.mainActivityRef = mainActivityRef; - holder.position = -1; // so we can grab this later view.setTag(holder); @@ -113,11 +111,10 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR final FeedItem item = itemAccess.getItem(position); if (item == null) return; holder.itemView.setOnLongClickListener(v -> { - this.position = position; + this.position = holder.getAdapterPosition(); return false; }); holder.item = item; - holder.position = position; holder.placeholder.setVisibility(View.VISIBLE); holder.placeholder.setText(item.getFeed().getTitle()); holder.title.setText(item.getTitle()); @@ -129,9 +126,9 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR holder.statusUnread.setVisibility(View.VISIBLE); } if(item.isPlayed()) { - ViewHelper.setAlpha(holder.content, 0.5f); + holder.content.setAlpha(0.5f); } else { - ViewHelper.setAlpha(holder.content, 1.0f); + holder.content.setAlpha(1.0f); } FeedMedia media = item.getMedia(); @@ -228,7 +225,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR return pos; } - private View.OnClickListener secondaryActionListener = new View.OnClickListener() { + private final View.OnClickListener secondaryActionListener = new View.OnClickListener() { @Override public void onClick(View v) { FeedItem item = (FeedItem) v.getTag(); @@ -253,7 +250,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR ImageButton butSecondary; FeedItem item; WeakReference<MainActivity> mainActivityRef; - int position; public Holder(View itemView) { super(itemView); @@ -266,18 +262,18 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR MainActivity mainActivity = mainActivityRef.get(); if (mainActivity != null) { long[] ids = itemAccess.getItemsIds().toArray(); - mainActivity.loadChildFragment(ItemFragment.newInstance(ids, position)); + mainActivity.loadChildFragment(ItemFragment.newInstance(ids, getAdapterPosition())); } } @Override public void onItemSelected() { - ViewHelper.setAlpha(itemView, 0.5f); + itemView.setAlpha(0.5f); } @Override public void onItemClear() { - ViewHelper.setAlpha(itemView, 1.0f); + itemView.setAlpha(1.0f); } public FeedItem getFeedItem() { return item; } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java index e271b5eed..7c0be47b6 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java @@ -29,11 +29,11 @@ import de.danoeh.antennapod.core.storage.DownloadRequestException; /** Displays a list of DownloadStatus entries. */ public class DownloadLogAdapter extends BaseAdapter { - private final String TAG = "DownloadLogAdapter"; + private static final String TAG = "DownloadLogAdapter"; - private Context context; + private final Context context; - private ItemAccess itemAccess; + private final ItemAccess itemAccess; public DownloadLogAdapter(Context context, ItemAccess itemAccess) { super(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java index 6907e467b..c62c30c90 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java @@ -12,7 +12,6 @@ import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; -import com.nineoldandroids.view.ViewHelper; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.FeedItem; @@ -87,9 +86,9 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter { .into(holder.imageView); if(item.isPlayed()) { - ViewHelper.setAlpha(convertView, 0.5f); + convertView.setAlpha(0.5f); } else { - ViewHelper.setAlpha(convertView, 1.0f); + convertView.setAlpha(1.0f); } holder.title.setText(item.getTitle()); @@ -111,7 +110,7 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter { return convertView; } - private View.OnClickListener secondaryActionListener = new View.OnClickListener() { + private final View.OnClickListener secondaryActionListener = new View.OnClickListener() { @Override public void onClick(View v) { FeedItem item = (FeedItem) v.getTag(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadlistAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadlistAdapter.java index e1efdaa7b..5bc67a95a 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadlistAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadlistAdapter.java @@ -19,11 +19,11 @@ import de.danoeh.antennapod.core.util.ThemeUtils; public class DownloadlistAdapter extends BaseAdapter { - public static final int SELECTION_NONE = -1; + private static final int SELECTION_NONE = -1; private int selectedItemIndex; - private ItemAccess itemAccess; - private Context context; + private final ItemAccess itemAccess; + private final Context context; public DownloadlistAdapter(Context context, ItemAccess itemAccess) { @@ -105,7 +105,7 @@ public class DownloadlistAdapter extends BaseAdapter { return convertView; } - private View.OnClickListener butSecondaryListener = new View.OnClickListener() { + private final View.OnClickListener butSecondaryListener = new View.OnClickListener() { @Override public void onClick(View v) { Downloader downloader = (Downloader) v.getTag(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java index f843ddb94..e29781be1 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java @@ -17,8 +17,6 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; -import com.nineoldandroids.view.ViewHelper; - import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; @@ -34,16 +32,16 @@ import de.danoeh.antennapod.core.util.ThemeUtils; */ public class FeedItemlistAdapter extends BaseAdapter { - private ActionButtonCallback callback; + private final ActionButtonCallback callback; private final ItemAccess itemAccess; private final Context context; - private boolean showFeedtitle; - private int selectedItemIndex; + private final boolean showFeedtitle; + private final int selectedItemIndex; /** true if played items should be made partially transparent */ - private boolean makePlayedItemsTransparent; + private final boolean makePlayedItemsTransparent; private final ActionButtonUtils actionButtonUtils; - public static final int SELECTION_NONE = -1; + private static final int SELECTION_NONE = -1; private final int playingBackGroundColor; private final int normalBackGroundColor; @@ -145,9 +143,9 @@ public class FeedItemlistAdapter extends BaseAdapter { holder.statusUnread.setVisibility(View.INVISIBLE); } if(item.isPlayed() && makePlayedItemsTransparent) { - ViewHelper.setAlpha(convertView, 0.5f); + convertView.setAlpha(0.5f); } else { - ViewHelper.setAlpha(convertView, 1.0f); + convertView.setAlpha(1.0f); } String pubDateStr = DateUtils.formatAbbrev(context, item.getPubDate()); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java index 465497b55..2daa5e70f 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -48,10 +48,10 @@ import de.danoeh.antennapod.fragment.SubscriptionFragment; public class NavListAdapter extends BaseAdapter implements SharedPreferences.OnSharedPreferenceChangeListener { - public static final int VIEW_TYPE_COUNT = 3; + private static final int VIEW_TYPE_COUNT = 3; public static final int VIEW_TYPE_NAV = 0; public static final int VIEW_TYPE_SECTION_DIVIDER = 1; - public static final int VIEW_TYPE_SUBSCRIPTION = 2; + private static final int VIEW_TYPE_SUBSCRIPTION = 2; /** * a tag used as a placeholder to indicate if the subscription list should be displayed or not @@ -62,8 +62,8 @@ public class NavListAdapter extends BaseAdapter private static List<String> tags; private static String[] titles; - private ItemAccess itemAccess; - private WeakReference<Activity> activity; + private final ItemAccess itemAccess; + private final WeakReference<Activity> activity; private boolean showSubscriptionList = true; public NavListAdapter(ItemAccess itemAccess, Activity context) { @@ -86,9 +86,7 @@ public class NavListAdapter extends BaseAdapter private void loadItems() { List<String> newTags = new ArrayList<>(Arrays.asList(MainActivity.NAV_DRAWER_TAGS)); List<String> hiddenFragments = UserPreferences.getHiddenDrawerItems(); - for(String hidden : hiddenFragments) { - newTags.remove(hidden); - } + newTags.removeAll(hiddenFragments); if (newTags.contains(SUBSCRIPTION_LIST_TAG)) { // we never want SUBSCRIPTION_LIST_TAG to be in 'tags' diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java index 2684dcccd..01dd4c2de 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java @@ -24,7 +24,6 @@ import android.widget.TextView; import com.bumptech.glide.Glide; import com.joanzapata.iconify.Iconify; -import com.nineoldandroids.view.ViewHelper; import org.apache.commons.lang3.ArrayUtils; @@ -51,7 +50,7 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap private static final String TAG = QueueRecyclerAdapter.class.getSimpleName(); - private WeakReference<MainActivity> mainActivity; + private final WeakReference<MainActivity> mainActivity; private final ItemAccess itemAccess; private final ActionButtonCallback actionButtonCallback; private final ActionButtonUtils actionButtonUtils; @@ -198,12 +197,12 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap @Override public void onItemSelected() { - ViewHelper.setAlpha(itemView, 0.5f); + itemView.setAlpha(0.5f); } @Override public void onItemClear() { - ViewHelper.setAlpha(itemView, 1.0f); + itemView.setAlpha(1.0f); } public void bind(FeedItem item) { @@ -305,7 +304,7 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap } - private View.OnClickListener secondaryActionListener = new View.OnClickListener() { + private final View.OnClickListener secondaryActionListener = new View.OnClickListener() { @Override public void onClick(View v) { FeedItem item = (FeedItem) v.getTag(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java index 8e1aa24e0..beb62b3bb 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java @@ -11,7 +11,6 @@ import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; -import com.nineoldandroids.view.ViewHelper; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.Feed; @@ -97,7 +96,7 @@ public class SearchlistAdapter extends BaseAdapter { holder.subtitle.setText(result.getSubtitle()); } - ViewHelper.setAlpha(convertView, item.isPlayed() ? 0.5f : 1.0f); + convertView.setAlpha(item.isPlayed() ? 0.5f : 1.0f); Glide.with(context) .load(item.getFeed().getImageLocation()) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java index c060083a6..50255c11f 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java @@ -23,8 +23,8 @@ import de.danoeh.antennapod.core.util.Converter; * Adapter for the statistics list */ public class StatisticsListAdapter extends BaseAdapter { - private Context context; - List<DBReader.StatisticsItem> feedTime = new ArrayList<>(); + private final Context context; + private List<DBReader.StatisticsItem> feedTime = new ArrayList<>(); private boolean countAll = true; public StatisticsListAdapter(Context context) { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java index 6d19bfa6c..bb76ab501 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java @@ -50,7 +50,6 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI } private int getAdjustedPosition(int origPosition) { - assert(origPosition != getAddTilePosition()); return origPosition < getAddTilePosition() ? origPosition : origPosition - 1; } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java index f1f8be559..e493a2ecc 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java @@ -124,7 +124,7 @@ public class ItunesAdapter extends ArrayAdapter<ItunesAdapter.Podcast> { * @param json object holding the podcast information * @throws JSONException */ - public static Podcast fromSearch(JSONObject json) throws JSONException { + public static Podcast fromSearch(JSONObject json) { String title = json.optString("collectionName", ""); String imageUrl = json.optString("artworkUrl100", null); String feedUrl = json.optString("feedUrl", null); @@ -162,7 +162,7 @@ public class ItunesAdapter extends ArrayAdapter<ItunesAdapter.Podcast> { /** * View holder object for the GridView */ - class PodcastViewHolder { + static class PodcastViewHolder { /** * ImageView holding the Podcast image diff --git a/app/src/main/java/de/danoeh/antennapod/asynctask/ExportWorker.java b/app/src/main/java/de/danoeh/antennapod/asynctask/ExportWorker.java index 192df8ca5..b6cf5cb84 100644 --- a/app/src/main/java/de/danoeh/antennapod/asynctask/ExportWorker.java +++ b/app/src/main/java/de/danoeh/antennapod/asynctask/ExportWorker.java @@ -23,15 +23,15 @@ public class ExportWorker { private static final String TAG = "ExportWorker"; private static final String DEFAULT_OUTPUT_NAME = "antennapod-feeds"; - private ExportWriter exportWriter; - private File output; + private final ExportWriter exportWriter; + private final File output; public ExportWorker(ExportWriter exportWriter) { this(exportWriter, new File(UserPreferences.getDataFolder(EXPORT_DIR), DEFAULT_OUTPUT_NAME + "." + exportWriter.fileExtension())); } - public ExportWorker(ExportWriter exportWriter, @NonNull File output) { + private ExportWorker(ExportWriter exportWriter, @NonNull File output) { this.exportWriter = exportWriter; this.output = output; } diff --git a/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java b/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java index 4449d82c2..ea5128102 100644 --- a/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java +++ b/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java @@ -1,6 +1,5 @@ package de.danoeh.antennapod.asynctask; -import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.Context; import android.os.AsyncTask; @@ -16,9 +15,9 @@ import de.danoeh.antennapod.core.storage.DownloadRequester; /** Queues items for download in the background. */ public class OpmlFeedQueuer extends AsyncTask<Void, Void, Void> { - private Context context; + private final Context context; private ProgressDialog progDialog; - private int[] selection; + private final int[] selection; public OpmlFeedQueuer(Context context, int[] selection) { super(); @@ -56,13 +55,8 @@ public class OpmlFeedQueuer extends AsyncTask<Void, Void, Void> { return null; } - @SuppressLint("NewApi") public void executeAsync() { - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - executeOnExecutor(THREAD_POOL_EXECUTOR); - } else { - execute(); - } + executeOnExecutor(THREAD_POOL_EXECUTOR); } } diff --git a/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlImportWorker.java b/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlImportWorker.java index 62ea85811..13b95907f 100644 --- a/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlImportWorker.java +++ b/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlImportWorker.java @@ -1,6 +1,5 @@ package de.danoeh.antennapod.asynctask; -import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.Context; import android.os.AsyncTask; @@ -21,12 +20,12 @@ public class OpmlImportWorker extends AsyncTask<Void, Void, ArrayList<OpmlElement>> { private static final String TAG = "OpmlImportWorker"; - private Context context; + private final Context context; private Exception exception; private ProgressDialog progDialog; - private Reader mReader; + private final Reader mReader; public OpmlImportWorker(Context context, Reader reader) { super(); @@ -93,13 +92,8 @@ public class OpmlImportWorker extends return exception != null; } - @SuppressLint("NewApi") public void executeAsync() { - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - executeOnExecutor(THREAD_POOL_EXECUTOR); - } else { - execute(); - } + executeOnExecutor(THREAD_POOL_EXECUTOR); } } diff --git a/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java b/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java index f26f2ea76..d2498955c 100644 --- a/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java +++ b/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java @@ -6,7 +6,7 @@ import de.danoeh.antennapod.core.ClientConfig; /** * Configures the ClientConfig class of the core package. */ -public class ClientConfigurator { +class ClientConfigurator { static { ClientConfig.USER_AGENT = "AntennaPod/" + BuildConfig.VERSION_NAME; diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java b/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java index ac073141d..10ce12771 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java @@ -32,14 +32,14 @@ import de.danoeh.antennapod.core.util.LongList; public class EpisodesApplyActionFragment extends Fragment { - public String TAG = "EpisodeActionFragment"; + public static final String TAG = "EpisodeActionFragment"; - public static final int ACTION_QUEUE = 1; - public static final int ACTION_MARK_PLAYED = 2; - public static final int ACTION_MARK_UNPLAYED = 4; - public static final int ACTION_DOWNLOAD = 8; + private static final int ACTION_QUEUE = 1; + private static final int ACTION_MARK_PLAYED = 2; + private static final int ACTION_MARK_UNPLAYED = 4; + private static final int ACTION_DOWNLOAD = 8; public static final int ACTION_REMOVE = 16; - public static final int ACTION_ALL = ACTION_QUEUE | ACTION_MARK_PLAYED | ACTION_MARK_UNPLAYED + private static final int ACTION_ALL = ACTION_QUEUE | ACTION_MARK_PLAYED | ACTION_MARK_UNPLAYED | ACTION_DOWNLOAD | ACTION_REMOVE; private ListView mListView; diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java index 0bd75b5b0..b9276982a 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java @@ -43,7 +43,7 @@ public class ProxyDialog { private static final String TAG = "ProxyDialog"; - private Context context; + private final Context context; private MaterialDialog dialog; @@ -243,47 +243,44 @@ public class ProxyDialog { txtvMessage.setTextColor(textColorPrimary); txtvMessage.setText("{fa-circle-o-notch spin} " + checking); txtvMessage.setVisibility(View.VISIBLE); - subscription = Observable.create(new Observable.OnSubscribe<Response>() { - @Override - public void call(Subscriber<? super Response> subscriber) { - String type = (String) spType.getSelectedItem(); - String host = etHost.getText().toString(); - String port = etPort.getText().toString(); - String username = etUsername.getText().toString(); - String password = etPassword.getText().toString(); - int portValue = 8080; - if(!TextUtils.isEmpty(port)) { - portValue = Integer.valueOf(port); - } - SocketAddress address = InetSocketAddress.createUnresolved(host, portValue); - Proxy.Type proxyType = Proxy.Type.valueOf(type.toUpperCase()); - Proxy proxy = new Proxy(proxyType, address); - OkHttpClient.Builder builder = AntennapodHttpClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .proxy(proxy); - builder.interceptors().clear(); - OkHttpClient client = builder.build(); - if(!TextUtils.isEmpty(username)) { - String credentials = Credentials.basic(username, password); - client.interceptors().add(chain -> { - Request request = chain.request().newBuilder() - .header("Proxy-Authorization", credentials).build(); - return chain.proceed(request); - }); - } - Request request = new Request.Builder() - .url("http://www.google.com") - .head() - .build(); - try { - Response response = client.newCall(request).execute(); - subscriber.onNext(response); - } catch(IOException e) { - subscriber.onError(e); - } - subscriber.onCompleted(); - } - }) + subscription = Observable.create((Observable.OnSubscribe<Response>) subscriber -> { + String type = (String) spType.getSelectedItem(); + String host = etHost.getText().toString(); + String port = etPort.getText().toString(); + String username = etUsername.getText().toString(); + String password = etPassword.getText().toString(); + int portValue = 8080; + if(!TextUtils.isEmpty(port)) { + portValue = Integer.valueOf(port); + } + SocketAddress address = InetSocketAddress.createUnresolved(host, portValue); + Proxy.Type proxyType = Proxy.Type.valueOf(type.toUpperCase()); + Proxy proxy = new Proxy(proxyType, address); + OkHttpClient.Builder builder = AntennapodHttpClient.newBuilder() + .connectTimeout(10, TimeUnit.SECONDS) + .proxy(proxy); + builder.interceptors().clear(); + OkHttpClient client = builder.build(); + if(!TextUtils.isEmpty(username)) { + String credentials = Credentials.basic(username, password); + client.interceptors().add(chain -> { + Request request = chain.request().newBuilder() + .header("Proxy-Authorization", credentials).build(); + return chain.proceed(request); + }); + } + Request request = new Request.Builder() + .url("http://www.google.com") + .head() + .build(); + try { + Response response = client.newCall(request).execute(); + subscriber.onNext(response); + } catch(IOException e) { + subscriber.onError(e); + } + subscriber.onCompleted(); + }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java index 64fc1fda4..72000170e 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java @@ -54,7 +54,7 @@ public class RatingDialog { } } - public static void rateNow() { + private static void rateNow() { Context context = mContext.get(); if(context == null) { return; @@ -67,11 +67,11 @@ public class RatingDialog { saveRated(); } - public static boolean rated() { + private static boolean rated() { return mPreferences.getBoolean(KEY_RATED, false); } - public static void saveRated() { + private static void saveRated() { mPreferences .edit() .putBoolean(KEY_RATED, true) diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java index 5bb3f09c3..be7850495 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java @@ -24,7 +24,7 @@ public abstract class SleepTimerDialog { private static final String TAG = SleepTimerDialog.class.getSimpleName(); - private Context context; + private final Context context; private MaterialDialog dialog; private EditText etxtTime; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java index f14ebbdaf..c050221e1 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java @@ -25,7 +25,7 @@ public class AddFeedFragment extends Fragment { /** * Preset value for url text field. */ - public static final String ARG_FEED_URL = "feedurl"; + private static final String ARG_FEED_URL = "feedurl"; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index bbfd1688d..f3846c8a4 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -69,24 +69,24 @@ public class AllEpisodesFragment extends Fragment { private static final String PREF_SCROLL_POSITION = "scroll_position"; private static final String PREF_SCROLL_OFFSET = "scroll_offset"; - protected RecyclerView recyclerView; - protected AllEpisodesRecycleAdapter listAdapter; + RecyclerView recyclerView; + AllEpisodesRecycleAdapter listAdapter; private ProgressBar progLoading; - protected List<FeedItem> episodes; + List<FeedItem> episodes; private List<Downloader> downloaderList; private boolean itemsLoaded = false; private boolean viewsCreated = false; private boolean isUpdatingFeeds; - protected boolean isMenuInvalidationAllowed = false; + boolean isMenuInvalidationAllowed = false; - protected Subscription subscription; + Subscription subscription; private LinearLayoutManager layoutManager; - protected boolean showOnlyNewEpisodes() { return false; } - protected String getPrefName() { return DEFAULT_PREF_NAME; } + boolean showOnlyNewEpisodes() { return false; } + String getPrefName() { return DEFAULT_PREF_NAME; } @Override public void onCreate(Bundle savedInstanceState) { @@ -165,7 +165,7 @@ public class AllEpisodesFragment extends Fragment { } } - protected void resetViewState() { + void resetViewState() { viewsCreated = false; listAdapter = null; } @@ -284,13 +284,7 @@ public class AllEpisodesFragment extends Fragment { return super.onContextItemSelected(item); } - try { - return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); - } catch (DownloadRequestException e) { - e.printStackTrace(); - Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); - return true; - } + return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); } @Override @@ -299,10 +293,10 @@ public class AllEpisodesFragment extends Fragment { R.layout.all_episodes_fragment); } - protected View onCreateViewHelper(LayoutInflater inflater, - ViewGroup container, - Bundle savedInstanceState, - int fragmentResource) { + View onCreateViewHelper(LayoutInflater inflater, + ViewGroup container, + Bundle savedInstanceState, + int fragmentResource) { super.onCreateView(inflater, container, savedInstanceState); View root = inflater.inflate(fragmentResource, container, false); @@ -346,7 +340,7 @@ public class AllEpisodesFragment extends Fragment { updateShowOnlyEpisodesListViewState(); } - protected AllEpisodesRecycleAdapter.ItemAccess itemAccess = new AllEpisodesRecycleAdapter.ItemAccess() { + private final AllEpisodesRecycleAdapter.ItemAccess itemAccess = new AllEpisodesRecycleAdapter.ItemAccess() { @Override public int getCount() { @@ -444,7 +438,7 @@ public class AllEpisodesFragment extends Fragment { } } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EVENTS) != 0) { @@ -459,7 +453,7 @@ public class AllEpisodesFragment extends Fragment { private void updateShowOnlyEpisodesListViewState() { } - protected void loadItems() { + void loadItems() { if(subscription != null) { subscription.unsubscribe(); } @@ -483,7 +477,7 @@ public class AllEpisodesFragment extends Fragment { }, error -> Log.e(TAG, Log.getStackTraceString(error))); } - protected List<FeedItem> loadData() { + List<FeedItem> loadData() { return DBReader.getRecentlyPublishedEpisodes(RECENT_EPISODES_LIMIT); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java index 1ba7ed557..f37ecd5e7 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java @@ -168,7 +168,7 @@ public class CompletedDownloadsFragment extends ListFragment { } } - private DownloadedEpisodesListAdapter.ItemAccess itemAccess = new DownloadedEpisodesListAdapter.ItemAccess() { + private final DownloadedEpisodesListAdapter.ItemAccess itemAccess = new DownloadedEpisodesListAdapter.ItemAccess() { @Override public int getCount() { return (items != null) ? items.size() : 0; @@ -189,7 +189,7 @@ public class CompletedDownloadsFragment extends ListFragment { } }; - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EVENTS) != 0) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java index 0a710196a..9a4c9e030 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java @@ -82,7 +82,7 @@ public class DownloadLogFragment extends ListFragment { getActivity().supportInvalidateOptionsMenu(); } - private DownloadLogAdapter.ItemAccess itemAccess = new DownloadLogAdapter.ItemAccess() { + private final DownloadLogAdapter.ItemAccess itemAccess = new DownloadLogAdapter.ItemAccess() { @Override public int getCount() { @@ -99,7 +99,7 @@ public class DownloadLogFragment extends ListFragment { } }; - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java index 52a38ccb9..9c4d00e31 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java @@ -25,7 +25,7 @@ public class DownloadsFragment extends Fragment { public static final String ARG_SELECTED_TAB = "selected_tab"; public static final int POS_RUNNING = 0; - public static final int POS_COMPLETED = 1; + private static final int POS_COMPLETED = 1; public static final int POS_LOG = 2; private static final String PREF_LAST_TAB_POSITION = "tab_position"; @@ -78,9 +78,9 @@ public class DownloadsFragment extends Fragment { viewPager.setCurrentItem(lastPosition); } - public class DownloadsPagerAdapter extends FragmentPagerAdapter { + public static class DownloadsPagerAdapter extends FragmentPagerAdapter { - Resources resources; + final Resources resources; public DownloadsPagerAdapter(FragmentManager fm, Resources resources) { super(fm); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java index e2fbd91f3..8928d2bf3 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java @@ -21,10 +21,10 @@ public class EpisodesFragment extends Fragment { public static final String TAG = "EpisodesFragment"; private static final String PREF_LAST_TAB_POSITION = "tab_position"; - public static final int POS_NEW_EPISODES = 0; - public static final int POS_ALL_EPISODES = 1; - public static final int POS_FAV_EPISODES = 2; - public static final int TOTAL_COUNT = 3; + private static final int POS_NEW_EPISODES = 0; + private static final int POS_ALL_EPISODES = 1; + private static final int POS_FAV_EPISODES = 2; + private static final int TOTAL_COUNT = 3; private TabLayout tabLayout; @@ -79,7 +79,7 @@ public class EpisodesFragment extends Fragment { public static class EpisodesPagerAdapter extends FragmentPagerAdapter { private final Resources resources; - private AllEpisodesFragment[] fragments = { + private final AllEpisodesFragment[] fragments = { new NewEpisodesFragment(), new AllEpisodesFragment(), new FavoriteEpisodesFragment() diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java index 5bb8e0a2d..a9bf39632 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java @@ -208,7 +208,7 @@ public class ExternalPlayerFragment extends Fragment { return controller; } - public void onPositionObserverUpdate() { + private void onPositionObserverUpdate() { mProgressBar.setProgress((int) ((double) controller.getPosition() / controller.getDuration() * 100)); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java index 234c8377d..76d19d61c 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java @@ -26,7 +26,7 @@ import de.danoeh.antennapod.core.storage.DBWriter; public class FavoriteEpisodesFragment extends AllEpisodesFragment { - public static final String TAG = "FavoriteEpisodesFrag"; + private static final String TAG = "FavoriteEpisodesFrag"; private static final String PREF_NAME = "PrefFavoriteEpisodesFragment"; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FyydSearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FyydSearchFragment.java index 7c1ec5ec1..6ee9ce467 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FyydSearchFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FyydSearchFragment.java @@ -49,7 +49,7 @@ public class FyydSearchFragment extends Fragment { private Button butRetry; private TextView txtvEmpty; - private FyydClient client = new FyydClient(AntennapodHttpClient.getHttpClient()); + private final FyydClient client = new FyydClient(AntennapodHttpClient.getHttpClient()); /** * List of podcasts retreived from the search @@ -169,7 +169,7 @@ public class FyydSearchFragment extends Fragment { progressBar.setVisibility(View.VISIBLE); } - void processSearchResult(FyydResponse response) { + private void processSearchResult(FyydResponse response) { adapter.clear(); if (!response.getData().isEmpty()) { adapter.clear(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java index a0586fe16..935fd7898 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java @@ -10,7 +10,6 @@ import android.content.SharedPreferences; import android.content.res.TypedArray; import android.graphics.Color; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; @@ -112,9 +111,7 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo Bundle savedInstanceState) { Log.d(TAG, "Creating view"); webvDescription = new WebView(getActivity().getApplicationContext()); - if (Build.VERSION.SDK_INT >= 11) { - webvDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null); - } + webvDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null); TypedArray ta = getActivity().getTheme().obtainStyledAttributes(new int[] {android.R.attr.colorBackground}); int backgroundColor = ta.getColor(0, UserPreferences.getTheme() == @@ -203,7 +200,7 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo } - private View.OnLongClickListener webViewLongClickListener = new View.OnLongClickListener() { + private final View.OnLongClickListener webViewLongClickListener = new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { @@ -238,17 +235,11 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo ShareUtils.shareLink(getActivity(), selectedURL); break; case R.id.copy_url_item: - if (android.os.Build.VERSION.SDK_INT >= 11) { - ClipData clipData = ClipData.newPlainText(selectedURL, - selectedURL); - android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity() - .getSystemService(Context.CLIPBOARD_SERVICE); - cm.setPrimaryClip(clipData); - } else { - android.text.ClipboardManager cm = (android.text.ClipboardManager) getActivity() - .getSystemService(Context.CLIPBOARD_SERVICE); - cm.setText(selectedURL); - } + ClipData clipData = ClipData.newPlainText(selectedURL, + selectedURL); + android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity() + .getSystemService(Context.CLIPBOARD_SERVICE); + cm.setPrimaryClip(clipData); Toast t = Toast.makeText(getActivity(), R.string.copied_url_msg, Toast.LENGTH_SHORT); t.show(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java index 7939dcb23..4ae6b97ee 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -184,8 +184,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { } webvDescription = (WebView) layout.findViewById(R.id.webvDescription); if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) { - if (Build.VERSION.SDK_INT >= 11 - && Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { webvDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } webvDescription.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.black)); @@ -335,13 +334,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { openPodcast(); return true; default: - try { - return FeedItemMenuHandler.onMenuItemClicked(getActivity(), menuItem.getItemId(), item); - } catch (DownloadRequestException e) { - e.printStackTrace(); - Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); - return true; - } + return FeedItemMenuHandler.onMenuItemClicked(getActivity(), menuItem.getItemId(), item); } } @@ -450,7 +443,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { } } - private View.OnLongClickListener webViewLongClickListener = new View.OnLongClickListener() { + private final View.OnLongClickListener webViewLongClickListener = new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { @@ -483,17 +476,11 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { ShareUtils.shareLink(getActivity(), selectedURL); break; case R.id.copy_url_item: - if (android.os.Build.VERSION.SDK_INT >= 11) { - ClipData clipData = ClipData.newPlainText(selectedURL, - selectedURL); - android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity() - .getSystemService(Context.CLIPBOARD_SERVICE); - cm.setPrimaryClip(clipData); - } else { - android.text.ClipboardManager cm = (android.text.ClipboardManager) getActivity() - .getSystemService(Context.CLIPBOARD_SERVICE); - cm.setText(selectedURL); - } + ClipData clipData = ClipData.newPlainText(selectedURL, + selectedURL); + android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity() + .getSystemService(Context.CLIPBOARD_SERVICE); + cm.setPrimaryClip(clipData); Toast t = Toast.makeText(getActivity(), R.string.copied_url_msg, Toast.LENGTH_SHORT); t.show(); @@ -558,7 +545,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EVENTS) != 0) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java index a118673a6..890f31f57 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -7,7 +7,6 @@ import android.content.Intent; import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.LightingColorFilter; -import android.os.Build; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.view.MenuItemCompat; @@ -22,7 +21,6 @@ import android.view.View; import android.widget.AdapterView; import android.widget.ImageButton; import android.widget.ImageView; -import android.widget.ListAdapter; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView; @@ -89,9 +87,9 @@ public class ItemlistFragment extends ListFragment { | EventDistributor.PLAYER_STATUS_UPDATE; public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.danoeh.antennapod.activity.selected_feeditem"; - public static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id"; + private static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id"; - protected FeedItemlistAdapter adapter; + private FeedItemlistAdapter adapter; private ContextMenu contextMenu; private AdapterView.AdapterContextMenuInfo lastMenuInfo = null; @@ -342,22 +340,7 @@ public class ItemlistFragment extends ListFragment { return super.onContextItemSelected(item); } - try { - return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); - } catch (DownloadRequestException e) { - // context menu doesn't contain download functionality - return true; - } - } - - - @Override - public void setListAdapter(ListAdapter adapter) { - // This workaround prevents the ListFragment from setting a list adapter when its state is restored. - // This is only necessary on API 10 because addFooterView throws an internal exception in this case. - if (Build.VERSION.SDK_INT > 10 || insideOnFragmentLoaded) { - super.setListAdapter(adapter); - } + return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); } @Override @@ -417,7 +400,7 @@ public class ItemlistFragment extends ListFragment { } } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { @@ -583,7 +566,7 @@ public class ItemlistFragment extends ListFragment { } } - private FeedItemlistAdapter.ItemAccess itemAccess = new FeedItemlistAdapter.ItemAccess() { + private final FeedItemlistAdapter.ItemAccess itemAccess = new FeedItemlistAdapter.ItemAccess() { @Override public FeedItem getItem(int position) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItunesSearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItunesSearchFragment.java index 43dedad25..08610c1f3 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItunesSearchFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItunesSearchFragment.java @@ -75,7 +75,7 @@ public class ItunesSearchFragment extends Fragment { * Replace adapter data with provided search results from SearchTask. * @param result List of Podcast objects containing search results */ - void updateData(List<Podcast> result) { + private void updateData(List<Podcast> result) { this.searchResults = result; adapter.clear(); if (result != null && result.size() > 0) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java index 441f0096c..fb6280021 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -199,7 +199,7 @@ public class PlaybackHistoryFragment extends ListFragment { } } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { @@ -224,7 +224,7 @@ public class PlaybackHistoryFragment extends ListFragment { getActivity().supportInvalidateOptionsMenu(); } - private FeedItemlistAdapter.ItemAccess itemAccess = new FeedItemlistAdapter.ItemAccess() { + private final FeedItemlistAdapter.ItemAccess itemAccess = new FeedItemlistAdapter.ItemAccess() { @Override public int getItemDownloadProgressPercent(FeedItem item) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index fccb86076..bf22e71f5 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -363,13 +363,7 @@ public class QueueFragment extends Fragment { DBWriter.moveQueueItemToBottom(selectedItem.getId(), true); return true; default: - try { - return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); - } catch (DownloadRequestException e) { - e.printStackTrace(); - Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); - return true; - } + return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); } } @@ -519,7 +513,7 @@ public class QueueFragment extends Fragment { infoBar.setText(info); } - private QueueRecyclerAdapter.ItemAccess itemAccess = new QueueRecyclerAdapter.ItemAccess() { + private final QueueRecyclerAdapter.ItemAccess itemAccess = new QueueRecyclerAdapter.ItemAccess() { @Override public int getCount() { return queue != null ? queue.size() : 0; @@ -579,7 +573,7 @@ public class QueueFragment extends Fragment { } }; - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EVENTS) != 0) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java index ba526edb3..66c59b7f7 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java @@ -75,7 +75,7 @@ public class RunningDownloadsFragment extends ListFragment { } - private DownloadlistAdapter.ItemAccess itemAccess = new DownloadlistAdapter.ItemAccess() { + private final DownloadlistAdapter.ItemAccess itemAccess = new DownloadlistAdapter.ItemAccess() { @Override public int getCount() { return (downloaderList != null) ? downloaderList.size() : 0; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java index 9626e6c2e..c834b7ea7 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -210,7 +210,7 @@ public class SubscriptionFragment extends Fragment { loadSubscriptions(); } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((EVENTS & arg) != 0) { @@ -220,7 +220,7 @@ public class SubscriptionFragment extends Fragment { } }; - private SubscriptionsAdapter.ItemAccess itemAccess = new SubscriptionsAdapter.ItemAccess() { + private final SubscriptionsAdapter.ItemAccess itemAccess = new SubscriptionsAdapter.ItemAccess() { @Override public int getCount() { if (navDrawerData != null) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java index aff5069c6..b48027668 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java @@ -20,7 +20,7 @@ import de.danoeh.antennapod.R; */ public class GpodnetMainFragment extends Fragment { - public static final String TAG = "GpodnetMainFragment"; + private static final String TAG = "GpodnetMainFragment"; private static final String PREF_LAST_TAB_POSITION = "tab_position"; private TabLayout tabLayout; @@ -71,7 +71,7 @@ public class GpodnetMainFragment extends Fragment { private static final int POS_TAGS = 1; private static final int POS_SUGGESTIONS = 2; - Resources resources; + final Resources resources; public GpodnetPagerAdapter(FragmentManager fm, Resources resources) { super(fm); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java index 15e9c9943..055358c64 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java @@ -91,7 +91,7 @@ public abstract class PodcastListFragment extends Fragment { return root; } - protected void onPodcastSelected(GpodnetPodcast selection) { + private void onPodcastSelected(GpodnetPodcast selection) { Log.d(TAG, "Selected podcast: " + selection.toString()); Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, selection.getUrl()); @@ -101,7 +101,7 @@ public abstract class PodcastListFragment extends Fragment { protected abstract List<GpodnetPodcast> loadPodcastData(GpodnetService service) throws GpodnetServiceException; - protected final void loadData() { + final void loadData() { AsyncTask<Void, Void, List<GpodnetPodcast>> loaderTask = new AsyncTask<Void, Void, List<GpodnetPodcast>>() { volatile Exception exception = null; @@ -160,10 +160,6 @@ public abstract class PodcastListFragment extends Fragment { } }; - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - loaderTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - loaderTask.execute(); - } + loaderTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/SearchListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/SearchListFragment.java index 613e06805..10bd636dd 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/SearchListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/SearchListFragment.java @@ -73,7 +73,7 @@ public class SearchListFragment extends PodcastListFragment { return service.searchPodcasts(query, 0); } - public void changeQuery(String query) { + private void changeQuery(String query) { Validate.notNull(query); this.query = query; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java index d2c7f32dd..1e46b1ac5 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java @@ -135,11 +135,7 @@ public class TagListFragment extends ListFragment { } } }; - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - loadTask.execute(); - } + loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java index 57b7c359c..f6f73e017 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -17,7 +17,6 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBWriter; -import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.ShareUtils; @@ -155,7 +154,7 @@ public class FeedItemMenuHandler { } public static boolean onMenuItemClicked(Context context, int menuItemId, - FeedItem selectedItem) throws DownloadRequestException { + FeedItem selectedItem) { switch (menuItemId) { case R.id.skip_episode_item: context.sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE)); diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index 3b5a68f7f..b5e0f1e99 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -38,6 +38,7 @@ import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; +import de.danoeh.antennapod.activity.ImportExportActivity; import org.apache.commons.lang3.ArrayUtils; import java.io.File; @@ -45,7 +46,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Collections; -import java.util.Comparator; import java.util.GregorianCalendar; import java.util.List; import java.util.concurrent.TimeUnit; @@ -56,8 +56,6 @@ import de.danoeh.antennapod.activity.AboutActivity; import de.danoeh.antennapod.activity.DirectoryChooserActivity; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.MediaplayerActivity; -import de.danoeh.antennapod.activity.PreferenceActivity; -import de.danoeh.antennapod.activity.PreferenceActivityGingerbread; import de.danoeh.antennapod.activity.StatisticsActivity; import de.danoeh.antennapod.asynctask.ExportWorker; import de.danoeh.antennapod.core.export.ExportWriter; @@ -93,12 +91,13 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc private static final String PREF_OPML_EXPORT = "prefOpmlExport"; private static final String PREF_HTML_EXPORT = "prefHtmlExport"; private static final String STATISTICS = "statistics"; + private static final String IMPORT_EXPORT = "importExport"; 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_PLAYBACK_SPEED_LAUNCHER = "prefPlaybackSpeedLauncher"; - public static final String PREF_PLAYBACK_REWIND_DELTA_LAUNCHER = "prefPlaybackRewindDeltaLauncher"; - public static final String PREF_PLAYBACK_FAST_FORWARD_DELTA_LAUNCHER = "prefPlaybackFastForwardDeltaLauncher"; + private static final String PREF_PLAYBACK_REWIND_DELTA_LAUNCHER = "prefPlaybackRewindDeltaLauncher"; + private static final String PREF_PLAYBACK_FAST_FORWARD_DELTA_LAUNCHER = "prefPlaybackFastForwardDeltaLauncher"; private static final String PREF_GPODNET_LOGIN = "pref_gpodnet_authenticate"; private static final String PREF_GPODNET_SETLOGIN_INFORMATION = "pref_gpodnet_setlogin_information"; private static final String PREF_GPODNET_SYNC = "pref_gpodnet_sync"; @@ -132,19 +131,6 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc .registerOnSharedPreferenceChangeListener(this); } - /** - * Returns the preference activity that should be used on this device. - * - * @return PreferenceActivity if the API level is greater than 10, PreferenceActivityGingerbread otherwise. - */ - public static Class<? extends Activity> getPreferenceActivity() { - if (Build.VERSION.SDK_INT > 10) { - return PreferenceActivity.class; - } else { - return PreferenceActivityGingerbread.class; - } - } - @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if(key.equals(UserPreferences.PREF_SONIC)) { @@ -189,6 +175,12 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc return true; } ); + ui.findPreference(PreferenceController.IMPORT_EXPORT).setOnPreferenceClickListener( + preference -> { + activity.startActivity(new Intent(activity, ImportExportActivity.class)); + return true; + } + ); ui.findPreference(PreferenceController.PREF_OPML_EXPORT).setOnPreferenceClickListener( preference -> export(new OpmlWriter())); ui.findPreference(PreferenceController.PREF_HTML_EXPORT).setOnPreferenceClickListener( @@ -230,12 +222,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc .setOnPreferenceChangeListener( (preference, newValue) -> { Intent i = new Intent(activity, MainActivity.class); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK - | Intent.FLAG_ACTIVITY_NEW_TASK); - } else { - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - } + i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK + | Intent.FLAG_ACTIVITY_NEW_TASK); activity.finish(); activity.startActivity(i); return true; @@ -513,7 +501,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc alert.setTitle(R.string.export_error_label); alert.setMessage(error.getMessage()); alert.show(); - }, () -> progressDialog.dismiss()); + }, progressDialog::dismiss); return true; } @@ -786,61 +774,56 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc WifiManager wifiservice = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks(); - if (networks != null) { - Collections.sort(networks, new Comparator<WifiConfiguration>() { - @Override - public int compare(WifiConfiguration x, WifiConfiguration y) { - return x.SSID.compareTo(y.SSID); + if (networks == null) { + Log.e(TAG, "Couldn't get list of configure Wi-Fi networks"); + return; + } + Collections.sort(networks, (x, y) -> x.SSID.compareTo(y.SSID)); + selectedNetworks = new CheckBoxPreference[networks.size()]; + List<String> prefValues = Arrays.asList(UserPreferences + .getAutodownloadSelectedNetworks()); + PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); + Preference.OnPreferenceClickListener clickListener = preference -> { + if (preference instanceof CheckBoxPreference) { + String key = preference.getKey(); + List<String> prefValuesList = new ArrayList<>( + Arrays.asList(UserPreferences + .getAutodownloadSelectedNetworks()) + ); + boolean newValue = ((CheckBoxPreference) preference) + .isChecked(); + Log.d(TAG, "Selected network " + key + ". New state: " + newValue); + + int index = prefValuesList.indexOf(key); + if (index >= 0 && !newValue) { + // remove network + prefValuesList.remove(index); + } else if (index < 0 && newValue) { + prefValuesList.add(key); } - }); - selectedNetworks = new CheckBoxPreference[networks.size()]; - List<String> prefValues = Arrays.asList(UserPreferences - .getAutodownloadSelectedNetworks()); - PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); - Preference.OnPreferenceClickListener clickListener = preference -> { - if (preference instanceof CheckBoxPreference) { - String key = preference.getKey(); - List<String> prefValuesList = new ArrayList<>( - Arrays.asList(UserPreferences - .getAutodownloadSelectedNetworks()) - ); - boolean newValue = ((CheckBoxPreference) preference) - .isChecked(); - Log.d(TAG, "Selected network " + key + ". New state: " + newValue); - - int index = prefValuesList.indexOf(key); - if (index >= 0 && !newValue) { - // remove network - prefValuesList.remove(index); - } else if (index < 0 && newValue) { - prefValuesList.add(key); - } - UserPreferences.setAutodownloadSelectedNetworks( - 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(activity); - 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); + UserPreferences.setAutodownloadSelectedNetworks( + prefValuesList.toArray(new String[prefValuesList.size()]) + ); + return true; + } else { + return false; } - } else { - Log.e(TAG, "Couldn't get list of configure Wi-Fi networks"); + }; + // 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(activity); + 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); } } diff --git a/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java b/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java index a373c5353..c9bd973cb 100644 --- a/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java +++ b/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java @@ -22,8 +22,8 @@ public class SPAReceiver extends BroadcastReceiver{ private static final String TAG = "SPAReceiver"; public static final String ACTION_SP_APPS_QUERY_FEEDS = "de.danoeh.antennapdsp.intent.SP_APPS_QUERY_FEEDS"; - public static final String ACTION_SP_APPS_QUERY_FEEDS_REPSONSE = "de.danoeh.antennapdsp.intent.SP_APPS_QUERY_FEEDS_RESPONSE"; - public static final String ACTION_SP_APPS_QUERY_FEEDS_REPSONSE_FEEDS_EXTRA = "feeds"; + private static final String ACTION_SP_APPS_QUERY_FEEDS_REPSONSE = "de.danoeh.antennapdsp.intent.SP_APPS_QUERY_FEEDS_RESPONSE"; + private static final String ACTION_SP_APPS_QUERY_FEEDS_REPSONSE_FEEDS_EXTRA = "feeds"; @Override public void onReceive(Context context, Intent intent) { diff --git a/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java b/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java index b5bfb1ae4..d5141bd37 100644 --- a/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java +++ b/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java @@ -38,7 +38,7 @@ public class PlayerWidgetService extends Service { /** * Controls write access to playbackservice reference */ - private Object psLock; + private final Object psLock = new Object(); /** * True while service is updating the widget @@ -53,7 +53,6 @@ public class PlayerWidgetService extends Service { super.onCreate(); Log.d(TAG, "Service created"); isUpdating = false; - psLock = new Object(); } @Override @@ -194,7 +193,7 @@ public class PlayerWidgetService extends Service { } } - private ServiceConnection mConnection = new ServiceConnection() { + private final ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { Log.d(TAG, "Connection to service established"); synchronized (psLock) { @@ -224,7 +223,7 @@ public class PlayerWidgetService extends Service { class ViewUpdater extends Thread { private static final String THREAD_NAME = "ViewUpdater"; - private PlayerWidgetService service; + private final PlayerWidgetService service; public ViewUpdater(PlayerWidgetService service) { super(); diff --git a/app/src/main/java/de/danoeh/antennapod/view/SquareImageView.java b/app/src/main/java/de/danoeh/antennapod/view/SquareImageView.java index 27b6ee2bc..7ce33e11f 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/SquareImageView.java +++ b/app/src/main/java/de/danoeh/antennapod/view/SquareImageView.java @@ -1,13 +1,13 @@ package de.danoeh.antennapod.view; import android.content.Context; +import android.support.v7.widget.AppCompatImageView; import android.util.AttributeSet; -import android.widget.ImageView; /** * From http://stackoverflow.com/a/19449488/6839 */ -public class SquareImageView extends ImageView { +public class SquareImageView extends AppCompatImageView { public SquareImageView(Context context) { super(context); @@ -26,6 +26,7 @@ public class SquareImageView extends ImageView { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int width = getMeasuredWidth(); + //noinspection SuspiciousNameCombination setMeasuredDimension(width, width); } diff --git a/app/src/main/res/layout-v14/authentication_dialog.xml b/app/src/main/res/layout-v14/authentication_dialog.xml deleted file mode 100644 index 00e74c9e1..000000000 --- a/app/src/main/res/layout-v14/authentication_dialog.xml +++ /dev/null @@ -1,87 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical" > - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="vertical" > - - <EditText - android:id="@+id/etxtUsername" - android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_weight="1" - android:layout_margin="16dp" - android:hint="@string/username_label" - android:focusable="true" - android:focusableInTouchMode="true" - android:cursorVisible="true"/> - - <EditText - android:id="@+id/etxtPassword" - android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_weight="1" - android:layout_margin="16dp" - android:inputType="textPassword" - android:hint="@string/password_label" - android:focusable="true" - android:focusableInTouchMode="true" - android:cursorVisible="true"/> - - <CheckBox - android:id="@+id/chkSaveUsernamePassword" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_margin="16dp" - android:text="@string/save_username_password_label"/> - </LinearLayout> - - <RelativeLayout - android:id="@+id/footer" - android:layout_width="fill_parent" - android:layout_height="48dp" > - - <View - android:layout_width="match_parent" - android:layout_height="1dip" - android:layout_alignParentTop="true" - android:background="?android:attr/dividerVertical" /> - - <View - android:id="@+id/horizontal_divider" - android:layout_width="1dip" - android:layout_height="fill_parent" - android:layout_alignParentTop="true" - android:layout_centerHorizontal="true" - android:layout_marginBottom="4dp" - android:layout_marginTop="4dp" - android:background="?android:attr/dividerVertical" /> - - <Button - android:id="@+id/butCancel" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:layout_alignParentLeft="true" - android:layout_alignParentTop="true" - android:layout_toLeftOf="@id/horizontal_divider" - android:background="?android:attr/selectableItemBackground" - android:text="@string/cancel_label" /> - - <Button - android:id="@+id/butConfirm" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:layout_alignParentRight="true" - android:layout_alignParentTop="true" - android:layout_toRightOf="@id/horizontal_divider" - android:background="?android:attr/selectableItemBackground" - android:text="@string/confirm_label" /> - </RelativeLayout> - -</LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout-v14/directory_chooser.xml b/app/src/main/res/layout-v14/directory_chooser.xml deleted file mode 100644 index 14e2f6a38..000000000 --- a/app/src/main/res/layout-v14/directory_chooser.xml +++ /dev/null @@ -1,114 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="match_parent" - tools:background="@android:color/darker_gray"> - - <RelativeLayout - android:id="@+id/footer" - android:layout_width="fill_parent" - android:layout_height="48dp" - android:layout_alignParentBottom="true" > - - <View - android:layout_width="match_parent" - android:layout_height="1dip" - android:layout_alignParentTop="true" - android:background="?android:attr/dividerVertical" /> - - <View - android:id="@+id/horizontal_divider" - android:layout_width="1dip" - android:layout_height="fill_parent" - android:layout_alignParentTop="true" - android:layout_centerHorizontal="true" - android:layout_marginBottom="4dp" - android:layout_marginTop="4dp" - android:background="?android:attr/dividerVertical" /> - - <Button - android:id="@+id/butCancel" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:layout_alignParentLeft="true" - android:layout_alignParentTop="true" - android:layout_toLeftOf="@id/horizontal_divider" - android:background="?android:attr/selectableItemBackground" - android:text="@string/cancel_label" /> - - <Button - android:id="@+id/butConfirm" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:layout_alignParentRight="true" - android:layout_alignParentTop="true" - android:layout_toRightOf="@id/horizontal_divider" - android:background="?android:attr/selectableItemBackground" - android:text="@string/confirm_label" /> - </RelativeLayout> - - <RelativeLayout - android:id="@+id/directory_info" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_alignParentTop="true" > - - <ImageButton - android:id="@+id/butNavUp" - android:contentDescription="@string/navigate_upwards_label" - android:layout_width="60dp" - android:layout_height="60dp" - android:layout_alignParentLeft="true" - android:layout_alignParentTop="true" - android:background="?attr/selectableItemBackground" - android:src="?attr/navigation_up" - tools:src="@drawable/navigation_up" - tools:background="@android:color/holo_green_dark" /> - - <TextView - android:id="@+id/txtvSelectedFolderLabel" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentTop="true" - android:layout_marginLeft="8dp" - android:layout_marginRight="8dp" - android:layout_marginTop="8dp" - android:layout_toRightOf="@id/butNavUp" - android:text="@string/selected_folder_label" - android:textStyle="bold" - tools:background="@android:color/holo_green_dark"> - </TextView> - - <TextView - android:id="@+id/txtvSelectedFolder" - android:layout_width="0dp" - android:layout_height="wrap_content" - android:layout_alignParentRight="true" - android:layout_below="@id/txtvSelectedFolderLabel" - android:layout_margin="8dp" - android:layout_toRightOf="@id/butNavUp" - android:ellipsize="start" - android:scrollHorizontally="true" - android:singleLine="true" - tools:text="/path/to/selected/folder" - tools:background="@android:color/holo_green_dark"/> - - <View - android:id="@+id/divider" - android:layout_width="match_parent" - android:layout_height="1dp" - android:layout_below="@id/butNavUp" - android:background="@color/holo_blue_light" /> - </RelativeLayout> - - <ListView - android:id="@+id/directory_list" - android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_above="@id/footer" - android:layout_below="@id/directory_info" /> - -</RelativeLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout-v14/download_authentication_activity.xml b/app/src/main/res/layout-v14/download_authentication_activity.xml deleted file mode 100644 index f6925dc3a..000000000 --- a/app/src/main/res/layout-v14/download_authentication_activity.xml +++ /dev/null @@ -1,98 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> - -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent"> - - <TextView - android:id="@+id/txtvTitle" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:text="@string/authentication_notification_title" - android:layout_alignParentTop="true" - android:textSize="@dimen/text_size_large" - android:layout_margin="16dp" - android:textColor="@color/holo_blue_light" - android:textStyle="italic"/> - - <TextView - android:id="@+id/txtvDescription" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:text="@string/authentication_notification_msg" - android:layout_below="@id/txtvTitle" - android:textSize="@dimen/text_size_medium" - android:textColor="?android:attr/textColorSecondary" - android:layout_margin="16dp"/> - - <EditText - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_margin="16dp" - android:id="@+id/etxtUsername" - android:hint="@string/username_label" - android:layout_below="@id/txtvDescription" - android:focusable="true" - android:focusableInTouchMode="true" - android:cursorVisible="true"/> - - <EditText - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_margin="16dp" - android:id="@+id/etxtPassword" - android:hint="@string/password_label" - android:inputType="textPassword" - android:layout_below="@id/etxtUsername" - android:focusable="true" - android:focusableInTouchMode="true" - android:cursorVisible="true"/> - - <RelativeLayout - android:id="@+id/footer" - android:layout_width="fill_parent" - android:layout_height="48dp" - android:focusableInTouchMode="true" - android:layout_alignParentBottom="true"> - - <View - android:layout_width="match_parent" - android:layout_height="1dip" - android:layout_alignParentTop="true" - android:background="?android:attr/dividerVertical"/> - - <View - android:id="@+id/horizontal_divider" - android:layout_width="1dip" - android:layout_height="fill_parent" - android:layout_alignParentTop="true" - android:layout_centerHorizontal="true" - android:layout_marginBottom="4dp" - android:layout_marginTop="4dp" - android:background="?android:attr/dividerVertical"/> - - <Button - android:id="@+id/butCancel" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:layout_alignParentLeft="true" - android:layout_alignParentTop="true" - android:layout_toLeftOf="@id/horizontal_divider" - android:background="?android:attr/selectableItemBackground" - android:text="@string/cancel_label"/> - - <Button - android:id="@+id/butConfirm" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:layout_alignParentRight="true" - android:layout_alignParentTop="true" - android:layout_toRightOf="@id/horizontal_divider" - android:background="?android:attr/selectableItemBackground" - android:text="@string/confirm_label"/> - </RelativeLayout> - - -</RelativeLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout-v14/opml_selection.xml b/app/src/main/res/layout-v14/opml_selection.xml deleted file mode 100644 index 3133debd1..000000000 --- a/app/src/main/res/layout-v14/opml_selection.xml +++ /dev/null @@ -1,61 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="match_parent" > - - <RelativeLayout - android:id="@+id/footer" - android:layout_width="fill_parent" - android:layout_height="48dp" - android:layout_alignParentBottom="true" > - - <View - android:layout_width="match_parent" - android:layout_height="1dip" - android:layout_alignParentTop="true" - android:background="?android:attr/dividerVertical" /> - - <View - android:id="@+id/horizontal_divider" - android:layout_width="1dip" - android:layout_height="fill_parent" - android:layout_alignParentTop="true" - android:layout_centerHorizontal="true" - android:layout_marginBottom="4dp" - android:layout_marginTop="4dp" - android:background="?android:attr/dividerVertical" /> - - <Button - android:id="@+id/butCancel" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:layout_alignParentLeft="true" - android:layout_alignParentTop="true" - android:layout_toLeftOf="@id/horizontal_divider" - android:background="?android:attr/selectableItemBackground" - android:text="@string/cancel_label" /> - - <Button - android:id="@+id/butConfirm" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:layout_alignParentRight="true" - android:layout_alignParentTop="true" - android:layout_toRightOf="@id/horizontal_divider" - android:background="?android:attr/selectableItemBackground" - android:text="@string/confirm_label" /> - </RelativeLayout> - - <ListView - android:id="@+id/feedlist" - android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_above="@id/footer" - android:layout_alignParentTop="true" - tools:listitem="@android:layout/simple_list_item_multiple_choice" > - </ListView> - -</RelativeLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout-v14/time_dialog.xml b/app/src/main/res/layout-v14/time_dialog.xml deleted file mode 100644 index ba4249268..000000000 --- a/app/src/main/res/layout-v14/time_dialog.xml +++ /dev/null @@ -1,67 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="vertical" - android:gravity="center"> - - <LinearLayout - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="horizontal" > - - <EditText - android:id="@+id/etxtTime" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="1" - android:layout_margin="8dp" - android:ems="2" - android:hint="@string/enter_time_here_label" - android:inputType="number" - android:maxLength="2" > - - <requestFocus /> - </EditText> - - <Spinner - android:id="@+id/spTimeUnit" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginBottom="8dp" - android:layout_marginTop="8dp" /> - </LinearLayout> - - <LinearLayout - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="vertical"> - - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginTop="8dp" - android:text="@string/timer_about_to_expire_label" - android:textSize="16sp" /> - - <CheckBox - android:id="@+id/cbShakeToReset" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/shake_to_reset_label" /> - - <CheckBox - android:id="@+id/cbVibrate" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/timer_vibration_label" /> - - <CheckBox - android:id="@+id/chAutoEnable" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/auto_enable_label" /> - - </LinearLayout> - -</LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/authentication_dialog.xml b/app/src/main/res/layout/authentication_dialog.xml index e18ab42eb..00e74c9e1 100644 --- a/app/src/main/res/layout/authentication_dialog.xml +++ b/app/src/main/res/layout/authentication_dialog.xml @@ -1,14 +1,13 @@ <?xml version="1.0" encoding="utf-8"?> - <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="vertical"> + android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical"> + android:orientation="vertical" > <EditText android:id="@+id/etxtUsername" @@ -39,30 +38,50 @@ android:layout_height="wrap_content" android:layout_margin="16dp" android:text="@string/save_username_password_label"/> + </LinearLayout> + <RelativeLayout + android:id="@+id/footer" + android:layout_width="fill_parent" + android:layout_height="48dp" > - </LinearLayout> + <View + android:layout_width="match_parent" + android:layout_height="1dip" + android:layout_alignParentTop="true" + android:background="?android:attr/dividerVertical" /> - <LinearLayout - style="@android:style/ButtonBar" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal"> + <View + android:id="@+id/horizontal_divider" + android:layout_width="1dip" + android:layout_height="fill_parent" + android:layout_alignParentTop="true" + android:layout_centerHorizontal="true" + android:layout_marginBottom="4dp" + android:layout_marginTop="4dp" + android:background="?android:attr/dividerVertical" /> <Button - android:id="@+id/butConfirm" - android:layout_width="0dp" + android:id="@+id/butCancel" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginRight="8dp" - android:text="@string/confirm_label" - android:layout_weight="1"/> + android:layout_alignParentBottom="true" + android:layout_alignParentLeft="true" + android:layout_alignParentTop="true" + android:layout_toLeftOf="@id/horizontal_divider" + android:background="?android:attr/selectableItemBackground" + android:text="@string/cancel_label" /> <Button - android:id="@+id/butCancel" - android:text="@string/cancel_label" - android:layout_width="0dp" + android:id="@+id/butConfirm" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="1"/> - </LinearLayout> + android:layout_alignParentBottom="true" + android:layout_alignParentRight="true" + android:layout_alignParentTop="true" + android:layout_toRightOf="@id/horizontal_divider" + android:background="?android:attr/selectableItemBackground" + android:text="@string/confirm_label" /> + </RelativeLayout> </LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/directory_chooser.xml b/app/src/main/res/layout/directory_chooser.xml index 635a73cf4..14e2f6a38 100644 --- a/app/src/main/res/layout/directory_chooser.xml +++ b/app/src/main/res/layout/directory_chooser.xml @@ -2,30 +2,53 @@ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" > + android:layout_height="match_parent" + tools:background="@android:color/darker_gray"> - <LinearLayout + <RelativeLayout android:id="@+id/footer" - style="@android:style/ButtonBar" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:orientation="horizontal" > + android:layout_width="fill_parent" + android:layout_height="48dp" + android:layout_alignParentBottom="true" > - <Button - android:id="@+id/butConfirm" - android:layout_width="0px" - android:layout_height="wrap_content" - android:layout_weight="1" - android:text="@string/confirm_label" /> + <View + android:layout_width="match_parent" + android:layout_height="1dip" + android:layout_alignParentTop="true" + android:background="?android:attr/dividerVertical" /> + + <View + android:id="@+id/horizontal_divider" + android:layout_width="1dip" + android:layout_height="fill_parent" + android:layout_alignParentTop="true" + android:layout_centerHorizontal="true" + android:layout_marginBottom="4dp" + android:layout_marginTop="4dp" + android:background="?android:attr/dividerVertical" /> <Button android:id="@+id/butCancel" - android:layout_width="0px" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="1" + android:layout_alignParentBottom="true" + android:layout_alignParentLeft="true" + android:layout_alignParentTop="true" + android:layout_toLeftOf="@id/horizontal_divider" + android:background="?android:attr/selectableItemBackground" android:text="@string/cancel_label" /> - </LinearLayout> + + <Button + android:id="@+id/butConfirm" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentBottom="true" + android:layout_alignParentRight="true" + android:layout_alignParentTop="true" + android:layout_toRightOf="@id/horizontal_divider" + android:background="?android:attr/selectableItemBackground" + android:text="@string/confirm_label" /> + </RelativeLayout> <RelativeLayout android:id="@+id/directory_info" @@ -56,7 +79,7 @@ android:layout_toRightOf="@id/butNavUp" android:text="@string/selected_folder_label" android:textStyle="bold" - tools:background="@android:color/holo_blue_bright"> + tools:background="@android:color/holo_green_dark"> </TextView> <TextView @@ -71,7 +94,7 @@ android:scrollHorizontally="true" android:singleLine="true" tools:text="/path/to/selected/folder" - tools:background="@android:color/holo_blue_bright"/> + tools:background="@android:color/holo_green_dark"/> <View android:id="@+id/divider" diff --git a/app/src/main/res/layout/download_authentication_activity.xml b/app/src/main/res/layout/download_authentication_activity.xml index 27604973a..f6925dc3a 100644 --- a/app/src/main/res/layout/download_authentication_activity.xml +++ b/app/src/main/res/layout/download_authentication_activity.xml @@ -48,28 +48,51 @@ android:focusableInTouchMode="true" android:cursorVisible="true"/> - <LinearLayout + <RelativeLayout android:id="@+id/footer" - style="@android:style/ButtonBar" android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:orientation="horizontal"> + android:layout_height="48dp" + android:focusableInTouchMode="true" + android:layout_alignParentBottom="true"> - <Button - android:id="@+id/butConfirm" - android:layout_width="0px" - android:layout_height="wrap_content" - android:layout_weight="1" - android:text="@string/confirm_label"/> + <View + android:layout_width="match_parent" + android:layout_height="1dip" + android:layout_alignParentTop="true" + android:background="?android:attr/dividerVertical"/> + + <View + android:id="@+id/horizontal_divider" + android:layout_width="1dip" + android:layout_height="fill_parent" + android:layout_alignParentTop="true" + android:layout_centerHorizontal="true" + android:layout_marginBottom="4dp" + android:layout_marginTop="4dp" + android:background="?android:attr/dividerVertical"/> <Button android:id="@+id/butCancel" - android:layout_width="0px" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="1" + android:layout_alignParentBottom="true" + android:layout_alignParentLeft="true" + android:layout_alignParentTop="true" + android:layout_toLeftOf="@id/horizontal_divider" + android:background="?android:attr/selectableItemBackground" android:text="@string/cancel_label"/> - </LinearLayout> + + <Button + android:id="@+id/butConfirm" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentBottom="true" + android:layout_alignParentRight="true" + android:layout_alignParentTop="true" + android:layout_toRightOf="@id/horizontal_divider" + android:background="?android:attr/selectableItemBackground" + android:text="@string/confirm_label"/> + </RelativeLayout> </RelativeLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/ellipsize_start_listitem.xml b/app/src/main/res/layout/ellipsize_start_listitem.xml index f737b60d3..4a70ff982 100644 --- a/app/src/main/res/layout/ellipsize_start_listitem.xml +++ b/app/src/main/res/layout/ellipsize_start_listitem.xml @@ -13,7 +13,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="@dimen/text_size_small" - android:lines="1" android:singleLine="true" android:layout_margin="16dp" android:ellipsize="start" diff --git a/app/src/main/res/layout/feedinfo.xml b/app/src/main/res/layout/feedinfo.xml index 69b835ee1..549c8ce22 100644 --- a/app/src/main/res/layout/feedinfo.xml +++ b/app/src/main/res/layout/feedinfo.xml @@ -249,10 +249,7 @@ app:layout_row="1" app:layout_column="0" android:text="@string/password_label" - android:textColor="?android:attr/textColorPrimary" - android:focusable="true" - android:focusableInTouchMode="true" - android:cursorVisible="true"/> + android:textColor="?android:attr/textColorPrimary" /> <EditText android:id="@+id/etxtPassword" @@ -261,7 +258,10 @@ app:layout_row="1" app:layout_column="1" android:hint="@string/password_label" - android:inputType="textPassword"/> + android:inputType="textPassword" + android:focusable="true" + android:focusableInTouchMode="true" + android:cursorVisible="true"/> </android.support.v7.widget.GridLayout> diff --git a/app/src/main/res/layout/import_export_activity.xml b/app/src/main/res/layout/import_export_activity.xml new file mode 100644 index 000000000..6614a8710 --- /dev/null +++ b/app/src/main/res/layout/import_export_activity.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:id="@+id/import_export_layout" + android:padding="8dp"> + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/import_export_warning" + android:gravity="center_horizontal"/> + + <Button + android:text="@string/label_export" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:id="@+id/button_export" + android:layout_marginTop="24dp"/> + + <Button + android:text="@string/label_import" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:id="@+id/button_import"/> + +</LinearLayout> diff --git a/app/src/main/res/layout/nav_list.xml b/app/src/main/res/layout/nav_list.xml index 7e72bb39b..db4d44675 100644 --- a/app/src/main/res/layout/nav_list.xml +++ b/app/src/main/res/layout/nav_list.xml @@ -31,7 +31,7 @@ android:scaleType="centerCrop" android:src="?attr/ic_settings" tools:background="@android:color/holo_orange_dark" - tools:src="@android:drawable/sym_def_app_icon"></ImageView> + tools:src="@android:drawable/sym_def_app_icon" /> <TextView android:layout_width="wrap_content" @@ -69,5 +69,5 @@ android:paddingTop="@dimen/list_vertical_padding" android:scrollbarStyle="outsideOverlay" tools:background="@android:color/holo_purple" - tools:listitem="@layout/nav_listitem"></ListView> + tools:listitem="@layout/nav_listitem" /> </RelativeLayout> diff --git a/app/src/main/res/layout/opml_import.xml b/app/src/main/res/layout/opml_import.xml index 2a67e7ee1..ac75cb8b3 100644 --- a/app/src/main/res/layout/opml_import.xml +++ b/app/src/main/res/layout/opml_import.xml @@ -6,7 +6,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" + android:layout_height="wrap_content" android:orientation="vertical" android:paddingTop="8dp" android:paddingLeft="16dp" diff --git a/app/src/main/res/layout/opml_selection.xml b/app/src/main/res/layout/opml_selection.xml index d08ebd0bd..3133debd1 100644 --- a/app/src/main/res/layout/opml_selection.xml +++ b/app/src/main/res/layout/opml_selection.xml @@ -4,28 +4,50 @@ android:layout_width="match_parent" android:layout_height="match_parent" > - <LinearLayout + <RelativeLayout android:id="@+id/footer" - style="@android:style/ButtonBar" android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_alignParentBottom="true" - android:orientation="horizontal" > + android:layout_height="48dp" + android:layout_alignParentBottom="true" > - <Button - android:id="@+id/butConfirm" - android:layout_width="0px" - android:layout_height="wrap_content" - android:layout_weight="1" - android:text="@string/confirm_label" /> + <View + android:layout_width="match_parent" + android:layout_height="1dip" + android:layout_alignParentTop="true" + android:background="?android:attr/dividerVertical" /> + + <View + android:id="@+id/horizontal_divider" + android:layout_width="1dip" + android:layout_height="fill_parent" + android:layout_alignParentTop="true" + android:layout_centerHorizontal="true" + android:layout_marginBottom="4dp" + android:layout_marginTop="4dp" + android:background="?android:attr/dividerVertical" /> <Button android:id="@+id/butCancel" - android:layout_width="0px" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="1" + android:layout_alignParentBottom="true" + android:layout_alignParentLeft="true" + android:layout_alignParentTop="true" + android:layout_toLeftOf="@id/horizontal_divider" + android:background="?android:attr/selectableItemBackground" android:text="@string/cancel_label" /> - </LinearLayout> + + <Button + android:id="@+id/butConfirm" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentBottom="true" + android:layout_alignParentRight="true" + android:layout_alignParentTop="true" + android:layout_toRightOf="@id/horizontal_divider" + android:background="?android:attr/selectableItemBackground" + android:text="@string/confirm_label" /> + </RelativeLayout> <ListView android:id="@+id/feedlist" diff --git a/app/src/main/res/layout/time_dialog.xml b/app/src/main/res/layout/time_dialog.xml index 0290ce708..ba4249268 100644 --- a/app/src/main/res/layout/time_dialog.xml +++ b/app/src/main/res/layout/time_dialog.xml @@ -8,7 +8,7 @@ <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" - android:orientation="horizontal"> + android:orientation="horizontal" > <EditText android:id="@+id/etxtTime" @@ -18,9 +18,11 @@ android:layout_margin="8dp" android:ems="2" android:hint="@string/enter_time_here_label" - android:inputType="number" - android:maxLength="2" /> + android:maxLength="2" > + + <requestFocus /> + </EditText> <Spinner android:id="@+id/spTimeUnit" @@ -28,7 +30,6 @@ android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginTop="8dp" /> - </LinearLayout> <LinearLayout diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index e81115627..8ed7da731 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -316,6 +316,9 @@ android:key="prefHtmlExport" android:title="@string/html_export_label"/> <Preference + android:key="importExport" + android:title="@string/import_export"/> + <Preference android:key="statistics" android:title="@string/statistics_label"/> </PreferenceCategory> diff --git a/app/src/play/java/de/danoeh/antennapod/dialog/CustomMRControllerDialog.java b/app/src/play/java/de/danoeh/antennapod/dialog/CustomMRControllerDialog.java index 7b07d3f84..4cde95d6f 100644 --- a/app/src/play/java/de/danoeh/antennapod/dialog/CustomMRControllerDialog.java +++ b/app/src/play/java/de/danoeh/antennapod/dialog/CustomMRControllerDialog.java @@ -20,6 +20,7 @@ import android.support.v4.view.accessibility.AccessibilityEventCompat; import android.support.v7.app.MediaRouteControllerDialog; import android.support.v7.graphics.Palette; import android.support.v7.media.MediaRouter; +import android.support.v7.widget.AppCompatImageView; import android.text.TextUtils; import android.util.Log; import android.util.TypedValue; @@ -68,7 +69,7 @@ public class CustomMRControllerDialog extends MediaRouteControllerDialog { this(context, 0); } - public CustomMRControllerDialog(Context context, int theme) { + private CustomMRControllerDialog(Context context, int theme) { super(context, theme); mediaRouter = MediaRouter.getInstance(getContext()); token = mediaRouter.getMediaSessionToken(); @@ -203,7 +204,7 @@ public class CustomMRControllerDialog extends MediaRouteControllerDialog { * http://stackoverflow.com/questions/18077325/scale-image-to-fill-imageview-width-and-keep-aspect-ratio */ if (landscape) { - artView = new ImageView(getContext()) { + artView = new AppCompatImageView(getContext()) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int desiredWidth = widthMeasureSpec; @@ -234,7 +235,7 @@ public class CustomMRControllerDialog extends MediaRouteControllerDialog { MarginLayoutParamsCompat.setMarginStart(artParams, getContext().getResources().getDimensionPixelSize(R.dimen.media_router_controller_playback_control_horizontal_spacing)); } else { - artView = new ImageView(getContext()) { + artView = new AppCompatImageView(getContext()) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int desiredHeight = heightMeasureSpec; |