Merge branch 'fix-405--swap-feedback-speed' of https://gitlab.com/pserwylo/fdroidclient
This commit is contained in:
commit
873910400d
@ -106,7 +106,7 @@ public class SwapService extends Service {
|
|||||||
// ==========================================================
|
// ==========================================================
|
||||||
|
|
||||||
public void scanForPeers() {
|
public void scanForPeers() {
|
||||||
Log.d(TAG, "Scanning for nearby devices to swap with...");
|
Utils.debugLog(TAG, "Scanning for nearby devices to swap with...");
|
||||||
bonjourFinder.scan();
|
bonjourFinder.scan();
|
||||||
bluetoothFinder.scan();
|
bluetoothFinder.scan();
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ public class SwapService extends Service {
|
|||||||
HttpHost host = new HttpHost(repoUri.getHost(), repoUri.getPort(), repoUri.getScheme());
|
HttpHost host = new HttpHost(repoUri.getHost(), repoUri.getPort(), repoUri.getScheme());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "Asking server at " + address + " to swap with us in return (by POSTing to \"/request-swap\" with repo \"" + swapBackUri + "\")...");
|
Utils.debugLog(TAG, "Asking server at " + address + " to swap with us in return (by POSTing to \"/request-swap\" with repo \"" + swapBackUri + "\")...");
|
||||||
populatePostParams(swapBackUri, request);
|
populatePostParams(swapBackUri, request);
|
||||||
client.execute(host, request);
|
client.execute(host, request);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -377,6 +377,8 @@ public class SwapService extends Service {
|
|||||||
// =============================================================
|
// =============================================================
|
||||||
|
|
||||||
private void persistPreferredSwapTypes() {
|
private void persistPreferredSwapTypes() {
|
||||||
|
Utils.debugLog(TAG, "Remembering that Bluetooth swap " + ( bluetoothSwap.isConnected() ? "IS" : "is NOT" ) +
|
||||||
|
" connected and WiFi swap " + (wifiSwap.isConnected() ? "IS" : "is NOT" ) + " connected.");
|
||||||
persistence().edit()
|
persistence().edit()
|
||||||
.putBoolean(KEY_BLUETOOTH_ENABLED, bluetoothSwap.isConnected())
|
.putBoolean(KEY_BLUETOOTH_ENABLED, bluetoothSwap.isConnected())
|
||||||
.putBoolean(KEY_WIFI_ENABLED, wifiSwap.isConnected())
|
.putBoolean(KEY_WIFI_ENABLED, wifiSwap.isConnected())
|
||||||
@ -399,7 +401,7 @@ public class SwapService extends Service {
|
|||||||
* Moves the service to the forground and [re]starts the timeout timer.
|
* Moves the service to the forground and [re]starts the timeout timer.
|
||||||
*/
|
*/
|
||||||
private void attachService() {
|
private void attachService() {
|
||||||
Log.d(TAG, "Moving SwapService to foreground so that it hangs around even when F-Droid is closed.");
|
Utils.debugLog(TAG, "Moving SwapService to foreground so that it hangs around even when F-Droid is closed (may already be foregrounded).");
|
||||||
startForeground(NOTIFICATION, createNotification());
|
startForeground(NOTIFICATION, createNotification());
|
||||||
|
|
||||||
// Regardless of whether it was previously enabled, start the timer again. This ensures that
|
// Regardless of whether it was previously enabled, start the timer again. This ensures that
|
||||||
@ -413,7 +415,7 @@ public class SwapService extends Service {
|
|||||||
timer.cancel();
|
timer.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "Moving SwapService to background so that it can be GC'ed if required.");
|
Utils.debugLog(TAG, "Moving SwapService to background so that it can be GC'ed if required.");
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,7 +427,7 @@ public class SwapService extends Service {
|
|||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
Log.d(TAG, "Restarting WiFi swap service");
|
Utils.debugLog(TAG, "Restarting WiFi swap service");
|
||||||
wifiSwap.stop();
|
wifiSwap.stop();
|
||||||
wifiSwap.start();
|
wifiSwap.start();
|
||||||
return null;
|
return null;
|
||||||
@ -511,7 +513,7 @@ public class SwapService extends Service {
|
|||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
Log.d(TAG, "Creating swap service.");
|
Utils.debugLog(TAG, "Creating swap service.");
|
||||||
|
|
||||||
SharedPreferences preferences = getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
SharedPreferences preferences = getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
|
||||||
|
|
||||||
@ -531,13 +533,15 @@ public class SwapService extends Service {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
if (wasBluetoothEnabled()) {
|
if (wasBluetoothEnabled()) {
|
||||||
Log.d(TAG, "Previously the user enabled Bluetooth swap, so enabling again automatically.");
|
Utils.debugLog(TAG, "Previously the user enabled Bluetooth swap, so enabling again automatically.");
|
||||||
bluetoothSwap.startInBackground();
|
bluetoothSwap.startInBackground();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (wasWifiEnabled()) {
|
if (wasWifiEnabled()) {
|
||||||
Log.d(TAG, "Previously the user enabled Wifi swap, so enabling again automatically.");
|
Utils.debugLog(TAG, "Previously the user enabled WiFi swap, so enabling again automatically.");
|
||||||
wifiSwap.startInBackground();
|
wifiSwap.startInBackground();
|
||||||
|
} else {
|
||||||
|
Utils.debugLog(TAG, "WiFi was NOT enabled last time user swapped, so starting with WiFi not visible.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -586,7 +590,7 @@ public class SwapService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
Log.d(TAG, "Destroying service, will disable swapping if required, and unregister listeners.");
|
Utils.debugLog(TAG, "Destroying service, will disable swapping if required, and unregister listeners.");
|
||||||
disableAllSwapping();
|
disableAllSwapping();
|
||||||
Preferences.get().unregisterLocalRepoHttpsListeners(httpsEnabledListener);
|
Preferences.get().unregisterLocalRepoHttpsListeners(httpsEnabledListener);
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(onWifiChange);
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(onWifiChange);
|
||||||
@ -607,16 +611,16 @@ public class SwapService extends Service {
|
|||||||
|
|
||||||
private void initTimer() {
|
private void initTimer() {
|
||||||
if (timer != null) {
|
if (timer != null) {
|
||||||
Log.d(TAG, "Cancelling existing timeout timer so timeout can be reset.");
|
Utils.debugLog(TAG, "Cancelling existing timeout timer so timeout can be reset.");
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "Initializing swap timeout to " + TIMEOUT + "ms minutes");
|
Utils.debugLog(TAG, "Initializing swap timeout to " + TIMEOUT + "ms minutes");
|
||||||
timer = new Timer();
|
timer = new Timer();
|
||||||
timer.schedule(new TimerTask() {
|
timer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Log.d(TAG, "Disabling swap because " + TIMEOUT + "ms passed.");
|
Utils.debugLog(TAG, "Disabling swap because " + TIMEOUT + "ms passed.");
|
||||||
disableAllSwapping();
|
disableAllSwapping();
|
||||||
}
|
}
|
||||||
}, TIMEOUT);
|
}, TIMEOUT);
|
||||||
|
@ -127,6 +127,14 @@ public class BluetoothSwap extends SwapType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Don't try to start BT in the background. you can only start/stop a BT server once, else new connections don't work.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void stopInBackground() {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
if (server != null && server.isAlive()) {
|
if (server != null && server.isAlive()) {
|
||||||
|
@ -5,7 +5,9 @@ import android.content.Intent;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.localrepo.SwapService;
|
import org.fdroid.fdroid.localrepo.SwapService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,6 +19,8 @@ import org.fdroid.fdroid.localrepo.SwapService;
|
|||||||
*/
|
*/
|
||||||
public abstract class SwapType {
|
public abstract class SwapType {
|
||||||
|
|
||||||
|
private final static String TAG = "SwapType";
|
||||||
|
|
||||||
private boolean isConnected;
|
private boolean isConnected;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -58,6 +62,7 @@ public abstract class SwapType {
|
|||||||
if (getBroadcastAction() != null) {
|
if (getBroadcastAction() != null) {
|
||||||
Intent intent = new Intent(getBroadcastAction());
|
Intent intent = new Intent(getBroadcastAction());
|
||||||
intent.putExtra(extra, true);
|
intent.putExtra(extra, true);
|
||||||
|
Utils.debugLog(TAG, "Sending broadcast " + extra + " from " + getClass().getSimpleName());
|
||||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,15 +72,12 @@ public abstract class SwapType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void startInBackground() {
|
public void startInBackground() {
|
||||||
start();
|
new Thread() {
|
||||||
/**
|
|
||||||
new AsyncTask<Void, Void, Void>() {
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
public void run() {
|
||||||
start();
|
SwapType.this.start();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}.execute();*/
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ensureRunning() {
|
public void ensureRunning() {
|
||||||
@ -85,23 +87,21 @@ public abstract class SwapType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void ensureRunningInBackground() {
|
public void ensureRunningInBackground() {
|
||||||
new AsyncTask<Void, Void, Void>() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
public void run() {
|
||||||
ensureRunning();
|
ensureRunning();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}.execute();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopInBackground() {
|
public void stopInBackground() {
|
||||||
new AsyncTask<Void, Void, Void>() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
public void run() {
|
||||||
stop();
|
SwapType.this.stop();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}.execute();
|
}.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.localrepo.SwapService;
|
import org.fdroid.fdroid.localrepo.SwapService;
|
||||||
import org.fdroid.fdroid.net.LocalHTTPD;
|
import org.fdroid.fdroid.net.LocalHTTPD;
|
||||||
import org.fdroid.fdroid.net.WifiStateChangeService;
|
import org.fdroid.fdroid.net.WifiStateChangeService;
|
||||||
@ -42,7 +43,7 @@ public class WifiSwap extends SwapType {
|
|||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
|
|
||||||
Log.d(TAG, "Preparing swap webserver.");
|
Utils.debugLog(TAG, "Preparing swap webserver.");
|
||||||
sendBroadcast(SwapService.EXTRA_STARTING);
|
sendBroadcast(SwapService.EXTRA_STARTING);
|
||||||
|
|
||||||
Runnable webServer = new Runnable() {
|
Runnable webServer = new Runnable() {
|
||||||
@ -67,10 +68,10 @@ public class WifiSwap extends SwapType {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "Starting swap webserver...");
|
Utils.debugLog(TAG, "Starting swap webserver...");
|
||||||
localHttpd.start();
|
localHttpd.start();
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
Log.d(TAG, "Swap webserver started.");
|
Utils.debugLog(TAG, "Swap webserver started.");
|
||||||
} catch (BindException e) {
|
} catch (BindException e) {
|
||||||
int prev = FDroidApp.port;
|
int prev = FDroidApp.port;
|
||||||
FDroidApp.port = FDroidApp.port + new Random().nextInt(1111);
|
FDroidApp.port = FDroidApp.port + new Random().nextInt(1111);
|
||||||
@ -93,7 +94,7 @@ public class WifiSwap extends SwapType {
|
|||||||
if (webServerThreadHandler == null) {
|
if (webServerThreadHandler == null) {
|
||||||
Log.i(TAG, "null handler in stopWebServer");
|
Log.i(TAG, "null handler in stopWebServer");
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Sending message to swap webserver to stop it.");
|
Utils.debugLog(TAG, "Sending message to swap webserver to stop it.");
|
||||||
Message msg = webServerThreadHandler.obtainMessage();
|
Message msg = webServerThreadHandler.obtainMessage();
|
||||||
msg.obj = webServerThreadHandler.getLooper().getThread().getName() + " says stop";
|
msg.obj = webServerThreadHandler.getLooper().getThread().getName() + " says stop";
|
||||||
webServerThreadHandler.sendMessage(msg);
|
webServerThreadHandler.sendMessage(msg);
|
||||||
|
@ -86,7 +86,7 @@ public class WifiStateChangeService extends Service {
|
|||||||
wifiInfo = wifiManager.getConnectionInfo();
|
wifiInfo = wifiManager.getConnectionInfo();
|
||||||
FDroidApp.ipAddressString = formatIpAddress(wifiInfo.getIpAddress());
|
FDroidApp.ipAddressString = formatIpAddress(wifiInfo.getIpAddress());
|
||||||
String netmask = formatIpAddress(wifiManager.getDhcpInfo().netmask);
|
String netmask = formatIpAddress(wifiManager.getDhcpInfo().netmask);
|
||||||
if (!TextUtils.isEmpty(FDroidApp.ipAddressString))
|
if (!TextUtils.isEmpty(FDroidApp.ipAddressString) && netmask != null)
|
||||||
FDroidApp.subnetInfo = new SubnetUtils(FDroidApp.ipAddressString, netmask).getInfo();
|
FDroidApp.subnetInfo = new SubnetUtils(FDroidApp.ipAddressString, netmask).getInfo();
|
||||||
} else if (wifiState == WifiManager.WIFI_STATE_DISABLED
|
} else if (wifiState == WifiManager.WIFI_STATE_DISABLED
|
||||||
|| wifiState == WifiManager.WIFI_STATE_DISABLING) {
|
|| wifiState == WifiManager.WIFI_STATE_DISABLING) {
|
||||||
|
@ -32,6 +32,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.localrepo.SwapService;
|
import org.fdroid.fdroid.localrepo.SwapService;
|
||||||
import org.fdroid.fdroid.localrepo.peers.Peer;
|
import org.fdroid.fdroid.localrepo.peers.Peer;
|
||||||
import org.fdroid.fdroid.net.WifiStateChangeService;
|
import org.fdroid.fdroid.net.WifiStateChangeService;
|
||||||
@ -44,10 +45,10 @@ public class StartSwapView extends ScrollView implements SwapWorkflowActivity.In
|
|||||||
|
|
||||||
private static final String TAG = "StartSwapView";
|
private static final String TAG = "StartSwapView";
|
||||||
|
|
||||||
// TODO: Is there a way to guarangee which of these constructors the inflater will call?
|
// TODO: Is there a way to guarantee which of these constructors the inflater will call?
|
||||||
// Especially on different API levels? It would be nice to only have the one which accepts
|
// Especially on different API levels? It would be nice to only have the one which accepts
|
||||||
// a Context, but I'm not sure if that is correct or not. As it stands, this class provides
|
// a Context, but I'm not sure if that is correct or not. As it stands, this class provides
|
||||||
// constructurs which match each of the ones available in the parent class.
|
// constructors which match each of the ones available in the parent class.
|
||||||
// The same is true for the other views in the swap process too.
|
// The same is true for the other views in the swap process too.
|
||||||
|
|
||||||
public StartSwapView(Context context) {
|
public StartSwapView(Context context) {
|
||||||
@ -87,11 +88,9 @@ public class StartSwapView extends ScrollView implements SwapWorkflowActivity.In
|
|||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private SwapWorkflowActivity getActivity() {
|
private SwapWorkflowActivity getActivity() {
|
||||||
// TODO: Try and find a better way to get to the SwapActivity, which makes less asumptions.
|
|
||||||
return (SwapWorkflowActivity)getContext();
|
return (SwapWorkflowActivity)getContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,9 +176,9 @@ public class StartSwapView extends ScrollView implements SwapWorkflowActivity.In
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Peer peer = intent.getParcelableExtra(SwapService.EXTRA_PEER);
|
Peer peer = intent.getParcelableExtra(SwapService.EXTRA_PEER);
|
||||||
if (adapter.getPosition(peer) >= 0) {
|
if (adapter.getPosition(peer) >= 0) {
|
||||||
Log.d(TAG, "Found peer: " + peer + ", ignoring though, because it is already in our list.");
|
Utils.debugLog(TAG, "Found peer: " + peer + ", ignoring though, because it is already in our list.");
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Found peer: " + peer + ", adding to list of peers in UI.");
|
Utils.debugLog(TAG, "Found peer: " + peer + ", adding to list of peers in UI.");
|
||||||
adapter.add(peer);
|
adapter.add(peer);
|
||||||
uiUpdatePeersInfo();
|
uiUpdatePeersInfo();
|
||||||
}
|
}
|
||||||
@ -216,21 +215,26 @@ public class StartSwapView extends ScrollView implements SwapWorkflowActivity.In
|
|||||||
textBluetoothVisible.setText(textResource);
|
textBluetoothVisible.setText(textResource);
|
||||||
|
|
||||||
final SwitchCompat bluetoothSwitch = ((SwitchCompat) findViewById(R.id.switch_bluetooth));
|
final SwitchCompat bluetoothSwitch = ((SwitchCompat) findViewById(R.id.switch_bluetooth));
|
||||||
|
Utils.debugLog(TAG, getManager().isBluetoothDiscoverable() ? "Initially marking switch as checked, because Bluetooth is discoverable." : "Initially marking switch as not-checked, because Bluetooth is not discoverable.");
|
||||||
bluetoothSwitch.setChecked(getManager().isBluetoothDiscoverable());
|
bluetoothSwitch.setChecked(getManager().isBluetoothDiscoverable());
|
||||||
bluetoothSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
bluetoothSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
|
Utils.debugLog(TAG, "Received onCheckChanged(true) for Bluetooth swap, prompting user as to whether they want to enable Bluetooth.");
|
||||||
getActivity().startBluetoothSwap();
|
getActivity().startBluetoothSwap();
|
||||||
textBluetoothVisible.setText(R.string.swap_visible_bluetooth);
|
textBluetoothVisible.setText(R.string.swap_visible_bluetooth);
|
||||||
viewBluetoothId.setVisibility(View.VISIBLE);
|
viewBluetoothId.setVisibility(View.VISIBLE);
|
||||||
uiUpdatePeersInfo();
|
uiUpdatePeersInfo();
|
||||||
|
Utils.debugLog(TAG, "Received onCheckChanged(true) for Bluetooth swap (prompting user or setup Bluetooth complete)");
|
||||||
// TODO: When they deny the request for enabling bluetooth, we need to disable this switch...
|
// TODO: When they deny the request for enabling bluetooth, we need to disable this switch...
|
||||||
} else {
|
} else {
|
||||||
|
Utils.debugLog(TAG, "Received onCheckChanged(false) for Bluetooth swap, disabling Bluetooth swap.");
|
||||||
getManager().getBluetoothSwap().stop();
|
getManager().getBluetoothSwap().stop();
|
||||||
textBluetoothVisible.setText(R.string.swap_not_visible_bluetooth);
|
textBluetoothVisible.setText(R.string.swap_not_visible_bluetooth);
|
||||||
viewBluetoothId.setVisibility(View.GONE);
|
viewBluetoothId.setVisibility(View.GONE);
|
||||||
uiUpdatePeersInfo();
|
uiUpdatePeersInfo();
|
||||||
|
Utils.debugLog(TAG, "Received onCheckChanged(false) for Bluetooth swap, Bluetooth swap disabled successfully.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -240,18 +244,18 @@ public class StartSwapView extends ScrollView implements SwapWorkflowActivity.In
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (intent.hasExtra(SwapService.EXTRA_STARTING)) {
|
if (intent.hasExtra(SwapService.EXTRA_STARTING)) {
|
||||||
Log.d(TAG, "Bluetooth service is starting...");
|
Utils.debugLog(TAG, "Bluetooth service is starting (setting toggle to disabled, not checking because we will wait for an intent that bluetooth is actually enabled)");
|
||||||
bluetoothSwitch.setEnabled(false);
|
bluetoothSwitch.setEnabled(false);
|
||||||
textBluetoothVisible.setText(R.string.swap_setting_up_bluetooth);
|
textBluetoothVisible.setText(R.string.swap_setting_up_bluetooth);
|
||||||
// bluetoothSwitch.setChecked(true);
|
// bluetoothSwitch.setChecked(true);
|
||||||
} else {
|
} else {
|
||||||
bluetoothSwitch.setEnabled(true);
|
bluetoothSwitch.setEnabled(true);
|
||||||
if (intent.hasExtra(SwapService.EXTRA_STARTED)) {
|
if (intent.hasExtra(SwapService.EXTRA_STARTED)) {
|
||||||
Log.d(TAG, "Bluetooth service has started.");
|
Utils.debugLog(TAG, "Bluetooth service has started (updating text to visible, but not marking as checked).");
|
||||||
textBluetoothVisible.setText(R.string.swap_visible_bluetooth);
|
textBluetoothVisible.setText(R.string.swap_visible_bluetooth);
|
||||||
// bluetoothSwitch.setChecked(true);
|
// bluetoothSwitch.setChecked(true);
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Bluetooth service has stopped.");
|
Utils.debugLog(TAG, "Bluetooth service has stopped (setting switch to not-visible).");
|
||||||
textBluetoothVisible.setText(R.string.swap_not_visible_bluetooth);
|
textBluetoothVisible.setText(R.string.swap_not_visible_bluetooth);
|
||||||
bluetoothSwitch.setChecked(false);
|
bluetoothSwitch.setChecked(false);
|
||||||
}
|
}
|
||||||
@ -275,9 +279,12 @@ public class StartSwapView extends ScrollView implements SwapWorkflowActivity.In
|
|||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
|
Utils.debugLog(TAG, "Received onCheckChanged(true) for WiFi swap, asking in background thread to ensure WiFi swap is running.");
|
||||||
getManager().getWifiSwap().ensureRunningInBackground();
|
getManager().getWifiSwap().ensureRunningInBackground();
|
||||||
} else {
|
} else {
|
||||||
|
Utils.debugLog(TAG, "Received onCheckChanged(false) for WiFi swap, disabling WiFi swap.");
|
||||||
getManager().getWifiSwap().stop();
|
getManager().getWifiSwap().stop();
|
||||||
|
Utils.debugLog(TAG, "Received onCheckChanged(false) for WiFi swap, WiFi swap disabled successfully.");
|
||||||
}
|
}
|
||||||
uiUpdatePeersInfo();
|
uiUpdatePeersInfo();
|
||||||
uiUpdateWifiNetwork();
|
uiUpdateWifiNetwork();
|
||||||
@ -288,30 +295,34 @@ public class StartSwapView extends ScrollView implements SwapWorkflowActivity.In
|
|||||||
int textResource = getManager().isBonjourDiscoverable() ? R.string.swap_visible_wifi : R.string.swap_not_visible_wifi;
|
int textResource = getManager().isBonjourDiscoverable() ? R.string.swap_visible_wifi : R.string.swap_not_visible_wifi;
|
||||||
textWifiVisible.setText(textResource);
|
textWifiVisible.setText(textResource);
|
||||||
|
|
||||||
|
// Note that this is only listening for the WifiSwap, whereas we start both the WifiSwap
|
||||||
|
// and the Bonjour service at the same time. Technically swap will work fine without
|
||||||
|
// Bonjour, and that is more of a convenience. Thus, we should show feedback once wifi
|
||||||
|
// is ready, even if Bonjour is not yet.
|
||||||
// TODO: Unregister receiver correctly...
|
// TODO: Unregister receiver correctly...
|
||||||
LocalBroadcastManager.getInstance(getContext()).registerReceiver(new BroadcastReceiver() {
|
LocalBroadcastManager.getInstance(getContext()).registerReceiver(new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (intent.hasExtra(SwapService.EXTRA_STARTING)) {
|
if (intent.hasExtra(SwapService.EXTRA_STARTING)) {
|
||||||
Log.d(TAG, "Bonjour/WiFi service is starting...");
|
Utils.debugLog(TAG, "WiFi service is starting (setting toggle to visible, but disabled).");
|
||||||
textWifiVisible.setText(R.string.swap_setting_up_wifi);
|
textWifiVisible.setText(R.string.swap_setting_up_wifi);
|
||||||
wifiSwitch.setEnabled(false);
|
wifiSwitch.setEnabled(false);
|
||||||
wifiSwitch.setChecked(true);
|
wifiSwitch.setChecked(true);
|
||||||
} else {
|
} else {
|
||||||
wifiSwitch.setEnabled(true);
|
wifiSwitch.setEnabled(true);
|
||||||
if (intent.hasExtra(SwapService.EXTRA_STARTED)) {
|
if (intent.hasExtra(SwapService.EXTRA_STARTED)) {
|
||||||
Log.d(TAG, "Bonjour/WiFi service has started.");
|
Utils.debugLog(TAG, "WiFi service has started (setting toggle to visible).");
|
||||||
textWifiVisible.setText(R.string.swap_visible_wifi);
|
textWifiVisible.setText(R.string.swap_visible_wifi);
|
||||||
wifiSwitch.setChecked(true);
|
wifiSwitch.setChecked(true);
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Bonjour/WiFi service has stopped.");
|
Utils.debugLog(TAG, "WiFi service has stopped (setting toggle to not-visible).");
|
||||||
textWifiVisible.setText(R.string.swap_not_visible_wifi);
|
textWifiVisible.setText(R.string.swap_not_visible_wifi);
|
||||||
wifiSwitch.setChecked(false);
|
wifiSwitch.setChecked(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uiUpdateWifiNetwork();
|
uiUpdateWifiNetwork();
|
||||||
}
|
}
|
||||||
}, new IntentFilter(SwapService.BONJOUR_STATE_CHANGE));
|
}, new IntentFilter(SwapService.WIFI_STATE_CHANGE));
|
||||||
|
|
||||||
viewWifiNetwork.setOnClickListener(new OnClickListener() {
|
viewWifiNetwork.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user