Search in sources :

Example 16 with AccountDataSource

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

the class SyncAccountJob method onRunJob.

@NonNull
@Override
protected Result onRunJob(Params params) {
    if (BuildConfig.DEBUG)
        Log.i(TAG, "SyncAccountJob started");
    if (getParams().getTag().equals(TAG_RETRY) && getParams().getFailureCount() >= 4) {
        // too many retries, give up and wait for the next regular scheduled run
        return Result.SUCCESS;
    }
    if (!getParams().getTag().equals(TAG_RETRY)) {
        updateLibraryConfig();
    }
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
    if (!sp.getBoolean(SyncAccountJobCreator.PREF_SYNC_SERVICE, false)) {
        if (BuildConfig.DEBUG)
            Log.i(TAG, "notifications are disabled");
        return Result.SUCCESS;
    }
    OpacClient app = getApp();
    AccountDataSource data = new AccountDataSource(getContext());
    ReminderHelper helper = new ReminderHelper(app);
    boolean failed = syncAccounts(app, data, sp, helper);
    if (BuildConfig.DEBUG) {
        Log.i(TAG, "SyncAccountJob finished " + (failed ? " with errors" : " " + "successfully"));
    }
    if (failed && params.getTag().equals(TAG)) {
        // only schedule a retry job if this is not already a retry
        scheduleRetryJob(getContext());
    }
    if (params.getTag().equals(TAG_RETRY)) {
        return failed ? Result.RESCHEDULE : Result.SUCCESS;
    } else {
        return failed ? Result.FAILURE : Result.SUCCESS;
    }
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OpacClient(de.geeksfactory.opacclient.OpacClient) SharedPreferences(android.content.SharedPreferences) NonNull(android.support.annotation.NonNull)

Example 17 with AccountDataSource

use of de.geeksfactory.opacclient.storage.AccountDataSource 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 18 with AccountDataSource

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

the class OpacActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    if (app.getLibrary() == null) {
        // Create new
        if (app.getAccount() != null) {
            try {
                InputStream stream = getAssets().open(OpacClient.ASSETS_BIBSDIR + "/" + app.getAccount().getLibrary() + ".json");
                stream.close();
            } catch (IOException e) {
                AccountDataSource data = new AccountDataSource(this);
                data.remove(app.getAccount());
                List<Account> available_accounts = data.getAllAccounts();
                if (available_accounts.size() > 0) {
                    ((OpacClient) getApplication()).setAccount(available_accounts.get(0).getId());
                }
                new ReminderHelper(app).generateAlarms();
                if (app.getLibrary() != null) {
                    return;
                }
            }
        }
        app.addFirstAccount(this);
    }
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) ReminderHelper(de.geeksfactory.opacclient.reminder.ReminderHelper) InputStream(java.io.InputStream) List(java.util.List) IOException(java.io.IOException)

Example 19 with AccountDataSource

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

the class OpacActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    supportRequestWindowFeature(android.view.Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(getContentView());
    app = (OpacClient) getApplication();
    aData = new AccountDataSource(this);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
    }
    fab = (FloatingActionButton) findViewById(R.id.search_fab);
    setupDrawer();
    setupAccountSwitcher();
    if (savedInstanceState != null) {
        setTwoPane(savedInstanceState.getBoolean("twoPane"));
        setFabVisible(savedInstanceState.getBoolean("fabVisible"));
        selectedItemId = savedInstanceState.getInt("selectedItemId");
        setFabOnClickListener(selectedItemId);
        if (savedInstanceState.containsKey("title")) {
            setTitle(savedInstanceState.getCharSequence("title"));
        }
        if (savedInstanceState.containsKey("fragment")) {
            fragment = getSupportFragmentManager().getFragment(savedInstanceState, "fragment");
            getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
        }
    }
    fixStatusBarFlashing();
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource)

Example 20 with AccountDataSource

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

the class AccountEditActivity method delete.

private void delete() {
    AccountDataSource data = new AccountDataSource(this);
    data.remove(account);
    // Check whether he deleted account was selected
    if (((OpacClient) getApplication()).getAccount().getId() == account.getId()) {
        List<Account> available_accounts = data.getAllAccounts();
        if (available_accounts.size() == 0) {
            ((OpacClient) getApplication()).setAccount(0);
            ((OpacClient) getApplication()).addFirstAccount(this);
        } else {
            ((OpacClient) getApplication()).setAccount(available_accounts.get(0).getId());
        }
    }
    new ReminderHelper((OpacClient) getApplication()).generateAlarms();
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) ReminderHelper(de.geeksfactory.opacclient.reminder.ReminderHelper) OpacClient(de.geeksfactory.opacclient.OpacClient)

Aggregations

AccountDataSource (de.geeksfactory.opacclient.storage.AccountDataSource)23 Intent (android.content.Intent)10 OpacClient (de.geeksfactory.opacclient.OpacClient)8 OnClickListener (android.view.View.OnClickListener)7 Account (de.geeksfactory.opacclient.objects.Account)7 View (android.view.View)6 ImageView (android.widget.ImageView)6 ListView (android.widget.ListView)6 TextView (android.widget.TextView)6 SuppressLint (android.annotation.SuppressLint)5 DialogInterface (android.content.DialogInterface)5 AlertDialog (android.support.v7.app.AlertDialog)5 RecyclerView (android.support.v7.widget.RecyclerView)4 ReminderHelper (de.geeksfactory.opacclient.reminder.ReminderHelper)4 SharedPreferences (android.content.SharedPreferences)3 LayoutInflater (android.view.LayoutInflater)3 AdapterView (android.widget.AdapterView)3 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)3 PendingIntent (android.app.PendingIntent)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2