diff options
author | vbh <56578479+vbh@users.noreply.github.com> | 2021-06-28 20:02:03 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-28 22:02:03 +0200 |
commit | 951aa3dce6bbc6cace9e9b6bcf0862749576233a (patch) | |
tree | d46886ab5a9212f56c5918fb555be33a025ffa58 /app/src/main/java/de | |
parent | 6c9a76e0b4c0c9087ad77241a4f6b253f133b0e3 (diff) | |
download | AntennaPod-951aa3dce6bbc6cace9e9b6bcf0862749576233a.zip |
Allow to choose from existing tags/folders in folder settings dialog (#5245)
Diffstat (limited to 'app/src/main/java/de')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java | 45 |
1 files changed, 45 insertions, 0 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 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<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) { if (TextUtils.isEmpty(name) || displayedTags.contains(name)) { return; |