mirror of
https://github.com/leanote/leanote-android.git
synced 2026-01-13 07:03:54 +08:00
show image in detail mode
This commit is contained in:
@@ -12,16 +12,23 @@ import android.text.style.BackgroundColorSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.database.AppDataBase;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.NoteFile;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
import org.houxg.leamonax.service.NoteFileService;
|
||||
import org.houxg.leamonax.utils.FileUtils;
|
||||
import org.houxg.leamonax.utils.TimeUtils;
|
||||
import org.houxg.leamonax.widget.NoteList;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -115,6 +122,21 @@ public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.NoteHolder> {
|
||||
}
|
||||
|
||||
private void renderDetail(NoteHolder holder, final Note note) {
|
||||
List<NoteFile> noteFiles = NoteFileService.getRelatedNoteFiles(note.getId());
|
||||
holder.imageView.setImageDrawable(null);
|
||||
for (NoteFile noteFile : noteFiles) {
|
||||
if (TextUtils.isEmpty(noteFile.getLocalPath())) {
|
||||
continue;
|
||||
}
|
||||
File file = new File(noteFile.getLocalPath());
|
||||
if (FileUtils.isImageFile(file)) {
|
||||
Glide.with(holder.container.getContext())
|
||||
.load(file)
|
||||
.fitCenter()
|
||||
.into(holder.imageView);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (TextUtils.isEmpty(note.getTitle())) {
|
||||
holder.titleTv.setText(R.string.untitled);
|
||||
} else {
|
||||
@@ -247,6 +269,9 @@ public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.NoteHolder> {
|
||||
TextView dirtyTv;
|
||||
@BindView(R.id.container)
|
||||
View container;
|
||||
@Nullable
|
||||
@BindView(R.id.iv_image)
|
||||
ImageView imageView;
|
||||
|
||||
public NoteHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import okio.BufferedSource;
|
||||
@@ -72,6 +73,10 @@ public class NoteFileService {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<NoteFile> getRelatedNoteFiles(long noteLocalId) {
|
||||
return AppDataBase.getAllRelatedFile(noteLocalId);
|
||||
}
|
||||
|
||||
public static InputStream getImage(String localId) {
|
||||
NoteFile noteFile = AppDataBase.getNoteFileByLocalId(localId);
|
||||
if (noteFile == null) {
|
||||
|
||||
10
app/src/main/java/org/houxg/leamonax/utils/FileUtils.java
Normal file
10
app/src/main/java/org/houxg/leamonax/utils/FileUtils.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package org.houxg.leamonax.utils;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FileUtils {
|
||||
public static boolean isImageFile(File file) {
|
||||
return file != null && file.isFile() && file.getName().matches("([^\\s]+(\\.(?i)(jpg|png|gif|bmp))$)");
|
||||
}
|
||||
}
|
||||
@@ -28,20 +28,36 @@
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:textColor="@color/primary_text_light"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginBottom="4dp"
|
||||
tools:text="Leanote API" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_content"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:fontFamily="sans-serif"
|
||||
android:maxHeight="120dp"
|
||||
android:maxLines="4"
|
||||
android:textColor="#9E9E9E"
|
||||
android:textSize="14sp"
|
||||
tools:text="Enim consequat enim pariatur id anim Ut Excepteur dolor in laborum incididunt veniam quis proident. in consequat aliquip in minim adipisicing exercitation sunt sed qui pariatur consequat commodo ea do." />
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/tv_title"
|
||||
android:fontFamily="sans-serif"
|
||||
android:maxHeight="120dp"
|
||||
android:maxLines="6"
|
||||
android:textColor="#9E9E9E"
|
||||
android:textSize="14sp"
|
||||
tools:text="Enim consequat enim pariatur id anim Ut Excepteur dolor in laborum incididunt veniam quis proident. in consequat aliquip in minim adipisicing exercitation sunt sed qui pariatur consequat commodo ea do." />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:maxWidth="100dp"
|
||||
android:maxHeight="100dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user