Browse Source

Update progress bar for Current Upload

masensio 9 years ago
parent
commit
6f58527273

+ 2 - 2
res/layout/upload_list_layout.xml

@@ -6,14 +6,14 @@
 
 
     <fragment
-        android:id="@+id/UploadListFragment"
+        android:id="@+id/upload_list_fragment"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:paddingLeft="25dp"
         android:paddingRight="25dp"
         android:layout_marginLeft="10dp"
         android:layout_marginRight="10dp"
-        class="com.owncloud.android.ui.fragment.UploadListFragment" />
+        class="com.owncloud.android.ui.fragment.UploadListFragment"/>
 
     <include
         layout="@layout/drawer"

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

@@ -1328,6 +1328,8 @@ public class FileUploadService extends Service implements OnDatatransferProgress
 //                DbHandler db = new DbHandler(this.getBaseContext());
 //                db.removeIUPendingFile(mCurrentUpload.getOriginalStoragePath());
 //                db.close();
+                mPendingUploads.remove(upload.getAccount(), upload.getFile().getRemotePath());
+                updateDatabaseUploadResult(uploadResult, mCurrentUpload);
                 // remove success notification, with a delay of 2 seconds
                 NotificationDelayer.cancelWithDelay(mNotificationManager, R.string.uploader_upload_succeeded_ticker,
                         2000);

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

@@ -19,6 +19,7 @@
  */
 package com.owncloud.android.ui.activity;
 
+import android.app.FragmentManager;
 import android.content.ActivityNotFoundException;
 import android.content.ComponentName;
 import android.content.Intent;
@@ -26,6 +27,8 @@ import android.content.ServiceConnection;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.IBinder;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
 import android.support.v4.view.GravityCompat;
 import android.view.Menu;
 import android.view.MenuInflater;
@@ -39,6 +42,7 @@ import com.owncloud.android.db.OCUpload;
 import com.owncloud.android.files.services.FileUploadService;
 import com.owncloud.android.files.services.FileUploadService.FileUploaderBinder;
 import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.ui.fragment.OCFileListFragment;
 import com.owncloud.android.ui.fragment.UploadListFragment;
 import com.owncloud.android.ui.preview.PreviewImageActivity;
 
@@ -54,6 +58,8 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
 
     private static final String TAG = UploadListActivity.class.getSimpleName();
 
+    private static final String TAG_UPLOAD_LIST_FRAGMENT = "UPLOAD_LIST_FRAGMENT";
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -61,6 +67,9 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
         //Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
         setContentView(R.layout.upload_list_layout);
 
+        // Add fragment with a transaction for setting a tag
+        createUploadListFragment();
+
         // Navigation Drawer
         initDrawer();
 
@@ -71,6 +80,13 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
 
     }
 
+    private void createUploadListFragment(){
+        UploadListFragment uploadList = new UploadListFragment();
+        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+        transaction.add(R.id.upload_list_fragment, uploadList, TAG_UPLOAD_LIST_FRAGMENT);
+        transaction.commit();
+    }
+
     // ////////////////////////////////////////
     // UploadListFragment.ContainerActivity
     // ////////////////////////////////////////
@@ -194,6 +210,12 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
                     Log_OC.d(TAG, "UploadListActivity connected to Upload service. component: " +
                             component + " service: "
                             + service);
+                    // Say to UploadListFragment that the Binder is READY in the Activity
+                    UploadListFragment uploadListFragment =
+                            (UploadListFragment) getSupportFragmentManager().findFragmentByTag(TAG_UPLOAD_LIST_FRAGMENT);
+                    if (uploadListFragment != null) {
+                        uploadListFragment.binderReady();
+                    }
                 } else {
                     Log_OC.d(TAG, "mUploaderBinder already set. mUploaderBinder: " +
                             mUploaderBinder + " service:" + service);
@@ -214,8 +236,4 @@ public class UploadListActivity extends FileActivity implements UploadListFragme
         }
     };
 
-    public void addBinderToItem(){
-
-    }
-
 }

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

@@ -19,12 +19,6 @@
  */
 package com.owncloud.android.ui.adapter;
 
-import java.lang.ref.WeakReference;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Observable;
-import java.util.Observer;
-
 import android.content.Context;
 import android.database.DataSetObserver;
 import android.graphics.Bitmap;
@@ -53,6 +47,12 @@ import com.owncloud.android.operations.UploadFileOperation;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.utils.DisplayUtils;
 
+import java.lang.ref.WeakReference;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Observable;
+import java.util.Observer;
+
 /**
  * This Adapter populates a ListView with following types of uploads: pending,
  * active, completed. Filtering possible.
@@ -66,7 +66,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
     private UploadsStorageManager mUploadsStorageManager;
     
     public ProgressListener mProgressListener; 
-    UploadFileOperation mCurrentUpload;
+    private UploadFileOperation mCurrentUpload;
     
     interface Refresh {
         public void refresh();
@@ -165,6 +165,9 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                     );
             view = inflator.inflate(R.layout.upload_list_item, null);
         }
+
+        view.invalidate();
+
         if (uploadsItems != null && uploadsItems.length > position) {
             final OCUpload upload = uploadsItems[position];
 
@@ -321,7 +324,6 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
         return false;
     }
 
-    
 
     /**
      * Load upload items from {@link UploadsStorageManager}.
@@ -407,12 +409,11 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
         listView.expandGroup(groupPosition);
         
         listView.setGroupIndicator(null);
-        
         UploadGroup group = (UploadGroup) getGroup(groupPosition);
         if (convertView == null) {
-            LayoutInflater infalInflater = (LayoutInflater) mParentActivity
+            LayoutInflater inflaInflater = (LayoutInflater) mParentActivity
                     .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-            convertView = infalInflater.inflate(R.layout.upload_list_group, null);
+            convertView = inflaInflater.inflate(R.layout.upload_list_group, null);
         }
         TextView tv = (TextView) convertView.findViewById(R.id.uploadListGroupName);
         tv.setText(group.getGroupName());
@@ -426,7 +427,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
         return true;
     }
     
-    private class ProgressListener implements OnDatatransferProgressListener {
+    public class ProgressListener implements OnDatatransferProgressListener {
         int mLastPercent = 0;
         WeakReference<ProgressBar> mProgressBar = null;
         
@@ -447,5 +448,9 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
             mLastPercent = percent;
         }
 
-    }; 
+    };
+
+    public void addBinder(){
+        notifyDataSetChanged();
+    }
 }

+ 0 - 3
src/com/owncloud/android/ui/fragment/ExpandableListFragment.java

@@ -20,12 +20,9 @@ package com.owncloud.android.ui.fragment;
 
 import android.os.Bundle;
 import android.support.v4.widget.SwipeRefreshLayout;
-import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemLongClickListener;
 import android.widget.ExpandableListAdapter;
 import android.widget.ExpandableListView;
 import android.widget.ExpandableListView.OnChildClickListener;

+ 2 - 2
src/com/owncloud/android/ui/fragment/ExtendedListFragment.java

@@ -20,8 +20,6 @@
 
 package com.owncloud.android.ui.fragment;
 
-import java.util.ArrayList;
-
 import android.os.Build;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
@@ -43,6 +41,8 @@ import com.owncloud.android.ui.ExtendedListView;
 import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
 import com.owncloud.android.ui.adapter.FileListListAdapter;
 
+import java.util.ArrayList;
+
 import third_parties.in.srain.cube.GridViewWithHeaderAndFooter;
 
 public class ExtendedListFragment extends Fragment

+ 31 - 5
src/com/owncloud/android/ui/fragment/UploadListFragment.java

@@ -22,7 +22,6 @@ package com.owncloud.android.ui.fragment;
 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
-import android.os.Parcelable;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.LayoutInflater;
@@ -54,7 +53,18 @@ public class UploadListFragment extends ExpandableListFragment {
      */
     private UploadListFragment.ContainerActivity mContainerActivity;
 
-    ExpandableUploadListAdapter mAdapter;
+    private ExpandableUploadListAdapter mAdapter;
+
+    /** Is binder ready in the Activity? */
+    private boolean mBinderReady = false;
+
+    public void setBinderReady(boolean ready) {
+        mBinderReady = ready;
+    }
+    public boolean isBinderReady(){
+        return mBinderReady;
+    }
+
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -85,14 +95,22 @@ public class UploadListFragment extends ExpandableListFragment {
     public void onActivityCreated(Bundle savedInstanceState) {
         Log_OC.d(TAG, "onActivityCreated() start");
         super.onActivityCreated(savedInstanceState);
-        mAdapter = new ExpandableUploadListAdapter((FileActivity)getActivity());
-        setListAdapter(mAdapter);
+//        mAdapter = new ExpandableUploadListAdapter((FileActivity)getActivity());
+//        setListAdapter(mAdapter);
         //mAdapter.setFileActivity(((FileActivity) getActivity()));
         
         registerForContextMenu(getListView());
         getListView().setOnCreateContextMenuListener(this);
     }
 
+    @Override
+    public void onStart() {
+        Log_OC.d(TAG, "onStart() start");
+        super.onStart();
+        mAdapter = new ExpandableUploadListAdapter((FileActivity)getActivity());
+        setListAdapter(mAdapter);
+    }
+
     @Override
     public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
         boolean handled = false;
@@ -156,7 +174,7 @@ public class UploadListFragment extends ExpandableListFragment {
 //            return true;
         }case R.id.action_see_details: {
             Intent showDetailsIntent = new Intent(getActivity(), FileDisplayActivity.class);
-            showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, (Parcelable) uploadFile.getOCFile());
+            showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, uploadFile.getOCFile());
             showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, uploadFile.getAccount(getActivity()));
             startActivity(showDetailsIntent);
             return true;
@@ -189,4 +207,12 @@ public class UploadListFragment extends ExpandableListFragment {
 
     }
 
+    public void binderReady(){
+        setBinderReady(true);
+
+        if (mAdapter != null) {
+            mAdapter.addBinder();
+        }
+    }
+
 }