mirror of https://github.com/readrops/Readrops.git
Set folder spinner selection
This commit is contained in:
parent
54d6fca734
commit
ef7e1a9b12
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
@Dao
|
||||
public interface FolderDao {
|
||||
|
||||
@Query("Select * from Folder")
|
||||
@Query("Select * from Folder Order By name ASC")
|
||||
LiveData<List<Folder>> getAllFolders();
|
||||
|
||||
@Insert
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class EditFeedDialog extends DialogFragment implements AdapterView.OnItemSelectedListener {
|
||||
|
@ -61,7 +62,7 @@ public class EditFeedDialog extends DialogFragment implements AdapterView.OnItem
|
|||
fillData(v);
|
||||
|
||||
viewModel.getFolders().observe(this, folders -> {
|
||||
values = new HashMap<>();
|
||||
values = new TreeMap<>(String::compareTo);
|
||||
for (Folder folder : folders) {
|
||||
if (folder.getId() != 1)
|
||||
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);
|
||||
}
|
||||
|
||||
ArrayAdapter<String> spinnerData = new ArrayAdapter<String>(getActivity(),
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
|
||||
android.R.layout.simple_spinner_dropdown_item, new ArrayList<>(values.keySet()));
|
||||
spinnerData.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
folder.setAdapter(spinnerData);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
|
||||
folder.setAdapter(adapter);
|
||||
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();
|
||||
|
|
|
@ -18,7 +18,8 @@ import java.util.List;
|
|||
public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWithFolderItem, FeedWithFolderItem.ViewHolder> {
|
||||
|
||||
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;
|
||||
|
||||
|
@ -53,11 +54,13 @@ public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWi
|
|||
if (!payloads.isEmpty()) {
|
||||
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));
|
||||
}
|
||||
|
||||
if (bundle.getString(FOLDER_NAME_KEY) != null)
|
||||
if (bundle.getString(FOLDER_NAME_KEY) != null) {
|
||||
holder.folderName.setText(bundle.getString(FOLDER_NAME_KEY));
|
||||
}
|
||||
} else {
|
||||
FeedWithFolder feedWithFolder = getModel();
|
||||
|
||||
|
@ -82,8 +85,8 @@ public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWi
|
|||
else
|
||||
holder.folderName.setText(holder.itemView.getResources().getString(R.string.no_folder));
|
||||
|
||||
holder.editFeed.setOnClickListener(v -> listener.onEdit(feedWithFolder));
|
||||
holder.deleteFeed.setOnClickListener(v -> listener.onDelete(feedWithFolder));
|
||||
holder.editFeed.setOnClickListener(v -> listener.onEdit(getModel()));
|
||||
holder.deleteFeed.setOnClickListener(v -> listener.onDelete(getModel()));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue