From: Bartek Przybylski Date: Fri, 4 May 2012 18:34:05 +0000 (+0200) Subject: sync option in filelist menu X-Git-Tag: oc-android-1.4.3~428 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/fae44486b9545bfb2a49ded9a0c3fd550fd18549?hp=--cc sync option in filelist menu --- fae44486b9545bfb2a49ded9a0c3fd550fd18549 diff --git a/res/menu/menu.xml b/res/menu/menu.xml index 7ffd43ab..df201e78 100644 --- a/res/menu/menu.xml +++ b/res/menu/menu.xml @@ -3,4 +3,5 @@ xmlns:android="http://schemas.android.com/apk/res/android"> + diff --git a/src/eu/alefzero/owncloud/FileDownloader.java b/src/eu/alefzero/owncloud/FileDownloader.java index bdcec721..c0c950ac 100644 --- a/src/eu/alefzero/owncloud/FileDownloader.java +++ b/src/eu/alefzero/owncloud/FileDownloader.java @@ -8,6 +8,7 @@ import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; +import android.content.BroadcastReceiver; import android.content.ContentValues; import android.content.Intent; import android.net.Uri; @@ -25,9 +26,10 @@ import eu.alefzero.owncloud.ui.activity.FileDisplayActivity; import eu.alefzero.webdav.WebdavClient; public class FileDownloader extends Service { + public static final String DOWNLOAD_FINISH_MESSAGE = "DOWNLOAD_FINISH"; public static final String EXTRA_ACCOUNT = "ACCOUNT"; public static final String EXTRA_FILE_PATH = "FILE_PATH"; - private static final String TAG = "OC_FileDownloader"; + private static final String TAG = "FileDownloader"; private NotificationManager nm; private Looper mServiceLooper; @@ -111,6 +113,8 @@ public class FileDownloader extends Service { ProviderTableMeta.FILE_NAME +"=? AND "+ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?", new String[]{mFilePath.substring(mFilePath.lastIndexOf('/')+1), mAccount.name}); nm.cancel(1); + Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE); + sendBroadcast(end); } } diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java index 816e79ee..a97d59d1 100644 --- a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java +++ b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java @@ -33,6 +33,7 @@ import android.content.Intent; import android.content.SyncResult; import android.content.IntentSender.SendIntentException; import android.os.Bundle; +import android.util.Log; import eu.alefzero.owncloud.datamodel.FileDataStorageManager; import eu.alefzero.owncloud.datamodel.OCFile; import eu.alefzero.webdav.WebdavEntry; @@ -45,10 +46,6 @@ import eu.alefzero.webdav.WebdavEntry; */ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { - public static final String SYNC_MESSAGE = "eu.alefzero.owncloud.files.ACCOUNT_SYNC"; - public static final String IN_PROGRESS = "sync_in_progress"; - public static final String ACCOUNT_NAME = "account_name"; - public FileSyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); } @@ -65,17 +62,19 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { this.setContentProvider(provider); this.setStorageManager(new FileDataStorageManager(account, getContentProvider())); - Intent i = new Intent(SYNC_MESSAGE); - i.putExtra(IN_PROGRESS, true); - i.putExtra("ACCOUNT_NAME", account.name); + Intent i = new Intent(FileSyncService.SYNC_MESSAGE); + i.putExtra(FileSyncService.IN_PROGRESS, true); + i.putExtra(FileSyncService.ACCOUNT_NAME, account.name); getContext().sendStickyBroadcast(i); PropFindMethod query; try { - query = new PropFindMethod(getUri().toString()); + Log.e("ASD", getUri().toString()); + query = new PropFindMethod(getUri().toString()+"/"); getClient().executeMethod(query); MultiStatus resp = null; resp = query.getResponseBodyAsMultiStatus(); + if (resp.getResponses().length > 0) { WebdavEntry we = new WebdavEntry(resp.getResponses()[0]); OCFile file = fillOCFile(we); @@ -95,7 +94,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { syncResult.stats.numIoExceptions++; e.printStackTrace(); } - i.putExtra(IN_PROGRESS, false); + i.putExtra(FileSyncService.IN_PROGRESS, false); getContext().sendStickyBroadcast(i); } diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncService.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncService.java index ed8480ef..7fa4574a 100644 --- a/src/eu/alefzero/owncloud/syncadapter/FileSyncService.java +++ b/src/eu/alefzero/owncloud/syncadapter/FileSyncService.java @@ -28,26 +28,29 @@ import android.os.IBinder; * */ public class FileSyncService extends Service { - private static final Object syncAdapterLock = new Object(); - private static AbstractOwnCloudSyncAdapter concretSyncAdapter = null; + public static final String SYNC_MESSAGE = "eu.alefzero.owncloud.files.ACCOUNT_SYNC"; + public static final String IN_PROGRESS = "sync_in_progress"; + public static final String ACCOUNT_NAME = "account_name"; + + private static final Object syncAdapterLock = new Object(); + private static AbstractOwnCloudSyncAdapter concretSyncAdapter = null; - /* - * {@inheritDoc} - */ - @Override - public void onCreate() { - synchronized (syncAdapterLock) { - if (concretSyncAdapter == null) { - concretSyncAdapter = new FileSyncAdapter(getApplicationContext(), true); - } - } + /* + * {@inheritDoc} + */ + @Override + public void onCreate() { + synchronized (syncAdapterLock) { + if (concretSyncAdapter == null) + concretSyncAdapter = new FileSyncAdapter(getApplicationContext(), true); } + } - /* - * {@inheritDoc} - */ - @Override - public IBinder onBind(Intent intent) { - return concretSyncAdapter.getSyncAdapterBinder(); - } + /* + * {@inheritDoc} + */ + @Override + public IBinder onBind(Intent intent) { + return concretSyncAdapter.getSyncAdapterBinder(); + } } diff --git a/src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java b/src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java index 3ecd3e79..545adef9 100644 --- a/src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java @@ -243,6 +243,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity implemen username_text.getText().toString(), password_text.getText().toString()); mAuthRunnable.setOnAuthenticationResultListener(this, mHandler); + Log.e(TAG, uri.toString()); mAuthThread = new Thread(mAuthRunnable); mAuthThread.start(); } diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index 1b909a4e..916b90ee 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -28,6 +28,7 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnClickListener; import android.content.BroadcastReceiver; +import android.content.ContentResolver; import android.content.Intent; import android.content.IntentFilter; import android.net.Uri; @@ -53,7 +54,9 @@ 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.db.ProviderMeta.ProviderTableMeta; import eu.alefzero.owncloud.syncadapter.FileSyncAdapter; +import eu.alefzero.owncloud.syncadapter.FileSyncService; import eu.alefzero.owncloud.ui.fragment.FileListFragment; import eu.alefzero.webdav.WebdavClient; @@ -179,6 +182,14 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements showDialog(DIALOG_CREATE_DIR); break; } + case R.id.startSync: { + Bundle bundle = new Bundle(); + bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); + ContentResolver.requestSync(AccountUtils.getCurrentOwnCloudAccount(this), + "org.owncloud", + bundle); + break; + } case android.R.id.home: { onBackPressed(); break; @@ -231,7 +242,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements showDialog(DIALOG_SETUP_ACCOUNT); return; } - IntentFilter f = new IntentFilter(FileSyncAdapter.SYNC_MESSAGE); + IntentFilter f = new IntentFilter(FileSyncService.SYNC_MESSAGE); b = new BR(); registerReceiver(b, f); setProgressBarIndeterminateVisibility(false); @@ -344,8 +355,8 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements private class BR extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - boolean in_progress = intent.getBooleanExtra(FileSyncAdapter.IN_PROGRESS, false); - String account_name = intent.getStringExtra(FileSyncAdapter.ACCOUNT_NAME); + boolean in_progress = intent.getBooleanExtra(FileSyncService.IN_PROGRESS, false); + String account_name = intent.getStringExtra(FileSyncService.ACCOUNT_NAME); Log.d("FileDisplay", "sync of account " + account_name + " is in_progress: " + in_progress); setProgressBarIndeterminateVisibility(in_progress); if (!in_progress) { diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index fac9fa4a..f6672040 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -18,7 +18,10 @@ package eu.alefzero.owncloud.ui.fragment; import android.accounts.Account; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -49,6 +52,22 @@ public class FileDetailFragment extends SherlockFragment implements OnClickListe private Intent mIntent; private View mView; + private DownloadFinishReceiver dfr; + + @Override + public void onResume() { + super.onResume(); + dfr = new DownloadFinishReceiver(); + IntentFilter filter = new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE); + getActivity().registerReceiver(dfr, filter); + } + + @Override + public void onPause() { + super.onPause(); + getActivity().unregisterReceiver(dfr); + dfr = null; + } public void setStuff(Intent intent) { mIntent = intent; @@ -144,4 +163,12 @@ public class FileDetailFragment extends SherlockFragment implements OnClickListe getActivity().startService(i); } + private class DownloadFinishReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + setStuff(getView()); + } + + } + }