From c23b92d38673bdd5b80add1b1e8f1c73d743e040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 12:10:45 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E3=83=AA=E3=83=8D=E3=83=BC=E3=83=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...Fragment.java => LibraryPageFragment.java} | 27 ++++--------------- .../navigation/feature_library_navigation.xml | 2 +- 2 files changed, 6 insertions(+), 23 deletions(-) rename feature/library/src/main/java/one/nem/lacerta/feature/library/{LibraryTopFragment.java => LibraryPageFragment.java} (84%) diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java similarity index 84% rename from feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java rename to feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java index 172246f4..ef037666 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java @@ -4,9 +4,6 @@ import android.app.AlertDialog; import android.os.Bundle; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; -import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -17,37 +14,23 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ListView; -import android.widget.TextView; import android.widget.Toast; -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.appbar.CollapsingToolbarLayout; - -import org.w3c.dom.Text; - -import java.util.ArrayList; -import java.util.List; - import javax.inject.Inject; import dagger.hilt.android.AndroidEntryPoint; -import one.nem.lacerta.data.Document; import one.nem.lacerta.data.LacertaLibrary; -import one.nem.lacerta.model.document.DocumentMeta; -import one.nem.lacerta.model.document.tag.DocumentTag; import one.nem.lacerta.utils.LacertaLogger; import one.nem.lacerta.utils.TextInputDialog; /** * A simple {@link Fragment} subclass. - * Use the {@link LibraryTopFragment#newInstance} factory method to + * Use the {@link LibraryPageFragment#newInstance} factory method to * create an instance of this fragment. */ @AndroidEntryPoint -public class LibraryTopFragment extends Fragment { +public class LibraryPageFragment extends Fragment { @Inject LacertaLibrary lacertaLibrary; @@ -59,11 +42,11 @@ public class LibraryTopFragment extends Fragment { int currentTotalItemCount = 0; - public LibraryTopFragment() { + public LibraryPageFragment() { // Required empty public constructor } - public static LibraryTopFragment newInstance() { - LibraryTopFragment fragment = new LibraryTopFragment(); + public static LibraryPageFragment newInstance() { + LibraryPageFragment fragment = new LibraryPageFragment(); Bundle args = new Bundle(); fragment.setArguments(args); return fragment; diff --git a/feature/library/src/main/res/navigation/feature_library_navigation.xml b/feature/library/src/main/res/navigation/feature_library_navigation.xml index 9f25086b..136b7b98 100644 --- a/feature/library/src/main/res/navigation/feature_library_navigation.xml +++ b/feature/library/src/main/res/navigation/feature_library_navigation.xml @@ -6,7 +6,7 @@ app:startDestination="@id/feature_library_top_fragment"> \ No newline at end of file From 225058f836a1ec100a7a6ee5b2eb54b9b5a43fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 12:11:06 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A3=8A=E3=82=8C=E3=81=9FImport=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/feature/library/LibraryPageFragment.java | 1 - 1 file changed, 1 deletion(-) diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java index ef037666..4ca69e98 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java @@ -21,7 +21,6 @@ import javax.inject.Inject; import dagger.hilt.android.AndroidEntryPoint; import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.utils.LacertaLogger; -import one.nem.lacerta.utils.TextInputDialog; /** From 3f893fc5802c2fe3b576580ac7473ac29102d197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 12:16:56 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=BF=E3=83=95?= =?UTF-8?q?=E3=82=A7=E3=83=BC=E3=82=B9=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/feature/library/DocumentSelectListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/DocumentSelectListener.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/DocumentSelectListener.java index 94ebe0bc..5aa5294a 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/DocumentSelectListener.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/DocumentSelectListener.java @@ -1,5 +1,6 @@ package one.nem.lacerta.feature.library; public interface DocumentSelectListener { - void onDocumentSelect(String documentId); + void onFolderSelected(String folderId, String folderName); + void onDocumentSelected(String documentId, String documentName); } From 1a80d00319bad89ba433b39aac2f2be43206c3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 13:29:40 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AB=E3=83=80?= =?UTF-8?q?=E3=82=92=E9=96=8B=E3=81=91=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/MainActivity.java | 21 +++--- .../lacerta/data/impl/LacertaLibraryImpl.java | 47 ++++++++++++- .../feature/library/LibraryPageFragment.java | 66 ++++++++++++++++--- .../feature/library/ListItemAdapter.java | 10 ++- .../nem/lacerta/model/FragmentNavigation.java | 7 ++ .../one/nem/lacerta/model/PublicPath.java | 22 ++++--- .../one/nem/lacerta/utils/FeatureSwitch.java | 4 +- 7 files changed, 142 insertions(+), 35 deletions(-) create mode 100644 model/src/main/java/one/nem/lacerta/model/FragmentNavigation.java diff --git a/app/src/main/java/one/nem/lacerta/MainActivity.java b/app/src/main/java/one/nem/lacerta/MainActivity.java index 66985ad0..a43cbf4d 100644 --- a/app/src/main/java/one/nem/lacerta/MainActivity.java +++ b/app/src/main/java/one/nem/lacerta/MainActivity.java @@ -3,18 +3,17 @@ package one.nem.lacerta; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.navigation.NavController; import androidx.navigation.fragment.NavHostFragment; import androidx.navigation.ui.NavigationUI; -import android.graphics.Color; import android.os.Bundle; import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; import android.widget.Toast; +import one.nem.lacerta.model.FragmentNavigation; import one.nem.lacerta.model.pref.FeatureSwitchOverride; import one.nem.lacerta.utils.FeatureSwitch; @@ -22,15 +21,13 @@ import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.bottomnavigation.BottomNavigationView; -import java.io.NotActiveException; - import dagger.hilt.android.AndroidEntryPoint; import one.nem.lacerta.utils.repository.SharedPrefUtils; import javax.inject.Inject; @AndroidEntryPoint -public class MainActivity extends AppCompatActivity { +public class MainActivity extends AppCompatActivity implements FragmentNavigation { @Inject SharedPrefUtils sharedPrefUtils; @@ -102,10 +99,6 @@ public class MainActivity extends AppCompatActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(isEnabled); } - public void setActionBarMenuItem(int itemId, boolean isEnabled) { - - } - private void initializeApp() { Log.d("Init", "Initializing app"); // Set feature switch override to default value @@ -120,4 +113,12 @@ public class MainActivity extends AppCompatActivity { boolean isEnabled = FeatureSwitch.Meta.canOverrideSwitch ? sharedPrefUtils.getFeatureSwitchOverride(featureSwitchOverride) : defaultValue; if (!isEnabled) bottomNavigationView.getMenu().removeItem(menuId); } + + @Override + public void navigateToFragment(Fragment fragment) { + getSupportFragmentManager().beginTransaction() + .replace(R.id.nav_host_fragment, fragment) + .addToBackStack(null) + .commit(); + } } diff --git a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java index f2e87da9..f1897557 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java @@ -135,7 +135,52 @@ public class LacertaLibraryImpl implements LacertaLibrary { @Override public CompletableFuture getLibraryPage(String pageId, int limit) { return CompletableFuture.supplyAsync(() -> { - return null; + LibraryItemPage libraryItemPage = new LibraryItemPage(); + + FolderEntity folderEntity = database.folderDao().findById(pageId); + if (folderEntity == null) { + return null; + } + + PublicPath publicPath = new PublicPath().parse(folderEntity.publicPath); + + String resolvedPublicPath = publicPath.resolve(folderEntity.name).getStringPath(); + + logger.debug("LacertaLibraryImpl", "Resolved publicPath: " + resolvedPublicPath); + + List folderEntities = getFolderEntitiesByPublicPath(resolvedPublicPath).join(); + logger.debug("LacertaLibraryImpl", "folderEntities.size(): " + folderEntities.size()); + List documentEntities = getDocumentEntitiesByPublicPath(resolvedPublicPath).join(); + logger.debug("LacertaLibraryImpl", "documentEntities.size(): " + documentEntities.size()); + + ArrayList listItems = new ArrayList<>(); + for (FolderEntity childFolderEntity : folderEntities) { + logger.debug("LacertaLibraryImpl", "childFolderEntity.name: " + childFolderEntity.name); + ListItem listItem = new ListItem(); + listItem.setItemType(ListItemType.ITEM_TYPE_FOLDER); + listItem.setTitle(childFolderEntity.name); + listItem.setDescription("フォルダ"); // TODO-rca: ハードコーディングやめる + listItem.setItemId(childFolderEntity.id); + listItems.add(listItem); + } + + for (DocumentEntity documentEntity : documentEntities) { + logger.debug("LacertaLibraryImpl", "documentEntity.title: " + documentEntity.title); + ListItem listItem = new ListItem(); + listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT); + listItem.setTitle(documentEntity.title); +// listItem.setDescription(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm").format(documentEntity.updatedAt.toInstant())); + listItem.setItemId(documentEntity.id); + listItems.add(listItem); + } + + libraryItemPage.setPageTitle(folderEntity.name); + libraryItemPage.setPageId(folderEntity.id); + libraryItemPage.setListItems(listItems); + + logger.debug("LacertaLibraryImpl", "libraryItemPage.getListItems().size(): " + libraryItemPage.getListItems().size()); + + return libraryItemPage; }); } diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java index 4ca69e98..14baa90c 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java @@ -20,6 +20,7 @@ import javax.inject.Inject; import dagger.hilt.android.AndroidEntryPoint; import one.nem.lacerta.data.LacertaLibrary; +import one.nem.lacerta.model.FragmentNavigation; import one.nem.lacerta.utils.LacertaLogger; @@ -31,6 +32,9 @@ import one.nem.lacerta.utils.LacertaLogger; @AndroidEntryPoint public class LibraryPageFragment extends Fragment { + // Param + private String folderId; + @Inject LacertaLibrary lacertaLibrary; @@ -44,9 +48,18 @@ public class LibraryPageFragment extends Fragment { public LibraryPageFragment() { // Required empty public constructor } + public static LibraryPageFragment newInstance(String folderId) { + LibraryPageFragment fragment = new LibraryPageFragment(); + Bundle args = new Bundle(); + args.putString("folderId", folderId); + fragment.setArguments(args); + return fragment; + } + public static LibraryPageFragment newInstance() { LibraryPageFragment fragment = new LibraryPageFragment(); Bundle args = new Bundle(); + args.putString("folderId", null); fragment.setArguments(args); return fragment; } @@ -73,20 +86,55 @@ public class LibraryPageFragment extends Fragment { RecyclerView recyclerView = view.findViewById(R.id.library_item_recycler_view); - this.listItemAdapter = new ListItemAdapter(documentId -> { - Toast.makeText(getContext(), documentId, Toast.LENGTH_SHORT).show(); + this.listItemAdapter = new ListItemAdapter(new DocumentSelectListener() { + @Override + public void onFolderSelected(String folderId, String folderName) { + logger.debug("LibraryTopFragment", "Folder selected! folderId: " + folderId + ", folderName: " + folderName); + // 画面遷移 + FragmentNavigation fragmentNavigation = (FragmentNavigation) getActivity(); + assert fragmentNavigation != null; + fragmentNavigation.navigateToFragment(LibraryPageFragment.newInstance(folderId)); + } + + @Override + public void onDocumentSelected(String documentId, String documentName) { + Toast.makeText(getContext(), "Document selected! documentId: " + documentId + ", documentName: " + documentName, Toast.LENGTH_SHORT).show(); + } }); recyclerView.setAdapter(listItemAdapter); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - lacertaLibrary.getLibraryPage(10).thenAccept(libraryItemPage -> { - logger.debug("LibraryTopFragment", "Item selected! libraryItemPage.getListItems().size(): " + libraryItemPage.getListItems().size()); - listItemAdapter.setLibraryItemPage(libraryItemPage); - this.currentTotalItemCount = libraryItemPage.getListItems().size(); - getActivity().runOnUiThread(() -> { - listItemAdapter.notifyItemRangeInserted(0, this.currentTotalItemCount - 1); + if (getArguments() != null) { + this.folderId = getArguments().getString("folderId"); + } + + if (this.folderId == null) { // Root + lacertaLibrary.getLibraryPage(10).thenAccept(libraryItemPage -> { + logger.debug("LibraryTopFragment", "Item selected! libraryItemPage.getListItems().size(): " + libraryItemPage.getListItems().size()); + listItemAdapter.setLibraryItemPage(libraryItemPage); + getActivity().runOnUiThread(() -> { + // ActionBarのタイトルを変更する + getActivity().setTitle("ライブラリ"); + // ActionBarに戻るボタンを非表示にする +// getActivity().getActionBar().setDisplayHomeAsUpEnabled(false); + listItemAdapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size() - 1); + }); + this.currentTotalItemCount = libraryItemPage.getListItems().size(); }); - }); + } else { // Root以外 + lacertaLibrary.getLibraryPage(this.folderId, 10).thenAccept(libraryItemPage -> { + logger.debug("LibraryTopFragment", "Item selected! libraryItemPage.getListItems().size(): " + libraryItemPage.getListItems().size()); + listItemAdapter.setLibraryItemPage(libraryItemPage); + getActivity().runOnUiThread(() -> { + // ActionBarのタイトルを変更する + getActivity().setTitle(libraryItemPage.getPageTitle()); + // ActionBarに戻るボタンを表示する +// getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); + listItemAdapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size() - 1); + }); + this.currentTotalItemCount = libraryItemPage.getListItems().size(); + }); + } } @Override diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/ListItemAdapter.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/ListItemAdapter.java index e47c465f..9d538716 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/ListItemAdapter.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/ListItemAdapter.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import one.nem.lacerta.model.LibraryItemPage; import one.nem.lacerta.model.ListItem; +import one.nem.lacerta.model.ListItemType; public class ListItemAdapter extends RecyclerView.Adapter{ @@ -46,9 +47,12 @@ public class ListItemAdapter extends RecyclerView.Adapter { -// Intent intent = new Intent(v.getContext(), ViewerMainActivity.class); -// intent.putExtra("documentId", listItem.getItemId()); -// v.getContext().startActivity(intent); + if (listItem.getItemType() == ListItemType.ITEM_TYPE_DOCUMENT) { + listener.onDocumentSelected(listItem.getItemId(), listItem.getTitle()); + } + else if (listItem.getItemType() == ListItemType.ITEM_TYPE_FOLDER) { + listener.onFolderSelected(listItem.getItemId(), listItem.getTitle()); + } }); } diff --git a/model/src/main/java/one/nem/lacerta/model/FragmentNavigation.java b/model/src/main/java/one/nem/lacerta/model/FragmentNavigation.java new file mode 100644 index 00000000..f7cddea6 --- /dev/null +++ b/model/src/main/java/one/nem/lacerta/model/FragmentNavigation.java @@ -0,0 +1,7 @@ +package one.nem.lacerta.model; + +import androidx.fragment.app.Fragment; + +public interface FragmentNavigation { + void navigateToFragment(Fragment fragment); +} diff --git a/model/src/main/java/one/nem/lacerta/model/PublicPath.java b/model/src/main/java/one/nem/lacerta/model/PublicPath.java index de000fbc..ccd902cb 100644 --- a/model/src/main/java/one/nem/lacerta/model/PublicPath.java +++ b/model/src/main/java/one/nem/lacerta/model/PublicPath.java @@ -1,5 +1,7 @@ package one.nem.lacerta.model; +import android.util.Log; + import java.util.ArrayList; import java.util.List; @@ -27,23 +29,23 @@ public class PublicPath { } private void resolveInternal(String path) { - if (path.startsWith("/")) { - this.path.clear(); - this.path.add("/"); + if (path.equals("..")) { + this.path.remove(this.path.size() - 1); + } else if (path.equals(".")) { + // do nothing } else { - if (path.equals("..")) { - this.path.remove(this.path.size() - 1); - } else if (path.equals(".")) { - // do nothing - } else { - this.path.add(path); - } + this.path.add(path); } } public PublicPath parse(String path) { + if (path.startsWith("/")) { + this.path.clear(); + path = path.substring(1); + } String[] pathArray = path.split("/"); for (String p : pathArray) { + Log.d("PublicPath", "parse: " + p); resolveInternal(p); } return this; diff --git a/utils/src/main/java/one/nem/lacerta/utils/FeatureSwitch.java b/utils/src/main/java/one/nem/lacerta/utils/FeatureSwitch.java index f2b6f742..5d8dbc57 100644 --- a/utils/src/main/java/one/nem/lacerta/utils/FeatureSwitch.java +++ b/utils/src/main/java/one/nem/lacerta/utils/FeatureSwitch.java @@ -7,8 +7,8 @@ public class FeatureSwitch { } public static class FeatureMaster { - public static boolean enableSearch = true; - public static boolean enableDebugMenu = true; + public static boolean enableSearch = false; + public static boolean enableDebugMenu = false; } public static class Setting {