Merge remote-tracking branch 'remotes/upstream/master' into uploadWhenCharging
authortobiasKaminsky <tobias@kaminsky.me>
Sun, 18 Oct 2015 10:50:54 +0000 (12:50 +0200)
committertobiasKaminsky <tobias@kaminsky.me>
Sun, 18 Oct 2015 10:50:54 +0000 (12:50 +0200)
AndroidManifest.xml
res/values-tzl/strings.xml [deleted file]
res/values/strings.xml
res/xml/preferences.xml
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java
src/com/owncloud/android/ui/activity/Preferences.java

index acb5f1d..f0d59e4 100644 (file)
             <intent-filter>
                 <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
             </intent-filter>
+            <intent-filter>
+                               <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
+                           <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
+                       </intent-filter>
         </receiver>
         <receiver android:name=".files.BootupBroadcastReceiver">
             <intent-filter>
diff --git a/res/values-tzl/strings.xml b/res/values-tzl/strings.xml
deleted file mode 100644 (file)
index 37e6152..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<resources>
-  <!--TODO re-enable when server-side folder size calculation is available   
-       <item>Biggest - Smallest</item>-->
-  <!--TODO re-enable when "Accounts" is available in Navigation Drawer-->
-  <!--<string name="drawer_item_accounts">Accounts</string>-->
-  <!--TODO re-enable when "On Device" is available
-    <string name="drawer_item_on_device">On device</string>-->
-  <string name="empty"></string>
-</resources>
index 267d713..2522307 100644 (file)
     <string name="placeholder_filesize">389 KB</string>
     <string name="placeholder_timestamp">2012/05/18 12:23 PM</string>
     <string name="placeholder_media_time">12:23:45</string>
-
-    <string name="instant_upload_on_wifi">Upload pictures via WiFi only</string>
-    <string name="instant_video_upload_on_wifi">Upload videos via WiFi only</string>
+    
+    <string name="instant_upload_on_wifi">Upload pictures via wifi only</string>
+    <string name="instant_upload_on_charging">Upload when charging only</string>
+    <string name="instant_video_upload_on_wifi">Upload videos via wifi only</string>
     <string name="instant_upload_path">/InstantUpload</string>
     <string name="conflict_title">File conflict</string>
     <string name="conflict_message">Which files do you want to keep? If you select both versions, the local file will have a number added to its name.</string>
     <string name="preview_image_error_unknown_format">This image cannot be shown</string>
 
     <string name="error__upload__local_file_not_copied">%1$s could not be copied to %2$s local folder</string>
-    <string name="prefs_instant_upload_path_title">Upload Path</string>
+    <string name="prefs_instant_upload_path_title">Upload path</string>
 
        <string name="share_link_no_support_share_api">Sorry, sharing is not enabled on your server. Please contact your
                administrator.</string>
     <string name="prefs_category_instant_uploading">Instant Uploads</string>
        <string name="prefs_category_security">Security</string>
 
-       <string name="prefs_instant_video_upload_path_title">Upload Video Path</string>
+       <string name="prefs_instant_video_upload_path_title">Upload video path</string>
     <string name="download_folder_failed_content">Download of %1$s folder could not be completed</string>
 
        <string name="shared_subject_header">shared</string>
index 4823a83..b645fc1 100644 (file)
@@ -3,7 +3,7 @@
   ownCloud Android client application
 
   Copyright (C) 2012  Bartek Przybylski
-  Copyright (C) 2015 ownCloud Inc.
+  Copyright (C) 2012-2013 ownCloud Inc.
 
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 2,
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
-    <PreferenceCategory android:title="@string/prefs_category_accounts" android:key="accounts_category">
+    <PreferenceCategory
+               android:title="@string/prefs_category_accounts"
+               android:key="accounts_category">
     </PreferenceCategory>
     
        <PreferenceCategory android:title="@string/prefs_category_security">
-           <android.preference.CheckBoxPreference android:title="@string/prefs_passcode" android:key="set_pincode" />
+               <!-- ListPreference
+            android:key="select_oc_account"
+            android:title="@string/prefs_select_oc_account"
+            android:summary="@string/prefs_summary_select_oc_account"
+            / -->
+               <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:title="@string/prefs_pincode" android:key="set_pincode"
+                       android:summary="@string/prefs_pincode_summary"/>
        </PreferenceCategory>
 
-    <PreferenceCategory android:title="@string/prefs_category_instant_uploading" android:key="instant_uploading_category">
-         <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading"
+    <PreferenceCategory android:title="@string/prefs_category_instant_uploading"
+               android:key="instant_uploading_category">
+           <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
+                       android:dependency="instant_uploading"
+                                       android:disableDependentsState="true"
+                                       android:title="@string/instant_upload_on_charging"
+                                       android:key="instant_upload_on_charging"/>
+           <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
+                       android:key="instant_uploading"
                                android:title="@string/prefs_instant_upload"
                                android:summary="@string/prefs_instant_upload_summary"/>
          <com.owncloud.android.ui.PreferenceWithLongSummary
@@ -35,7 +50,8 @@
            <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
                                                android:title="@string/instant_upload_on_wifi"
                                                android:key="instant_upload_on_wifi"/>
-           <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_video_uploading"
+           <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
+                       android:key="instant_video_uploading"
                                android:title="@string/prefs_instant_video_upload"
                                android:summary="@string/prefs_instant_video_upload_summary" />
            <com.owncloud.android.ui.PreferenceWithLongSummary
     </PreferenceCategory>
        
        <PreferenceCategory android:title="@string/prefs_category_more" android:key="more">
-    <Preference android:title="@string/prefs_help" android:key="help" />
-    <Preference android:title="@string/prefs_recommend" android:key="recommend" />
-    <Preference android:title="@string/prefs_feedback" android:key="feedback" />
-    <Preference android:title="@string/prefs_imprint" android:key="imprint" />
-                        
-       <Preference             android:id="@+id/about_app" 
-                                       android:title="@string/about_title" 
-                                       android:key="about_app" />
+               <Preference android:title="@string/prefs_help" android:key="help" />
+               <Preference android:title="@string/prefs_recommend" android:key="recommend" />
+               <Preference android:title="@string/prefs_feedback" android:key="feedback" />
+               <Preference android:title="@string/prefs_imprint" android:key="imprint" />
+
+               <Preference             android:id="@+id/about_app"
+                       android:title="@string/about_title"
+                       android:key="about_app" />
        </PreferenceCategory>
-    
+
 
 </PreferenceScreen>
index 47f7127..2a335ad 100644 (file)
@@ -29,14 +29,15 @@ import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.utils.FileStorageUtils;
 
-
 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.net.ConnectivityManager;
 import android.net.NetworkInfo.State;
+import android.os.BatteryManager;
 import android.preference.PreferenceManager;
 import android.provider.MediaStore.Images;
 import android.provider.MediaStore.Video;
@@ -58,7 +59,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
     @Override
     public void onReceive(Context context, Intent intent) {
         Log_OC.d(TAG, "Received: " + intent.getAction());
-        if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
+        if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION) || intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) {
             handleConnectivityAction(context, intent);
         }else if (intent.getAction().equals(NEW_PHOTO_ACTION_UNOFFICIAL)) {
             handleNewPictureAction(context, intent); 
@@ -103,7 +104,6 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
         file_name = c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME));
         mime_type = c.getString(c.getColumnIndex(Images.Media.MIME_TYPE));
         c.close();
-        
         Log_OC.d(TAG, file_path + "");
 
         // save always temporally the picture to upload
@@ -111,7 +111,10 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
         db.putFileForLater(file_path, account.name, null);
         db.close();
 
-        if (!isOnline(context) || (instantPictureUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context))) {
+        if (!isOnline(context) 
+                || (instantPictureUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context))
+                || (instantUploadWhenChargingOnly(context) && !isCharging(context))
+           ) {
             return;
         }
 
@@ -155,8 +158,16 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
         mime_type = c.getString(c.getColumnIndex(Video.Media.MIME_TYPE));
         c.close();
         Log_OC.d(TAG, file_path + "");
+        
+        // save always temporally the picture to upload
+        DbHandler db = new DbHandler(context);
+        db.putFileForLater(file_path, account.name, null);
+        db.close();
 
-        if (!isOnline(context) || (instantVideoUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context))) {
+        if (!isOnline(context) 
+                || (instantVideoUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context))
+                || (instantUploadWhenChargingOnly(context) && !isCharging(context))
+           ) {
             return;
         }
 
@@ -172,14 +183,17 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
     }
 
     private void handleConnectivityAction(Context context, Intent intent) {
-        if (!instantPictureUploadEnabled(context)) {
+        if (!instantPictureUploadEnabled(context) && !instantVideoUploadEnabled(context)) {
             Log_OC.d(TAG, "Instant upload disabled, don't upload anything");
             return;
         }
 
         if (!intent.hasExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY)
                 && isOnline(context)
-                && (!instantPictureUploadViaWiFiOnly(context) || (instantPictureUploadViaWiFiOnly(context) == isConnectedViaWiFi(context) == true))) {
+                && (!instantUploadWhenChargingOnly(context) || (instantUploadWhenChargingOnly(context) == isCharging(context) == true))
+                && (!instantPictureUploadViaWiFiOnly(context) || (instantPictureUploadViaWiFiOnly(context) == isConnectedViaWiFi(context) == true))
+                && (!instantVideoUploadViaWiFiOnly(context) || (instantVideoUploadViaWiFiOnly(context) == isConnectedViaWiFi(context) == true))
+            ) {
             DbHandler db = new DbHandler(context);
             Cursor c = db.getAwaitingFiles();
             if (c.moveToFirst()) {
@@ -217,7 +231,6 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
             c.close();
             db.close();
         }
-
     }
 
     public static boolean isOnline(Context context) {
@@ -231,6 +244,15 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
                 && cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI
                 && cm.getActiveNetworkInfo().getState() == State.CONNECTED;
     }
+    
+    public static boolean isCharging(Context context){
+        IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
+        Intent batteryStatus = context.registerReceiver(null, ifilter);
+        
+        int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
+        return status == BatteryManager.BATTERY_STATUS_CHARGING ||
+                status == BatteryManager.BATTERY_STATUS_FULL;
+    }
 
     public static boolean instantPictureUploadEnabled(Context context) {
         return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_uploading", false);
@@ -247,4 +269,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
     public static boolean instantVideoUploadViaWiFiOnly(Context context) {
         return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_video_upload_on_wifi", false);
     }
+    public static boolean instantUploadWhenChargingOnly(Context context) {
+        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_upload_on_charging", false);
+    }
 }
index e1c5c10..d980b97 100644 (file)
@@ -457,8 +457,8 @@ public class Preferences extends PreferenceActivity
             mPrefInstantUploadCategory.addPreference(mPrefInstantUploadPathWiFi);
             mPrefInstantUploadCategory.addPreference(mPrefInstantUploadPath);
         } else {
-            mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPathWiFi);
-            mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPath);
+//            mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPathWiFi);
+//            mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPath);
         }
     }
     
@@ -467,8 +467,8 @@ public class Preferences extends PreferenceActivity
             mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPathWiFi);
             mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPath);
         } else {
-            mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPathWiFi);
-            mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPath);
+//            mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPathWiFi);
+//            mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPath);
         }
     }
 
@@ -805,7 +805,7 @@ public class Preferences extends PreferenceActivity
         SharedPreferences appPrefs =
                 PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
         mUploadVideoPath = appPrefs.getString("instant_video_upload_path", getString(R.string.instant_upload_path));
-        mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
+//        mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
     }
 
     /**