From d652bd21842e851802b7a842856726048d7f2498 Mon Sep 17 00:00:00 2001 From: Spencer Visick Date: Thu, 19 Apr 2018 21:39:21 -0700 Subject: [PATCH 01/15] Fix Bluetooth Forward Skip Button for Android 8 It appears that Oreo has changed the behavior for Bluetooth KeyEvents. Starting with Android 8.0, KeyEvent.getSource() returns 0 (unknown source). This change explicitly sets when a key press is sent from a notification, or lockscreen event. Otherwise we use the customer-defined skip behavior. --- .../core/service/playback/PlaybackService.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index ab25f0a5f..dd7e84857 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -447,8 +447,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { if (keycode != -1) { Log.d(TAG, "Received media button event"); - handleKeycode(keycode, intent.getIntExtra(MediaButtonReceiver.EXTRA_SOURCE, - InputDeviceCompat.SOURCE_CLASS_NONE)); + handleKeycode(keycode, true); } else if (!flavorHelper.castDisconnect(castDisconnect) && playable != null) { started = true; boolean stream = intent.getBooleanExtra(EXTRA_SHOULD_STREAM, @@ -472,7 +471,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { * Handles media button events * return: keycode was handled */ - private boolean handleKeycode(int keycode, int source) { + private boolean handleKeycode(int keycode, boolean notificationButton) { Log.d(TAG, "Handling keycode: " + keycode); final PlaybackServiceMediaPlayer.PSMPInfo info = mediaPlayer.getPSMPInfo(); final PlayerStatus status = info.playerStatus; @@ -505,7 +504,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { return true; case KeyEvent.KEYCODE_MEDIA_NEXT: - if (source == InputDevice.SOURCE_CLASS_NONE || + if (notificationButton || UserPreferences.shouldHardwareButtonSkip()) { // assume the skip command comes from a notification or the lockscreen // a >| skip button should actually skip @@ -1756,11 +1755,11 @@ public class PlaybackService extends MediaBrowserServiceCompat { public boolean onMediaButtonEvent(final Intent mediaButton) { Log.d(TAG, "onMediaButtonEvent(" + mediaButton + ")"); if (mediaButton != null) { - KeyEvent keyEvent = (KeyEvent) mediaButton.getExtras().get(Intent.EXTRA_KEY_EVENT); + KeyEvent keyEvent = (KeyEvent) mediaButton.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getRepeatCount() == 0) { - return handleKeycode(keyEvent.getKeyCode(), keyEvent.getSource()); + return handleKeycode(keyEvent.getKeyCode(), false); } } return false; From 4bba6b30a1b5e82b93edc27742ec35362b08d1c7 Mon Sep 17 00:00:00 2001 From: orionlee Date: Mon, 30 Apr 2018 14:59:45 -0700 Subject: [PATCH 02/15] Issue #2579: Provide share Link in episode playback screen even when the episode has no link - Use podcast link as the fallback. Also bug fix share link with position: to include epsiode and podcast title. --- .../activity/MediaplayerActivity.java | 2 +- .../antennapod/core/util/ShareUtils.java | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) 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 21e375435..b9d261b0e 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -324,7 +324,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements menu.findItem(R.id.visit_website_item).setVisible(hasWebsiteLink); boolean isItemAndHasLink = isFeedMedia && - ((FeedMedia) media).getItem() != null && ((FeedMedia) media).getItem().getLink() != null; + ShareUtils.hasLinkToShare(((FeedMedia) media).getItem()); menu.findItem(R.id.share_link_item).setVisible(isItemAndHasLink); menu.findItem(R.id.share_link_with_position_item).setVisible(isItemAndHasLink); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java index 898f7bedb..149cdcbc6 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java @@ -50,11 +50,30 @@ public class ShareUtils { return item.getFeed().getTitle() + ": " + item.getTitle(); } + /** + * Get the link for the feed item for the purpose of Share. It fallbacks to + * use the feed's link if the named feed item has no link. + */ + private static String getItemShareLink(FeedItem item) { + String link = item.getLink(); + if (link == null) { + Feed feed = item.getFeed(); + if (feed != null) { + link = feed.getLink(); + } + } + return link; + } + + public static boolean hasLinkToShare(FeedItem item) { + return ( item != null && getItemShareLink(item) != null ); + } + public static void shareFeedItemLink(Context context, FeedItem item, boolean withPosition) { - String text = getItemShareText(item) + " " + item.getLink(); + String text = getItemShareText(item) + " " + getItemShareLink(item); if(withPosition) { int pos = item.getMedia().getPosition(); - text = item.getLink() + " [" + Converter.getDurationStringLong(pos) + "]"; + text += " [" + Converter.getDurationStringLong(pos) + "]"; } shareLink(context, text); } From 36507eb5064fe4b10a364f7b24855dba7f10d1c0 Mon Sep 17 00:00:00 2001 From: orionlee Date: Mon, 30 Apr 2018 15:14:58 -0700 Subject: [PATCH 03/15] Provide share Link in episode information screen, similar to episode playback screen. --- .../de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f6f73e017..1de41421f 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -86,7 +86,7 @@ public class FeedItemMenuHandler { mi.setItemVisibility(R.id.add_to_queue_item, false); } - if (!showExtendedMenu || selectedItem.getLink() == null) { + if (!showExtendedMenu || !ShareUtils.hasLinkToShare(selectedItem)) { mi.setItemVisibility(R.id.visit_website_item, false); mi.setItemVisibility(R.id.share_link_item, false); mi.setItemVisibility(R.id.share_link_with_position_item, false); From 345fcc17d0416f8db61a2506aa88c25b53718ebb Mon Sep 17 00:00:00 2001 From: orionlee Date: Mon, 30 Apr 2018 15:44:19 -0700 Subject: [PATCH 04/15] FeedItem Visit Website tweak: use feed website as a fallback, analogous to how share FeedItem link work. Applicable to both feed playback screen and feed information screen. --- .../activity/MediaplayerActivity.java | 18 ++++++++++++++++-- .../menuhandler/FeedItemMenuHandler.java | 3 ++- .../antennapod/core/util/FeedItemUtil.java | 15 +++++++++++++++ .../antennapod/core/util/ShareUtils.java | 19 ++----------------- 4 files changed, 35 insertions(+), 20 deletions(-) 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 b9d261b0e..229848753 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -42,6 +42,7 @@ import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.Converter; +import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.Flavors; import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.StorageUtils; @@ -320,7 +321,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements ((FeedMedia) media).getItem().getFlattrStatus().flattrable() ); - boolean hasWebsiteLink = media != null && media.getWebsiteLink() != null; + boolean hasWebsiteLink = ( getWebsiteLinkWithFallback(media) != null ); menu.findItem(R.id.visit_website_item).setVisible(hasWebsiteLink); boolean isItemAndHasLink = isFeedMedia && @@ -560,7 +561,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements }); break; case R.id.visit_website_item: - Uri uri = Uri.parse(media.getWebsiteLink()); + Uri uri = Uri.parse(getWebsiteLinkWithFallback(media)); startActivity(new Intent(Intent.ACTION_VIEW, uri)); break; case R.id.support_item: @@ -603,6 +604,19 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements } } + private static String getWebsiteLinkWithFallback(Playable media) { + String link = null; + if (media != null) { + link = media.getWebsiteLink(); + if (link == null) { + if (media instanceof FeedMedia) { + link = FeedItemUtil.getLinkWithFallback(((FeedMedia)media).getItem()); + } // else case not a FeedMedia, return null + } + } // else no media, return null + return link; + } + @Override protected void onResume() { super.onResume(); 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 1de41421f..de47ee5e4 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -17,6 +17,7 @@ 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.util.FeedItemUtil; import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.ShareUtils; @@ -216,7 +217,7 @@ public class FeedItemMenuHandler { DBWriter.setFeedItemAutoDownload(selectedItem, false); break; case R.id.visit_website_item: - Uri uri = Uri.parse(selectedItem.getLink()); + Uri uri = Uri.parse(FeedItemUtil.getLinkWithFallback(selectedItem)); Intent intent = new Intent(Intent.ACTION_VIEW, uri); if(IntentUtils.isCallable(context, intent)) { context.startActivity(intent); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java index 892e5ff38..129c1923e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.util; import java.util.List; +import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; public class FeedItemUtil { @@ -75,4 +76,18 @@ public class FeedItemUtil { return false; } + /** + * Get the link for the feed item for the purpose of Share. It fallbacks to + * use the feed's link if the named feed item has no link. + */ + public static String getLinkWithFallback(FeedItem item) { + String link = item.getLink(); + if (link == null) { + Feed feed = item.getFeed(); + if (feed != null) { + link = feed.getLink(); + } + } + return link; + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java index 149cdcbc6..0fbca2437 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java @@ -50,27 +50,12 @@ public class ShareUtils { return item.getFeed().getTitle() + ": " + item.getTitle(); } - /** - * Get the link for the feed item for the purpose of Share. It fallbacks to - * use the feed's link if the named feed item has no link. - */ - private static String getItemShareLink(FeedItem item) { - String link = item.getLink(); - if (link == null) { - Feed feed = item.getFeed(); - if (feed != null) { - link = feed.getLink(); - } - } - return link; - } - public static boolean hasLinkToShare(FeedItem item) { - return ( item != null && getItemShareLink(item) != null ); + return ( item != null && FeedItemUtil.getLinkWithFallback(item) != null ); } public static void shareFeedItemLink(Context context, FeedItem item, boolean withPosition) { - String text = getItemShareText(item) + " " + getItemShareLink(item); + String text = getItemShareText(item) + " " + FeedItemUtil.getLinkWithFallback(item); if(withPosition) { int pos = item.getMedia().getPosition(); text += " [" + Converter.getDurationStringLong(pos) + "]"; From ab0f4131850695537c22258633aecb4aca0aece5 Mon Sep 17 00:00:00 2001 From: orionlee Date: Mon, 30 Apr 2018 15:49:18 -0700 Subject: [PATCH 05/15] Make FeedItemUtil.getLinkWithFallback(item) tolerates null item. --- .../danoeh/antennapod/core/util/FeedItemUtil.java | 15 +++++++++------ .../danoeh/antennapod/core/util/ShareUtils.java | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java index 129c1923e..516c57d55 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java @@ -81,13 +81,16 @@ public class FeedItemUtil { * use the feed's link if the named feed item has no link. */ public static String getLinkWithFallback(FeedItem item) { - String link = item.getLink(); - if (link == null) { - Feed feed = item.getFeed(); - if (feed != null) { - link = feed.getLink(); + String link = null; + if (item != null) { + link = item.getLink(); + if (link == null) { + Feed feed = item.getFeed(); + if (feed != null) { + link = feed.getLink(); + } } - } + } // else null item, can only return null return link; } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java index 0fbca2437..5ae00460e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/ShareUtils.java @@ -51,7 +51,7 @@ public class ShareUtils { } public static boolean hasLinkToShare(FeedItem item) { - return ( item != null && FeedItemUtil.getLinkWithFallback(item) != null ); + return FeedItemUtil.getLinkWithFallback(item) != null; } public static void shareFeedItemLink(Context context, FeedItem item, boolean withPosition) { From 4c7531d277bf4b2a733031b9b1d3a7e9c1ad0241 Mon Sep 17 00:00:00 2001 From: orionlee Date: Wed, 2 May 2018 13:53:56 -0700 Subject: [PATCH 06/15] Flatten nested ifs, per @ByteHamster feedback --- .../activity/MediaplayerActivity.java | 18 ++++++++--------- .../antennapod/core/util/FeedItemUtil.java | 20 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) 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 229848753..35f9579df 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -605,16 +605,14 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements } private static String getWebsiteLinkWithFallback(Playable media) { - String link = null; - if (media != null) { - link = media.getWebsiteLink(); - if (link == null) { - if (media instanceof FeedMedia) { - link = FeedItemUtil.getLinkWithFallback(((FeedMedia)media).getItem()); - } // else case not a FeedMedia, return null - } - } // else no media, return null - return link; + if (media == null) { + return null; + } else if (media.getWebsiteLink() != null) { + return media.getWebsiteLink(); + } else if (media instanceof FeedMedia) { + return FeedItemUtil.getLinkWithFallback(((FeedMedia)media).getItem()); + } + return null; } @Override diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java index 516c57d55..76a6549ae 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java @@ -2,7 +2,6 @@ package de.danoeh.antennapod.core.util; import java.util.List; -import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; public class FeedItemUtil { @@ -81,16 +80,13 @@ public class FeedItemUtil { * use the feed's link if the named feed item has no link. */ public static String getLinkWithFallback(FeedItem item) { - String link = null; - if (item != null) { - link = item.getLink(); - if (link == null) { - Feed feed = item.getFeed(); - if (feed != null) { - link = feed.getLink(); - } - } - } // else null item, can only return null - return link; + if (item == null) { + return null; + } else if (item.getLink() != null) { + return item.getLink(); + } else if (item.getFeed() != null) { + return item.getFeed().getLink(); + } + return null; } } From 9f0d187efdba753e110dbc32ed9ba58c2fe4ce66 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Fri, 4 May 2018 13:57:52 +0200 Subject: [PATCH 07/15] Fix empty contentEncoded This code duplication was forgotten in #2607 --- .../java/de/danoeh/antennapod/core/feed/FeedMedia.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java index 2d551e1b2..a22422596 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java @@ -554,15 +554,9 @@ public class FeedMedia extends FeedFile implements Playable { public Callable loadShownotes() { return () -> { if (item == null) { - item = DBReader.getFeedItem( - itemID); + item = DBReader.getFeedItem(itemID); } - if (item.getContentEncoded() == null || item.getDescription() == null) { - DBReader.loadExtraInformationOfFeedItem( - item); - - } - return (item.getContentEncoded() != null) ? item.getContentEncoded() : item.getDescription(); + return item.loadShownotes().call(); }; } From 686801fea2fbe162fae9f1c64ab204587e19fc95 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Fri, 4 May 2018 17:51:12 +0200 Subject: [PATCH 08/15] Switched to PreferenceCompat --- app/build.gradle | 1 + .../activity/PreferenceActivity.java | 48 +++---- .../preferences/MasterSwitchPreference.java | 14 ++- .../preferences/PreferenceController.java | 119 +++++++++--------- .../preferences/SwitchCompatPreference.java | 37 ------ .../res/layout/preference_switch_layout.xml | 9 -- .../main/res/xml/preferences_autodownload.xml | 10 +- .../main/res/xml/preferences_integrations.xml | 2 +- app/src/main/res/xml/preferences_network.xml | 6 +- app/src/main/res/xml/preferences_playback.xml | 30 ++--- app/src/main/res/xml/preferences_storage.xml | 4 +- .../res/xml/preferences_user_interface.xml | 12 +- core/src/main/res/values/styles.xml | 4 + 13 files changed, 120 insertions(+), 176 deletions(-) delete mode 100644 app/src/main/java/de/danoeh/antennapod/preferences/SwitchCompatPreference.java delete mode 100644 app/src/main/res/layout/preference_switch_layout.xml diff --git a/app/build.gradle b/app/build.gradle index e4f66fe64..6a991f7f2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -139,6 +139,7 @@ dependencies { implementation "com.android.support:support-v4:$supportVersion" implementation "com.android.support:appcompat-v7:$supportVersion" implementation "com.android.support:design:$supportVersion" + implementation "com.android.support:preference-v14:$supportVersion" implementation "com.android.support:gridlayout-v7:$supportVersion" implementation "com.android.support:percent:$supportVersion" implementation "com.android.support:recyclerview-v7:$supportVersion" 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 a6aec2425..43bd147ea 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -1,13 +1,12 @@ package de.danoeh.antennapod.activity; -import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.preference.Preference; -import android.preference.PreferenceFragment; -import android.preference.PreferenceScreen; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceFragmentCompat; +import android.support.v7.preference.PreferenceScreen; import android.view.Menu; import android.view.MenuItem; import android.view.ViewGroup; @@ -29,10 +28,10 @@ public class PreferenceActivity extends AppCompatActivity { private static WeakReference instance; private PreferenceController preferenceController; private final PreferenceController.PreferenceUI preferenceUI = new PreferenceController.PreferenceUI() { - private PreferenceFragment fragment; + private PreferenceFragmentCompat fragment; @Override - public void setFragment(PreferenceFragment fragment) { + public void setFragment(PreferenceFragmentCompat fragment) { this.fragment = fragment; } @@ -47,7 +46,7 @@ public class PreferenceActivity extends AppCompatActivity { } @Override - public Activity getActivity() { + public AppCompatActivity getActivity() { return PreferenceActivity.this; } }; @@ -77,12 +76,12 @@ public class PreferenceActivity extends AppCompatActivity { // since the MainFragment depends on the preferenceController already being created preferenceController = new PreferenceController(preferenceUI); - PreferenceFragment prefFragment = new MainFragment(); + PreferenceFragmentCompat prefFragment = new MainFragment(); preferenceUI.setFragment(prefFragment); Bundle args = new Bundle(); args.putInt(PARAM_RESOURCE, R.xml.preferences); prefFragment.setArguments(args); - getFragmentManager().beginTransaction().replace(R.id.content, prefFragment).commit(); + getSupportFragmentManager().beginTransaction().replace(R.id.content, prefFragment).commit(); } @Override @@ -101,10 +100,10 @@ public class PreferenceActivity extends AppCompatActivity { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: - if (getFragmentManager().getBackStackEntryCount() == 0) { + if (getSupportFragmentManager().getBackStackEntryCount() == 0) { finish(); } else { - getFragmentManager().popBackStack(); + getSupportFragmentManager().popBackStack(); } return true; default: @@ -112,13 +111,17 @@ public class PreferenceActivity extends AppCompatActivity { } } - public static class MainFragment extends PreferenceFragment { + public static class MainFragment extends PreferenceFragmentCompat { private int screen; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { screen = getArguments().getInt(PARAM_RESOURCE); addPreferencesFromResource(screen); PreferenceActivity activity = instance.get(); @@ -133,31 +136,12 @@ public class PreferenceActivity extends AppCompatActivity { super.onResume(); PreferenceActivity activity = instance.get(); if(activity != null && activity.preferenceController != null) { - activity.setTitle(getTitle(screen)); + activity.setTitle(activity.preferenceController.getTitleOfPage(screen)); activity.preferenceUI.setFragment(this); activity.preferenceController.onResume(screen); } } - private int getTitle(int preferences) { - switch (preferences) { - case R.xml.preferences_network: - return R.string.network_pref; - case R.xml.preferences_autodownload: - return R.string.pref_automatic_download_title; - case R.xml.preferences_playback: - return R.string.playback_pref; - case R.xml.preferences_storage: - return R.string.storage_pref; - case R.xml.preferences_user_interface: - return R.string.user_interface_label; - case R.xml.preferences_integrations: - return R.string.integrations_label; - default: - return R.string.settings_label; - } - } - @Override public void onPause() { PreferenceActivity activity = instance.get(); diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/MasterSwitchPreference.java b/app/src/main/java/de/danoeh/antennapod/preferences/MasterSwitchPreference.java index bcac65804..e500267fe 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/MasterSwitchPreference.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/MasterSwitchPreference.java @@ -4,13 +4,14 @@ import android.annotation.TargetApi; import android.content.Context; import android.graphics.Typeface; import android.os.Build; +import android.support.v14.preference.SwitchPreference; +import android.support.v7.preference.PreferenceViewHolder; import android.util.AttributeSet; import android.util.TypedValue; -import android.view.View; import android.widget.TextView; import de.danoeh.antennapod.R; -public class MasterSwitchPreference extends SwitchCompatPreference { +public class MasterSwitchPreference extends SwitchPreference { public MasterSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); @@ -29,15 +30,16 @@ public class MasterSwitchPreference extends SwitchCompatPreference { super(context); } + @Override - protected void onBindView(View view) { - super.onBindView(view); + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); TypedValue typedValue = new TypedValue(); getContext().getTheme().resolveAttribute(R.attr.master_switch_background, typedValue, true); - view.setBackgroundColor(typedValue.data); + holder.itemView.setBackgroundColor(typedValue.data); - TextView title = (TextView) view.findViewById(android.R.id.title); + TextView title = (TextView) holder.findViewById(android.R.id.title); if (title != null) { title.setTypeface(title.getTypeface(), Typeface.BOLD); } 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 fceaf6abf..2902e00bc 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -3,7 +3,6 @@ package de.danoeh.antennapod.preferences; import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; -import android.app.Fragment; import android.app.ProgressDialog; import android.app.TimePickerDialog; import android.content.ActivityNotFoundException; @@ -18,31 +17,27 @@ import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Bundle; -import android.preference.CheckBoxPreference; -import android.preference.EditTextPreference; -import android.preference.ListPreference; -import android.preference.Preference; -import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; -import android.preference.PreferenceScreen; import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; import android.support.v4.content.FileProvider; import android.support.v7.app.AlertDialog; -import android.text.Editable; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.preference.CheckBoxPreference; +import android.support.v7.preference.ListPreference; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceFragmentCompat; +import android.support.v7.preference.PreferenceManager; +import android.support.v7.preference.PreferenceScreen; import android.text.Html; -import android.text.TextWatcher; import android.text.format.DateFormat; import android.text.format.DateUtils; import android.util.Log; -import android.widget.EditText; import android.widget.ListView; import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; import de.danoeh.antennapod.activity.AboutActivity; -import com.afollestad.materialdialogs.prefs.MaterialListPreference; import de.danoeh.antennapod.activity.ImportExportActivity; import de.danoeh.antennapod.activity.MediaplayerActivity; import de.danoeh.antennapod.activity.OpmlImportFromPathActivity; @@ -395,7 +390,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc return true; }); if (!PictureInPictureUtil.supportsPictureInPicture(activity)) { - MaterialListPreference behaviour = (MaterialListPreference) ui.findPreference(UserPreferences.PREF_VIDEO_BEHAVIOR); + ListPreference behaviour = (ListPreference) ui.findPreference(UserPreferences.PREF_VIDEO_BEHAVIOR); behaviour.setEntries(R.array.video_background_behavior_options_without_pip); behaviour.setEntryValues(R.array.video_background_behavior_values_without_pip); } @@ -432,9 +427,11 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } private void setupNetworkScreen() { - final Activity activity = ui.getActivity(); - ui.findPreference(PREF_SCREEN_AUTODL).setOnPreferenceClickListener(preference -> - openScreen(R.xml.preferences_autodownload, activity)); + final AppCompatActivity activity = ui.getActivity(); + ui.findPreference(PREF_SCREEN_AUTODL).setOnPreferenceClickListener(preference -> { + openScreen(R.xml.preferences_autodownload, activity); + return true; + }); ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL) .setOnPreferenceClickListener(preference -> { showUpdateIntervalTimePreferencesDialog(); @@ -458,33 +455,6 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } ); // validate and set correct value: number of downloads between 1 and 50 (inclusive) - final EditText ev = ((EditTextPreference) ui.findPreference(UserPreferences.PREF_PARALLEL_DOWNLOADS)).getEditText(); - ev.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - } - - @Override - public void afterTextChanged(Editable s) { - if (s.length() > 0) { - try { - int value = Integer.parseInt(s.toString()); - if (value <= 0) { - ev.setText("1"); - } else if (value > 50) { - ev.setText("50"); - } - } catch (NumberFormatException e) { - ev.setText("6"); - } - ev.setSelection(ev.getText().length()); - } - } - }); ui.findPreference(PREF_PROXY).setOnPreferenceClickListener(preference -> { ProxyDialog dialog = new ProxyDialog(ui.getActivity()); dialog.createDialog().show(); @@ -493,17 +463,27 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } private void setupMainScreen() { - final Activity activity = ui.getActivity(); - ui.findPreference(PREF_SCREEN_USER_INTERFACE).setOnPreferenceClickListener(preference -> - openScreen(R.xml.preferences_user_interface, activity)); - ui.findPreference(PREF_SCREEN_PLAYBACK).setOnPreferenceClickListener(preference -> - openScreen(R.xml.preferences_playback, activity)); - ui.findPreference(PREF_SCREEN_NETWORK).setOnPreferenceClickListener(preference -> - openScreen(R.xml.preferences_network, activity)); - ui.findPreference(PREF_SCREEN_INTEGRATIONS).setOnPreferenceClickListener(preference -> - openScreen(R.xml.preferences_integrations, activity)); - ui.findPreference(PREF_SCREEN_STORAGE).setOnPreferenceClickListener(preference -> - openScreen(R.xml.preferences_storage, activity)); + final AppCompatActivity activity = ui.getActivity(); + ui.findPreference(PREF_SCREEN_USER_INTERFACE).setOnPreferenceClickListener(preference -> { + openScreen(R.xml.preferences_user_interface, activity); + return true; + }); + ui.findPreference(PREF_SCREEN_PLAYBACK).setOnPreferenceClickListener(preference -> { + openScreen(R.xml.preferences_playback, activity); + return true; + }); + ui.findPreference(PREF_SCREEN_NETWORK).setOnPreferenceClickListener(preference -> { + openScreen(R.xml.preferences_network, activity); + return true; + }); + ui.findPreference(PREF_SCREEN_INTEGRATIONS).setOnPreferenceClickListener(preference -> { + openScreen(R.xml.preferences_integrations, activity); + return true; + }); + ui.findPreference(PREF_SCREEN_STORAGE).setOnPreferenceClickListener(preference -> { + openScreen(R.xml.preferences_storage, activity); + return true; + }); ui.findPreference(PreferenceController.PREF_ABOUT).setOnPreferenceClickListener( preference -> { @@ -550,15 +530,34 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc }); } - private boolean openScreen(int preferences, Activity activity) { - Fragment prefFragment = new PreferenceActivity.MainFragment(); + public PreferenceFragmentCompat openScreen(int preferences, AppCompatActivity activity) { + PreferenceFragmentCompat prefFragment = new PreferenceActivity.MainFragment(); Bundle args = new Bundle(); args.putInt(PARAM_RESOURCE, preferences); prefFragment.setArguments(args); - activity.getFragmentManager().beginTransaction() + activity.getSupportFragmentManager().beginTransaction() .replace(R.id.content, prefFragment) .addToBackStack(TAG).commit(); - return true; + return prefFragment; + } + + public int getTitleOfPage(int preferences) { + switch (preferences) { + case R.xml.preferences_network: + return R.string.network_pref; + case R.xml.preferences_autodownload: + return R.string.pref_automatic_download_title; + case R.xml.preferences_playback: + return R.string.playback_pref; + case R.xml.preferences_storage: + return R.string.storage_pref; + case R.xml.preferences_user_interface: + return R.string.user_interface_label; + case R.xml.preferences_integrations: + return R.string.integrations_label; + default: + return R.string.settings_label; + } } private boolean export(ExportWriter exportWriter) { @@ -1115,7 +1114,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc public interface PreferenceUI { - void setFragment(PreferenceFragment fragment); + void setFragment(PreferenceFragmentCompat fragment); /** * Finds a preference based on its key. @@ -1124,6 +1123,6 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc PreferenceScreen getPreferenceScreen(); - Activity getActivity(); + AppCompatActivity getActivity(); } } diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/SwitchCompatPreference.java b/app/src/main/java/de/danoeh/antennapod/preferences/SwitchCompatPreference.java deleted file mode 100644 index 10c11b88e..000000000 --- a/app/src/main/java/de/danoeh/antennapod/preferences/SwitchCompatPreference.java +++ /dev/null @@ -1,37 +0,0 @@ -package de.danoeh.antennapod.preferences; - -import android.annotation.TargetApi; -import android.content.Context; -import android.os.Build; -import android.preference.CheckBoxPreference; -import android.util.AttributeSet; - -import de.danoeh.antennapod.R; - -public class SwitchCompatPreference extends CheckBoxPreference { - - public SwitchCompatPreference(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - init(); - } - - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public SwitchCompatPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - init(); - } - - public SwitchCompatPreference(Context context, AttributeSet attrs) { - super(context, attrs); - init(); - } - - public SwitchCompatPreference(Context context) { - super(context); - init(); - } - - private void init() { - setWidgetLayoutResource(R.layout.preference_switch_layout); - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/preference_switch_layout.xml b/app/src/main/res/layout/preference_switch_layout.xml deleted file mode 100644 index 54fa74061..000000000 --- a/app/src/main/res/layout/preference_switch_layout.xml +++ /dev/null @@ -1,9 +0,0 @@ - - \ No newline at end of file diff --git a/app/src/main/res/xml/preferences_autodownload.xml b/app/src/main/res/xml/preferences_autodownload.xml index 72716423a..037e92d75 100644 --- a/app/src/main/res/xml/preferences_autodownload.xml +++ b/app/src/main/res/xml/preferences_autodownload.xml @@ -7,14 +7,14 @@ android:key="prefEnableAutoDl" android:title="@string/pref_automatic_download_title" android:defaultValue="false"/> - - - - - diff --git a/app/src/main/res/xml/preferences_integrations.xml b/app/src/main/res/xml/preferences_integrations.xml index 8ce35b596..0169bb337 100644 --- a/app/src/main/res/xml/preferences_integrations.xml +++ b/app/src/main/res/xml/preferences_integrations.xml @@ -53,7 +53,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @drawable/ic_create_new_folder_grey600_24dp @drawable/ic_cast_disconnect_grey600_36dp @color/master_switch_background_light + @style/PreferenceThemeOverlay.v14.Material