Search in sources :

Example 1 with JsonSearchFieldDataSource

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);
            }
        }
    }
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) SearchFieldDataSource(de.geeksfactory.opacclient.storage.SearchFieldDataSource) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) ArrayList(java.util.ArrayList) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint)

Example 2 with JsonSearchFieldDataSource

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);
}
Also used : SearchFieldDataSource(de.geeksfactory.opacclient.storage.SearchFieldDataSource) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)

Example 3 with JsonSearchFieldDataSource

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);
}
Also used : SearchFieldDataSource(de.geeksfactory.opacclient.storage.SearchFieldDataSource) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)

Example 4 with JsonSearchFieldDataSource

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);
    }
}
Also used : OpacClient(de.geeksfactory.opacclient.OpacClient) PreferenceDataSource(de.geeksfactory.opacclient.storage.PreferenceDataSource) JSONException(org.json.JSONException) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File) DateTime(org.joda.time.DateTime)

Example 5 with JsonSearchFieldDataSource

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;
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) SharedPreferences(android.content.SharedPreferences) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) List(java.util.List) ArrayList(java.util.ArrayList) Starred(de.geeksfactory.opacclient.objects.Starred)

Aggregations

JsonSearchFieldDataSource (de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)8 SearchFieldDataSource (de.geeksfactory.opacclient.storage.SearchFieldDataSource)5 Intent (android.content.Intent)3 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)3 PreferenceDataSource (de.geeksfactory.opacclient.storage.PreferenceDataSource)3 SharedPreferences (android.content.SharedPreferences)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)2 SearchQuery (de.geeksfactory.opacclient.searchfields.SearchQuery)2 LibraryConfigUpdateService (de.geeksfactory.opacclient.webservice.LibraryConfigUpdateService)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 BroadcastReceiver (android.content.BroadcastReceiver)1 IntentFilter (android.content.IntentFilter)1 DialogFragment (android.support.v4.app.DialogFragment)1 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)1 ListPreference (android.support.v7.preference.ListPreference)1 Preference (android.support.v7.preference.Preference)1