Skip to content

Commit 69f95f4

Browse files
committed
Use better way to get services
1 parent de4b5a8 commit 69f95f4

2 files changed

Lines changed: 8 additions & 23 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ import org.schabi.newpipe.databinding.FeedItemCarouselBinding
3434
import org.schabi.newpipe.databinding.FragmentSubscriptionBinding
3535
import org.schabi.newpipe.error.ErrorInfo
3636
import org.schabi.newpipe.error.UserAction
37-
import org.schabi.newpipe.extractor.NewPipe
37+
import org.schabi.newpipe.extractor.ServiceList
3838
import org.schabi.newpipe.extractor.channel.ChannelInfoItem
39-
import org.schabi.newpipe.extractor.exceptions.ExtractionException
4039
import org.schabi.newpipe.fragments.BaseStateFragment
4140
import org.schabi.newpipe.ktx.animate
4241
import org.schabi.newpipe.local.subscription.SubscriptionViewModel.SubscriptionState
@@ -146,26 +145,16 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
146145
addMenuItemToSubmenu(importSubMenu, R.string.previous_export) { onImportPreviousSelected() }
147146
.setIcon(R.drawable.ic_backup)
148147

149-
val services = requireContext().resources.getStringArray(R.array.service_list)
150-
for (serviceName in services) {
151-
try {
152-
val service = NewPipe.getService(serviceName)
148+
for (service in ServiceList.all()) {
149+
val subscriptionExtractor = service.subscriptionExtractor ?: continue
153150

154-
val subscriptionExtractor = service.subscriptionExtractor ?: continue
151+
val supportedSources = subscriptionExtractor.supportedSources
152+
if (supportedSources.isEmpty()) continue
155153

156-
val supportedSources = subscriptionExtractor.supportedSources
157-
if (supportedSources.isEmpty()) continue
158-
159-
addMenuItemToSubmenu(importSubMenu, serviceName) {
160-
onImportFromServiceSelected(service.serviceId)
161-
}
162-
.setIcon(ServiceHelper.getIcon(service.serviceId))
163-
} catch (e: ExtractionException) {
164-
throw RuntimeException(
165-
"Services array contains an entry that it's not a valid service name ($serviceName)",
166-
e
167-
)
154+
addMenuItemToSubmenu(importSubMenu, service.serviceInfo.name) {
155+
onImportFromServiceSelected(service.serviceId)
168156
}
157+
.setIcon(ServiceHelper.getIcon(service.serviceId))
169158
}
170159

171160
// -- Export --

app/src/main/res/values/settings_keys.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
<string name="last_used_preferences_version">last_used_preferences_version</string>
55

66
<!-- Service -->
7-
<string-array name="service_list">
8-
<item>@string/youtube</item>
9-
<item>@string/soundcloud</item>
10-
</string-array>
117
<string name="current_service_key">service</string>
128
<string name="default_service_value">@string/youtube</string>
139

0 commit comments

Comments
 (0)