diff --git a/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java b/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java index 8e88ceaed..38ecc1c63 100644 --- a/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java @@ -4,6 +4,8 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Bundle; + +import androidx.annotation.Nullable; import androidx.preference.PreferenceManager; import android.util.Log; import android.view.Menu; @@ -15,8 +17,10 @@ import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import androidx.viewbinding.ViewBinding; import org.schabi.newpipe.R; +import org.schabi.newpipe.databinding.PignateFooterBinding; import org.schabi.newpipe.fragments.BaseStateFragment; import org.schabi.newpipe.fragments.list.ListViewContract; @@ -42,8 +46,8 @@ public abstract class BaseLocalListFragment extends BaseStateFragment //////////////////////////////////////////////////////////////////////////*/ private static final int LIST_MODE_UPDATE_FLAG = 0x32; - private View headerRootView; - private View footerRootView; + private ViewBinding headerRootBinding; + private ViewBinding footerRootBinding; protected LocalItemListAdapter itemListAdapter; protected RecyclerView itemsList; private int updateFlags = 0; @@ -86,12 +90,13 @@ public abstract class BaseLocalListFragment extends BaseStateFragment // Lifecycle - View //////////////////////////////////////////////////////////////////////////*/ - 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 getGridLayoutManager() { @@ -120,10 +125,12 @@ public abstract class BaseLocalListFragment extends BaseStateFragment itemsList.setLayoutManager(useGrid ? getGridLayoutManager() : getListLayoutManager()); itemListAdapter.setUseGridVariant(useGrid); - headerRootView = getListHeader(); - itemListAdapter.setHeader(headerRootView); - footerRootView = getListFooter(); - itemListAdapter.setFooter(footerRootView); + headerRootBinding = getListHeader(); + if (headerRootBinding != null) { + itemListAdapter.setHeader(headerRootBinding.getRoot()); + } + footerRootBinding = getListFooter(); + itemListAdapter.setFooter(footerRootBinding.getRoot()); itemsList.setAdapter(itemListAdapter); } @@ -180,8 +187,8 @@ public abstract class BaseLocalListFragment extends BaseStateFragment if (itemsList != null) { animateView(itemsList, false, 200); } - if (headerRootView != null) { - animateView(headerRootView, false, 200); + if (headerRootBinding != null) { + animateView(headerRootBinding.getRoot(), false, 200); } } @@ -191,8 +198,8 @@ public abstract class BaseLocalListFragment extends BaseStateFragment if (itemsList != null) { animateView(itemsList, true, 200); } - if (headerRootView != null) { - animateView(headerRootView, true, 200); + if (headerRootBinding != null) { + animateView(headerRootBinding.getRoot(), true, 200); } } @@ -204,8 +211,8 @@ public abstract class BaseLocalListFragment extends BaseStateFragment if (itemsList != null) { animateView(itemsList, false, 200); } - if (headerRootView != null) { - animateView(headerRootView, false, 200); + if (headerRootBinding != null) { + animateView(headerRootBinding.getRoot(), false, 200); } } diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 0d549ecf9..f9aa38054 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -10,13 +10,12 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import androidx.viewbinding.ViewBinding; import com.google.android.material.snackbar.Snackbar; @@ -26,6 +25,8 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.database.LocalItem; import org.schabi.newpipe.database.stream.StreamStatisticsEntry; import org.schabi.newpipe.database.stream.model.StreamEntity; +import org.schabi.newpipe.databinding.PlaylistControlBinding; +import org.schabi.newpipe.databinding.StatisticPlaylistControlBinding; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.info_list.InfoItemDialog; @@ -60,13 +61,10 @@ public class StatisticsPlaylistFragment @State Parcelable itemsListState; private StatisticSortMode sortMode = StatisticSortMode.LAST_PLAYED; - private View headerPlayAllButton; - private View headerPopupButton; - private View headerBackgroundButton; - private View playlistCtrl; - private View sortButton; - private ImageView sortButtonIcon; - private TextView sortButtonText; + + private StatisticPlaylistControlBinding headerBinding; + private PlaylistControlBinding playlistControlBinding; + /* Used for independent events */ private Subscription databaseSubscription; private HistoryRecordManager recordManager; @@ -131,17 +129,12 @@ public class StatisticsPlaylistFragment } @Override - protected View getListHeader() { - final View headerRootLayout = activity.getLayoutInflater() - .inflate(R.layout.statistic_playlist_control, itemsList, false); - playlistCtrl = headerRootLayout.findViewById(R.id.playlist_control); - 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); - sortButton = headerRootLayout.findViewById(R.id.sortButton); - sortButtonIcon = headerRootLayout.findViewById(R.id.sortButtonIcon); - sortButtonText = headerRootLayout.findViewById(R.id.sortButtonText); - return headerRootLayout; + protected ViewBinding getListHeader() { + headerBinding = StatisticPlaylistControlBinding.inflate(activity.getLayoutInflater(), + itemsList, false); + playlistControlBinding = headerBinding.playlistControl; + + return headerBinding; } @Override @@ -245,14 +238,13 @@ public class StatisticsPlaylistFragment if (itemListAdapter != null) { itemListAdapter.unsetSelectedListener(); } - if (headerBackgroundButton != null) { - headerBackgroundButton.setOnClickListener(null); - } - if (headerPlayAllButton != null) { - headerPlayAllButton.setOnClickListener(null); - } - if (headerPopupButton != null) { - headerPopupButton.setOnClickListener(null); + if (playlistControlBinding != null) { + playlistControlBinding.playlistCtrlPlayBgButton.setOnClickListener(null); + playlistControlBinding.playlistCtrlPlayAllButton.setOnClickListener(null); + playlistControlBinding.playlistCtrlPlayPopupButton.setOnClickListener(null); + + headerBinding = null; + playlistControlBinding = null; } if (databaseSubscription != null) { @@ -311,7 +303,7 @@ public class StatisticsPlaylistFragment return; } - playlistCtrl.setVisibility(View.VISIBLE); + playlistControlBinding.getRoot().setVisibility(View.VISIBLE); itemListAdapter.clearStreamItemList(); @@ -326,13 +318,13 @@ public class StatisticsPlaylistFragment itemsListState = null; } - 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)); - sortButton.setOnClickListener(view -> toggleSortMode()); + headerBinding.sortButton.setOnClickListener(view -> toggleSortMode()); hideLoading(); } @@ -368,15 +360,15 @@ public class StatisticsPlaylistFragment if (sortMode == StatisticSortMode.LAST_PLAYED) { sortMode = StatisticSortMode.MOST_PLAYED; setTitle(getString(R.string.title_most_played)); - sortButtonIcon.setImageResource( + headerBinding.sortButtonIcon.setImageResource( ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_history)); - sortButtonText.setText(R.string.title_last_played); + headerBinding.sortButtonText.setText(R.string.title_last_played); } else { sortMode = StatisticSortMode.LAST_PLAYED; setTitle(getString(R.string.title_last_played)); - sortButtonIcon.setImageResource( + headerBinding.sortButtonIcon.setImageResource( ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_filter_list)); - sortButtonText.setText(R.string.title_most_played); + headerBinding.sortButtonText.setText(R.string.title_most_played); } startLoading(true); } diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 17f7a4ff9..08b7101e6 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -14,7 +14,6 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -22,6 +21,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; +import androidx.viewbinding.ViewBinding; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -32,6 +32,8 @@ import org.schabi.newpipe.database.history.model.StreamHistoryEntry; import org.schabi.newpipe.database.playlist.PlaylistStreamEntry; import org.schabi.newpipe.database.stream.model.StreamEntity; import org.schabi.newpipe.database.stream.model.StreamStateEntity; +import org.schabi.newpipe.databinding.LocalPlaylistHeaderBinding; +import org.schabi.newpipe.databinding.PlaylistControlBinding; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.info_list.InfoItemDialog; @@ -77,13 +79,8 @@ public class LocalPlaylistFragment extends BaseLocalListFragment createRenameDialog()); + headerBinding.playlistTitleView.setOnClickListener(view -> createRenameDialog()); itemTouchHelper = new ItemTouchHelper(getItemTouchCallback()); itemTouchHelper.attachToRecyclerView(itemsList); @@ -210,22 +200,18 @@ public class LocalPlaylistFragment extends BaseLocalListFragment + 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; }); @@ -806,8 +791,9 @@ public class LocalPlaylistFragment extends BaseLocalListFragment - + + diff --git a/app/src/main/res/layout/statistic_playlist_control.xml b/app/src/main/res/layout/statistic_playlist_control.xml index ef090807c..c8eff8fd3 100644 --- a/app/src/main/res/layout/statistic_playlist_control.xml +++ b/app/src/main/res/layout/statistic_playlist_control.xml @@ -38,6 +38,8 @@ tools:ignore="RtlHardcoded" /> - +