forked from haiwen/seadroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring of Camera upload as Sync Provider
This patch reworks most of the camera upload. It contains two important changes: (1) The old code implemented camera upload as a service. While that worked, it proved somewhat problematic. Services can be killed by Android, and the service had to be started by an Activity. Android provides an API for implementing data syncing: https://developer.android.com/training/sync-adapters/index.html This API provides a number of advantages compared to a self-implemented service. Among them are: * Less code * Automatic error recovery (e.g. retry on network errors) * Periodic synchronisation (e.g. every 24h) * Better visibility to the user (via Android Settings->Accounts) (2) The old camera media sync algortihm tried to upload media via two ways: a) when a new photo was added to the MediaStore, that photo was uploaded. But *only* if the data plan allowed it. b) when the user interacts with Seadroid, the service uploaded all photos not yet uploaded. It did that by scanning certain hard-coded directories on the externalStorage and looking for new media files. Important changes added by this patch: - This new design builds soly on the MediaStore. The MediaStore contains all images/videos on the phone. Therefore it should not be necessary to scan (or even be aware of) where the photos are actually stored. - The MediaStore has a column where it records the "DATA_ADDED" for every media file. We can use that to sort and filter for new newly added media files. This eases up the syncing mechanism considerably. - Allowing to sync to sub directories in a repository. - There is still a service necessary to monitor MediaStore activity. However even without that service, Android will perform a sync about every 24h. Also that service is now autostarted on System boot and on Seadroid apk upgrades. - Finally merging with existing files on the server was also improved by skipping files that are already present on the server (it compares the file size and will still upload if the sizes differ. That's probably the best one can do with the current API2). Overall, this patch should adresses the following issues: issue haiwen#277 (Camera upload function dumps all subdir files into single dir) issue haiwen#301 (Inconsistency in camera upload sync) issue haiwen#311 (second suggestion: target repo sub directories) issue haiwen#336 (file duplication when doing a full resync) issue haiwen#375 (Picture upload not acting as service?) issue haiwen#423 (Pictures never upload) [maybe. not sure what's going on there] Useful links: https://developer.android.com/training/sync-adapters/creating-sync-adapter.html http://blog.udinic.com/2013/07/24/write-your-own-android-sync-adapter/
- Loading branch information
Showing
37 changed files
with
1,464 additions
and
2,008 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> | ||
<solid android:color="#7EE6FF" /> | ||
<stroke android:width="5px" android:color="#00E6FF"/> | ||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent"> | ||
|
||
<ImageView | ||
android:id="@+id/bucket_item_thumbImage" | ||
android:layout_width="512px" | ||
android:layout_height="384px" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentTop="true" | ||
android:scaleType="centerCrop" /> | ||
|
||
<ImageView | ||
android:id="@+id/bucket_item_text_background" | ||
android:layout_width="512px" | ||
android:layout_height="50px" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentLeft="true" | ||
android:alpha="0.5" | ||
android:background="#000000" /> | ||
|
||
<ImageView | ||
android:id="@+id/bucket_item_marking" | ||
android:layout_width="512px" | ||
android:layout_height="384px" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentTop="true" | ||
android:background="@drawable/camera_bucket_selected" | ||
android:alpha="0.7" /> | ||
|
||
<TextView | ||
android:id="@+id/bucket_item_name" | ||
android:layout_width="512px" | ||
android:layout_height="50px" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentLeft="true" | ||
android:textColor="#ffffff" | ||
android:layout_marginLeft="10px" | ||
android:layout_marginTop="5px" | ||
android:layout_marginRight="5px" /> | ||
|
||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent"> | ||
|
||
<GridView android:id="@+id/cuc_bucket_selection_grid" | ||
android:layout_width="fill_parent" android:layout_height="fill_parent" | ||
android:numColumns="auto_fit" android:verticalSpacing="10dp" | ||
android:horizontalSpacing="10dp" android:columnWidth="150dp" | ||
android:stretchMode="columnWidth" android:gravity="center" /> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<sync-adapter | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:contentAuthority="com.seafile.seadroid2.cameraupload" | ||
android:accountType="com.seafile.seadroid2" | ||
android:userVisible="true" | ||
android:supportsUploading="true" | ||
android:allowParallelSyncs="false" | ||
android:isAlwaysSyncable="true"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.seafile.seadroid2; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.util.Log; | ||
|
||
import com.seafile.seadroid2.cameraupload.MediaObserverService; | ||
|
||
/** | ||
* This receiver is called whenever the system has booted or | ||
* the Seadroid app has been upgraded to a new version. | ||
* | ||
* It can be used to start up background services. | ||
*/ | ||
public class BootAutostart extends BroadcastReceiver { | ||
private static final String DEBUG_TAG = "BootAutostart"; | ||
|
||
/** | ||
* This method will be excecuted after | ||
* - booting the device | ||
* - upgrade of the Seadroid package | ||
*/ | ||
public void onReceive(Context context, Intent intent) | ||
{ | ||
Log.i(DEBUG_TAG, "Registering for MediaProvider changes."); | ||
|
||
Intent mediaObserver = new Intent(context, MediaObserverService.class); | ||
context.startService(mediaObserver); | ||
} | ||
|
||
} |
Oops, something went wrong.