From 88a3044fe37b59f4bd5619ac7d278e4bb20a54be Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sat, 1 May 2021 11:09:26 +0200 Subject: [PATCH] Automatically add tag when pressing OK --- .../antennapod/dialog/TagSettingsDialog.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java index 4feaefe28..de9f4d504 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java @@ -24,6 +24,8 @@ public class TagSettingsDialog extends DialogFragment { public static final String TAG = "TagSettingsDialog"; private static final String ARG_FEED_PREFERENCES = "feed_preferences"; private List displayedTags; + private EditTagsDialogBinding viewBinding; + private TagSelectionAdapter adapter; public static TagSettingsDialog newInstance(FeedPreferences preferences) { TagSettingsDialog fragment = new TagSettingsDialog(); @@ -40,29 +42,22 @@ public class TagSettingsDialog extends DialogFragment { displayedTags = new ArrayList<>(preferences.getTags()); displayedTags.remove(FeedPreferences.TAG_ROOT); - EditTagsDialogBinding viewBinding = EditTagsDialogBinding.inflate(getLayoutInflater()); + viewBinding = EditTagsDialogBinding.inflate(getLayoutInflater()); viewBinding.tagsRecycler.setLayoutManager(new GridLayoutManager(getContext(), 2)); viewBinding.tagsRecycler.addItemDecoration(new ItemOffsetDecoration(getContext(), 4)); - TagSelectionAdapter adapter = new TagSelectionAdapter(); + adapter = new TagSelectionAdapter(); adapter.setHasStableIds(true); viewBinding.tagsRecycler.setAdapter(adapter); viewBinding.rootFolderCheckbox.setChecked(preferences.getTags().contains(FeedPreferences.TAG_ROOT)); - - viewBinding.newTagButton.setOnClickListener(v -> { - String name = viewBinding.newTagEditText.getText().toString().trim(); - if (TextUtils.isEmpty(name) || displayedTags.contains(name)) { - return; - } - displayedTags.add(name); - viewBinding.newTagEditText.setText(""); - adapter.notifyDataSetChanged(); - }); + viewBinding.newTagButton.setOnClickListener(v -> + addTag(viewBinding.newTagEditText.getText().toString().trim())); AlertDialog.Builder dialog = new AlertDialog.Builder(getContext()); dialog.setView(viewBinding.getRoot()); dialog.setTitle(R.string.feed_folders_label); dialog.setPositiveButton(android.R.string.ok, (d, input) -> { + addTag(viewBinding.newTagEditText.getText().toString().trim()); preferences.getTags().clear(); preferences.getTags().addAll(displayedTags); if (viewBinding.rootFolderCheckbox.isChecked()) { @@ -74,6 +69,15 @@ public class TagSettingsDialog extends DialogFragment { return dialog.create(); } + private void addTag(String name) { + if (TextUtils.isEmpty(name) || displayedTags.contains(name)) { + return; + } + displayedTags.add(name); + viewBinding.newTagEditText.setText(""); + adapter.notifyDataSetChanged(); + } + public class TagSelectionAdapter extends RecyclerView.Adapter { @Override