apiloader: cache results unless forced not to

This commit is contained in:
Andrew Dolgov 2017-05-31 16:24:33 +03:00
parent 4d54d69378
commit 6bec08951e
2 changed files with 20 additions and 3 deletions

View File

@ -42,6 +42,7 @@ public class ApiLoader extends AsyncTaskLoader<JsonElement> {
protected String m_lastErrorMessage;
protected ApiError m_lastError;
protected HashMap<String,String> m_params;
protected JsonElement m_data;
public ApiLoader(Context context, HashMap<String,String> params) {
super(context);
@ -57,6 +58,22 @@ public class ApiLoader extends AsyncTaskLoader<JsonElement> {
}
@Override
protected void onStartLoading() {
if (m_data != null) {
deliverResult(m_data);
} else {
forceLoad();
}
}
@Override
public void deliverResult(JsonElement data) {
m_data = data;
super.deliverResult(data);
}
public int getErrorMessage() {
switch (m_lastError) {
case NO_ERROR:

View File

@ -327,7 +327,7 @@ public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnIt
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (savedInstanceState != null) {
m_selectedCat = savedInstanceState.getParcelable("selectedCat");
m_cats = savedInstanceState.getParcelable("cats");
//m_cats = savedInstanceState.getParcelable("cats");
}
View view = inflater.inflate(R.layout.fragment_cats, container, false);
@ -376,7 +376,7 @@ public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnIt
public void onResume() {
super.onResume();
getLoaderManager().initLoader(0, null, this).forceLoad();
getLoaderManager().initLoader(0, null, this);
m_activity.invalidateOptionsMenu();
}
@ -387,7 +387,7 @@ public class FeedCategoriesFragment extends BaseFeedlistFragment implements OnIt
out.setClassLoader(getClass().getClassLoader());
out.putParcelable("selectedCat", m_selectedCat);
out.putParcelable("cats", m_cats);
//out.putParcelable("cats", m_cats);
}
public void refresh(boolean background) {