Search in sources :

Example 6 with PreferenceDataSource

use of de.geeksfactory.opacclient.storage.PreferenceDataSource in project opacclient by opacapp.

the class MainPreferenceFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    this.context = getActivity();
    addPreferencesFromResource(R.xml.settings);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH || !context.getPackageManager().hasSystemFeature("android.hardware.nfc")) {
        if (findPreference("nfc_search") != null) {
            findPreference("nfc_search").setEnabled(false);
        }
    }
    Preference assistant = findPreference("accounts");
    assistant.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            ((OpacClient) context.getApplication()).openAccountList(context);
            return false;
        }
    });
    if (!ebooksSupported()) {
        ((PreferenceCategory) findPreference("cat_web_opac")).removePreference(findPreference("email"));
    }
    CheckBoxPreference notification = (CheckBoxPreference) findPreference("notification_service");
    if (notification != null) {
        notification.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                boolean enabled = (Boolean) newValue;
                new ReminderHelper((OpacClient) getActivity().getApplication()).updateAlarms(enabled);
                return true;
            }
        });
    }
    ListPreference warning = (ListPreference) findPreference("notification_warning");
    if (warning != null) {
        warning.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
                // int oldWarning = Integer.parseInt(prefs.getString("notification_warning",
                // "3"));
                int newWarning = Integer.parseInt((String) newValue);
                new ReminderHelper((OpacClient) getActivity().getApplication()).updateAlarms(newWarning);
                return true;
            }
        });
    }
    Preference meta_run_check = findPreference("meta_run_check");
    if (meta_run_check != null) {
        meta_run_check.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                SyncAccountJob.runImmediately();
                return false;
            }
        });
    }
    Preference meta = findPreference("meta_clear");
    if (meta != null) {
        meta.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                AccountDataSource adata = new AccountDataSource(context);
                adata.invalidateCachedData();
                new ReminderHelper((OpacClient) context.getApplication()).updateAlarms(-1);
                SearchFieldDataSource sfdata = new JsonSearchFieldDataSource(context);
                sfdata.clearAll();
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
                sp.edit().remove("reservation_fee_warning_ignore").apply();
                SyncAccountJob.runImmediately();
                return false;
            }
        });
    }
    final Preference updateLibraryConfig = findPreference("update_library_config");
    if (updateLibraryConfig != null) {
        updateLibraryConfig.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                IntentFilter successFilter = new IntentFilter(LibraryConfigUpdateService.ACTION_SUCCESS);
                IntentFilter failureFilter = new IntentFilter(LibraryConfigUpdateService.ACTION_FAILURE);
                BroadcastReceiver receiver = new LibraryConfigServiceReceiver(updateLibraryConfig);
                LocalBroadcastManager.getInstance(context).registerReceiver(receiver, successFilter);
                LocalBroadcastManager.getInstance(context).registerReceiver(receiver, failureFilter);
                Intent i = new Intent(context, LibraryConfigUpdateService.class);
                context.startService(i);
                DialogFragment newFragment = ProgressDialogFragment.getInstance(R.string.updating_library_config);
                showDialog(newFragment);
                updateLibraryConfig.setEnabled(false);
                return false;
            }
        });
        refreshLastConfigUpdate(updateLibraryConfig);
    }
    final Preference resetLibraryConfig = findPreference("reset_library_config");
    if (resetLibraryConfig != null) {
        PreferenceDataSource prefs = new PreferenceDataSource(getActivity());
        resetLibraryConfig.setEnabled(prefs.hasBundledConfiguration());
        resetLibraryConfig.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                LibraryConfigUpdateService.clearConfigurationUpdates(getContext());
                if (getView() != null) {
                    Snackbar.make(getView(), R.string.library_config_reset, Snackbar.LENGTH_SHORT).show();
                    refreshLastConfigUpdate(updateLibraryConfig);
                }
                return false;
            }
        });
    }
}
Also used : IntentFilter(android.content.IntentFilter) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) SharedPreferences(android.content.SharedPreferences) DialogFragment(android.support.v4.app.DialogFragment) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) Intent(android.content.Intent) ListPreference(android.support.v7.preference.ListPreference) BroadcastReceiver(android.content.BroadcastReceiver) ReminderHelper(de.geeksfactory.opacclient.reminder.ReminderHelper) SearchFieldDataSource(de.geeksfactory.opacclient.storage.SearchFieldDataSource) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) PreferenceCategory(android.support.v7.preference.PreferenceCategory) PreferenceDataSource(de.geeksfactory.opacclient.storage.PreferenceDataSource) LibraryConfigUpdateService(de.geeksfactory.opacclient.webservice.LibraryConfigUpdateService)

Example 7 with PreferenceDataSource

use of de.geeksfactory.opacclient.storage.PreferenceDataSource in project opacclient by opacapp.

the class ResultsAdapter method getView.

@Override
public View getView(int position, View contentView, ViewGroup viewGroup) {
    View view;
    // position always 0-7
    if (objects.get(position) == null) {
        LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.listitem_searchresult, viewGroup, false);
        return view;
    }
    SearchResult item = objects.get(position);
    if (contentView == null) {
        LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.listitem_searchresult, viewGroup, false);
    } else {
        view = contentView;
    }
    TextView tv = (TextView) view.findViewById(R.id.tvResult);
    tv.setText(Html.fromHtml(item.getInnerhtml()));
    ImageView ivType = (ImageView) view.findViewById(R.id.ivType);
    PreferenceDataSource pds = new PreferenceDataSource(getContext());
    ConnectivityManager connMgr = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    if (item.getCoverBitmap() != null) {
        ivType.setImageBitmap(BitmapUtils.bitmapFromBytes(item.getCoverBitmap()));
        ivType.setVisibility(View.VISIBLE);
    } else if ((pds.isLoadCoversOnDataPreferenceSet() || !ConnectivityManagerCompat.isActiveNetworkMetered(connMgr)) && item.getCover() != null) {
        LoadCoverTask lct = new LoadCoverTask(ivType, item);
        lct.execute();
        ivType.setImageResource(R.drawable.ic_loading);
        ivType.setVisibility(View.VISIBLE);
    } else if (item.getType() != null && item.getType() != MediaType.NONE) {
        ivType.setImageResource(getResourceByMediaType(item.getType()));
        ivType.setVisibility(View.VISIBLE);
    } else {
        ivType.setVisibility(View.INVISIBLE);
    }
    ImageView ivStatus = (ImageView) view.findViewById(R.id.ivStatus);
    if (item.getStatus() != null) {
        ivStatus.setVisibility(View.VISIBLE);
        switch(item.getStatus()) {
            case GREEN:
                ivStatus.setImageResource(R.drawable.status_light_green);
                break;
            case RED:
                ivStatus.setImageResource(R.drawable.status_light_red);
                break;
            case YELLOW:
                ivStatus.setImageResource(R.drawable.status_light_yellow);
                break;
            case UNKNOWN:
                ivStatus.setVisibility(View.INVISIBLE);
                break;
        }
    } else {
        ivStatus.setVisibility(View.GONE);
    }
    return view;
}
Also used : PreferenceDataSource(de.geeksfactory.opacclient.storage.PreferenceDataSource) ConnectivityManager(android.net.ConnectivityManager) LayoutInflater(android.view.LayoutInflater) SearchResult(de.geeksfactory.opacclient.objects.SearchResult) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 8 with PreferenceDataSource

use of de.geeksfactory.opacclient.storage.PreferenceDataSource in project opacclient by opacapp.

the class OpacClient method getLibrary.

public Library getLibrary(String ident) throws IOException, JSONException {
    String filename = ident + ".json";
    String json;
    File filesDir = getLibrariesDir();
    PreferenceDataSource prefs = getPreferenceDataSource();
    if (fileExists(filesDir, filename) && (!prefs.hasBundledConfiguration() || prefs.getLastLibraryConfigUpdateVersion() == BuildConfig.VERSION_CODE)) {
        // only use files if they were downloaded using the current app version
        json = Utils.readStreamToString(openFile(filesDir, filename));
    } else {
        json = Utils.readStreamToString(getAssets().open(ASSETS_BIBSDIR + "/" + filename));
    }
    return Library.fromJSON(ident, new JSONObject(json));
}
Also used : JSONObject(org.json.JSONObject) PreferenceDataSource(de.geeksfactory.opacclient.storage.PreferenceDataSource) File(java.io.File)

Aggregations

PreferenceDataSource (de.geeksfactory.opacclient.storage.PreferenceDataSource)8 File (java.io.File)4 JsonSearchFieldDataSource (de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)3 DateTime (org.joda.time.DateTime)3 Intent (android.content.Intent)2 LibraryConfigUpdateService (de.geeksfactory.opacclient.webservice.LibraryConfigUpdateService)2 IOException (java.io.IOException)2 JSONException (org.json.JSONException)2 BroadcastReceiver (android.content.BroadcastReceiver)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 ConnectivityManager (android.net.ConnectivityManager)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 PreferenceCategory (android.support.v7.preference.PreferenceCategory)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1