Skip to content

Commit 5f696a7

Browse files
author
ditclear
committed
update part 3
1 parent 255e8f4 commit 5f696a7

13 files changed

Lines changed: 847 additions & 403 deletions

File tree

.idea/misc.xml

Lines changed: 1 addition & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 148 additions & 347 deletions
Large diffs are not rendered by default.

app/build.gradle

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ apply plugin: 'kotlin-kapt'
44

55
android {
66
compileSdkVersion 26
7-
buildToolsVersion "26.0.1"
7+
buildToolsVersion "26.0.2"
88
defaultConfig {
99
applicationId "io.ditclear.app"
1010
minSdkVersion 14
1111
targetSdkVersion 26
1212
versionCode 1
1313
versionName "1.0"
1414
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
// used by Room, to test migrations
16+
javaCompileOptions {
17+
annotationProcessorOptions {
18+
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
19+
}
20+
}
1521
}
1622
buildTypes {
1723
release {
@@ -22,34 +28,45 @@ android {
2228
dataBinding{
2329
enabled = true
2430
}
31+
32+
// used by Room, to test migrations
33+
sourceSets {
34+
androidTest.assets.srcDirs +=
35+
files("$projectDir/schemas".toString())
36+
}
2537
}
2638
kapt {
2739
generateStubs = true
2840
}
2941
dependencies {
30-
compile fileTree(dir: 'libs', include: ['*.jar'])
31-
compile 'com.android.support:appcompat-v7:26.1.0'
32-
compile 'com.android.support:design:26.1.0'
33-
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
42+
implementation fileTree(dir: 'libs', include: ['*.jar'])
43+
implementation 'com.android.support:appcompat-v7:26.1.0'
44+
implementation 'com.android.support:design:26.1.0'
45+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
3446
//data binding
35-
kapt "com.android.databinding:compiler:2.3.3"
47+
kapt "com.android.databinding:compiler:3.1.0"
3648
//rx android
37-
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
38-
compile 'io.reactivex.rxjava2:rxjava:2.1.3'
39-
compile 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.0'
49+
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
50+
implementation 'io.reactivex.rxjava2:rxjava:2.1.8'
51+
implementation 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.1'
4052
//retrofit
41-
compile 'com.squareup.retrofit2:retrofit:2.3.0'
42-
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
43-
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
44-
compile 'com.google.code.gson:gson:2.8.0'
53+
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
54+
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
55+
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
56+
implementation 'com.google.code.gson:gson:2.8.1'
57+
implementation 'com.facebook.stetho:stetho:1.5.0'
4558

59+
//room (local)
60+
implementation 'android.arch.persistence.room:runtime:1.0.0'
61+
implementation 'android.arch.persistence.room:rxjava2:1.0.0'
62+
kapt 'android.arch.persistence.room:compiler:1.0.0'
4663

4764
//不重要
48-
compile 'us.feras.mdv:markdownview:1.1.0'
49-
compile 'org.jsoup:jsoup:1.10.3'//处理html中的image
65+
implementation 'us.feras.mdv:markdownview:1.1.0'
66+
implementation 'org.jsoup:jsoup:1.10.3'//处理html中的image
5067

51-
testCompile 'junit:junit:4.12'
52-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
68+
testImplementation 'junit:junit:4.12'
69+
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
5370
exclude group: 'com.android.support', module: 'support-annotations'
5471
})
5572
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"formatVersion": 1,
3+
"database": {
4+
"version": 1,
5+
"identityHash": "31cfd90c8b3f7a928fd65b660fee395a",
6+
"entities": [
7+
{
8+
"tableName": "articles",
9+
"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`))",
10+
"fields": [
11+
{
12+
"fieldPath": "id",
13+
"columnName": "articleid",
14+
"affinity": "INTEGER",
15+
"notNull": true
16+
},
17+
{
18+
"fieldPath": "content",
19+
"columnName": "content",
20+
"affinity": "TEXT",
21+
"notNull": false
22+
},
23+
{
24+
"fieldPath": "readme",
25+
"columnName": "readme",
26+
"affinity": "TEXT",
27+
"notNull": false
28+
},
29+
{
30+
"fieldPath": "description",
31+
"columnName": "description",
32+
"affinity": "TEXT",
33+
"notNull": false
34+
},
35+
{
36+
"fieldPath": "click",
37+
"columnName": "click",
38+
"affinity": "INTEGER",
39+
"notNull": true
40+
},
41+
{
42+
"fieldPath": "channel",
43+
"columnName": "channel",
44+
"affinity": "INTEGER",
45+
"notNull": true
46+
},
47+
{
48+
"fieldPath": "comments",
49+
"columnName": "comments",
50+
"affinity": "INTEGER",
51+
"notNull": true
52+
},
53+
{
54+
"fieldPath": "stow",
55+
"columnName": "stow",
56+
"affinity": "INTEGER",
57+
"notNull": true
58+
},
59+
{
60+
"fieldPath": "upvote",
61+
"columnName": "upvote",
62+
"affinity": "INTEGER",
63+
"notNull": true
64+
},
65+
{
66+
"fieldPath": "downvote",
67+
"columnName": "downvote",
68+
"affinity": "INTEGER",
69+
"notNull": true
70+
},
71+
{
72+
"fieldPath": "url",
73+
"columnName": "url",
74+
"affinity": "TEXT",
75+
"notNull": false
76+
},
77+
{
78+
"fieldPath": "pubDate",
79+
"columnName": "pubDate",
80+
"affinity": "TEXT",
81+
"notNull": false
82+
},
83+
{
84+
"fieldPath": "thumbnail",
85+
"columnName": "thumbnail",
86+
"affinity": "TEXT",
87+
"notNull": false
88+
},
89+
{
90+
"fieldPath": "title",
91+
"columnName": "title",
92+
"affinity": "TEXT",
93+
"notNull": false
94+
}
95+
],
96+
"primaryKey": {
97+
"columnNames": [
98+
"articleid"
99+
],
100+
"autoGenerate": false
101+
},
102+
"indices": [],
103+
"foreignKeys": []
104+
}
105+
],
106+
"setupQueries": [
107+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
108+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"31cfd90c8b3f7a928fd65b660fee395a\")"
109+
]
110+
}
111+
}
Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
package io.ditclear.app.model.data
22

3+
import android.arch.persistence.room.ColumnInfo
4+
import android.arch.persistence.room.Entity
5+
import android.arch.persistence.room.PrimaryKey
6+
import com.google.gson.annotations.SerializedName
7+
38
/**
49
* 页面描述:Article
510
*
611
* Created by ditclear on 2017/11/19.
712
*/
8-
data class Article(
9-
var id: Int = 0,
10-
var title: String?,
11-
var readme: String?,
12-
var describe: String?,
13-
var click: Int = 0,
14-
var channel: Int = 0,
15-
var comments: Int = 0,
16-
var stow: Int = 0,
17-
var upvote: Int = 0,
18-
var downvote: Int = 0,
19-
var url: String?,
20-
var pubDate: String?,
21-
var thumbnail: String?) {
2213

23-
var content: String? = null
14+
@Entity(tableName = "articles")
15+
class Article(var title: String?){
2416

17+
@PrimaryKey
18+
@ColumnInfo(name = "articleid")
19+
var id: Int = 0
20+
var content: String? = null
21+
var readme: String? = null
22+
@SerializedName("describe")
23+
var description: String? = null
24+
var click: Int = 0
25+
var channel: Int = 0
26+
var comments: Int = 0
27+
var stow: Int = 0
28+
var upvote: Int = 0
29+
var downvote: Int = 0
30+
var url: String? = null
31+
var pubDate: String? = null
32+
var thumbnail: String? = null
2533

26-
}
34+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.ditclear.app.model.local
2+
3+
import android.arch.persistence.room.Database
4+
import android.arch.persistence.room.Room
5+
import android.arch.persistence.room.RoomDatabase
6+
import android.content.Context
7+
import io.ditclear.app.model.data.Article
8+
import io.ditclear.app.model.local.dao.PaoDao
9+
10+
/**
11+
* 页面描述:AppDatabase
12+
*
13+
*/
14+
@Database(entities = arrayOf(Article::class),version = 1)
15+
abstract class AppDatabase :RoomDatabase(){
16+
17+
abstract fun paoDao(): PaoDao
18+
19+
companion object {
20+
@Volatile private var INSTANCE: AppDatabase? = null
21+
fun getInstance(context: Context): AppDatabase =
22+
INSTANCE ?: synchronized(this) {
23+
INSTANCE ?: buildDatabase(context).also { INSTANCE = it }
24+
}
25+
26+
private fun buildDatabase(context: Context) =
27+
Room.databaseBuilder(context.applicationContext,
28+
AppDatabase::class.java, "app.db")
29+
.build()
30+
}
31+
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.ditclear.app.model.local.dao
2+
3+
import android.arch.persistence.room.Dao
4+
import android.arch.persistence.room.Insert
5+
import android.arch.persistence.room.OnConflictStrategy
6+
import android.arch.persistence.room.Query
7+
import io.ditclear.app.model.data.Article
8+
import io.reactivex.Single
9+
10+
/**
11+
* 页面描述:ArticleDao
12+
*
13+
* Created by ditclear on 2017/10/30.
14+
*/
15+
@Dao
16+
interface PaoDao{
17+
18+
@Insert(onConflict = OnConflictStrategy.REPLACE)
19+
fun insetAll(articles: List<Article>)
20+
21+
@Query("SELECT * FROM Articles WHERE articleid= :id")
22+
fun getArticleById(id:Int):Single<Article>
23+
24+
25+
@Insert(onConflict = OnConflictStrategy.REPLACE)
26+
fun insertArticle(article :Article)
27+
28+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.ditclear.app.model.repository
2+
3+
import io.ditclear.app.model.local.dao.PaoDao
4+
import io.ditclear.app.model.remote.PaoService
5+
6+
/**
7+
* 页面描述:PaoRepo
8+
*
9+
* Created by ditclear on 2018/4/14.
10+
*/
11+
class PaoRepo constructor(private val remote:PaoService,private val local :PaoDao){
12+
13+
fun getArticleDetail(id:Int)= local.getArticleById(id)
14+
.onErrorResumeNext {
15+
remote.getArticleDetail(id)
16+
.doOnSuccess { local.insertArticle(it) }
17+
}
18+
19+
20+
}

0 commit comments

Comments
 (0)