Skip to content

Commit

Permalink
Refactor WifiScanConnect.BroadcastReceiver to get timer as parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
zealotzealot committed Nov 30, 2019
1 parent 900c18f commit 522eae4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,7 @@ public void tryWifiConnect() {
SsidPwPick ssidPwPick = new SsidPwPick(receivedTextBlockList, receivedWifiDataList);
final SsidPw ssidPw = getSsidPw();

wifiConnectReceiver = WifiScanConnect.connectAndRegisterReceiver(this, wifiManager, new IntentFilter(), ssidPw);
Log.d(TAG, "Start timer");
timer.schedule(new TimerTask() {
@Override
public void run() {
Log.d(TAG, "Run timer");
ProcessingActivity activity = mWeakReference.get();
if (activity != null && !activity.isFinishing()) {
Intent failIntent = new Intent(activity, FailActivity.class);
failIntent.putExtra("id", ssidPw.ssid);
failIntent.putExtra("pw", ssidPw.pw);
startActivity(failIntent);
}
}
}, 3500);
wifiConnectReceiver = WifiScanConnect.connectAndRegisterReceiver(this, wifiManager, new IntentFilter(), ssidPw, timer);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

public class WifiScanConnect {
final static String TAG = "WifiScanConnect";
Expand All @@ -36,7 +38,7 @@ public static BroadcastReceiver scanAndRegisterReceiver(

public static BroadcastReceiver connectAndRegisterReceiver(
final AppCompatActivity activity, final WifiManager wifiManager,
IntentFilter intentFilter, final SsidPw ssidPw) {
IntentFilter intentFilter, final SsidPw ssidPw, Timer timer) {
if (ssidPw == null || ssidPw.ssid == null) {
return null;
}
Expand Down Expand Up @@ -80,6 +82,21 @@ public void onReceive(Context context, Intent intent) {
activity.registerReceiver(connectReceiver, intentFilter);
wifiManager.enableNetwork(netId, true);
// wifiManager.reconnect();

Log.d(TAG, "Start timer");
timer.schedule(new TimerTask() {
@Override
public void run() {
Log.d(TAG, "Run timer");
if (activity != null && !activity.isFinishing()) {
Intent failIntent = new Intent(activity, FailActivity.class);
failIntent.putExtra("id", ssidPw.ssid);
failIntent.putExtra("pw", ssidPw.pw);
activity.startActivity(failIntent);
}
}
}, 3500);

return connectReceiver;
}
}

0 comments on commit 522eae4

Please sign in to comment.