mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 07:05:49 +03:00
add upload via wifi only option
This commit is contained in:
parent
c72f89c4ba
commit
671cb91cef
3 changed files with 20 additions and 2 deletions
|
@ -194,4 +194,6 @@
|
|||
<string name="ssl_validator_not_saved">The certificate could not be saved</string>
|
||||
|
||||
<string name="text_placeholder">This is a placeholder</string>
|
||||
|
||||
<string name="instant_upload_on_wifi">Upload pictures via WiFi only</string>
|
||||
</resources>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<CheckBoxPreference android:key="instant_uploading"
|
||||
android:title="@string/prefs_instant_upload"
|
||||
android:summary="@string/prefs_instant_upload_summary"/>
|
||||
<CheckBoxPreference android:dependency="instant_uploading" android:disableDependentsState="true" android:title="@string/instant_upload_on_wifi" android:key="instant_upload_on_wifi"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
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.util.Log;
|
||||
|
@ -45,10 +46,13 @@ public class PhotoTakenBroadcastReceiver extends BroadcastReceiver {
|
|||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (!PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_uploading", false)) {
|
||||
boolean iu_enabled = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_uploading", false);
|
||||
|
||||
if (!iu_enabled) {
|
||||
Log.d(TAG, "Instant upload disabled, abording uploading");
|
||||
return;
|
||||
}
|
||||
|
||||
if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
|
||||
handleConnectivityAction(context, intent);
|
||||
} else if (intent.getAction().equals(NEW_PHOTO_ACTION)) {
|
||||
|
@ -71,6 +75,17 @@ public class PhotoTakenBroadcastReceiver extends BroadcastReceiver {
|
|||
Log.e(TAG, "Couldn't resolve given uri!");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean iu_via_wifi = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_upload_on_wifi", false);
|
||||
boolean is_conn_via_wifi = false;
|
||||
if (iu_via_wifi) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (cm != null && cm.getActiveNetworkInfo() != null &&
|
||||
cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI &&
|
||||
cm.getActiveNetworkInfo().getState() == State.CONNECTED)
|
||||
is_conn_via_wifi = true;
|
||||
}
|
||||
|
||||
|
||||
String file_path = c.getString(c.getColumnIndex(Media.DATA));
|
||||
String file_name = c.getString(c.getColumnIndex(Media.DISPLAY_NAME));
|
||||
|
@ -79,7 +94,7 @@ public class PhotoTakenBroadcastReceiver extends BroadcastReceiver {
|
|||
|
||||
c.close();
|
||||
|
||||
if (!isOnline(context)) {
|
||||
if (!isOnline(context) || (iu_via_wifi && !is_conn_via_wifi)) {
|
||||
DbHandler db = new DbHandler(context);
|
||||
db.putFileForLater(file_path, account.name);
|
||||
db.close();
|
||||
|
|
Loading…
Reference in a new issue