Skip to content

Commit

Permalink
Fixed Issue cgeo#708 - Refresh caches + no internet = normal progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
donEgro committed Apr 20, 2013
1 parent 8c39176 commit 705dc21
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions main/src/cgeo/geocaching/cgeocaches.java
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,11 @@ public void refreshStored(final List<Geocache> caches) {
return;
}

if (!Network.isNetworkConnected(getApplicationContext())) {
showToast(getString(R.string.err_server));
return;
}

if (Settings.getChooseList() && type != CacheListType.OFFLINE) {
// let user select list to store cache in
new StoredList.UserInterface(this).promptForListSelection(R.string.list_title,
Expand Down
18 changes: 18 additions & 0 deletions main/src/cgeo/geocaching/network/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;

import java.io.File;
Expand Down Expand Up @@ -471,4 +474,19 @@ public static String encode(final String text) {
return null;
}

/**
* Checks if the device has network connection.
*
* @param context
* context of the application, cannot be null
*
* @return <code>true</code> if the device is connected to the network.
*/
public static boolean isNetworkConnected(Context context) {
ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = conMan.getActiveNetworkInfo();

return activeNetwork != null && activeNetwork.isConnected();
}

}

0 comments on commit 705dc21

Please sign in to comment.