mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-23 08:23:15 +00:00
フォルダ管理機能を実装してみた。
This commit is contained in:
parent
54f2076eda
commit
751089a73a
|
@ -0,0 +1,32 @@
|
|||
package one.nem.lacerta.feature.library;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import one.nem.lacerta.model.document.DocumentMeta;
|
||||
|
||||
public class LibraryFolderFragment extends Fragment{
|
||||
|
||||
private Map<String, List<DocumentMeta>> folderMap;
|
||||
|
||||
public LibraryFolderFragment() {
|
||||
folderMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public void addDocumentToFolder(String folderName, DocumentMeta documentMeta) {
|
||||
if (!folderMap.containsKey(folderName)) {
|
||||
folderMap.put(folderName, new ArrayList<>());
|
||||
}
|
||||
|
||||
List<DocumentMeta> documents = folderMap.get(folderName);
|
||||
documents.add(documentMeta);
|
||||
}
|
||||
|
||||
public List<DocumentMeta> getDocumentsInFolder(String folderName) {
|
||||
return folderMap.getOrDefault(folderName, new ArrayList<>());
|
||||
}
|
||||
}
|
|
@ -36,6 +36,8 @@ public class LibraryTopFragment extends Fragment {
|
|||
@Inject
|
||||
Document document;
|
||||
|
||||
private LibraryFolderFragment folderManager;
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
|
@ -74,6 +76,7 @@ public class LibraryTopFragment extends Fragment {
|
|||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
folderManager = new LibraryFolderFragment();
|
||||
}
|
||||
|
||||
|
||||
|
@ -89,9 +92,16 @@ public class LibraryTopFragment extends Fragment {
|
|||
documentRecyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
//データを取得
|
||||
|
||||
List<DocumentMeta> metas = document.getAllDocumentMetas(100);
|
||||
|
||||
// フォルダごとにドキュメントを管理する
|
||||
for (DocumentMeta meta : metas) {
|
||||
folderManager.addDocumentToFolder("Default Folder", meta);
|
||||
}
|
||||
|
||||
// 特定のフォルダのドキュメントを取得
|
||||
List<DocumentMeta> folderDocuments = folderManager.getDocumentsInFolder("Default Folder");
|
||||
|
||||
Toast.makeText(getContext(), "Documents: " + Integer.toString(metas.size()), Toast.LENGTH_LONG).show();
|
||||
|
||||
// Create and set the adapter
|
||||
|
|
Loading…
Reference in New Issue
Block a user