Skip to content

Commit af866b7

Browse files
committed
CodeGood: 修复一些缓存问题
1 parent 5482134 commit af866b7

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

app/src/main/kotlin/com/rayfantasy/icode/ui/activity/BlocksActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class BlocksActivity : ActivityBindingStatus() {
3333
itemAnimator = RefactoredDefaultItemAnimator()
3434
}
3535

36+
codeGood.loadContentFromCache()
3637
codeGood.content?.let { recyclerView.adapter = BlockAdapter(this, codeGood, PostUtil.gson.fromJson(codeGood.content)) }
3738

3839
PostUtil.loadCodeContent(codeGood.id!!,

app/src/main/kotlin/com/rayfantasy/icode/ui/fragment/MainFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class MainFragment : FragmentBase() {
103103
//本地缓存
104104
fun cacheData(data: List<CodeGood>) {
105105
data.forEach {
106+
it.loadContentFromCache()
106107
it.save()
107108
}
108109
}

postutil/src/main/kotlin/com/rayfantasy/icode/postutil/bean/CodeGood.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
package com.rayfantasy.icode.postutil.bean;
1818

1919
import android.support.annotation.NonNull;
20-
2120
import com.google.gson.annotations.Expose;
2221
import com.google.gson.annotations.SerializedName;
2322
import com.raizlabs.android.dbflow.annotation.Column;
2423
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
2524
import com.raizlabs.android.dbflow.annotation.Table;
25+
import com.raizlabs.android.dbflow.sql.language.Select;
2626
import com.raizlabs.android.dbflow.structure.BaseModel;
2727
import com.rayfantasy.icode.postutil.database.PostUtilDatabase;
2828

@@ -84,6 +84,17 @@ public boolean equals(Object o) {
8484
return codeGood.id.equals(id) && codeGood.updateAt.equals(updateAt);
8585
}
8686

87+
public void loadContentFromCache() {
88+
if (content == null) {
89+
CodeGood codeGood = new Select(CodeGood_Table.content)
90+
.from(CodeGood.class)
91+
.where(CodeGood_Table.id.is(id))
92+
.querySingle();
93+
if (codeGood != null)
94+
content = codeGood.content;
95+
}
96+
}
97+
8798
public CodeGood() {
8899
}
89100

0 commit comments

Comments
 (0)