1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-24 17:10:33 +00:00

made fragments frontpagable

This commit is contained in:
Christian Schabesberger 2017-09-26 18:16:39 +02:00
parent 65c8b6e66a
commit 3490273b49
8 changed files with 54 additions and 33 deletions

View File

@ -50,6 +50,8 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
protected Button errorButtonRetry; protected Button errorButtonRetry;
protected TextView errorTextView; protected TextView errorTextView;
protected boolean useAsFrontPage = false;
@Override @Override
public void onViewCreated(View rootView, Bundle savedInstanceState) { public void onViewCreated(View rootView, Bundle savedInstanceState) {
super.onViewCreated(rootView, savedInstanceState); super.onViewCreated(rootView, savedInstanceState);
@ -62,6 +64,10 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
wasLoading.set(isLoading.get()); wasLoading.set(isLoading.get());
} }
public void useAsFrontPage(boolean value) {
useAsFrontPage = value;
}
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Init // Init
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/

View File

@ -1,5 +1,6 @@
package org.schabi.newpipe.fragments; package org.schabi.newpipe.fragments;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
@ -19,6 +20,8 @@ import android.view.ViewGroup;
import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.BaseFragment;
import org.schabi.newpipe.R; 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.list.kiosk.KioskFragment;
import org.schabi.newpipe.fragments.subscription.SubscriptionFragment; import org.schabi.newpipe.fragments.subscription.SubscriptionFragment;
import org.schabi.newpipe.report.ErrorActivity; 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))) { if(set_main_page.equals(getString(R.string.blank_page_key))) {
return new BlankFragment(); return new BlankFragment();
} else if(set_main_page.equals(getString(R.string.kiosk_page_key))) { } 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))) { } 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))) { } 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 { } else {
return new BlankFragment(); return new BlankFragment();
} }
} catch (Exception e) { } catch (Exception e) {
ErrorActivity.reportError(activity, e, ErrorActivity.reportError(activity, e,
activity.getClass(), activity.getClass(),

View File

@ -135,7 +135,9 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I> implem
@Override @Override
public void selected(StreamInfoItem selectedItem) { public void selected(StreamInfoItem selectedItem) {
onItemSelected(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<I, N> extends BaseStateFragment<I> implem
@Override @Override
public void selected(ChannelInfoItem selectedItem) { public void selected(ChannelInfoItem selectedItem) {
onItemSelected(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<I, N> extends BaseStateFragment<I> implem
@Override @Override
public void selected(PlaylistInfoItem selectedItem) { public void selected(PlaylistInfoItem selectedItem) {
onItemSelected(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);
} }
}); });

View File

@ -7,6 +7,7 @@ import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -118,15 +119,21 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (DEBUG) Log.d(TAG, "onCreateOptionsMenu() called with: menu = [" + menu + "], inflater = [" + inflater + "]");
super.onCreateOptionsMenu(menu, 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 @Override

View File

@ -36,10 +36,8 @@ import io.reactivex.MaybeObserver;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer; import io.reactivex.functions.Consumer;
import io.reactivex.functions.Predicate; import io.reactivex.functions.Predicate;
import io.reactivex.schedulers.Schedulers;
public class FeedFragment extends BaseListFragment<List<SubscriptionEntity>, Void> { public class FeedFragment extends BaseListFragment<List<SubscriptionEntity>, Void> {
@ -121,6 +119,11 @@ public class FeedFragment extends BaseListFragment<List<SubscriptionEntity>, Voi
if (supportActionBar != null) { if (supportActionBar != null) {
supportActionBar.setTitle(R.string.fragment_whats_new); supportActionBar.setTitle(R.string.fragment_whats_new);
} }
if(useAsFrontPage) {
supportActionBar.setDisplayHomeAsUpEnabled(false);
supportActionBar.setDisplayShowTitleEnabled(false);
}
} }
@Override @Override

View File

@ -52,7 +52,6 @@ import static org.schabi.newpipe.util.AnimationUtils.animateView;
public class KioskFragment extends BaseListInfoFragment<KioskInfo> { public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Views // Views
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
@ -90,7 +89,7 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
ActionBar supportActionBar = activity.getSupportActionBar(); ActionBar supportActionBar = activity.getSupportActionBar();
if (supportActionBar != null) { if (supportActionBar != null && useAsFrontPage) {
supportActionBar.setDisplayShowTitleEnabled(false); supportActionBar.setDisplayShowTitleEnabled(false);
supportActionBar.setDisplayHomeAsUpEnabled(false); supportActionBar.setDisplayHomeAsUpEnabled(false);
} }
@ -107,21 +106,6 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
return headerRootLayout; 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<StreamInfoItem>() {
@Override
public void selected(StreamInfoItem selectedItem) {
onItemSelected(selectedItem);
NavigationHelper.openVideoDetailFragment(getParentFragment().getFragmentManager(),
selectedItem.service_id, selectedItem.url, selectedItem.name);
}
});
}
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Load and handle // Load and handle
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/

View File

@ -6,6 +6,7 @@ import android.support.v7.preference.Preference;
import android.util.Log; import android.util.Log;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.util.Constants;
public class ContentSettingsFragment extends BasePreferenceFragment { public class ContentSettingsFragment extends BasePreferenceFragment {
@Override @Override
@ -36,6 +37,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
Preference pref = findPreference(getString(R.string.main_page_content_key)); Preference pref = findPreference(getString(R.string.main_page_content_key));
pref.setSummary(name); pref.setSummary(name);
} }
}); });
selectChannelFragment.show(getFragmentManager(), "select_channel"); selectChannelFragment.show(getFragmentManager(), "select_channel");

View File

@ -66,7 +66,6 @@ public class SelectChannelFragment extends DialogFragment {
onSelectedLisener = listener; onSelectedLisener = listener;
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.select_channel_fragment, container, false); View v = inflater.inflate(R.layout.select_channel_fragment, container, false);