Search in sources :

Example 11 with PersistableBundleCompat

use of com.evernote.android.job.util.support.PersistableBundleCompat in project cw-omnibus by commonsguy.

the class MainActivity method manageUnified.

private void manageUnified(boolean start) {
    if (start) {
        final JobRequest.Builder b = new JobRequest.Builder(DemoUnifiedJob.JOB_TAG);
        PersistableBundleCompat extras = new PersistableBundleCompat();
        if (download.isChecked()) {
            extras.putBoolean(KEY_DOWNLOAD, true);
            b.setExtras(extras).setRequiredNetworkType(JobRequest.NetworkType.CONNECTED);
        } else {
            b.setRequiredNetworkType(JobRequest.NetworkType.ANY);
        }
        b.setPeriodic(getPeriod()).setPersisted(false).setRequiresCharging(false).setRequiresDeviceIdle(true);
        unifiedJobId = b.build().schedule();
    } else {
        JobManager.instance().cancel(unifiedJobId);
    }
}
Also used : JobRequest(com.evernote.android.job.JobRequest) PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat)

Example 12 with PersistableBundleCompat

use of com.evernote.android.job.util.support.PersistableBundleCompat in project android by nextcloud.

the class ContactsPreferenceActivity method cancelPreviousContactBackupJobForAccount.

public static void cancelPreviousContactBackupJobForAccount(Context context, Account account) {
    Log_OC.d(TAG, "disabling existing contacts backup job for account: " + account.name);
    JobManager jobManager = JobManager.create(context);
    Set<JobRequest> jobs = jobManager.getAllJobRequestsForTag(ContactsBackupJob.TAG);
    for (JobRequest jobRequest : jobs) {
        PersistableBundleCompat extras = jobRequest.getExtras();
        if (extras.getString(ContactsBackupJob.ACCOUNT, "").equalsIgnoreCase(account.name) && jobRequest.isPeriodic()) {
            jobManager.cancel(jobRequest.getJobId());
        }
    }
}
Also used : JobRequest(com.evernote.android.job.JobRequest) PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat) JobManager(com.evernote.android.job.JobManager)

Example 13 with PersistableBundleCompat

use of com.evernote.android.job.util.support.PersistableBundleCompat in project android by nextcloud.

the class ContactsPreferenceActivity method startContactBackupJob.

public static void startContactBackupJob(Account account) {
    Log_OC.d(TAG, "start daily contacts backup job");
    PersistableBundleCompat bundle = new PersistableBundleCompat();
    bundle.putString(ContactsBackupJob.ACCOUNT, account.name);
    cancelPreviousContactBackupJobForAccount(MainApp.getAppContext(), account);
    new JobRequest.Builder(ContactsBackupJob.TAG).setExtras(bundle).setPeriodic(24 * 60 * 60 * 1000).build().schedule();
}
Also used : PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat)

Example 14 with PersistableBundleCompat

use of com.evernote.android.job.util.support.PersistableBundleCompat in project android by nextcloud.

the class ManageAccountsActivity method performAccountRemoval.

private void performAccountRemoval(Account account) {
    // disable account in list view
    for (int i = 0; i < mAccountListAdapter.getCount(); i++) {
        AccountListItem item = mAccountListAdapter.getItem(i);
        if (item != null && item.getAccount().equals(account)) {
            item.setEnabled(false);
            break;
        }
        mAccountListAdapter.notifyDataSetChanged();
    }
    // store pending account removal
    ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
    arbitraryDataProvider.storeOrUpdateKeyValue(account.name, PENDING_FOR_REMOVAL, String.valueOf(true));
    // Cancel transfers
    if (mUploaderBinder != null) {
        mUploaderBinder.cancel(account);
    }
    if (mDownloaderBinder != null) {
        mDownloaderBinder.cancel(account);
    }
    // schedule job
    PersistableBundleCompat bundle = new PersistableBundleCompat();
    bundle.putString(AccountRemovalJob.ACCOUNT, account.name);
    new JobRequest.Builder(AccountRemovalJob.TAG).startNow().setExtras(bundle).setUpdateCurrent(false).build().schedule();
    // immediately select a new account
    Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
    String newAccountName = "";
    for (Account acc : accounts) {
        if (!account.name.equalsIgnoreCase(acc.name)) {
            newAccountName = acc.name;
            break;
        }
    }
    if (newAccountName.isEmpty()) {
        Log_OC.d(TAG, "new account set to null");
        AccountUtils.resetOwnCloudAccount(this);
    } else {
        Log_OC.d(TAG, "new account set to: " + newAccountName);
        AccountUtils.setCurrentOwnCloudAccount(this, newAccountName);
    }
    // only one to be (deleted) account remaining
    if (accounts.length < 2) {
        Intent resultIntent = new Intent();
        resultIntent.putExtra(KEY_ACCOUNT_LIST_CHANGED, true);
        resultIntent.putExtra(KEY_CURRENT_ACCOUNT_CHANGED, true);
        setResult(RESULT_OK, resultIntent);
        super.onBackPressed();
    }
}
Also used : AccountListItem(com.owncloud.android.ui.adapter.AccountListItem) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat) JobRequest(com.evernote.android.job.JobRequest) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Intent(android.content.Intent)

Example 15 with PersistableBundleCompat

use of com.evernote.android.job.util.support.PersistableBundleCompat in project android by nextcloud.

the class ContactListAdapter method importContacts.

private void importContacts(ContactAccount account) {
    PersistableBundleCompat bundle = new PersistableBundleCompat();
    bundle.putString(ContactsImportJob.ACCOUNT_NAME, account.name);
    bundle.putString(ContactsImportJob.ACCOUNT_TYPE, account.type);
    bundle.putString(ContactsImportJob.VCARD_FILE_PATH, getFile().getStoragePath());
    bundle.putIntArray(ContactsImportJob.CHECKED_ITEMS_ARRAY, contactListAdapter.getCheckedIntArray());
    new JobRequest.Builder(ContactsImportJob.TAG).setExtras(bundle).startNow().setRequiresCharging(false).setUpdateCurrent(false).build().schedule();
    Snackbar.make(recyclerView, R.string.contacts_preferences_import_scheduled, Snackbar.LENGTH_LONG).show();
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            if (getFragmentManager().getBackStackEntryCount() > 0) {
                getFragmentManager().popBackStack();
            } else {
                getActivity().finish();
            }
        }
    }, 1750);
}
Also used : PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat) Handler(android.os.Handler)

Aggregations

PersistableBundleCompat (com.evernote.android.job.util.support.PersistableBundleCompat)25 JobRequest (com.evernote.android.job.JobRequest)11 NonNull (android.support.annotation.NonNull)7 Context (android.content.Context)5 Account (android.accounts.Account)4 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)4 Test (org.junit.Test)4 Intent (android.content.Intent)3 File (java.io.File)3 Bundle (android.os.Bundle)2 Handler (android.os.Handler)2 LargeTest (android.support.test.filters.LargeTest)2 SmallTest (android.support.test.filters.SmallTest)2 FilesystemDataProvider (com.owncloud.android.datamodel.FilesystemDataProvider)2 SyncedFolder (com.owncloud.android.datamodel.SyncedFolder)2 SyncedFolderProvider (com.owncloud.android.datamodel.SyncedFolderProvider)2 FileUploader (com.owncloud.android.files.services.FileUploader)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 PrivateKey (java.security.PrivateKey)2