app/src/main/java/com/mensa/zhmensa/services/MensaManager.java
/**
     * Loads Mensas for async for the given category.
     * Whenever a mensa is obtained that is not stored in the cache, the associated listeners get called
     *
     * @param category The category which mensas shoudl be loaded.
     */
Loads Mensas for async for the given category.
Whenever a mensa is obtained that is not stored in the cache, the associated listeners get called

@param category The category which mensas shoudl be loaded.
Loads Mensas for async for the given category . Whenever a mensa is obtained that is not stored in the cache the associated listeners get called @param category The category which mensas shoudl be loaded .
public static void loadMensasForCategory(@NonNull final MensaCategory category, final boolean loadFromInternet, final Context ctx) {
        new AsyncTask<Void, Boolean, Pair<List<Mensa>, List<Mensa>>>() {
            @Override
            protected Pair<List<Mensa>, List<Mensa>> doInBackground(Void... voids) {
                try {
                    return loadCachedMensaForCategory(category, ctx);
                } catch (JsonParseException e) {
                    clearCache(ctx);
                    Log.e("JSON ERROR", "Json Parse Exception", e);
                    return null;
                }
            }
            @Override
            protected void onPostExecute(Pair<List<Mensa>, List<Mensa>> listListPair) {
                Log.d("post execute", "post");
                if(listListPair == null) {
                    loadMensasForCategoryFromInternet(category, ctx);
                    return;
                }
                for(Mensa m : listListPair.first)
                    listener.onMensaUpdated(m);
                listener.onNewMensaLoaded(listListPair.second);
                if(loadFromInternet)
                    loadMensasForCategoryFromInternet(category, ctx);
            }
        }.execute();
    }
public static void loadMensasForCategory ( @ NonNull final MensaCategory category , final boolean loadFromInternet , final Context ctx ) { new AsyncTask < Void , Boolean , Pair < List < Mensa > , List < Mensa > > > ( ) { @ Override protected Pair < List < Mensa > , List < Mensa > > doInBackground ( Void ... voids ) { try { return loadCachedMensaForCategory ( category , ctx ) ; } catch ( JsonParseException e ) { clearCache ( ctx ) ; Log . e ( "JSON ERROR" , "Json Parse Exception" , e ) ; return null ; } } @ Override protected void onPostExecute ( Pair < List < Mensa > , List < Mensa > > listListPair ) { Log . d ( "post execute" , "post" ) ; if ( listListPair == null ) { loadMensasForCategoryFromInternet ( category , ctx ) ; return ; } for ( Mensa m : listListPair . first ) listener . onMensaUpdated ( m ) ; listener . onNewMensaLoaded ( listListPair . second ) ; if ( loadFromInternet ) loadMensasForCategoryFromInternet ( category , ctx ) ; } } . execute ( ) ; }
Loads Mensas for async for the given category.
Loads Mensas for async for the given category .