mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-23 00:13:16 +00:00
Merge pull request #77 from lacerta-doc/feature/lacerta_library_recent
Feature/lacerta library recent
This commit is contained in:
commit
5c3d811979
|
@ -1,5 +1,8 @@
|
||||||
package one.nem.lacerta.data;
|
package one.nem.lacerta.data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import one.nem.lacerta.model.ListItem;
|
||||||
import one.nem.lacerta.model.ListItemType;
|
import one.nem.lacerta.model.ListItemType;
|
||||||
|
|
||||||
import one.nem.lacerta.model.LibraryItemPage;
|
import one.nem.lacerta.model.LibraryItemPage;
|
||||||
|
@ -8,8 +11,8 @@ import one.nem.lacerta.model.document.DocumentDetail;
|
||||||
public interface LacertaLibrary {
|
public interface LacertaLibrary {
|
||||||
|
|
||||||
// Get History
|
// Get History
|
||||||
LibraryItemPage getRecentDocument(int limit);
|
ArrayList<ListItem> getRecentDocument(int limit);
|
||||||
LibraryItemPage getRecentDocument(int limit, int offset);
|
ArrayList<ListItem> getRecentDocument(int limit, int offset);
|
||||||
|
|
||||||
// Get Library page
|
// Get Library page
|
||||||
LibraryItemPage getLibraryPage(int limit);
|
LibraryItemPage getLibraryPage(int limit);
|
||||||
|
|
|
@ -1,18 +1,48 @@
|
||||||
package one.nem.lacerta.data.impl;
|
package one.nem.lacerta.data.impl;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import one.nem.lacerta.data.LacertaLibrary;
|
import one.nem.lacerta.data.LacertaLibrary;
|
||||||
import one.nem.lacerta.model.LibraryItemPage;
|
import one.nem.lacerta.model.LibraryItemPage;
|
||||||
|
import one.nem.lacerta.model.ListItem;
|
||||||
|
import one.nem.lacerta.model.ListItemType;
|
||||||
import one.nem.lacerta.model.document.DocumentDetail;
|
import one.nem.lacerta.model.document.DocumentDetail;
|
||||||
|
import one.nem.lacerta.source.database.LacertaDatabase;
|
||||||
|
import one.nem.lacerta.source.database.common.DateTypeConverter;
|
||||||
|
import one.nem.lacerta.source.database.entity.DocumentEntity;
|
||||||
|
import one.nem.lacerta.utils.LacertaLogger;
|
||||||
|
|
||||||
public class LacertaLibraryImpl implements LacertaLibrary {
|
public class LacertaLibraryImpl implements LacertaLibrary {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
LacertaLogger logger;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
LacertaDatabase database;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LibraryItemPage getRecentDocument(int limit) {
|
public ArrayList<ListItem> getRecentDocument(int limit) {
|
||||||
return null;
|
List<DocumentEntity> documentEntities = database.documentDao().getRecentDocument(limit);
|
||||||
|
|
||||||
|
ArrayList<ListItem> listItems = new ArrayList<>();
|
||||||
|
for (DocumentEntity documentEntity : documentEntities) {
|
||||||
|
ListItem listItem = new ListItem();
|
||||||
|
listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT);
|
||||||
|
listItem.setTitle(documentEntity.title);
|
||||||
|
listItem.setDescription(DateFormat.getDateInstance().format(documentEntity.updatedAt));
|
||||||
|
listItem.setItemId(documentEntity.id);
|
||||||
|
listItems.add(listItem);
|
||||||
|
}
|
||||||
|
return listItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LibraryItemPage getRecentDocument(int limit, int offset) {
|
public ArrayList<ListItem> getRecentDocument(int limit, int offset) {
|
||||||
return null;
|
return null; // TODO-rca: Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -148,8 +148,8 @@ public class LacertaLibraryStubImpl implements LacertaLibrary {
|
||||||
* @return ページオブジェクト
|
* @return ページオブジェクト
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public LibraryItemPage getRecentDocument(int limit) {
|
public ArrayList<ListItem> getRecentDocument(int limit) {
|
||||||
return getRecentDocumentPage(limit);
|
return getRecentDocumentPage(limit).getListItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,8 +159,8 @@ public class LacertaLibraryStubImpl implements LacertaLibrary {
|
||||||
* @return ページオブジェクト
|
* @return ページオブジェクト
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public LibraryItemPage getRecentDocument(int limit, int offset) {
|
public ArrayList<ListItem> getRecentDocument(int limit, int offset) {
|
||||||
return getRecentDocumentPage(limit);
|
return getRecentDocumentPage(limit).getListItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -47,4 +47,7 @@ dependencies {
|
||||||
// Utils モジュール
|
// Utils モジュール
|
||||||
implementation project(':utils')
|
implementation project(':utils')
|
||||||
|
|
||||||
|
// Model
|
||||||
|
implementation project(':model')
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,6 +4,8 @@ import androidx.room.Database;
|
||||||
import androidx.room.RoomDatabase;
|
import androidx.room.RoomDatabase;
|
||||||
|
|
||||||
// Entities
|
// Entities
|
||||||
|
import one.nem.lacerta.source.database.dao.FolderDao;
|
||||||
|
import one.nem.lacerta.source.database.entity.FolderEntity;
|
||||||
import one.nem.lacerta.source.database.entity.TagEntity;
|
import one.nem.lacerta.source.database.entity.TagEntity;
|
||||||
import one.nem.lacerta.source.database.entity.DocumentEntity;
|
import one.nem.lacerta.source.database.entity.DocumentEntity;
|
||||||
import one.nem.lacerta.source.database.entity.LibraryEntity;
|
import one.nem.lacerta.source.database.entity.LibraryEntity;
|
||||||
|
@ -17,11 +19,12 @@ import one.nem.lacerta.source.database.dao.LibraryDao;
|
||||||
import one.nem.lacerta.source.database.dao.VcsRevDao;
|
import one.nem.lacerta.source.database.dao.VcsRevDao;
|
||||||
import one.nem.lacerta.source.database.dao.VcsLogDao;
|
import one.nem.lacerta.source.database.dao.VcsLogDao;
|
||||||
|
|
||||||
@Database(entities = {TagEntity.class, DocumentEntity.class, LibraryEntity.class, VcsRevEntity.class, VcsLogEntity.class}, version = 3)
|
@Database(entities = {TagEntity.class, DocumentEntity.class, LibraryEntity.class, VcsRevEntity.class, VcsLogEntity.class, FolderEntity.class}, version = 4)
|
||||||
public abstract class LacertaDatabase extends RoomDatabase {
|
public abstract class LacertaDatabase extends RoomDatabase {
|
||||||
public abstract TagDao tagDao();
|
public abstract TagDao tagDao();
|
||||||
public abstract DocumentDao documentDao();
|
public abstract DocumentDao documentDao();
|
||||||
public abstract LibraryDao libraryDao();
|
public abstract LibraryDao libraryDao();
|
||||||
public abstract VcsRevDao vcsRevDao();
|
public abstract VcsRevDao vcsRevDao();
|
||||||
public abstract VcsLogDao vcsLogDao();
|
public abstract VcsLogDao vcsLogDao();
|
||||||
|
public abstract FolderDao folderDao();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,12 @@ public interface DocumentDao {
|
||||||
@Query("SELECT * FROM Document WHERE id IN (:ids)")
|
@Query("SELECT * FROM Document WHERE id IN (:ids)")
|
||||||
List<DocumentEntity> findByIds(List<String> ids);
|
List<DocumentEntity> findByIds(List<String> ids);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM Document WHERE public_path = :publicPath LIMIT :limit")
|
||||||
|
List<DocumentEntity> findByPublicPathWithLimit(String publicPath, int limit);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM Document ORDER BY created_at DESC LIMIT :limit")
|
||||||
|
List<DocumentEntity> getRecentDocument(int limit);
|
||||||
|
|
||||||
// Insert
|
// Insert
|
||||||
@Insert
|
@Insert
|
||||||
void insert(DocumentEntity document);
|
void insert(DocumentEntity document);
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package one.nem.lacerta.source.database.dao;
|
||||||
|
|
||||||
|
import androidx.room.Dao;
|
||||||
|
import androidx.room.Insert;
|
||||||
|
import androidx.room.Query;
|
||||||
|
|
||||||
|
import one.nem.lacerta.source.database.entity.FolderEntity;
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
public interface FolderDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM Folder WHERE id = :id")
|
||||||
|
FolderEntity findById(String id);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM Folder WHERE public_path = :publicPath")
|
||||||
|
FolderEntity findByPublicPath(String publicPath);
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
void insert(FolderEntity folderEntity);
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
void insertAll(FolderEntity... folderEntities);
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package one.nem.lacerta.source.database.entity;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.room.ColumnInfo;
|
||||||
|
import androidx.room.Entity;
|
||||||
|
import androidx.room.PrimaryKey;
|
||||||
|
|
||||||
|
@Entity(tableName = "folder")
|
||||||
|
public class FolderEntity {
|
||||||
|
|
||||||
|
@PrimaryKey
|
||||||
|
@ColumnInfo(name = "id")
|
||||||
|
@NonNull
|
||||||
|
public String id; // フォルダID
|
||||||
|
|
||||||
|
@ColumnInfo(name = "title")
|
||||||
|
public String name; // フォルダ名
|
||||||
|
|
||||||
|
@ColumnInfo(name = "public_path")
|
||||||
|
public String publicPath; // 公開パス
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user