Bläddra i källkod

logic error: stop monitoring should be possible when network isn't available

Fabio Arnold 9 år sedan
förälder
incheckning
8625ecba5e
1 ändrade filer med 35 tillägg och 26 borttagningar
  1. 35 26
      src/de/tudarmstadt/informatik/hostage/ui/fragment/HomeFragment.java

+ 35 - 26
src/de/tudarmstadt/informatik/hostage/ui/fragment/HomeFragment.java

@@ -290,32 +290,36 @@ public class HomeFragment extends Fragment {
 		if (mSwitchChangeListener == null) {
 			mSwitchChangeListener = new CompoundButton.OnCheckedChangeListener() {
 				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-					if (!HelperUtils.isNetworkAvailable(getActivity())) {
-						new AlertDialog.Builder(getActivity()).setTitle(R.string.information).setMessage(R.string.network_not_connected_msg)
-								.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-									public void onClick(DialogInterface dialog, int which) {
+					if (isChecked) { // switch activated
+						// we need a network connection
+						if (!HelperUtils.isNetworkAvailable(getActivity())) {
+							new AlertDialog.Builder(getActivity()).setTitle(R.string.information).setMessage(R.string.network_not_connected_msg)
+									.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+										public void onClick(DialogInterface dialog, int which) {
 
-									}
-								}).setIcon(android.R.drawable.ic_dialog_info).show();
+										}
+									}).setIcon(android.R.drawable.ic_dialog_info).show();
 
-						setStateNotActive();
-						setStateNotConnected();
-					} else {
-						if (isChecked) {
+							setStateNotActive();
+							setStateNotConnected();
+						} else { // network available
 							boolean protocolActivated = false;
 							if (ProfileManager.getInstance().getCurrentActivatedProfile() == null) {
-								MainActivity.getInstance().startMonitorServices(Arrays.asList(getResources().getStringArray(R.array.protocols)));
+								MainActivity.getInstance().startMonitorServices(Arrays.asList(
+										getResources().getStringArray(R.array.protocols)));
 							} else {
 								ProfileManager profileManager = ProfileManager.getInstance();
 
 								if (profileManager.isRandomActive()) {
-									profileManager.randomizeProtocols(profileManager.getRandomProfile());
+									profileManager
+											.randomizeProtocols(profileManager.getRandomProfile());
 								}
 
-								Profile currentProfile = profileManager.getCurrentActivatedProfile();
+								Profile currentProfile = profileManager
+										.getCurrentActivatedProfile();
 								List<String> protocols = currentProfile.getActiveProtocols();
 
-								if(protocols.size() > 0 || currentProfile.mGhostActive){
+								if (protocols.size() > 0 || currentProfile.mGhostActive) {
 									protocols.add("GHOST");
 									MainActivity.getInstance().startMonitorServices(protocols);
 									protocolActivated = true;
@@ -325,22 +329,27 @@ public class HomeFragment extends Fragment {
 							if (protocolActivated) {
 								setStateActive();
 							} else {
-								new AlertDialog.Builder(getActivity()).setTitle(R.string.information).setMessage(R.string.profile_no_services_msg)
-										.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-											public void onClick(DialogInterface dialog, int which) {
-
-											}
-										}).setIcon(android.R.drawable.ic_dialog_info).show();
+								new AlertDialog.Builder(getActivity())
+										.setTitle(R.string.information)
+										.setMessage(R.string.profile_no_services_msg)
+										.setPositiveButton(android.R.string.ok,
+												new DialogInterface.OnClickListener() {
+													public void onClick(DialogInterface dialog,
+															int which) {
+
+													}
+												}).setIcon(android.R.drawable.ic_dialog_info)
+										.show();
 
 								setStateNotActive();
 							}
-						} else {
-							if (MainActivity.getInstance().getHostageService() != null) {
-								MainActivity.getInstance().getHostageService().stopListeners();
-								MainActivity.getInstance().stopAndUnbind();
-							}
-							setStateNotActive();
 						}
+					} else { // switch deactivated
+						if (MainActivity.getInstance().getHostageService() != null) {
+							MainActivity.getInstance().getHostageService().stopListeners();
+							MainActivity.getInstance().stopAndUnbind();
+						}
+						setStateNotActive();
 					}
 				}
 			};