Fixed bugs&crashes
This commit is contained in:
parent
6675d3e2cd
commit
5cb7771484
|
@ -59,7 +59,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
|||
private Bundle savedInstanceStateBundle;
|
||||
|
||||
SharedPreferences.OnSharedPreferenceChangeListener listener = (prefs, key) -> {
|
||||
if(key.equals("saveUsedTabs")||key.equals("service")) {
|
||||
if(key.equals("service")||key.equals("saveUsedTabs")) {
|
||||
mainPageChanged();
|
||||
}
|
||||
};
|
||||
|
@ -99,19 +99,66 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
|||
protected void initViews(View rootView, Bundle savedInstanceState) {
|
||||
super.initViews(rootView, savedInstanceState);
|
||||
|
||||
getTabOrder();
|
||||
|
||||
tabLayout = rootView.findViewById(R.id.main_tab_layout);
|
||||
viewPager = rootView.findViewById(R.id.pager);
|
||||
|
||||
/* Nested fragment, use child fragment here to maintain backstack in view pager. */
|
||||
adapter = new PagerAdapter(getChildFragmentManager());
|
||||
viewPager.setAdapter(adapter);
|
||||
viewPager.setOffscreenPageLimit(adapter.getCount());
|
||||
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
|
||||
mainPageChanged();
|
||||
}
|
||||
|
||||
|
||||
public void mainPageChanged() {
|
||||
getTabOrder();
|
||||
adapter.notifyDataSetChanged();
|
||||
viewPager.setOffscreenPageLimit(adapter.getCount());
|
||||
setIcons();
|
||||
}
|
||||
|
||||
private void setIcons() {
|
||||
for (int i = 0; i < tabs.size(); i++) {
|
||||
String tabNumber = tabs.get(i);
|
||||
|
||||
TabLayout.Tab tabToSet = tabLayout.getTabAt(i);
|
||||
|
||||
if (tabToSet != null) {
|
||||
|
||||
if (tabNumber.startsWith("1\t")) {
|
||||
String kiosk[] = tabNumber.split("\t");
|
||||
if (kiosk.length == 2) {
|
||||
try {
|
||||
tabToSet.setIcon(KioskTranslator.getKioskIcons(kiosk[1], getContext()));
|
||||
} catch (Exception e) {
|
||||
//ignore this. It WILL be thrown while the service is changed.
|
||||
}
|
||||
}
|
||||
} 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);
|
||||
case "2":
|
||||
tabToSet.setIcon(R.drawable.ic_channel_white_24dp);
|
||||
case "3":
|
||||
tabToSet.setIcon(R.drawable.ic_rss_feed_white_24dp);
|
||||
case "4":
|
||||
tabToSet.setIcon(R.drawable.ic_bookmark_white_24dp);
|
||||
case "5":
|
||||
tabToSet.setIcon(R.drawable.ic_history_white_24dp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void getTabOrder() {
|
||||
tabs.clear();
|
||||
|
||||
|
@ -194,11 +241,6 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
|||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
}
|
||||
|
||||
public void mainPageChanged() {
|
||||
getTabOrder();
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private class PagerAdapter extends FragmentPagerAdapter {
|
||||
PagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
|
@ -213,8 +255,6 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
|||
if(kiosk.length==2) {
|
||||
KioskFragment fragment = null;
|
||||
try {
|
||||
tabLayout.getTabAt(position).setIcon(KioskTranslator.getKioskIcons(kiosk[1], getContext()));
|
||||
|
||||
fragment = KioskFragment.getInstance(currentServiceId, kiosk[1]);
|
||||
fragment.useAsFrontPage(true);
|
||||
return fragment;
|
||||
|
@ -229,8 +269,6 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
|||
} else if(tabNumber.startsWith("6\t")) {
|
||||
String channelInfo[] = tabNumber.split("\t");
|
||||
if(channelInfo.length==4) {
|
||||
tabLayout.getTabAt(position).setIcon(R.drawable.ic_channel_white_24dp);
|
||||
|
||||
ChannelFragment fragment = ChannelFragment.getInstance(Integer.parseInt(channelInfo[3]), channelInfo[1], channelInfo[2]);
|
||||
fragment.useAsFrontPage(true);
|
||||
return fragment;
|
||||
|
@ -240,30 +278,20 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
|||
} else {
|
||||
switch (tabNumber) {
|
||||
case "0":
|
||||
tabLayout.getTabAt(position).setIcon(R.drawable.ic_whatshot_white_24dp);
|
||||
|
||||
return new BlankFragment();
|
||||
case "2":
|
||||
tabLayout.getTabAt(position).setIcon(R.drawable.ic_channel_white_24dp);
|
||||
|
||||
SubscriptionFragment sfragment = new SubscriptionFragment();
|
||||
sfragment.useAsFrontPage(true);
|
||||
return sfragment;
|
||||
case "3":
|
||||
tabLayout.getTabAt(position).setIcon(R.drawable.ic_rss_feed_white_24dp);
|
||||
|
||||
FeedFragment ffragment = new FeedFragment();
|
||||
ffragment.useAsFrontPage(true);
|
||||
return ffragment;
|
||||
case "4":
|
||||
tabLayout.getTabAt(position).setIcon(R.drawable.ic_bookmark_white_24dp);
|
||||
|
||||
BookmarkFragment bFragment = new BookmarkFragment();
|
||||
bFragment.useAsFrontPage(true);
|
||||
return bFragment;
|
||||
case "5":
|
||||
tabLayout.getTabAt(position).setIcon(R.drawable.ic_history_white_24dp);
|
||||
|
||||
StatisticsPlaylistFragment cFragment = new StatisticsPlaylistFragment();
|
||||
cFragment.useAsFrontPage(true);
|
||||
return cFragment;
|
||||
|
@ -284,5 +312,10 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
|||
public int getCount() {
|
||||
return tabs.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
getFragmentManager().beginTransaction().remove((Fragment)object).commitNowAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,6 +91,8 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
|
|||
|
||||
private MenuItem menuRssButton;
|
||||
|
||||
private boolean mIsVisibleToUser = false;
|
||||
|
||||
public static ChannelFragment getInstance(int serviceId, String url, String name) {
|
||||
ChannelFragment instance = new ChannelFragment();
|
||||
instance.setInitialData(serviceId, url, name);
|
||||
|
@ -104,6 +106,7 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
|
|||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
mIsVisibleToUser = isVisibleToUser;
|
||||
if(activity != null
|
||||
&& useAsFrontPage
|
||||
&& isVisibleToUser) {
|
||||
|
@ -516,7 +519,13 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
|
|||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
super.setTitle(title);
|
||||
headerTitleView.setText(title);
|
||||
if(!useAsFrontPage) {
|
||||
super.setTitle(title);
|
||||
headerTitleView.setText(title);
|
||||
} else {
|
||||
if(mIsVisibleToUser) {
|
||||
super.setTitle(title);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,11 +69,10 @@ public final class BookmarkFragment
|
|||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
if (activity != null && activity.getSupportActionBar() != null) {
|
||||
activity.getSupportActionBar().setDisplayShowTitleEnabled(true);
|
||||
activity.setTitle(R.string.tab_subscriptions);
|
||||
}
|
||||
|
||||
if(!useAsFrontPage) {
|
||||
setTitle(activity.getString(R.string.tab_bookmarks));
|
||||
}
|
||||
return inflater.inflate(R.layout.fragment_bookmarks, container, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,10 @@ public class FeedFragment extends BaseListFragment<List<SubscriptionEntity>, Voi
|
|||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
if(!useAsFrontPage) {
|
||||
setTitle(activity.getString(R.string.fragment_whats_new));
|
||||
}
|
||||
return inflater.inflate(R.layout.fragment_feed, container, false);
|
||||
}
|
||||
|
||||
|
@ -105,6 +109,14 @@ public class FeedFragment extends BaseListFragment<List<SubscriptionEntity>, Voi
|
|||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (activity != null && isVisibleToUser) {
|
||||
setTitle(activity.getString(R.string.fragment_whats_new));
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
protected RecyclerView.LayoutManager getListLayoutManager() {
|
||||
boolean isPortrait = getResources().getDisplayMetrics().heightPixels > getResources().getDisplayMetrics().widthPixels;
|
||||
|
@ -116,9 +128,6 @@ public class FeedFragment extends BaseListFragment<List<SubscriptionEntity>, Voi
|
|||
super.onCreateOptionsMenu(menu, inflater);
|
||||
|
||||
ActionBar supportActionBar = activity.getSupportActionBar();
|
||||
if (supportActionBar != null) {
|
||||
supportActionBar.setTitle(R.string.fragment_whats_new);
|
||||
}
|
||||
|
||||
if(useAsFrontPage) {
|
||||
supportActionBar.setDisplayShowTitleEnabled(true);
|
||||
|
|
Loading…
Reference in New Issue