mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-29 19:13:16 +00:00
Merge pull request #92 from lacerta-doc/feature/library/create_folder
Feature/library/create folder
This commit is contained in:
commit
41e5ab2349
|
@ -21,4 +21,7 @@ public interface LacertaLibrary {
|
||||||
CompletableFuture<LibraryItemPage> getLibraryPage(String pageId, int limit);
|
CompletableFuture<LibraryItemPage> getLibraryPage(String pageId, int limit);
|
||||||
CompletableFuture<LibraryItemPage> getLibraryPage(String pageId, int limit, int offset);
|
CompletableFuture<LibraryItemPage> getLibraryPage(String pageId, int limit, int offset);
|
||||||
|
|
||||||
|
// Create Folder
|
||||||
|
CompletableFuture<String> createFolder(String path, String name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -13,6 +14,7 @@ import one.nem.lacerta.data.LacertaLibrary;
|
||||||
import one.nem.lacerta.model.LibraryItemPage;
|
import one.nem.lacerta.model.LibraryItemPage;
|
||||||
import one.nem.lacerta.model.ListItem;
|
import one.nem.lacerta.model.ListItem;
|
||||||
import one.nem.lacerta.model.ListItemType;
|
import one.nem.lacerta.model.ListItemType;
|
||||||
|
import one.nem.lacerta.model.PublicPath;
|
||||||
import one.nem.lacerta.model.document.DocumentDetail;
|
import one.nem.lacerta.model.document.DocumentDetail;
|
||||||
import one.nem.lacerta.source.database.LacertaDatabase;
|
import one.nem.lacerta.source.database.LacertaDatabase;
|
||||||
import one.nem.lacerta.source.database.common.DateTypeConverter;
|
import one.nem.lacerta.source.database.common.DateTypeConverter;
|
||||||
|
@ -143,4 +145,25 @@ public class LacertaLibraryImpl implements LacertaLibrary {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> createFolder(String parentId, String name) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
|
||||||
|
FolderEntity parentFolderEntity = database.folderDao().findById(parentId);
|
||||||
|
PublicPath publicPath;
|
||||||
|
if (parentFolderEntity == null) {
|
||||||
|
publicPath = new PublicPath().resolve("/");
|
||||||
|
} else {
|
||||||
|
publicPath = new PublicPath().resolve(parentFolderEntity.publicPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
FolderEntity folderEntity = new FolderEntity();
|
||||||
|
folderEntity.id = UUID.randomUUID().toString();
|
||||||
|
folderEntity.name = name;
|
||||||
|
folderEntity.publicPath = publicPath.getStringPath();
|
||||||
|
database.folderDao().insert(folderEntity);
|
||||||
|
return folderEntity.id;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package one.nem.lacerta.feature.library;
|
package one.nem.lacerta.feature.library;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -13,6 +14,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
@ -23,6 +25,8 @@ import android.widget.Toast;
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||||
|
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -34,7 +38,7 @@ import one.nem.lacerta.data.LacertaLibrary;
|
||||||
import one.nem.lacerta.model.document.DocumentMeta;
|
import one.nem.lacerta.model.document.DocumentMeta;
|
||||||
import one.nem.lacerta.model.document.tag.DocumentTag;
|
import one.nem.lacerta.model.document.tag.DocumentTag;
|
||||||
import one.nem.lacerta.utils.LacertaLogger;
|
import one.nem.lacerta.utils.LacertaLogger;
|
||||||
|
import one.nem.lacerta.utils.TextInputDialog;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,6 +55,10 @@ public class LibraryTopFragment extends Fragment {
|
||||||
@Inject
|
@Inject
|
||||||
LacertaLogger logger;
|
LacertaLogger logger;
|
||||||
|
|
||||||
|
ListItemAdapter listItemAdapter;
|
||||||
|
|
||||||
|
int currentTotalItemCount = 0;
|
||||||
|
|
||||||
public LibraryTopFragment() {
|
public LibraryTopFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
@ -83,7 +91,7 @@ public class LibraryTopFragment extends Fragment {
|
||||||
|
|
||||||
RecyclerView recyclerView = view.findViewById(R.id.library_item_recycler_view);
|
RecyclerView recyclerView = view.findViewById(R.id.library_item_recycler_view);
|
||||||
|
|
||||||
ListItemAdapter listItemAdapter = new ListItemAdapter(documentId -> {
|
this.listItemAdapter = new ListItemAdapter(documentId -> {
|
||||||
Toast.makeText(getContext(), documentId, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), documentId, Toast.LENGTH_SHORT).show();
|
||||||
});
|
});
|
||||||
recyclerView.setAdapter(listItemAdapter);
|
recyclerView.setAdapter(listItemAdapter);
|
||||||
|
@ -92,8 +100,9 @@ public class LibraryTopFragment extends Fragment {
|
||||||
lacertaLibrary.getLibraryPage(10).thenAccept(libraryItemPage -> {
|
lacertaLibrary.getLibraryPage(10).thenAccept(libraryItemPage -> {
|
||||||
logger.debug("LibraryTopFragment", "Item selected! libraryItemPage.getListItems().size(): " + libraryItemPage.getListItems().size());
|
logger.debug("LibraryTopFragment", "Item selected! libraryItemPage.getListItems().size(): " + libraryItemPage.getListItems().size());
|
||||||
listItemAdapter.setLibraryItemPage(libraryItemPage);
|
listItemAdapter.setLibraryItemPage(libraryItemPage);
|
||||||
|
this.currentTotalItemCount = libraryItemPage.getListItems().size();
|
||||||
getActivity().runOnUiThread(() -> {
|
getActivity().runOnUiThread(() -> {
|
||||||
listItemAdapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size() - 1);
|
listItemAdapter.notifyItemRangeInserted(0, this.currentTotalItemCount - 1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -103,4 +112,45 @@ public class LibraryTopFragment extends Fragment {
|
||||||
inflater.inflate(R.menu.dir_menu, menu);
|
inflater.inflate(R.menu.dir_menu, menu);
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Selected
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
|
if (item.getItemId() == R.id.menu_item_create_new_folder) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
|
builder.setTitle("フォルダの作成");
|
||||||
|
builder.setMessage("フォルダ名を入力してください");
|
||||||
|
final android.widget.EditText input = new android.widget.EditText(getContext());
|
||||||
|
input.setText("フォルダ名");
|
||||||
|
builder.setView(input);
|
||||||
|
builder.setPositiveButton("作成", (dialog, which) -> {
|
||||||
|
lacertaLibrary.createFolder(null, input.getText().toString()).thenAccept(folderId -> {
|
||||||
|
logger.debug("LibraryTopFragment", "folderId: " + folderId);
|
||||||
|
});
|
||||||
|
// Refresh
|
||||||
|
updateItem();
|
||||||
|
});
|
||||||
|
builder.setNegativeButton("キャンセル", (dialog, which) -> {
|
||||||
|
dialog.cancel();
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateItem() {
|
||||||
|
lacertaLibrary.getLibraryPage(10).thenAccept(libraryItemPage -> {
|
||||||
|
logger.debug("LibraryTopFragment", "Item selected! libraryItemPage.getListItems().size(): " + libraryItemPage.getListItems().size());
|
||||||
|
getActivity().runOnUiThread(() -> {
|
||||||
|
listItemAdapter.notifyItemRangeRemoved(0, this.currentTotalItemCount - 1);
|
||||||
|
});
|
||||||
|
listItemAdapter.setLibraryItemPage(libraryItemPage);
|
||||||
|
getActivity().runOnUiThread(() -> {
|
||||||
|
listItemAdapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size() - 1);
|
||||||
|
});
|
||||||
|
this.currentTotalItemCount = libraryItemPage.getListItems().size();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,12 +27,27 @@ public class PublicPath {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolveInternal(String path) {
|
private void resolveInternal(String path) {
|
||||||
|
if (path.startsWith("/")) {
|
||||||
|
this.path.clear();
|
||||||
|
this.path.add("/");
|
||||||
|
} else {
|
||||||
if (path.equals("..")) {
|
if (path.equals("..")) {
|
||||||
this.path.remove(this.path.size() - 1);
|
this.path.remove(this.path.size() - 1);
|
||||||
|
} else if (path.equals(".")) {
|
||||||
|
// do nothing
|
||||||
} else {
|
} else {
|
||||||
add(path);
|
this.path.add(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PublicPath parse(String path) {
|
||||||
|
String[] pathArray = path.split("/");
|
||||||
|
for (String p : pathArray) {
|
||||||
|
resolveInternal(p);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public PublicPath resolve(String path) {
|
public PublicPath resolve(String path) {
|
||||||
resolveInternal(path);
|
resolveInternal(path);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user