-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增 1.新增文章列表缓存 2.新增最新文章详细缓存 3.新增目录列表数据缓存
- Loading branch information
Showing
5 changed files
with
211 additions
and
176 deletions.
There are no files selected for viewing
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
73 changes: 73 additions & 0 deletions
73
app/src/main/java/com/zhongzilu/bit100/application/helper/CacheHelper.java
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,73 @@ | ||
package com.zhongzilu.bit100.application.helper; | ||
|
||
import android.content.Context; | ||
import com.zhongzilu.bit100.application.App; | ||
|
||
/** | ||
* JSON数据缓存帮助类 | ||
* Created by zhongzilu on 2016-11-02. | ||
*/ | ||
public class CacheHelper { | ||
|
||
private static final String CACHE_FILE = "POSTS_CACHE", | ||
ITEM_POSTS_ALL = "posts_all", | ||
ITEM_POSTS_RECENT = "posts_recent", | ||
ITEM_ALL_CATEGORIES = "all_categories"; | ||
|
||
public static void savePostsAll(final String json){ | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
App.getAppContext() | ||
.getSharedPreferences(CACHE_FILE, Context.MODE_PRIVATE) | ||
.edit() | ||
.putString(ITEM_POSTS_ALL, json) | ||
.apply(); | ||
} | ||
}).start(); | ||
} | ||
|
||
public static String getPostsAll(){ | ||
return App.getAppContext() | ||
.getSharedPreferences(CACHE_FILE, Context.MODE_PRIVATE) | ||
.getString(ITEM_POSTS_ALL, null); | ||
} | ||
|
||
public static void saveRecentPosts(final String json){ | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
App.getAppContext() | ||
.getSharedPreferences(CACHE_FILE, Context.MODE_PRIVATE) | ||
.edit() | ||
.putString(ITEM_POSTS_RECENT, json) | ||
.apply(); | ||
} | ||
}).start(); | ||
} | ||
|
||
public static String getRecentPosts(){ | ||
return App.getAppContext() | ||
.getSharedPreferences(CACHE_FILE, Context.MODE_PRIVATE) | ||
.getString(ITEM_POSTS_RECENT, null); | ||
} | ||
|
||
public static void saveAllCategories(final String json){ | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
App.getAppContext() | ||
.getSharedPreferences(CACHE_FILE, Context.MODE_PRIVATE) | ||
.edit() | ||
.putString(ITEM_ALL_CATEGORIES, json) | ||
.apply(); | ||
} | ||
}).start(); | ||
} | ||
|
||
public static String getAllCategories(){ | ||
return App.getAppContext() | ||
.getSharedPreferences(CACHE_FILE, Context.MODE_PRIVATE) | ||
.getString(ITEM_ALL_CATEGORIES, null); | ||
} | ||
} |
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
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
Oops, something went wrong.