mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-26 17:53:14 +00:00
iroiro
This commit is contained in:
parent
a825ad6a36
commit
dc9a6bfd9b
|
@ -1,20 +1,36 @@
|
||||||
package one.nem.lacerta.component.viewer;
|
package one.nem.lacerta.component.viewer;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
* Use the {@link ComponentViewerTopFragment#newInstance} factory method to
|
* Use the {@link ComponentViewerTopFragment#newInstance} factory method to
|
||||||
* create an instance of this fragment.
|
* create an instance of this fragment.
|
||||||
*/
|
*/
|
||||||
|
@AndroidEntryPoint
|
||||||
public class ComponentViewerTopFragment extends Fragment {
|
public class ComponentViewerTopFragment extends Fragment {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
Document document;
|
||||||
|
|
||||||
private static final String TAG = "ComponentViewerTopFragment";
|
private static final String TAG = "ComponentViewerTopFragment";
|
||||||
|
|
||||||
private String documentId;
|
private String documentId;
|
||||||
|
@ -43,6 +59,18 @@ public class ComponentViewerTopFragment extends Fragment {
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
return inflater.inflate(R.layout.fragment_component_viewer_top, container, false);
|
View view = inflater.inflate(R.layout.fragment_component_viewer_top, container, false);
|
||||||
|
|
||||||
|
DocumentDetail documentDetail = document.getDocument(documentId);
|
||||||
|
|
||||||
|
ArrayList<Page> documentPages = new ArrayList<>();
|
||||||
|
documentPages = documentDetail.getPages();
|
||||||
|
|
||||||
|
RecyclerView recyclerView = view.findViewById(R.id.body_recycler_view);
|
||||||
|
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
|
ViewerBodyAdapter viewerBodyAdapter = new ViewerBodyAdapter(documentPages);
|
||||||
|
recyclerView.setAdapter(viewerBodyAdapter);
|
||||||
|
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,12 +11,14 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import one.nem.lacerta.model.document.page.Page;
|
||||||
|
|
||||||
public class ViewerBodyAdapter extends RecyclerView.Adapter<ViewerBodyAdapter.ViewHolder>{
|
public class ViewerBodyAdapter extends RecyclerView.Adapter<ViewerBodyAdapter.ViewHolder>{
|
||||||
|
|
||||||
ArrayList<Bitmap> images;
|
ArrayList<Page> pages;
|
||||||
|
|
||||||
public ViewerBodyAdapter(ArrayList<Bitmap> images){
|
public ViewerBodyAdapter(ArrayList<Page> pages){
|
||||||
this.images = images;
|
this.pages = pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -28,12 +30,13 @@ public class ViewerBodyAdapter extends RecyclerView.Adapter<ViewerBodyAdapter.Vi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ViewerBodyAdapter.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ViewerBodyAdapter.ViewHolder holder, int position) {
|
||||||
holder.image.setImageBitmap(images.get(position));
|
Bitmap bitmap = pages.get(position).getBitmap();
|
||||||
|
holder.image.setImageBitmap(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return images.size();
|
return pages.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder{
|
public class ViewHolder extends RecyclerView.ViewHolder{
|
||||||
|
|
|
@ -59,5 +59,9 @@ public class ViewerMainActivity extends AppCompatActivity {
|
||||||
Toast.makeText(this, "Failed to get documentId from intent", Toast.LENGTH_LONG).show();
|
Toast.makeText(this, "Failed to get documentId from intent", Toast.LENGTH_LONG).show();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSupportFragmentManager().beginTransaction()
|
||||||
|
.replace(R.id.nav_host_fragment, ComponentViewerTopFragment.newInstance(documentId))
|
||||||
|
.commitNow();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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"
|
||||||
|
android:layout_margin="16dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/imageView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:elevation="8dp"
|
||||||
|
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>
|
Loading…
Reference in New Issue
Block a user