Browse Source

Allow retry of failed uploads of accounts different than the current one

David A. Velasco 9 years ago
parent
commit
e78bf9179b

+ 0 - 9
src/com/owncloud/android/files/FileOperationsHelper.java

@@ -527,15 +527,6 @@ public class FileOperationsHelper {
                 getString(R.string.wait_a_moment));
     }
 
-    /**
-     * Retry uploading a failed or cancelled upload with force.
-     */
-    public void retryUpload(OCUpload upload) {
-        Account account = mFileActivity.getAccount();
-        FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
-        requester.retry(mFileActivity, account, upload);
-    }
-
     /**
      * Cancel the transference in downloads (files/folders) and file uploads
      * @param file OCFile

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

@@ -225,14 +225,14 @@ public class FileUploader extends Service
                 behaviour, String mimeType, boolean createRemoteFile, int createdBy) {
 
             uploadNewFile(
-                    context,
-                    account,
-                    new String[]{localPath},
-                    new String[]{remotePath},
-                    new String[]{mimeType},
-                    behaviour,
-                    createRemoteFile,
-                    createdBy
+                context,
+                account,
+                new String[]{localPath},
+                new String[]{remotePath},
+                new String[]{mimeType},
+                behaviour,
+                createRemoteFile,
+                createdBy
             );
         }
 
@@ -264,16 +264,20 @@ public class FileUploader extends Service
         /**
          * Call to retry upload identified by remotePath
          */
-        public void retry(Context context, Account account, OCUpload upload) {
-            if (upload != null) {
-                Intent i = new Intent(context, FileUploader.class);
-                i.putExtra(FileUploader.KEY_RETRY, true);
-                i.putExtra(FileUploader.KEY_ACCOUNT, account);
-                i.putExtra(FileUploader.KEY_RETRY_UPLOAD, upload);
-                context.startService(i);
+        public void retry (Context context, OCUpload upload) {
+            if (upload != null && context != null) {
+                Account account = AccountUtils.getOwnCloudAccountByName(
+                    context,
+                    upload.getAccountName()
+                );
+                retry(context, account, upload);
+
+            } else {
+                throw new IllegalArgumentException("Null parameter!");
             }
         }
 
+
         /**
          * Retry a subset of all the stored failed uploads.
          *
@@ -301,6 +305,23 @@ public class FileUploader extends Service
             }
         }
 
+        /**
+         * Private implementation of retry.
+         *
+         * @param context
+         * @param account
+         * @param upload
+         */
+        private void retry(Context context, Account account, OCUpload upload) {
+            if (upload != null) {
+                Intent i = new Intent(context, FileUploader.class);
+                i.putExtra(FileUploader.KEY_RETRY, true);
+                i.putExtra(FileUploader.KEY_ACCOUNT, account);
+                i.putExtra(FileUploader.KEY_RETRY_UPLOAD, upload);
+                context.startService(i);
+            }
+        }
+
     }
 
 

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

@@ -398,9 +398,11 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                     @Override
                     public void onClick(View v) {
                         File file = new File(upload.getLocalPath());
-                        if (file.exists())
-                            mParentActivity.getFileOperationsHelper().retryUpload(upload);
-                        else {
+                        if (file.exists()) {
+                            FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
+                            requester.retry(mParentActivity, upload);
+                            refreshView();
+                        } else {
                             final String message = String.format(mParentActivity.getString(R.string.local_file_not_found_toast));
                             Toast.makeText(mParentActivity, message, Toast.LENGTH_SHORT).show();
                         }

+ 0 - 138
src/com/owncloud/android/ui/adapter/MyExpandableListAdapter.java

@@ -1,138 +0,0 @@
-/**
- *   ownCloud Android client application
- *
- *   Copyright (C) 2015  ownCloud Inc.
- *
- *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License version 2,
- *   as published by the Free Software Foundation.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-package com.owncloud.android.ui.adapter;
-
-import android.app.Activity;
-import android.util.SparseArray;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.widget.BaseExpandableListAdapter;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import com.owncloud.android.R;
-
-public class MyExpandableListAdapter extends BaseExpandableListAdapter {
-
-    private final SparseArray<GroupAdapter> groups;
-    public LayoutInflater inflater;
-    public Activity activity;
-
-    public MyExpandableListAdapter(Activity act, SparseArray<GroupAdapter> groups) {
-        activity = act;
-        this.groups = groups;
-        inflater = act.getLayoutInflater();
-
-    }
-
-
-    @Override
-    public Object getChild(int groupPosition, int childPosition) {
-        return groups.get(groupPosition).children.get(childPosition);
-    }
-
-    @Override
-    public long getChildId(int groupPosition, int childPosition) {
-        return 0;
-    }
-
-    @Override
-    public View getChildView(int groupPosition, final int childPosition,
-                             boolean isLastChild, View convertView, ViewGroup parent) {
-        final String children = (String) getChild(groupPosition, childPosition);
-        TextView text = null;
-        if (convertView == null) {
-            convertView = inflater.inflate(R.layout.listrow_details, null);
-        }
-
-
-        text = (TextView) convertView.findViewById(R.id.textView1);
-        text.setText(children);
-        convertView.setOnClickListener(new OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                Toast.makeText(activity, children, Toast.LENGTH_SHORT).show();
-            }
-        });
-        return convertView;
-    }
-
-    @Override
-    public View getGroupView(int groupPosition, boolean isExpanded,
-                             View convertView, ViewGroup parent) {
-        if (convertView == null) {
-            convertView = inflater.inflate(R.layout.listrow_group, null);
-        }
-
-        final GroupAdapter groupAdapter = (GroupAdapter) getGroup(groupPosition);
-        if (groupAdapter.children.size() == 0){
-            convertView.setOnClickListener(new OnClickListener() {
-                @Override
-                public void onClick(View v) {
-                    Toast.makeText(activity, groupAdapter.string, Toast.LENGTH_SHORT).show();
-                }
-            });
-        }
-        ((TextView) convertView).setText(groupAdapter.string);
-
-        return convertView;
-    }
-
-    @Override
-    public int getChildrenCount(int groupPosition) {
-        return groups.get(groupPosition).children.size();
-    }
-
-    @Override
-    public Object getGroup(int groupPosition) {
-        return groups.get(groupPosition);
-    }
-
-    @Override
-    public int getGroupCount() {
-        return groups.size();
-    }
-
-    @Override
-    public void onGroupCollapsed(int groupPosition) {
-        super.onGroupCollapsed(groupPosition);
-    }
-
-    @Override
-    public void onGroupExpanded(int groupPosition) {
-        super.onGroupExpanded(groupPosition);
-    }
-
-    @Override
-    public long getGroupId(int groupPosition) {
-        return 0;
-    }
-
-    @Override
-    public boolean hasStableIds() {
-        return false;
-    }
-
-    @Override
-    public boolean isChildSelectable(int groupPosition, int childPosition) {
-        return false;
-    }
-}