moved upload helpers to UploadUtils

This commit is contained in:
Luke Owncloud 2014-11-27 09:02:12 +01:00
parent 949c2ae3c0
commit d7499fdd0d
3 changed files with 16 additions and 17 deletions

View file

@ -25,8 +25,6 @@ import android.content.BroadcastReceiver;
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;
import android.provider.MediaStore.Video;
@ -214,18 +212,6 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
//
// }
public static boolean isOnline(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected();
}
public static boolean isConnectedViaWiFi(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
return cm != null && cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI
&& cm.getActiveNetworkInfo().getState() == State.CONNECTED;
}
public static boolean instantPictureUploadEnabled(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("instant_uploading", false);
}

View file

@ -55,7 +55,6 @@ import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.db.UploadDbHandler;
import com.owncloud.android.db.UploadDbHandler.UploadStatus;
import com.owncloud.android.db.UploadDbObject;
import com.owncloud.android.files.InstantUploadBroadcastReceiver;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
@ -258,7 +257,7 @@ public class FileUploadService extends IntentService {
}
//TODO This service can be instantiated at any time. Better move this retry call to start of app.
if(InstantUploadBroadcastReceiver.isOnline(getApplicationContext())) {
if(UploadUtils.isOnline(getApplicationContext())) {
Log_OC.d(TAG, "FileUploadService.retry() called by onCreate()");
FileUploadService.retry(getApplicationContext());
}
@ -615,7 +614,7 @@ public class FileUploadService extends IntentService {
}
if (uploadDbObject.isUseWifiOnly()
&& !InstantUploadBroadcastReceiver.isConnectedViaWiFi(getApplicationContext())) {
&& !UploadUtils.isConnectedViaWiFi(getApplicationContext())) {
Log_OC.d(TAG, "Do not start upload because it is wifi-only.");
return CanUploadFileNowStatus.LATER;
}

View file

@ -3,6 +3,8 @@ package com.owncloud.android.utils;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
import android.os.BatteryManager;
@ -15,4 +17,16 @@ public class UploadUtils {
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
}
public static boolean isOnline(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected();
}
public static boolean isConnectedViaWiFi(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
return cm != null && cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI
&& cm.getActiveNetworkInfo().getState() == State.CONNECTED;
}
}