mirror of
https://github.com/yuliskov/SmartTube.git
synced 2026-01-08 06:50:28 -06:00
Channels: search field first step
This commit is contained in:
@@ -229,13 +229,15 @@ public abstract class ObjectAdapter {
|
||||
mObservable.unregisterAll();
|
||||
}
|
||||
|
||||
// MOD: remove final from some notify* methods
|
||||
|
||||
/**
|
||||
* Notifies UI that some items has changed.
|
||||
*
|
||||
* @param positionStart Starting position of the changed items.
|
||||
* @param itemCount Total number of items that changed.
|
||||
*/
|
||||
public final void notifyItemRangeChanged(int positionStart, int itemCount) {
|
||||
public void notifyItemRangeChanged(int positionStart, int itemCount) {
|
||||
mObservable.notifyItemRangeChanged(positionStart, itemCount);
|
||||
}
|
||||
|
||||
@@ -256,7 +258,7 @@ public abstract class ObjectAdapter {
|
||||
* @param positionStart Position where new items has been inserted.
|
||||
* @param itemCount Count of the new items has been inserted.
|
||||
*/
|
||||
final protected void notifyItemRangeInserted(int positionStart, int itemCount) {
|
||||
protected void notifyItemRangeInserted(int positionStart, int itemCount) {
|
||||
mObservable.notifyItemRangeInserted(positionStart, itemCount);
|
||||
}
|
||||
|
||||
@@ -266,7 +268,7 @@ public abstract class ObjectAdapter {
|
||||
* @param positionStart Starting position of the removed items.
|
||||
* @param itemCount Total number of items that has been removed.
|
||||
*/
|
||||
final protected void notifyItemRangeRemoved(int positionStart, int itemCount) {
|
||||
protected void notifyItemRangeRemoved(int positionStart, int itemCount) {
|
||||
mObservable.notifyItemRangeRemoved(positionStart, itemCount);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.liskovsoft.smartyoutubetv2.tv.adapter;
|
||||
|
||||
import androidx.leanback.widget.Presenter;
|
||||
import androidx.leanback.widget.PresenterSelector;
|
||||
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.data.VideoGroup;
|
||||
|
||||
public class HeaderVideoGroupObjectAdapter extends VideoGroupObjectAdapter {
|
||||
private Object mHeader;
|
||||
|
||||
public HeaderVideoGroupObjectAdapter(VideoGroup videoGroup, Presenter presenter) {
|
||||
super(videoGroup, presenter);
|
||||
}
|
||||
|
||||
public HeaderVideoGroupObjectAdapter(VideoGroup videoGroup, PresenterSelector presenter) {
|
||||
super(videoGroup, presenter);
|
||||
}
|
||||
|
||||
public HeaderVideoGroupObjectAdapter(Presenter presenter) {
|
||||
super(presenter);
|
||||
}
|
||||
|
||||
public HeaderVideoGroupObjectAdapter(PresenterSelector presenter) {
|
||||
super(presenter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return super.size() + (mHeader != null ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(int index) {
|
||||
if (index == 0 && mHeader != null) {
|
||||
return mHeader;
|
||||
}
|
||||
|
||||
return super.get(mHeader != null ? index - 1 : index);
|
||||
}
|
||||
|
||||
public void setHeader(Object header) {
|
||||
mHeader = header;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyItemRangeChanged(int positionStart, int itemCount) {
|
||||
super.notifyItemRangeChanged(mHeader != null ? positionStart + 1 : positionStart, itemCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyItemRangeInserted(int positionStart, int itemCount) {
|
||||
super.notifyItemRangeInserted(mHeader != null ? positionStart + 1 : positionStart, itemCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyItemRangeRemoved(int positionStart, int itemCount) {
|
||||
super.notifyItemRangeRemoved(mHeader != null ? positionStart + 1 : positionStart, itemCount);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package com.liskovsoft.smartyoutubetv2.tv.adapter;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.leanback.widget.ObjectAdapter;
|
||||
import androidx.leanback.widget.Presenter;
|
||||
import androidx.leanback.widget.PresenterSelector;
|
||||
|
||||
import com.liskovsoft.sharedutils.helpers.Helpers;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.data.Video;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.data.VideoGroup;
|
||||
@@ -13,38 +15,50 @@ import java.util.List;
|
||||
|
||||
public class VideoGroupObjectAdapter extends ObjectAdapter {
|
||||
private static final String TAG = VideoGroupObjectAdapter.class.getSimpleName();
|
||||
private final List<Video> mVideoItems;
|
||||
private final List<Video> mVideoItems = new ArrayList<Video>() {
|
||||
@Override
|
||||
public boolean addAll(@NonNull Collection<? extends Video> c) {
|
||||
// TODO: remove the hack someday.
|
||||
// Dirty hack for avoiding group duplication.
|
||||
// Duplicated items suddenly appeared in Home, Subscriptions and History.
|
||||
|
||||
// Another alt method.
|
||||
if (size() > 0 && size() < CHECK_MAX_SIZE) {
|
||||
Helpers.removeIf(c, this::contains);
|
||||
}
|
||||
|
||||
return super.addAll(c);
|
||||
}
|
||||
};
|
||||
private final List<VideoGroup> mVideoGroups = new ArrayList<>(); // keep groups from being garbage collected
|
||||
private static final int CHECK_MAX_SIZE = 200;
|
||||
|
||||
public VideoGroupObjectAdapter(VideoGroup videoGroup, Presenter presenter) {
|
||||
super(presenter);
|
||||
//mVideoItems = new ArrayList<>();
|
||||
mVideoItems = new ArrayList<Video>() {
|
||||
@Override
|
||||
public boolean addAll(@NonNull Collection<? extends Video> c) {
|
||||
// TODO: remove the hack someday.
|
||||
// Dirty hack for avoiding group duplication.
|
||||
// Duplicated items suddenly appeared in Home, Subscriptions and History.
|
||||
|
||||
// Another alt method.
|
||||
if (size() > 0 && size() < CHECK_MAX_SIZE) {
|
||||
Helpers.removeIf(c, this::contains);
|
||||
}
|
||||
initData(videoGroup);
|
||||
}
|
||||
|
||||
return super.addAll(c);
|
||||
}
|
||||
};
|
||||
public VideoGroupObjectAdapter(VideoGroup videoGroup, PresenterSelector presenter) {
|
||||
super(presenter);
|
||||
|
||||
if (videoGroup != null) {
|
||||
append(videoGroup);
|
||||
}
|
||||
initData(videoGroup);
|
||||
}
|
||||
|
||||
public VideoGroupObjectAdapter(Presenter presenter) {
|
||||
this(null, presenter);
|
||||
}
|
||||
|
||||
public VideoGroupObjectAdapter(PresenterSelector presenter) {
|
||||
this(null, presenter);
|
||||
}
|
||||
|
||||
private void initData(VideoGroup videoGroup) {
|
||||
if (videoGroup != null) {
|
||||
append(videoGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return mVideoItems.size();
|
||||
@@ -52,7 +66,7 @@ public class VideoGroupObjectAdapter extends ObjectAdapter {
|
||||
|
||||
@Override
|
||||
public Object get(int index) {
|
||||
if (index < 0 || index >= size()) {
|
||||
if (index < 0 || index >= mVideoItems.size()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.liskovsoft.smartyoutubetv2.tv.presenter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.leanback.widget.Presenter;
|
||||
|
||||
public class SearchBarPresenter extends Presenter {
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent) {
|
||||
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
||||
View contentView = inflater.inflate(com.liskovsoft.smartyoutubetv2.common.R.layout.simple_edit_dialog, null);
|
||||
|
||||
return new ViewHolder(contentView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder viewHolder, Object item) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnbindViewHolder(ViewHolder viewHolder) {
|
||||
|
||||
}
|
||||
|
||||
public static class Data {
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.leanback.widget.ClassPresenterSelector;
|
||||
import androidx.leanback.widget.OnItemViewClickedListener;
|
||||
import androidx.leanback.widget.OnItemViewSelectedListener;
|
||||
import androidx.leanback.widget.Presenter;
|
||||
@@ -18,7 +19,9 @@ import com.liskovsoft.smartyoutubetv2.common.app.presenters.interfaces.VideoGrou
|
||||
import com.liskovsoft.smartyoutubetv2.common.prefs.MainUIData;
|
||||
import com.liskovsoft.smartyoutubetv2.common.misc.TickleManager;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.R;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.adapter.HeaderVideoGroupObjectAdapter;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.adapter.VideoGroupObjectAdapter;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.presenter.SearchBarPresenter;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.presenter.VideoCardPresenter;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.presenter.ChannelCardPresenter;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.presenter.CustomVerticalGridPresenter;
|
||||
@@ -35,7 +38,7 @@ import java.util.List;
|
||||
|
||||
public class MultiVideoGridFragment extends MultiGridFragment implements VideoSection {
|
||||
private static final String TAG = MultiVideoGridFragment.class.getSimpleName();
|
||||
private VideoGroupObjectAdapter mGridAdapter1;
|
||||
private HeaderVideoGroupObjectAdapter mGridAdapter1;
|
||||
private VideoGroupObjectAdapter mGridAdapter2;
|
||||
private final List<VideoGroup> mPendingUpdates1 = new ArrayList<>();
|
||||
private final List<VideoGroup> mPendingUpdates2 = new ArrayList<>();
|
||||
@@ -182,7 +185,11 @@ public class MultiVideoGridFragment extends MultiGridFragment implements VideoSe
|
||||
setGridPresenter2(presenter2);
|
||||
|
||||
if (mGridAdapter1 == null) {
|
||||
mGridAdapter1 = new VideoGroupObjectAdapter(mCardPresenter1);
|
||||
ClassPresenterSelector presenterSelector = new ClassPresenterSelector();
|
||||
presenterSelector.addClassPresenter(Video.class, mCardPresenter1);
|
||||
presenterSelector.addClassPresenter(SearchBarPresenter.Data.class, new SearchBarPresenter());
|
||||
|
||||
mGridAdapter1 = new HeaderVideoGroupObjectAdapter(presenterSelector);
|
||||
setAdapter1(mGridAdapter1);
|
||||
}
|
||||
|
||||
@@ -270,24 +277,29 @@ public class MultiVideoGridFragment extends MultiGridFragment implements VideoSe
|
||||
}
|
||||
}
|
||||
|
||||
private void clear1() {
|
||||
if (mGridAdapter1 != null) {
|
||||
mGridAdapter1.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
clear1();
|
||||
clear2();
|
||||
}
|
||||
|
||||
private void clear1() {
|
||||
if (mGridAdapter1 != null) {
|
||||
mGridAdapter1.clear();
|
||||
//addSearchHeader();
|
||||
}
|
||||
}
|
||||
|
||||
private void clear2() {
|
||||
if (mGridAdapter2 != null) {
|
||||
mGridAdapter2.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void addSearchHeader() {
|
||||
mGridAdapter1.setHeader(new SearchBarPresenter.Data());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return isEmpty1() && isEmpty2();
|
||||
|
||||
Reference in New Issue
Block a user