Merge pull request #87 from lacerta-doc/component/viewer/1

ビューワー実装 WIP
This commit is contained in:
ろむねこ 2024-01-21 18:49:50 +09:00 committed by GitHub
commit 0be12e73a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 493 additions and 35 deletions

View File

@ -4,10 +4,10 @@
<selectionStates> <selectionStates>
<SelectionState runConfigName="app"> <SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" /> <option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2023-12-18T03:36:14.973846Z"> <DropdownSelection timestamp="2024-01-20T07:15:21.179573376Z">
<Target type="DEFAULT_BOOT"> <Target type="DEFAULT_BOOT">
<handle> <handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=ZY22H7V3G7" /> <DeviceId pluginId="LocalEmulator" identifier="path=/home/rca/.android/avd/Pixel_3a_API_34_extension_level_7_x86_64.avd" />
</handle> </handle>
</Target> </Target>
</DropdownSelection> </DropdownSelection>

View File

@ -161,13 +161,14 @@ public class ScannerManagerActivity extends AppCompatActivity {
dialog.setCancelable(false); dialog.setCancelable(false);
dialog.show(); dialog.show();
DocumentMeta documentMeta = new DocumentMeta("Untitled"); // TODO-rca: デフォルトタイトルを指定できるようにする DocumentMeta documentMeta = new DocumentMeta("Untitled"); // TODO-rca: デフォルトタイトルを指定できるようにする
document.createDocument(documentMeta).thenAccept((documentDetail1) -> { document.createDocument(documentMeta).thenAccept((documentDetail) -> {
Bitmap[] bitmaps = new Bitmap[this.croppedImages.size()]; Bitmap[] bitmaps = new Bitmap[croppedImages.size()];
this.croppedImages.toArray(bitmaps); croppedImages.toArray(bitmaps);
addPagesToDocumentDetail(documentDetail1, bitmaps).thenRun(() -> { logger.debug(TAG, "bitmaps.length: " + bitmaps.length);
dialog.dismiss(); addPagesToDocumentDetail(documentDetail, bitmaps).join();
finish(); document.updateDocument(documentDetail).join();
}); dialog.dismiss();
finish();
}); });
} }
@ -175,7 +176,7 @@ public class ScannerManagerActivity extends AppCompatActivity {
private CompletableFuture<Void> addPagesToDocumentDetail(DocumentDetail documentDetail, Bitmap[] bitmaps) { private CompletableFuture<Void> addPagesToDocumentDetail(DocumentDetail documentDetail, Bitmap[] bitmaps) {
return CompletableFuture.runAsync(() -> { return CompletableFuture.runAsync(() -> {
try { try {
documentProcessorFactory.create(documentDetail).addNewPagesToLast(bitmaps); document.updateDocument(documentProcessorFactory.create(documentDetail).addNewPagesToLast(bitmaps).getDocumentDetail()).join();
lacertaVcsFactory.create(documentDetail.getMeta().getId()).generateRevisionAtCurrent("Initial commit"); lacertaVcsFactory.create(documentDetail.getMeta().getId()).generateRevisionAtCurrent("Initial commit");
} catch (Exception e) { } catch (Exception e) {
logger.error(TAG, "Error: " + e.getMessage()); logger.error(TAG, "Error: " + e.getMessage());

View File

@ -1,5 +1,6 @@
plugins { plugins {
alias(libs.plugins.com.android.library) alias(libs.plugins.com.android.library)
id 'com.google.dagger.hilt.android'
} }
android { android {
@ -29,7 +30,28 @@ dependencies {
implementation libs.androidx.appcompat implementation libs.androidx.appcompat
implementation libs.com.google.android.material implementation libs.com.google.android.material
implementation libs.androidx.activity
implementation libs.androidx.constraintlayout
testImplementation libs.junit testImplementation libs.junit
androidTestImplementation libs.androidx.test.ext.junit androidTestImplementation libs.androidx.test.ext.junit
androidTestImplementation libs.androidx.test.espresso.core androidTestImplementation libs.androidx.test.espresso.core
// Navigation
implementation libs.navigation.fragment
implementation libs.navigation.ui
implementation libs.navigation.dynamic.features.fragment
// DI
implementation libs.com.google.dagger.hilt.android
annotationProcessor libs.com.google.dagger.hilt.compiler
// shared
implementation project(':shared:ui')
implementation project(':utils')
implementation project(':data')
implementation project(':model')
} }

View File

@ -1,4 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity
android:name=".ViewerMainActivity"
android:exported="false" />
</application>
</manifest> </manifest>

View File

@ -0,0 +1,88 @@
package one.nem.lacerta.component.viewer;
import android.graphics.Bitmap;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint;
import one.nem.lacerta.data.Document;
import one.nem.lacerta.model.document.DocumentDetail;
import one.nem.lacerta.model.document.page.Page;
import one.nem.lacerta.utils.LacertaLogger;
/**
* A simple {@link Fragment} subclass.
* Use the {@link ComponentViewerTopFragment#newInstance} factory method to
* create an instance of this fragment.
*/
@AndroidEntryPoint
public class ComponentViewerTopFragment extends Fragment {
@Inject
Document document;
@Inject
LacertaLogger logger;
private static final String TAG = "ComponentViewerTopFragment";
private String documentId;
public ComponentViewerTopFragment() {
// Required empty public constructor
}
public static ComponentViewerTopFragment newInstance(String documentId) {
ComponentViewerTopFragment fragment = new ComponentViewerTopFragment();
Bundle args = new Bundle();
args.putString("documentId", documentId);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
documentId = getArguments().getString("documentId");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_component_viewer_top, container, false);
RecyclerView recyclerView = view.findViewById(R.id.body_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
ViewerBodyAdapter viewerBodyAdapter = new ViewerBodyAdapter(fileName -> {
Toast.makeText(getContext(), fileName, Toast.LENGTH_SHORT).show();
});
recyclerView.setAdapter(viewerBodyAdapter);
document.getDocument(documentId).thenAccept(documentDetail -> {
ArrayList<Page> pages = documentDetail.getPages();
logger.debug(TAG, "pages.size(): " + pages.size());
viewerBodyAdapter.setPages(pages);
getActivity().runOnUiThread(() -> {
viewerBodyAdapter.notifyItemRangeChanged(0, pages.size());
});
});
return view;
}
}

View File

@ -0,0 +1,5 @@
package one.nem.lacerta.component.viewer;
public interface ItemClickListener {
void onItemClick(String fileName); // DEBUG
}

View File

@ -0,0 +1,66 @@
package one.nem.lacerta.component.viewer;
import android.graphics.Bitmap;
import android.media.Image;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import one.nem.lacerta.model.document.page.Page;
public class ViewerBodyAdapter extends RecyclerView.Adapter<ViewerBodyAdapter.ViewHolder>{
ArrayList<Page> pages;
ItemClickListener listener;
public ViewerBodyAdapter(ArrayList<Page> pages, ItemClickListener listener){
this.pages = pages;
this.listener = listener;
}
public ViewerBodyAdapter(ItemClickListener listener){
this.pages = new ArrayList<>();
this.listener = listener;
}
public void setPages(ArrayList<Page> pages){
this.pages = pages;
}
@NonNull
@Override
public ViewerBodyAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = View.inflate(parent.getContext(), R.layout.viewer_body_list_item, null);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewerBodyAdapter.ViewHolder holder, int position) {
Bitmap bitmap = pages.get(position).getBitmap();
holder.image.setImageBitmap(bitmap);
holder.itemView.setOnClickListener(v -> {
});
}
@Override
public int getItemCount() {
return pages.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
ImageView image;
public ViewHolder(@NonNull View itemView) {
super(itemView);
image = itemView.findViewById(R.id.imageView);
}
}
}

View File

@ -0,0 +1,65 @@
package one.nem.lacerta.component.viewer;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.FragmentManager;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.NavigationUI;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint;
import one.nem.lacerta.utils.LacertaLogger;
@AndroidEntryPoint
public class ViewerMainActivity extends AppCompatActivity {
@Inject
LacertaLogger logger;
@Inject
public ViewerMainActivity() {
}
// Variables
private static final String TAG = "ViewerMainActivity";
String documentId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_viewer_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
Intent intent = getIntent();
try {
documentId = intent.getStringExtra("documentId");
}
catch (Exception e) {
logger.error(TAG, "Failed to get documentId from intent");
logger.error(TAG, "Searchable Error code: " + "f64c21a2-391f-4c40-92f6-183da459de21");
Toast.makeText(this, "Failed to get documentId from intent", Toast.LENGTH_LONG).show();
finish();
}
getSupportFragmentManager().beginTransaction()
.replace(R.id.nav_host_fragment, ComponentViewerTopFragment.newInstance(documentId))
.commitNow();
}
}

View File

@ -0,0 +1,20 @@
package one.nem.lacerta.component.viewer.model;
import android.graphics.Bitmap;
public class ViewerBodyListItem {
Bitmap image;
public ViewerBodyListItem(Bitmap image) {
this.image = image;
}
public Bitmap getImage() {
return image;
}
public void setImage(Bitmap image) {
this.image = image;
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ViewerMainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="one.nem.lacerta.component.viewer.ComponentViewerTopFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,51 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorSurface">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
app:contentScrim="@color/colorSecondaryContainer"
android:background="@color/colorSurface"
android:layout_width="match_parent"
android:layout_height="160dp"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:collapsedTitleGravity="start|center_vertical"
app:expandedTitleGravity="start|bottom"
app:expandedTitleMarginBottom="16dp"
app:expandedTitleMarginStart="16dp"
app:expandedTitleTextAppearance="@style/TextAppearance.MaterialComponents.Headline4"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:title="Title" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/body_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</FrameLayout>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="8dp"
android:adjustViewBounds="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/component_viewer_navigation"
app:startDestination="@id/componentViewerTopFragment">
<fragment
android:id="@+id/componentViewerTopFragment"
android:name="one.nem.lacerta.component.viewer.ComponentViewerTopFragment"
android:label="ComponentViewerTopFragment" />
</navigation>

View File

@ -0,0 +1,4 @@
<resources>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>

View File

@ -20,7 +20,7 @@ public interface Document {
CompletableFuture<Void> deleteDocument(String documentId); CompletableFuture<Void> deleteDocument(String documentId);
CompletableFuture<Void> updateDocument(DocumentMeta meta, DocumentDetail detail); CompletableFuture<Void> updateDocument(DocumentDetail detail);
CompletableFuture<DocumentDetail> getDocument(String documentId); CompletableFuture<DocumentDetail> getDocument(String documentId);
} }

View File

@ -18,6 +18,7 @@ import one.nem.lacerta.model.document.DocumentMeta;
import one.nem.lacerta.model.document.DocumentDetail; import one.nem.lacerta.model.document.DocumentDetail;
// Lacerta/source // Lacerta/source
import one.nem.lacerta.model.document.internal.XmlMetaModel;
import one.nem.lacerta.model.document.internal.XmlMetaPageModel; import one.nem.lacerta.model.document.internal.XmlMetaPageModel;
import one.nem.lacerta.model.document.page.Page; import one.nem.lacerta.model.document.page.Page;
import one.nem.lacerta.source.database.LacertaDatabase; import one.nem.lacerta.source.database.LacertaDatabase;
@ -87,6 +88,9 @@ public class DocumentImpl implements Document {
LacertaVcs vcs = vcsFactory.create(meta.getId()); LacertaVcs vcs = vcsFactory.create(meta.getId());
vcs.createDocument(meta.getId()); vcs.createDocument(meta.getId());
// XmlMeta
updateXmlMeta(detail).join();
return detail; return detail;
}); });
} }
@ -113,8 +117,9 @@ public class DocumentImpl implements Document {
} }
@Override @Override
public CompletableFuture<Void> updateDocument(DocumentMeta meta, DocumentDetail detail) { public CompletableFuture<Void> updateDocument(DocumentDetail detail) {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
updateXmlMeta(detail).join();
return null; return null;
}); });
} }
@ -139,9 +144,11 @@ public class DocumentImpl implements Document {
DocumentDetail detail = new DocumentDetail(); DocumentDetail detail = new DocumentDetail();
getPagesByXmlMeta(documentId).thenCompose(xmlMetaPageModels -> getPagesByXmlMetaPageModel(documentId, xmlMetaPageModels)).thenAccept(pages -> { getPagesByXmlMeta(documentId).thenCompose(xmlMetaPageModels -> getPagesByXmlMetaPageModel(documentId, xmlMetaPageModels)).thenAccept(pages -> {
logger.debug(TAG, "pages: " + pages.size());
detail.setMeta(meta); detail.setMeta(meta);
detail.setPages(pages); detail.setPages(pages);
}); }).join();
return detail; return detail;
}); });
} }
@ -150,7 +157,13 @@ public class DocumentImpl implements Document {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory()); FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory());
try { try {
return xmlMetaParser.deserialize(fileManager.resolve(documentId).loadXml("meta.xml")).getPages(); ArrayList<XmlMetaPageModel> xmlMetaPageModels = xmlMetaParser.deserialize(fileManager.resolve(documentId).loadXml("meta.xml")).getPages();
// Debug
logger.debug(TAG, "xmlMetaPageModels: " + xmlMetaPageModels.size());
for (XmlMetaPageModel xmlMetaPageModel : xmlMetaPageModels) {
logger.debug(TAG, "\txmlMetaPageModel: " + xmlMetaPageModel.getFilename());
}
return xmlMetaPageModels;
} catch (IOException e) { } catch (IOException e) {
logger.error(TAG, "DocumentMeta parse error"); logger.error(TAG, "DocumentMeta parse error");
logger.trace(TAG, e.getMessage()); logger.trace(TAG, e.getMessage());
@ -174,7 +187,7 @@ public class DocumentImpl implements Document {
} }
for (XmlMetaPageModel xmlMetaPageModel : xmlMetaPageModels) { for (XmlMetaPageModel xmlMetaPageModel : xmlMetaPageModels) {
try { try {
pages.add(new Page(xmlMetaPageModel.getFilename(), fileManager.loadBitmap(xmlMetaPageModel.getFilename()))); pages.add(new Page(xmlMetaPageModel.getFilename(), fileManager.resolve("raw").loadBitmap(xmlMetaPageModel.getFilename())));
} catch (IOException e) { } catch (IOException e) {
logger.error(TAG, "Bitmap decode error"); logger.error(TAG, "Bitmap decode error");
logger.trace(TAG, e.getMessage()); logger.trace(TAG, e.getMessage());
@ -185,4 +198,24 @@ public class DocumentImpl implements Document {
return pages; return pages;
}); });
} }
private CompletableFuture<Void> updateXmlMeta(DocumentDetail documentDetail) {
return CompletableFuture.supplyAsync(() -> {
// TODO-rca: リビジョンIDを検証する, 挿入する
FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory());
ArrayList<XmlMetaPageModel> xmlMetaPageModels = new ArrayList<>();
for (Page page : documentDetail.getPages()) {
xmlMetaPageModels.add(new XmlMetaPageModel(page.getFileName()));
}
try {
fileManager.createDirectoryIfNotExist(documentDetail.getMeta().getId()).resolve(documentDetail.getMeta().getId())
.createFileIfNotExist("meta.xml").resolve("meta.xml").saveXml(xmlMetaParser.serialize(new XmlMetaModel("revisionId_PLACEHOLDER", xmlMetaPageModels)));
} catch (IOException e) {
logger.error(TAG, "DocumentMeta serialize error");
logger.trace(TAG, e.getMessage());
logger.e_code("e3b4d0c9-5b7e-4b7e-9e9a-5b8b8b8b8b8b");
}
return null;
});
}
} }

View File

@ -57,4 +57,6 @@ dependencies {
implementation "androidx.recyclerview:recyclerview:1.3.2" implementation "androidx.recyclerview:recyclerview:1.3.2"
implementation project(':component:common') implementation project(':component:common')
implementation project(':component:viewer')
} }

View File

@ -0,0 +1,5 @@
package one.nem.lacerta.feature.home;
public interface DocumentSelectListener {
void onDocumentSelect(String documentId);
}

View File

@ -1,5 +1,6 @@
package one.nem.lacerta.feature.home; package one.nem.lacerta.feature.home;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -28,6 +29,7 @@ import java.util.concurrent.CompletableFuture;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint; import dagger.hilt.android.AndroidEntryPoint;
import one.nem.lacerta.component.viewer.ViewerMainActivity;
import one.nem.lacerta.data.Document; import one.nem.lacerta.data.Document;
import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.data.LacertaLibrary;
import one.nem.lacerta.model.ListItem; import one.nem.lacerta.model.ListItem;
@ -78,7 +80,12 @@ public class HomeTopFragment extends Fragment {
RecyclerView recyclerView = view.findViewById(R.id.home_item_recycler_view); RecyclerView recyclerView = view.findViewById(R.id.home_item_recycler_view);
ListItemAdapter listItemAdapter = new ListItemAdapter(); ListItemAdapter listItemAdapter = new ListItemAdapter(documentId -> {
Log.d("HomeTopFragment", "onViewCreated: " + documentId);
Intent intent = new Intent(getContext(), ViewerMainActivity.class);
intent.putExtra("documentId", documentId);
startActivity(intent);
});
recyclerView.setAdapter(listItemAdapter); recyclerView.setAdapter(listItemAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

View File

@ -1,5 +1,6 @@
package one.nem.lacerta.feature.home; package one.nem.lacerta.feature.home;
import android.content.Intent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -11,18 +12,18 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList; import java.util.ArrayList;
import one.nem.lacerta.component.viewer.ViewerMainActivity;
import one.nem.lacerta.model.ListItem; import one.nem.lacerta.model.ListItem;
public class ListItemAdapter extends RecyclerView.Adapter<ListItemAdapter.ListItemViewHolder>{ public class ListItemAdapter extends RecyclerView.Adapter<ListItemAdapter.ListItemViewHolder>{
ArrayList<ListItem> listItems; ArrayList<ListItem> listItems;
public ListItemAdapter(ArrayList<ListItem> listItems){ DocumentSelectListener listener;
this.listItems = listItems;
}
public ListItemAdapter() { public ListItemAdapter(DocumentSelectListener listener){
this.listItems = new ArrayList<>(); this.listItems = new ArrayList<>();
this.listener = listener;
} }
public void setListItems(ArrayList<ListItem> listItems) { public void setListItems(ArrayList<ListItem> listItems) {
@ -43,6 +44,12 @@ public class ListItemAdapter extends RecyclerView.Adapter<ListItemAdapter.ListIt
holder.icon.setColorFilter(one.nem.lacerta.shared.ui.R.color.colorOnSurface); holder.icon.setColorFilter(one.nem.lacerta.shared.ui.R.color.colorOnSurface);
holder.title.setText(listItem.getTitle()); holder.title.setText(listItem.getTitle());
holder.description.setText(listItem.getDescription()); 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);
});
} }
@Override @Override

View File

@ -7,13 +7,13 @@ import one.nem.lacerta.model.document.DocumentDetail;
public interface DocumentProcessor { public interface DocumentProcessor {
// ページ操作 // ページ操作
void addNewPageToLast(Bitmap bitmap) throws Exception; DocumentProcessor addNewPageToLast(Bitmap bitmap) throws Exception;
void addNewPagesToLast(Bitmap[] bitmaps) throws Exception; DocumentProcessor addNewPagesToLast(Bitmap[] bitmaps) throws Exception;
void insertPageAtIndex(Bitmap bitmap, int index) throws Exception; DocumentProcessor insertPageAtIndex(Bitmap bitmap, int index) throws Exception;
void removePageAtIndex(int index) throws Exception; DocumentProcessor removePageAtIndex(int index) throws Exception;
// 更新 // 更新
void updatePageAtIndex(Bitmap bitmap, int index); DocumentProcessor updatePageAtIndex(Bitmap bitmap, int index);
// ページ取得 // ページ取得
Bitmap getPageAtIndex(int index); Bitmap getPageAtIndex(int index);

View File

@ -70,7 +70,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{
@Override @Override
public void addNewPageToLast(Bitmap bitmap) throws Exception{ public DocumentProcessor addNewPageToLast(Bitmap bitmap) throws Exception{
logger.debug("addNewPageToLast", "called"); logger.debug("addNewPageToLast", "called");
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
@ -85,19 +85,23 @@ public class DocumentProcessorImpl implements DocumentProcessor{
logger.info("addNewPageToLast", "finished"); logger.info("addNewPageToLast", "finished");
logger.info("addNewPageToLast", "filename: " + filename); logger.info("addNewPageToLast", "filename: " + filename);
return this;
} }
@Override @Override
public void addNewPagesToLast(Bitmap[] bitmaps) throws Exception{ public DocumentProcessor addNewPagesToLast(Bitmap[] bitmaps) throws Exception{
logger.debug("addNewPagesToLast", "called"); logger.debug("addNewPagesToLast", "called");
for (Bitmap bitmap : bitmaps) { for (Bitmap bitmap : bitmaps) {
addNewPageToLast(bitmap); addNewPageToLast(bitmap);
} // TODO-rca: 効率悪いので改善する } // TODO-rca: 効率悪いので改善する
return this;
} }
@Override @Override
public void insertPageAtIndex(Bitmap bitmap, int index) throws Exception { public DocumentProcessor insertPageAtIndex(Bitmap bitmap, int index) throws Exception {
logger.debug("addNewPageAfterIndex", "called"); logger.debug("addNewPageAfterIndex", "called");
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
@ -109,16 +113,18 @@ public class DocumentProcessorImpl implements DocumentProcessor{
this.documentDetail.getPages().add(index, page); this.documentDetail.getPages().add(index, page);
lacertaVcs.insertPage(index, filename); lacertaVcs.insertPage(index, filename);
return this;
} }
@Override @Override
public void removePageAtIndex(int index) { public DocumentProcessor removePageAtIndex(int index) {
return null;
} }
@Override @Override
public void updatePageAtIndex(Bitmap bitmap, int index) { public DocumentProcessor updatePageAtIndex(Bitmap bitmap, int index) {
return null;
} }
@Override @Override

View File

@ -37,7 +37,11 @@ public class FileManagerImpl implements FileManager {
@AssistedInject @AssistedInject
public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) { public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) {
this.logger = logger; this.logger = logger;
if (rootDir == null) {
throw new IllegalArgumentException("rootDir must not be null");
}
this.rootDir = rootDir; this.rootDir = rootDir;
this.path = rootDir;
} }
// for generate new instance // for generate new instance
@ -62,6 +66,10 @@ public class FileManagerImpl implements FileManager {
try { try {
resolvedPath = resolvedPath.resolve(pathPart); resolvedPath = resolvedPath.resolve(pathPart);
} catch (Exception e) { } catch (Exception e) {
logger.error("resolveStringPath", e.getMessage());
logger.debug("resolveStringPath", "this.path: " + this.path);
logger.debug("resolveStringPath", "pathPart: " + pathPart);
logger.debug("resolveStringPath", "resolvedPath: " + resolvedPath);
throw new IOException("Invalid path: " + path); throw new IOException("Invalid path: " + path);
} }
} }

View File

@ -20,7 +20,9 @@ public class DeviceInfoUtilsImpl implements DeviceInfoUtils {
@Override @Override
public Path getExternalStorageDirectory() { public Path getExternalStorageDirectory() {
// TODO-rca: 結果がnullだった場合の処理を追加する if (applicationContext.getExternalFilesDir(null) == null) {
throw new RuntimeException("applicationContext.getExternalFilesDir(null) is null");
}
return Objects.requireNonNull(applicationContext.getExternalFilesDir(null)).toPath(); return Objects.requireNonNull(applicationContext.getExternalFilesDir(null)).toPath();
} }
@ -31,7 +33,9 @@ public class DeviceInfoUtilsImpl implements DeviceInfoUtils {
@Override @Override
public Path getExternalStorageDirectory(String type) { public Path getExternalStorageDirectory(String type) {
// TODO-rca: 結果がnullだった場合の処理を追加する if(applicationContext.getExternalFilesDir(type) == null) {
throw new RuntimeException("applicationContext.getExternalFilesDir(" + type + ") is null");
}
return Objects.requireNonNull(applicationContext.getExternalFilesDir(type)).toPath(); return Objects.requireNonNull(applicationContext.getExternalFilesDir(type)).toPath();
} }

View File

@ -17,6 +17,8 @@ import one.nem.lacerta.utils.LacertaLogger;
public class XmlMetaParserImpl implements XmlMetaParser{ public class XmlMetaParserImpl implements XmlMetaParser{
String TAG = getClass().getSimpleName();
@Inject @Inject
LacertaLogger logger; LacertaLogger logger;
@ -35,13 +37,18 @@ public class XmlMetaParserImpl implements XmlMetaParser{
meta.setRevisionId(rootElement.getElementsByTagName("revisionId").item(0).getTextContent()); meta.setRevisionId(rootElement.getElementsByTagName("revisionId").item(0).getTextContent());
ArrayList<XmlMetaPageModel> pages = new ArrayList<>(); ArrayList<XmlMetaPageModel> pages = new ArrayList<>();
for(int i = 0; i < rootElement.getElementsByTagName("pages").getLength(); i++) { for (int i = 0; i < rootElement.getElementsByTagName("page").getLength(); i++) {
Element pageElement = (Element) rootElement.getElementsByTagName("page").item(i); Element pageElement = (Element) rootElement.getElementsByTagName("page").item(i);
XmlMetaPageModel page = new XmlMetaPageModel(); XmlMetaPageModel page = new XmlMetaPageModel();
page.setFilename(pageElement.getElementsByTagName("filename").item(0).getTextContent()); page.setFilename(pageElement.getElementsByTagName("filename").item(0).getTextContent());
pages.add(page); pages.add(page);
} }
logger.debug(TAG, "Parsed Meta: " + meta.getRevisionId() + " " + pages.size() + " pages.");
for (XmlMetaPageModel page : pages) {
logger.debug(TAG, "\tPage: " + page.getFilename());
}
meta.setPages(pages); meta.setPages(pages);
return meta; return meta;