Search in sources :

Example 11 with UploadsStorageManager

use of com.owncloud.android.datamodel.UploadsStorageManager in project android by owncloud.

the class FileUploader method onCreate.

/**
 * Service initialization
 */
@Override
public void onCreate() {
    super.onCreate();
    Timber.d("Creating service");
    mNotificationBuilder = NotificationUtils.newNotificationBuilder(this, UPLOAD_NOTIFICATION_CHANNEL_ID);
    HandlerThread thread = new HandlerThread("FileUploaderThread", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    mBinder = new FileUploaderBinder();
    mUploadsStorageManager = new UploadsStorageManager(getContentResolver());
    int failedCounter = mUploadsStorageManager.failInProgressUploads(// Add UploadResult.KILLED?
    UploadResult.SERVICE_INTERRUPTED);
    if (failedCounter > 0) {
        resurrection();
    }
    // add AccountsUpdatedListener
    AccountManager am = AccountManager.get(getApplicationContext());
    am.addOnAccountsUpdatedListener(this, null, false);
    // create manager for local broadcasts
    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
}
Also used : HandlerThread(android.os.HandlerThread) UploadsStorageManager(com.owncloud.android.datamodel.UploadsStorageManager) AccountManager(android.accounts.AccountManager)

Example 12 with UploadsStorageManager

use of com.owncloud.android.datamodel.UploadsStorageManager in project android by owncloud.

the class TransferRequester method getRequiredNetworkType.

/**
 * Retrieve the type of network connection required to schedule the last upload for an account
 *
 * @param context
 * @param accountName
 * @param remotePath  to upload the file
 * @return 2 if only wifi is required, 1 if any internet connection is required (wifi or cellular)
 */
private int getRequiredNetworkType(Context context, String accountName, String remotePath) {
    UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver());
    // Get last upload to be retried
    OCUpload ocUpload = uploadsStorageManager.getLastUploadFor(new OCFile(remotePath), accountName);
    // Wifi by default
    int networkType = JobInfo.NETWORK_TYPE_UNMETERED;
    return networkType;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.datamodel.OCUpload) UploadsStorageManager(com.owncloud.android.datamodel.UploadsStorageManager)

Aggregations

UploadsStorageManager (com.owncloud.android.datamodel.UploadsStorageManager)12 OCUpload (com.owncloud.android.datamodel.OCUpload)4 Account (android.accounts.Account)3 OCFile (com.owncloud.android.datamodel.OCFile)3 AccountManager (android.accounts.AccountManager)2 Context (android.content.Context)2 UserAccountManager (com.nextcloud.client.account.UserAccountManager)2 BatteryStatus (com.nextcloud.client.device.BatteryStatus)2 PowerManagementService (com.nextcloud.client.device.PowerManagementService)2 ConnectivityService (com.nextcloud.client.network.ConnectivityService)2 FileUploader (com.owncloud.android.files.services.FileUploader)2 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)2 UploadFileOperation (com.owncloud.android.operations.UploadFileOperation)2 File (java.io.File)2 HandlerThread (android.os.HandlerThread)1 NonNull (android.support.annotation.NonNull)1 BottomNavigationView (android.support.design.widget.BottomNavigationView)1 PersistableBundleCompat (com.evernote.android.job.util.support.PersistableBundleCompat)1 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)1 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)1