mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
Update files list when an upload finishes, if the file is uploaded to the current folder
This commit is contained in:
parent
121a462bdf
commit
114e0c2521
2 changed files with 55 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
|||
package eu.alefzero.owncloud.files.services;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import eu.alefzero.owncloud.AccountUtils;
|
||||
import eu.alefzero.owncloud.R;
|
||||
|
@ -9,7 +10,6 @@ import eu.alefzero.owncloud.datamodel.FileDataStorageManager;
|
|||
import eu.alefzero.owncloud.datamodel.OCFile;
|
||||
import eu.alefzero.owncloud.files.interfaces.OnDatatransferProgressListener;
|
||||
import eu.alefzero.owncloud.utils.OwnCloudVersion;
|
||||
import eu.alefzero.webdav.OnUploadProgressListener;
|
||||
import eu.alefzero.webdav.WebdavClient;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
|
@ -32,6 +32,9 @@ import android.widget.Toast;
|
|||
|
||||
public class FileUploader extends Service implements OnDatatransferProgressListener {
|
||||
|
||||
public static final String UPLOAD_FINISH_MESSAGE = "UPLOAD_FINISH";
|
||||
public static final String EXTRA_PARENT_DIR_ID = "PARENT_DIR_ID";
|
||||
|
||||
public static final String KEY_LOCAL_FILE = "LOCAL_FILE";
|
||||
public static final String KEY_REMOTE_FILE = "REMOTE_FILE";
|
||||
public static final String KEY_ACCOUNT = "ACCOUNT";
|
||||
|
@ -190,12 +193,16 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
|
|||
new_file.setLastSyncDate(0);
|
||||
new_file.setStoragePath(mLocalPaths[i]);
|
||||
File f = new File(mRemotePaths[i]);
|
||||
new_file.setParentId(storageManager.getFileByPath(f.getParent().endsWith("/")?f.getParent():f.getParent()+"/").getFileId());
|
||||
long parentDirId = storageManager.getFileByPath(f.getParent().endsWith("/")?f.getParent():f.getParent()+"/").getFileId();
|
||||
new_file.setParentId(parentDirId);
|
||||
storageManager.saveFile(new_file);
|
||||
|
||||
Intent end = new Intent(UPLOAD_FINISH_MESSAGE);
|
||||
end.putExtra(EXTRA_PARENT_DIR_ID, parentDirId);
|
||||
sendBroadcast(end);
|
||||
}
|
||||
|
||||
}
|
||||
// notification.contentView.setProgressBar(R.id.status_progress,
|
||||
// mLocalPaths.length-1, mLocalPaths.length-1, false);
|
||||
mNotificationManager.cancel(42);
|
||||
run();
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
|
||||
|
@ -61,6 +62,7 @@ import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
|
|||
import eu.alefzero.owncloud.datamodel.DataStorageManager;
|
||||
import eu.alefzero.owncloud.datamodel.FileDataStorageManager;
|
||||
import eu.alefzero.owncloud.datamodel.OCFile;
|
||||
import eu.alefzero.owncloud.files.services.FileDownloader;
|
||||
import eu.alefzero.owncloud.files.services.FileUploader;
|
||||
import eu.alefzero.owncloud.syncadapter.FileSyncService;
|
||||
import eu.alefzero.owncloud.ui.fragment.FileDetailFragment;
|
||||
|
@ -82,7 +84,8 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
private String[] mDirs = null;
|
||||
|
||||
private DataStorageManager mStorageManager;
|
||||
private SyncBroadcastReceiver syncBroadcastReceiver;
|
||||
private SyncBroadcastReceiver mSyncBroadcastReceiver;
|
||||
private UploadFinishReceiver mUploadFinishReceiver;
|
||||
|
||||
private View mLayoutView = null;
|
||||
private FileListFragment mFileList;
|
||||
|
@ -300,8 +303,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
|
||||
// Listen for sync messages
|
||||
IntentFilter syncIntentFilter = new IntentFilter(FileSyncService.SYNC_MESSAGE);
|
||||
syncBroadcastReceiver = new SyncBroadcastReceiver();
|
||||
registerReceiver(syncBroadcastReceiver, syncIntentFilter);
|
||||
mSyncBroadcastReceiver = new SyncBroadcastReceiver();
|
||||
registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
|
||||
|
||||
// Listen for upload messages
|
||||
IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.UPLOAD_FINISH_MESSAGE);
|
||||
mUploadFinishReceiver = new UploadFinishReceiver();
|
||||
registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
|
||||
|
||||
// Storage manager initialization
|
||||
mStorageManager = new FileDataStorageManager(
|
||||
|
@ -374,9 +382,13 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
protected void onPause() {
|
||||
Log.i(getClass().toString(), "onPause() start");
|
||||
super.onPause();
|
||||
if (syncBroadcastReceiver != null) {
|
||||
unregisterReceiver(syncBroadcastReceiver);
|
||||
syncBroadcastReceiver = null;
|
||||
if (mSyncBroadcastReceiver != null) {
|
||||
unregisterReceiver(mSyncBroadcastReceiver);
|
||||
mSyncBroadcastReceiver = null;
|
||||
}
|
||||
if (mUploadFinishReceiver != null) {
|
||||
unregisterReceiver(mUploadFinishReceiver);
|
||||
mUploadFinishReceiver = null;
|
||||
}
|
||||
getIntent().putExtra(FileDetailFragment.EXTRA_FILE, mCurrentDir);
|
||||
Log.i(getClass().toString(), "onPause() end");
|
||||
|
@ -611,7 +623,33 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private class UploadFinishReceiver extends BroadcastReceiver {
|
||||
/**
|
||||
* Once the file upload has finished -> update view
|
||||
* @author David A. Velasco
|
||||
* {@link BroadcastReceiver} to enable upload feedback in UI
|
||||
*/
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
long parentDirId = intent.getLongExtra(FileUploader.EXTRA_PARENT_DIR_ID, -1);
|
||||
OCFile parentDir = mStorageManager.getFileById(parentDirId);
|
||||
|
||||
if (parentDir != null && (
|
||||
(mCurrentDir == null && parentDir.getFileName().equals("/")) ||
|
||||
parentDir.equals(mCurrentDir))
|
||||
) {
|
||||
FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);
|
||||
if (fileListFragment != null) {
|
||||
fileListFragment.listDirectory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getId() == R.id.setup_account) {
|
||||
|
|
Loading…
Reference in a new issue