Skip to content

Commit

Permalink
Remove manual menu creation from some fragments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mauriciocolli authored and Stypox committed Mar 2, 2022
1 parent af20b2c commit 96185fa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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;
Expand Down Expand Up @@ -51,8 +50,6 @@
import io.reactivex.rxjava3.schedulers.Schedulers;

public class PeertubeInstanceListFragment extends Fragment {
private static final int MENU_ITEM_RESTORE_ID = 123456;

private final List<PeertubeInstance> instanceList = new ArrayList<>();
private PeertubeInstance selectedInstance;
private String savedInstanceListKey;
Expand Down Expand Up @@ -142,17 +139,12 @@ public void onDestroy() {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;
Expand All @@ -17,7 +16,6 @@
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;
Expand Down Expand Up @@ -107,12 +105,8 @@ public void onPause() {
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;
});
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/drawable/ic_settings_backup_restore.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
android:tint="@color/defaultIconTint"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M14,12c0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2 0.9,2 2,2 2,-0.9 2,-2zM12,3c-4.97,0 -9,4.03 -9,9L0,12l4,4 4,-4L5,12c0,-3.87 3.13,-7 7,-7s7,3.13 7,7 -3.13,7 -7,7c-1.51,0 -2.91,-0.49 -4.06,-1.3l-1.42,1.44C8.04,20.3 9.94,21 12,21c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9z" />
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/menu/menu_chooser_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_item_restore_default"
android:title="@string/restore_defaults"
android:icon="@drawable/ic_settings_backup_restore"
app:showAsAction="always" />
</menu>

0 comments on commit 96185fa

Please sign in to comment.