Added basic tag editor UI
This commit is contained in:
parent
8586c76720
commit
3f21ef50d3
|
@ -0,0 +1,116 @@
|
|||
package de.danoeh.antennapod.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.ViewGroup;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.google.android.material.chip.Chip;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.databinding.EditTagsDialogBinding;
|
||||
import de.danoeh.antennapod.view.ItemOffsetDecoration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TagSettingsDialog extends DialogFragment {
|
||||
public static final String TAG = "TagSettingsDialog";
|
||||
private static final String ARG_FEED_PREFERENCES = "feed_preferences";
|
||||
private List<String> displayedTags;
|
||||
|
||||
public static TagSettingsDialog newInstance(FeedPreferences preferences) {
|
||||
TagSettingsDialog fragment = new TagSettingsDialog();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(ARG_FEED_PREFERENCES, preferences);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
FeedPreferences preferences = (FeedPreferences) getArguments().getSerializable(ARG_FEED_PREFERENCES);
|
||||
displayedTags = new ArrayList<>(preferences.getTags());
|
||||
displayedTags.remove(FeedPreferences.TAG_ROOT);
|
||||
|
||||
EditTagsDialogBinding viewBinding = EditTagsDialogBinding.inflate(getLayoutInflater());
|
||||
viewBinding.tagsRecycler.setLayoutManager(new GridLayoutManager(getContext(), 2));
|
||||
viewBinding.tagsRecycler.addItemDecoration(new ItemOffsetDecoration(getContext(), 4));
|
||||
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();
|
||||
});
|
||||
|
||||
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) -> {
|
||||
preferences.getTags().clear();
|
||||
preferences.getTags().addAll(displayedTags);
|
||||
if (viewBinding.rootFolderCheckbox.isChecked()) {
|
||||
preferences.getTags().add(FeedPreferences.TAG_ROOT);
|
||||
}
|
||||
DBWriter.setFeedPreferences(preferences);
|
||||
});
|
||||
dialog.setNegativeButton(R.string.cancel_label, null);
|
||||
return dialog.create();
|
||||
}
|
||||
|
||||
public class TagSelectionAdapter extends RecyclerView.Adapter<TagSelectionAdapter.ViewHolder> {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public TagSelectionAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
Chip chip = new Chip(getContext());
|
||||
chip.setCloseIconVisible(true);
|
||||
chip.setCloseIconResource(R.drawable.ic_delete_black);
|
||||
return new TagSelectionAdapter.ViewHolder(chip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull TagSelectionAdapter.ViewHolder holder, int position) {
|
||||
holder.chip.setText(displayedTags.get(position));
|
||||
holder.chip.setOnCloseIconClickListener(v -> {
|
||||
displayedTags.remove(position);
|
||||
notifyDataSetChanged();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return displayedTags.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return displayedTags.get(position).hashCode();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
Chip chip;
|
||||
|
||||
ViewHolder(Chip itemView) {
|
||||
super(itemView);
|
||||
chip = itemView;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,7 +9,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.ListPreference;
|
||||
|
@ -28,10 +27,10 @@ import de.danoeh.antennapod.core.feed.VolumeAdaptionSetting;
|
|||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.databinding.EditTextDialogBinding;
|
||||
import de.danoeh.antennapod.dialog.AuthenticationDialog;
|
||||
import de.danoeh.antennapod.dialog.EpisodeFilterDialog;
|
||||
import de.danoeh.antennapod.dialog.FeedPreferenceSkipDialog;
|
||||
import de.danoeh.antennapod.dialog.TagSettingsDialog;
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.MaybeOnSubscribe;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
|
@ -41,8 +40,6 @@ import org.greenrobot.eventbus.EventBus;
|
|||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
|
||||
import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
|
||||
|
@ -403,20 +400,7 @@ public class FeedSettingsFragment extends Fragment {
|
|||
|
||||
private void setupTags() {
|
||||
findPreference(PREF_TAGS).setOnPreferenceClickListener(preference -> {
|
||||
EditTextDialogBinding alertViewBinding = EditTextDialogBinding.inflate(getLayoutInflater());
|
||||
alertViewBinding.urlEditText.setText(feed.getPreferences().getTagsAsString());
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setView(alertViewBinding.getRoot())
|
||||
.setTitle(R.string.feed_folders_label)
|
||||
.setPositiveButton(android.R.string.ok, (d, input) -> {
|
||||
String foldersString = alertViewBinding.urlEditText.getText().toString();
|
||||
feedPreferences.getTags().clear();
|
||||
feedPreferences.getTags().addAll(new HashSet<>(Arrays.asList(
|
||||
foldersString.split(FeedPreferences.TAG_SEPARATOR))));
|
||||
DBWriter.setFeedPreferences(feedPreferences);
|
||||
})
|
||||
.setNegativeButton(R.string.cancel_label, null)
|
||||
.show();
|
||||
TagSettingsDialog.newInstance(feedPreferences).show(getChildFragmentManager(), TagSettingsDialog.TAG);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/tagsRecycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/rootFolderCheckbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/feed_folders_include_root" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<EditText
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:inputType="text"
|
||||
android:ems="10"
|
||||
android:id="@+id/newTagEditText"/>
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="?attr/content_new"
|
||||
android:contentDescription="@string/new_label"
|
||||
android:id="@+id/newTagButton"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,11 +1,12 @@
|
|||
package de.danoeh.antennapod.core.feed;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class FeedFilter {
|
||||
public class FeedFilter implements Serializable {
|
||||
|
||||
private static final String TAG = "FeedFilter";
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.text.TextUtils;
|
|||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -14,11 +15,11 @@ import java.util.Set;
|
|||
/**
|
||||
* Contains preferences for a single feed.
|
||||
*/
|
||||
public class FeedPreferences {
|
||||
public class FeedPreferences implements Serializable {
|
||||
|
||||
public static final float SPEED_USE_GLOBAL = -1;
|
||||
public static final String TAG_ROOT = "#root";
|
||||
public static final String TAG_SEPARATOR = ",";
|
||||
public static final String TAG_SEPARATOR = "\u001e";
|
||||
|
||||
public enum AutoDeleteAction {
|
||||
GLOBAL,
|
||||
|
|
|
@ -736,6 +736,7 @@
|
|||
<string name="authentication_descr">Change your username and password for this podcast and its episodes.</string>
|
||||
<string name="feed_folders_label">Folders</string>
|
||||
<string name="feed_folders_summary">Change the folders in which this podcast is displayed.</string>
|
||||
<string name="feed_folders_include_root">Show in main list</string>
|
||||
<string name="auto_download_settings_label">Auto Download Settings</string>
|
||||
<string name="episode_filters_label">Episode Filter</string>
|
||||
<string name="episode_filters_description">List of terms used to decide if an episode should be included or excluded when auto downloading</string>
|
||||
|
|
Loading…
Reference in New Issue