Android: tags caching

This commit is contained in:
jendib 2014-11-28 01:40:54 +01:00
parent 2837b21a86
commit 3330acfc75
5 changed files with 12 additions and 2 deletions

View File

@ -105,7 +105,6 @@
<orderEntry type="library" exported="" name="support-v4-21.0.2" level="project" />
<orderEntry type="library" exported="" name="eventbus-2.4.0" level="project" />
<orderEntry type="library" exported="" name="android-query.0.26.8" level="project" />
<orderEntry type="library" exported="" name="tokenautocomplete-1.2.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.2" level="project" />
<orderEntry type="library" exported="" name="android-async-http-1.4.6" level="project" />
</component>

View File

@ -20,6 +20,7 @@ public class MainApplication extends Application {
JSONObject json = PreferenceUtil.getCachedJson(getApplicationContext(), PreferenceUtil.PREF_CACHED_USER_INFO_JSON);
ApplicationContext.getInstance().setUserInfo(getApplicationContext(), json);
// TODO Tags caching
// TODO Fullscreen preview
// TODO Caching preferences
// TODO Edit sharing

View File

@ -25,6 +25,7 @@ import com.sismics.docs.listener.JsonHttpResponseHandler;
import com.sismics.docs.model.application.ApplicationContext;
import com.sismics.docs.provider.RecentSuggestionsProvider;
import com.sismics.docs.resource.TagResource;
import com.sismics.docs.util.PreferenceUtil;
import org.apache.http.Header;
import org.json.JSONObject;
@ -81,9 +82,14 @@ public class MainActivity extends ActionBarActivity {
final View tagProgressView = findViewById(R.id.tagProgressView);
final TextView tagEmptyView = (TextView) findViewById(R.id.tagEmptyView);
tagListView.setEmptyView(tagProgressView);
JSONObject cacheTags = PreferenceUtil.getCachedJson(this, PreferenceUtil.PREF_CACHED_TAGS_JSON);
if (cacheTags != null) {
tagListView.setAdapter(new TagListAdapter(cacheTags.optJSONArray("stats")));
}
TagResource.stats(this, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
PreferenceUtil.setCachedJson(MainActivity.this, PreferenceUtil.PREF_CACHED_TAGS_JSON, response);
tagListView.setAdapter(new TagListAdapter(response.optJSONArray("stats")));
tagProgressView.setVisibility(View.GONE);
tagListView.setEmptyView(tagEmptyView);

View File

@ -20,6 +20,7 @@ import java.util.List;
public class PreferenceUtil {
public static final String PREF_CACHED_USER_INFO_JSON = "pref_cachedUserInfoJson";
public static final String PREF_CACHED_TAGS_JSON = "pref_cachedTagsJson";
public static final String PREF_SERVER_URL = "pref_ServerUrl";
/**
@ -108,7 +109,10 @@ public class PreferenceUtil {
public static void resetUserCache(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
Editor editor = sharedPreferences.edit();
editor.putString(PREF_CACHED_USER_INFO_JSON, null).apply();
editor
.putString(PREF_CACHED_USER_INFO_JSON, null)
.putString(PREF_CACHED_TAGS_JSON, null)
.apply();
}
/**