Set folder spinner selection

This commit is contained in:
Shinokuni 2019-03-06 16:20:30 +01:00
parent 54d6fca734
commit ef7e1a9b12
3 changed files with 20 additions and 10 deletions

View File

@ -13,7 +13,7 @@ import java.util.List;
@Dao @Dao
public interface FolderDao { public interface FolderDao {
@Query("Select * from Folder") @Query("Select * from Folder Order By name ASC")
LiveData<List<Folder>> getAllFolders(); LiveData<List<Folder>> getAllFolders();
@Insert @Insert

View File

@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
public class EditFeedDialog extends DialogFragment implements AdapterView.OnItemSelectedListener { public class EditFeedDialog extends DialogFragment implements AdapterView.OnItemSelectedListener {
@ -61,7 +62,7 @@ public class EditFeedDialog extends DialogFragment implements AdapterView.OnItem
fillData(v); fillData(v);
viewModel.getFolders().observe(this, folders -> { viewModel.getFolders().observe(this, folders -> {
values = new HashMap<>(); values = new TreeMap<>(String::compareTo);
for (Folder folder : folders) { for (Folder folder : folders) {
if (folder.getId() != 1) if (folder.getId() != 1)
values.put(folder.getName(), folder.getId()); values.put(folder.getName(), folder.getId());
@ -69,11 +70,17 @@ public class EditFeedDialog extends DialogFragment implements AdapterView.OnItem
values.put(getString(R.string.no_folder), 1); values.put(getString(R.string.no_folder), 1);
} }
ArrayAdapter<String> spinnerData = new ArrayAdapter<String>(getActivity(), ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
android.R.layout.simple_spinner_dropdown_item, new ArrayList<>(values.keySet())); android.R.layout.simple_spinner_dropdown_item, new ArrayList<>(values.keySet()));
spinnerData.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
folder.setAdapter(spinnerData);
folder.setAdapter(adapter);
folder.setOnItemSelectedListener(this); folder.setOnItemSelectedListener(this);
if (!feedWithFolder.getFolder().getName().equals("reserved"))
folder.setSelection(adapter.getPosition(feedWithFolder.getFolder().getName()));
else
folder.setSelection(adapter.getPosition(getString(R.string.no_folder)));
}); });
return builder.create(); return builder.create();

View File

@ -18,7 +18,8 @@ import java.util.List;
public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWithFolderItem, FeedWithFolderItem.ViewHolder> { public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWithFolderItem, FeedWithFolderItem.ViewHolder> {
public static final String FEED_NAME_KEY = "name"; public static final String FEED_NAME_KEY = "name";
public static final String FOLDER_NAME_KEY = "folder_name"; public static final String FOLDER_NAME_KEY = "folderName";
public static final String FOLDER_ID_KEY = "folderKey";
private ManageFeedsListener listener; private ManageFeedsListener listener;
@ -53,11 +54,13 @@ public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWi
if (!payloads.isEmpty()) { if (!payloads.isEmpty()) {
Bundle bundle = (Bundle)payloads.get(0); Bundle bundle = (Bundle)payloads.get(0);
if (bundle.getString(FEED_NAME_KEY) != null) if (bundle.getString(FEED_NAME_KEY) != null) {
holder.feedName.setText(bundle.getString(FEED_NAME_KEY)); holder.feedName.setText(bundle.getString(FEED_NAME_KEY));
}
if (bundle.getString(FOLDER_NAME_KEY) != null) if (bundle.getString(FOLDER_NAME_KEY) != null) {
holder.folderName.setText(bundle.getString(FOLDER_NAME_KEY)); holder.folderName.setText(bundle.getString(FOLDER_NAME_KEY));
}
} else { } else {
FeedWithFolder feedWithFolder = getModel(); FeedWithFolder feedWithFolder = getModel();
@ -82,8 +85,8 @@ public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWi
else else
holder.folderName.setText(holder.itemView.getResources().getString(R.string.no_folder)); holder.folderName.setText(holder.itemView.getResources().getString(R.string.no_folder));
holder.editFeed.setOnClickListener(v -> listener.onEdit(feedWithFolder)); holder.editFeed.setOnClickListener(v -> listener.onEdit(getModel()));
holder.deleteFeed.setOnClickListener(v -> listener.onDelete(feedWithFolder)); holder.deleteFeed.setOnClickListener(v -> listener.onDelete(getModel()));
} }