use of de.geeksfactory.opacclient.objects.Library in project opacclient by opacapp.
the class UpdateHandler method updateConfig.
public int updateConfig(WebService service, PreferenceDataSource prefs, LibraryConfigUpdateService.FileOutput output, SearchFieldDataSource searchFields) throws IOException, JSONException {
DateTime last_update = prefs.getLastLibraryConfigUpdate();
if (prefs.getLastLibraryConfigUpdateVersion() != BuildConfig.VERSION_CODE) {
last_update = prefs.getBundledConfigUpdateTime();
}
Response<List<Library>> response = getServerResponse(service, last_update);
if (!response.isSuccessful()) {
throw new IOException(String.valueOf(response.code()));
}
if (prefs.getLastLibraryConfigUpdateVersion() != BuildConfig.VERSION_CODE) {
output.clearFiles();
}
List<Library> updatedLibraries = response.body();
for (Library lib : updatedLibraries) {
if (lib == null) {
continue;
}
String filename = lib.getIdent() + ".json";
JSONObject json = lib.toJSON();
output.writeFile(filename, json.toString());
if (searchFields.hasSearchFields(lib.getIdent())) {
// clear cached search fields when configuration was updated
searchFields.clearSearchFields(lib.getIdent());
}
}
DateTime lastUpdate = new DateTime(response.headers().get("X-Page-Generated"));
prefs.setLastLibraryConfigUpdate(lastUpdate);
prefs.setLastLibraryConfigUpdateVersion(BuildConfig.VERSION_CODE);
return updatedLibraries.size();
}
use of de.geeksfactory.opacclient.objects.Library in project opacclient by opacapp.
the class LibraryListActivity method showListLibraries.
public void showListLibraries(String country, String state, String city) {
LibraryListFragment fragment = new LibraryListFragment();
Bundle args = new Bundle();
args.putInt("level", LEVEL_LIBRARY);
args.putString("country", country);
args.putString("state", state);
args.putString("city", city);
fragment.setArguments(args);
Set<Library> data = new HashSet<>();
for (Library lib : libraries) {
if (country.equals(lib.getCountry()) && state.equals(lib.getState()) && city.equals(lib.getCity()) && !data.contains(lib)) {
data.add(lib);
}
}
List<Library> list = new ArrayList<>(data);
Collections.sort(list);
LibraryAdapter adapter = new LibraryAdapter(this, R.layout.listitem_library_in_city, R.id.tvTitle, list);
fragment.setListAdapter(adapter);
if (findViewById(R.id.llFragments) != null) {
fragment4 = fragment;
getSupportFragmentManager().beginTransaction().replace(R.id.container4, fragment4).commit();
} else {
this.fragment = fragment;
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment).addToBackStack(null).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
}
}
use of de.geeksfactory.opacclient.objects.Library in project opacclient by opacapp.
the class LibraryListActivity method showListCities.
public void showListCities(String country, String state) {
LibraryListFragment fragment = new LibraryListFragment();
Bundle args = new Bundle();
args.putInt("level", LEVEL_CITY);
args.putString("country", country);
args.putString("state", state);
fragment.setArguments(args);
Set<String> data = new HashSet<>();
for (Library lib : libraries) {
if (country.equals(lib.getCountry()) && state.equals(lib.getState()) && !data.contains(lib.getCity())) {
data.add(lib.getCity());
}
}
List<String> list = new ArrayList<>(data);
if (data.size() == 1 && list.get(0).equals(state)) {
// City states
showListLibraries(country, state, list.get(0));
}
Collator deCollator = Collator.getInstance(Locale.GERMAN);
deCollator.setStrength(Collator.TERTIARY);
Collections.sort(list, deCollator);
ArrayAdapter<String> adapter = new CityAdapter(this, R.layout.listitem_simple, R.id.txtText, list);
fragment.setListAdapter(adapter);
if (findViewById(R.id.llFragments) != null) {
fragment3 = fragment;
getSupportFragmentManager().beginTransaction().replace(R.id.container3, fragment3).commit();
if (fragment4 != null) {
getSupportFragmentManager().beginTransaction().detach(fragment4).commit();
}
} else if (data.size() > 1 || !list.get(0).equals(state)) {
this.fragment = fragment;
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment).addToBackStack(null).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
}
}
use of de.geeksfactory.opacclient.objects.Library in project opacclient by opacapp.
the class AccountFragment method displayHeader.
protected void displayHeader() {
if (accountData == null || tvAccLabel == null || tvAccUser == null || tvAccCity == null || tvPendingFees == null || tvPendingFeesLabel == null || tvValidUntil == null || tvValidUntilLabel == null) {
return;
}
tvAccLabel.setText(account.getLabel());
tvAccUser.setText(account.getName());
Library lib;
try {
lib = app.getLibrary(account.getLibrary());
tvAccCity.setText(lib.getDisplayName());
} catch (IOException e) {
ErrorReporter.handleException(e);
e.printStackTrace();
} catch (JSONException e) {
ErrorReporter.handleException(e);
}
if (accountData != null) {
if (accountData.getPendingFees() != null) {
tvPendingFeesLabel.setVisibility(View.VISIBLE);
tvPendingFees.setVisibility(View.VISIBLE);
tvPendingFees.setText(accountData.getPendingFees());
} else {
tvPendingFeesLabel.setVisibility(View.GONE);
tvPendingFees.setVisibility(View.GONE);
}
if (accountData.getValidUntil() != null) {
tvValidUntilLabel.setVisibility(View.VISIBLE);
tvValidUntil.setVisibility(View.VISIBLE);
tvValidUntil.setText(accountData.getValidUntil());
} else {
tvValidUntilLabel.setVisibility(View.GONE);
tvValidUntil.setVisibility(View.GONE);
}
}
}
use of de.geeksfactory.opacclient.objects.Library in project opacclient by opacapp.
the class OpacClient method getLibraries.
public List<Library> getLibraries(ProgressCallback callback) throws IOException {
AssetManager assets = getAssets();
String[] files = assets.list(ASSETS_BIBSDIR);
String[] additionalFiles = getLibrariesDir().list();
Set<String> allFiles = new HashSet<>();
Collections.addAll(allFiles, files);
Collections.addAll(allFiles, additionalFiles);
int num = allFiles.size();
List<Library> libs = new ArrayList<>();
int i = 0;
for (String file : allFiles) {
try {
Library lib = getLibrary(file.substring(0, file.length() - ".json".length()));
if ((!lib.getApi().equals("test") || BuildConfig.DEBUG) && lib.isActive()) {
libs.add(lib);
}
} catch (JSONException e) {
Log.w("JSON library files", "Failed parsing library " + file);
e.printStackTrace();
}
if (callback != null && i % 10 == 0 && i > 0) {
// reporting progress for every 10 loaded files should be enough
callback.publishProgress(((double) i) / num);
}
i++;
}
return libs;
}
Aggregations