Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ditclear
committed
Apr 14, 2018
1 parent
255e8f4
commit 5f696a7
Showing
13 changed files
with
847 additions
and
403 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
app/schemas/io.ditclear.app.model.local.AppDatabase/1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "31cfd90c8b3f7a928fd65b660fee395a", | ||
"entities": [ | ||
{ | ||
"tableName": "articles", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`articleid` INTEGER NOT NULL, `content` TEXT, `readme` TEXT, `description` TEXT, `click` INTEGER NOT NULL, `channel` INTEGER NOT NULL, `comments` INTEGER NOT NULL, `stow` INTEGER NOT NULL, `upvote` INTEGER NOT NULL, `downvote` INTEGER NOT NULL, `url` TEXT, `pubDate` TEXT, `thumbnail` TEXT, `title` TEXT, PRIMARY KEY(`articleid`))", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "articleid", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "content", | ||
"columnName": "content", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "readme", | ||
"columnName": "readme", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "description", | ||
"columnName": "description", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "click", | ||
"columnName": "click", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "channel", | ||
"columnName": "channel", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "comments", | ||
"columnName": "comments", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "stow", | ||
"columnName": "stow", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "upvote", | ||
"columnName": "upvote", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "downvote", | ||
"columnName": "downvote", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "url", | ||
"columnName": "url", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "pubDate", | ||
"columnName": "pubDate", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "thumbnail", | ||
"columnName": "thumbnail", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "title", | ||
"columnName": "title", | ||
"affinity": "TEXT", | ||
"notNull": false | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"articleid" | ||
], | ||
"autoGenerate": false | ||
}, | ||
"indices": [], | ||
"foreignKeys": [] | ||
} | ||
], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"31cfd90c8b3f7a928fd65b660fee395a\")" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,34 @@ | ||
package io.ditclear.app.model.data | ||
|
||
import android.arch.persistence.room.ColumnInfo | ||
import android.arch.persistence.room.Entity | ||
import android.arch.persistence.room.PrimaryKey | ||
import com.google.gson.annotations.SerializedName | ||
|
||
/** | ||
* 页面描述:Article | ||
* | ||
* Created by ditclear on 2017/11/19. | ||
*/ | ||
data class Article( | ||
var id: Int = 0, | ||
var title: String?, | ||
var readme: String?, | ||
var describe: String?, | ||
var click: Int = 0, | ||
var channel: Int = 0, | ||
var comments: Int = 0, | ||
var stow: Int = 0, | ||
var upvote: Int = 0, | ||
var downvote: Int = 0, | ||
var url: String?, | ||
var pubDate: String?, | ||
var thumbnail: String?) { | ||
|
||
var content: String? = null | ||
@Entity(tableName = "articles") | ||
class Article(var title: String?){ | ||
|
||
@PrimaryKey | ||
@ColumnInfo(name = "articleid") | ||
var id: Int = 0 | ||
var content: String? = null | ||
var readme: String? = null | ||
@SerializedName("describe") | ||
var description: String? = null | ||
var click: Int = 0 | ||
var channel: Int = 0 | ||
var comments: Int = 0 | ||
var stow: Int = 0 | ||
var upvote: Int = 0 | ||
var downvote: Int = 0 | ||
var url: String? = null | ||
var pubDate: String? = null | ||
var thumbnail: String? = null | ||
|
||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/io/ditclear/app/model/local/AppDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.ditclear.app.model.local | ||
|
||
import android.arch.persistence.room.Database | ||
import android.arch.persistence.room.Room | ||
import android.arch.persistence.room.RoomDatabase | ||
import android.content.Context | ||
import io.ditclear.app.model.data.Article | ||
import io.ditclear.app.model.local.dao.PaoDao | ||
|
||
/** | ||
* 页面描述:AppDatabase | ||
* | ||
*/ | ||
@Database(entities = arrayOf(Article::class),version = 1) | ||
abstract class AppDatabase :RoomDatabase(){ | ||
|
||
abstract fun paoDao(): PaoDao | ||
|
||
companion object { | ||
@Volatile private var INSTANCE: AppDatabase? = null | ||
fun getInstance(context: Context): AppDatabase = | ||
INSTANCE ?: synchronized(this) { | ||
INSTANCE ?: buildDatabase(context).also { INSTANCE = it } | ||
} | ||
|
||
private fun buildDatabase(context: Context) = | ||
Room.databaseBuilder(context.applicationContext, | ||
AppDatabase::class.java, "app.db") | ||
.build() | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/io/ditclear/app/model/local/dao/ArticleDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.ditclear.app.model.local.dao | ||
|
||
import android.arch.persistence.room.Dao | ||
import android.arch.persistence.room.Insert | ||
import android.arch.persistence.room.OnConflictStrategy | ||
import android.arch.persistence.room.Query | ||
import io.ditclear.app.model.data.Article | ||
import io.reactivex.Single | ||
|
||
/** | ||
* 页面描述:ArticleDao | ||
* | ||
* Created by ditclear on 2017/10/30. | ||
*/ | ||
@Dao | ||
interface PaoDao{ | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
fun insetAll(articles: List<Article>) | ||
|
||
@Query("SELECT * FROM Articles WHERE articleid= :id") | ||
fun getArticleById(id:Int):Single<Article> | ||
|
||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
fun insertArticle(article :Article) | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/io/ditclear/app/model/repository/PaoRepo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.ditclear.app.model.repository | ||
|
||
import io.ditclear.app.model.local.dao.PaoDao | ||
import io.ditclear.app.model.remote.PaoService | ||
|
||
/** | ||
* 页面描述:PaoRepo | ||
* | ||
* Created by ditclear on 2018/4/14. | ||
*/ | ||
class PaoRepo constructor(private val remote:PaoService,private val local :PaoDao){ | ||
|
||
fun getArticleDetail(id:Int)= local.getArticleById(id) | ||
.onErrorResumeNext { | ||
remote.getArticleDetail(id) | ||
.doOnSuccess { local.insertArticle(it) } | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.