diff --git a/app/build.gradle b/app/build.gradle index e49d4cc8d74..a6e704258e2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -77,6 +77,10 @@ android { sourceSets { androidTest.assets.srcDirs += files("$projectDir/schemas".toString()) } + + viewBinding { + enabled = true + } } ext { diff --git a/app/src/main/java/org/schabi/newpipe/BaseFragment.java b/app/src/main/java/org/schabi/newpipe/BaseFragment.java index 54513a0afd1..8c38e27a4d2 100644 --- a/app/src/main/java/org/schabi/newpipe/BaseFragment.java +++ b/app/src/main/java/org/schabi/newpipe/BaseFragment.java @@ -6,7 +6,6 @@ import android.view.View; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -20,7 +19,7 @@ public abstract class BaseFragment extends Fragment { public static final ImageLoader IMAGE_LOADER = ImageLoader.getInstance(); protected final String TAG = getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()); protected final boolean DEBUG = MainActivity.DEBUG; - protected AppCompatActivity activity; + protected MainActivity activity; //These values are used for controlling fragments when they are part of the frontpage @State protected boolean useAsFrontPage = false; @@ -37,7 +36,7 @@ public void useAsFrontPage(final boolean value) { @Override public void onAttach(final Context context) { super.onAttach(context); - activity = (AppCompatActivity) context; + activity = (MainActivity) context; } @Override diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index e72d4609e43..3327daf458d 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -30,9 +30,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; -import androidx.preference.PreferenceManager; import android.util.Log; - import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; @@ -41,11 +39,10 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.FrameLayout; -import android.widget.ImageView; import android.widget.Spinner; import android.widget.TextView; + import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBarDrawerToggle; @@ -55,10 +52,13 @@ import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; +import androidx.preference.PreferenceManager; import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.navigation.NavigationView; +import org.schabi.newpipe.databinding.ActivityMainBinding; +import org.schabi.newpipe.databinding.DrawerHeaderBinding; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; @@ -71,8 +71,8 @@ import org.schabi.newpipe.player.event.OnKeyDownListener; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.report.ErrorActivity; -import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.Constants; +import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.KioskTranslator; import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; @@ -83,6 +83,7 @@ import org.schabi.newpipe.util.StateSaver; import org.schabi.newpipe.util.TLSSocketFactoryCompat; import org.schabi.newpipe.util.ThemeHelper; +import org.schabi.newpipe.views.FocusAwareDrawerLayout; import org.schabi.newpipe.views.FocusOverlayView; import java.util.ArrayList; @@ -94,15 +95,12 @@ public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release"); + public ActivityMainBinding binding; + private DrawerHeaderBinding headerBinding; + private ActionBarDrawerToggle toggle; - private DrawerLayout drawer; - private NavigationView drawerItems; - private ImageView headerServiceIcon; - private TextView headerServiceView; - private Button toggleServiceButton; private boolean servicesShown = false; - private ImageView serviceArrow; private BroadcastReceiver broadcastReceiver; @@ -135,14 +133,16 @@ protected void onCreate(final Bundle savedInstanceState) { assureCorrectAppLanguage(this); super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); + binding = ActivityMainBinding.inflate(getLayoutInflater()); + final View view = binding.getRoot(); + setContentView(view); if (getSupportFragmentManager() != null && getSupportFragmentManager().getBackStackEntryCount() == 0) { initFragments(); } - setSupportActionBar(findViewById(R.id.toolbar)); + setSupportActionBar(binding.toolbarLayout.toolbar); try { setupDrawer(); } catch (final Exception e) { @@ -156,9 +156,9 @@ && getSupportFragmentManager().getBackStackEntryCount() == 0) { } private void setupDrawer() throws Exception { - final Toolbar toolbar = findViewById(R.id.toolbar); - drawer = findViewById(R.id.drawer_layout); - drawerItems = findViewById(R.id.navigation); + final Toolbar toolbar = binding.toolbarLayout.toolbar; + final FocusAwareDrawerLayout drawer = binding.mainDrawerLayout; + final NavigationView drawerItems = binding.drawerLayout.drawerLayout; //Tabs final int currentServiceId = ServiceHelper.getSelectedServiceId(this); @@ -245,16 +245,16 @@ private boolean drawerItemSelected(final MenuItem item) { return false; } - drawer.closeDrawers(); + binding.mainDrawerLayout.closeDrawers(); return true; } private void changeService(final MenuItem item) { - drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)) - .setChecked(false); + binding.drawerLayout.drawerLayout.getMenu() + .getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(false); ServiceHelper.setSelectedServiceId(this, item.getItemId()); - drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)) - .setChecked(true); + binding.drawerLayout.drawerLayout.getMenu() + .getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true); } private void tabSelected(final MenuItem item) throws ExtractionException { @@ -305,19 +305,15 @@ private void optionsAboutSelected(final MenuItem item) { } private void setupDrawerHeader() { - final NavigationView navigationView = findViewById(R.id.navigation); - final View hView = navigationView.getHeaderView(0); + final View hView = binding.drawerLayout.drawerLayout.getHeaderView(0); + headerBinding = DrawerHeaderBinding.bind(hView); - serviceArrow = hView.findViewById(R.id.drawer_arrow); - headerServiceIcon = hView.findViewById(R.id.drawer_header_service_icon); - headerServiceView = hView.findViewById(R.id.drawer_header_service_view); - toggleServiceButton = hView.findViewById(R.id.drawer_header_action_button); - toggleServiceButton.setOnClickListener(view -> toggleServices()); + headerBinding.drawerHeaderActionButton.setOnClickListener(view -> toggleServices()); // If the current app name is bigger than the default "NewPipe" (7 chars), // let the text view grow a little more as well. if (getString(R.string.app_name).length() > "NewPipe".length()) { - final TextView headerTitle = hView.findViewById(R.id.drawer_header_newpipe_title); + final TextView headerTitle = headerBinding.drawerHeaderNewpipeTitle; final ViewGroup.LayoutParams layoutParams = headerTitle.getLayoutParams(); layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; headerTitle.setLayoutParams(layoutParams); @@ -332,9 +328,9 @@ private void setupDrawerHeader() { private void toggleServices() { servicesShown = !servicesShown; - drawerItems.getMenu().removeGroup(R.id.menu_services_group); - drawerItems.getMenu().removeGroup(R.id.menu_tabs_group); - drawerItems.getMenu().removeGroup(R.id.menu_options_about_group); + binding.drawerLayout.drawerLayout.getMenu().removeGroup(R.id.menu_services_group); + binding.drawerLayout.drawerLayout.getMenu().removeGroup(R.id.menu_tabs_group); + binding.drawerLayout.drawerLayout.getMenu().removeGroup(R.id.menu_options_about_group); if (servicesShown) { showServices(); @@ -348,13 +344,13 @@ private void toggleServices() { } private void showServices() { - serviceArrow.setImageResource(R.drawable.ic_arrow_drop_up_white_24dp); + headerBinding.drawerArrow.setImageResource(R.drawable.ic_arrow_drop_up_white_24dp); for (final StreamingService s : NewPipe.getServices()) { final String title = s.getServiceInfo().getName() + (ServiceHelper.isBeta(s) ? " (beta)" : ""); - final MenuItem menuItem = drawerItems.getMenu() + final MenuItem menuItem = binding.drawerLayout.drawerLayout.getMenu() .add(R.id.menu_services_group, s.getServiceId(), ORDER, title) .setIcon(ServiceHelper.getIcon(s.getServiceId())); @@ -363,8 +359,8 @@ private void showServices() { enhancePeertubeMenu(s, menuItem); } } - drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)) - .setChecked(true); + binding.drawerLayout.drawerLayout.getMenu() + .getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true); } private void enhancePeertubeMenu(final StreamingService s, final MenuItem menuItem) { @@ -396,7 +392,7 @@ public void onItemSelected(final AdapterView parent, final View view, } PeertubeHelper.selectInstance(newInstance, getApplicationContext()); changeService(menuItem); - drawer.closeDrawers(); + binding.mainDrawerLayout.closeDrawers(); new Handler(Looper.getMainLooper()).postDelayed(() -> { getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); @@ -413,7 +409,7 @@ public void onNothingSelected(final AdapterView parent) { } private void showTabs() throws ExtractionException { - serviceArrow.setImageResource(R.drawable.ic_arrow_drop_down_white_24dp); + headerBinding.drawerArrow.setImageResource(R.drawable.ic_arrow_drop_down_white_24dp); //Tabs final int currentServiceId = ServiceHelper.getSelectedServiceId(this); @@ -421,6 +417,8 @@ private void showTabs() throws ExtractionException { int kioskId = 0; + final NavigationView drawerItems = binding.drawerLayout.drawerLayout; + for (final String ks : service.getKioskList().getAvailableKiosks()) { drawerItems.getMenu() .add(R.id.menu_tabs_group, kioskId, ORDER, @@ -474,16 +472,18 @@ protected void onResume() { // Close drawer on return, and don't show animation, // so it looks like the drawer isn't open when the user returns to MainActivity - drawer.closeDrawer(GravityCompat.START, false); + binding.mainDrawerLayout.closeDrawer(GravityCompat.START, false); try { final int selectedServiceId = ServiceHelper.getSelectedServiceId(this); final String selectedServiceName = NewPipe.getService(selectedServiceId) .getServiceInfo().getName(); - headerServiceView.setText(selectedServiceName); - headerServiceIcon.setImageResource(ServiceHelper.getIcon(selectedServiceId)); + headerBinding.drawerHeaderServiceView.setText(selectedServiceName); + headerBinding.drawerHeaderServiceIcon + .setImageResource(ServiceHelper.getIcon(selectedServiceId)); - headerServiceView.post(() -> headerServiceView.setSelected(true)); - toggleServiceButton.setContentDescription( + headerBinding.drawerHeaderServiceView.post(() -> + headerBinding.drawerHeaderServiceView.setSelected(true)); + headerBinding.drawerHeaderActionButton.setContentDescription( getString(R.string.drawer_header_description) + selectedServiceName); } catch (final Exception e) { ErrorActivity.reportUiError(this, e); @@ -512,7 +512,8 @@ protected void onResume() { final boolean isHistoryEnabled = sharedPreferences.getBoolean( getString(R.string.enable_watch_history_key), true); - drawerItems.getMenu().findItem(ITEM_ID_HISTORY).setVisible(isHistoryEnabled); + binding.drawerLayout.drawerLayout.getMenu().findItem(ITEM_ID_HISTORY) + .setVisible(isHistoryEnabled); } @Override @@ -556,9 +557,9 @@ public void onBackPressed() { } if (DeviceUtils.isTv(this)) { - final View drawerPanel = findViewById(R.id.navigation); - if (drawer.isDrawerOpen(drawerPanel)) { - drawer.closeDrawers(); + final View drawerPanel = binding.drawerLayout.drawerLayout; + if (binding.mainDrawerLayout.isDrawerOpen(drawerPanel)) { + binding.mainDrawerLayout.closeDrawers(); return; } } @@ -584,8 +585,7 @@ public void onBackPressed() { // delegate the back press to it if (fragmentPlayer instanceof BackPressable) { if (!((BackPressable) fragmentPlayer).onBackPressed()) { - final FrameLayout bottomSheetLayout = - findViewById(R.id.fragment_player_holder); + final FrameLayout bottomSheetLayout = binding.fragmentPlayerHolder; BottomSheetBehavior.from(bottomSheetLayout) .setState(BottomSheetBehavior.STATE_COLLAPSED); } @@ -669,8 +669,7 @@ public boolean onCreateOptionsMenu(final Menu menu) { final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder); if (!(fragment instanceof SearchFragment)) { - findViewById(R.id.toolbar).findViewById(R.id.toolbar_search_container) - .setVisibility(View.GONE); + binding.toolbarLayout.toolbarSearchContainer.getRoot().setVisibility(View.GONE); } final ActionBar actionBar = getSupportActionBar(); @@ -731,7 +730,7 @@ private void updateDrawerNavigation() { return; } - final Toolbar toolbar = findViewById(R.id.toolbar); + final Toolbar toolbar = binding.toolbarLayout.toolbar; final Fragment fragment = getSupportFragmentManager() .findFragmentById(R.id.fragment_holder); @@ -739,11 +738,12 @@ private void updateDrawerNavigation() { getSupportActionBar().setDisplayHomeAsUpEnabled(false); if (toggle != null) { toggle.syncState(); - toolbar.setNavigationOnClickListener(v -> drawer.openDrawer(GravityCompat.START)); - drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED); + toolbar.setNavigationOnClickListener(v -> + binding.mainDrawerLayout.openDrawer(GravityCompat.START)); + binding.mainDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED); } } else { - drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); + binding.mainDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setNavigationOnClickListener(v -> onHomeButtonPressed()); } @@ -836,7 +836,7 @@ public void onReceive(final Context context, final Intent intent) { } private boolean bottomSheetHiddenOrCollapsed() { - final FrameLayout bottomSheetLayout = findViewById(R.id.fragment_player_holder); + final FrameLayout bottomSheetLayout = binding.fragmentPlayerHolder; final BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout); 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 6a8611d0e28..89d485ba718 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 @@ -97,6 +97,13 @@ public void onDestroy() { .unregisterOnSharedPreferenceChangeListener(this); } + @Override + public void onDestroyView() { + super.onDestroyView(); + + itemsList = null; + } + @Override public void onResume() { super.onResume(); 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 8902834e4e3..ebfff361e68 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,9 +14,6 @@ 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; import androidx.annotation.Nullable; @@ -28,6 +25,8 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.database.subscription.SubscriptionEntity; +import org.schabi.newpipe.databinding.ChannelHeaderBinding; +import org.schabi.newpipe.databinding.FragmentChannelBinding; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; @@ -74,27 +73,10 @@ public class ChannelFragment extends BaseListInfoFragment private final CompositeDisposable disposables = new CompositeDisposable(); private Disposable subscribeButtonMonitor; - /*////////////////////////////////////////////////////////////////////////// - // Views - //////////////////////////////////////////////////////////////////////////*/ - 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 MenuItem menuRssButton; - private TextView contentNotSupportedTextView; - private TextView kaomojiTextView; - private TextView noVideosTextView; + private FragmentChannelBinding binding; + private ChannelHeaderBinding headerBinding; public static ChannelFragment getInstance(final int serviceId, final String url, final String name) { @@ -127,26 +109,21 @@ public void onAttach(final Context context) { public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_channel, container, false); + binding = FragmentChannelBinding.inflate(inflater, container, false); + return binding.getRoot(); } @Override - public void onViewCreated(final View rootView, final Bundle savedInstanceState) { - super.onViewCreated(rootView, savedInstanceState); - contentNotSupportedTextView = rootView.findViewById(R.id.error_content_not_supported); - kaomojiTextView = rootView.findViewById(R.id.channel_kaomoji); - noVideosTextView = rootView.findViewById(R.id.channel_no_videos); - } - - @Override - public void onDestroy() { - super.onDestroy(); + public void onDestroyView() { + super.onDestroyView(); if (disposables != null) { disposables.clear(); } if (subscribeButtonMonitor != null) { subscribeButtonMonitor.dispose(); } + headerBinding = null; + binding = null; } /*////////////////////////////////////////////////////////////////////////// @@ -154,32 +131,17 @@ public void onDestroy() { //////////////////////////////////////////////////////////////////////////*/ 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); - - 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; + headerBinding = ChannelHeaderBinding.inflate(activity.getLayoutInflater(), itemsList, + false); + return headerBinding.getRoot(); } @Override protected void initListeners() { super.initListeners(); - headerSubChannelTitleView.setOnClickListener(this); - headerSubChannelAvatarView.setOnClickListener(this); + headerBinding.subChannelTitleView.setOnClickListener(this); + headerBinding.subChannelAvatarView.setOnClickListener(this); } /*////////////////////////////////////////////////////////////////////////// @@ -242,7 +204,7 @@ public boolean onOptionsItemSelected(final MenuItem item) { 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); @@ -352,15 +314,15 @@ private Consumer> getSubscribeUpdateMonitor(final Chann 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)); } }; } @@ -371,7 +333,8 @@ private void updateSubscribeButton(final boolean isSubscribed) { + "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; @@ -383,18 +346,21 @@ private void updateSubscribeButton(final boolean isSubscribed) { 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); } /*////////////////////////////////////////////////////////////////////////// @@ -447,48 +413,48 @@ public void onClick(final View v) { 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, - ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS); - IMAGE_LOADER.displayImage(result.getParentChannelAvatarUrl(), headerSubChannelAvatarView, + IMAGE_LOADER.displayImage(result.getAvatarUrl(), headerBinding.channelAvatarView, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS); + 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); + headerBinding.playlistControl.playlistControl.setVisibility(View.VISIBLE); final List errors = new ArrayList<>(result.getErrors()); if (!errors.isEmpty()) { @@ -518,29 +484,29 @@ public void handleResult(@NonNull final ChannelInfo result) { updateSubscription(result); monitorSubscription(result); - headerPlayAllButton.setOnClickListener(view -> NavigationHelper - .playOnMainPlayer(activity, getPlayQueue(), true)); - headerPopupButton.setOnClickListener(view -> NavigationHelper - .playOnPopupPlayer(activity, getPlayQueue(), false)); - headerBackgroundButton.setOnClickListener(view -> NavigationHelper - .playOnBackgroundPlayer(activity, getPlayQueue(), false)); + headerBinding.playlistControl.playlistCtrlPlayAllButton.setOnClickListener(view + -> NavigationHelper.playOnMainPlayer(activity, getPlayQueue(), true)); + headerBinding.playlistControl.playlistCtrlPlayPopupButton.setOnClickListener(view + -> NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(), false)); + headerBinding.playlistControl.playlistCtrlPlayBgButton.setOnClickListener(view + -> NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue(), false)); - headerPopupButton.setOnLongClickListener(view -> { + headerBinding.playlistControl.playlistCtrlPlayPopupButton.setOnLongClickListener(view -> { NavigationHelper.enqueueOnPopupPlayer(activity, getPlayQueue(), true); return true; }); - headerBackgroundButton.setOnLongClickListener(view -> { + headerBinding.playlistControl.playlistCtrlPlayBgButton.setOnLongClickListener(view -> { NavigationHelper.enqueueOnBackgroundPlayer(activity, getPlayQueue(), true); return true; }); } private void showContentNotSupported() { - contentNotSupportedTextView.setVisibility(View.VISIBLE); - kaomojiTextView.setText("(︶︹︺)"); - kaomojiTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 45f); - noVideosTextView.setVisibility(View.GONE); + binding.errorContentNotSupported.setVisibility(View.VISIBLE); + binding.channelKaomoji.setText("(︶︹︺)"); + binding.channelKaomoji.setTextSize(TypedValue.COMPLEX_UNIT_SP, 45f); + binding.channelNoVideos.setVisibility(View.GONE); } private PlayQueue getPlayQueue() { @@ -598,7 +564,7 @@ protected boolean onError(final Throwable exception) { 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/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index 64eaf3a3d00..972d580814e 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -5,8 +5,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; -import androidx.core.text.HtmlCompat; -import androidx.preference.PreferenceManager; import android.text.Editable; import android.text.Html; import android.text.TextUtils; @@ -30,12 +28,15 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.TooltipCompat; +import androidx.core.text.HtmlCompat; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; import org.schabi.newpipe.R; import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.database.history.model.SearchHistoryEntry; +import org.schabi.newpipe.databinding.FragmentSearchBinding; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; @@ -49,9 +50,9 @@ import org.schabi.newpipe.local.history.HistoryRecordManager; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; -import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.AnimationUtils; import org.schabi.newpipe.util.Constants; +import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.ExceptionUtils; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.NavigationHelper; @@ -147,15 +148,13 @@ public class SearchFragment extends BaseListFragment()); @@ -619,7 +622,7 @@ private void showSuggestionsPanel() { Log.d(TAG, "showSuggestionsPanel() called"); } suggestionsPanelVisible = true; - animateView(suggestionsPanel, AnimationUtils.Type.LIGHT_SLIDE_AND_ALPHA, true, 200); + animateView(binding.suggestionsPanel, AnimationUtils.Type.LIGHT_SLIDE_AND_ALPHA, true, 200); } private void hideSuggestionsPanel() { @@ -627,7 +630,8 @@ private void hideSuggestionsPanel() { Log.d(TAG, "hideSuggestionsPanel() called"); } suggestionsPanelVisible = false; - animateView(suggestionsPanel, AnimationUtils.Type.LIGHT_SLIDE_AND_ALPHA, false, 200); + animateView(binding.suggestionsPanel, AnimationUtils.Type.LIGHT_SLIDE_AND_ALPHA, false, + 200); } private void showKeyboardSearch() { @@ -922,8 +926,8 @@ public void handleSuggestions(@NonNull final List suggestions) { if (DEBUG) { Log.d(TAG, "handleSuggestions() called with: suggestions = [" + suggestions + "]"); } - suggestionsRecyclerView.smoothScrollToPosition(0); - suggestionsRecyclerView.post(() -> suggestionListAdapter.setItems(suggestions)); + binding.suggestionsList.smoothScrollToPosition(0); + binding.suggestionsList.post(() -> suggestionListAdapter.setItems(suggestions)); if (suggestionsPanelVisible && errorPanelRoot.getVisibility() == View.VISIBLE) { hideLoading(); @@ -999,7 +1003,7 @@ public void handleResult(@NonNull final SearchInfo result) { private void handleSearchSuggestion() { if (TextUtils.isEmpty(searchSuggestion)) { - correctSuggestion.setVisibility(View.GONE); + binding.correctSuggestion.setVisibility(View.GONE); } else { final String helperText = getString(isCorrectedSearch ? R.string.search_showing_result_for @@ -1008,22 +1012,23 @@ private void handleSearchSuggestion() { final String highlightedSearchSuggestion = "" + Html.escapeHtml(searchSuggestion) + ""; final String text = String.format(helperText, highlightedSearchSuggestion); - correctSuggestion.setText(HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY)); + binding.correctSuggestion.setText(HtmlCompat.fromHtml(text, + HtmlCompat.FROM_HTML_MODE_LEGACY)); - correctSuggestion.setOnClickListener(v -> { - correctSuggestion.setVisibility(View.GONE); + binding.correctSuggestion.setOnClickListener(v -> { + binding.correctSuggestion.setVisibility(View.GONE); search(searchSuggestion, contentFilter, sortFilter); searchEditText.setText(searchSuggestion); }); - correctSuggestion.setOnLongClickListener(v -> { + binding.correctSuggestion.setOnLongClickListener(v -> { searchEditText.setText(searchSuggestion); searchEditText.setSelection(searchSuggestion.length()); showKeyboardSearch(); return true; }); - correctSuggestion.setVisibility(View.VISIBLE); + binding.correctSuggestion.setVisibility(View.VISIBLE); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 87c964e8727..e34a2804293 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,8 +1,7 @@ - @@ -16,7 +15,9 @@ android:layout_height="match_parent" android:layout_marginTop="?attr/actionBarSize" /> - + - + app:layout_behavior="org.schabi.newpipe.player.event.CustomBottomSheetBehavior"> - + diff --git a/app/src/main/res/layout/channel_header.xml b/app/src/main/res/layout/channel_header.xml index 241aa474129..c2a66941313 100644 --- a/app/src/main/res/layout/channel_header.xml +++ b/app/src/main/res/layout/channel_header.xml @@ -119,7 +119,9 @@ android:layout_height="wrap_content" android:layout_below="@id/channel_metadata"> - + diff --git a/app/src/main/res/layout/drawer_layout.xml b/app/src/main/res/layout/drawer_layout.xml index 55c19c52c78..24874f4059b 100644 --- a/app/src/main/res/layout/drawer_layout.xml +++ b/app/src/main/res/layout/drawer_layout.xml @@ -2,10 +2,10 @@ \ No newline at end of file + app:headerLayout="@layout/drawer_header" /> diff --git a/app/src/main/res/layout/toolbar_layout.xml b/app/src/main/res/layout/toolbar_layout.xml index 318d16ff560..5a2edc13722 100644 --- a/app/src/main/res/layout/toolbar_layout.xml +++ b/app/src/main/res/layout/toolbar_layout.xml @@ -3,7 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/toolbar_container" + android:id="@+id/toolbar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> @@ -27,4 +27,4 @@ - \ No newline at end of file +