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 a40ff1bf3..02c7a4818 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 @@ -12,13 +12,16 @@ import android.view.MenuInflater; import android.view.View; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import androidx.viewbinding.ViewBinding; import org.schabi.newpipe.R; +import org.schabi.newpipe.databinding.PignateFooterBinding; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.comments.CommentsInfoItem; @@ -215,12 +218,13 @@ public abstract class BaseListFragment extends BaseStateFragment // Init //////////////////////////////////////////////////////////////////////////*/ - protected View getListHeader() { + @Nullable + protected ViewBinding getListHeader() { return null; } - protected View getListFooter() { - return activity.getLayoutInflater().inflate(R.layout.pignate_footer, itemsList, false); + protected ViewBinding getListFooter() { + return PignateFooterBinding.inflate(activity.getLayoutInflater(), itemsList, false); } protected RecyclerView.LayoutManager getListLayoutManager() { @@ -247,8 +251,12 @@ public abstract class BaseListFragment extends BaseStateFragment itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager()); infoListAdapter.setUseGridVariant(useGrid); - infoListAdapter.setFooter(getListFooter()); - infoListAdapter.setHeader(getListHeader()); + infoListAdapter.setFooter(getListFooter().getRoot()); + + final ViewBinding listHeader = getListHeader(); + if (listHeader != null) { + infoListAdapter.setHeader(listHeader.getRoot()); + } itemsList.setAdapter(infoListAdapter); } 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 0342bb99c..b97ef9acc 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 @@ -14,8 +14,6 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -23,11 +21,14 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; +import androidx.viewbinding.ViewBinding; import com.jakewharton.rxbinding4.view.RxView; import org.schabi.newpipe.R; import org.schabi.newpipe.database.subscription.SubscriptionEntity; +import org.schabi.newpipe.databinding.ChannelHeaderBinding; +import org.schabi.newpipe.databinding.PlaylistControlBinding; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; @@ -78,18 +79,10 @@ public class ChannelFragment extends BaseListInfoFragment //////////////////////////////////////////////////////////////////////////*/ private SubscriptionManager subscriptionManager; - private View headerRootLayout; - private ImageView headerChannelBanner; - private ImageView headerAvatarView; - private TextView headerTitleView; - private ImageView headerSubChannelAvatarView; - private TextView headerSubChannelTitleView; - private TextView headerSubscribersTextView; - private Button headerSubscribeButton; - private View playlistCtrl; - private LinearLayout headerPlayAllButton; - private LinearLayout headerPopupButton; - private LinearLayout headerBackgroundButton; + + private ChannelHeaderBinding headerBinding; + private PlaylistControlBinding playlistControlBinding; + private MenuItem menuRssButton; private TextView contentNotSupportedTextView; private TextView kaomojiTextView; @@ -140,45 +133,38 @@ public class ChannelFragment extends BaseListInfoFragment @Override public void onDestroy() { super.onDestroy(); - if (disposables != null) { - disposables.clear(); - } + disposables.clear(); if (subscribeButtonMonitor != null) { subscribeButtonMonitor.dispose(); } } + @Override + public void onDestroyView() { + headerBinding = null; + playlistControlBinding = null; + super.onDestroyView(); + } + /*////////////////////////////////////////////////////////////////////////// // Init //////////////////////////////////////////////////////////////////////////*/ - protected View getListHeader() { - headerRootLayout = activity.getLayoutInflater() - .inflate(R.layout.channel_header, itemsList, false); - headerChannelBanner = headerRootLayout.findViewById(R.id.channel_banner_image); - headerAvatarView = headerRootLayout.findViewById(R.id.channel_avatar_view); - headerTitleView = headerRootLayout.findViewById(R.id.channel_title_view); - headerSubscribersTextView = headerRootLayout.findViewById(R.id.channel_subscriber_view); - headerSubscribeButton = headerRootLayout.findViewById(R.id.channel_subscribe_button); - playlistCtrl = headerRootLayout.findViewById(R.id.playlist_control); - headerSubChannelAvatarView = - headerRootLayout.findViewById(R.id.sub_channel_avatar_view); - headerSubChannelTitleView = - headerRootLayout.findViewById(R.id.sub_channel_title_view); + @Override + protected ViewBinding getListHeader() { + headerBinding = ChannelHeaderBinding + .inflate(activity.getLayoutInflater(), itemsList, false); + playlistControlBinding = headerBinding.playlistControl; - headerPlayAllButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_all_button); - headerPopupButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_popup_button); - headerBackgroundButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_bg_button); - - return headerRootLayout; + return headerBinding; } @Override protected void initListeners() { super.initListeners(); - headerSubChannelTitleView.setOnClickListener(this); - headerSubChannelAvatarView.setOnClickListener(this); + headerBinding.subChannelTitleView.setOnClickListener(this); + headerBinding.subChannelAvatarView.setOnClickListener(this); } /*////////////////////////////////////////////////////////////////////////// @@ -241,7 +227,7 @@ public class ChannelFragment extends BaseListInfoFragment private void monitorSubscription(final ChannelInfo info) { final Consumer onError = (Throwable throwable) -> { - animateView(headerSubscribeButton, false, 100); + animateView(headerBinding.channelSubscribeButton, false, 100); showSnackBarError(throwable, UserAction.SUBSCRIPTION, NewPipe.getNameOfService(currentInfo.getServiceId()), "Get subscription status", 0); @@ -351,15 +337,15 @@ public class ChannelFragment extends BaseListInfoFragment info.getAvatarUrl(), info.getDescription(), info.getSubscriberCount()); - subscribeButtonMonitor = monitorSubscribeButton(headerSubscribeButton, - mapOnSubscribe(channel, info)); + subscribeButtonMonitor = monitorSubscribeButton( + headerBinding.channelSubscribeButton, mapOnSubscribe(channel, info)); } else { if (DEBUG) { Log.d(TAG, "Found subscription to this channel!"); } final SubscriptionEntity subscription = subscriptionEntities.get(0); - subscribeButtonMonitor = monitorSubscribeButton(headerSubscribeButton, - mapOnUnsubscribe(subscription)); + subscribeButtonMonitor = monitorSubscribeButton( + headerBinding.channelSubscribeButton, mapOnUnsubscribe(subscription)); } }; } @@ -370,7 +356,8 @@ public class ChannelFragment extends BaseListInfoFragment + "isSubscribed = [" + isSubscribed + "]"); } - final boolean isButtonVisible = headerSubscribeButton.getVisibility() == View.VISIBLE; + final boolean isButtonVisible = headerBinding.channelSubscribeButton.getVisibility() + == View.VISIBLE; final int backgroundDuration = isButtonVisible ? 300 : 0; final int textDuration = isButtonVisible ? 200 : 0; @@ -382,18 +369,21 @@ public class ChannelFragment extends BaseListInfoFragment final int subscribedText = ContextCompat.getColor(activity, R.color.subscribed_text_color); if (!isSubscribed) { - headerSubscribeButton.setText(R.string.subscribe_button_title); - animateBackgroundColor(headerSubscribeButton, backgroundDuration, subscribedBackground, - subscribeBackground); - animateTextColor(headerSubscribeButton, textDuration, subscribedText, subscribeText); + headerBinding.channelSubscribeButton.setText(R.string.subscribe_button_title); + animateBackgroundColor(headerBinding.channelSubscribeButton, backgroundDuration, + subscribedBackground, subscribeBackground); + animateTextColor(headerBinding.channelSubscribeButton, textDuration, subscribedText, + subscribeText); } else { - headerSubscribeButton.setText(R.string.subscribed_button_title); - animateBackgroundColor(headerSubscribeButton, backgroundDuration, subscribeBackground, - subscribedBackground); - animateTextColor(headerSubscribeButton, textDuration, subscribeText, subscribedText); + headerBinding.channelSubscribeButton.setText(R.string.subscribed_button_title); + animateBackgroundColor(headerBinding.channelSubscribeButton, backgroundDuration, + subscribeBackground, subscribedBackground); + animateTextColor(headerBinding.channelSubscribeButton, textDuration, subscribeText, + subscribedText); } - animateView(headerSubscribeButton, AnimationUtils.Type.LIGHT_SCALE_AND_ALPHA, true, 100); + animateView(headerBinding.channelSubscribeButton, AnimationUtils.Type.LIGHT_SCALE_AND_ALPHA, + true, 100); } /*////////////////////////////////////////////////////////////////////////// @@ -446,48 +436,49 @@ public class ChannelFragment extends BaseListInfoFragment public void showLoading() { super.showLoading(); - IMAGE_LOADER.cancelDisplayTask(headerChannelBanner); - IMAGE_LOADER.cancelDisplayTask(headerAvatarView); - IMAGE_LOADER.cancelDisplayTask(headerSubChannelAvatarView); - animateView(headerSubscribeButton, false, 100); + IMAGE_LOADER.cancelDisplayTask(headerBinding.channelBannerImage); + IMAGE_LOADER.cancelDisplayTask(headerBinding.channelAvatarView); + IMAGE_LOADER.cancelDisplayTask(headerBinding.subChannelAvatarView); + animateView(headerBinding.channelSubscribeButton, false, 100); } @Override public void handleResult(@NonNull final ChannelInfo result) { super.handleResult(result); - headerRootLayout.setVisibility(View.VISIBLE); - IMAGE_LOADER.displayImage(result.getBannerUrl(), headerChannelBanner, + headerBinding.getRoot().setVisibility(View.VISIBLE); + IMAGE_LOADER.displayImage(result.getBannerUrl(), headerBinding.channelBannerImage, ImageDisplayConstants.DISPLAY_BANNER_OPTIONS); - IMAGE_LOADER.displayImage(result.getAvatarUrl(), headerAvatarView, + IMAGE_LOADER.displayImage(result.getAvatarUrl(), headerBinding.channelAvatarView, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS); - IMAGE_LOADER.displayImage(result.getParentChannelAvatarUrl(), headerSubChannelAvatarView, + IMAGE_LOADER.displayImage(result.getParentChannelAvatarUrl(), + headerBinding.subChannelAvatarView, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS); - headerSubscribersTextView.setVisibility(View.VISIBLE); + headerBinding.channelSubscriberView.setVisibility(View.VISIBLE); if (result.getSubscriberCount() >= 0) { - headerSubscribersTextView.setText(Localization + headerBinding.channelSubscriberView.setText(Localization .shortSubscriberCount(activity, result.getSubscriberCount())); } else { - headerSubscribersTextView.setText(R.string.subscribers_count_not_available); + headerBinding.channelSubscriberView.setText(R.string.subscribers_count_not_available); } if (!TextUtils.isEmpty(currentInfo.getParentChannelName())) { - headerSubChannelTitleView.setText(String.format( + headerBinding.subChannelTitleView.setText(String.format( getString(R.string.channel_created_by), currentInfo.getParentChannelName()) ); - headerSubChannelTitleView.setVisibility(View.VISIBLE); - headerSubChannelAvatarView.setVisibility(View.VISIBLE); + headerBinding.subChannelTitleView.setVisibility(View.VISIBLE); + headerBinding.subChannelAvatarView.setVisibility(View.VISIBLE); } else { - headerSubChannelTitleView.setVisibility(View.GONE); + headerBinding.subChannelTitleView.setVisibility(View.GONE); } if (menuRssButton != null) { menuRssButton.setVisible(!TextUtils.isEmpty(result.getFeedUrl())); } - playlistCtrl.setVisibility(View.VISIBLE); + playlistControlBinding.getRoot().setVisibility(View.VISIBLE); final List errors = new ArrayList<>(result.getErrors()); if (!errors.isEmpty()) { @@ -516,19 +507,22 @@ public class ChannelFragment extends BaseListInfoFragment updateSubscription(result); monitorSubscription(result); - headerPlayAllButton.setOnClickListener(view -> NavigationHelper - .playOnMainPlayer(activity, getPlayQueue())); - headerPopupButton.setOnClickListener(view -> NavigationHelper - .playOnPopupPlayer(activity, getPlayQueue(), false)); - headerBackgroundButton.setOnClickListener(view -> NavigationHelper - .playOnBackgroundPlayer(activity, getPlayQueue(), false)); + playlistControlBinding.playlistCtrlPlayAllButton + .setOnClickListener(view -> NavigationHelper + .playOnMainPlayer(activity, getPlayQueue())); + playlistControlBinding.playlistCtrlPlayPopupButton + .setOnClickListener(view -> NavigationHelper + .playOnPopupPlayer(activity, getPlayQueue(), false)); + playlistControlBinding.playlistCtrlPlayBgButton + .setOnClickListener(view -> NavigationHelper + .playOnBackgroundPlayer(activity, getPlayQueue(), false)); - headerPopupButton.setOnLongClickListener(view -> { + playlistControlBinding.playlistCtrlPlayPopupButton.setOnLongClickListener(view -> { NavigationHelper.enqueueOnPopupPlayer(activity, getPlayQueue(), true); return true; }); - headerBackgroundButton.setOnLongClickListener(view -> { + playlistControlBinding.playlistCtrlPlayBgButton.setOnLongClickListener(view -> { NavigationHelper.enqueueOnBackgroundPlayer(activity, getPlayQueue(), true); return true; }); @@ -596,7 +590,7 @@ public class ChannelFragment extends BaseListInfoFragment public void setTitle(final String title) { super.setTitle(title); if (!useAsFrontPage) { - headerTitleView.setText(title); + headerBinding.channelTitleView.setText(title); } } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index 8f7d6128b..6e723a686 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -11,18 +11,20 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.content.res.AppCompatResources; +import androidx.viewbinding.ViewBinding; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import org.schabi.newpipe.NewPipeDatabase; import org.schabi.newpipe.R; import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity; +import org.schabi.newpipe.databinding.PlaylistControlBinding; +import org.schabi.newpipe.databinding.PlaylistHeaderBinding; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; @@ -53,7 +55,6 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import de.hdodenhof.circleimageview.CircleImageView; import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; import io.reactivex.rxjava3.core.Flowable; import io.reactivex.rxjava3.core.Single; @@ -74,17 +75,8 @@ public class PlaylistFragment extends BaseListInfoFragment { // Views //////////////////////////////////////////////////////////////////////////*/ - private View headerRootLayout; - private TextView headerTitleView; - private View headerUploaderLayout; - private TextView headerUploaderName; - private CircleImageView headerUploaderAvatar; - private TextView headerStreamCount; - private View playlistCtrl; - - private View headerPlayAllButton; - private View headerPopupButton; - private View headerBackgroundButton; + private PlaylistHeaderBinding headerBinding; + private PlaylistControlBinding playlistControlBinding; private MenuItem playlistBookmarkButton; @@ -119,22 +111,13 @@ public class PlaylistFragment extends BaseListInfoFragment { // Init //////////////////////////////////////////////////////////////////////////*/ - protected View getListHeader() { - headerRootLayout = activity.getLayoutInflater() - .inflate(R.layout.playlist_header, itemsList, false); - headerTitleView = headerRootLayout.findViewById(R.id.playlist_title_view); - headerUploaderLayout = headerRootLayout.findViewById(R.id.uploader_layout); - headerUploaderName = headerRootLayout.findViewById(R.id.uploader_name); - headerUploaderAvatar = headerRootLayout.findViewById(R.id.uploader_avatar_view); - headerStreamCount = headerRootLayout.findViewById(R.id.playlist_stream_count); - playlistCtrl = headerRootLayout.findViewById(R.id.playlist_control); + @Override + protected ViewBinding getListHeader() { + headerBinding = PlaylistHeaderBinding + .inflate(activity.getLayoutInflater(), itemsList, false); + playlistControlBinding = headerBinding.playlistControl; - headerPlayAllButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_all_button); - headerPopupButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_popup_button); - headerBackgroundButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_bg_button); - - - return headerRootLayout; + return headerBinding; } @Override @@ -203,6 +186,9 @@ public class PlaylistFragment extends BaseListInfoFragment { @Override public void onDestroyView() { + headerBinding = null; + playlistControlBinding = null; + super.onDestroyView(); if (isBookmarkButtonReady != null) { isBookmarkButtonReady.set(false); @@ -275,25 +261,25 @@ public class PlaylistFragment extends BaseListInfoFragment { @Override public void showLoading() { super.showLoading(); - animateView(headerRootLayout, false, 200); + animateView(headerBinding.getRoot(), false, 200); animateView(itemsList, false, 100); - IMAGE_LOADER.cancelDisplayTask(headerUploaderAvatar); - animateView(headerUploaderLayout, false, 200); + IMAGE_LOADER.cancelDisplayTask(headerBinding.uploaderAvatarView); + animateView(headerBinding.uploaderLayout, false, 200); } @Override public void handleResult(@NonNull final PlaylistInfo result) { super.handleResult(result); - animateView(headerRootLayout, true, 100); - animateView(headerUploaderLayout, true, 300); - headerUploaderLayout.setOnClickListener(null); + animateView(headerBinding.getRoot(), true, 100); + animateView(headerBinding.uploaderLayout, true, 300); + headerBinding.uploaderLayout.setOnClickListener(null); // If we have an uploader put them into the UI if (!TextUtils.isEmpty(result.getUploaderName())) { - headerUploaderName.setText(result.getUploaderName()); + headerBinding.uploaderName.setText(result.getUploaderName()); if (!TextUtils.isEmpty(result.getUploaderUrl())) { - headerUploaderLayout.setOnClickListener(v -> { + headerBinding.uploaderLayout.setOnClickListener(v -> { try { NavigationHelper.openChannelFragment(getFM(), result.getServiceId(), result.getUploaderUrl(), result.getUploaderName()); @@ -303,28 +289,29 @@ public class PlaylistFragment extends BaseListInfoFragment { }); } } else { // Otherwise say we have no uploader - headerUploaderName.setText(R.string.playlist_no_uploader); + headerBinding.uploaderName.setText(R.string.playlist_no_uploader); } - playlistCtrl.setVisibility(View.VISIBLE); + playlistControlBinding.getRoot().setVisibility(View.VISIBLE); final String avatarUrl = result.getUploaderAvatarUrl(); if (result.getServiceId() == ServiceList.YouTube.getServiceId() && (YoutubeParsingHelper.isYoutubeMixId(result.getId()) || YoutubeParsingHelper.isYoutubeMusicMixId(result.getId()))) { // this is an auto-generated playlist (e.g. Youtube mix), so a radio is shown - headerUploaderAvatar.setDisableCircularTransformation(true); - headerUploaderAvatar.setBorderColor( + headerBinding.uploaderAvatarView.setDisableCircularTransformation(true); + headerBinding.uploaderAvatarView.setBorderColor( getResources().getColor(R.color.transparent_background_color)); - headerUploaderAvatar.setImageDrawable(AppCompatResources.getDrawable(requireContext(), - resolveResourceIdFromAttr(requireContext(), R.attr.ic_radio))); - + headerBinding.uploaderAvatarView.setImageDrawable( + AppCompatResources.getDrawable(requireContext(), + resolveResourceIdFromAttr(requireContext(), R.attr.ic_radio)) + ); } else { - IMAGE_LOADER.displayImage(avatarUrl, headerUploaderAvatar, + IMAGE_LOADER.displayImage(avatarUrl, headerBinding.uploaderAvatarView, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS); } - headerStreamCount.setText(Localization + headerBinding.playlistStreamCount.setText(Localization .localizeStreamCount(getContext(), result.getStreamCount())); if (!result.getErrors().isEmpty()) { @@ -338,19 +325,19 @@ public class PlaylistFragment extends BaseListInfoFragment { .observeOn(AndroidSchedulers.mainThread()) .subscribe(getPlaylistBookmarkSubscriber()); - headerPlayAllButton.setOnClickListener(view -> + playlistControlBinding.playlistCtrlPlayAllButton.setOnClickListener(view -> NavigationHelper.playOnMainPlayer(activity, getPlayQueue())); - headerPopupButton.setOnClickListener(view -> + playlistControlBinding.playlistCtrlPlayPopupButton.setOnClickListener(view -> NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(), false)); - headerBackgroundButton.setOnClickListener(view -> + playlistControlBinding.playlistCtrlPlayBgButton.setOnClickListener(view -> NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue(), false)); - headerPopupButton.setOnLongClickListener(view -> { + playlistControlBinding.playlistCtrlPlayPopupButton.setOnLongClickListener(view -> { NavigationHelper.enqueueOnPopupPlayer(activity, getPlayQueue(), true); return true; }); - headerBackgroundButton.setOnLongClickListener(view -> { + playlistControlBinding.playlistCtrlPlayBgButton.setOnLongClickListener(view -> { NavigationHelper.enqueueOnBackgroundPlayer(activity, getPlayQueue(), true); return true; }); @@ -459,7 +446,7 @@ public class PlaylistFragment extends BaseListInfoFragment { @Override public void setTitle(final String title) { super.setTitle(title); - headerTitleView.setText(title); + headerBinding.playlistTitleView.setText(title); } private void onBookmarkClicked() { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java index 907615b45..7fb41f0e5 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java @@ -8,13 +8,14 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Switch; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.preference.PreferenceManager; +import androidx.viewbinding.ViewBinding; import org.schabi.newpipe.R; +import org.schabi.newpipe.databinding.RelatedStreamsHeaderBinding; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.stream.StreamInfo; @@ -38,8 +39,7 @@ public class RelatedVideosFragment extends BaseListInfoFragment + headerBinding.autoplaySwitch.setChecked(autoplay); + headerBinding.autoplaySwitch.setOnCheckedChangeListener((compoundButton, b) -> PreferenceManager.getDefaultSharedPreferences(requireContext()).edit() .putBoolean(getString(R.string.auto_queue_key), b).apply()); - return headerRootLayout; + return headerBinding; } else { return null; } @@ -107,8 +111,8 @@ public class RelatedVideosFragment extends BaseListInfoFragment - + + diff --git a/app/src/main/res/layout/playlist_header.xml b/app/src/main/res/layout/playlist_header.xml index d27c86872..a5960472f 100644 --- a/app/src/main/res/layout/playlist_header.xml +++ b/app/src/main/res/layout/playlist_header.xml @@ -83,7 +83,9 @@ android:layout_height="wrap_content" android:layout_below="@id/playlist_meta"> - +