Skip to content

Commit fae4448

Browse files
committed
sync option in filelist menu
1 parent a2a8dc1 commit fae4448

File tree

7 files changed

+78
-32
lines changed

7 files changed

+78
-32
lines changed

res/menu/menu.xml

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
xmlns:android="http://schemas.android.com/apk/res/android">
44
<item android:title="Settings" android:icon="@android:drawable/ic_menu_preferences" android:id="@+id/settingsItem"></item>
55
<item android:id="@+id/createDirectoryItem" android:title="Create Directory" android:icon="@android:drawable/ic_menu_add"></item>
6+
<item android:id="@+id/startSync" android:title="Sync account"></item>
67
</menu>

src/eu/alefzero/owncloud/FileDownloader.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.app.NotificationManager;
99
import android.app.PendingIntent;
1010
import android.app.Service;
11+
import android.content.BroadcastReceiver;
1112
import android.content.ContentValues;
1213
import android.content.Intent;
1314
import android.net.Uri;
@@ -25,9 +26,10 @@
2526
import eu.alefzero.webdav.WebdavClient;
2627

2728
public class FileDownloader extends Service {
29+
public static final String DOWNLOAD_FINISH_MESSAGE = "DOWNLOAD_FINISH";
2830
public static final String EXTRA_ACCOUNT = "ACCOUNT";
2931
public static final String EXTRA_FILE_PATH = "FILE_PATH";
30-
private static final String TAG = "OC_FileDownloader";
32+
private static final String TAG = "FileDownloader";
3133

3234
private NotificationManager nm;
3335
private Looper mServiceLooper;
@@ -111,6 +113,8 @@ void downloadFile() {
111113
ProviderTableMeta.FILE_NAME +"=? AND "+ProviderTableMeta.FILE_ACCOUNT_OWNER+"=?",
112114
new String[]{mFilePath.substring(mFilePath.lastIndexOf('/')+1), mAccount.name});
113115
nm.cancel(1);
116+
Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE);
117+
sendBroadcast(end);
114118
}
115119

116120
}

src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.content.SyncResult;
3434
import android.content.IntentSender.SendIntentException;
3535
import android.os.Bundle;
36+
import android.util.Log;
3637
import eu.alefzero.owncloud.datamodel.FileDataStorageManager;
3738
import eu.alefzero.owncloud.datamodel.OCFile;
3839
import eu.alefzero.webdav.WebdavEntry;
@@ -45,10 +46,6 @@
4546
*/
4647
public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
4748

48-
public static final String SYNC_MESSAGE = "eu.alefzero.owncloud.files.ACCOUNT_SYNC";
49-
public static final String IN_PROGRESS = "sync_in_progress";
50-
public static final String ACCOUNT_NAME = "account_name";
51-
5249
public FileSyncAdapter(Context context, boolean autoInitialize) {
5350
super(context, autoInitialize);
5451
}
@@ -65,17 +62,19 @@ public synchronized void onPerformSync(
6562
this.setContentProvider(provider);
6663
this.setStorageManager(new FileDataStorageManager(account, getContentProvider()));
6764

68-
Intent i = new Intent(SYNC_MESSAGE);
69-
i.putExtra(IN_PROGRESS, true);
70-
i.putExtra("ACCOUNT_NAME", account.name);
65+
Intent i = new Intent(FileSyncService.SYNC_MESSAGE);
66+
i.putExtra(FileSyncService.IN_PROGRESS, true);
67+
i.putExtra(FileSyncService.ACCOUNT_NAME, account.name);
7168
getContext().sendStickyBroadcast(i);
7269

7370
PropFindMethod query;
7471
try {
75-
query = new PropFindMethod(getUri().toString());
72+
Log.e("ASD", getUri().toString());
73+
query = new PropFindMethod(getUri().toString()+"/");
7674
getClient().executeMethod(query);
7775
MultiStatus resp = null;
7876
resp = query.getResponseBodyAsMultiStatus();
77+
7978
if (resp.getResponses().length > 0) {
8079
WebdavEntry we = new WebdavEntry(resp.getResponses()[0]);
8180
OCFile file = fillOCFile(we);
@@ -95,7 +94,7 @@ public synchronized void onPerformSync(
9594
syncResult.stats.numIoExceptions++;
9695
e.printStackTrace();
9796
}
98-
i.putExtra(IN_PROGRESS, false);
97+
i.putExtra(FileSyncService.IN_PROGRESS, false);
9998
getContext().sendStickyBroadcast(i);
10099
}
101100

src/eu/alefzero/owncloud/syncadapter/FileSyncService.java

+22-19
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,29 @@
2828
*
2929
*/
3030
public class FileSyncService extends Service {
31-
private static final Object syncAdapterLock = new Object();
32-
private static AbstractOwnCloudSyncAdapter concretSyncAdapter = null;
31+
public static final String SYNC_MESSAGE = "eu.alefzero.owncloud.files.ACCOUNT_SYNC";
32+
public static final String IN_PROGRESS = "sync_in_progress";
33+
public static final String ACCOUNT_NAME = "account_name";
34+
35+
private static final Object syncAdapterLock = new Object();
36+
private static AbstractOwnCloudSyncAdapter concretSyncAdapter = null;
3337

34-
/*
35-
* {@inheritDoc}
36-
*/
37-
@Override
38-
public void onCreate() {
39-
synchronized (syncAdapterLock) {
40-
if (concretSyncAdapter == null) {
41-
concretSyncAdapter = new FileSyncAdapter(getApplicationContext(), true);
42-
}
43-
}
38+
/*
39+
* {@inheritDoc}
40+
*/
41+
@Override
42+
public void onCreate() {
43+
synchronized (syncAdapterLock) {
44+
if (concretSyncAdapter == null)
45+
concretSyncAdapter = new FileSyncAdapter(getApplicationContext(), true);
4446
}
47+
}
4548

46-
/*
47-
* {@inheritDoc}
48-
*/
49-
@Override
50-
public IBinder onBind(Intent intent) {
51-
return concretSyncAdapter.getSyncAdapterBinder();
52-
}
49+
/*
50+
* {@inheritDoc}
51+
*/
52+
@Override
53+
public IBinder onBind(Intent intent) {
54+
return concretSyncAdapter.getSyncAdapterBinder();
55+
}
5356
}

src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public void onOkClick(View view) {
243243
username_text.getText().toString(),
244244
password_text.getText().toString());
245245
mAuthRunnable.setOnAuthenticationResultListener(this, mHandler);
246+
Log.e(TAG, uri.toString());
246247
mAuthThread = new Thread(mAuthRunnable);
247248
mAuthThread.start();
248249
}

src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.content.DialogInterface.OnCancelListener;
2929
import android.content.DialogInterface.OnClickListener;
3030
import android.content.BroadcastReceiver;
31+
import android.content.ContentResolver;
3132
import android.content.Intent;
3233
import android.content.IntentFilter;
3334
import android.net.Uri;
@@ -53,7 +54,9 @@
5354
import eu.alefzero.owncloud.datamodel.DataStorageManager;
5455
import eu.alefzero.owncloud.datamodel.FileDataStorageManager;
5556
import eu.alefzero.owncloud.datamodel.OCFile;
57+
import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
5658
import eu.alefzero.owncloud.syncadapter.FileSyncAdapter;
59+
import eu.alefzero.owncloud.syncadapter.FileSyncService;
5760
import eu.alefzero.owncloud.ui.fragment.FileListFragment;
5861
import eu.alefzero.webdav.WebdavClient;
5962

@@ -179,6 +182,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
179182
showDialog(DIALOG_CREATE_DIR);
180183
break;
181184
}
185+
case R.id.startSync: {
186+
Bundle bundle = new Bundle();
187+
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
188+
ContentResolver.requestSync(AccountUtils.getCurrentOwnCloudAccount(this),
189+
"org.owncloud",
190+
bundle);
191+
break;
192+
}
182193
case android.R.id.home: {
183194
onBackPressed();
184195
break;
@@ -231,7 +242,7 @@ protected void onResume() {
231242
showDialog(DIALOG_SETUP_ACCOUNT);
232243
return;
233244
}
234-
IntentFilter f = new IntentFilter(FileSyncAdapter.SYNC_MESSAGE);
245+
IntentFilter f = new IntentFilter(FileSyncService.SYNC_MESSAGE);
235246
b = new BR();
236247
registerReceiver(b, f);
237248
setProgressBarIndeterminateVisibility(false);
@@ -344,8 +355,8 @@ private boolean accountsAreSetup() {
344355
private class BR extends BroadcastReceiver {
345356
@Override
346357
public void onReceive(Context context, Intent intent) {
347-
boolean in_progress = intent.getBooleanExtra(FileSyncAdapter.IN_PROGRESS, false);
348-
String account_name = intent.getStringExtra(FileSyncAdapter.ACCOUNT_NAME);
358+
boolean in_progress = intent.getBooleanExtra(FileSyncService.IN_PROGRESS, false);
359+
String account_name = intent.getStringExtra(FileSyncService.ACCOUNT_NAME);
349360
Log.d("FileDisplay", "sync of account " + account_name + " is in_progress: " + in_progress);
350361
setProgressBarIndeterminateVisibility(in_progress);
351362
if (!in_progress) {

src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java

+27
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
package eu.alefzero.owncloud.ui.fragment;
1919

2020
import android.accounts.Account;
21+
import android.content.BroadcastReceiver;
22+
import android.content.Context;
2123
import android.content.Intent;
24+
import android.content.IntentFilter;
2225
import android.database.Cursor;
2326
import android.graphics.Bitmap;
2427
import android.graphics.BitmapFactory;
@@ -49,6 +52,22 @@ public class FileDetailFragment extends SherlockFragment implements OnClickListe
4952

5053
private Intent mIntent;
5154
private View mView;
55+
private DownloadFinishReceiver dfr;
56+
57+
@Override
58+
public void onResume() {
59+
super.onResume();
60+
dfr = new DownloadFinishReceiver();
61+
IntentFilter filter = new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE);
62+
getActivity().registerReceiver(dfr, filter);
63+
}
64+
65+
@Override
66+
public void onPause() {
67+
super.onPause();
68+
getActivity().unregisterReceiver(dfr);
69+
dfr = null;
70+
}
5271

5372
public void setStuff(Intent intent) {
5473
mIntent = intent;
@@ -144,4 +163,12 @@ public void onClick(View v) {
144163
getActivity().startService(i);
145164
}
146165

166+
private class DownloadFinishReceiver extends BroadcastReceiver {
167+
@Override
168+
public void onReceive(Context context, Intent intent) {
169+
setStuff(getView());
170+
}
171+
172+
}
173+
147174
}

0 commit comments

Comments
 (0)