Prechádzať zdrojové kódy

extracted string value
first try to get uploadStorageManager show job

tobiasKaminsky 8 rokov pred
rodič
commit
96777a7d36

+ 31 - 2
src/com/owncloud/android/datamodel/UploadsStorageManager.java

@@ -20,10 +20,14 @@
  */
  */
 package com.owncloud.android.datamodel;
 package com.owncloud.android.datamodel;
 
 
+import android.app.job.JobInfo;
+import android.app.job.JobScheduler;
 import android.content.ContentResolver;
 import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.ContentValues;
+import android.content.Context;
 import android.database.Cursor;
 import android.database.Cursor;
 import android.net.Uri;
 import android.net.Uri;
+import android.os.PersistableBundle;
 
 
 import com.owncloud.android.db.OCUpload;
 import com.owncloud.android.db.OCUpload;
 import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
 import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
@@ -33,7 +37,9 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.operations.UploadFileOperation;
 import com.owncloud.android.operations.UploadFileOperation;
 
 
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Calendar;
+import java.util.List;
 import java.util.Observable;
 import java.util.Observable;
 
 
 /**
 /**
@@ -43,6 +49,7 @@ import java.util.Observable;
 public class UploadsStorageManager extends Observable {
 public class UploadsStorageManager extends Observable {
 
 
     private ContentResolver mContentResolver;
     private ContentResolver mContentResolver;
+    private Context mContext;
     private static final String AND = " AND ";
     private static final String AND = " AND ";
 
 
     static private final String TAG = UploadsStorageManager.class.getSimpleName();
     static private final String TAG = UploadsStorageManager.class.getSimpleName();
@@ -89,11 +96,12 @@ public class UploadsStorageManager extends Observable {
 
 
     }
     }
 
 
-    public UploadsStorageManager(ContentResolver contentResolver) {
+    public UploadsStorageManager(ContentResolver contentResolver, Context context) {
         if (contentResolver == null) {
         if (contentResolver == null) {
             throw new IllegalArgumentException("Cannot create an instance with a NULL contentResolver");
             throw new IllegalArgumentException("Cannot create an instance with a NULL contentResolver");
         }
         }
         mContentResolver = contentResolver;
         mContentResolver = contentResolver;
+        mContext = context;
     }
     }
 
 
     /**
     /**
@@ -364,12 +372,33 @@ public class UploadsStorageManager extends Observable {
      * Get all uploads which are currently being uploaded or waiting in the queue to be uploaded.
      * Get all uploads which are currently being uploaded or waiting in the queue to be uploaded.
      */
      */
     public OCUpload[] getCurrentAndPendingUploads() {
     public OCUpload[] getCurrentAndPendingUploads() {
-        return getUploads(
+
+        OCUpload[] uploads = getUploads(
             ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_IN_PROGRESS.value + " OR " +
             ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_IN_PROGRESS.value + " OR " +
             ProviderTableMeta.UPLOADS_LAST_RESULT + "==" + UploadResult.DELAYED_FOR_WIFI.getValue() + " OR " +
             ProviderTableMeta.UPLOADS_LAST_RESULT + "==" + UploadResult.DELAYED_FOR_WIFI.getValue() + " OR " +
             ProviderTableMeta.UPLOADS_LAST_RESULT + "==" + UploadResult.DELAYED_FOR_CHARGING.getValue(),
             ProviderTableMeta.UPLOADS_LAST_RESULT + "==" + UploadResult.DELAYED_FOR_CHARGING.getValue(),
             null
             null
         );
         );
+
+        // add pending Jobs
+        return getPendingJobs().toArray(uploads);
+    }
+
+    private List<OCUpload> getPendingJobs() {
+        JobScheduler js = (JobScheduler) mContext.getSystemService(Context.JOB_SCHEDULER_SERVICE);
+
+        ArrayList<OCUpload> list = new ArrayList<>();
+
+        for (JobInfo ji: js.getAllPendingJobs()) {
+            PersistableBundle extras = ji.getExtras();
+            OCUpload upload  = new OCUpload(extras.getString("filePath"),
+                    extras.getString("remotePath"),
+                    extras.getString("account"));
+
+            list.add(upload);
+        }
+
+        return list;
     }
     }
 
 
     /**
     /**

+ 2 - 2
src/com/owncloud/android/files/services/FileUploader.java

@@ -294,7 +294,7 @@ public class FileUploader extends Service
          *                          otherwise, failed uploads due to any result will be retried.
          *                          otherwise, failed uploads due to any result will be retried.
          */
          */
         public void retryFailedUploads(Context context, Account account, UploadResult uploadResult) {
         public void retryFailedUploads(Context context, Account account, UploadResult uploadResult) {
-            UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver());
+            UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver(), context);
             OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
             OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
             Account currentAccount = null;
             Account currentAccount = null;
             boolean resultMatch, accountMatch;
             boolean resultMatch, accountMatch;
@@ -346,7 +346,7 @@ public class FileUploader extends Service
         mServiceHandler = new ServiceHandler(mServiceLooper, this);
         mServiceHandler = new ServiceHandler(mServiceLooper, this);
         mBinder = new FileUploaderBinder();
         mBinder = new FileUploaderBinder();
 
 
-        mUploadsStorageManager = new UploadsStorageManager(getContentResolver());
+        mUploadsStorageManager = new UploadsStorageManager(getContentResolver(), getApplicationContext());
 
 
         int failedCounter = mUploadsStorageManager.failInProgressUploads(
         int failedCounter = mUploadsStorageManager.failInProgressUploads(
             UploadResult.SERVICE_INTERRUPTED    // Add UploadResult.KILLED?
             UploadResult.SERVICE_INTERRUPTED    // Add UploadResult.KILLED?

+ 13 - 6
src/com/owncloud/android/services/SyncedFolderJobService.java

@@ -44,6 +44,13 @@ import java.io.File;
 public class SyncedFolderJobService extends JobService {
 public class SyncedFolderJobService extends JobService {
     private static final String TAG = "SyncedFolderJobService";
     private static final String TAG = "SyncedFolderJobService";
 
 
+    public static final String LOCAL_PATH = "filePath";
+    public static final String REMOTE_PATH = "remotePath";
+    public static final String DATE_TAKEN = "dateTaken";
+    public static final String SUBFOLDER_BY_DATE = "subfolderByDate";
+    public static final String ACCOUNT = "account";
+    public static final String UPLOAD_BEHAVIOUR = "uploadBehaviour";
+
     @Override
     @Override
     public int onStartCommand(Intent intent, int flags, int startId) {
     public int onStartCommand(Intent intent, int flags, int startId) {
         return START_REDELIVER_INTENT;
         return START_REDELIVER_INTENT;
@@ -53,12 +60,12 @@ public class SyncedFolderJobService extends JobService {
     public boolean onStartJob(JobParameters params) {
     public boolean onStartJob(JobParameters params) {
         Context context = MainApp.getAppContext();
         Context context = MainApp.getAppContext();
         PersistableBundle bundle = params.getExtras();
         PersistableBundle bundle = params.getExtras();
-        String filePath = bundle.getString("filePath");
-        String remoteFolder = bundle.getString("remotePath");
-        Long dateTaken = bundle.getLong("dateTaken");
-        Boolean subfolderByDate = bundle.getInt("subfolderByDate") == 1;
-        Account account = AccountUtils.getOwnCloudAccountByName(context, bundle.getString("account"));
-        Integer uploadBehaviour = bundle.getInt("uploadBehaviour");
+        String filePath = bundle.getString(LOCAL_PATH);
+        String remoteFolder = bundle.getString(REMOTE_PATH);
+        Long dateTaken = bundle.getLong(DATE_TAKEN);
+        Boolean subfolderByDate = bundle.getInt(SUBFOLDER_BY_DATE) == 1;
+        Account account = AccountUtils.getOwnCloudAccountByName(context, bundle.getString(ACCOUNT));
+        Integer uploadBehaviour = bundle.getInt(UPLOAD_BEHAVIOUR);
 
 
         Log_OC.d(TAG, "startJob: " + params.getJobId() + ", filePath: " + filePath);
         Log_OC.d(TAG, "startJob: " + params.getJobId() + ", filePath: " + filePath);
 
 

+ 6 - 6
src/com/owncloud/android/services/observer/SyncedFolderObserver.java

@@ -46,12 +46,12 @@ class SyncedFolderObserver extends RecursiveFileObserver {
         if (!temp.getName().equalsIgnoreCase("null")) {
         if (!temp.getName().equalsIgnoreCase("null")) {
             PersistableBundle bundle = new PersistableBundle();
             PersistableBundle bundle = new PersistableBundle();
             // TODO extract
             // TODO extract
-            bundle.putString("filePath", path);
-            bundle.putString("remotePath", syncedFolder.getRemotePath());
-            bundle.putLong("dateTaken", new Date().getTime());
-            bundle.putString("account", syncedFolder.getAccount());
-            bundle.putInt("uploadBehaviour", syncedFolder.getUploadAction());
-            bundle.putInt("subfolderByDate", syncedFolder.getSubfolderByDate() ? 1 : 0);
+            bundle.putString(SyncedFolderJobService.LOCAL_PATH, path);
+            bundle.putString(SyncedFolderJobService.REMOTE_PATH, syncedFolder.getRemotePath());
+            bundle.putLong(SyncedFolderJobService.DATE_TAKEN, new Date().getTime());
+            bundle.putString(SyncedFolderJobService.ACCOUNT, syncedFolder.getAccount());
+            bundle.putInt(SyncedFolderJobService.UPLOAD_BEHAVIOUR, syncedFolder.getUploadAction());
+            bundle.putInt(SyncedFolderJobService.SUBFOLDER_BY_DATE, syncedFolder.getSubfolderByDate() ? 1 : 0);
 
 
             JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
             JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
 
 

+ 3 - 3
src/com/owncloud/android/ui/activity/UploadListActivity.java

@@ -202,19 +202,19 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
                 break;
                 break;
 
 
             case R.id.action_clear_failed_uploads:
             case R.id.action_clear_failed_uploads:
-                storageManager = new UploadsStorageManager(getContentResolver());
+                storageManager = new UploadsStorageManager(getContentResolver(), getApplicationContext());
                 storageManager.clearFailedButNotDelayedUploads();
                 storageManager.clearFailedButNotDelayedUploads();
                 uploadListFragment.updateUploads();
                 uploadListFragment.updateUploads();
                 break;
                 break;
 
 
             case R.id.action_clear_successfull_uploads:
             case R.id.action_clear_successfull_uploads:
-                storageManager = new UploadsStorageManager(getContentResolver());
+                storageManager = new UploadsStorageManager(getContentResolver(), getApplicationContext());
                 storageManager.clearSuccessfulUploads();
                 storageManager.clearSuccessfulUploads();
                 uploadListFragment.updateUploads();
                 uploadListFragment.updateUploads();
                 break;
                 break;
 
 
             case R.id.action_clear_finished_uploads:
             case R.id.action_clear_finished_uploads:
-                storageManager = new UploadsStorageManager(getContentResolver());
+                storageManager = new UploadsStorageManager(getContentResolver(), getApplicationContext());
                 storageManager.clearAllFinishedButNotDelayedUploads();
                 storageManager.clearAllFinishedButNotDelayedUploads();
                 uploadListFragment.updateUploads();
                 uploadListFragment.updateUploads();
                 break;
                 break;

+ 1 - 1
src/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java

@@ -136,7 +136,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
     public ExpandableUploadListAdapter(FileActivity parentActivity) {
     public ExpandableUploadListAdapter(FileActivity parentActivity) {
         Log_OC.d(TAG, "ExpandableUploadListAdapter");
         Log_OC.d(TAG, "ExpandableUploadListAdapter");
         mParentActivity = parentActivity;
         mParentActivity = parentActivity;
-        mUploadsStorageManager = new UploadsStorageManager(mParentActivity.getContentResolver());
+        mUploadsStorageManager = new UploadsStorageManager(mParentActivity.getContentResolver(), parentActivity.getApplicationContext());
         mUploadGroups = new UploadGroup[3];
         mUploadGroups = new UploadGroup[3];
         mUploadGroups[0] = new UploadGroup(mParentActivity.getString(R.string.uploads_view_group_current_uploads)) {
         mUploadGroups[0] = new UploadGroup(mParentActivity.getString(R.string.uploads_view_group_current_uploads)) {
             @Override
             @Override