Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/data/FavoritesLiveData.java
Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | private void loadData() { | ||||
loadData(false); | loadData(false); | ||||
} | } | ||||
private static Uri.Builder getStopsBuilder(){ | private static Uri.Builder getStopsBuilder(){ | ||||
return AppDataProvider.getUriBuilderToComplete().appendPath("stop"); | return AppDataProvider.getUriBuilderToComplete().appendPath("stop"); | ||||
} | } | ||||
private void loadData(boolean forceQuery) { | private void loadData(boolean forceQuery) { | ||||
Log.d(TAG, "loadData()"); | Log.d(TAG, "loadData() force: "+forceQuery); | ||||
if (!forceQuery){ | if (!forceQuery){ | ||||
if (getValue()!= null){ | if (getValue()!= null){ | ||||
//Data already loaded | //Data already loaded | ||||
Log.d(TAG, "Data already loaded"); | |||||
return; | return; | ||||
} | } | ||||
} | } | ||||
if (isQueryRunning){ | if (isQueryRunning){ | ||||
//we are waiting for data, we will get an update soon | //we are waiting for data, we will get an update soon | ||||
Log.d(TAG, "Query is running, abort"); | |||||
return; | return; | ||||
} | } | ||||
isQueryRunning = true; | isQueryRunning = true; | ||||
queryHandler.startQuery(FAV_TOKEN,null, FAVORITES_URI, UserDB.getFavoritesColumnNamesAsArray, null, null, null); | queryHandler.startQuery(FAV_TOKEN,null, FAVORITES_URI, UserDB.getFavoritesColumnNamesAsArray, null, null, null); | ||||
} | } | ||||
@Override | @Override | ||||
protected void onActive() { | protected void onActive() { | ||||
//Log.d(TAG, "onActive()"); | //Log.d(TAG, "onActive()"); | ||||
loadData(); | loadData(true); | ||||
} | } | ||||
/** | /** | ||||
* Clear the data for the cursor | * Clear the data for the cursor | ||||
*/ | */ | ||||
public void onClear(){ | public void onClear(){ | ||||
ContentResolver resolver = mContext.getContentResolver(); | ContentResolver resolver = mContext.getContentResolver(); | ||||
Show All 24 Lines | public void onQueryComplete(int token, Object cookie, Cursor cursor) { | ||||
stopsFromFavorites = UserDB.getFavoritesFromCursor(cursor, UserDB.getFavoritesColumnNamesAsArray); | stopsFromFavorites = UserDB.getFavoritesFromCursor(cursor, UserDB.getFavoritesColumnNamesAsArray); | ||||
cursor.close(); | cursor.close(); | ||||
//reset counters | //reset counters | ||||
stopNeededCount = stopsFromFavorites.size(); | stopNeededCount = stopsFromFavorites.size(); | ||||
stopsDone = new ArrayList<>(); | stopsDone = new ArrayList<>(); | ||||
if(stopsFromFavorites.size() == 0){ | if(stopsFromFavorites.size() == 0){ | ||||
//we don't need to call the other query | //we don't need to call the other query | ||||
setValue(stopsDone); | setValue(stopsDone); | ||||
isQueryRunning = false; | |||||
} else | } else | ||||
for (int i = 0; i < stopsFromFavorites.size(); i++) { | for (int i = 0; i < stopsFromFavorites.size(); i++) { | ||||
Stop s = stopsFromFavorites.get(i); | Stop s = stopsFromFavorites.get(i); | ||||
queryHandler.startQuery(STOPS_TOKEN_BASE + i, null, | queryHandler.startQuery(STOPS_TOKEN_BASE + i, null, | ||||
getStopsBuilder().appendPath(s.ID).build(), | getStopsBuilder().appendPath(s.ID).build(), | ||||
NextGenDB.QUERY_COLUMN_stops_all, null, null, null); | NextGenDB.QUERY_COLUMN_stops_all, null, null, null); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register