mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-23 00:13:16 +00:00
パッケージ構成変更
This commit is contained in:
parent
d222d77a91
commit
cbe5d1069a
|
@ -1,15 +0,0 @@
|
|||
package one.nem.lacerta.source.db;
|
||||
|
||||
import androidx.room.Database;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
import one.nem.lacerta.source.db.dao.DocumentsDao;
|
||||
import one.nem.lacerta.source.db.dao.RepositoriesDao;
|
||||
import one.nem.lacerta.source.db.entity.Documents;
|
||||
import one.nem.lacerta.source.db.entity.Repositories;
|
||||
|
||||
@Database(entities = {Documents.class, Repositories.class}, version = 1)
|
||||
public abstract class LacertaDatabase extends RoomDatabase {
|
||||
public abstract DocumentsDao documentsDao();
|
||||
public abstract RepositoriesDao repositoriesDao();
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package one.nem.lacerta.source.db;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext;
|
||||
|
||||
public class RoomUtils {
|
||||
// Internal Utils
|
||||
|
||||
|
||||
|
||||
@Inject // TODO-rca: 実装を切り離す?
|
||||
RoomUtils(@ApplicationContext Context context) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package one.nem.lacerta.source.db;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.hilt.InstallIn;
|
||||
import dagger.hilt.components.SingletonComponent;
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent.class)
|
||||
abstract public class RoomUtilsModule {
|
||||
|
||||
@Binds
|
||||
public abstract RoomUtils bindRoomUtils(Context context);
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package one.nem.lacerta.source.db.dao;
|
||||
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import one.nem.lacerta.source.db.entity.Documents;
|
||||
|
||||
@Dao
|
||||
public interface DocumentsDao {
|
||||
|
||||
@Query("SELECT * FROM documents")
|
||||
List<Documents> getAll();
|
||||
|
||||
@Query("SELECT * FROM documents WHERE id IN (:ids)")
|
||||
List<Documents> loadAllByIds(int[] ids);
|
||||
|
||||
@Query("SELECT * FROM documents WHERE title LIKE :title LIMIT 1")
|
||||
Documents findByTitle(String title);
|
||||
|
||||
@Query("SELECT * FROM documents WHERE id LIKE :id LIMIT 1")
|
||||
Documents findById(String id);
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package one.nem.lacerta.source.db.dao;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import one.nem.lacerta.source.db.entity.Repositories;
|
||||
|
||||
@Dao
|
||||
public interface RepositoriesDao {
|
||||
|
||||
@Query("SELECT * FROM repositories")
|
||||
List<Repositories> getAll();
|
||||
|
||||
@Query("SELECT * FROM repositories WHERE id IN (:ids)")
|
||||
List<Repositories> loadAllByIds(int[] ids);
|
||||
|
||||
@Query("SELECT * FROM repositories WHERE relative_path LIKE :relativePath LIMIT 1")
|
||||
Repositories findByRelativePath(String relativePath);
|
||||
|
||||
@Query("SELECT * FROM repositories WHERE id LIKE :id LIMIT 1")
|
||||
Repositories findById(String id);
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package one.nem.lacerta.source.db.entity;
|
||||
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import one.nem.lacerta.data.model.documents.enums.DocumentType;
|
||||
|
||||
@Entity
|
||||
public class Documents {
|
||||
@PrimaryKey
|
||||
private String id;
|
||||
|
||||
@ColumnInfo(name = "title")
|
||||
private String title; // Titleに変更する?
|
||||
|
||||
@ColumnInfo(name = "type")
|
||||
private DocumentType type; // DocumentTypeに変更する?
|
||||
|
||||
@ColumnInfo(name = "created")
|
||||
private Date created;
|
||||
|
||||
@ColumnInfo(name = "updated")
|
||||
private Date updated;
|
||||
|
||||
@ColumnInfo(name = "tags")
|
||||
private String[] tags;
|
||||
|
||||
@ColumnInfo(name = "categories")
|
||||
private String[] categories;
|
||||
|
||||
// WIP
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package one.nem.lacerta.source.db.entity;
|
||||
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
@Entity
|
||||
public class Repositories {
|
||||
|
||||
@PrimaryKey
|
||||
private String id;
|
||||
|
||||
@ColumnInfo(name = "relative_path")
|
||||
private String relativePath;
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package one.nem.lacerta.source.jgit;
|
||||
|
||||
import org.eclipse.jgit.internal.storage.file.FileRepository;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import one.nem.lacerta.utils.repository.FileUtils;
|
||||
|
||||
public class RepoUtils {
|
||||
// Internal Utils
|
||||
|
||||
@Inject // TODO-rca: 実装を切り離す?
|
||||
RepoUtils() {
|
||||
}
|
||||
|
||||
@Inject
|
||||
FileUtils fileUtils;
|
||||
|
||||
|
||||
public Repository createRepo(String id) {
|
||||
Path rootPath = fileUtils.getExternalFilesDirPath();
|
||||
|
||||
try {
|
||||
Repository repo = new FileRepositoryBuilder().setGitDir(rootPath.resolve(id).resolve(".git").toFile()).build();
|
||||
repo.create();
|
||||
return repo;
|
||||
} catch (Exception e) {
|
||||
// TODO-rca: handle exception
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Repository getRepo(String id) {
|
||||
Path rootPath = fileUtils.getExternalFilesDirPath();
|
||||
try {
|
||||
Repository repo = new FileRepositoryBuilder().setGitDir(rootPath.resolve(id).resolve(".git").toFile()).build();
|
||||
return repo;
|
||||
} catch (Exception e) {
|
||||
// TODO-rca: handle exception
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public String getRepoName(Repository repo) {
|
||||
return repo.getDirectory().getParentFile().getName();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -15,6 +15,8 @@ import one.nem.lacerta.data.repository.SharedPref;
|
|||
|
||||
import one.nem.lacerta.data.model.shared_pref.enums.SharedPrefType;
|
||||
|
||||
import one.nem.lacerta.source.db.LacertaDatabase;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
|
@ -28,6 +30,9 @@ public class DebugPlayGroundFragment extends Fragment {
|
|||
@Inject // DI
|
||||
SharedPref sharedPref;
|
||||
|
||||
@Inject
|
||||
LacertaDatabase lacertaDatabase; // TODO-rca: Repositoryを噛ませる
|
||||
|
||||
public DebugPlayGroundFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
@ -60,6 +65,6 @@ public class DebugPlayGroundFragment extends Fragment {
|
|||
// (viewは引数として受け取ってるviewなので、別メソッドに切り出したりするなら渡してあげる)
|
||||
|
||||
// ShardPrefの要素数をトーストする例
|
||||
Toast.makeText(getContext(), "SharedPrefの要素数: " + sharedPref.getSharedPreferencesByTag(SharedPrefType.COMMON).getAll().size(), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getContext(), "DBの要素数" + lacertaDatabase.repositoriesDao(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
|
@ -11,4 +11,38 @@
|
|||
android:layout_height="match_parent"
|
||||
android:text="@string/hello_blank_fragment" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
</ScrollView>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
</ScrollView>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
</ScrollView>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</FrameLayout>
|
|
@ -1,30 +0,0 @@
|
|||
package one.nem.lacerta.utils.impl;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext;
|
||||
|
||||
import one.nem.lacerta.utils.repository.FileUtils;
|
||||
|
||||
public class FileUtilsImpl implements FileUtils {
|
||||
|
||||
private final Context applicationContext;
|
||||
|
||||
@Inject
|
||||
public FileUtilsImpl(@ApplicationContext Context applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public Path getExternalFilesDirPath(String type) {
|
||||
return Objects.requireNonNull(applicationContext.getExternalFilesDir(type)).toPath();
|
||||
}
|
||||
|
||||
public Path getExternalFilesDirPath() {
|
||||
return Objects.requireNonNull(applicationContext.getExternalFilesDir(null)).toPath();
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package one.nem.lacerta.utils.module;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.hilt.InstallIn;
|
||||
import dagger.hilt.components.SingletonComponent;
|
||||
import one.nem.lacerta.utils.repository.FileUtils;
|
||||
import one.nem.lacerta.utils.impl.FileUtilsImpl;
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent.class)
|
||||
abstract public class FileUtilsModule {
|
||||
|
||||
@Binds
|
||||
public abstract FileUtils bindFileUtils(FileUtilsImpl fileUtilsImpl);
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package one.nem.lacerta.utils.repository;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface FileUtils {
|
||||
|
||||
Path getExternalFilesDirPath(String type);
|
||||
|
||||
Path getExternalFilesDirPath();
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user