From f3da712e433dbd842eaf50ddf04996d706c87dd2 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Mon, 18 Jun 2018 22:42:42 +0200 Subject: [PATCH] Changed the way how kiosks are handled --- .../newpipe/fragments/MainFragment.java | 43 +++---------------- .../newpipe/settings/ContentSettingsMain.java | 28 +++++++++--- 2 files changed, 27 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java index 55fbe833f..3ac65e4a0 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -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) { diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMain.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMain.java index 672cbcb41..22cebd6b5 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMain.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMain.java @@ -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))]);