mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-22 16:03:15 +00:00
commit
0be12e73a8
|
@ -4,10 +4,10 @@
|
|||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<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">
|
||||
<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>
|
||||
</Target>
|
||||
</DropdownSelection>
|
||||
|
|
|
@ -161,21 +161,22 @@ public class ScannerManagerActivity extends AppCompatActivity {
|
|||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
DocumentMeta documentMeta = new DocumentMeta("Untitled"); // TODO-rca: デフォルトタイトルを指定できるようにする
|
||||
document.createDocument(documentMeta).thenAccept((documentDetail1) -> {
|
||||
Bitmap[] bitmaps = new Bitmap[this.croppedImages.size()];
|
||||
this.croppedImages.toArray(bitmaps);
|
||||
addPagesToDocumentDetail(documentDetail1, bitmaps).thenRun(() -> {
|
||||
document.createDocument(documentMeta).thenAccept((documentDetail) -> {
|
||||
Bitmap[] bitmaps = new Bitmap[croppedImages.size()];
|
||||
croppedImages.toArray(bitmaps);
|
||||
logger.debug(TAG, "bitmaps.length: " + bitmaps.length);
|
||||
addPagesToDocumentDetail(documentDetail, bitmaps).join();
|
||||
document.updateDocument(documentDetail).join();
|
||||
dialog.dismiss();
|
||||
finish();
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> addPagesToDocumentDetail(DocumentDetail documentDetail, Bitmap[] bitmaps) {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
documentProcessorFactory.create(documentDetail).addNewPagesToLast(bitmaps);
|
||||
document.updateDocument(documentProcessorFactory.create(documentDetail).addNewPagesToLast(bitmaps).getDocumentDetail()).join();
|
||||
lacertaVcsFactory.create(documentDetail.getMeta().getId()).generateRevisionAtCurrent("Initial commit");
|
||||
} catch (Exception e) {
|
||||
logger.error(TAG, "Error: " + e.getMessage());
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
plugins {
|
||||
alias(libs.plugins.com.android.library)
|
||||
id 'com.google.dagger.hilt.android'
|
||||
}
|
||||
|
||||
android {
|
||||
|
@ -29,7 +30,28 @@ dependencies {
|
|||
|
||||
implementation libs.androidx.appcompat
|
||||
implementation libs.com.google.android.material
|
||||
implementation libs.androidx.activity
|
||||
implementation libs.androidx.constraintlayout
|
||||
testImplementation libs.junit
|
||||
androidTestImplementation libs.androidx.test.ext.junit
|
||||
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')
|
||||
|
||||
}
|
|
@ -1,4 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application>
|
||||
<activity
|
||||
android:name=".ViewerMainActivity"
|
||||
android:exported="false" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package one.nem.lacerta.component.viewer;
|
||||
|
||||
public interface ItemClickListener {
|
||||
void onItemClick(String fileName); // DEBUG
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
4
component/viewer/src/main/res/values/strings.xml
Normal file
4
component/viewer/src/main/res/values/strings.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<resources>
|
||||
<!-- TODO: Remove or change this placeholder text -->
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
</resources>
|
|
@ -20,7 +20,7 @@ public interface Document {
|
|||
|
||||
CompletableFuture<Void> deleteDocument(String documentId);
|
||||
|
||||
CompletableFuture<Void> updateDocument(DocumentMeta meta, DocumentDetail detail);
|
||||
CompletableFuture<Void> updateDocument(DocumentDetail detail);
|
||||
|
||||
CompletableFuture<DocumentDetail> getDocument(String documentId);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import one.nem.lacerta.model.document.DocumentMeta;
|
|||
import one.nem.lacerta.model.document.DocumentDetail;
|
||||
|
||||
// Lacerta/source
|
||||
import one.nem.lacerta.model.document.internal.XmlMetaModel;
|
||||
import one.nem.lacerta.model.document.internal.XmlMetaPageModel;
|
||||
import one.nem.lacerta.model.document.page.Page;
|
||||
import one.nem.lacerta.source.database.LacertaDatabase;
|
||||
|
@ -87,6 +88,9 @@ public class DocumentImpl implements Document {
|
|||
LacertaVcs vcs = vcsFactory.create(meta.getId());
|
||||
vcs.createDocument(meta.getId());
|
||||
|
||||
// XmlMeta
|
||||
updateXmlMeta(detail).join();
|
||||
|
||||
return detail;
|
||||
});
|
||||
}
|
||||
|
@ -113,8 +117,9 @@ public class DocumentImpl implements Document {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> updateDocument(DocumentMeta meta, DocumentDetail detail) {
|
||||
public CompletableFuture<Void> updateDocument(DocumentDetail detail) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
updateXmlMeta(detail).join();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
@ -139,9 +144,11 @@ public class DocumentImpl implements Document {
|
|||
DocumentDetail detail = new DocumentDetail();
|
||||
|
||||
getPagesByXmlMeta(documentId).thenCompose(xmlMetaPageModels -> getPagesByXmlMetaPageModel(documentId, xmlMetaPageModels)).thenAccept(pages -> {
|
||||
logger.debug(TAG, "pages: " + pages.size());
|
||||
detail.setMeta(meta);
|
||||
detail.setPages(pages);
|
||||
});
|
||||
}).join();
|
||||
|
||||
return detail;
|
||||
});
|
||||
}
|
||||
|
@ -150,7 +157,13 @@ public class DocumentImpl implements Document {
|
|||
return CompletableFuture.supplyAsync(() -> {
|
||||
FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory());
|
||||
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) {
|
||||
logger.error(TAG, "DocumentMeta parse error");
|
||||
logger.trace(TAG, e.getMessage());
|
||||
|
@ -174,7 +187,7 @@ public class DocumentImpl implements Document {
|
|||
}
|
||||
for (XmlMetaPageModel xmlMetaPageModel : xmlMetaPageModels) {
|
||||
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) {
|
||||
logger.error(TAG, "Bitmap decode error");
|
||||
logger.trace(TAG, e.getMessage());
|
||||
|
@ -185,4 +198,24 @@ public class DocumentImpl implements Document {
|
|||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,4 +57,6 @@ dependencies {
|
|||
implementation "androidx.recyclerview:recyclerview:1.3.2"
|
||||
|
||||
implementation project(':component:common')
|
||||
|
||||
implementation project(':component:viewer')
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package one.nem.lacerta.feature.home;
|
||||
|
||||
public interface DocumentSelectListener {
|
||||
void onDocumentSelect(String documentId);
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package one.nem.lacerta.feature.home;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -28,6 +29,7 @@ import java.util.concurrent.CompletableFuture;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import one.nem.lacerta.component.viewer.ViewerMainActivity;
|
||||
import one.nem.lacerta.data.Document;
|
||||
import one.nem.lacerta.data.LacertaLibrary;
|
||||
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);
|
||||
|
||||
|
||||
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.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package one.nem.lacerta.feature.home;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -11,18 +12,18 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import one.nem.lacerta.component.viewer.ViewerMainActivity;
|
||||
import one.nem.lacerta.model.ListItem;
|
||||
|
||||
public class ListItemAdapter extends RecyclerView.Adapter<ListItemAdapter.ListItemViewHolder>{
|
||||
|
||||
ArrayList<ListItem> listItems;
|
||||
|
||||
public ListItemAdapter(ArrayList<ListItem> listItems){
|
||||
this.listItems = listItems;
|
||||
}
|
||||
DocumentSelectListener listener;
|
||||
|
||||
public ListItemAdapter() {
|
||||
public ListItemAdapter(DocumentSelectListener listener){
|
||||
this.listItems = new ArrayList<>();
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
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.title.setText(listItem.getTitle());
|
||||
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
|
||||
|
|
|
@ -7,13 +7,13 @@ import one.nem.lacerta.model.document.DocumentDetail;
|
|||
public interface DocumentProcessor {
|
||||
|
||||
// ページ操作
|
||||
void addNewPageToLast(Bitmap bitmap) throws Exception;
|
||||
void addNewPagesToLast(Bitmap[] bitmaps) throws Exception;
|
||||
void insertPageAtIndex(Bitmap bitmap, int index) throws Exception;
|
||||
void removePageAtIndex(int index) throws Exception;
|
||||
DocumentProcessor addNewPageToLast(Bitmap bitmap) throws Exception;
|
||||
DocumentProcessor addNewPagesToLast(Bitmap[] bitmaps) throws Exception;
|
||||
DocumentProcessor insertPageAtIndex(Bitmap bitmap, 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);
|
||||
|
|
|
@ -70,7 +70,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
|||
|
||||
|
||||
@Override
|
||||
public void addNewPageToLast(Bitmap bitmap) throws Exception{
|
||||
public DocumentProcessor addNewPageToLast(Bitmap bitmap) throws Exception{
|
||||
logger.debug("addNewPageToLast", "called");
|
||||
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
|
||||
|
||||
|
@ -85,19 +85,23 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
|||
|
||||
logger.info("addNewPageToLast", "finished");
|
||||
logger.info("addNewPageToLast", "filename: " + filename);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNewPagesToLast(Bitmap[] bitmaps) throws Exception{
|
||||
public DocumentProcessor addNewPagesToLast(Bitmap[] bitmaps) throws Exception{
|
||||
logger.debug("addNewPagesToLast", "called");
|
||||
|
||||
for (Bitmap bitmap : bitmaps) {
|
||||
addNewPageToLast(bitmap);
|
||||
} // TODO-rca: 効率悪いので改善する
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertPageAtIndex(Bitmap bitmap, int index) throws Exception {
|
||||
public DocumentProcessor insertPageAtIndex(Bitmap bitmap, int index) throws Exception {
|
||||
logger.debug("addNewPageAfterIndex", "called");
|
||||
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
|
||||
|
||||
|
@ -109,16 +113,18 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
|||
this.documentDetail.getPages().add(index, page);
|
||||
|
||||
lacertaVcs.insertPage(index, filename);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePageAtIndex(int index) {
|
||||
|
||||
public DocumentProcessor removePageAtIndex(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePageAtIndex(Bitmap bitmap, int index) {
|
||||
|
||||
public DocumentProcessor updatePageAtIndex(Bitmap bitmap, int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,7 +37,11 @@ public class FileManagerImpl implements FileManager {
|
|||
@AssistedInject
|
||||
public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) {
|
||||
this.logger = logger;
|
||||
if (rootDir == null) {
|
||||
throw new IllegalArgumentException("rootDir must not be null");
|
||||
}
|
||||
this.rootDir = rootDir;
|
||||
this.path = rootDir;
|
||||
}
|
||||
|
||||
// for generate new instance
|
||||
|
@ -62,6 +66,10 @@ public class FileManagerImpl implements FileManager {
|
|||
try {
|
||||
resolvedPath = resolvedPath.resolve(pathPart);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@ public class DeviceInfoUtilsImpl implements DeviceInfoUtils {
|
|||
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -31,7 +33,9 @@ public class DeviceInfoUtilsImpl implements DeviceInfoUtils {
|
|||
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ import one.nem.lacerta.utils.LacertaLogger;
|
|||
|
||||
public class XmlMetaParserImpl implements XmlMetaParser{
|
||||
|
||||
String TAG = getClass().getSimpleName();
|
||||
|
||||
@Inject
|
||||
LacertaLogger logger;
|
||||
|
||||
|
@ -35,13 +37,18 @@ public class XmlMetaParserImpl implements XmlMetaParser{
|
|||
meta.setRevisionId(rootElement.getElementsByTagName("revisionId").item(0).getTextContent());
|
||||
|
||||
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);
|
||||
XmlMetaPageModel page = new XmlMetaPageModel();
|
||||
page.setFilename(pageElement.getElementsByTagName("filename").item(0).getTextContent());
|
||||
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);
|
||||
|
||||
return meta;
|
||||
|
|
Loading…
Reference in New Issue
Block a user