Fix compile errors
This commit is contained in:
parent
bd19013771
commit
04e8e03d8f
9 changed files with 69 additions and 66 deletions
|
|
@ -1,9 +1,12 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
|
|
@ -18,9 +21,10 @@ import org.schabi.newpipe.extractor.StreamingService;
|
|||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class ServiceHelper {
|
||||
private static final StreamingService DEFAULT_FALLBACK_SERVICE = ServiceList.YouTube;
|
||||
|
|
@ -113,18 +117,32 @@ public final class ServiceHelper {
|
|||
}
|
||||
|
||||
public static int getSelectedServiceId(final Context context) {
|
||||
return Optional.ofNullable(getSelectedService(context))
|
||||
.orElse(DEFAULT_FALLBACK_SERVICE)
|
||||
.getServiceId();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static StreamingService getSelectedService(final Context context) {
|
||||
final String serviceName = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString(context.getString(R.string.current_service_key),
|
||||
context.getString(R.string.default_service_value));
|
||||
|
||||
int serviceId;
|
||||
try {
|
||||
serviceId = NewPipe.getService(serviceName).getServiceId();
|
||||
return NewPipe.getService(serviceName);
|
||||
} catch (final ExtractionException e) {
|
||||
serviceId = DEFAULT_FALLBACK_SERVICE.getServiceId();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return serviceId;
|
||||
@Nonnull
|
||||
public static String getNameOfServiceById(final int serviceId) {
|
||||
return ServiceList.all().stream()
|
||||
.filter(s -> s.getServiceId() == serviceId)
|
||||
.findFirst()
|
||||
.map(StreamingService::getServiceInfo)
|
||||
.map(StreamingService.ServiceInfo::getName)
|
||||
.orElse("<unknown>");
|
||||
}
|
||||
|
||||
public static void setSelectedServiceId(final Context context, final int serviceId) {
|
||||
|
|
@ -138,16 +156,6 @@ public final class ServiceHelper {
|
|||
setSelectedServicePreferences(context, serviceName);
|
||||
}
|
||||
|
||||
public static void setSelectedServiceId(final Context context, final String serviceName) {
|
||||
final int serviceId = NewPipe.getIdOfService(serviceName);
|
||||
if (serviceId == -1) {
|
||||
setSelectedServicePreferences(context,
|
||||
DEFAULT_FALLBACK_SERVICE.getServiceInfo().getName());
|
||||
} else {
|
||||
setSelectedServicePreferences(context, serviceName);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setSelectedServicePreferences(final Context context,
|
||||
final String serviceName) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue