mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
Use better way to get services
This commit is contained in:
parent
de4b5a8f0f
commit
69f95f4148
@ -34,9 +34,8 @@ import org.schabi.newpipe.databinding.FeedItemCarouselBinding
|
|||||||
import org.schabi.newpipe.databinding.FragmentSubscriptionBinding
|
import org.schabi.newpipe.databinding.FragmentSubscriptionBinding
|
||||||
import org.schabi.newpipe.error.ErrorInfo
|
import org.schabi.newpipe.error.ErrorInfo
|
||||||
import org.schabi.newpipe.error.UserAction
|
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.channel.ChannelInfoItem
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException
|
|
||||||
import org.schabi.newpipe.fragments.BaseStateFragment
|
import org.schabi.newpipe.fragments.BaseStateFragment
|
||||||
import org.schabi.newpipe.ktx.animate
|
import org.schabi.newpipe.ktx.animate
|
||||||
import org.schabi.newpipe.local.subscription.SubscriptionViewModel.SubscriptionState
|
import org.schabi.newpipe.local.subscription.SubscriptionViewModel.SubscriptionState
|
||||||
@ -146,26 +145,16 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
|||||||
addMenuItemToSubmenu(importSubMenu, R.string.previous_export) { onImportPreviousSelected() }
|
addMenuItemToSubmenu(importSubMenu, R.string.previous_export) { onImportPreviousSelected() }
|
||||||
.setIcon(R.drawable.ic_backup)
|
.setIcon(R.drawable.ic_backup)
|
||||||
|
|
||||||
val services = requireContext().resources.getStringArray(R.array.service_list)
|
for (service in ServiceList.all()) {
|
||||||
for (serviceName in services) {
|
val subscriptionExtractor = service.subscriptionExtractor ?: continue
|
||||||
try {
|
|
||||||
val service = NewPipe.getService(serviceName)
|
|
||||||
|
|
||||||
val subscriptionExtractor = service.subscriptionExtractor ?: continue
|
val supportedSources = subscriptionExtractor.supportedSources
|
||||||
|
if (supportedSources.isEmpty()) continue
|
||||||
|
|
||||||
val supportedSources = subscriptionExtractor.supportedSources
|
addMenuItemToSubmenu(importSubMenu, service.serviceInfo.name) {
|
||||||
if (supportedSources.isEmpty()) continue
|
onImportFromServiceSelected(service.serviceId)
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
.setIcon(ServiceHelper.getIcon(service.serviceId))
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- Export --
|
// -- Export --
|
||||||
|
@ -4,10 +4,6 @@
|
|||||||
<string name="last_used_preferences_version">last_used_preferences_version</string>
|
<string name="last_used_preferences_version">last_used_preferences_version</string>
|
||||||
|
|
||||||
<!-- Service -->
|
<!-- Service -->
|
||||||
<string-array name="service_list">
|
|
||||||
<item>@string/youtube</item>
|
|
||||||
<item>@string/soundcloud</item>
|
|
||||||
</string-array>
|
|
||||||
<string name="current_service_key">service</string>
|
<string name="current_service_key">service</string>
|
||||||
<string name="default_service_value">@string/youtube</string>
|
<string name="default_service_value">@string/youtube</string>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user