From 96185faca65edb39a5fa6762a3a3b91777fe04e9 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Wed, 8 Dec 2021 09:49:52 -0300 Subject: [PATCH] Remove manual menu creation from some fragments Doing this programmatically is just a no-go when themes are being set in some other places (the toolbar is using a custom theme, in this case), so, instead of hunting down the proper theme, just let the system do its work. --- .../settings/PeertubeInstanceListFragment.java | 12 ++---------- .../newpipe/settings/tabs/ChooseTabsFragment.java | 10 ++-------- .../main/res/drawable/ic_settings_backup_restore.xml | 6 +++--- app/src/main/res/menu/menu_chooser_fragment.xml | 8 ++++++++ 4 files changed, 15 insertions(+), 21 deletions(-) create mode 100644 app/src/main/res/menu/menu_chooser_fragment.xml diff --git a/app/src/main/java/org/schabi/newpipe/settings/PeertubeInstanceListFragment.java b/app/src/main/java/org/schabi/newpipe/settings/PeertubeInstanceListFragment.java index dfc053a62..6df6ea868 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/PeertubeInstanceListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/PeertubeInstanceListFragment.java @@ -21,7 +21,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.widget.AppCompatImageView; import androidx.fragment.app.Fragment; import androidx.preference.PreferenceManager; @@ -51,8 +50,6 @@ import io.reactivex.rxjava3.disposables.Disposable; import io.reactivex.rxjava3.schedulers.Schedulers; public class PeertubeInstanceListFragment extends Fragment { - private static final int MENU_ITEM_RESTORE_ID = 123456; - private final List instanceList = new ArrayList<>(); private PeertubeInstance selectedInstance; private String savedInstanceListKey; @@ -142,17 +139,12 @@ public class PeertubeInstanceListFragment extends Fragment { public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); - - final MenuItem restoreItem = menu - .add(Menu.NONE, MENU_ITEM_RESTORE_ID, Menu.NONE, R.string.restore_defaults); - restoreItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - restoreItem.setIcon(AppCompatResources.getDrawable(requireContext(), - R.drawable.ic_settings_backup_restore)); + inflater.inflate(R.menu.menu_chooser_fragment, menu); } @Override public boolean onOptionsItemSelected(final MenuItem item) { - if (item.getItemId() == MENU_ITEM_RESTORE_ID) { + if (item.getItemId() == R.id.menu_item_restore_default) { restoreDefaults(); return true; } diff --git a/app/src/main/java/org/schabi/newpipe/settings/tabs/ChooseTabsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/tabs/ChooseTabsFragment.java index 490e299bd..2ec987a64 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/tabs/ChooseTabsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/tabs/ChooseTabsFragment.java @@ -7,7 +7,6 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; -import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -17,7 +16,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.widget.AppCompatImageView; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.ItemTouchHelper; @@ -107,12 +105,8 @@ public class ChooseTabsFragment extends Fragment { public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); - - final MenuItem restoreItem = menu.add(R.string.restore_defaults); - restoreItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - restoreItem.setIcon(AppCompatResources.getDrawable(requireContext(), - R.drawable.ic_settings_backup_restore)); - restoreItem.setOnMenuItemClickListener(ev -> { + inflater.inflate(R.menu.menu_chooser_fragment, menu); + menu.findItem(R.id.menu_item_restore_default).setOnMenuItemClickListener(item -> { restoreDefaults(); return true; }); diff --git a/app/src/main/res/drawable/ic_settings_backup_restore.xml b/app/src/main/res/drawable/ic_settings_backup_restore.xml index ae22bc141..580025971 100644 --- a/app/src/main/res/drawable/ic_settings_backup_restore.xml +++ b/app/src/main/res/drawable/ic_settings_backup_restore.xml @@ -1,9 +1,9 @@ + android:tint="@color/defaultIconTint" + android:viewportWidth="24" + android:viewportHeight="24"> diff --git a/app/src/main/res/menu/menu_chooser_fragment.xml b/app/src/main/res/menu/menu_chooser_fragment.xml new file mode 100644 index 000000000..8052f60ef --- /dev/null +++ b/app/src/main/res/menu/menu_chooser_fragment.xml @@ -0,0 +1,8 @@ + + +