Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/middleware/AsyncDataDownload.java
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public class AsyncDataDownload extends AsyncTask<String,Fetcher.result,Object>{ | ||||
private final AtomicReference<Fetcher.result> res; | private final AtomicReference<Fetcher.result> res; | ||||
private final RequestType t; | private final RequestType t; | ||||
private String query; | private String query; | ||||
WeakReference<FragmentHelper> helperRef; | WeakReference<FragmentHelper> helperRef; | ||||
private final ArrayList<Thread> otherActivities = new ArrayList<>(); | private final ArrayList<Thread> otherActivities = new ArrayList<>(); | ||||
private final Fetcher[] theFetchers; | private final Fetcher[] theFetchers; | ||||
private Context context; | private Context context; | ||||
private final boolean replaceFragment; | |||||
public AsyncDataDownload(FragmentHelper fh, @NonNull Fetcher[] fetchers, Context context) { | public AsyncDataDownload(FragmentHelper fh, @NonNull Fetcher[] fetchers, Context context) { | ||||
RequestType type; | RequestType type; | ||||
helperRef = new WeakReference<>(fh); | helperRef = new WeakReference<>(fh); | ||||
fh.setLastTaskRef(new WeakReference<>(this)); | fh.setLastTaskRef(new WeakReference<>(this)); | ||||
res = new AtomicReference<>(); | res = new AtomicReference<>(); | ||||
this.context = context.getApplicationContext(); | this.context = context.getApplicationContext(); | ||||
this.replaceFragment = true; | |||||
theFetchers = fetchers; | theFetchers = fetchers; | ||||
if (theFetchers.length < 1){ | if (theFetchers.length < 1){ | ||||
throw new IllegalArgumentException("You have to put at least one Fetcher, idiot!"); | throw new IllegalArgumentException("You have to put at least one Fetcher, idiot!"); | ||||
} | } | ||||
if (theFetchers[0] instanceof ArrivalsFetcher){ | if (theFetchers[0] instanceof ArrivalsFetcher){ | ||||
type = RequestType.ARRIVALS; | type = RequestType.ARRIVALS; | ||||
} else if (theFetchers[0] instanceof StopsFinderByName){ | } else if (theFetchers[0] instanceof StopsFinderByName){ | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | protected void onPostExecute(Object o) { | ||||
return; | return; | ||||
} | } | ||||
if(isCancelled()) return; | if(isCancelled()) return; | ||||
switch (t){ | switch (t){ | ||||
case ARRIVALS: | case ARRIVALS: | ||||
Palina palina = (Palina) o; | Palina palina = (Palina) o; | ||||
fh.createOrUpdateStopFragment(palina); | fh.createOrUpdateStopFragment(palina, replaceFragment); | ||||
break; | break; | ||||
case STOPS: | case STOPS: | ||||
//this should never be a problem | //this should never be a problem | ||||
List<Stop> stopList = (List<Stop>) o; | List<Stop> stopList = (List<Stop>) o; | ||||
if(query!=null && !isCancelled()) { | if(query!=null && !isCancelled()) { | ||||
fh.createFragmentFor(stopList,query); | fh.createStopListFragment(stopList,query, replaceFragment); | ||||
} else Log.e(TAG,"QUERY NULL, COULD NOT CREATE FRAGMENT"); | } else Log.e(TAG,"QUERY NULL, COULD NOT CREATE FRAGMENT"); | ||||
break; | break; | ||||
case DBUPDATE: | case DBUPDATE: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
▲ Show 20 Lines • Show All 104 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