mirror of
				https://github.com/lacerta-doc/Lacerta.git
				synced 2025-10-31 15:30:49 +00:00 
			
		
		
		
	フォルダを開けるように WIP
This commit is contained in:
		
							parent
							
								
									3f893fc580
								
							
						
					
					
						commit
						1a80d00319
					
				| @ -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(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -135,7 +135,52 @@ public class LacertaLibraryImpl implements LacertaLibrary { | ||||
|     @Override | ||||
|     public CompletableFuture<LibraryItemPage> getLibraryPage(String pageId, int limit) { | ||||
|         return CompletableFuture.supplyAsync(() -> { | ||||
|             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<FolderEntity> folderEntities = getFolderEntitiesByPublicPath(resolvedPublicPath).join(); | ||||
|             logger.debug("LacertaLibraryImpl", "folderEntities.size(): " + folderEntities.size()); | ||||
|             List<DocumentEntity> documentEntities = getDocumentEntitiesByPublicPath(resolvedPublicPath).join(); | ||||
|             logger.debug("LacertaLibraryImpl", "documentEntities.size(): " + documentEntities.size()); | ||||
| 
 | ||||
|             ArrayList<ListItem> 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; | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -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())); | ||||
| 
 | ||||
|         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); | ||||
|             this.currentTotalItemCount = libraryItemPage.getListItems().size(); | ||||
|                 getActivity().runOnUiThread(() -> { | ||||
|                 listItemAdapter.notifyItemRangeInserted(0, this.currentTotalItemCount - 1); | ||||
|                     // 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 | ||||
|  | ||||
| @ -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<ListItemAdapter.ListItemViewHolder>{ | ||||
| 
 | ||||
| @ -46,9 +47,12 @@ public class ListItemAdapter extends RecyclerView.Adapter<ListItemAdapter.ListIt | ||||
|         holder.description.setText(listItem.getDescription()); | ||||
| 
 | ||||
|         holder.itemView.setOnClickListener( v -> { | ||||
| //            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()); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -0,0 +1,7 @@ | ||||
| package one.nem.lacerta.model; | ||||
| 
 | ||||
| import androidx.fragment.app.Fragment; | ||||
| 
 | ||||
| public interface FragmentNavigation { | ||||
|     void navigateToFragment(Fragment fragment); | ||||
| } | ||||
| @ -1,5 +1,7 @@ | ||||
| package one.nem.lacerta.model; | ||||
| 
 | ||||
| import android.util.Log; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| 
 | ||||
| @ -27,10 +29,6 @@ public class PublicPath { | ||||
|     } | ||||
| 
 | ||||
|     private void resolveInternal(String path) { | ||||
|         if (path.startsWith("/")) { | ||||
|             this.path.clear(); | ||||
|             this.path.add("/"); | ||||
|         } else { | ||||
|         if (path.equals("..")) { | ||||
|             this.path.remove(this.path.size() - 1); | ||||
|         } else if (path.equals(".")) { | ||||
| @ -39,11 +37,15 @@ public class PublicPath { | ||||
|             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; | ||||
|  | ||||
| @ -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 { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user