Allow to choose from existing tags/folders in folder settings dialog (#5245)
This commit is contained in:
parent
6c9a76e0b4
commit
951aa3dce6
|
@ -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;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -22,20 +23,21 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<EditText
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/newTagEditText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:inputType="text"
|
||||
android:ems="10"
|
||||
android:id="@+id/newTagEditText"/>
|
||||
android:ems="10" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/newTagButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:srcCompat="@drawable/ic_add"
|
||||
android:contentDescription="@string/new_label"
|
||||
android:id="@+id/newTagButton"/>
|
||||
app:srcCompat="@drawable/ic_add" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -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" />
|
Loading…
Reference in New Issue