1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-02 06:50:13 +01:00

Changed the way how kiosks are handled

This commit is contained in:
Somethingweirdhere 2018-06-18 22:42:42 +02:00
parent 2d2d5a042c
commit f3da712e43
2 changed files with 27 additions and 44 deletions

View File

@ -68,22 +68,11 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
private static final String TAB_NUMBER_CHANNEL = "6";
SharedPreferences.OnSharedPreferenceChangeListener listener = (prefs, key) -> {
if(key.equals("service")||key.equals("saveUsedTabs")) {
if(key.equals("saveUsedTabs")) {
mainPageChanged();
}
};
/*//////////////////////////////////////////////////////////////////////////
// Constants
//////////////////////////////////////////////////////////////////////////*/
private static final int FALLBACK_SERVICE_ID = ServiceList.YouTube.getServiceId();
private static final String FALLBACK_CHANNEL_URL = "https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ";
private static final String FALLBACK_CHANNEL_NAME = "Music";
private static final String FALLBACK_KIOSK_ID = "Trending";
private static final int KIOSK_MENU_OFFSET = 2000;
/*//////////////////////////////////////////////////////////////////////////
// Fragment's LifeCycle
//////////////////////////////////////////////////////////////////////////*/
@ -136,7 +125,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
if (tabNumber.startsWith(TAB_NUMBER_KIOSK + "\t")) {
String kiosk[] = tabNumber.split("\t");
if (kiosk.length == 2) {
if (kiosk.length == 3) {
try {
setTitle(kiosk[1]);
} catch (Exception e) {
@ -184,7 +173,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
if (tabNumber.startsWith(TAB_NUMBER_KIOSK + "\t")) {
String kiosk[] = tabNumber.split("\t");
if (kiosk.length == 2) {
if (kiosk.length == 3) {
try {
tabToSet.setIcon(KioskTranslator.getKioskIcons(kiosk[1], getContext()));
} catch (Exception e) {
@ -224,27 +213,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
String save = prefs.getString("saveUsedTabs", "1\n2\n4\n");
String tabsArray[] = save.trim().split("\n");
KioskList kl = null;
try {
StreamingService service = NewPipe.getService(currentServiceId);
kl = service.getKioskList();
} catch (Exception e) {
ErrorActivity.reportError(activity, e,
activity.getClass(),
null,
ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR,
"none", "", R.string.app_ui_crash));
}
for(String tabNumber:tabsArray) {
if(tabNumber.equals(TAB_NUMBER_KIOSK)) {
if (kl != null) {
for(String ks : kl.getAvailableKiosks()) {
tabs.add(tabNumber+"\t"+ks);
}
}
} else {
for(String tabNumber:tabsArray) { {
tabs.add(tabNumber);
}
}
@ -304,10 +273,10 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
if(tabNumber.startsWith(TAB_NUMBER_KIOSK + "\t")) {
String kiosk[] = tabNumber.split("\t");
if(kiosk.length==2) {
if(kiosk.length==3) {
KioskFragment fragment = null;
try {
fragment = KioskFragment.getInstance(currentServiceId, kiosk[1]);
fragment = KioskFragment.getInstance(Integer.parseInt(kiosk[2]), kiosk[1]);
fragment.useAsFrontPage(true);
return fragment;
} catch (Exception e) {

View File

@ -132,11 +132,7 @@ public class ContentSettingsMain extends Fragment {
private void addTab(int position) {
if(position!=6) {
usedTabs.add(String.valueOf(position));
usedAdapter.notifyDataSetChanged();
saveChanges();
} else {
if(position==6) {
SelectChannelFragment selectChannelFragment = new SelectChannelFragment();
selectChannelFragment.setOnSelectedLisener((String url, String name, int service) -> {
usedTabs.add(position+"\t"+url+"\t"+name+"\t"+service);
@ -144,6 +140,18 @@ public class ContentSettingsMain extends Fragment {
saveChanges();
});
selectChannelFragment.show(getFragmentManager(), "select_channel");
} else if(position==1) {
SelectKioskFragment selectKioskFragment = new SelectKioskFragment();
selectKioskFragment.setOnSelectedLisener((String kioskId, int service_id) -> {
usedTabs.add(position+"\t"+kioskId+"\t"+service_id);
usedAdapter.notifyDataSetChanged();
saveChanges();
});
selectKioskFragment.show(getFragmentManager(), "select_kiosk");
} else {
usedTabs.add(String.valueOf(position));
usedAdapter.notifyDataSetChanged();
saveChanges();
}
}
@ -212,8 +220,14 @@ public class ContentSettingsMain extends Fragment {
if(usedTabs.get(position).startsWith("6\t")) {
String channelInfo[] = usedTabs.get(position).split("\t");
String channelName = "";
if(channelInfo.length==4) channelName = channelInfo[2];
String textToSet = allTabs[6]+": "+channelName;
if (channelInfo.length == 4) channelName = channelInfo[2];
String textToSet = allTabs[6] + ": " + channelName;
text.setText(textToSet);
} else if(usedTabs.get(position).startsWith("1\t")) {
String kioskInfo[] = usedTabs.get(position).split("\t");
String kioskName = "";
if (kioskInfo.length == 3) kioskName = kioskInfo[1];
String textToSet = allTabs[1] + ": " + kioskName;
text.setText(textToSet);
} else {
text.setText(allTabs[Integer.parseInt(usedTabs.get(position))]);