Fix compile errors
This commit is contained in:
parent
9c00e681bb
commit
4e285a4e70
|
@ -7,13 +7,13 @@ import kotlinx.parcelize.IgnoredOnParcel
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.extractor.Info
|
import org.schabi.newpipe.extractor.Info
|
||||||
import org.schabi.newpipe.extractor.NewPipe
|
|
||||||
import org.schabi.newpipe.extractor.exceptions.AccountTerminatedException
|
import org.schabi.newpipe.extractor.exceptions.AccountTerminatedException
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException
|
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException
|
||||||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor.DeobfuscateException
|
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor.DeobfuscateException
|
||||||
import org.schabi.newpipe.ktx.isNetworkRelated
|
import org.schabi.newpipe.ktx.isNetworkRelated
|
||||||
|
import org.schabi.newpipe.util.ServiceHelper
|
||||||
import java.io.PrintWriter
|
import java.io.PrintWriter
|
||||||
import java.io.StringWriter
|
import java.io.StringWriter
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class ErrorInfo(
|
||||||
constructor(throwable: Throwable, userAction: UserAction, request: String) :
|
constructor(throwable: Throwable, userAction: UserAction, request: String) :
|
||||||
this(throwable, userAction, SERVICE_NONE, request)
|
this(throwable, userAction, SERVICE_NONE, request)
|
||||||
constructor(throwable: Throwable, userAction: UserAction, request: String, serviceId: Int) :
|
constructor(throwable: Throwable, userAction: UserAction, request: String, serviceId: Int) :
|
||||||
this(throwable, userAction, NewPipe.getNameOfService(serviceId), request)
|
this(throwable, userAction, ServiceHelper.getNameOfServiceById(serviceId), request)
|
||||||
constructor(throwable: Throwable, userAction: UserAction, request: String, info: Info?) :
|
constructor(throwable: Throwable, userAction: UserAction, request: String, info: Info?) :
|
||||||
this(throwable, userAction, getInfoServiceName(info), request)
|
this(throwable, userAction, getInfoServiceName(info), request)
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ class ErrorInfo(
|
||||||
constructor(throwable: List<Throwable>, userAction: UserAction, request: String) :
|
constructor(throwable: List<Throwable>, userAction: UserAction, request: String) :
|
||||||
this(throwable, userAction, SERVICE_NONE, request)
|
this(throwable, userAction, SERVICE_NONE, request)
|
||||||
constructor(throwable: List<Throwable>, userAction: UserAction, request: String, serviceId: Int) :
|
constructor(throwable: List<Throwable>, userAction: UserAction, request: String, serviceId: Int) :
|
||||||
this(throwable, userAction, NewPipe.getNameOfService(serviceId), request)
|
this(throwable, userAction, ServiceHelper.getNameOfServiceById(serviceId), request)
|
||||||
constructor(throwable: List<Throwable>, userAction: UserAction, request: String, info: Info?) :
|
constructor(throwable: List<Throwable>, userAction: UserAction, request: String, info: Info?) :
|
||||||
this(throwable, userAction, getInfoServiceName(info), request)
|
this(throwable, userAction, getInfoServiceName(info), request)
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ class ErrorInfo(
|
||||||
Array(throwable.size) { i -> getStackTrace(throwable[i]) }
|
Array(throwable.size) { i -> getStackTrace(throwable[i]) }
|
||||||
|
|
||||||
private fun getInfoServiceName(info: Info?) =
|
private fun getInfoServiceName(info: Info?) =
|
||||||
if (info == null) SERVICE_NONE else NewPipe.getNameOfService(info.serviceId)
|
if (info == null) SERVICE_NONE else ServiceHelper.getNameOfServiceById(info.serviceId)
|
||||||
|
|
||||||
@StringRes
|
@StringRes
|
||||||
private fun getMessageStringId(
|
private fun getMessageStringId(
|
||||||
|
|
|
@ -15,7 +15,6 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.rxjava3.disposables.Disposable
|
import io.reactivex.rxjava3.disposables.Disposable
|
||||||
import org.schabi.newpipe.MainActivity
|
import org.schabi.newpipe.MainActivity
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.extractor.NewPipe
|
|
||||||
import org.schabi.newpipe.extractor.exceptions.AccountTerminatedException
|
import org.schabi.newpipe.extractor.exceptions.AccountTerminatedException
|
||||||
import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException
|
import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
|
||||||
|
@ -106,7 +105,7 @@ class ErrorPanelHelper(
|
||||||
if (!isNullOrEmpty((errorInfo.throwable as AccountTerminatedException).message)) {
|
if (!isNullOrEmpty((errorInfo.throwable as AccountTerminatedException).message)) {
|
||||||
errorServiceInfoTextView.text = context.resources.getString(
|
errorServiceInfoTextView.text = context.resources.getString(
|
||||||
R.string.service_provides_reason,
|
R.string.service_provides_reason,
|
||||||
NewPipe.getNameOfService(ServiceHelper.getSelectedServiceId(context))
|
ServiceHelper.getSelectedService(context)?.serviceInfo?.name ?: "<unknown>"
|
||||||
)
|
)
|
||||||
errorServiceInfoTextView.isVisible = true
|
errorServiceInfoTextView.isVisible = true
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,12 @@ import androidx.core.content.ContextCompat;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.database.LocalItem;
|
import org.schabi.newpipe.database.LocalItem;
|
||||||
import org.schabi.newpipe.database.playlist.PlaylistStreamEntry;
|
import org.schabi.newpipe.database.playlist.PlaylistStreamEntry;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
|
||||||
import org.schabi.newpipe.ktx.ViewUtils;
|
import org.schabi.newpipe.ktx.ViewUtils;
|
||||||
import org.schabi.newpipe.local.LocalItemBuilder;
|
import org.schabi.newpipe.local.LocalItemBuilder;
|
||||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
import org.schabi.newpipe.util.PicassoHelper;
|
|
||||||
import org.schabi.newpipe.util.Localization;
|
import org.schabi.newpipe.util.Localization;
|
||||||
|
import org.schabi.newpipe.util.PicassoHelper;
|
||||||
|
import org.schabi.newpipe.util.ServiceHelper;
|
||||||
import org.schabi.newpipe.views.AnimatedProgressBar;
|
import org.schabi.newpipe.views.AnimatedProgressBar;
|
||||||
|
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
@ -59,7 +59,7 @@ public class LocalPlaylistStreamItemHolder extends LocalItemHolder {
|
||||||
itemVideoTitleView.setText(item.getStreamEntity().getTitle());
|
itemVideoTitleView.setText(item.getStreamEntity().getTitle());
|
||||||
itemAdditionalDetailsView.setText(Localization
|
itemAdditionalDetailsView.setText(Localization
|
||||||
.concatenateStrings(item.getStreamEntity().getUploader(),
|
.concatenateStrings(item.getStreamEntity().getUploader(),
|
||||||
NewPipe.getNameOfService(item.getStreamEntity().getServiceId())));
|
ServiceHelper.getNameOfServiceById(item.getStreamEntity().getServiceId())));
|
||||||
|
|
||||||
if (item.getStreamEntity().getDuration() > 0) {
|
if (item.getStreamEntity().getDuration() > 0) {
|
||||||
itemDurationView.setText(Localization
|
itemDurationView.setText(Localization
|
||||||
|
|
|
@ -11,12 +11,12 @@ import androidx.core.content.ContextCompat;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.database.LocalItem;
|
import org.schabi.newpipe.database.LocalItem;
|
||||||
import org.schabi.newpipe.database.stream.StreamStatisticsEntry;
|
import org.schabi.newpipe.database.stream.StreamStatisticsEntry;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
|
||||||
import org.schabi.newpipe.ktx.ViewUtils;
|
import org.schabi.newpipe.ktx.ViewUtils;
|
||||||
import org.schabi.newpipe.local.LocalItemBuilder;
|
import org.schabi.newpipe.local.LocalItemBuilder;
|
||||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
import org.schabi.newpipe.util.PicassoHelper;
|
|
||||||
import org.schabi.newpipe.util.Localization;
|
import org.schabi.newpipe.util.Localization;
|
||||||
|
import org.schabi.newpipe.util.PicassoHelper;
|
||||||
|
import org.schabi.newpipe.util.ServiceHelper;
|
||||||
import org.schabi.newpipe.views.AnimatedProgressBar;
|
import org.schabi.newpipe.views.AnimatedProgressBar;
|
||||||
|
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
@ -70,11 +70,12 @@ public class LocalStatisticStreamItemHolder extends LocalItemHolder {
|
||||||
|
|
||||||
private String getStreamInfoDetailLine(final StreamStatisticsEntry entry,
|
private String getStreamInfoDetailLine(final StreamStatisticsEntry entry,
|
||||||
final DateTimeFormatter dateTimeFormatter) {
|
final DateTimeFormatter dateTimeFormatter) {
|
||||||
final String watchCount = Localization
|
return Localization.concatenateStrings(
|
||||||
.shortViewCount(itemBuilder.getContext(), entry.getWatchCount());
|
// watchCount
|
||||||
final String uploadDate = dateTimeFormatter.format(entry.getLatestAccessDate());
|
Localization.shortViewCount(itemBuilder.getContext(), entry.getWatchCount()),
|
||||||
final String serviceName = NewPipe.getNameOfService(entry.getStreamEntity().getServiceId());
|
dateTimeFormatter.format(entry.getLatestAccessDate()),
|
||||||
return Localization.concatenateStrings(watchCount, uploadDate, serviceName);
|
// serviceName
|
||||||
|
ServiceHelper.getNameOfServiceById(entry.getStreamEntity().getServiceId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,11 +5,11 @@ import android.view.ViewGroup;
|
||||||
|
|
||||||
import org.schabi.newpipe.database.LocalItem;
|
import org.schabi.newpipe.database.LocalItem;
|
||||||
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
|
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
|
||||||
import org.schabi.newpipe.local.LocalItemBuilder;
|
import org.schabi.newpipe.local.LocalItemBuilder;
|
||||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
import org.schabi.newpipe.util.PicassoHelper;
|
|
||||||
import org.schabi.newpipe.util.Localization;
|
import org.schabi.newpipe.util.Localization;
|
||||||
|
import org.schabi.newpipe.util.PicassoHelper;
|
||||||
|
import org.schabi.newpipe.util.ServiceHelper;
|
||||||
|
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@ public class RemotePlaylistItemHolder extends PlaylistItemHolder {
|
||||||
// Here is where the uploader name is set in the bookmarked playlists library
|
// Here is where the uploader name is set in the bookmarked playlists library
|
||||||
if (!TextUtils.isEmpty(item.getUploader())) {
|
if (!TextUtils.isEmpty(item.getUploader())) {
|
||||||
itemUploaderView.setText(Localization.concatenateStrings(item.getUploader(),
|
itemUploaderView.setText(Localization.concatenateStrings(item.getUploader(),
|
||||||
NewPipe.getNameOfService(item.getServiceId())));
|
ServiceHelper.getNameOfServiceById(item.getServiceId())));
|
||||||
} else {
|
} else {
|
||||||
itemUploaderView.setText(NewPipe.getNameOfService(item.getServiceId()));
|
itemUploaderView.setText(ServiceHelper.getNameOfServiceById(item.getServiceId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
PicassoHelper.loadPlaylistThumbnail(item.getThumbnailUrl()).into(itemThumbnailView);
|
PicassoHelper.loadPlaylistThumbnail(item.getThumbnailUrl()).into(itemThumbnailView);
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package org.schabi.newpipe.local.subscription;
|
package org.schabi.newpipe.local.subscription;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.subscription.SubscriptionExtractor.ContentSource.CHANNEL_URL;
|
||||||
|
import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.CHANNEL_URL_MODE;
|
||||||
|
import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.INPUT_STREAM_MODE;
|
||||||
|
import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_MODE;
|
||||||
|
import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_VALUE;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -40,12 +46,6 @@ import java.util.List;
|
||||||
|
|
||||||
import icepick.State;
|
import icepick.State;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.subscription.SubscriptionExtractor.ContentSource.CHANNEL_URL;
|
|
||||||
import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.CHANNEL_URL_MODE;
|
|
||||||
import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.INPUT_STREAM_MODE;
|
|
||||||
import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_MODE;
|
|
||||||
import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_VALUE;
|
|
||||||
|
|
||||||
public class SubscriptionsImportFragment extends BaseFragment {
|
public class SubscriptionsImportFragment extends BaseFragment {
|
||||||
@State
|
@State
|
||||||
int currentServiceId = Constants.NO_SERVICE_ID;
|
int currentServiceId = Constants.NO_SERVICE_ID;
|
||||||
|
@ -89,7 +89,7 @@ public class SubscriptionsImportFragment extends BaseFragment {
|
||||||
if (supportedSources.isEmpty() && currentServiceId != Constants.NO_SERVICE_ID) {
|
if (supportedSources.isEmpty() && currentServiceId != Constants.NO_SERVICE_ID) {
|
||||||
ErrorUtil.showSnackbar(activity,
|
ErrorUtil.showSnackbar(activity,
|
||||||
new ErrorInfo(new String[]{}, UserAction.SUBSCRIPTION_IMPORT_EXPORT,
|
new ErrorInfo(new String[]{}, UserAction.SUBSCRIPTION_IMPORT_EXPORT,
|
||||||
NewPipe.getNameOfService(currentServiceId),
|
ServiceHelper.getNameOfServiceById(currentServiceId),
|
||||||
"Service does not support importing subscriptions",
|
"Service does not support importing subscriptions",
|
||||||
R.string.general_error));
|
R.string.general_error));
|
||||||
activity.finish();
|
activity.finish();
|
||||||
|
|
|
@ -5,9 +5,9 @@ import android.text.TextUtils;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
|
||||||
import org.schabi.newpipe.util.Localization;
|
import org.schabi.newpipe.util.Localization;
|
||||||
import org.schabi.newpipe.util.PicassoHelper;
|
import org.schabi.newpipe.util.PicassoHelper;
|
||||||
|
import org.schabi.newpipe.util.ServiceHelper;
|
||||||
|
|
||||||
public class PlayQueueItemBuilder {
|
public class PlayQueueItemBuilder {
|
||||||
private static final String TAG = PlayQueueItemBuilder.class.toString();
|
private static final String TAG = PlayQueueItemBuilder.class.toString();
|
||||||
|
@ -25,7 +25,7 @@ public class PlayQueueItemBuilder {
|
||||||
holder.itemVideoTitleView.setText(item.getTitle());
|
holder.itemVideoTitleView.setText(item.getTitle());
|
||||||
}
|
}
|
||||||
holder.itemAdditionalDetailsView.setText(Localization.concatenateStrings(item.getUploader(),
|
holder.itemAdditionalDetailsView.setText(Localization.concatenateStrings(item.getUploader(),
|
||||||
NewPipe.getNameOfService(item.getServiceId())));
|
ServiceHelper.getNameOfServiceById(item.getServiceId())));
|
||||||
|
|
||||||
if (item.getDuration() > 0) {
|
if (item.getDuration() > 0) {
|
||||||
holder.itemDurationView.setText(Localization.getDurationString(item.getDuration()));
|
holder.itemDurationView.setText(Localization.getDurationString(item.getDuration()));
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package org.schabi.newpipe.settings.tabs;
|
package org.schabi.newpipe.settings.tabs;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.settings.tabs.Tab.typeFrom;
|
||||||
|
import static org.schabi.newpipe.util.ServiceHelper.getNameOfServiceById;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -28,7 +31,6 @@ import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.error.ErrorInfo;
|
import org.schabi.newpipe.error.ErrorInfo;
|
||||||
import org.schabi.newpipe.error.ErrorUtil;
|
import org.schabi.newpipe.error.ErrorUtil;
|
||||||
import org.schabi.newpipe.error.UserAction;
|
import org.schabi.newpipe.error.UserAction;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
|
||||||
import org.schabi.newpipe.settings.SelectChannelFragment;
|
import org.schabi.newpipe.settings.SelectChannelFragment;
|
||||||
import org.schabi.newpipe.settings.SelectKioskFragment;
|
import org.schabi.newpipe.settings.SelectKioskFragment;
|
||||||
import org.schabi.newpipe.settings.SelectPlaylistFragment;
|
import org.schabi.newpipe.settings.SelectPlaylistFragment;
|
||||||
|
@ -39,8 +41,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.schabi.newpipe.settings.tabs.Tab.typeFrom;
|
|
||||||
|
|
||||||
public class ChooseTabsFragment extends Fragment {
|
public class ChooseTabsFragment extends Fragment {
|
||||||
private TabsManager tabsManager;
|
private TabsManager tabsManager;
|
||||||
|
|
||||||
|
@ -374,36 +374,31 @@ public class ChooseTabsFragment extends Fragment {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String tabName;
|
tabNameView.setText(getTabName(type, tab));
|
||||||
|
tabIconView.setImageResource(tab.getTabIconRes(requireContext()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTabName(@NonNull final Tab.Type type, @NonNull final Tab tab) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BLANK:
|
case BLANK:
|
||||||
tabName = getString(R.string.blank_page_summary);
|
return getString(R.string.blank_page_summary);
|
||||||
break;
|
|
||||||
case DEFAULT_KIOSK:
|
case DEFAULT_KIOSK:
|
||||||
tabName = getString(R.string.default_kiosk_page_summary);
|
return getString(R.string.default_kiosk_page_summary);
|
||||||
break;
|
|
||||||
case KIOSK:
|
case KIOSK:
|
||||||
tabName = NewPipe.getNameOfService(((Tab.KioskTab) tab)
|
return getNameOfServiceById(((Tab.KioskTab) tab).getKioskServiceId())
|
||||||
.getKioskServiceId()) + "/" + tab.getTabName(requireContext());
|
+ "/" + tab.getTabName(requireContext());
|
||||||
break;
|
|
||||||
case CHANNEL:
|
case CHANNEL:
|
||||||
tabName = NewPipe.getNameOfService(((Tab.ChannelTab) tab)
|
return getNameOfServiceById(((Tab.ChannelTab) tab).getChannelServiceId())
|
||||||
.getChannelServiceId()) + "/" + tab.getTabName(requireContext());
|
+ "/" + tab.getTabName(requireContext());
|
||||||
break;
|
|
||||||
case PLAYLIST:
|
case PLAYLIST:
|
||||||
final int serviceId = ((Tab.PlaylistTab) tab).getPlaylistServiceId();
|
final int serviceId = ((Tab.PlaylistTab) tab).getPlaylistServiceId();
|
||||||
final String serviceName = serviceId == -1
|
final String serviceName = serviceId == -1
|
||||||
? getString(R.string.local)
|
? getString(R.string.local)
|
||||||
: NewPipe.getNameOfService(serviceId);
|
: getNameOfServiceById(serviceId);
|
||||||
tabName = serviceName + "/" + tab.getTabName(requireContext());
|
return serviceName + "/" + tab.getTabName(requireContext());
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
tabName = tab.getTabName(requireContext());
|
return tab.getTabName(requireContext());
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tabNameView.setText(tabName);
|
|
||||||
tabIconView.setImageResource(tab.getTabIconRes(requireContext()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package org.schabi.newpipe.util;
|
package org.schabi.newpipe.util;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
import androidx.annotation.DrawableRes;
|
import androidx.annotation.DrawableRes;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.preference.PreferenceManager;
|
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.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance;
|
import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public final class ServiceHelper {
|
public final class ServiceHelper {
|
||||||
private static final StreamingService DEFAULT_FALLBACK_SERVICE = ServiceList.YouTube;
|
private static final StreamingService DEFAULT_FALLBACK_SERVICE = ServiceList.YouTube;
|
||||||
|
@ -113,18 +117,32 @@ public final class ServiceHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getSelectedServiceId(final Context context) {
|
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)
|
final String serviceName = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
.getString(context.getString(R.string.current_service_key),
|
.getString(context.getString(R.string.current_service_key),
|
||||||
context.getString(R.string.default_service_value));
|
context.getString(R.string.default_service_value));
|
||||||
|
|
||||||
int serviceId;
|
|
||||||
try {
|
try {
|
||||||
serviceId = NewPipe.getService(serviceName).getServiceId();
|
return NewPipe.getService(serviceName);
|
||||||
} catch (final ExtractionException e) {
|
} 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) {
|
public static void setSelectedServiceId(final Context context, final int serviceId) {
|
||||||
|
@ -138,16 +156,6 @@ public final class ServiceHelper {
|
||||||
setSelectedServicePreferences(context, serviceName);
|
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,
|
private static void setSelectedServicePreferences(final Context context,
|
||||||
final String serviceName) {
|
final String serviceName) {
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit().
|
PreferenceManager.getDefaultSharedPreferences(context).edit().
|
||||||
|
|
Loading…
Reference in New Issue