xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Settings" android:icon="@android:drawable/ic_menu_preferences" android:id="@+id/settingsItem"></item>
<item android:id="@+id/createDirectoryItem" android:title="Create Directory" android:icon="@android:drawable/ic_menu_add"></item>
+ <item android:id="@+id/startSync" android:title="Sync account"></item>
</menu>
import android.app.NotificationManager;\r
import android.app.PendingIntent;\r
import android.app.Service;\r
+import android.content.BroadcastReceiver;\r
import android.content.ContentValues;\r
import android.content.Intent;\r
import android.net.Uri;\r
import eu.alefzero.webdav.WebdavClient;\r
\r
public class FileDownloader extends Service {\r
+ public static final String DOWNLOAD_FINISH_MESSAGE = "DOWNLOAD_FINISH";\r
public static final String EXTRA_ACCOUNT = "ACCOUNT";\r
public static final String EXTRA_FILE_PATH = "FILE_PATH";\r
- private static final String TAG = "OC_FileDownloader";\r
+ private static final String TAG = "FileDownloader";\r
\r
private NotificationManager nm;\r
private Looper mServiceLooper;\r
ProviderTableMeta.FILE_NAME +"=? AND "+ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",\r
new String[]{mFilePath.substring(mFilePath.lastIndexOf('/')+1), mAccount.name});\r
nm.cancel(1);\r
+ Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE);\r
+ sendBroadcast(end);\r
}\r
\r
}\r
import android.content.SyncResult;\r
import android.content.IntentSender.SendIntentException;\r
import android.os.Bundle;\r
+import android.util.Log;\r
import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
import eu.alefzero.owncloud.datamodel.OCFile;\r
import eu.alefzero.webdav.WebdavEntry;\r
*/\r
public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {\r
\r
- public static final String SYNC_MESSAGE = "eu.alefzero.owncloud.files.ACCOUNT_SYNC";\r
- public static final String IN_PROGRESS = "sync_in_progress";\r
- public static final String ACCOUNT_NAME = "account_name";\r
- \r
public FileSyncAdapter(Context context, boolean autoInitialize) {\r
super(context, autoInitialize);\r
}\r
this.setContentProvider(provider);\r
this.setStorageManager(new FileDataStorageManager(account, getContentProvider()));\r
\r
- Intent i = new Intent(SYNC_MESSAGE);\r
- i.putExtra(IN_PROGRESS, true);\r
- i.putExtra("ACCOUNT_NAME", account.name);\r
+ Intent i = new Intent(FileSyncService.SYNC_MESSAGE);\r
+ i.putExtra(FileSyncService.IN_PROGRESS, true);\r
+ i.putExtra(FileSyncService.ACCOUNT_NAME, account.name);\r
getContext().sendStickyBroadcast(i);\r
\r
PropFindMethod query;\r
try {\r
- query = new PropFindMethod(getUri().toString());\r
+ Log.e("ASD", getUri().toString());\r
+ query = new PropFindMethod(getUri().toString()+"/");\r
getClient().executeMethod(query);\r
MultiStatus resp = null;\r
resp = query.getResponseBodyAsMultiStatus();\r
+ \r
if (resp.getResponses().length > 0) {\r
WebdavEntry we = new WebdavEntry(resp.getResponses()[0]);\r
OCFile file = fillOCFile(we);\r
syncResult.stats.numIoExceptions++;\r
e.printStackTrace();\r
}\r
- i.putExtra(IN_PROGRESS, false);\r
+ i.putExtra(FileSyncService.IN_PROGRESS, false);\r
getContext().sendStickyBroadcast(i);\r
}\r
\r
*\r
*/\r
public class FileSyncService extends Service {\r
- private static final Object syncAdapterLock = new Object();\r
- private static AbstractOwnCloudSyncAdapter concretSyncAdapter = null;\r
+ public static final String SYNC_MESSAGE = "eu.alefzero.owncloud.files.ACCOUNT_SYNC";\r
+ public static final String IN_PROGRESS = "sync_in_progress";\r
+ public static final String ACCOUNT_NAME = "account_name";\r
+ \r
+ private static final Object syncAdapterLock = new Object();\r
+ private static AbstractOwnCloudSyncAdapter concretSyncAdapter = null;\r
\r
- /*\r
- * {@inheritDoc}\r
- */\r
- @Override\r
- public void onCreate() {\r
- synchronized (syncAdapterLock) {\r
- if (concretSyncAdapter == null) {\r
- concretSyncAdapter = new FileSyncAdapter(getApplicationContext(), true);\r
- }\r
- }\r
+ /*\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public void onCreate() {\r
+ synchronized (syncAdapterLock) {\r
+ if (concretSyncAdapter == null)\r
+ concretSyncAdapter = new FileSyncAdapter(getApplicationContext(), true);\r
}\r
+ }\r
\r
- /*\r
- * {@inheritDoc}\r
- */\r
- @Override\r
- public IBinder onBind(Intent intent) {\r
- return concretSyncAdapter.getSyncAdapterBinder();\r
- }\r
+ /*\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public IBinder onBind(Intent intent) {\r
+ return concretSyncAdapter.getSyncAdapterBinder();\r
+ }\r
}\r
username_text.getText().toString(),\r
password_text.getText().toString());\r
mAuthRunnable.setOnAuthenticationResultListener(this, mHandler);\r
+ Log.e(TAG, uri.toString());\r
mAuthThread = new Thread(mAuthRunnable);\r
mAuthThread.start();\r
}\r
import android.content.DialogInterface.OnCancelListener;\r
import android.content.DialogInterface.OnClickListener;\r
import android.content.BroadcastReceiver;\r
+import android.content.ContentResolver;\r
import android.content.Intent;\r
import android.content.IntentFilter;\r
import android.net.Uri;\r
import eu.alefzero.owncloud.datamodel.DataStorageManager;\r
import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
import eu.alefzero.owncloud.datamodel.OCFile;\r
+import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;\r
import eu.alefzero.owncloud.syncadapter.FileSyncAdapter;\r
+import eu.alefzero.owncloud.syncadapter.FileSyncService;\r
import eu.alefzero.owncloud.ui.fragment.FileListFragment;\r
import eu.alefzero.webdav.WebdavClient;\r
\r
showDialog(DIALOG_CREATE_DIR);\r
break;\r
}\r
+ case R.id.startSync: {\r
+ Bundle bundle = new Bundle();\r
+ bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
+ ContentResolver.requestSync(AccountUtils.getCurrentOwnCloudAccount(this),\r
+ "org.owncloud",\r
+ bundle);\r
+ break;\r
+ }\r
case android.R.id.home: {\r
onBackPressed();\r
break;\r
showDialog(DIALOG_SETUP_ACCOUNT);\r
return;\r
}\r
- IntentFilter f = new IntentFilter(FileSyncAdapter.SYNC_MESSAGE);\r
+ IntentFilter f = new IntentFilter(FileSyncService.SYNC_MESSAGE);\r
b = new BR();\r
registerReceiver(b, f);\r
setProgressBarIndeterminateVisibility(false);\r
private class BR extends BroadcastReceiver {\r
@Override\r
public void onReceive(Context context, Intent intent) {\r
- boolean in_progress = intent.getBooleanExtra(FileSyncAdapter.IN_PROGRESS, false);\r
- String account_name = intent.getStringExtra(FileSyncAdapter.ACCOUNT_NAME);\r
+ boolean in_progress = intent.getBooleanExtra(FileSyncService.IN_PROGRESS, false);\r
+ String account_name = intent.getStringExtra(FileSyncService.ACCOUNT_NAME);\r
Log.d("FileDisplay", "sync of account " + account_name + " is in_progress: " + in_progress);\r
setProgressBarIndeterminateVisibility(in_progress);\r
if (!in_progress) {\r
package eu.alefzero.owncloud.ui.fragment;\r
\r
import android.accounts.Account;\r
+import android.content.BroadcastReceiver;\r
+import android.content.Context;\r
import android.content.Intent;\r
+import android.content.IntentFilter;\r
import android.database.Cursor;\r
import android.graphics.Bitmap;\r
import android.graphics.BitmapFactory;\r
\r
private Intent mIntent;\r
private View mView;\r
+ private DownloadFinishReceiver dfr;\r
+ \r
+ @Override\r
+ public void onResume() {\r
+ super.onResume();\r
+ dfr = new DownloadFinishReceiver();\r
+ IntentFilter filter = new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE);\r
+ getActivity().registerReceiver(dfr, filter);\r
+ }\r
+ \r
+ @Override\r
+ public void onPause() {\r
+ super.onPause();\r
+ getActivity().unregisterReceiver(dfr);\r
+ dfr = null;\r
+ }\r
\r
public void setStuff(Intent intent) {\r
mIntent = intent;\r
getActivity().startService(i);\r
}\r
\r
+ private class DownloadFinishReceiver extends BroadcastReceiver {\r
+ @Override\r
+ public void onReceive(Context context, Intent intent) {\r
+ setStuff(getView());\r
+ }\r
+ \r
+ }\r
+ \r
}\r