Skip to content

Commit d3cd3d6

Browse files
committed
Tried to repair #4475 and #3368
* Always recreate the footer so that it's not possible to attach the same instance twice * Removed support for creating a custom footer as it's never used * Supply the header with an supplier * This might not fix the problem completely as we currently can only create the header once inside Channel, Playlist and RelatedItems-Fragment - allowing creation of multiple headers might be done in the future if the issues still arise * Other minor fixes
1 parent 91c67b0 commit d3cd3d6

5 files changed

Lines changed: 78 additions & 78 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
import androidx.preference.PreferenceManager;
1818
import androidx.recyclerview.widget.GridLayoutManager;
1919
import androidx.recyclerview.widget.RecyclerView;
20-
import androidx.viewbinding.ViewBinding;
2120

2221
import org.schabi.newpipe.R;
23-
import org.schabi.newpipe.databinding.PignateFooterBinding;
2422
import org.schabi.newpipe.error.ErrorUtil;
2523
import org.schabi.newpipe.extractor.InfoItem;
2624
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
@@ -44,6 +42,7 @@
4442
import java.util.Arrays;
4543
import java.util.List;
4644
import java.util.Queue;
45+
import java.util.function.Supplier;
4746

4847
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
4948
import static org.schabi.newpipe.ktx.ViewUtils.animate;
@@ -215,14 +214,10 @@ public void onStart() {
215214
//////////////////////////////////////////////////////////////////////////*/
216215

217216
@Nullable
218-
protected ViewBinding getListHeader() {
217+
protected Supplier<View> getListHeaderSupplier() {
219218
return null;
220219
}
221220

222-
protected ViewBinding getListFooter() {
223-
return PignateFooterBinding.inflate(activity.getLayoutInflater(), itemsList, false);
224-
}
225-
226221
protected RecyclerView.LayoutManager getListLayoutManager() {
227222
return new SuperScrollLayoutManager(activity);
228223
}
@@ -247,11 +242,10 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) {
247242
itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager());
248243

249244
infoListAdapter.setUseGridVariant(useGrid);
250-
infoListAdapter.setFooter(getListFooter().getRoot());
251245

252-
final ViewBinding listHeader = getListHeader();
253-
if (listHeader != null) {
254-
infoListAdapter.setHeader(listHeader.getRoot());
246+
final Supplier<View> listHeaderSupplier = getListHeaderSupplier();
247+
if (listHeaderSupplier != null) {
248+
infoListAdapter.setHeaderSupplier(listHeaderSupplier);
255249
}
256250

257251
itemsList.setAdapter(infoListAdapter);
@@ -447,7 +441,7 @@ protected void ifMoreItemsLoadableLoadUntilScrollable(final int recursiveCallCou
447441
if (itemsList.canScrollVertically(1)
448442
|| itemsList.canScrollVertically(-1)) {
449443
if (DEBUG) {
450-
Log.d(TAG, "loadEnoughInitial - OK: itemList is scrollable");
444+
Log.d(TAG, "loadEnoughInitialData - OK: itemList is scrollable");
451445
}
452446
return;
453447
}

app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.schabi.newpipe.fragments.list.channel;
22

3+
import static org.schabi.newpipe.ktx.TextViewUtils.animateTextColor;
4+
import static org.schabi.newpipe.ktx.ViewUtils.animate;
5+
import static org.schabi.newpipe.ktx.ViewUtils.animateBackgroundColor;
6+
37
import android.content.Context;
48
import android.os.Bundle;
59
import android.text.TextUtils;
@@ -17,7 +21,6 @@
1721
import androidx.annotation.Nullable;
1822
import androidx.appcompat.app.ActionBar;
1923
import androidx.core.content.ContextCompat;
20-
import androidx.viewbinding.ViewBinding;
2124

2225
import com.jakewharton.rxbinding4.view.RxView;
2326

@@ -29,7 +32,6 @@
2932
import org.schabi.newpipe.error.ErrorInfo;
3033
import org.schabi.newpipe.error.ErrorUtil;
3134
import org.schabi.newpipe.error.UserAction;
32-
import org.schabi.newpipe.extractor.InfoItem;
3335
import org.schabi.newpipe.extractor.ListExtractor;
3436
import org.schabi.newpipe.extractor.channel.ChannelInfo;
3537
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
@@ -43,13 +45,14 @@
4345
import org.schabi.newpipe.util.ExtractorHelper;
4446
import org.schabi.newpipe.util.Localization;
4547
import org.schabi.newpipe.util.NavigationHelper;
46-
import org.schabi.newpipe.util.external_communication.ShareUtils;
4748
import org.schabi.newpipe.util.PicassoHelper;
4849
import org.schabi.newpipe.util.ThemeHelper;
50+
import org.schabi.newpipe.util.external_communication.ShareUtils;
4951

50-
import java.util.ArrayList;
5152
import java.util.List;
5253
import java.util.concurrent.TimeUnit;
54+
import java.util.function.Supplier;
55+
import java.util.stream.Collectors;
5356

5457
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
5558
import io.reactivex.rxjava3.core.Observable;
@@ -61,10 +64,6 @@
6164
import io.reactivex.rxjava3.functions.Function;
6265
import io.reactivex.rxjava3.schedulers.Schedulers;
6366

64-
import static org.schabi.newpipe.ktx.TextViewUtils.animateTextColor;
65-
import static org.schabi.newpipe.ktx.ViewUtils.animate;
66-
import static org.schabi.newpipe.ktx.ViewUtils.animateBackgroundColor;
67-
6867
public class ChannelFragment extends BaseListInfoFragment<ChannelInfo>
6968
implements View.OnClickListener {
7069

@@ -145,12 +144,12 @@ public void onDestroy() {
145144
//////////////////////////////////////////////////////////////////////////*/
146145

147146
@Override
148-
protected ViewBinding getListHeader() {
147+
protected Supplier<View> getListHeaderSupplier() {
149148
headerBinding = ChannelHeaderBinding
150149
.inflate(activity.getLayoutInflater(), itemsList, false);
151150
playlistControlBinding = headerBinding.playlistControl;
152151

153-
return headerBinding;
152+
return headerBinding::getRoot;
154153
}
155154

156155
@Override

app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.schabi.newpipe.fragments.list.playlist;
22

3+
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
4+
import static org.schabi.newpipe.ktx.ViewUtils.animate;
5+
import static org.schabi.newpipe.ktx.ViewUtils.animateHideRecyclerViewAllowingScrolling;
6+
37
import android.app.Activity;
48
import android.content.Context;
59
import android.os.Bundle;
@@ -15,7 +19,6 @@
1519
import androidx.annotation.NonNull;
1620
import androidx.annotation.Nullable;
1721
import androidx.appcompat.content.res.AppCompatResources;
18-
import androidx.viewbinding.ViewBinding;
1922

2023
import org.reactivestreams.Subscriber;
2124
import org.reactivestreams.Subscription;
@@ -42,28 +45,25 @@
4245
import org.schabi.newpipe.player.playqueue.PlayQueue;
4346
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue;
4447
import org.schabi.newpipe.util.ExtractorHelper;
45-
import org.schabi.newpipe.util.PicassoHelper;
46-
import org.schabi.newpipe.util.external_communication.KoreUtils;
4748
import org.schabi.newpipe.util.Localization;
4849
import org.schabi.newpipe.util.NavigationHelper;
49-
import org.schabi.newpipe.util.external_communication.ShareUtils;
50+
import org.schabi.newpipe.util.PicassoHelper;
5051
import org.schabi.newpipe.util.StreamDialogEntry;
52+
import org.schabi.newpipe.util.external_communication.KoreUtils;
53+
import org.schabi.newpipe.util.external_communication.ShareUtils;
5154

5255
import java.util.ArrayList;
5356
import java.util.Arrays;
5457
import java.util.List;
5558
import java.util.concurrent.atomic.AtomicBoolean;
59+
import java.util.function.Supplier;
5660

5761
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
5862
import io.reactivex.rxjava3.core.Flowable;
5963
import io.reactivex.rxjava3.core.Single;
6064
import io.reactivex.rxjava3.disposables.CompositeDisposable;
6165
import io.reactivex.rxjava3.disposables.Disposable;
6266

63-
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
64-
import static org.schabi.newpipe.ktx.ViewUtils.animate;
65-
import static org.schabi.newpipe.ktx.ViewUtils.animateHideRecyclerViewAllowingScrolling;
66-
6767
public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
6868

6969
private static final String PICASSO_PLAYLIST_TAG = "PICASSO_PLAYLIST_TAG";
@@ -120,12 +120,12 @@ public View onCreateView(@NonNull final LayoutInflater inflater,
120120
//////////////////////////////////////////////////////////////////////////*/
121121

122122
@Override
123-
protected ViewBinding getListHeader() {
123+
protected Supplier<View> getListHeaderSupplier() {
124124
headerBinding = PlaylistHeaderBinding
125125
.inflate(activity.getLayoutInflater(), itemsList, false);
126126
playlistControlBinding = headerBinding.playlistControl;
127127

128-
return headerBinding;
128+
return headerBinding::getRoot;
129129
}
130130

131131
@Override

app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedItemsFragment.java

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.schabi.newpipe.fragments.list.videos;
22

3-
import android.content.Context;
43
import android.content.SharedPreferences;
54
import android.os.Bundle;
65
import android.view.LayoutInflater;
@@ -12,7 +11,6 @@
1211
import androidx.annotation.NonNull;
1312
import androidx.annotation.Nullable;
1413
import androidx.preference.PreferenceManager;
15-
import androidx.viewbinding.ViewBinding;
1614

1715
import org.schabi.newpipe.R;
1816
import org.schabi.newpipe.databinding.RelatedItemsHeaderBinding;
@@ -24,6 +22,7 @@
2422
import org.schabi.newpipe.util.RelatedItemInfo;
2523

2624
import java.io.Serializable;
25+
import java.util.function.Supplier;
2726

2827
import io.reactivex.rxjava3.core.Single;
2928

@@ -60,32 +59,30 @@ public View onCreateView(@NonNull final LayoutInflater inflater,
6059
return inflater.inflate(R.layout.fragment_related_items, container, false);
6160
}
6261

63-
@Override
64-
}
65-
6662
@Override
6763
public void onDestroyView() {
6864
headerBinding = null;
6965
super.onDestroyView();
7066
}
7167

7268
@Override
73-
protected ViewBinding getListHeader() {
74-
if (relatedItemInfo != null && relatedItemInfo.getRelatedItems() != null) {
75-
headerBinding = RelatedItemsHeaderBinding
76-
.inflate(activity.getLayoutInflater(), itemsList, false);
77-
78-
final SharedPreferences pref = PreferenceManager
79-
.getDefaultSharedPreferences(requireContext());
80-
final boolean autoplay = pref.getBoolean(getString(R.string.auto_queue_key), false);
81-
headerBinding.autoplaySwitch.setChecked(autoplay);
82-
headerBinding.autoplaySwitch.setOnCheckedChangeListener((compoundButton, b) ->
83-
PreferenceManager.getDefaultSharedPreferences(requireContext()).edit()
84-
.putBoolean(getString(R.string.auto_queue_key), b).apply());
85-
return headerBinding;
86-
} else {
69+
protected Supplier<View> getListHeaderSupplier() {
70+
if (relatedItemInfo == null || relatedItemInfo.getRelatedItems() == null) {
8771
return null;
8872
}
73+
74+
headerBinding = RelatedItemsHeaderBinding
75+
.inflate(activity.getLayoutInflater(), itemsList, false);
76+
77+
final SharedPreferences pref = PreferenceManager
78+
.getDefaultSharedPreferences(requireContext());
79+
final boolean autoplay = pref.getBoolean(getString(R.string.auto_queue_key), false);
80+
headerBinding.autoplaySwitch.setChecked(autoplay);
81+
headerBinding.autoplaySwitch.setOnCheckedChangeListener((compoundButton, b) ->
82+
PreferenceManager.getDefaultSharedPreferences(requireContext()).edit()
83+
.putBoolean(getString(R.string.auto_queue_key), b).apply());
84+
85+
return headerBinding::getRoot;
8986
}
9087

9188
@Override
@@ -161,11 +158,10 @@ protected void onRestoreInstanceState(@NonNull final Bundle savedState) {
161158
@Override
162159
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
163160
final String s) {
164-
final SharedPreferences pref =
165-
PreferenceManager.getDefaultSharedPreferences(requireContext());
166-
final boolean autoplay = pref.getBoolean(getString(R.string.auto_queue_key), false);
167161
if (headerBinding != null) {
168-
headerBinding.autoplaySwitch.setChecked(autoplay);
162+
headerBinding.autoplaySwitch.setChecked(
163+
sharedPreferences.getBoolean(
164+
getString(R.string.auto_queue_key), false));
169165
}
170166
}
171167

0 commit comments

Comments
 (0)