فهرست منبع

Issue #136 [Feature] Instant upload of videos

zerginator 12 سال پیش
والد
کامیت
536cc166b6
3فایلهای تغییر یافته به همراه46 افزوده شده و 20 حذف شده
  1. 5 1
      AndroidManifest.xml
  2. 1 1
      res/values/strings.xml
  3. 40 18
      src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java

+ 5 - 1
AndroidManifest.xml

@@ -156,9 +156,13 @@
         
         <receiver android:name=".files.InstantUploadBroadcastReceiver">
             <intent-filter>
-                <action android:name="com.android.camera.NEW_PICTURE" />
+                <action android:name="android.hardware.action.NEW_PICTURE" />
                 <data android:mimeType="image/*" />
             </intent-filter>
+            <intent-filter>
+                <action android:name="android.hardware.action.NEW_VIDEO" />
+                <data android:mimeType="video/*" />
+            </intent-filter>
             <intent-filter>
                 <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
             </intent-filter>

+ 1 - 1
res/values/strings.xml

@@ -40,7 +40,7 @@
     <string name="prefs_pincode">App PIN</string>
     <string name="prefs_pincode_summary">Protect your client</string>
     <string name="prefs_instant_upload">Enable instant uploads</string>
-    <string name="prefs_instant_upload_summary">Instantly upload photos taken by camera</string>
+    <string name="prefs_instant_upload_summary">Instantly upload media taken by camera</string>
     <string name="prefs_log_title">Enable Logging</string>
     <string name="prefs_log_summary">This is used to log problems</string>
     <string name="prefs_log_title_history">Logging History</string>

+ 40 - 18
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java

@@ -29,7 +29,7 @@ import android.database.Cursor;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo.State;
 import android.preference.PreferenceManager;
-import android.provider.MediaStore.Images.Media;
+import android.provider.MediaStore.*;
 import android.webkit.MimeTypeMap;
 
 import com.owncloud.android.AccountUtils;
@@ -41,17 +41,17 @@ import com.owncloud.android.utils.FileStorageUtils;
 
 public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
 
-    private static String TAG = "PhotoTakenBroadcastReceiver";
-    private static final String[] CONTENT_PROJECTION = { Media.DATA, Media.DISPLAY_NAME, Media.MIME_TYPE, Media.SIZE };
-    private static String NEW_PHOTO_ACTION = "com.android.camera.NEW_PICTURE";
+    private static String TAG = "InstantUploadBroadcastReceiver";
+    private static String NEW_PHOTO_ACTION = "android.hardware.action.NEW_PICTURE";
+    private static String NEW_VIDEO_ACTION = "android.hardware.action.NEW_VIDEO";
 
     @Override
     public void onReceive(Context context, Intent intent) {
         Log_OC.d(TAG, "Received: " + intent.getAction());
         if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
             handleConnectivityAction(context, intent);
-        } else if (intent.getAction().equals(NEW_PHOTO_ACTION)) {
-            handleNewPhotoAction(context, intent);
+        } else if (intent.getAction().equals(NEW_PHOTO_ACTION) || intent.getAction().equals(NEW_VIDEO_ACTION)) {
+            handleNewMediaAction(context, intent);
         } else if (intent.getAction().equals(FileUploader.UPLOAD_FINISH_MESSAGE)) {
             handleUploadFinished(context, intent);
         } else {
@@ -71,7 +71,12 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
         }
     }
 
-    private void handleNewPhotoAction(Context context, Intent intent) {
+    private void handleNewMediaAction(Context context, Intent intent) {
+        Cursor c = null;
+        String file_path = null;
+        String file_name = null;
+        String mime_type = null;
+
         if (!instantUploadEnabled(context)) {
             Log_OC.d(TAG, "Instant upload disabled, abording uploading");
             return;
@@ -83,19 +88,36 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
             return;
         }
 
-        Cursor c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null);
-
-        if (!c.moveToFirst()) {
-            Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString());
-            return;
+        if (intent.getAction().equals(NEW_PHOTO_ACTION)) {
+            String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE, Images.Media.SIZE };
+            c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null);
+            if (!c.moveToFirst()) {
+                Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString());
+                return;
+            }
+            file_path = c.getString(c.getColumnIndex(Images.Media.DATA));
+            file_name = c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME));
+            mime_type = c.getString(c.getColumnIndex(Images.Media.MIME_TYPE));
+            Log_OC.w(TAG, "New photo received");
+        }
+        else if (intent.getAction().equals(NEW_VIDEO_ACTION)) {
+            if (!isConnectedViaWiFi(context)) {
+                Log_OC.e(TAG, "No Wifi available .. Video instant upload only possible if WiFi is on");
+                return;
+            }
+            String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME, Video.Media.MIME_TYPE, Video.Media.SIZE };
+            c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null);
+            if (!c.moveToFirst()) {
+                Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString());
+                return;
+            } 
+            file_path = c.getString(c.getColumnIndex(Video.Media.DATA));
+            file_name = c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));
+            mime_type = c.getString(c.getColumnIndex(Video.Media.MIME_TYPE));
+            Log_OC.w(TAG, "New video received");
         }
-
-        String file_path = c.getString(c.getColumnIndex(Media.DATA));
-        String file_name = c.getString(c.getColumnIndex(Media.DISPLAY_NAME));
-        String mime_type = c.getString(c.getColumnIndex(Media.MIME_TYPE));
-
         c.close();
-        Log_OC.e(TAG, file_path + "");
+        Log_OC.d(TAG, file_path + "");
 
         // same always temporally the picture to upload
         DbHandler db = new DbHandler(context);