From 69f95f41488a2ad59d2dd0ff936886e2fb93726c Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Mon, 9 May 2022 20:58:10 +0200 Subject: [PATCH] Use better way to get services --- .../subscription/SubscriptionFragment.kt | 27 ++++++------------- app/src/main/res/values/settings_keys.xml | 4 --- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index 7dec3b30d..4295424e6 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -34,9 +34,8 @@ import org.schabi.newpipe.databinding.FeedItemCarouselBinding import org.schabi.newpipe.databinding.FragmentSubscriptionBinding import org.schabi.newpipe.error.ErrorInfo import org.schabi.newpipe.error.UserAction -import org.schabi.newpipe.extractor.NewPipe +import org.schabi.newpipe.extractor.ServiceList import org.schabi.newpipe.extractor.channel.ChannelInfoItem -import org.schabi.newpipe.extractor.exceptions.ExtractionException import org.schabi.newpipe.fragments.BaseStateFragment import org.schabi.newpipe.ktx.animate import org.schabi.newpipe.local.subscription.SubscriptionViewModel.SubscriptionState @@ -146,26 +145,16 @@ class SubscriptionFragment : BaseStateFragment() { addMenuItemToSubmenu(importSubMenu, R.string.previous_export) { onImportPreviousSelected() } .setIcon(R.drawable.ic_backup) - val services = requireContext().resources.getStringArray(R.array.service_list) - for (serviceName in services) { - try { - val service = NewPipe.getService(serviceName) + for (service in ServiceList.all()) { + val subscriptionExtractor = service.subscriptionExtractor ?: continue - val subscriptionExtractor = service.subscriptionExtractor ?: continue + val supportedSources = subscriptionExtractor.supportedSources + if (supportedSources.isEmpty()) continue - val supportedSources = subscriptionExtractor.supportedSources - if (supportedSources.isEmpty()) continue - - addMenuItemToSubmenu(importSubMenu, serviceName) { - onImportFromServiceSelected(service.serviceId) - } - .setIcon(ServiceHelper.getIcon(service.serviceId)) - } catch (e: ExtractionException) { - throw RuntimeException( - "Services array contains an entry that it's not a valid service name ($serviceName)", - e - ) + addMenuItemToSubmenu(importSubMenu, service.serviceInfo.name) { + onImportFromServiceSelected(service.serviceId) } + .setIcon(ServiceHelper.getIcon(service.serviceId)) } // -- Export -- diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index bf42aaf0e..c13caf610 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -4,10 +4,6 @@ last_used_preferences_version - - @string/youtube - @string/soundcloud - service @string/youtube