diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java index 5a8d8dd52..80f05585b 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java @@ -50,6 +50,8 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC protected Button errorButtonRetry; protected TextView errorTextView; + protected boolean useAsFrontPage = false; + @Override public void onViewCreated(View rootView, Bundle savedInstanceState) { super.onViewCreated(rootView, savedInstanceState); @@ -62,6 +64,10 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC wasLoading.set(isLoading.get()); } + public void useAsFrontPage(boolean value) { + useAsFrontPage = value; + } + /*////////////////////////////////////////////////////////////////////////// // Init //////////////////////////////////////////////////////////////////////////*/ 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 0a8e9b655..aa28c54fb 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.fragments; +import android.content.SharedPreferences; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.design.widget.TabLayout; @@ -19,6 +20,8 @@ import android.view.ViewGroup; import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; +import org.schabi.newpipe.fragments.list.channel.ChannelFragment; +import org.schabi.newpipe.fragments.list.feed.FeedFragment; import org.schabi.newpipe.fragments.list.kiosk.KioskFragment; import org.schabi.newpipe.fragments.subscription.SubscriptionFragment; import org.schabi.newpipe.report.ErrorActivity; @@ -153,16 +156,27 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte if(set_main_page.equals(getString(R.string.blank_page_key))) { return new BlankFragment(); } else if(set_main_page.equals(getString(R.string.kiosk_page_key))) { - return KioskFragment.getInstance(currentServiceId); + KioskFragment fragment = KioskFragment.getInstance(currentServiceId); + fragment.useAsFrontPage(true); + return fragment; } else if(set_main_page.equals(getString(R.string.feed_page_key))) { - return new BlankFragment(); + FeedFragment fragment = new FeedFragment(); + fragment.useAsFrontPage(true); + return fragment; } else if(set_main_page.equals(getString(R.string.channel_page_key))) { - return new BlankFragment(); + SharedPreferences preferences = + PreferenceManager.getDefaultSharedPreferences(getActivity()); + int serviceId = preferences.getInt(getString(R.string.main_page_selected_service), 0); + String url = preferences.getString(getString(R.string.main_page_selected_channel_url), + "https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ"); + String name = preferences.getString(getString(R.string.main_page_selected_channel_name), "Music"); + ChannelFragment fragment = ChannelFragment.getInstance(serviceId, url, name); + fragment.useAsFrontPage(true); + return fragment; } else { return new BlankFragment(); } - } catch (Exception e) { ErrorActivity.reportError(activity, e, activity.getClass(), diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index 4501ab859..48661969f 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -135,7 +135,9 @@ public abstract class BaseListFragment extends BaseStateFragment implem @Override public void selected(StreamInfoItem selectedItem) { onItemSelected(selectedItem); - NavigationHelper.openVideoDetailFragment(getFragmentManager(), selectedItem.service_id, selectedItem.url, selectedItem.name); + NavigationHelper.openVideoDetailFragment( + useAsFrontPage?getParentFragment().getFragmentManager():getFragmentManager(), + selectedItem.service_id, selectedItem.url, selectedItem.name); } }); @@ -143,7 +145,9 @@ public abstract class BaseListFragment extends BaseStateFragment implem @Override public void selected(ChannelInfoItem selectedItem) { onItemSelected(selectedItem); - NavigationHelper.openChannelFragment(getFragmentManager(), selectedItem.service_id, selectedItem.url, selectedItem.name); + NavigationHelper.openChannelFragment( + useAsFrontPage?getParentFragment().getFragmentManager():getFragmentManager(), + selectedItem.service_id, selectedItem.url, selectedItem.name); } }); @@ -151,7 +155,9 @@ public abstract class BaseListFragment extends BaseStateFragment implem @Override public void selected(PlaylistInfoItem selectedItem) { onItemSelected(selectedItem); - NavigationHelper.openPlaylistFragment(getFragmentManager(), selectedItem.service_id, selectedItem.url, selectedItem.name); + NavigationHelper.openPlaylistFragment( + useAsFrontPage?getParentFragment().getFragmentManager():getFragmentManager(), + selectedItem.service_id, selectedItem.url, selectedItem.name); } }); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index b7148fe63..5a722ec4c 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -7,6 +7,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; +import android.support.v7.app.ActionBar; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; @@ -118,15 +119,21 @@ public class ChannelFragment extends BaseListInfoFragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "], inflater = [" + inflater + "]"); super.onCreateOptionsMenu(menu, inflater); - inflater.inflate(R.menu.menu_channel, menu); + ActionBar supportActionBar = activity.getSupportActionBar(); + if(useAsFrontPage) { + supportActionBar.setDisplayHomeAsUpEnabled(false); + supportActionBar.setDisplayShowTitleEnabled(false); + } else { + inflater.inflate(R.menu.menu_channel, menu); + + if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "], inflater = [" + inflater + "]"); + menuRssButton = menu.findItem(R.id.menu_item_rss); + if (currentInfo != null) { + menuRssButton.setVisible(!TextUtils.isEmpty(currentInfo.feed_url)); + } - menuRssButton = menu.findItem(R.id.menu_item_rss); - if (currentInfo != null) { - menuRssButton.setVisible(!TextUtils.isEmpty(currentInfo.feed_url)); } - } @Override diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/feed/FeedFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/feed/FeedFragment.java index 2af9a9270..1a8f8e625 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/feed/FeedFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/feed/FeedFragment.java @@ -36,10 +36,8 @@ import io.reactivex.MaybeObserver; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Action; import io.reactivex.functions.Consumer; import io.reactivex.functions.Predicate; -import io.reactivex.schedulers.Schedulers; public class FeedFragment extends BaseListFragment, Void> { @@ -121,6 +119,11 @@ public class FeedFragment extends BaseListFragment, Voi if (supportActionBar != null) { supportActionBar.setTitle(R.string.fragment_whats_new); } + + if(useAsFrontPage) { + supportActionBar.setDisplayHomeAsUpEnabled(false); + supportActionBar.setDisplayShowTitleEnabled(false); + } } @Override 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 932cf2a44..3d019e6cb 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 @@ -52,7 +52,6 @@ import static org.schabi.newpipe.util.AnimationUtils.animateView; public class KioskFragment extends BaseListInfoFragment { - /*////////////////////////////////////////////////////////////////////////// // Views //////////////////////////////////////////////////////////////////////////*/ @@ -90,7 +89,7 @@ public class KioskFragment extends BaseListInfoFragment { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); ActionBar supportActionBar = activity.getSupportActionBar(); - if (supportActionBar != null) { + if (supportActionBar != null && useAsFrontPage) { supportActionBar.setDisplayShowTitleEnabled(false); supportActionBar.setDisplayHomeAsUpEnabled(false); } @@ -107,21 +106,6 @@ public class KioskFragment extends BaseListInfoFragment { return headerRootLayout; } - @Override - public void initListeners() { - // We have to override this because the default implementation of this function calls - // openVideoDetailFragment on getFragmentManager() but what we want here is - // getParentFragment().getFragmentManager() - infoListAdapter.setOnStreamSelectedListener(new InfoItemBuilder.OnInfoItemSelectedListener() { - @Override - public void selected(StreamInfoItem selectedItem) { - onItemSelected(selectedItem); - NavigationHelper.openVideoDetailFragment(getParentFragment().getFragmentManager(), - selectedItem.service_id, selectedItem.url, selectedItem.name); - } - }); - } - /*////////////////////////////////////////////////////////////////////////// // Load and handle //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 0164f584e..9b3ffb5ae 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -6,6 +6,7 @@ import android.support.v7.preference.Preference; import android.util.Log; import org.schabi.newpipe.R; +import org.schabi.newpipe.util.Constants; public class ContentSettingsFragment extends BasePreferenceFragment { @Override @@ -36,6 +37,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment { Preference pref = findPreference(getString(R.string.main_page_content_key)); pref.setSummary(name); + } }); selectChannelFragment.show(getFragmentManager(), "select_channel"); diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java index 5cc7070f9..16b68196a 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java @@ -66,7 +66,6 @@ public class SelectChannelFragment extends DialogFragment { onSelectedLisener = listener; } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.select_channel_fragment, container, false);