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