Bläddra i källkod

1,增加UI界面数据处理操作

YIN-PC\yin 7 år sedan
förälder
incheckning
d46d8d444e

+ 18 - 3
app/src/main/java/top/yinxueqin/readbook/AppExecutors.java

@@ -18,21 +18,32 @@ public class AppExecutors {
 
     private final Executor mDbIO;
 
+    private final Executor mDbQueryIO;
+
     private final Executor mDiskIO;
 
     private final Executor mNetworkIO;
 
     private final Executor mMainThread;
 
-    private AppExecutors(Executor dbIO, Executor diskIO, Executor networkIO, Executor mainThread) {
+    private static class AppExecutorsHolder {
+        private static final AppExecutors INSTANCE = new AppExecutors();
+    }
+
+    public static final AppExecutors getInstance() {
+        return AppExecutors.AppExecutorsHolder.INSTANCE;
+    }
+
+    private AppExecutors(Executor dbIO, Executor dbQueryIO, Executor diskIO, Executor networkIO, Executor mainThread) {
         this.mDbIO = dbIO;
+        this.mDbQueryIO = dbQueryIO;
         this.mDiskIO = diskIO;
         this.mNetworkIO = networkIO;
         this.mMainThread = mainThread;
     }
 
-    public AppExecutors() {
-        this(Executors.newSingleThreadExecutor(), Executors.newSingleThreadExecutor(), Executors.newFixedThreadPool(3),
+    private AppExecutors() {
+        this(Executors.newSingleThreadExecutor(), Executors.newFixedThreadPool(3), Executors.newSingleThreadExecutor(), Executors.newFixedThreadPool(3),
                 new MainThreadExecutor());
     }
 
@@ -40,6 +51,10 @@ public class AppExecutors {
         return mDbIO;
     }
 
+    public Executor dbQueryIO() {
+        return mDbQueryIO;
+    }
+
     public Executor diskIO() {
         return mDiskIO;
     }

+ 5 - 1
app/src/main/java/top/yinxueqin/readbook/BasicApp.java

@@ -20,7 +20,7 @@ public class BasicApp extends Application {
     public void onCreate() {
         super.onCreate();
 
-        mAppExecutors = new AppExecutors();
+        mAppExecutors = AppExecutors.getInstance();
     }
 
     public DBDatabase getDBDatabase() {
@@ -34,4 +34,8 @@ public class BasicApp extends Application {
     public DataRepository getRepository() {
         return DataRepository.getInstance(getDBDatabase(), getDSDiskStorage());
     }
+
+    public AppExecutors getmAppExecutors() {
+        return mAppExecutors;
+    }
 }

+ 4 - 0
app/src/main/java/top/yinxueqin/readbook/DataRepository.java

@@ -124,6 +124,10 @@ public class DataRepository {
         return mDBDatabase.dbChapterInfoDao().loadChapterInfos(bookId);
     }
 
+    public LiveData<String> getBookChapterContent(int chapterId) {
+        return mDBDatabase.dbChapterInfoDao().loadChapterContent(chapterId);
+    }
+
     public void insertChapterInfo(final DBChapterInfoEntity chapterInfo) {
         mDBDatabase.dbChapterInfoDao().insertChapterInfo(chapterInfo);
     }

+ 4 - 1
app/src/main/java/top/yinxueqin/readbook/data/local/db/dao/DBChapterInfoDao.java

@@ -22,9 +22,12 @@ import top.yinxueqin.readbook.data.local.db.entity.DBChapterInfoEntity;
 @Dao
 public interface DBChapterInfoDao {
 
-    @Query("SELECT * FROM ChapterInfo where bookInfoId = :bookId")
+    @Query("SELECT chapterId, chapterName, chapterLink, chapterCache  FROM ChapterInfo where bookInfoId = :bookId")
     LiveData<List<DBChapterInfoEntity>> loadChapterInfos(int bookId);
 
+    @Query("SELECT chapterContent FROM ChapterInfo where chapterId = :chapterId")
+    LiveData<String> loadChapterContent(int chapterId);
+
     @Insert(onConflict = OnConflictStrategy.REPLACE)
     void insertChapterInfo(DBChapterInfoEntity chapterInfo);
 

+ 1 - 1
app/src/main/java/top/yinxueqin/readbook/data/local/db/entity/DBBookInfoEntity.java

@@ -32,7 +32,7 @@ public class DBBookInfoEntity implements DBBookInfo {
     private String bookImage;
     //最新更新时间
     private String bookUpdateNewestChapterTime;
-    //最后阅读章节
+    //最后阅读章节名称
     private String bookReadChapter;
     //阅读章节目录位置
     private int bookCatalogPosition;

+ 17 - 0
app/src/main/java/top/yinxueqin/readbook/viewmodel/BookListViewModel.java

@@ -0,0 +1,17 @@
+package top.yinxueqin.readbook.viewmodel;
+
+import android.app.Application;
+import android.arch.lifecycle.AndroidViewModel;
+import android.support.annotation.NonNull;
+
+/**
+ * Author: yin
+ * Time: 2018/5/2.
+ * Email: yinxueqin@rd.hgits.cn
+ * Effect: TODO
+ */
+public class BookListViewModel extends AndroidViewModel {
+    public BookListViewModel(@NonNull Application application) {
+        super(application);
+    }
+}

+ 18 - 0
app/src/main/java/top/yinxueqin/readbook/viewmodel/ReadViewModel.java

@@ -0,0 +1,18 @@
+package top.yinxueqin.readbook.viewmodel;
+
+import android.app.Application;
+import android.arch.lifecycle.AndroidViewModel;
+import android.support.annotation.NonNull;
+
+/**
+ * Author: yin
+ * Time: 2018/5/2.
+ * Email: yinxueqin@rd.hgits.cn
+ * Effect: TODO
+ */
+public class ReadViewModel extends AndroidViewModel {
+
+    public ReadViewModel(@NonNull Application application) {
+        super(application);
+    }
+}

+ 1 - 1
build.gradle

@@ -7,7 +7,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.1.1'
+        classpath 'com.android.tools.build:gradle:3.1.2'
         
 
         // NOTE: Do not place your application dependencies here; they belong