merged upstream/dev
This commit is contained in:
commit
81658de08f
12 changed files with 202 additions and 144 deletions
|
|
@ -20,6 +20,7 @@ import com.nostra13.universalimageloader.core.ImageLoader;
|
|||
|
||||
import org.schabi.newpipe.App;
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.ServiceList;
|
||||
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
||||
import org.schabi.newpipe.extractor.localization.Localization;
|
||||
|
|
@ -182,6 +183,8 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
|||
if (!selectedLocalization.equals(initialSelectedLocalization)
|
||||
|| !selectedContentCountry.equals(initialSelectedContentCountry)) {
|
||||
Toast.makeText(requireContext(), R.string.localization_changes_requires_app_restart, Toast.LENGTH_LONG).show();
|
||||
|
||||
NewPipe.setupLocalization(selectedLocalization, selectedContentCountry);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ public class ChooseTabsFragment extends Fragment {
|
|||
break;
|
||||
case DEFAULT_KIOSK:
|
||||
if (!tabList.contains(tab)) {
|
||||
returnList.add(new ChooseTabListItem(tab.getTabId(), getString(R.string.default_kiosk_page_sumatry),
|
||||
returnList.add(new ChooseTabListItem(tab.getTabId(), getString(R.string.default_kiosk_page_summary),
|
||||
ThemeHelper.resolveResourceIdFromAttr(context, R.attr.ic_hot)));
|
||||
}
|
||||
break;
|
||||
|
|
@ -305,23 +305,25 @@ public class ChooseTabsFragment extends Fragment {
|
|||
return;
|
||||
}
|
||||
|
||||
String tabName = tab.getTabName(requireContext());
|
||||
final String tabName;
|
||||
switch (type) {
|
||||
case BLANK:
|
||||
tabName = requireContext().getString(R.string.blank_page_summary);
|
||||
break;
|
||||
case KIOSK:
|
||||
tabName = NewPipe.getNameOfService(((Tab.KioskTab) tab).getKioskServiceId()) + "/" + tabName;
|
||||
break;
|
||||
case CHANNEL:
|
||||
tabName = NewPipe.getNameOfService(((Tab.ChannelTab) tab).getChannelServiceId()) + "/" + tabName;
|
||||
tabName = getString(R.string.blank_page_summary);
|
||||
break;
|
||||
case DEFAULT_KIOSK:
|
||||
tabName = requireContext().getString(R.string.default_kiosk_page_sumatry);
|
||||
tabName = getString(R.string.default_kiosk_page_summary);
|
||||
break;
|
||||
case KIOSK:
|
||||
tabName = NewPipe.getNameOfService(((Tab.KioskTab) tab).getKioskServiceId()) + "/" + tab.getTabName(requireContext());
|
||||
break;
|
||||
case CHANNEL:
|
||||
tabName = NewPipe.getNameOfService(((Tab.ChannelTab) tab).getChannelServiceId()) + "/" + tab.getTabName(requireContext());
|
||||
break;
|
||||
default:
|
||||
tabName = tab.getTabName(requireContext());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
tabNameView.setText(tabName);
|
||||
tabIconView.setImageResource(tab.getTabIconRes(requireContext()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package org.schabi.newpipe.settings.tabs;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
|
@ -9,22 +10,26 @@ import androidx.fragment.app.Fragment;
|
|||
import com.grack.nanojson.JsonObject;
|
||||
import com.grack.nanojson.JsonSink;
|
||||
|
||||
import org.jsoup.helper.StringUtil;
|
||||
import org.schabi.newpipe.App;
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.fragments.BlankFragment;
|
||||
import org.schabi.newpipe.fragments.list.channel.ChannelFragment;
|
||||
import org.schabi.newpipe.fragments.list.kiosk.DefaultKioskFragment;
|
||||
import org.schabi.newpipe.fragments.list.kiosk.KioskFragment;
|
||||
import org.schabi.newpipe.local.bookmark.BookmarkFragment;
|
||||
import org.schabi.newpipe.local.feed.FeedFragment;
|
||||
import org.schabi.newpipe.local.history.StatisticsPlaylistFragment;
|
||||
import org.schabi.newpipe.local.subscription.SubscriptionFragment;
|
||||
import org.schabi.newpipe.report.ErrorActivity;
|
||||
import org.schabi.newpipe.report.UserAction;
|
||||
import org.schabi.newpipe.util.KioskTranslator;
|
||||
import org.schabi.newpipe.util.ServiceHelper;
|
||||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class Tab {
|
||||
Tab() {
|
||||
}
|
||||
|
|
@ -40,10 +45,12 @@ public abstract class Tab {
|
|||
/**
|
||||
* Return a instance of the fragment that this tab represent.
|
||||
*/
|
||||
public abstract Fragment getFragment() throws ExtractionException;
|
||||
public abstract Fragment getFragment(Context context) throws ExtractionException;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) return true;
|
||||
|
||||
return obj instanceof Tab && obj.getClass().equals(this.getClass())
|
||||
&& ((Tab) obj).getTabId() == this.getTabId();
|
||||
}
|
||||
|
|
@ -115,12 +122,6 @@ public abstract class Tab {
|
|||
return new KioskTab(jsonObject);
|
||||
case CHANNEL:
|
||||
return new ChannelTab(jsonObject);
|
||||
case DEFAULT_KIOSK:
|
||||
DefaultKioskTab tab = new DefaultKioskTab();
|
||||
if(!StringUtil.isBlank(tab.getKioskId())){
|
||||
return tab;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -133,13 +134,13 @@ public abstract class Tab {
|
|||
|
||||
public enum Type {
|
||||
BLANK(new BlankTab()),
|
||||
DEFAULT_KIOSK(new DefaultKioskTab()),
|
||||
SUBSCRIPTIONS(new SubscriptionsTab()),
|
||||
FEED(new FeedTab()),
|
||||
BOOKMARKS(new BookmarksTab()),
|
||||
HISTORY(new HistoryTab()),
|
||||
KIOSK(new KioskTab()),
|
||||
CHANNEL(new ChannelTab()),
|
||||
DEFAULT_KIOSK(new DefaultKioskTab());
|
||||
CHANNEL(new ChannelTab());
|
||||
|
||||
private Tab tab;
|
||||
|
||||
|
|
@ -176,7 +177,7 @@ public abstract class Tab {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlankFragment getFragment() {
|
||||
public BlankFragment getFragment(Context context) {
|
||||
return new BlankFragment();
|
||||
}
|
||||
}
|
||||
|
|
@ -201,7 +202,7 @@ public abstract class Tab {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionFragment getFragment() {
|
||||
public SubscriptionFragment getFragment(Context context) {
|
||||
return new SubscriptionFragment();
|
||||
}
|
||||
|
||||
|
|
@ -227,7 +228,7 @@ public abstract class Tab {
|
|||
}
|
||||
|
||||
@Override
|
||||
public FeedFragment getFragment() {
|
||||
public FeedFragment getFragment(Context context) {
|
||||
return new FeedFragment();
|
||||
}
|
||||
}
|
||||
|
|
@ -252,7 +253,7 @@ public abstract class Tab {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BookmarkFragment getFragment() {
|
||||
public BookmarkFragment getFragment(Context context) {
|
||||
return new BookmarkFragment();
|
||||
}
|
||||
}
|
||||
|
|
@ -277,7 +278,7 @@ public abstract class Tab {
|
|||
}
|
||||
|
||||
@Override
|
||||
public StatisticsPlaylistFragment getFragment() {
|
||||
public StatisticsPlaylistFragment getFragment(Context context) {
|
||||
return new StatisticsPlaylistFragment();
|
||||
}
|
||||
}
|
||||
|
|
@ -327,7 +328,7 @@ public abstract class Tab {
|
|||
}
|
||||
|
||||
@Override
|
||||
public KioskFragment getFragment() throws ExtractionException {
|
||||
public KioskFragment getFragment(Context context) throws ExtractionException {
|
||||
return KioskFragment.getInstance(kioskServiceId, kioskId);
|
||||
}
|
||||
|
||||
|
|
@ -343,6 +344,13 @@ public abstract class Tab {
|
|||
kioskId = jsonObject.getString(JSON_KIOSK_ID_KEY, "<no-id>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj) &&
|
||||
kioskServiceId == ((KioskTab) obj).kioskServiceId
|
||||
&& Objects.equals(kioskId, ((KioskTab) obj).kioskId);
|
||||
}
|
||||
|
||||
public int getKioskServiceId() {
|
||||
return kioskServiceId;
|
||||
}
|
||||
|
|
@ -394,7 +402,7 @@ public abstract class Tab {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ChannelFragment getFragment() {
|
||||
public ChannelFragment getFragment(Context context) {
|
||||
return ChannelFragment.getInstance(channelServiceId, channelUrl, channelName);
|
||||
}
|
||||
|
||||
|
|
@ -412,6 +420,14 @@ public abstract class Tab {
|
|||
channelName = jsonObject.getString(JSON_CHANNEL_NAME_KEY, "<no-name>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj) &&
|
||||
channelServiceId == ((ChannelTab) obj).channelServiceId
|
||||
&& Objects.equals(channelUrl, ((ChannelTab) obj).channelUrl)
|
||||
&& Objects.equals(channelName, ((ChannelTab) obj).channelName);
|
||||
}
|
||||
|
||||
public int getChannelServiceId() {
|
||||
return channelServiceId;
|
||||
}
|
||||
|
|
@ -428,22 +444,6 @@ public abstract class Tab {
|
|||
public static class DefaultKioskTab extends Tab {
|
||||
public static final int ID = 7;
|
||||
|
||||
private int kioskServiceId;
|
||||
private String kioskId;
|
||||
|
||||
protected DefaultKioskTab() {
|
||||
initKiosk();
|
||||
}
|
||||
|
||||
public void initKiosk() {
|
||||
this.kioskServiceId = ServiceHelper.getSelectedServiceId(App.getApp());
|
||||
try {
|
||||
this.kioskId = NewPipe.getService(this.kioskServiceId).getKioskList().getDefaultKioskId();
|
||||
} catch (ExtractionException e) {
|
||||
this.kioskId = "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTabId() {
|
||||
return ID;
|
||||
|
|
@ -451,27 +451,31 @@ public abstract class Tab {
|
|||
|
||||
@Override
|
||||
public String getTabName(Context context) {
|
||||
return KioskTranslator.getTranslatedKioskName(kioskId, context);
|
||||
return KioskTranslator.getTranslatedKioskName(getDefaultKioskId(context), context);
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
@Override
|
||||
public int getTabIconRes(Context context) {
|
||||
final int kioskIcon = KioskTranslator.getKioskIcons(kioskId, context);
|
||||
|
||||
if (kioskIcon <= 0) {
|
||||
throw new IllegalStateException("Kiosk ID is not valid: \"" + kioskId + "\"");
|
||||
}
|
||||
|
||||
return kioskIcon;
|
||||
return KioskTranslator.getKioskIcons(getDefaultKioskId(context), context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KioskFragment getFragment() throws ExtractionException {
|
||||
return KioskFragment.getInstance(kioskServiceId, kioskId);
|
||||
public DefaultKioskFragment getFragment(Context context) throws ExtractionException {
|
||||
return new DefaultKioskFragment();
|
||||
}
|
||||
|
||||
public String getKioskId() {
|
||||
private String getDefaultKioskId(Context context) {
|
||||
final int kioskServiceId = ServiceHelper.getSelectedServiceId(context);
|
||||
|
||||
String kioskId = "";
|
||||
try {
|
||||
final StreamingService service = NewPipe.getService(kioskServiceId);
|
||||
kioskId = service.getKioskList().getDefaultKioskId();
|
||||
} catch (ExtractionException e) {
|
||||
ErrorActivity.reportError(context, e, null, null,
|
||||
ErrorActivity.ErrorInfo.make(UserAction.REQUESTED_KIOSK, "none", "Loading default kiosk from selected service", 0));
|
||||
}
|
||||
return kioskId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package org.schabi.newpipe.settings.tabs;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.grack.nanojson.JsonArray;
|
||||
import com.grack.nanojson.JsonObject;
|
||||
import com.grack.nanojson.JsonParser;
|
||||
|
|
@ -9,18 +7,25 @@ import com.grack.nanojson.JsonParserException;
|
|||
import com.grack.nanojson.JsonStringWriter;
|
||||
import com.grack.nanojson.JsonWriter;
|
||||
|
||||
import org.jsoup.helper.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Class to get a JSON representation of a list of tabs, and the other way around.
|
||||
*/
|
||||
public class TabsJsonHelper {
|
||||
private static final String JSON_TABS_ARRAY_KEY = "tabs";
|
||||
|
||||
private static final List<Tab> FALLBACK_INITIAL_TABS_LIST = Collections.unmodifiableList(Arrays.asList(
|
||||
Tab.Type.DEFAULT_KIOSK.getTab(),
|
||||
Tab.Type.SUBSCRIPTIONS.getTab(),
|
||||
Tab.Type.BOOKMARKS.getTab()
|
||||
));
|
||||
|
||||
public static class InvalidJsonException extends Exception {
|
||||
private InvalidJsonException() {
|
||||
super();
|
||||
|
|
@ -83,16 +88,6 @@ public class TabsJsonHelper {
|
|||
return returnTabs;
|
||||
}
|
||||
|
||||
public static List<Tab> getDefaultTabs(){
|
||||
List<Tab> tabs = new ArrayList<>();
|
||||
Tab.DefaultKioskTab tab = new Tab.DefaultKioskTab();
|
||||
if(!StringUtil.isBlank(tab.getKioskId())){
|
||||
tabs.add(tab);
|
||||
}
|
||||
tabs.add(Tab.Type.SUBSCRIPTIONS.getTab());
|
||||
tabs.add(Tab.Type.BOOKMARKS.getTab());
|
||||
return Collections.unmodifiableList(tabs);
|
||||
}
|
||||
/**
|
||||
* Get a JSON representation from a list of tabs.
|
||||
*
|
||||
|
|
@ -112,4 +107,8 @@ public class TabsJsonHelper {
|
|||
jsonWriter.end();
|
||||
return jsonWriter.done();
|
||||
}
|
||||
|
||||
public static List<Tab> getDefaultTabs(){
|
||||
return FALLBACK_INITIAL_TABS_LIST;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue