@Override public Loader<List<Anime>> onCreateLoader(int id, Bundle args) { Loader<List<Anime>> loader = new AsyncTaskLoader<List<Anime>>(getActivity()) { @Override public List<Anime> loadInBackground() { List<Anime> animeList = ParseManager.getInstance(getActivity()).getAnimeList(mCurrentPage); List<Anime> cacheAnimeList = new ArrayList<>(); List<Anime> nonCachedAnimeList = new ArrayList<>(); Anime cachedAnime = null; for (Anime anime : animeList) { cachedAnime = MAVApplication.getInstance().getRepository().getAnimeByUrl(anime.getUrl()); if (cachedAnime != null) { AnimeHelper.update(anime, cachedAnime); cacheAnimeList.add(cachedAnime); } else { nonCachedAnimeList.add(anime); } } MAVApplication.getInstance().getRepository().updateAnimeList(cacheAnimeList); MAVApplication.getInstance().getRepository().insertAnimeList(nonCachedAnimeList); return animeList; } }; loader.forceLoad(); return loader; }
@Override public Loader<MapCatalog> onCreateLoader(int id, Bundle args) { final ApplicationEx app = ApplicationEx.getInstance(MapListFragment.this.getActivity()); switch(id){ case LOCAL_CATALOG_LOADER: return new AsyncTaskLoader<MapCatalog>(getActivity()) { @Override public MapCatalog loadInBackground() { return app.getLocalMapCatalogManager().getMapCatalog(); } }; case REMOTE_CATALOG_LOADER: return new AsyncTaskLoader<MapCatalog>(getActivity()) { @Override public MapCatalog loadInBackground() { return app.getRemoteMapCatalogProvider().getMapCatalog(false); } }; } return null; }
@Override public Loader<List<SocialSpaceInfo>> onCreateLoader(int id, Bundle args) { return new AsyncTaskLoader<List<SocialSpaceInfo>>(this) { @Override public List<SocialSpaceInfo> loadInBackground() { List<SocialSpaceInfo> spacesNames = new ArrayList<SocialSpaceInfo>(); if (SocialServiceHelper.getInstance().spaceService == null) { Log.e(LOG_TAG, "Cannot retrieve spaces. Social Space service is null."); return null; } List<RestSpace> spaces = SocialServiceHelper.getInstance().spaceService.getMySocialSpaces(); String currentServer = AccountSetting.getInstance().getDomainName(); for (RestSpace space : spaces) { SocialSpaceInfo sp = new SocialSpaceInfo(); sp.displayName = space.getDisplayName(); sp.name = space.getName(); sp.avatarUrl = currentServer + space.getAvatarUrl(); sp.groupId = space.getGroupId(); spacesNames.add(sp); } return spacesNames; } }; }
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { PoemLog.i(this, "onCreateLoader"); String text = null; if (args != null) { text = args.getString(PoemConstant.QUERY); } final String finalText = text == null ? null : text.trim(); Loader<Cursor> loader = new AsyncTaskLoader<Cursor>(getActivity()) { @Override public Cursor loadInBackground() { return onQuery(finalText); } @Override protected void onStartLoading() { forceLoad(); } }; return loader; }
@Override public Loader<List<Post>> onCreateLoader(int id, Bundle args) { return new AsyncTaskLoader<List<Post>>(getContext()) { @Override public List<Post> loadInBackground() { List<Post> data = new ArrayList<>(); try { data = Api.getPosts(); } catch (IOException e) { e.printStackTrace(); } return data; } }; }
@Override protected AsyncTaskLoader<ListData> createLoader(int id, Bundle args) { ItemsLoader loader = null; if (id == ItemsLoader.ID) { boolean needLoadRepImage; if (!Client.getInstance().getLogined()){ getPreferences().edit().putBoolean("needLoadRepImage", false).remove("repPlusImage").apply(); needLoadRepImage = false; }else { needLoadRepImage = getPreferences().getBoolean("needLoadRepImage", false); } setLoading(true); loader = new ItemsLoader(getActivity(), args, needLoadRepImage); } return loader; }
@Override public Loader<AccessToken> onCreateLoader(int id, Bundle args) { // show ProgressDialog mProgressDialog = new ProgressDialog(mContext); mProgressDialog.setTitle(R.string.dialog_title_text); mProgressDialog.setMessage(mContext .getString(R.string.dialog_message_text)); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); mProgressDialog.setCancelable(false); mProgressDialog.show(); // run AsyncTaskLoader AsyncTaskLoader<AccessToken> loader = new TwitterOAuthAccessTokenLoader( mContext, mTwitter, mPin); loader.startLoading(); return loader; }
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new AsyncTaskLoader<Cursor>(getActivity()) { Cursor mTaskDAta = null; @Override protected void onStartLoading() { if (mTaskDAta != null) { notifyLoaderChangeListener(); } else { forceLoad(); } } private void notifyLoaderChangeListener() { } @Override public Cursor loadInBackground() { //to do Make it private again try { return getActivity().getContentResolver().query(TaskItemsContract.TaskItemsColumns.CONTENT_URI, null, null, null, null); } catch (Exception e) { Log.e(TAG, "Failed to asynchronously load data."); e.printStackTrace(); return null; } } }; }
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new AsyncTaskLoader<Cursor>(getActivity()) { Cursor mTaskDAta = null; @Override protected void onStartLoading() { if (mTaskDAta != null) { notifyLoaderChangeListener(); } else { forceLoad(); } } private void notifyLoaderChangeListener() { } @Override public Cursor loadInBackground() { try { Uri todayUri = TaskItemsContract.TaskItemsColumns.CONTENT_URI.buildUpon().appendPath(TaskItemsContract.TaskItemsColumns.COLUMN_NAME_IS_TODAY).appendPath("1").build(); return getActivity().getContentResolver().query(todayUri, null, null, null, null); } catch (Exception e) { Log.e(TAG, "Failed to asynchronously load data."); e.printStackTrace(); return null; } } }; }
/** * Instantiates and returns a new AsyncTaskLoader with the given ID. * This loader will return task data as a Cursor or null if an error occurs. * * Implements the required callbacks to take care of loading data at all stages of loading. */ @Override public Loader<Cursor> onCreateLoader(int id, final Bundle loaderArgs) { return new AsyncTaskLoader<Cursor>(this) { // Initialize a Cursor, this will hold all the task data Cursor mTaskData = null; // onStartLoading() is called when a loader first starts loading data @Override protected void onStartLoading() { if (mTaskData != null) { // Delivers any previously loaded data immediately deliverResult(mTaskData); } else { // Force a new load forceLoad(); } } // loadInBackground() performs asynchronous loading of data @Override public Cursor loadInBackground() { // Will implement to load data return null; } // deliverResult sends the result of the load, a Cursor, to the registered listener public void deliverResult(Cursor data) { mTaskData = data; super.deliverResult(data); } }; }
@Override public Loader<List<OfflineHistoryRecord>> onCreateLoader(int arg0, Bundle arg1) { AsyncTaskLoader<List<OfflineHistoryRecord>> loader = new AsyncTaskLoader<List<OfflineHistoryRecord>>(getActivity()) { @Override public List<OfflineHistoryRecord> loadInBackground() { return MAVApplication.getInstance().getRepository().getOfflineHistoryRecords(); } }; // This is called when a new Loader needs to be created. This // sample only has one Loader with no arguments, so it is simple. loader.forceLoad(); return loader; }
@Override public Loader<List<HistoryRecord>> onCreateLoader(int arg0, Bundle arg1) { Loader<List<HistoryRecord>> loader = new AsyncTaskLoader<List<HistoryRecord>>(getActivity()) { @Override public List<HistoryRecord> loadInBackground() { return MAVApplication.getInstance().getRepository().getHistoryRecords(); } }; // This is called when a new Loader needs to be created. This // sample only has one Loader with no arguments, so it is simple. loader.forceLoad(); return loader; }
@Override public Loader<String> onCreateLoader(int id, Bundle args) { AsyncTaskLoader<String> loader = new AsyncTaskLoader<String>(getActivity()) { @Override public String loadInBackground() { Parser parser = Parser.getExistingInstance(anime.getUrl()); videoUrl = parser.getEpisodeVideo(episode.getUrl()); WriteLog.appendLog("VideoDetailsFragment", "loadInBackground " + videoUrl); return videoUrl; } }; loader.forceLoad(); return loader; }
@Override public Loader<String> onCreateLoader(int id, Bundle args) { AsyncTaskLoader<String> loader = new AsyncTaskLoader<String>(this) { @Override public String loadInBackground() { Parser parser = Parser.getExistingInstance(anime.getUrl()); videoUrl = parser.getEpisodeVideo(episode.getUrl()); WriteLog.appendLog(mTag, "loadInBackground " + videoUrl); return videoUrl; } }; loader.forceLoad(); return loader; }
@Override public Loader<String> onCreateLoader(int id, final Bundle args) { return new AsyncTaskLoader<String>(mContext) { private String mResponse; @Override protected void onStartLoading() { if (args == null) return; if (mResponse == null) { forceLoad(); } else { deliverResult(mResponse); } } @Nullable @Override public String loadInBackground() { URL url = (java.net.URL) args.getSerializable(URL_EXTRA); if (url != null) { try { Log.i(TAG, "Requesting Data From: " + url.toString()); return HTTPUtils.getHTTPResponse(url); } catch (IOException e) { Log.e(TAG, e.getMessage()); } } return null; } @Override public void deliverResult(@Nullable String data) { super.deliverResult(data); mResponse = data; } }; }
@Override public Loader<MapInfo[]> onCreateLoader(int id, Bundle args) { return new AsyncTaskLoader<MapInfo[]>(getActivity()) { @Override public MapInfo[] loadInBackground() { ApplicationEx app = ApplicationEx.getInstance(this); final Set<String> loadedMaps = new HashSet<>(); for (MapInfo m : app.getLocalMapCatalogManager().getMapCatalog().getMaps()) { loadedMaps.add(m.getFileName()); } MapCatalog remoteMapCatalog = app.getRemoteMapCatalogProvider() .getMapCatalog(false); if(remoteMapCatalog == null){ return null; } Collection<MapInfo> remoteMaps = ListUtils.filter(Arrays.asList(remoteMapCatalog.getMaps()), new ListUtils.IPredicate<MapInfo>() { @Override public boolean apply(MapInfo map) { return !loadedMaps.contains(map.getFileName()); } }); return remoteMaps.toArray(new MapInfo[remoteMaps.size()]); } }; }
@Override public Loader<List<ContentValues>> onCreateLoader(int id, Bundle args) { return new AsyncTaskLoader<List<ContentValues>>(getActivity()) { @Override public List<ContentValues> loadInBackground() { return new CartItemSQLiteHelper(getContext()).getAllCartItems(); } }; }
@Override public void onRefreshFragmentContent(final SwipeRefreshLayout swipeLayout) { showProgressLoading(); AsyncTaskLoader<JSONObject> loader = (AsyncTaskLoader<JSONObject>) getSupportLoaderManager() .<JSONObject> getLoader(0); if (loader != null) { loader.stopLoading(); loader.forceLoad(); } else { Log.e(TAG, "loader is null!"); } }
/** * Instantiates and returns a new AsyncTaskLoader with the given ID. * This loader will return task data as a Cursor or null if an error occurs. * <p> * Implements the required callbacks to take care of loading data at all stages of loading. */ @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new AsyncTaskLoader<Cursor>(this) { // Initialize a Cursor, this will hold all the task data Cursor mTaskData = null; // onStartLoading() is called when a loader first starts loading data @Override protected void onStartLoading() { if (mTaskData != null) { // Delivers any previously loaded data immediately deliverResult(mTaskData); } else { // Force a new load forceLoad(); } } // loadInBackground() performs asynchronous loading of data @Override public Cursor loadInBackground() { // Will implement to load data // Query and load all task data in the background; try { return getContentResolver().query(ArticleContract.ArticleEntry.CONTENT_URI, null, null, null, null); } catch (Exception e) { e.printStackTrace(); return null; } } // deliverResult sends the result of the load, a Cursor, to the registered listener public void deliverResult(Cursor data) { mTaskData = data; super.deliverResult(data); } }; }
/** * Instantiates and returns a new AsyncTaskLoader with the given ID. * This loader will return task data as a Cursor or null if an error occurs. * * Implements the required callbacks to take care of loading data at all stages of loading. */ @Override public Loader<Cursor> onCreateLoader(int id, final Bundle loaderArgs) { return new AsyncTaskLoader<Cursor>(this) { // Initialize a Cursor, this will hold all the task data Cursor mTaskData = null; // onStartLoading() is called when a loader first starts loading data @Override protected void onStartLoading() { if (mTaskData != null) { // Delivers any previously loaded data immediately deliverResult(mTaskData); } else { // Force a new load forceLoad(); } } // loadInBackground() performs asynchronous loading of data @Override public Cursor loadInBackground() { // Will implement to load data // COMPLETED (5) Query and load all task data in the background; sort by priority // [Hint] use a try/catch block to catch any errors in loading data try { return getContentResolver().query(TaskContract.TaskEntry.CONTENT_URI, null, null, null, TaskContract.TaskEntry.COLUMN_PRIORITY); } catch (Exception e) { Log.e(TAG, "Failed to asynchronously load data."); e.printStackTrace(); return null; } } // deliverResult sends the result of the load, a Cursor, to the registered listener public void deliverResult(Cursor data) { mTaskData = data; super.deliverResult(data); } }; }
/** * Instantiates and returns a new AsyncTaskLoader with the given ID. * This loader will return task data as a Cursor or null if an error occurs. * * Implements the required callbacks to take care of loading data at all stages of loading. */ @Override public Loader<Cursor> onCreateLoader(int id, final Bundle loaderArgs) { return new AsyncTaskLoader<Cursor>(this) { // Initialize a Cursor, this will hold all the task data Cursor mTaskData = null; // onStartLoading() is called when a loader first starts loading data @Override protected void onStartLoading() { if (mTaskData != null) { // Delivers any previously loaded data immediately deliverResult(mTaskData); } else { // Force a new load forceLoad(); } } // loadInBackground() performs asynchronous loading of data @Override public Cursor loadInBackground() { // Will implement to load data // Query and load all task data in the background; sort by priority // [Hint] use a try/catch block to catch any errors in loading data try { return getContentResolver().query(TaskContract.TaskEntry.CONTENT_URI, null, null, null, TaskContract.TaskEntry.COLUMN_PRIORITY); } catch (Exception e) { Log.e(TAG, "Failed to asynchronously load data."); e.printStackTrace(); return null; } } // deliverResult sends the result of the load, a Cursor, to the registered listener public void deliverResult(Cursor data) { mTaskData = data; super.deliverResult(data); } }; }
@Override public Loader<String> onCreateLoader(final int i, final Bundle bundle) { // Within onCreateLoader // COMPLETED (4) Return a new AsyncTaskLoader<String> as an anonymous inner class with this as the constructor's parameter return new AsyncTaskLoader<String>(this) { // COMPLETED (5) Override onStartLoading @Override protected void onStartLoading() { // Within onStartLoading // COMPLETED (6) If args is null, return. if (bundle == null) { return; } // COMPLETED (7) Show the loading indicator mLoadingIndicator.setVisibility(View.VISIBLE); // COMPLETED (8) Force a load forceLoad(); // END - onStartLoading } // COMPLETED (9) Override loadInBackground @Override public String loadInBackground() { // Within loadInBackground // COMPLETED (10) Get the String for our URL from the bundle passed to onCreateLoader String searchQueryUrlString = bundle.getString(SEARCH_QUERY_URL_EXTRA); // COMPLETED (11) If the URL is null or empty, return null if (searchQueryUrlString == null || searchQueryUrlString.isEmpty()) { return null; } // COMPLETED (12) Copy the try / catch block from the AsyncTask's doInBackground method try { URL githubURL = new URL(searchQueryUrlString); String githubSearchResults = NetworkUtils.getResponseFromHttpUrl(githubURL); return githubSearchResults; } catch (IOException e) { e.printStackTrace(); return null; } // END - loadInBackground } }; }
@Override public Loader<String> onCreateLoader(int id, final Bundle args) { return new AsyncTaskLoader<String>(this) { // COMPLETED (1) Create a String member variable called mGithubJson that will store the raw JSON private String mGithubJson; @Override protected void onStartLoading() { /* If no arguments were passed, we don't have a query to perform. Simply return. */ if (args == null) { return; } /* * When we initially begin loading in the background, we want to display the * loading indicator to the user */ mLoadingIndicator.setVisibility(View.VISIBLE); // COMPLETED (2) If mGithubJson is not null, deliver that result. Otherwise, force a load if (mGithubJson != null) { deliverResult(mGithubJson); } else { forceLoad(); } } @Override public String loadInBackground() { /* Extract the search query from the args using our constant */ String searchQueryUrlString = args.getString(SEARCH_QUERY_URL_EXTRA); /* If the user didn't enter anything, there's nothing to search for */ if (searchQueryUrlString == null || TextUtils.isEmpty(searchQueryUrlString)) { return null; } /* Parse the URL from the passed in String and perform the search */ try { URL githubUrl = new URL(searchQueryUrlString); String githubSearchResults = NetworkUtils.getResponseFromHttpUrl(githubUrl); return githubSearchResults; } catch (IOException e) { e.printStackTrace(); return null; } } // COMPLETED (3) Override deliverResult and store the data in mGithubJson // COMPLETED (4) Call super.deliverResult after storing the data @Override public void deliverResult(String data) { mGithubJson = data; super.deliverResult(data); } }; }
/** * Instantiate and return a new Loader for the given ID. * * @param id The ID whose loader is to be created. * @param loaderArgs Any arguments supplied by the caller. * * @return Return a new Loader instance that is ready to start loading. */ @Override public Loader<String[]> onCreateLoader(int id, final Bundle loaderArgs) { return new AsyncTaskLoader<String[]>(this) { /* This String array will hold and help cache our weather data */ String[] mWeatherData = null; /** * Subclasses of AsyncTaskLoader must implement this to take care of loading their data. */ @Override protected void onStartLoading() { if (mWeatherData != null) { deliverResult(mWeatherData); } else { mLoadingIndicator.setVisibility(View.VISIBLE); forceLoad(); } } /** * This is the method of the AsyncTaskLoader that will load and parse the JSON data * from OpenWeatherMap in the background. * * @return Weather data from OpenWeatherMap as an array of Strings. * null if an error occurs */ @Override public String[] loadInBackground() { URL weatherRequestUrl = NetworkUtils.getUrl(MainActivity.this); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } } /** * Sends the result of the load to the registered listener. * * @param data The result of the load */ public void deliverResult(String[] data) { mWeatherData = data; super.deliverResult(data); } }; }
@Override public Loader<String[]> onCreateLoader(int id, Bundle args) { return new AsyncTaskLoader<String[]>(this) { String[] mWeatherData = null; @Override protected void onStartLoading() { if (mWeatherData != null) { deliverResult(mWeatherData); } else { mLoadingIndicator.setVisibility(View.VISIBLE); forceLoad(); } } @Override public String[] loadInBackground() { String locationQuery = SunshinePreferences.getPreferredWeatherLocation(MainActivity.this); URL weatherRequestURL = NetworkUtils.buildUrl(locationQuery); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestURL); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } } @Override public void deliverResult(String[] data) { mWeatherData = data; super.deliverResult(data); } }; }
/** * Instantiate and return a new Loader for the given ID. * * @param id The ID whose loader is to be created. * @param loaderArgs Any arguments supplied by the caller. * * @return Return a new Loader instance that is ready to start loading. */ @Override public Loader<String[]> onCreateLoader(int id, final Bundle loaderArgs) { return new AsyncTaskLoader<String[]>(this) { /* This String array will hold and help cache our weather data */ String[] mWeatherData = null; /** * Subclasses of AsyncTaskLoader must implement this to take care of loading their data. */ @Override protected void onStartLoading() { if (mWeatherData != null) { deliverResult(mWeatherData); } else { mLoadingIndicator.setVisibility(View.VISIBLE); forceLoad(); } } /** * This is the method of the AsyncTaskLoader that will load and parse the JSON data * from OpenWeatherMap in the background. * * @return Weather data from OpenWeatherMap as an array of Strings. * null if an error occurs */ @Override public String[] loadInBackground() { String locationQuery = SunshinePreferences .getPreferredWeatherLocation(MainActivity.this); URL weatherRequestUrl = NetworkUtils.buildUrl(locationQuery); try { String jsonWeatherResponse = NetworkUtils .getResponseFromHttpUrl(weatherRequestUrl); String[] simpleJsonWeatherData = OpenWeatherJsonUtils .getSimpleWeatherStringsFromJson(MainActivity.this, jsonWeatherResponse); return simpleJsonWeatherData; } catch (Exception e) { e.printStackTrace(); return null; } } /** * Sends the result of the load to the registered listener. * * @param data The result of the load */ public void deliverResult(String[] data) { mWeatherData = data; super.deliverResult(data); } }; }
@Override public Loader<String> onCreateLoader(int id, final Bundle args) { return new AsyncTaskLoader<String>(this) { // TODO (1) Create a String member variable called mGithubJson that will store the raw JSON String mGithubJson; @Override protected void onStartLoading() { /* If no arguments were passed, we don't have a query to perform. Simply return. */ if (args == null) { return; } /* * When we initially begin loading in the background, we want to display the * loading indicator to the user */ mLoadingIndicator.setVisibility(View.VISIBLE); // TODO (2) If mGithubJson is not null, deliver that result. Otherwise, force a load if(mGithubJson != null){ deliverResult(mGithubJson); } else { forceLoad(); } } @Override public String loadInBackground() { /* Extract the search query from the args using our constant */ String searchQueryUrlString = args.getString(SEARCH_QUERY_URL_EXTRA); /* If the user didn't enter anything, there's nothing to search for */ if (searchQueryUrlString == null || TextUtils.isEmpty(searchQueryUrlString)) { return null; } /* Parse the URL from the passed in String and perform the search */ try { URL githubUrl = new URL(searchQueryUrlString); String githubSearchResults = NetworkUtils.getResponseFromHttpUrl(githubUrl); return githubSearchResults; } catch (IOException e) { e.printStackTrace(); return null; } } // TODO (3) Override deliverResult and store the data in mGithubJson // TODO (4) Call super.deliverResult after storing the data @Override public void deliverResult(String githubJson){ mGithubJson = githubJson; super.deliverResult(githubJson); } }; }