Allow to choose from existing tags/folders in folder settings dialog (#5245)

This commit is contained in:
vbh 2021-06-28 20:02:03 +00:00 committed by GitHub
parent 6c9a76e0b4
commit 951aa3dce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 28 deletions

View File

@ -3,7 +3,11 @@ package de.danoeh.antennapod.dialog;
import android.app.Dialog; import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
@ -12,10 +16,15 @@ import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.chip.Chip; import com.google.android.material.chip.Chip;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.NavDrawerData;
import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.model.feed.FeedPreferences;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.databinding.EditTagsDialogBinding; import de.danoeh.antennapod.databinding.EditTagsDialogBinding;
import de.danoeh.antennapod.view.ItemOffsetDecoration; import de.danoeh.antennapod.view.ItemOffsetDecoration;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -53,6 +62,17 @@ public class TagSettingsDialog extends DialogFragment {
viewBinding.newTagButton.setOnClickListener(v -> viewBinding.newTagButton.setOnClickListener(v ->
addTag(viewBinding.newTagEditText.getText().toString().trim())); addTag(viewBinding.newTagEditText.getText().toString().trim()));
loadTags();
viewBinding.newTagEditText.setThreshold(1);
viewBinding.newTagEditText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
viewBinding.newTagEditText.showDropDown();
viewBinding.newTagEditText.requestFocus();
return false;
}
});
AlertDialog.Builder dialog = new AlertDialog.Builder(getContext()); AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
dialog.setView(viewBinding.getRoot()); dialog.setView(viewBinding.getRoot());
dialog.setTitle(R.string.feed_folders_label); dialog.setTitle(R.string.feed_folders_label);
@ -69,6 +89,31 @@ public class TagSettingsDialog extends DialogFragment {
return dialog.create(); return dialog.create();
} }
private void loadTags() {
Observable.fromCallable(
() -> {
NavDrawerData data = DBReader.getNavDrawerData();
List<NavDrawerData.DrawerItem> items = data.items;
List<String> folders = new ArrayList<String>();
for (NavDrawerData.DrawerItem item : items) {
if (item.type == NavDrawerData.DrawerItem.Type.FOLDER) {
folders.add(item.getTitle());
}
}
return folders;
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
result -> {
ArrayAdapter<String> acAdapter = new ArrayAdapter<String>(getContext(),
R.layout.single_tag_text_view, result);
viewBinding.newTagEditText.setAdapter(acAdapter);
}, error -> {
Log.e(TAG, Log.getStackTraceString(error));
});
}
private void addTag(String name) { private void addTag(String name) {
if (TextUtils.isEmpty(name) || displayedTags.contains(name)) { if (TextUtils.isEmpty(name) || displayedTags.contains(name)) {
return; return;

View File

@ -1,41 +1,43 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent" android:layout_width="match_parent"
android:orientation="vertical" android:layout_height="match_parent"
android:padding="16dp"> android:orientation="vertical"
android:padding="16dp">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/tagsRecycler" android:id="@+id/tagsRecycler"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content" />
<CheckBox <CheckBox
android:id="@+id/rootFolderCheckbox" android:id="@+id/rootFolderCheckbox"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/feed_folders_include_root" /> android:text="@string/feed_folders_include_root" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<EditText <AutoCompleteTextView
android:layout_width="0dp" android:id="@+id/newTagEditText"
android:layout_height="wrap_content" android:layout_width="0dp"
android:layout_weight="1" android:layout_height="wrap_content"
android:inputType="text" android:layout_weight="1"
android:ems="10" android:inputType="text"
android:id="@+id/newTagEditText"/> android:ems="10" />
<ImageButton <ImageButton
android:layout_width="wrap_content" android:id="@+id/newTagButton"
android:layout_height="wrap_content" android:layout_width="wrap_content"
app:srcCompat="@drawable/ic_add" android:layout_height="wrap_content"
android:contentDescription="@string/new_label" android:contentDescription="@string/new_label"
android:id="@+id/newTagButton"/> app:srcCompat="@drawable/ic_add" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:padding="10dp"
android:ems="10" />