Browse Source

split "on charging" to photo and video

tobiasKaminsky 9 năm trước cách đây
mục cha
commit
e92297ccaf

+ 1 - 0
res/values/strings.xml

@@ -267,6 +267,7 @@
     <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>

+ 38 - 24
res/xml/preferences.xml

@@ -35,42 +35,56 @@
 
     <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
-							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
+			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: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
-							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
-	        				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"/ -->
-                        
-    </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" />

+ 13 - 6
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java

@@ -166,7 +166,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
 
         if (!isOnline(context) 
                 || (instantVideoUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context))
-                || (instantUploadWhenChargingOnly(context) && !isCharging(context))
+                || (instantVideoUploadWhenChargingOnly(context) && !isCharging(context))
            ) {
             return;
         }
@@ -190,9 +190,10 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
 
         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();
@@ -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);
-        
-        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;
     }
@@ -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 instantVideoUploadWhenChargingOnly(Context context) {
+        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_video_upload_on_charging", false);
+    }
 }