From dc1896e3f599bec4bc7295ba2f28284753d86394 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Mon, 11 Jun 2018 11:01:18 +0200 Subject: [PATCH] Fixed icons and tab titles --- .../newpipe/fragments/MainFragment.java | 62 ++++++++++++++++--- .../fragments/list/kiosk/KioskFragment.java | 22 ++++++- .../history/StatisticsPlaylistFragment.java | 4 +- 3 files changed, 79 insertions(+), 9 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 1073f174c..1d2ee0394 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -116,6 +116,50 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte adapter.notifyDataSetChanged(); viewPager.setOffscreenPageLimit(adapter.getCount()); setIcons(); + setFirstTitle(); + } + + private void setFirstTitle() { + if((tabs.size()>0)&&activity != null) { + String tabNumber = tabs.get(0); + + if (tabNumber.startsWith("1\t")) { + String kiosk[] = tabNumber.split("\t"); + if (kiosk.length == 2) { + try { + setTitle(kiosk[1]); + } catch (Exception e) { + //ignore this. It WILL be thrown while the service is changed. + } + } + } else if (tabNumber.startsWith("6\t")) { + + String channelInfo[] = tabNumber.split("\t"); + if(channelInfo.length==4) { + setTitle(channelInfo[2]); + } + } else { + switch (tabNumber) { + case "0": + setTitle(getString(R.string.app_name)); + break; + case "2": + setTitle(getString(R.string.tab_subscriptions)); + break; + case "3": + setTitle(getString(R.string.fragment_whats_new)); + break; + case "4": + setTitle(getString(R.string.tab_bookmarks)); + break; + case "5": + setTitle(getString(R.string.title_activity_history)); + break; + } + } + + + } } private void setIcons() { @@ -137,19 +181,23 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte } } else if (tabNumber.startsWith("6\t")) { tabToSet.setIcon(R.drawable.ic_channel_white_24dp); - } else { switch (tabNumber) { case "0": tabToSet.setIcon(R.drawable.ic_whatshot_white_24dp); + break; case "2": tabToSet.setIcon(R.drawable.ic_channel_white_24dp); + break; case "3": tabToSet.setIcon(R.drawable.ic_rss_feed_white_24dp); + break; case "4": tabToSet.setIcon(R.drawable.ic_bookmark_white_24dp); + break; case "5": tabToSet.setIcon(R.drawable.ic_history_white_24dp); + break; } } @@ -272,13 +320,13 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte case "0": return new BlankFragment(); case "2": - SubscriptionFragment sfragment = new SubscriptionFragment(); - sfragment.useAsFrontPage(true); - return sfragment; + SubscriptionFragment sFragment = new SubscriptionFragment(); + sFragment.useAsFrontPage(true); + return sFragment; case "3": - FeedFragment ffragment = new FeedFragment(); - ffragment.useAsFrontPage(true); - return ffragment; + FeedFragment fFragment = new FeedFragment(); + fFragment.useAsFrontPage(true); + return fFragment; case "4": BookmarkFragment bFragment = new BookmarkFragment(); bFragment.useAsFrontPage(true); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index 5dfdcd655..5f74fba06 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -59,6 +59,8 @@ public class KioskFragment extends BaseListInfoFragment { protected String kioskId = ""; protected String kioskTranslatedName; + private boolean mIsVisibleToUser = false; + /*////////////////////////////////////////////////////////////////////////// // Views //////////////////////////////////////////////////////////////////////////*/ @@ -97,6 +99,7 @@ public class KioskFragment extends BaseListInfoFragment { @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); + mIsVisibleToUser = isVisibleToUser; if(useAsFrontPage && isVisibleToUser && activity != null) { try { setTitle(kioskTranslatedName); @@ -163,7 +166,9 @@ public class KioskFragment extends BaseListInfoFragment { super.handleResult(result); name = kioskTranslatedName; - setTitle(kioskTranslatedName); + if(!useAsFrontPage) { + setTitle(kioskTranslatedName); + } if (!result.getErrors().isEmpty()) { showSnackBarError(result.getErrors(), @@ -182,4 +187,19 @@ public class KioskFragment extends BaseListInfoFragment { , "Get next page of: " + url, 0); } } + + /*////////////////////////////////////////////////////////////////////////// + // Utils + //////////////////////////////////////////////////////////////////////////*/ + + @Override + public void setTitle(String title) { + if(!useAsFrontPage) { + super.setTitle(title); + } else { + if(mIsVisibleToUser) { + super.setTitle(title); + } + } + } } diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 2c329cc20..09b756643 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -111,7 +111,9 @@ public class StatisticsPlaylistFragment @Override protected void initViews(View rootView, Bundle savedInstanceState) { super.initViews(rootView, savedInstanceState); - setTitle(getString(R.string.title_last_played)); + if(!useAsFrontPage) { + setTitle(getString(R.string.title_last_played)); + } } @Override