split "on charging" to photo and video
authortobiasKaminsky <tobias@kaminsky.me>
Sun, 18 Oct 2015 10:51:08 +0000 (12:51 +0200)
committertobiasKaminsky <tobias@kaminsky.me>
Sun, 18 Oct 2015 10:51:08 +0000 (12:51 +0200)
res/values/strings.xml
res/xml/preferences.xml
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java

index 2522307..d41189f 100644 (file)
     <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_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_video_upload_on_charging">Upload when charging 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="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>
index b645fc1..5c853fe 100644 (file)
 
     <PreferenceCategory android:title="@string/prefs_category_instant_uploading"
                android:key="instant_uploading_category">
 
     <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"
            <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
-                                                       android:title="@string/prefs_instant_upload_path_title"
-                                                       android:key="instant_upload_path" />
-           <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
-                                               android:title="@string/instant_upload_on_wifi"
-                                               android:key="instant_upload_on_wifi"/>
+               android:title="@string/prefs_instant_upload"
+               android:summary="@string/prefs_instant_upload_summary"/>
+               <com.owncloud.android.ui.PreferenceWithLongSummary
+                       android:dependency="instant_uploading"
+                       android:disableDependentsState="true"
+                       android:title="@string/prefs_instant_upload_path_title"
+                       android:key="instant_upload_path" />
            <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
            <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
+                       android:dependency="instant_uploading"
+                       android:disableDependentsState="true"
+               android:title="@string/instant_upload_on_wifi"
+               android:key="instant_upload_on_wifi"/>
+               <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_video_uploading"
                        android:key="instant_video_uploading"
-                               android:title="@string/prefs_instant_video_upload"
-                               android:summary="@string/prefs_instant_video_upload_summary" />
+               android:title="@string/prefs_instant_video_upload"
+               android:summary="@string/prefs_instant_video_upload_summary" />
            <com.owncloud.android.ui.PreferenceWithLongSummary
            <com.owncloud.android.ui.PreferenceWithLongSummary
-                                                       android:title="@string/prefs_instant_video_upload_path_title"
-                                                       android:key="instant_video_upload_path" />
+                       android:dependency="instant_video_uploading"
+                       android:disableDependentsState="true"
+                       android:title="@string/prefs_instant_video_upload_path_title"
+                       android:key="instant_video_upload_path" />
            <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
            <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
-                                               android:title="@string/instant_video_upload_on_wifi"
-                                               android:key="instant_video_upload_on_wifi"/>
-           <!-- DISABLED FOR RELEASE UNTIL FIXED
+                       android:dependency="instant_video_uploading"
+                       android:disableDependentsState="true"
+               android:title="@string/instant_video_upload_on_wifi"
+               android:key="instant_video_upload_on_wifi"/>
+               <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle
+                       android:dependency="instant_video_uploading"
+                       android:disableDependentsState="true"
+                       android:title="@string/instant_video_upload_on_charging"
+                       android:key="instant_video_upload_on_charging"/>
+       </PreferenceCategory>
+       
+       <PreferenceCategory android:title="@string/prefs_category_more" android:key="more">
+               <!-- DISABLED FOR RELEASE UNTIL FIXED
            CheckBoxPreference android:key="log_to_file"
                                android:title="@string/prefs_log_title"
                                android:summary="@string/prefs_log_summary"/>
                <Preference             android:key="log_history"
                                android:title="@string/prefs_log_title_history"
                                android:summary="@string/prefs_log_summary_history"/ -->
            CheckBoxPreference android:key="log_to_file"
                                android:title="@string/prefs_log_title"
                                android:summary="@string/prefs_log_summary"/>
                <Preference             android:key="log_history"
                                android:title="@string/prefs_log_title_history"
                                android:summary="@string/prefs_log_summary_history"/ -->
-                        
-    </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_help" android:key="help" />
                <Preference android:title="@string/prefs_recommend" android:key="recommend" />
                <Preference android:title="@string/prefs_feedback" android:key="feedback" />
index 2a335ad..33ad1cc 100644 (file)
@@ -166,7 +166,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
 
         if (!isOnline(context) 
                 || (instantVideoUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context))
 
         if (!isOnline(context) 
                 || (instantVideoUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context))
-                || (instantUploadWhenChargingOnly(context) && !isCharging(context))
+                || (instantVideoUploadWhenChargingOnly(context) && !isCharging(context))
            ) {
             return;
         }
            ) {
             return;
         }
@@ -190,9 +190,10 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
 
         if (!intent.hasExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY)
                 && isOnline(context)
 
         if (!intent.hasExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY)
                 && isOnline(context)
-                && (!instantUploadWhenChargingOnly(context) || (instantUploadWhenChargingOnly(context) == isCharging(context) == true))
-                && (!instantPictureUploadViaWiFiOnly(context) || (instantPictureUploadViaWiFiOnly(context) == isConnectedViaWiFi(context) == true))
-                && (!instantVideoUploadViaWiFiOnly(context) || (instantVideoUploadViaWiFiOnly(context) == isConnectedViaWiFi(context) == true))
+                && (!instantUploadWhenChargingOnly(context) || (instantUploadWhenChargingOnly(context) && isCharging(context)))
+                && (!instantVideoUploadWhenChargingOnly(context) || (instantVideoUploadWhenChargingOnly(context) && isCharging(context)))
+                && (!instantPictureUploadViaWiFiOnly(context) || (instantPictureUploadViaWiFiOnly(context) && isConnectedViaWiFi(context)))
+                && (!instantVideoUploadViaWiFiOnly(context) || (instantVideoUploadViaWiFiOnly(context) && isConnectedViaWiFi(context)))
             ) {
             DbHandler db = new DbHandler(context);
             Cursor c = db.getAwaitingFiles();
             ) {
             DbHandler db = new DbHandler(context);
             Cursor c = db.getAwaitingFiles();
@@ -248,8 +249,11 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
     public static boolean isCharging(Context context){
         IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
         Intent batteryStatus = context.registerReceiver(null, ifilter);
     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);
+
+        int status = 0;
+        if (batteryStatus != null) {
+            status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
+        }
         return status == BatteryManager.BATTERY_STATUS_CHARGING ||
                 status == BatteryManager.BATTERY_STATUS_FULL;
     }
         return status == BatteryManager.BATTERY_STATUS_CHARGING ||
                 status == BatteryManager.BATTERY_STATUS_FULL;
     }
@@ -272,4 +276,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
     public static boolean instantUploadWhenChargingOnly(Context context) {
         return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_upload_on_charging", false);
     }
     public static boolean instantUploadWhenChargingOnly(Context context) {
         return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_upload_on_charging", false);
     }
+    public static boolean instantVideoUploadWhenChargingOnly(Context context) {
+        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_video_upload_on_charging", false);
+    }
 }
 }