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,41 +1,43 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
<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"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/tagsRecycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
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" />
|
||||
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">
|
||||
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"/>
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/newTagEditText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:inputType="text"
|
||||
android:ems="10" />
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:srcCompat="@drawable/ic_add"
|
||||
android:contentDescription="@string/new_label"
|
||||
android:id="@+id/newTagButton"/>
|
||||
android:id="@+id/newTagButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/new_label"
|
||||
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