Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feed group main-page tab #3556

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class SelectChannelFragment extends DialogFragment {

private final ImageLoader imageLoader = ImageLoader.getInstance();

private OnSelectedLisener onSelectedLisener = null;
private OnSelectedListener onSelectedListener = null;
private OnCancelListener onCancelListener = null;

private ProgressBar progressBar;
Expand All @@ -71,8 +71,8 @@ public class SelectChannelFragment extends DialogFragment {

private List<SubscriptionEntity> subscriptions = new Vector<>();

public void setOnSelectedLisener(final OnSelectedLisener listener) {
onSelectedLisener = listener;
public void setOnSelectedListener(final OnSelectedListener listener) {
onSelectedListener = listener;
}

public void setOnCancelListener(final OnCancelListener listener) {
Expand Down Expand Up @@ -121,9 +121,9 @@ public void onCancel(final DialogInterface dialogInterface) {
}

private void clickedItem(final int position) {
if (onSelectedLisener != null) {
if (onSelectedListener != null) {
SubscriptionEntity entry = subscriptions.get(position);
onSelectedLisener
onSelectedListener
.onChannelSelected(entry.getServiceId(), entry.getUrl(), entry.getName());
}
dismiss();
Expand Down Expand Up @@ -178,7 +178,7 @@ protected void onError(final Throwable e) {
// Interfaces
//////////////////////////////////////////////////////////////////////////*/

public interface OnSelectedLisener {
public interface OnSelectedListener {
void onChannelSelected(int serviceId, String url, String name);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
package org.schabi.newpipe.settings;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.schabi.newpipe.R;
import org.schabi.newpipe.database.feed.model.FeedGroupEntity;
import org.schabi.newpipe.local.feed.FeedDatabaseManager;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;

import java.util.List;
import java.util.Vector;

import io.reactivex.disposables.Disposable;

/**
* Created by Christian Schabesberger on 26.09.17.
* SelectChannelFragment.java is part of NewPipe.
* <p>
* NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* </p>
* <p>
* NewPipe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* </p>
* <p>
* You should have received a copy of the GNU General Public License
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
* </p>
*/

public class SelectFeedGroupFragment extends DialogFragment {
private OnSelectedListener onSelectedListener = null;
private OnCancelListener onCancelListener = null;

private ProgressBar progressBar;
private TextView emptyView;
private RecyclerView recyclerView;

private List<FeedGroupEntity> feedGroups = new Vector<>();
private Disposable feedGroupsSubscriber;

public void setOnSelectedListener(final OnSelectedListener listener) {
onSelectedListener = listener;
}

public void setOnCancelListener(final OnCancelListener listener) {
onCancelListener = listener;
}

/*//////////////////////////////////////////////////////////////////////////
// Fragment's Lifecycle
//////////////////////////////////////////////////////////////////////////*/

@Override
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {
final View v = inflater.inflate(
R.layout.select_feed_group_fragment, container, false);
recyclerView = v.findViewById(R.id.items_list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
SelectFeedGroupAdapter channelAdapter = new SelectFeedGroupAdapter();
recyclerView.setAdapter(channelAdapter);

progressBar = v.findViewById(R.id.progressBar);
emptyView = v.findViewById(R.id.empty_state_view);
progressBar.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
emptyView.setVisibility(View.GONE);

final FeedDatabaseManager feedDatabaseManager = new FeedDatabaseManager(getContext());
feedGroupsSubscriber = feedDatabaseManager.groups().toObservable()
.subscribe(this::displayFeedGroups, this::onError);

return v;
}

@Override
public void onDestroy() {
super.onDestroy();

if (feedGroupsSubscriber != null) {
feedGroupsSubscriber.dispose();
feedGroupsSubscriber = null;
}
}

/*//////////////////////////////////////////////////////////////////////////
// Handle actions
//////////////////////////////////////////////////////////////////////////*/

@Override
public void onCancel(final DialogInterface dialogInterface) {
super.onCancel(dialogInterface);
if (onCancelListener != null) {
onCancelListener.onCancel();
}
}

private void clickedItem(final int position) {
if (onSelectedListener != null) {
FeedGroupEntity entry = feedGroups.get(position);
onSelectedListener
.onFeedGroupSelected(entry.getUid(), entry.getName(),
entry.getIcon().getDrawableResourceAttr());
}
dismiss();
}

/*//////////////////////////////////////////////////////////////////////////
// Item handling
//////////////////////////////////////////////////////////////////////////*/

private void displayFeedGroups(final List<FeedGroupEntity> newFeedGroups) {
this.feedGroups = newFeedGroups;
progressBar.setVisibility(View.GONE);
if (newFeedGroups.isEmpty()) {
emptyView.setVisibility(View.VISIBLE);
return;
}

recyclerView.setVisibility(View.VISIBLE);
}

/*//////////////////////////////////////////////////////////////////////////
// Error
//////////////////////////////////////////////////////////////////////////*/

protected void onError(final Throwable e) {
final Activity activity = getActivity();
ErrorActivity.reportError(activity, e, activity.getClass(), null, ErrorActivity.ErrorInfo
.make(UserAction.UI_ERROR, "none", "", R.string.app_ui_crash));
}

/*//////////////////////////////////////////////////////////////////////////
// Interfaces
//////////////////////////////////////////////////////////////////////////*/

public interface OnSelectedListener {
void onFeedGroupSelected(long id, String name, int thumbnailId);
}

public interface OnCancelListener {
void onCancel();
}

private class SelectFeedGroupAdapter
extends RecyclerView.Adapter<SelectFeedGroupAdapter.SelectFeedGroupItemHolder> {
@Override
public SelectFeedGroupItemHolder onCreateViewHolder(final ViewGroup parent,
final int viewType) {
final View item = LayoutInflater.from(parent.getContext())
.inflate(R.layout.select_feed_group_item, parent, false);

return new SelectFeedGroupItemHolder(item);
}

@Override
public void onBindViewHolder(final SelectFeedGroupItemHolder holder, final int position) {
final FeedGroupEntity entry = feedGroups.get(position);
holder.titleView.setText(entry.getName());
holder.view.setOnClickListener(view -> clickedItem(position));

final Context context = SelectFeedGroupFragment.this.getContext();
holder.thumbnailView.setImageResource(entry.getIcon().getDrawableRes(context));
}

@Override
public int getItemCount() {
return feedGroups.size();
}

public class SelectFeedGroupItemHolder extends RecyclerView.ViewHolder {
public final View view;
final ImageView thumbnailView;
final TextView titleView;

SelectFeedGroupItemHolder(final View v) {
super(v);
this.view = v;
thumbnailView = v.findViewById(R.id.itemThumbnailView);
titleView = v.findViewById(R.id.itemTitleView);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public class SelectKioskFragment extends DialogFragment {
private RecyclerView recyclerView = null;
private SelectKioskAdapter selectKioskAdapter = null;

private OnSelectedLisener onSelectedLisener = null;
private OnSelectedListener onSelectedListener = null;
private OnCancelListener onCancelListener = null;

public void setOnSelectedLisener(final OnSelectedLisener listener) {
onSelectedLisener = listener;
public void setOnSelectedListener(final OnSelectedListener listener) {
onSelectedListener = listener;
}

public void setOnCancelListener(final OnCancelListener listener) {
Expand Down Expand Up @@ -90,8 +90,8 @@ public void onCancel(final DialogInterface dialogInterface) {
}

private void clickedItem(final SelectKioskAdapter.Entry entry) {
if (onSelectedLisener != null) {
onSelectedLisener.onKioskSelected(entry.serviceId, entry.kioskId, entry.kioskName);
if (onSelectedListener != null) {
onSelectedListener.onKioskSelected(entry.serviceId, entry.kioskId, entry.kioskName);
}
dismiss();
}
Expand All @@ -110,7 +110,7 @@ protected void onError(final Throwable e) {
// Interfaces
//////////////////////////////////////////////////////////////////////////*/

public interface OnSelectedLisener {
public interface OnSelectedListener {
void onKioskSelected(int serviceId, String kioskId, String kioskName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.settings.SelectChannelFragment;
import org.schabi.newpipe.settings.SelectFeedGroupFragment;
import org.schabi.newpipe.settings.SelectKioskFragment;
import org.schabi.newpipe.settings.tabs.AddTabDialog.ChooseTabListItem;
import org.schabi.newpipe.util.ThemeHelper;
Expand All @@ -48,7 +49,7 @@ public class ChooseTabsFragment extends Fragment {

private TabsManager tabsManager;

private List<Tab> tabList = new ArrayList<>();
private final List<Tab> tabList = new ArrayList<>();
private ChooseTabsFragment.SelectedTabsAdapter selectedTabsAdapter;

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -78,10 +79,10 @@ public void onViewCreated(@NonNull final View rootView,

initButton(rootView);

RecyclerView listSelectedTabs = rootView.findViewById(R.id.selectedTabs);
final RecyclerView listSelectedTabs = rootView.findViewById(R.id.selectedTabs);
listSelectedTabs.setLayoutManager(new LinearLayoutManager(requireContext()));

ItemTouchHelper itemTouchHelper = new ItemTouchHelper(getItemTouchCallback());
final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(getItemTouchCallback());
itemTouchHelper.attachToRecyclerView(listSelectedTabs);

selectedTabsAdapter = new SelectedTabsAdapter(requireContext(), itemTouchHelper);
Expand Down Expand Up @@ -138,7 +139,7 @@ private void updateTabList() {

private void updateTitle() {
if (getActivity() instanceof AppCompatActivity) {
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
final ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(R.string.main_page_content);
}
Expand Down Expand Up @@ -201,16 +202,22 @@ private void addTab(final int tabId) {
switch (type) {
case KIOSK:
SelectKioskFragment selectKioskFragment = new SelectKioskFragment();
selectKioskFragment.setOnSelectedLisener((serviceId, kioskId, kioskName) ->
selectKioskFragment.setOnSelectedListener((serviceId, kioskId, kioskName) ->
addTab(new Tab.KioskTab(serviceId, kioskId)));
selectKioskFragment.show(requireFragmentManager(), "select_kiosk");
return;
case CHANNEL:
SelectChannelFragment selectChannelFragment = new SelectChannelFragment();
selectChannelFragment.setOnSelectedLisener((serviceId, url, name) ->
selectChannelFragment.setOnSelectedListener((serviceId, url, name) ->
addTab(new Tab.ChannelTab(serviceId, url, name)));
selectChannelFragment.show(requireFragmentManager(), "select_channel");
return;
case FEED_GROUP:
SelectFeedGroupFragment selectFeedGroupFragment = new SelectFeedGroupFragment();
selectFeedGroupFragment.setOnSelectedListener((id, name, thumbnailId) ->
addTab(new Tab.FeedGroupTab(id, name, thumbnailId)));
selectFeedGroupFragment.show(requireFragmentManager(), "select_feed_group");
return;
default:
addTab(type.getTab());
break;
Expand Down Expand Up @@ -247,6 +254,11 @@ private ChooseTabListItem[] getAvailableTabs(final Context context) {
ThemeHelper.resolveResourceIdFromAttr(context, R.attr.ic_hot)));
}
break;
case FEED_GROUP:
returnList.add(new ChooseTabListItem(tab.getTabId(),
getString(R.string.feed_group_page_summary),
ThemeHelper.resolveResourceIdFromAttr(context, R.attr.rss)));
break;
default:
if (!tabList.contains(tab)) {
returnList.add(new ChooseTabListItem(context, tab));
Expand Down Expand Up @@ -336,7 +348,7 @@ public void swapItems(final int fromPosition, final int toPosition) {
@Override
public ChooseTabsFragment.SelectedTabsAdapter.TabViewHolder onCreateViewHolder(
@NonNull final ViewGroup parent, final int viewType) {
View view = inflater.inflate(R.layout.list_choose_tabs, parent, false);
final View view = inflater.inflate(R.layout.list_choose_tabs, parent, false);
return new ChooseTabsFragment.SelectedTabsAdapter.TabViewHolder(view);
}

Expand Down
Loading