フォルダ管理機能を実装してみた。

This commit is contained in:
nero 2023-12-22 12:24:01 +09:00
parent 54f2076eda
commit 751089a73a
2 changed files with 43 additions and 1 deletions

View File

@ -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<>());
}
}

View File

@ -36,6 +36,8 @@ public class LibraryTopFragment extends Fragment {
@Inject @Inject
Document document; Document document;
private LibraryFolderFragment folderManager;
// TODO: Rename parameter arguments, choose names that match // TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM1 = "param1";
@ -74,6 +76,7 @@ public class LibraryTopFragment extends Fragment {
mParam1 = getArguments().getString(ARG_PARAM1); mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2); mParam2 = getArguments().getString(ARG_PARAM2);
} }
folderManager = new LibraryFolderFragment();
} }
@ -89,9 +92,16 @@ public class LibraryTopFragment extends Fragment {
documentRecyclerView.setLayoutManager(layoutManager); documentRecyclerView.setLayoutManager(layoutManager);
//データを取得 //データを取得
List<DocumentMeta> metas = document.getAllDocumentMetas(100); 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(); Toast.makeText(getContext(), "Documents: " + Integer.toString(metas.size()), Toast.LENGTH_LONG).show();
// Create and set the adapter // Create and set the adapter