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 de9f4d504..8ef01590f 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java @@ -3,7 +3,11 @@ package de.danoeh.antennapod.dialog; import android.app.Dialog; import android.os.Bundle; import android.text.TextUtils; +import android.util.Log; +import android.view.MotionEvent; +import android.view.View; import android.view.ViewGroup; +import android.widget.ArrayAdapter; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; @@ -12,10 +16,15 @@ 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.storage.DBReader; +import de.danoeh.antennapod.core.storage.NavDrawerData; import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.databinding.EditTagsDialogBinding; 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.List; @@ -53,6 +62,17 @@ public class TagSettingsDialog extends DialogFragment { viewBinding.newTagButton.setOnClickListener(v -> 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()); dialog.setView(viewBinding.getRoot()); dialog.setTitle(R.string.feed_folders_label); @@ -69,6 +89,31 @@ public class TagSettingsDialog extends DialogFragment { return dialog.create(); } + private void loadTags() { + Observable.fromCallable( + () -> { + NavDrawerData data = DBReader.getNavDrawerData(); + List items = data.items; + List folders = new ArrayList(); + 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 acAdapter = new ArrayAdapter(getContext(), + R.layout.single_tag_text_view, result); + viewBinding.newTagEditText.setAdapter(acAdapter); + }, error -> { + Log.e(TAG, Log.getStackTraceString(error)); + }); + } + private void addTag(String name) { if (TextUtils.isEmpty(name) || displayedTags.contains(name)) { return; diff --git a/app/src/main/res/layout/edit_tags_dialog.xml b/app/src/main/res/layout/edit_tags_dialog.xml index 2e7774cea..57e3c412f 100644 --- a/app/src/main/res/layout/edit_tags_dialog.xml +++ b/app/src/main/res/layout/edit_tags_dialog.xml @@ -1,41 +1,43 @@ - + + android:id="@+id/tagsRecycler" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + android:id="@+id/rootFolderCheckbox" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/feed_folders_include_root" /> + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> - + + android:id="@+id/newTagButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:contentDescription="@string/new_label" + app:srcCompat="@drawable/ic_add" /> + diff --git a/app/src/main/res/layout/single_tag_text_view.xml b/app/src/main/res/layout/single_tag_text_view.xml new file mode 100644 index 000000000..67410a20e --- /dev/null +++ b/app/src/main/res/layout/single_tag_text_view.xml @@ -0,0 +1,8 @@ + +