use of de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource in project opacclient by opacapp.
the class MainActivity method onNewIntent.
@SuppressLint("NewApi")
@Override
public void onNewIntent(Intent intent) {
if (nfc_capable && sp.getBoolean("nfc_search", false)) {
android.nfc.Tag tag = intent.getParcelableExtra(android.nfc.NfcAdapter.EXTRA_TAG);
String scanResult = readPageToString(tag);
if (scanResult != null) {
if (scanResult.length() > 5) {
SearchFieldDataSource source = new JsonSearchFieldDataSource(this);
if (source.hasSearchFields(app.getLibrary().getIdent())) {
List<SearchField> fields = source.getSearchFields(app.getLibrary().getIdent());
for (SearchField field : fields) {
if (field.getMeaning() == SearchField.Meaning.BARCODE) {
List<SearchQuery> queries = new ArrayList<>();
queries.add(new SearchQuery(field, scanResult));
app.startSearch(this, queries);
return;
}
}
}
Intent detailIntent = new Intent(this, SearchResultDetailActivity.class);
detailIntent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, scanResult);
startActivity(detailIntent);
}
}
}
}
use of de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource in project opacclient by opacapp.
the class SearchFragment method saveFields.
public void saveFields(List<SearchField> fields) {
SearchFieldDataSource dataSource = new JsonSearchFieldDataSource(app);
dataSource.saveSearchFields(app.getLibrary().getIdent(), fields);
}
use of de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource in project opacclient by opacapp.
the class SearchFragment method accountSelected.
@Override
public void accountSelected(Account account) {
errorView.removeAllViews();
progress(false);
if (!app.getLibrary().isActive()) {
showConnectivityError(getString(R.string.library_removed_error), false);
return;
}
SearchFieldDataSource dataSource = new JsonSearchFieldDataSource(app);
int versionCode = 0;
try {
versionCode = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionCode;
} catch (NameNotFoundException e) {
}
String language = getActivity().getResources().getConfiguration().locale.getLanguage();
if (dataSource.hasSearchFields(app.getLibrary().getIdent()) && dataSource.getLastSearchFieldUpdateVersion(app.getLibrary().getIdent()) == versionCode && language.equals(dataSource.getSearchFieldLanguage(app.getLibrary().getIdent()))) {
if (task != null && !task.isCancelled()) {
task.cancel(true);
}
Map<String, String> saved = saveQuery();
fields = dataSource.getSearchFields(app.getLibrary().getIdent());
buildSearchForm(savedState != null ? OpacClient.bundleToMap(savedState) : saved);
savedState = null;
} else {
executeNewLoadSearchFieldsTask();
}
setAdvanced(false);
}
use of de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource in project opacclient by opacapp.
the class LibraryConfigUpdateService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
WebService service = WebServiceManager.getInstance();
PreferenceDataSource prefs = new PreferenceDataSource(this);
File filesDir = new File(getFilesDir(), LIBRARIES_DIR);
filesDir.mkdirs();
try {
int count = ((OpacClient) getApplication()).getUpdateHandler().updateConfig(service, prefs, new FileOutput(filesDir), new JsonSearchFieldDataSource(this));
if (!BuildConfig.DEBUG) {
DateTime lastUpdate = prefs.getLastLibraryConfigUpdate();
ACRA.getErrorReporter().putCustomData("data_version", lastUpdate != null ? lastUpdate.toString() : "null");
}
if (BuildConfig.DEBUG) {
Log.d("LibraryConfigUpdate", "updated config for " + String.valueOf(count) + " libraries");
}
Intent broadcast = new Intent(ACTION_SUCCESS).putExtra(EXTRA_UPDATE_COUNT, count);
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
((OpacClient) getApplication()).resetCache();
} catch (IOException e) {
Intent broadcast = new Intent(ACTION_FAILURE);
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
} catch (JSONException e) {
Intent broadcast = new Intent(ACTION_FAILURE);
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
ErrorReporter.handleException(e);
}
}
use of de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource in project opacclient by opacapp.
the class StarredFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
view = inflater.inflate(R.layout.fragment_starred, container, false);
app = (OpacClient) getActivity().getApplication();
adapter = new ItemListAdapter();
listView = (ListView) view.findViewById(R.id.lvStarred);
tvWelcome = (TextView) view.findViewById(R.id.tvWelcome);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Starred item = (Starred) view.findViewById(R.id.ivDelete).getTag();
if (item.getMNr() == null || item.getMNr().equals("null") || item.getMNr().equals("")) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
List<SearchQuery> query = new ArrayList<>();
List<SearchField> fields = new JsonSearchFieldDataSource(app).getSearchFields(app.getLibrary().getIdent());
if (fields != null) {
SearchField title_field = null, free_field = null;
for (SearchField field : fields) {
if (field.getMeaning() == Meaning.TITLE) {
title_field = field;
} else if (field.getMeaning() == Meaning.FREE) {
free_field = field;
} else if (field.getMeaning() == Meaning.HOME_BRANCH) {
query.add(new SearchQuery(field, sp.getString(OpacClient.PREF_HOME_BRANCH_PREFIX + app.getAccount().getId(), null)));
}
}
if (title_field != null) {
query.add(new SearchQuery(title_field, item.getTitle()));
} else if (free_field != null) {
query.add(new SearchQuery(free_field, item.getTitle()));
}
app.startSearch(getActivity(), query);
} else {
Toast.makeText(getActivity(), R.string.no_search_cache, Toast.LENGTH_LONG).show();
}
} else {
callback.showDetail(item.getMNr());
}
}
});
listView.setClickable(true);
listView.setTextFilterEnabled(true);
getActivity().getSupportLoaderManager().initLoader(0, null, this);
listView.setAdapter(adapter);
// Restore the previously serialized activated item position.
if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
}
setActivateOnItemClick(((OpacActivity) getActivity()).isTablet());
return view;
}
Aggregations