Skip to content

Commit 2c29019

Browse files
committed
Fixed : Ignore wifi state check when user has enabled localhost option
1 parent a5df9c0 commit 2c29019

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
minSdk 21
1111
targetSdk 31
1212
multiDexEnabled true
13-
versionCode 12
14-
versionName "2.2.2"
13+
versionCode 13
14+
versionName "2.2.3"
1515

1616

1717
}

app/src/main/java/github/umer0586/fragments/ServerFragment.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import github.umer0586.sensorserver.ServerInfo;
3333
import github.umer0586.service.SensorService;
3434
import github.umer0586.service.ServiceBindHelper;
35+
import github.umer0586.setting.AppSettings;
3536
import github.umer0586.util.UIUtil;
3637

3738

@@ -42,6 +43,7 @@ public class ServerFragment extends Fragment
4243

4344
private SensorService sensorService;
4445
private ServiceBindHelper serviceBindHelper;
46+
private AppSettings appSettings;
4547

4648
// Button at center to start/stop server
4749
private MaterialButton startButton;
@@ -75,6 +77,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
7577
pulseAnimation = view.findViewById(R.id.loading_animation);
7678
cardView = view.findViewById(R.id.card_view);
7779

80+
appSettings = new AppSettings(getContext());
81+
7882
serviceBindHelper = new ServiceBindHelper(
7983
getContext(),
8084
this,
@@ -115,17 +119,26 @@ private void startServer()
115119
Log.d(TAG, "startServer() called");
116120

117121
WifiManager wifiManager = (WifiManager) getContext().getApplicationContext().getSystemService(getContext().WIFI_SERVICE);
118-
119-
// TODO: ignore wifi check when user has enabled adb option
120-
if(!wifiManager.isWifiEnabled())
122+
123+
//If user has enabled local-host option (for adb) then don't check wifi state
124+
if(appSettings.isLocalHostOptionEnable())
125+
{
126+
Intent intent = new Intent(getContext(), SensorService.class);
127+
ContextCompat.startForegroundService(getContext(),intent);
128+
}
129+
//If user has not enabled local-host option then check if wifi is enabled
130+
else if(wifiManager.isWifiEnabled())
131+
{
132+
Intent intent = new Intent(getContext(), SensorService.class);
133+
ContextCompat.startForegroundService(getContext(),intent);
134+
}
135+
136+
else
121137
{
122138
showMessage("Please enable Wi-Fi");
123-
return;
124139
}
125140

126-
serviceBindHelper.bindToService();
127-
Intent intent = new Intent(getContext(), SensorService.class);
128-
ContextCompat.startForegroundService(getContext(),intent);
141+
129142

130143
}
131144

app/src/main/java/github/umer0586/service/SensorService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public int onStartCommand(Intent intent, int flags, int startId)
117117

118118
String ipAddress = null;
119119

120-
// is "local host" switch in enable
120+
// if "local host" switch in enable
121121
// no need to check for wifi network
122122
if(appSettings.isLocalHostOptionEnable())
123123
ipAddress = "127.0.0.1"; // use loopback address

0 commit comments

Comments
 (0)