Merge pull request #4762 from Isira-Seneviratne/Use_view_binding_in_activities

Use view binding in activities.
This commit is contained in:
Stypox 2020-12-19 08:09:51 +01:00 committed by GitHub
commit 75e34a5a8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 264 additions and 323 deletions

View File

@ -85,6 +85,10 @@ android {
sourceSets { sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas".toString()) androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
} }
buildFeatures {
viewBinding true
}
} }
ext { ext {

View File

@ -39,17 +39,13 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.view.GravityCompat; import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
@ -58,8 +54,12 @@ import androidx.fragment.app.FragmentManager;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import com.google.android.material.bottomsheet.BottomSheetBehavior; 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.databinding.DrawerLayoutBinding;
import org.schabi.newpipe.databinding.InstanceSpinnerLayoutBinding;
import org.schabi.newpipe.databinding.ToolbarLayoutBinding;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@ -97,15 +97,14 @@ public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity"; private static final String TAG = "MainActivity";
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release"); public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
private ActivityMainBinding mainBinding;
private DrawerHeaderBinding drawerHeaderBinding;
private DrawerLayoutBinding drawerLayoutBinding;
private ToolbarLayoutBinding toolbarLayoutBinding;
private ActionBarDrawerToggle toggle; private ActionBarDrawerToggle toggle;
private DrawerLayout drawer;
private NavigationView drawerItems;
private ImageView headerServiceIcon;
private TextView headerServiceView;
private Button toggleServiceButton;
private boolean servicesShown = false; private boolean servicesShown = false;
private ImageView serviceArrow;
private BroadcastReceiver broadcastReceiver; private BroadcastReceiver broadcastReceiver;
@ -138,13 +137,19 @@ public class MainActivity extends AppCompatActivity {
assureCorrectAppLanguage(this); assureCorrectAppLanguage(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainBinding = ActivityMainBinding.inflate(getLayoutInflater());
drawerLayoutBinding = mainBinding.drawerLayout;
drawerHeaderBinding = DrawerHeaderBinding.bind(drawerLayoutBinding.navigation
.getHeaderView(0));
toolbarLayoutBinding = mainBinding.toolbarLayout;
setContentView(mainBinding.getRoot());
if (getSupportFragmentManager().getBackStackEntryCount() == 0) { if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
initFragments(); initFragments();
} }
setSupportActionBar(findViewById(R.id.toolbar)); setSupportActionBar(toolbarLayoutBinding.toolbar);
try { try {
setupDrawer(); setupDrawer();
} catch (final Exception e) { } catch (final Exception e) {
@ -158,10 +163,6 @@ public class MainActivity extends AppCompatActivity {
} }
private void setupDrawer() throws Exception { private void setupDrawer() throws Exception {
final Toolbar toolbar = findViewById(R.id.toolbar);
drawer = findViewById(R.id.drawer_layout);
drawerItems = findViewById(R.id.navigation);
//Tabs //Tabs
final int currentServiceId = ServiceHelper.getSelectedServiceId(this); final int currentServiceId = ServiceHelper.getSelectedServiceId(this);
final StreamingService service = NewPipe.getService(currentServiceId); final StreamingService service = NewPipe.getService(currentServiceId);
@ -169,43 +170,43 @@ public class MainActivity extends AppCompatActivity {
int kioskId = 0; int kioskId = 0;
for (final String ks : service.getKioskList().getAvailableKiosks()) { for (final String ks : service.getKioskList().getAvailableKiosks()) {
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, kioskId, 0, KioskTranslator .add(R.id.menu_tabs_group, kioskId, 0, KioskTranslator
.getTranslatedKioskName(ks, this)) .getTranslatedKioskName(ks, this))
.setIcon(KioskTranslator.getKioskIcon(ks, this)); .setIcon(KioskTranslator.getKioskIcon(ks, this));
kioskId++; kioskId++;
} }
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_SUBSCRIPTIONS, ORDER, .add(R.id.menu_tabs_group, ITEM_ID_SUBSCRIPTIONS, ORDER,
R.string.tab_subscriptions) R.string.tab_subscriptions)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_channel)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_channel));
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_FEED, ORDER, R.string.fragment_feed_title) .add(R.id.menu_tabs_group, ITEM_ID_FEED, ORDER, R.string.fragment_feed_title)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_rss)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_rss));
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_BOOKMARKS, ORDER, R.string.tab_bookmarks) .add(R.id.menu_tabs_group, ITEM_ID_BOOKMARKS, ORDER, R.string.tab_bookmarks)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_bookmark)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_bookmark));
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_DOWNLOADS, ORDER, R.string.downloads) .add(R.id.menu_tabs_group, ITEM_ID_DOWNLOADS, ORDER, R.string.downloads)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_file_download)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_file_download));
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_HISTORY, ORDER, R.string.action_history) .add(R.id.menu_tabs_group, ITEM_ID_HISTORY, ORDER, R.string.action_history)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_history)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_history));
//Settings and About //Settings and About
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_options_about_group, ITEM_ID_SETTINGS, ORDER, R.string.settings) .add(R.id.menu_options_about_group, ITEM_ID_SETTINGS, ORDER, R.string.settings)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_settings)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_settings));
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_options_about_group, ITEM_ID_ABOUT, ORDER, R.string.tab_about) .add(R.id.menu_options_about_group, ITEM_ID_ABOUT, ORDER, R.string.tab_about)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_info_outline)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_info_outline));
toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.drawer_open, toggle = new ActionBarDrawerToggle(this, mainBinding.getRoot(),
R.string.drawer_close); toolbarLayoutBinding.toolbar, R.string.drawer_open, R.string.drawer_close);
toggle.syncState(); toggle.syncState();
drawer.addDrawerListener(toggle); mainBinding.getRoot().addDrawerListener(toggle);
drawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() { mainBinding.getRoot().addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
private int lastService; private int lastService;
@Override @Override
@ -224,7 +225,7 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
drawerItems.setNavigationItemSelectedListener(this::drawerItemSelected); drawerLayoutBinding.navigation.setNavigationItemSelectedListener(this::drawerItemSelected);
setupDrawerHeader(); setupDrawerHeader();
} }
@ -247,15 +248,17 @@ public class MainActivity extends AppCompatActivity {
return false; return false;
} }
drawer.closeDrawers(); mainBinding.getRoot().closeDrawers();
return true; return true;
} }
private void changeService(final MenuItem item) { private void changeService(final MenuItem item) {
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)) drawerLayoutBinding.navigation.getMenu()
.getItem(ServiceHelper.getSelectedServiceId(this))
.setChecked(false); .setChecked(false);
ServiceHelper.setSelectedServiceId(this, item.getItemId()); ServiceHelper.setSelectedServiceId(this, item.getItemId());
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)) drawerLayoutBinding.navigation.getMenu()
.getItem(ServiceHelper.getSelectedServiceId(this))
.setChecked(true); .setChecked(true);
} }
@ -307,26 +310,19 @@ public class MainActivity extends AppCompatActivity {
} }
private void setupDrawerHeader() { private void setupDrawerHeader() {
final NavigationView navigationView = findViewById(R.id.navigation); drawerHeaderBinding.drawerHeaderActionButton.setOnClickListener(view -> toggleServices());
final View hView = navigationView.getHeaderView(0);
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());
// If the current app name is bigger than the default "NewPipe" (7 chars), // If the current app name is bigger than the default "NewPipe" (7 chars),
// let the text view grow a little more as well. // let the text view grow a little more as well.
if (getString(R.string.app_name).length() > "NewPipe".length()) { if (getString(R.string.app_name).length() > "NewPipe".length()) {
final TextView headerTitle = hView.findViewById(R.id.drawer_header_newpipe_title); final ViewGroup.LayoutParams layoutParams =
final ViewGroup.LayoutParams layoutParams = headerTitle.getLayoutParams(); drawerHeaderBinding.drawerHeaderNewpipeTitle.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
headerTitle.setLayoutParams(layoutParams); drawerHeaderBinding.drawerHeaderNewpipeTitle.setLayoutParams(layoutParams);
headerTitle.setMaxLines(2); drawerHeaderBinding.drawerHeaderNewpipeTitle.setMaxLines(2);
headerTitle.setMinWidth(getResources() drawerHeaderBinding.drawerHeaderNewpipeTitle.setMinWidth(getResources()
.getDimensionPixelSize(R.dimen.drawer_header_newpipe_title_default_width)); .getDimensionPixelSize(R.dimen.drawer_header_newpipe_title_default_width));
headerTitle.setMaxWidth(getResources() drawerHeaderBinding.drawerHeaderNewpipeTitle.setMaxWidth(getResources()
.getDimensionPixelSize(R.dimen.drawer_header_newpipe_title_max_width)); .getDimensionPixelSize(R.dimen.drawer_header_newpipe_title_max_width));
} }
} }
@ -334,9 +330,9 @@ public class MainActivity extends AppCompatActivity {
private void toggleServices() { private void toggleServices() {
servicesShown = !servicesShown; servicesShown = !servicesShown;
drawerItems.getMenu().removeGroup(R.id.menu_services_group); drawerLayoutBinding.navigation.getMenu().removeGroup(R.id.menu_services_group);
drawerItems.getMenu().removeGroup(R.id.menu_tabs_group); drawerLayoutBinding.navigation.getMenu().removeGroup(R.id.menu_tabs_group);
drawerItems.getMenu().removeGroup(R.id.menu_options_about_group); drawerLayoutBinding.navigation.getMenu().removeGroup(R.id.menu_options_about_group);
if (servicesShown) { if (servicesShown) {
showServices(); showServices();
@ -350,13 +346,13 @@ public class MainActivity extends AppCompatActivity {
} }
private void showServices() { private void showServices() {
serviceArrow.setImageResource(R.drawable.ic_arrow_drop_up_white_24dp); drawerHeaderBinding.drawerArrow.setImageResource(R.drawable.ic_arrow_drop_up_white_24dp);
for (final StreamingService s : NewPipe.getServices()) { for (final StreamingService s : NewPipe.getServices()) {
final String title = s.getServiceInfo().getName() final String title = s.getServiceInfo().getName()
+ (ServiceHelper.isBeta(s) ? " (beta)" : ""); + (ServiceHelper.isBeta(s) ? " (beta)" : "");
final MenuItem menuItem = drawerItems.getMenu() final MenuItem menuItem = drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_services_group, s.getServiceId(), ORDER, title) .add(R.id.menu_services_group, s.getServiceId(), ORDER, title)
.setIcon(ServiceHelper.getIcon(s.getServiceId())); .setIcon(ServiceHelper.getIcon(s.getServiceId()));
@ -365,15 +361,16 @@ public class MainActivity extends AppCompatActivity {
enhancePeertubeMenu(s, menuItem); enhancePeertubeMenu(s, menuItem);
} }
} }
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)) drawerLayoutBinding.navigation.getMenu()
.getItem(ServiceHelper.getSelectedServiceId(this))
.setChecked(true); .setChecked(true);
} }
private void enhancePeertubeMenu(final StreamingService s, final MenuItem menuItem) { private void enhancePeertubeMenu(final StreamingService s, final MenuItem menuItem) {
final PeertubeInstance currentInstance = PeertubeHelper.getCurrentInstance(); final PeertubeInstance currentInstance = PeertubeHelper.getCurrentInstance();
menuItem.setTitle(currentInstance.getName() + (ServiceHelper.isBeta(s) ? " (beta)" : "")); menuItem.setTitle(currentInstance.getName() + (ServiceHelper.isBeta(s) ? " (beta)" : ""));
final Spinner spinner = (Spinner) LayoutInflater.from(this) final Spinner spinner = InstanceSpinnerLayoutBinding.inflate(LayoutInflater.from(this))
.inflate(R.layout.instance_spinner_layout, null); .getRoot();
final List<PeertubeInstance> instances = PeertubeHelper.getInstanceList(this); final List<PeertubeInstance> instances = PeertubeHelper.getInstanceList(this);
final List<String> items = new ArrayList<>(); final List<String> items = new ArrayList<>();
int defaultSelect = 0; int defaultSelect = 0;
@ -398,7 +395,7 @@ public class MainActivity extends AppCompatActivity {
} }
PeertubeHelper.selectInstance(newInstance, getApplicationContext()); PeertubeHelper.selectInstance(newInstance, getApplicationContext());
changeService(menuItem); changeService(menuItem);
drawer.closeDrawers(); mainBinding.getRoot().closeDrawers();
new Handler(Looper.getMainLooper()).postDelayed(() -> { new Handler(Looper.getMainLooper()).postDelayed(() -> {
getSupportFragmentManager().popBackStack(null, getSupportFragmentManager().popBackStack(null,
FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentManager.POP_BACK_STACK_INCLUSIVE);
@ -415,7 +412,7 @@ public class MainActivity extends AppCompatActivity {
} }
private void showTabs() throws ExtractionException { private void showTabs() throws ExtractionException {
serviceArrow.setImageResource(R.drawable.ic_arrow_drop_down_white_24dp); drawerHeaderBinding.drawerArrow.setImageResource(R.drawable.ic_arrow_drop_down_white_24dp);
//Tabs //Tabs
final int currentServiceId = ServiceHelper.getSelectedServiceId(this); final int currentServiceId = ServiceHelper.getSelectedServiceId(this);
@ -424,34 +421,34 @@ public class MainActivity extends AppCompatActivity {
int kioskId = 0; int kioskId = 0;
for (final String ks : service.getKioskList().getAvailableKiosks()) { for (final String ks : service.getKioskList().getAvailableKiosks()) {
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, kioskId, ORDER, .add(R.id.menu_tabs_group, kioskId, ORDER,
KioskTranslator.getTranslatedKioskName(ks, this)) KioskTranslator.getTranslatedKioskName(ks, this))
.setIcon(KioskTranslator.getKioskIcon(ks, this)); .setIcon(KioskTranslator.getKioskIcon(ks, this));
kioskId++; kioskId++;
} }
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_SUBSCRIPTIONS, ORDER, R.string.tab_subscriptions) .add(R.id.menu_tabs_group, ITEM_ID_SUBSCRIPTIONS, ORDER, R.string.tab_subscriptions)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_channel)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_channel));
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_FEED, ORDER, R.string.fragment_feed_title) .add(R.id.menu_tabs_group, ITEM_ID_FEED, ORDER, R.string.fragment_feed_title)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_rss)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_rss));
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_BOOKMARKS, ORDER, R.string.tab_bookmarks) .add(R.id.menu_tabs_group, ITEM_ID_BOOKMARKS, ORDER, R.string.tab_bookmarks)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_bookmark)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_bookmark));
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_DOWNLOADS, ORDER, R.string.downloads) .add(R.id.menu_tabs_group, ITEM_ID_DOWNLOADS, ORDER, R.string.downloads)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_file_download)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_file_download));
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, ITEM_ID_HISTORY, ORDER, R.string.action_history) .add(R.id.menu_tabs_group, ITEM_ID_HISTORY, ORDER, R.string.action_history)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_history)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_history));
//Settings and About //Settings and About
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_options_about_group, ITEM_ID_SETTINGS, ORDER, R.string.settings) .add(R.id.menu_options_about_group, ITEM_ID_SETTINGS, ORDER, R.string.settings)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_settings)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_settings));
drawerItems.getMenu() drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_options_about_group, ITEM_ID_ABOUT, ORDER, R.string.tab_about) .add(R.id.menu_options_about_group, ITEM_ID_ABOUT, ORDER, R.string.tab_about)
.setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_info_outline)); .setIcon(ThemeHelper.resolveResourceIdFromAttr(this, R.attr.ic_info_outline));
} }
@ -476,16 +473,18 @@ public class MainActivity extends AppCompatActivity {
// Close drawer on return, and don't show animation, // Close drawer on return, and don't show animation,
// so it looks like the drawer isn't open when the user returns to MainActivity // so it looks like the drawer isn't open when the user returns to MainActivity
drawer.closeDrawer(GravityCompat.START, false); mainBinding.getRoot().closeDrawer(GravityCompat.START, false);
try { try {
final int selectedServiceId = ServiceHelper.getSelectedServiceId(this); final int selectedServiceId = ServiceHelper.getSelectedServiceId(this);
final String selectedServiceName = NewPipe.getService(selectedServiceId) final String selectedServiceName = NewPipe.getService(selectedServiceId)
.getServiceInfo().getName(); .getServiceInfo().getName();
headerServiceView.setText(selectedServiceName); drawerHeaderBinding.drawerHeaderServiceView.setText(selectedServiceName);
headerServiceIcon.setImageResource(ServiceHelper.getIcon(selectedServiceId)); drawerHeaderBinding.drawerHeaderServiceIcon.setImageResource(ServiceHelper
.getIcon(selectedServiceId));
headerServiceView.post(() -> headerServiceView.setSelected(true)); drawerHeaderBinding.drawerHeaderServiceView.post(() -> drawerHeaderBinding
toggleServiceButton.setContentDescription( .drawerHeaderServiceView.setSelected(true));
drawerHeaderBinding.drawerHeaderActionButton.setContentDescription(
getString(R.string.drawer_header_description) + selectedServiceName); getString(R.string.drawer_header_description) + selectedServiceName);
} catch (final Exception e) { } catch (final Exception e) {
ErrorActivity.reportUiError(this, e); ErrorActivity.reportUiError(this, e);
@ -511,7 +510,8 @@ public class MainActivity extends AppCompatActivity {
final boolean isHistoryEnabled = sharedPreferences.getBoolean( final boolean isHistoryEnabled = sharedPreferences.getBoolean(
getString(R.string.enable_watch_history_key), true); getString(R.string.enable_watch_history_key), true);
drawerItems.getMenu().findItem(ITEM_ID_HISTORY).setVisible(isHistoryEnabled); drawerLayoutBinding.navigation.getMenu().findItem(ITEM_ID_HISTORY)
.setVisible(isHistoryEnabled);
} }
@Override @Override
@ -555,9 +555,8 @@ public class MainActivity extends AppCompatActivity {
} }
if (DeviceUtils.isTv(this)) { if (DeviceUtils.isTv(this)) {
final View drawerPanel = findViewById(R.id.navigation); if (mainBinding.getRoot().isDrawerOpen(drawerLayoutBinding.navigation)) {
if (drawer.isDrawerOpen(drawerPanel)) { mainBinding.getRoot().closeDrawers();
drawer.closeDrawers();
return; return;
} }
} }
@ -583,9 +582,7 @@ public class MainActivity extends AppCompatActivity {
// delegate the back press to it // delegate the back press to it
if (fragmentPlayer instanceof BackPressable) { if (fragmentPlayer instanceof BackPressable) {
if (!((BackPressable) fragmentPlayer).onBackPressed()) { if (!((BackPressable) fragmentPlayer).onBackPressed()) {
final FrameLayout bottomSheetLayout = BottomSheetBehavior.from(mainBinding.fragmentPlayerHolder)
findViewById(R.id.fragment_player_holder);
BottomSheetBehavior.from(bottomSheetLayout)
.setState(BottomSheetBehavior.STATE_COLLAPSED); .setState(BottomSheetBehavior.STATE_COLLAPSED);
} }
return; return;
@ -668,8 +665,7 @@ public class MainActivity extends AppCompatActivity {
final Fragment fragment final Fragment fragment
= getSupportFragmentManager().findFragmentById(R.id.fragment_holder); = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
if (!(fragment instanceof SearchFragment)) { if (!(fragment instanceof SearchFragment)) {
findViewById(R.id.toolbar).findViewById(R.id.toolbar_search_container) toolbarLayoutBinding.toolbarSearchContainer.getRoot().setVisibility(View.GONE);
.setVisibility(View.GONE);
} }
final ActionBar actionBar = getSupportActionBar(); final ActionBar actionBar = getSupportActionBar();
@ -730,21 +726,20 @@ public class MainActivity extends AppCompatActivity {
return; return;
} }
final Toolbar toolbar = findViewById(R.id.toolbar);
final Fragment fragment = getSupportFragmentManager() final Fragment fragment = getSupportFragmentManager()
.findFragmentById(R.id.fragment_holder); .findFragmentById(R.id.fragment_holder);
if (fragment instanceof MainFragment) { if (fragment instanceof MainFragment) {
getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(false);
if (toggle != null) { if (toggle != null) {
toggle.syncState(); toggle.syncState();
toolbar.setNavigationOnClickListener(v -> drawer.openDrawer(GravityCompat.START)); toolbarLayoutBinding.toolbar.setNavigationOnClickListener(v -> mainBinding.getRoot()
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED); .openDrawer(GravityCompat.START));
mainBinding.getRoot().setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED);
} }
} else { } else {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); mainBinding.getRoot().setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationOnClickListener(v -> onHomeButtonPressed()); toolbarLayoutBinding.toolbar.setNavigationOnClickListener(v -> onHomeButtonPressed());
} }
} }
@ -852,9 +847,8 @@ public class MainActivity extends AppCompatActivity {
} }
private boolean bottomSheetHiddenOrCollapsed() { private boolean bottomSheetHiddenOrCollapsed() {
final FrameLayout bottomSheetLayout = findViewById(R.id.fragment_player_holder);
final BottomSheetBehavior<FrameLayout> bottomSheetBehavior = final BottomSheetBehavior<FrameLayout> bottomSheetBehavior =
BottomSheetBehavior.from(bottomSheetLayout); BottomSheetBehavior.from(mainBinding.fragmentPlayerHolder);
final int sheetState = bottomSheetBehavior.getState(); final int sheetState = bottomSheetBehavior.getState();
return sheetState == BottomSheetBehavior.STATE_HIDDEN return sheetState == BottomSheetBehavior.STATE_HIDDEN

View File

@ -18,10 +18,10 @@ import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.NavUtils; import androidx.core.app.NavUtils;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import org.schabi.newpipe.databinding.ActivityRecaptchaBinding;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@ -62,30 +62,28 @@ public class ReCaptchaActivity extends AppCompatActivity {
} }
} }
private ActivityRecaptchaBinding recaptchaBinding;
private WebView webView;
private String foundCookies = ""; private String foundCookies = "";
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
ThemeHelper.setTheme(this); ThemeHelper.setTheme(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recaptcha);
final Toolbar toolbar = findViewById(R.id.toolbar); recaptchaBinding = ActivityRecaptchaBinding.inflate(getLayoutInflater());
setSupportActionBar(toolbar); setContentView(recaptchaBinding.getRoot());
setSupportActionBar(recaptchaBinding.toolbar);
final String url = sanitizeRecaptchaUrl(getIntent().getStringExtra(RECAPTCHA_URL_EXTRA)); final String url = sanitizeRecaptchaUrl(getIntent().getStringExtra(RECAPTCHA_URL_EXTRA));
// set return to Cancel by default // set return to Cancel by default
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);
webView = findViewById(R.id.reCaptchaWebView);
// enable Javascript // enable Javascript
final WebSettings webSettings = webView.getSettings(); final WebSettings webSettings = recaptchaBinding.reCaptchaWebView.getSettings();
webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptEnabled(true);
webSettings.setUserAgentString(DownloaderImpl.USER_AGENT); webSettings.setUserAgentString(DownloaderImpl.USER_AGENT);
webView.setWebViewClient(new WebViewClient() { recaptchaBinding.reCaptchaWebView.setWebViewClient(new WebViewClient() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override @Override
public boolean shouldOverrideUrlLoading(final WebView view, public boolean shouldOverrideUrlLoading(final WebView view,
@ -117,16 +115,16 @@ public class ReCaptchaActivity extends AppCompatActivity {
}); });
// cleaning cache, history and cookies from webView // cleaning cache, history and cookies from webView
webView.clearCache(true); recaptchaBinding.reCaptchaWebView.clearCache(true);
webView.clearHistory(); recaptchaBinding.reCaptchaWebView.clearHistory();
final android.webkit.CookieManager cookieManager = CookieManager.getInstance(); final CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.removeAllCookies(value -> { }); cookieManager.removeAllCookies(value -> { });
} else { } else {
cookieManager.removeAllCookie(); cookieManager.removeAllCookie();
} }
webView.loadUrl(url); recaptchaBinding.reCaptchaWebView.loadUrl(url);
} }
@Override @Override
@ -158,7 +156,8 @@ public class ReCaptchaActivity extends AppCompatActivity {
} }
private void saveCookiesAndFinish() { private void saveCookiesAndFinish() {
handleCookiesFromUrl(webView.getUrl()); // try to get cookies of unclosed page // try to get cookies of unclosed page
handleCookiesFromUrl(recaptchaBinding.reCaptchaWebView.getUrl());
if (MainActivity.DEBUG) { if (MainActivity.DEBUG) {
Log.d(TAG, "saveCookiesAndFinish: foundCookies=" + foundCookies); Log.d(TAG, "saveCookiesAndFinish: foundCookies=" + foundCookies);
} }

View File

@ -14,7 +14,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import android.widget.Toast; import android.widget.Toast;
@ -30,6 +29,8 @@ import androidx.core.widget.TextViewCompat;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import org.schabi.newpipe.databinding.ListRadioIconItemBinding;
import org.schabi.newpipe.databinding.SingleChoiceDialogViewBinding;
import org.schabi.newpipe.download.DownloadDialog; import org.schabi.newpipe.download.DownloadDialog;
import org.schabi.newpipe.extractor.Info; import org.schabi.newpipe.extractor.Info;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
@ -267,9 +268,8 @@ public class RouterActivity extends AppCompatActivity {
final Context themeWrapperContext = getThemeWrapperContext(); final Context themeWrapperContext = getThemeWrapperContext();
final LayoutInflater inflater = LayoutInflater.from(themeWrapperContext); final LayoutInflater inflater = LayoutInflater.from(themeWrapperContext);
final LinearLayout rootLayout = (LinearLayout) inflater.inflate( final RadioGroup radioGroup = SingleChoiceDialogViewBinding.inflate(getLayoutInflater())
R.layout.single_choice_dialog_view, null, false); .list;
final RadioGroup radioGroup = rootLayout.findViewById(android.R.id.list);
final DialogInterface.OnClickListener dialogButtonsClickListener = (dialog, which) -> { final DialogInterface.OnClickListener dialogButtonsClickListener = (dialog, which) -> {
final int indexOfChild = radioGroup.indexOfChild( final int indexOfChild = radioGroup.indexOfChild(
@ -322,8 +322,7 @@ public class RouterActivity extends AppCompatActivity {
int id = 12345; int id = 12345;
for (final AdapterChoiceItem item : choices) { for (final AdapterChoiceItem item : choices) {
final RadioButton radioButton final RadioButton radioButton = ListRadioIconItemBinding.inflate(inflater).getRoot();
= (RadioButton) inflater.inflate(R.layout.list_radio_icon_item, null);
radioButton.setText(item.description); radioButton.setText(item.description);
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(radioButton, TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(radioButton,
AppCompatResources.getDrawable(getApplicationContext(), item.icon), AppCompatResources.getDrawable(getApplicationContext(), item.icon),

View File

@ -6,22 +6,19 @@ import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator; import com.google.android.material.tabs.TabLayoutMediator;
import org.schabi.newpipe.BuildConfig; import org.schabi.newpipe.BuildConfig;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.ActivityAboutBinding;
import org.schabi.newpipe.databinding.FragmentAboutBinding;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
@ -68,40 +65,27 @@ public class AboutActivity extends AppCompatActivity {
private static final int POS_ABOUT = 0; private static final int POS_ABOUT = 0;
private static final int POS_LICENSE = 1; private static final int POS_LICENSE = 1;
private static final int TOTAL_COUNT = 2; private static final int TOTAL_COUNT = 2;
/**
* The {@link RecyclerView.Adapter} that will provide
* fragments for each of the sections. We use a
* {@link FragmentStateAdapter} derivative, which will keep every
* loaded fragment in memory.
*/
private SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager2} that will host the section contents.
*/
private ViewPager2 mViewPager;
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
assureCorrectAppLanguage(this); assureCorrectAppLanguage(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ThemeHelper.setTheme(this); ThemeHelper.setTheme(this);
this.setTitle(getString(R.string.title_activity_about)); setTitle(getString(R.string.title_activity_about));
setContentView(R.layout.activity_about); final ActivityAboutBinding aboutBinding = ActivityAboutBinding.inflate(getLayoutInflater());
setContentView(aboutBinding.getRoot());
final Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(aboutBinding.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Create the adapter that will return a fragment for each of the three // Create the adapter that will return a fragment for each of the three
// primary sections of the activity. // primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(this); final SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(this);
// Set up the ViewPager with the sections adapter. // Set up the ViewPager with the sections adapter.
mViewPager = findViewById(R.id.container); aboutBinding.container.setAdapter(mSectionsPagerAdapter);
mViewPager.setAdapter(mSectionsPagerAdapter);
final TabLayout tabLayout = findViewById(R.id.tabs); new TabLayoutMediator(aboutBinding.tabs, aboutBinding.container, (tab, position) -> {
new TabLayoutMediator(tabLayout, mViewPager, (tab, position) -> {
switch (position) { switch (position) {
default: default:
case POS_ABOUT: case POS_ABOUT:
@ -143,33 +127,28 @@ public class AboutActivity extends AppCompatActivity {
} }
@Override @Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) { final Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_about, container, false); final FragmentAboutBinding aboutBinding =
final Context context = this.getContext(); FragmentAboutBinding.inflate(inflater, container, false);
final Context context = getContext();
final TextView version = rootView.findViewById(R.id.app_version); aboutBinding.appVersion.setText(BuildConfig.VERSION_NAME);
version.setText(BuildConfig.VERSION_NAME);
final View githubLink = rootView.findViewById(R.id.github_link); aboutBinding.githubLink.setOnClickListener(nv ->
githubLink.setOnClickListener(nv ->
openUrlInBrowser(context, context.getString(R.string.github_url))); openUrlInBrowser(context, context.getString(R.string.github_url)));
final View donationLink = rootView.findViewById(R.id.donation_link); aboutBinding.donationLink.setOnClickListener(v ->
donationLink.setOnClickListener(v ->
openUrlInBrowser(context, context.getString(R.string.donation_url))); openUrlInBrowser(context, context.getString(R.string.donation_url)));
final View websiteLink = rootView.findViewById(R.id.website_link); aboutBinding.websiteLink.setOnClickListener(nv ->
websiteLink.setOnClickListener(nv ->
openUrlInBrowser(context, context.getString(R.string.website_url))); openUrlInBrowser(context, context.getString(R.string.website_url)));
final View privacyPolicyLink = rootView.findViewById(R.id.privacy_policy_link); aboutBinding.privacyPolicyLink.setOnClickListener(v ->
privacyPolicyLink.setOnClickListener(v ->
openUrlInBrowser(context, context.getString(R.string.privacy_policy_url))); openUrlInBrowser(context, context.getString(R.string.privacy_policy_url)));
return rootView; return aboutBinding.getRoot();
} }
} }
/** /**

View File

@ -9,10 +9,10 @@ import android.view.ViewTreeObserver;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.ActivityDownloaderBinding;
import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
import org.schabi.newpipe.views.FocusOverlayView; import org.schabi.newpipe.views.FocusOverlayView;
@ -35,11 +35,14 @@ public class DownloadActivity extends AppCompatActivity {
assureCorrectAppLanguage(this); assureCorrectAppLanguage(this);
ThemeHelper.setTheme(this); ThemeHelper.setTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_downloader);
final Toolbar toolbar = findViewById(R.id.toolbar); super.onCreate(savedInstanceState);
setSupportActionBar(toolbar);
final ActivityDownloaderBinding downloaderBinding =
ActivityDownloaderBinding.inflate(getLayoutInflater());
setContentView(downloaderBinding.getRoot());
setSupportActionBar(downloaderBinding.toolbarLayout.toolbar);
final ActionBar actionBar = getSupportActionBar(); final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) { if (actionBar != null) {

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.player; package org.schabi.newpipe.player;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.Bundle; import android.os.Bundle;
@ -11,15 +12,10 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import android.widget.ProgressBar;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
@ -29,6 +25,7 @@ import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.ActivityPlayerQueueControlBinding;
import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
@ -70,30 +67,10 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
// Views // Views
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
private View rootView; private ActivityPlayerQueueControlBinding queueControlBinding;
private RecyclerView itemsList;
private ItemTouchHelper itemTouchHelper; private ItemTouchHelper itemTouchHelper;
private LinearLayout metadata;
private TextView metadataTitle;
private TextView metadataArtist;
private SeekBar progressSeekBar;
private TextView progressCurrentTime;
private TextView progressEndTime;
private TextView progressLiveSync;
private TextView seekDisplay;
private ImageButton repeatButton;
private ImageButton backwardButton;
private ImageButton fastRewindButton;
private ImageButton playPauseButton;
private ImageButton fastForwardButton;
private ImageButton forwardButton;
private ImageButton shuffleButton;
private ProgressBar progressBar;
private Menu menu; private Menu menu;
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -123,11 +100,11 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
assureCorrectAppLanguage(this); assureCorrectAppLanguage(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ThemeHelper.setTheme(this); ThemeHelper.setTheme(this);
setContentView(R.layout.activity_player_queue_control);
rootView = findViewById(R.id.main_content);
final Toolbar toolbar = rootView.findViewById(R.id.toolbar); queueControlBinding = ActivityPlayerQueueControlBinding.inflate(getLayoutInflater());
setSupportActionBar(toolbar); setContentView(queueControlBinding.getRoot());
setSupportActionBar(queueControlBinding.toolbar);
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(getSupportActionTitle()); getSupportActionBar().setTitle(getSupportActionTitle());
@ -230,14 +207,11 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
if (player != null && player.getPlayQueueAdapter() != null) { if (player != null && player.getPlayQueueAdapter() != null) {
player.getPlayQueueAdapter().unsetSelectedListener(); player.getPlayQueueAdapter().unsetSelectedListener();
} }
if (itemsList != null) { queueControlBinding.playQueue.setAdapter(null);
itemsList.setAdapter(null);
}
if (itemTouchHelper != null) { if (itemTouchHelper != null) {
itemTouchHelper.attachToRecyclerView(null); itemTouchHelper.attachToRecyclerView(null);
} }
itemsList = null;
itemTouchHelper = null; itemTouchHelper = null;
player = null; player = null;
} }
@ -284,58 +258,38 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
} }
private void buildQueue() { private void buildQueue() {
itemsList = findViewById(R.id.play_queue); queueControlBinding.playQueue.setLayoutManager(new LinearLayoutManager(this));
itemsList.setLayoutManager(new LinearLayoutManager(this)); queueControlBinding.playQueue.setAdapter(player.getPlayQueueAdapter());
itemsList.setAdapter(player.getPlayQueueAdapter()); queueControlBinding.playQueue.setClickable(true);
itemsList.setClickable(true); queueControlBinding.playQueue.setLongClickable(true);
itemsList.setLongClickable(true); queueControlBinding.playQueue.clearOnScrollListeners();
itemsList.clearOnScrollListeners(); queueControlBinding.playQueue.addOnScrollListener(getQueueScrollListener());
itemsList.addOnScrollListener(getQueueScrollListener());
itemTouchHelper = new ItemTouchHelper(getItemTouchCallback()); itemTouchHelper = new ItemTouchHelper(getItemTouchCallback());
itemTouchHelper.attachToRecyclerView(itemsList); itemTouchHelper.attachToRecyclerView(queueControlBinding.playQueue);
player.getPlayQueueAdapter().setSelectedListener(getOnSelectedListener()); player.getPlayQueueAdapter().setSelectedListener(getOnSelectedListener());
} }
private void buildMetadata() { private void buildMetadata() {
metadata = rootView.findViewById(R.id.metadata); queueControlBinding.metadata.setOnClickListener(this);
metadataTitle = rootView.findViewById(R.id.song_name); queueControlBinding.songName.setSelected(true);
metadataArtist = rootView.findViewById(R.id.artist_name); queueControlBinding.artistName.setSelected(true);
metadata.setOnClickListener(this);
metadataTitle.setSelected(true);
metadataArtist.setSelected(true);
} }
private void buildSeekBar() { private void buildSeekBar() {
progressCurrentTime = rootView.findViewById(R.id.current_time); queueControlBinding.seekBar.setOnSeekBarChangeListener(this);
progressSeekBar = rootView.findViewById(R.id.seek_bar); queueControlBinding.liveSync.setOnClickListener(this);
progressEndTime = rootView.findViewById(R.id.end_time);
progressLiveSync = rootView.findViewById(R.id.live_sync);
seekDisplay = rootView.findViewById(R.id.seek_display);
progressSeekBar.setOnSeekBarChangeListener(this);
progressLiveSync.setOnClickListener(this);
} }
private void buildControls() { private void buildControls() {
repeatButton = rootView.findViewById(R.id.control_repeat); queueControlBinding.controlRepeat.setOnClickListener(this);
backwardButton = rootView.findViewById(R.id.control_backward); queueControlBinding.controlBackward.setOnClickListener(this);
fastRewindButton = rootView.findViewById(R.id.control_fast_rewind); queueControlBinding.controlFastRewind.setOnClickListener(this);
playPauseButton = rootView.findViewById(R.id.control_play_pause); queueControlBinding.controlPlayPause.setOnClickListener(this);
fastForwardButton = rootView.findViewById(R.id.control_fast_forward); queueControlBinding.controlFastForward.setOnClickListener(this);
forwardButton = rootView.findViewById(R.id.control_forward); queueControlBinding.controlForward.setOnClickListener(this);
shuffleButton = rootView.findViewById(R.id.control_shuffle); queueControlBinding.controlShuffle.setOnClickListener(this);
progressBar = rootView.findViewById(R.id.control_progress_bar);
repeatButton.setOnClickListener(this);
backwardButton.setOnClickListener(this);
fastRewindButton.setOnClickListener(this);
playPauseButton.setOnClickListener(this);
fastForwardButton.setOnClickListener(this);
forwardButton.setOnClickListener(this);
shuffleButton.setOnClickListener(this);
} }
private void buildItemPopupMenu(final PlayQueueItem item, final View view) { private void buildItemPopupMenu(final PlayQueueItem item, final View view) {
@ -391,8 +345,8 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
if (player != null && player.getPlayQueue() != null if (player != null && player.getPlayQueue() != null
&& !player.getPlayQueue().isComplete()) { && !player.getPlayQueue().isComplete()) {
player.getPlayQueue().fetch(); player.getPlayQueue().fetch();
} else if (itemsList != null) { } else {
itemsList.clearOnScrollListeners(); queueControlBinding.playQueue.clearOnScrollListeners();
} }
} }
}; };
@ -453,8 +407,9 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
final int currentPlayingIndex = player.getPlayQueue().getIndex(); final int currentPlayingIndex = player.getPlayQueue().getIndex();
final int currentVisibleIndex; final int currentVisibleIndex;
if (itemsList.getLayoutManager() instanceof LinearLayoutManager) { if (queueControlBinding.playQueue.getLayoutManager() instanceof LinearLayoutManager) {
final LinearLayoutManager layout = ((LinearLayoutManager) itemsList.getLayoutManager()); final LinearLayoutManager layout =
(LinearLayoutManager) queueControlBinding.playQueue.getLayoutManager();
currentVisibleIndex = layout.findFirstVisibleItemPosition(); currentVisibleIndex = layout.findFirstVisibleItemPosition();
} else { } else {
currentVisibleIndex = 0; currentVisibleIndex = 0;
@ -462,9 +417,9 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
final int distance = Math.abs(currentPlayingIndex - currentVisibleIndex); final int distance = Math.abs(currentPlayingIndex - currentVisibleIndex);
if (distance < SMOOTH_SCROLL_MAXIMUM_DISTANCE) { if (distance < SMOOTH_SCROLL_MAXIMUM_DISTANCE) {
itemsList.smoothScrollToPosition(currentPlayingIndex); queueControlBinding.playQueue.smoothScrollToPosition(currentPlayingIndex);
} else { } else {
itemsList.scrollToPosition(currentPlayingIndex); queueControlBinding.playQueue.scrollToPosition(currentPlayingIndex);
} }
} }
@ -478,23 +433,23 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
return; return;
} }
if (view.getId() == repeatButton.getId()) { if (view.getId() == queueControlBinding.controlRepeat.getId()) {
player.onRepeatClicked(); player.onRepeatClicked();
} else if (view.getId() == backwardButton.getId()) { } else if (view.getId() == queueControlBinding.controlBackward.getId()) {
player.onPlayPrevious(); player.onPlayPrevious();
} else if (view.getId() == fastRewindButton.getId()) { } else if (view.getId() == queueControlBinding.controlFastRewind.getId()) {
player.onFastRewind(); player.onFastRewind();
} else if (view.getId() == playPauseButton.getId()) { } else if (view.getId() == queueControlBinding.controlPlayPause.getId()) {
player.onPlayPause(); player.onPlayPause();
} else if (view.getId() == fastForwardButton.getId()) { } else if (view.getId() == queueControlBinding.controlFastForward.getId()) {
player.onFastForward(); player.onFastForward();
} else if (view.getId() == forwardButton.getId()) { } else if (view.getId() == queueControlBinding.controlForward.getId()) {
player.onPlayNext(); player.onPlayNext();
} else if (view.getId() == shuffleButton.getId()) { } else if (view.getId() == queueControlBinding.controlShuffle.getId()) {
player.onShuffleClicked(); player.onShuffleClicked();
} else if (view.getId() == metadata.getId()) { } else if (view.getId() == queueControlBinding.metadata.getId()) {
scrollToSelected(); scrollToSelected();
} else if (view.getId() == progressLiveSync.getId()) { } else if (view.getId() == queueControlBinding.liveSync.getId()) {
player.seekToDefault(); player.seekToDefault();
} }
} }
@ -528,15 +483,15 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
final boolean fromUser) { final boolean fromUser) {
if (fromUser) { if (fromUser) {
final String seekTime = Localization.getDurationString(progress / 1000); final String seekTime = Localization.getDurationString(progress / 1000);
progressCurrentTime.setText(seekTime); queueControlBinding.currentTime.setText(seekTime);
seekDisplay.setText(seekTime); queueControlBinding.seekDisplay.setText(seekTime);
} }
} }
@Override @Override
public void onStartTrackingTouch(final SeekBar seekBar) { public void onStartTrackingTouch(final SeekBar seekBar) {
seeking = true; seeking = true;
seekDisplay.setVisibility(View.VISIBLE); queueControlBinding.seekDisplay.setVisibility(View.VISIBLE);
} }
@Override @Override
@ -544,7 +499,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
if (player != null) { if (player != null) {
player.seekTo(seekBar.getProgress()); player.seekTo(seekBar.getProgress());
} }
seekDisplay.setVisibility(View.GONE); queueControlBinding.seekDisplay.setVisibility(View.GONE);
seeking = false; seeking = false;
} }
@ -602,45 +557,46 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
public void onProgressUpdate(final int currentProgress, final int duration, public void onProgressUpdate(final int currentProgress, final int duration,
final int bufferPercent) { final int bufferPercent) {
// Set buffer progress // Set buffer progress
progressSeekBar.setSecondaryProgress((int) (progressSeekBar.getMax() queueControlBinding.seekBar.setSecondaryProgress((int) (queueControlBinding.seekBar.getMax()
* ((float) bufferPercent / 100))); * ((float) bufferPercent / 100)));
// Set Duration // Set Duration
progressSeekBar.setMax(duration); queueControlBinding.seekBar.setMax(duration);
progressEndTime.setText(Localization.getDurationString(duration / 1000)); queueControlBinding.endTime.setText(Localization.getDurationString(duration / 1000));
// Set current time if not seeking // Set current time if not seeking
if (!seeking) { if (!seeking) {
progressSeekBar.setProgress(currentProgress); queueControlBinding.seekBar.setProgress(currentProgress);
progressCurrentTime.setText(Localization.getDurationString(currentProgress / 1000)); queueControlBinding.currentTime.setText(Localization
.getDurationString(currentProgress / 1000));
} }
if (player != null) { if (player != null) {
progressLiveSync.setClickable(!player.isLiveEdge()); queueControlBinding.liveSync.setClickable(!player.isLiveEdge());
} }
// this will make sure progressCurrentTime has the same width as progressEndTime // this will make sure progressCurrentTime has the same width as progressEndTime
final ViewGroup.LayoutParams endTimeParams = progressEndTime.getLayoutParams(); final ViewGroup.LayoutParams currentTimeParams =
final ViewGroup.LayoutParams currentTimeParams = progressCurrentTime.getLayoutParams(); queueControlBinding.currentTime.getLayoutParams();
currentTimeParams.width = progressEndTime.getWidth(); currentTimeParams.width = queueControlBinding.endTime.getWidth();
progressCurrentTime.setLayoutParams(currentTimeParams); queueControlBinding.currentTime.setLayoutParams(currentTimeParams);
} }
@Override @Override
public void onMetadataUpdate(final StreamInfo info, final PlayQueue queue) { public void onMetadataUpdate(final StreamInfo info, final PlayQueue queue) {
if (info != null) { if (info != null) {
metadataTitle.setText(info.getName()); queueControlBinding.songName.setText(info.getName());
metadataArtist.setText(info.getUploaderName()); queueControlBinding.artistName.setText(info.getUploaderName());
progressEndTime.setVisibility(View.GONE); queueControlBinding.endTime.setVisibility(View.GONE);
progressLiveSync.setVisibility(View.GONE); queueControlBinding.liveSync.setVisibility(View.GONE);
switch (info.getStreamType()) { switch (info.getStreamType()) {
case LIVE_STREAM: case LIVE_STREAM:
case AUDIO_LIVE_STREAM: case AUDIO_LIVE_STREAM:
progressLiveSync.setVisibility(View.VISIBLE); queueControlBinding.liveSync.setVisibility(View.VISIBLE);
break; break;
default: default:
progressEndTime.setVisibility(View.VISIBLE); queueControlBinding.endTime.setVisibility(View.VISIBLE);
break; break;
} }
@ -661,13 +617,16 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
private void onStateChanged(final int state) { private void onStateChanged(final int state) {
switch (state) { switch (state) {
case BasePlayer.STATE_PAUSED: case BasePlayer.STATE_PAUSED:
playPauseButton.setImageResource(R.drawable.ic_play_arrow_white_24dp); queueControlBinding.controlPlayPause
.setImageResource(R.drawable.ic_play_arrow_white_24dp);
break; break;
case BasePlayer.STATE_PLAYING: case BasePlayer.STATE_PLAYING:
playPauseButton.setImageResource(R.drawable.ic_pause_white_24dp); queueControlBinding.controlPlayPause
.setImageResource(R.drawable.ic_pause_white_24dp);
break; break;
case BasePlayer.STATE_COMPLETED: case BasePlayer.STATE_COMPLETED:
playPauseButton.setImageResource(R.drawable.ic_replay_white_24dp); queueControlBinding.controlPlayPause
.setImageResource(R.drawable.ic_replay_white_24dp);
break; break;
default: default:
break; break;
@ -677,14 +636,14 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
case BasePlayer.STATE_PAUSED: case BasePlayer.STATE_PAUSED:
case BasePlayer.STATE_PLAYING: case BasePlayer.STATE_PLAYING:
case BasePlayer.STATE_COMPLETED: case BasePlayer.STATE_COMPLETED:
playPauseButton.setClickable(true); queueControlBinding.controlPlayPause.setClickable(true);
playPauseButton.setVisibility(View.VISIBLE); queueControlBinding.controlPlayPause.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE); queueControlBinding.progressBar.setVisibility(View.GONE);
break; break;
default: default:
playPauseButton.setClickable(false); queueControlBinding.controlPlayPause.setClickable(false);
playPauseButton.setVisibility(View.INVISIBLE); queueControlBinding.controlPlayPause.setVisibility(View.INVISIBLE);
progressBar.setVisibility(View.VISIBLE); queueControlBinding.progressBar.setVisibility(View.VISIBLE);
break; break;
} }
} }
@ -692,18 +651,21 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
private void onPlayModeChanged(final int repeatMode, final boolean shuffled) { private void onPlayModeChanged(final int repeatMode, final boolean shuffled) {
switch (repeatMode) { switch (repeatMode) {
case Player.REPEAT_MODE_OFF: case Player.REPEAT_MODE_OFF:
repeatButton.setImageResource(R.drawable.exo_controls_repeat_off); queueControlBinding.controlRepeat
.setImageResource(R.drawable.exo_controls_repeat_off);
break; break;
case Player.REPEAT_MODE_ONE: case Player.REPEAT_MODE_ONE:
repeatButton.setImageResource(R.drawable.exo_controls_repeat_one); queueControlBinding.controlRepeat
.setImageResource(R.drawable.exo_controls_repeat_one);
break; break;
case Player.REPEAT_MODE_ALL: case Player.REPEAT_MODE_ALL:
repeatButton.setImageResource(R.drawable.exo_controls_repeat_all); queueControlBinding.controlRepeat
.setImageResource(R.drawable.exo_controls_repeat_all);
break; break;
} }
final int shuffleAlpha = shuffled ? 255 : 77; final int shuffleAlpha = shuffled ? 255 : 77;
shuffleButton.setImageAlpha(shuffleAlpha); queueControlBinding.controlShuffle.setImageAlpha(shuffleAlpha);
} }
private void onPlaybackParameterChanged(final PlaybackParameters parameters) { private void onPlaybackParameterChanged(final PlaybackParameters parameters) {
@ -716,12 +678,13 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
} }
private void onMaybePlaybackAdapterChanged() { private void onMaybePlaybackAdapterChanged() {
if (itemsList == null || player == null) { if (player == null) {
return; return;
} }
final PlayQueueAdapter maybeNewAdapter = player.getPlayQueueAdapter(); final PlayQueueAdapter maybeNewAdapter = player.getPlayQueueAdapter();
if (maybeNewAdapter != null && itemsList.getAdapter() != maybeNewAdapter) { if (maybeNewAdapter != null
itemsList.setAdapter(maybeNewAdapter); && queueControlBinding.playQueue.getAdapter() != maybeNewAdapter) {
queueControlBinding.playQueue.setAdapter(maybeNewAdapter);
} }
} }
@ -735,7 +698,8 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
//2) Icon change accordingly to current App Theme //2) Icon change accordingly to current App Theme
// using rootView.getContext() because getApplicationContext() didn't work // using rootView.getContext() because getApplicationContext() didn't work
item.setIcon(ThemeHelper.resolveResourceIdFromAttr(rootView.getContext(), final Context context = queueControlBinding.getRoot().getContext();
item.setIcon(ThemeHelper.resolveResourceIdFromAttr(context,
player.isMuted() player.isMuted()
? R.attr.ic_volume_off ? R.attr.ic_volume_off
: R.attr.ic_volume_up)); : R.attr.ic_volume_up));

View File

@ -14,15 +14,11 @@ import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.NavUtils; import androidx.core.app.NavUtils;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -34,6 +30,7 @@ import org.schabi.newpipe.ActivityCommunicator;
import org.schabi.newpipe.BuildConfig; import org.schabi.newpipe.BuildConfig;
import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.ActivityErrorBinding;
import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.ShareUtils;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
@ -87,7 +84,8 @@ public class ErrorActivity extends AppCompatActivity {
private ErrorInfo errorInfo; private ErrorInfo errorInfo;
private Class returnActivity; private Class returnActivity;
private String currentTimeStamp; private String currentTimeStamp;
private EditText userCommentBox;
private ActivityErrorBinding activityErrorBinding;
public static void reportUiError(final AppCompatActivity activity, final Throwable el) { public static void reportUiError(final AppCompatActivity activity, final Throwable el) {
reportError(activity, el, activity.getClass(), null, ErrorInfo.make(UserAction.UI_ERROR, reportError(activity, el, activity.getClass(), null, ErrorInfo.make(UserAction.UI_ERROR,
@ -181,12 +179,13 @@ public class ErrorActivity extends AppCompatActivity {
assureCorrectAppLanguage(this); assureCorrectAppLanguage(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ThemeHelper.setTheme(this); ThemeHelper.setTheme(this);
setContentView(R.layout.activity_error);
activityErrorBinding = ActivityErrorBinding.inflate(getLayoutInflater());
setContentView(activityErrorBinding.getRoot());
final Intent intent = getIntent(); final Intent intent = getIntent();
final Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(activityErrorBinding.toolbarLayout.toolbar);
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar(); final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) { if (actionBar != null) {
@ -195,15 +194,6 @@ public class ErrorActivity extends AppCompatActivity {
actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowTitleEnabled(true);
} }
final Button reportEmailButton = findViewById(R.id.errorReportEmailButton);
final Button copyButton = findViewById(R.id.errorReportCopyButton);
final Button reportGithubButton = findViewById(R.id.errorReportGitHubButton);
userCommentBox = findViewById(R.id.errorCommentBox);
final TextView errorView = findViewById(R.id.errorView);
final TextView infoView = findViewById(R.id.errorInfosView);
final TextView errorMessageView = findViewById(R.id.errorMessageView);
final ActivityCommunicator ac = ActivityCommunicator.getCommunicator(); final ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
returnActivity = ac.getReturnActivity(); returnActivity = ac.getReturnActivity();
errorInfo = intent.getParcelableExtra(ERROR_INFO); errorInfo = intent.getParcelableExtra(ERROR_INFO);
@ -213,28 +203,27 @@ public class ErrorActivity extends AppCompatActivity {
addGuruMeditation(); addGuruMeditation();
currentTimeStamp = getCurrentTimeStamp(); currentTimeStamp = getCurrentTimeStamp();
reportEmailButton.setOnClickListener(v -> activityErrorBinding.errorReportEmailButton.setOnClickListener(v ->
openPrivacyPolicyDialog(this, "EMAIL")); openPrivacyPolicyDialog(this, "EMAIL"));
copyButton.setOnClickListener(v -> { activityErrorBinding.errorReportCopyButton.setOnClickListener(v -> {
ShareUtils.copyToClipboard(this, buildMarkdown()); ShareUtils.copyToClipboard(this, buildMarkdown());
Toast.makeText(this, R.string.msg_copied, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.msg_copied, Toast.LENGTH_SHORT).show();
}); });
reportGithubButton.setOnClickListener(v -> activityErrorBinding.errorReportGitHubButton.setOnClickListener(v ->
openPrivacyPolicyDialog(this, "GITHUB")); openPrivacyPolicyDialog(this, "GITHUB"));
// normal bugreport // normal bugreport
buildInfo(errorInfo); buildInfo(errorInfo);
if (errorInfo.getMessage() != 0) { if (errorInfo.getMessage() != 0) {
errorMessageView.setText(errorInfo.getMessage()); activityErrorBinding.errorMessageView.setText(errorInfo.getMessage());
} else { } else {
errorMessageView.setVisibility(View.GONE); activityErrorBinding.errorMessageView.setVisibility(View.GONE);
findViewById(R.id.messageWhatHappenedView).setVisibility(View.GONE); activityErrorBinding.messageWhatHappenedView.setVisibility(View.GONE);
} }
errorView.setText(formErrorText(errorList)); activityErrorBinding.errorView.setText(formErrorText(errorList));
// print stack trace once again for debugging: // print stack trace once again for debugging:
for (final String e : errorList) { for (final String e : errorList) {
@ -339,11 +328,10 @@ public class ErrorActivity extends AppCompatActivity {
} }
private void buildInfo(final ErrorInfo info) { private void buildInfo(final ErrorInfo info) {
final TextView infoLabelView = findViewById(R.id.errorInfoLabelsView);
final TextView infoView = findViewById(R.id.errorInfosView);
String text = ""; String text = "";
infoLabelView.setText(getString(R.string.info_labels).replace("\\n", "\n")); activityErrorBinding.errorInfoLabelsView.setText(getString(R.string.info_labels)
.replace("\\n", "\n"));
text += getUserActionString(info.getUserAction()) + "\n" text += getUserActionString(info.getUserAction()) + "\n"
+ info.getRequest() + "\n" + info.getRequest() + "\n"
@ -356,7 +344,7 @@ public class ErrorActivity extends AppCompatActivity {
+ BuildConfig.VERSION_NAME + "\n" + BuildConfig.VERSION_NAME + "\n"
+ getOsString(); + getOsString();
infoView.setText(text); activityErrorBinding.errorInfosView.setText(text);
} }
private String buildJson() { private String buildJson() {
@ -374,7 +362,8 @@ public class ErrorActivity extends AppCompatActivity {
.value("os", getOsString()) .value("os", getOsString())
.value("time", currentTimeStamp) .value("time", currentTimeStamp)
.array("exceptions", Arrays.asList(errorList)) .array("exceptions", Arrays.asList(errorList))
.value("user_comment", userCommentBox.getText().toString()) .value("user_comment", activityErrorBinding.errorCommentBox.getText()
.toString())
.end() .end()
.done(); .done();
} catch (final Throwable e) { } catch (final Throwable e) {
@ -389,7 +378,7 @@ public class ErrorActivity extends AppCompatActivity {
try { try {
final StringBuilder htmlErrorReport = new StringBuilder(); final StringBuilder htmlErrorReport = new StringBuilder();
final String userComment = userCommentBox.getText().toString(); final String userComment = activityErrorBinding.errorCommentBox.getText().toString();
if (!userComment.isEmpty()) { if (!userComment.isEmpty()) {
htmlErrorReport.append(userComment).append("\n"); htmlErrorReport.append(userComment).append("\n");
} }
@ -473,10 +462,9 @@ public class ErrorActivity extends AppCompatActivity {
private void addGuruMeditation() { private void addGuruMeditation() {
//just an easter egg //just an easter egg
final TextView sorryView = findViewById(R.id.errorSorryView); String text = activityErrorBinding.errorSorryView.getText().toString();
String text = sorryView.getText().toString();
text += "\n" + getString(R.string.guru_meditation); text += "\n" + getString(R.string.guru_meditation);
sorryView.setText(text); activityErrorBinding.errorSorryView.setText(text);
} }
@Override @Override

View File

@ -7,12 +7,12 @@ import android.view.MenuItem;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.SettingsLayoutBinding;
import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
import org.schabi.newpipe.views.FocusOverlayView; import org.schabi.newpipe.views.FocusOverlayView;
@ -51,10 +51,12 @@ public class SettingsActivity extends AppCompatActivity
setTheme(ThemeHelper.getSettingsThemeStyle(this)); setTheme(ThemeHelper.getSettingsThemeStyle(this));
assureCorrectAppLanguage(this); assureCorrectAppLanguage(this);
super.onCreate(savedInstanceBundle); super.onCreate(savedInstanceBundle);
setContentView(R.layout.settings_layout);
final Toolbar toolbar = findViewById(R.id.toolbar); final SettingsLayoutBinding settingsLayoutBinding =
setSupportActionBar(toolbar); SettingsLayoutBinding.inflate(getLayoutInflater());
setContentView(settingsLayoutBinding.getRoot());
setSupportActionBar(settingsLayoutBinding.toolbarLayout.toolbar);
if (savedInstanceBundle == null) { if (savedInstanceBundle == null) {
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()

View File

@ -2,12 +2,12 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/video_item_detail"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/windowBackground"> android:background="?attr/windowBackground">
<LinearLayout <LinearLayout
android:id="@+id/video_item_detail"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:baselineAligned="false" android:baselineAligned="false"

View File

@ -3,7 +3,9 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<include layout="@layout/toolbar_layout" /> <include
layout="@layout/toolbar_layout"
android:id="@+id/toolbar_layout" />
<FrameLayout <FrameLayout
android:id="@+id/frame" android:id="@+id/frame"

View File

@ -5,7 +5,9 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".report.ErrorActivity"> tools:context=".report.ErrorActivity">
<include layout="@layout/toolbar_layout" /> <include
layout="@layout/toolbar_layout"
android:id="@+id/toolbar_layout"/>
<ScrollView <ScrollView
android:id="@+id/scrollView" android:id="@+id/scrollView"

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<org.schabi.newpipe.views.FocusAwareDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" <org.schabi.newpipe.views.FocusAwareDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -15,7 +14,9 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize" /> android:layout_marginTop="?attr/actionBarSize" />
<include layout="@layout/toolbar_layout" /> <include
layout="@layout/toolbar_layout"
android:id="@+id/toolbar_layout"/>
<FrameLayout <FrameLayout
android:id="@+id/fragment_player_holder" android:id="@+id/fragment_player_holder"
@ -28,6 +29,8 @@
</org.schabi.newpipe.views.FocusAwareCoordinator> </org.schabi.newpipe.views.FocusAwareCoordinator>
<include layout="@layout/drawer_layout" /> <include
layout="@layout/drawer_layout"
android:id="@+id/drawer_layout" />
</org.schabi.newpipe.views.FocusAwareDrawerLayout> </org.schabi.newpipe.views.FocusAwareDrawerLayout>

View File

@ -12,6 +12,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize" /> android:layout_marginTop="?attr/actionBarSize" />
<include layout="@layout/toolbar_layout" /> <include
layout="@layout/toolbar_layout"
android:id="@+id/toolbar_layout"/>
</RelativeLayout> </RelativeLayout>